时间戳服务BUG修复

This commit is contained in:
zhangqinbin
2021-07-16 14:53:37 +08:00
parent 192d0a5589
commit 091ea9dd82
2 changed files with 19 additions and 13 deletions

View File

@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import java.io.InputStream; import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -18,6 +19,7 @@ import java.util.Date;
import java.util.Properties; import java.util.Properties;
@Slf4j @Slf4j
@Service
public class TimeServiceConstant { public class TimeServiceConstant {
public static TSAClient client; public static TSAClient client;
@ -25,7 +27,7 @@ public class TimeServiceConstant {
@Value("${spring.redis.sentinel.master}") @Value("${spring.redis.sentinel.master}")
private String redis; private String redis;
public TimeServiceConstant(){ static {
try{ try{
Properties prop = new Properties(); Properties prop = new Properties();
ClassPathResource classPathResource = new ClassPathResource("cssconfig.properties"); ClassPathResource classPathResource = new ClassPathResource("cssconfig.properties");

View File

@ -1,12 +1,14 @@
package com.chinaunicom.mall.ebtp.extend.timeService.controller; package com.chinaunicom.mall.ebtp.extend.timeService.controller;
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
import com.chinaunicom.mall.ebtp.extend.export.service.ExportServiceFactory;
import com.chinaunicom.mall.ebtp.extend.timeService.TimeServiceConstant; import com.chinaunicom.mall.ebtp.extend.timeService.TimeServiceConstant;
import com.chinaunicom.mall.ebtp.extend.timeService.tsa.SystemTime; import com.chinaunicom.mall.ebtp.extend.timeService.tsa.SystemTime;
import com.chinaunicom.mall.ebtp.extend.timeService.tsa.TtsAgent; import com.chinaunicom.mall.ebtp.extend.timeService.tsa.TtsAgent;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -20,6 +22,8 @@ import java.util.Date;
@RequestMapping("/v1/timeService") @RequestMapping("/v1/timeService")
public class TimeServiceController { public class TimeServiceController {
@Autowired
private TimeServiceConstant timeServiceConstant;
/** /**
* 申请时间戳 * 申请时间戳
* *
@ -29,8 +33,8 @@ public class TimeServiceController {
@ApiOperation("申请时间戳") @ApiOperation("申请时间戳")
@GetMapping(value = "/signTimeStamp") @GetMapping(value = "/signTimeStamp")
public BaseResponse<String> signTimeStamp(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) { public BaseResponse<String> signTimeStamp(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) {
TimeServiceConstant constant = new TimeServiceConstant(); //TimeServiceConstant constant = new TimeServiceConstant();
return BaseResponse.success(constant.signTimeStamp(data)); return BaseResponse.success(timeServiceConstant.signTimeStamp(data));
} }
/** /**
@ -42,8 +46,8 @@ public class TimeServiceController {
@ApiOperation("解析时间戳加密原文") @ApiOperation("解析时间戳加密原文")
@PostMapping(value = "/verifyTimeStamp") @PostMapping(value = "/verifyTimeStamp")
public BaseResponse<TtsAgent.TtsParseResult> verifyTimeStamp(@ApiParam(value = "时间戳加密原文", required = true) @RequestBody String timestamp) { public BaseResponse<TtsAgent.TtsParseResult> verifyTimeStamp(@ApiParam(value = "时间戳加密原文", required = true) @RequestBody String timestamp) {
TimeServiceConstant constant = new TimeServiceConstant(); //TimeServiceConstant constant = new TimeServiceConstant();
return BaseResponse.success(constant.verifyTimeStamp2(timestamp)); return BaseResponse.success(timeServiceConstant.verifyTimeStamp2(timestamp));
} }
/** /**
@ -55,8 +59,8 @@ public class TimeServiceController {
@ApiOperation("直接获取时间戳对象(内涵日期)") @ApiOperation("直接获取时间戳对象(内涵日期)")
@PostMapping(value = "/getServiceTimeObj") @PostMapping(value = "/getServiceTimeObj")
public BaseResponse<TtsAgent.TtsParseResult> getServiceTimeObj(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) { public BaseResponse<TtsAgent.TtsParseResult> getServiceTimeObj(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) {
TimeServiceConstant constant = new TimeServiceConstant(); //TimeServiceConstant constant = new TimeServiceConstant();
return BaseResponse.success(constant.getServiceTimeObj(data)); return BaseResponse.success(timeServiceConstant.getServiceTimeObj(data));
} }
/** /**
@ -68,8 +72,8 @@ public class TimeServiceController {
@ApiOperation("直接获取日期字符串") @ApiOperation("直接获取日期字符串")
@GetMapping(value = "/getServiceTime") @GetMapping(value = "/getServiceTime")
public BaseResponse<String> getServiceTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) { public BaseResponse<String> getServiceTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) {
TimeServiceConstant constant = new TimeServiceConstant(); //TimeServiceConstant constant = new TimeServiceConstant();
return BaseResponse.success(constant.getServiceTime(data)); return BaseResponse.success(timeServiceConstant.getServiceTime(data));
} }
/** /**
@ -81,8 +85,8 @@ public class TimeServiceController {
@ApiOperation("获取日期对象SystemTime") @ApiOperation("获取日期对象SystemTime")
@GetMapping(value = "/getServiceSystemTime") @GetMapping(value = "/getServiceSystemTime")
public BaseResponse<SystemTime> getServiceSystemTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) { public BaseResponse<SystemTime> getServiceSystemTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) {
TimeServiceConstant constant = new TimeServiceConstant(); //TimeServiceConstant constant = new TimeServiceConstant();
return BaseResponse.success(constant.getServiceSystemTime(data)); return BaseResponse.success(timeServiceConstant.getServiceSystemTime(data));
} }
/** /**
@ -96,9 +100,9 @@ public class TimeServiceController {
public BaseResponse<SystemTime> getDescOpenRoomTime(@RequestParam(name = "openTime", required = true) String openTime) { public BaseResponse<SystemTime> getDescOpenRoomTime(@RequestParam(name = "openTime", required = true) String openTime) {
try { try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
TimeServiceConstant constant = new TimeServiceConstant(); //TimeServiceConstant constant = new TimeServiceConstant();
Date now = constant.getServiceDate("getDescOpenRoomTime"); Date now = timeServiceConstant.getServiceDate("getDescOpenRoomTime");
;//当前时间 ;//当前时间
Date date = df.parse(openTime);//过去 Date date = df.parse(openTime);//过去
long l = date.getTime() - now.getTime(); long l = date.getTime() - now.getTime();