From 02c5934cc95e527d68d2208fc17b0a50f76dc843 Mon Sep 17 00:00:00 2001 From: zhangqinbin <181961702@qq.com> Date: Fri, 16 Jul 2021 14:38:35 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1BUG=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeService/TimeServiceConstant.java | 100 +++++++++++++----- 1 file changed, 72 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java index d88c289..e2463cd 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java @@ -9,11 +9,11 @@ import com.chinaunicom.mall.ebtp.extend.timeService.tsa.SystemTime; import com.chinaunicom.mall.ebtp.extend.timeService.tsa.TtsAgent; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.ClassPathResource; import java.io.InputStream; import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Date; import java.util.Properties; @@ -22,6 +22,9 @@ public class TimeServiceConstant { public static TSAClient client; + @Value("${spring.redis.sentinel.master}") + private String redis; + public TimeServiceConstant(){ try{ Properties prop = new Properties(); @@ -44,7 +47,11 @@ public class TimeServiceConstant { * @return 时间戳加密原文 */ public String signTimeStamp(String data){ + if(redis.equals("eshop-redis-sim")){ + return ""; + } try{ + data = data!=null&&!"".equals(data)?data:"system"; //第三步:申请时间戳,向时间戳服务器发起申请时间戳请求,返回时间戳结果 TSASignedResult result = client.signTimeStamp("SHA1", data.getBytes("UTF-8")); @@ -57,7 +64,7 @@ public class TimeServiceConstant { }catch (Exception e){ log.error("申请时间戳异常", e); } - return null; + return ""; } /** * 解析时间戳 @@ -65,21 +72,28 @@ public class TimeServiceConstant { * @return 时间戳对象 */ public TtsAgent.TtsParseResult verifyTimeStamp2(String timestamp){ + String systemtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + TtsAgent.TtsParseResult ttsParseResult = new TtsAgent.TtsParseResult(systemtime,"",""); + if(redis.equals("eshop-redis-sim")){ + return ttsParseResult; + } try{ + log.info("timestamp -->"+timestamp); TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp); String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(verifyResult.getSignedTime()); - TtsAgent.TtsParseResult ttsParseResult = new TtsAgent.TtsParseResult(time, HelperUtil.bytesToHexString(verifyResult.getData()), + ttsParseResult = new TtsAgent.TtsParseResult(time, HelperUtil.bytesToHexString(verifyResult.getData()), verifyResult.getSignerSubject()); - return ttsParseResult; }catch (Exception e){ log.error("解析时间戳", e); } - return null; + return ttsParseResult; } private TSAVerifyResult verifyTimeStamp(String timestamp){ + try{ + log.info("timestamp -->"+timestamp); TSAVerifyResult verifyResult = client.verifyTimeStamp(Base64.decodeBase64(timestamp)); return verifyResult; @@ -95,14 +109,19 @@ public class TimeServiceConstant { * @return 时间戳对象 */ public TtsAgent.TtsParseResult getServiceTimeObj(String data){ - try{ - String timestamp = this.signTimeStamp(data); - TtsAgent.TtsParseResult ttsParseResult = this.verifyTimeStamp2(timestamp); + String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + TtsAgent.TtsParseResult ttsParseResult = new TtsAgent.TtsParseResult(time,"",""); + if(redis.equals("eshop-redis-sim")){ return ttsParseResult; + } + try{ + + String timestamp = this.signTimeStamp(data); + ttsParseResult = this.verifyTimeStamp2(timestamp); }catch (Exception e){ log.error("获取时间戳异常", e); } - return null; + return ttsParseResult; } /** @@ -111,16 +130,19 @@ public class TimeServiceConstant { * @return 时间 */ public String getServiceTime(String data){ + String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + if(redis.equals("eshop-redis-sim")){ + return time; + } try{ + String timestamp = this.signTimeStamp(data); TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp); - String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(verifyResult.getSignedTime()); - - return time; + time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(verifyResult.getSignedTime()); }catch (Exception e){ log.error("获取时间戳异常", e); } - return null; + return time; } @@ -130,7 +152,11 @@ public class TimeServiceConstant { * @return date时间 */ public Date getServiceDate(String data){ + if(redis.equals("eshop-redis-sim")){ + return new Date(); + } try{ + String timestamp = this.signTimeStamp(data); TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp); Date date = verifyResult.getSignedTime(); @@ -138,7 +164,7 @@ public class TimeServiceConstant { }catch (Exception e){ log.error("获取时间戳异常", e); } - return null; + return new Date(); } /** * 获取年月日时分秒分割存储对象 @@ -146,11 +172,9 @@ public class TimeServiceConstant { * @return SystemTime */ public SystemTime getServiceSystemTime(String data){ - try{ - String timestamp = this.signTimeStamp(data); - TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp); - Date date = verifyResult.getSignedTime(); - SystemTime systemTime = new SystemTime() + Date date = new Date(); + if(redis.equals("eshop-redis-sim")){ + return new SystemTime() .setYear(date.getYear()+1900) .setMonth(date.getMonth()+1) .setDate(date.getDate()) @@ -158,20 +182,40 @@ public class TimeServiceConstant { .setMinute(date.getMinutes()) .setSecond(date.getSeconds()) .setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); - return systemTime; + } + try{ + + String timestamp = this.signTimeStamp(data); + TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp); + date = verifyResult.getSignedTime(); + }catch (Exception e){ log.error("获取时间戳异常", e); } - return null; + SystemTime systemTime = new SystemTime() + .setYear(date.getYear()+1900) + .setMonth(date.getMonth()+1) + .setDate(date.getDate()) + .setHour(date.getHours()) + .setMinute(date.getMinutes()) + .setSecond(date.getSeconds()) + .setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); + return systemTime; } public static void main(String arge[]){ - Date date = new Date(); - System.out.println("-----------"+(date.getYear()+1900)); - System.out.println("-----------"+(date.getMonth()+1)); - System.out.println("-----------"+date.getDate()); - System.out.println("-----------"+date.getHours()); - System.out.println("-----------"+date.getMinutes()); - System.out.println("-----------"+date.getSeconds()); + try{ + + Date date = new Date(); + System.out.println("-----------"+(date.getYear()+1900)); + System.out.println("-----------"+(date.getMonth()+1)); + System.out.println("-----------"+date.getDate()); + System.out.println("-----------"+date.getHours()); + System.out.println("-----------"+date.getMinutes()); + System.out.println("-----------"+date.getSeconds()); + + }catch (Exception e){ + e.printStackTrace(); + } } } From 192d0a5589f1790d276f49625960c696ecc12ff3 Mon Sep 17 00:00:00 2001 From: zhangqinbin <181961702@qq.com> Date: Fri, 16 Jul 2021 14:41:00 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1BUG=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/ebtp/extend/timeService/TimeServiceConstant.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java index e2463cd..141322f 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java @@ -130,6 +130,7 @@ public class TimeServiceConstant { * @return 时间 */ public String getServiceTime(String data){ + log.info("------------------redis-"+redis); String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); if(redis.equals("eshop-redis-sim")){ return time; From 091ea9dd8267209e3fc70b1ec4d4bc89f64aa4d1 Mon Sep 17 00:00:00 2001 From: zhangqinbin <181961702@qq.com> Date: Fri, 16 Jul 2021 14:53:37 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1BUG=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timeService/TimeServiceConstant.java | 4 ++- .../controller/TimeServiceController.java | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java index 141322f..1fff3ff 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/TimeServiceConstant.java @@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.ClassPathResource; +import org.springframework.stereotype.Service; import java.io.InputStream; import java.text.SimpleDateFormat; @@ -18,6 +19,7 @@ import java.util.Date; import java.util.Properties; @Slf4j +@Service public class TimeServiceConstant { public static TSAClient client; @@ -25,7 +27,7 @@ public class TimeServiceConstant { @Value("${spring.redis.sentinel.master}") private String redis; - public TimeServiceConstant(){ + static { try{ Properties prop = new Properties(); ClassPathResource classPathResource = new ClassPathResource("cssconfig.properties"); diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/controller/TimeServiceController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/controller/TimeServiceController.java index 0b15b23..22ce64e 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/controller/TimeServiceController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/controller/TimeServiceController.java @@ -1,12 +1,14 @@ package com.chinaunicom.mall.ebtp.extend.timeService.controller; 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.tsa.SystemTime; import com.chinaunicom.mall.ebtp.extend.timeService.tsa.TtsAgent; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -20,6 +22,8 @@ import java.util.Date; @RequestMapping("/v1/timeService") public class TimeServiceController { + @Autowired + private TimeServiceConstant timeServiceConstant; /** * 申请时间戳 * @@ -29,8 +33,8 @@ public class TimeServiceController { @ApiOperation("申请时间戳") @GetMapping(value = "/signTimeStamp") public BaseResponse signTimeStamp(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) { - TimeServiceConstant constant = new TimeServiceConstant(); - return BaseResponse.success(constant.signTimeStamp(data)); + //TimeServiceConstant constant = new TimeServiceConstant(); + return BaseResponse.success(timeServiceConstant.signTimeStamp(data)); } /** @@ -42,8 +46,8 @@ public class TimeServiceController { @ApiOperation("解析时间戳加密原文") @PostMapping(value = "/verifyTimeStamp") public BaseResponse verifyTimeStamp(@ApiParam(value = "时间戳加密原文", required = true) @RequestBody String timestamp) { - TimeServiceConstant constant = new TimeServiceConstant(); - return BaseResponse.success(constant.verifyTimeStamp2(timestamp)); + //TimeServiceConstant constant = new TimeServiceConstant(); + return BaseResponse.success(timeServiceConstant.verifyTimeStamp2(timestamp)); } /** @@ -55,8 +59,8 @@ public class TimeServiceController { @ApiOperation("直接获取时间戳对象(内涵日期)") @PostMapping(value = "/getServiceTimeObj") public BaseResponse getServiceTimeObj(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) { - TimeServiceConstant constant = new TimeServiceConstant(); - return BaseResponse.success(constant.getServiceTimeObj(data)); + //TimeServiceConstant constant = new TimeServiceConstant(); + return BaseResponse.success(timeServiceConstant.getServiceTimeObj(data)); } /** @@ -68,8 +72,8 @@ public class TimeServiceController { @ApiOperation("直接获取日期字符串") @GetMapping(value = "/getServiceTime") public BaseResponse getServiceTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) { - TimeServiceConstant constant = new TimeServiceConstant(); - return BaseResponse.success(constant.getServiceTime(data)); + //TimeServiceConstant constant = new TimeServiceConstant(); + return BaseResponse.success(timeServiceConstant.getServiceTime(data)); } /** @@ -81,8 +85,8 @@ public class TimeServiceController { @ApiOperation("获取日期对象SystemTime") @GetMapping(value = "/getServiceSystemTime") public BaseResponse getServiceSystemTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data", required = false) String data) { - TimeServiceConstant constant = new TimeServiceConstant(); - return BaseResponse.success(constant.getServiceSystemTime(data)); + //TimeServiceConstant constant = new TimeServiceConstant(); + return BaseResponse.success(timeServiceConstant.getServiceSystemTime(data)); } /** @@ -96,9 +100,9 @@ public class TimeServiceController { public BaseResponse getDescOpenRoomTime(@RequestParam(name = "openTime", required = true) String openTime) { try { 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);//过去 long l = date.getTime() - now.getTime(); From 2f9fc4116b073ddb9fbcc5fbb2ae18b17fdcb428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E5=BA=86=E5=90=89?= <51312040@qq.com> Date: Mon, 2 Aug 2021 09:24:29 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deployment-dev.yaml | 8 ++++++++ deployment-sim.yaml | 5 ++--- deployment-uat.yaml | 5 ++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/deployment-dev.yaml b/deployment-dev.yaml index 797b04c..50b3a03 100644 --- a/deployment-dev.yaml +++ b/deployment-dev.yaml @@ -35,10 +35,18 @@ spec: # 定义容器模板,该模板可以包含多个容器 spec: + volumes: + - name: log + hostPath: + path: /var/lib/docker/log/349553515466-test/default-group/all #开发环境 # 必选,Pod中容器列表 containers: - name: biz-service-ebtp-extend image: harbor.dcos.guangzhou.unicom.local/eshop/biz-service-ebtp-extend:latest + # 在容器中挂载日志存储区 + volumeMounts: + - name: log + mountPath: /log # 需要暴露的端口库号列表 ports: - containerPort: 18018 diff --git a/deployment-sim.yaml b/deployment-sim.yaml index 50a52d0..6d1ff47 100644 --- a/deployment-sim.yaml +++ b/deployment-sim.yaml @@ -37,9 +37,8 @@ spec: spec: volumes: - name: log - persistentVolumeClaim: - claimName: log-pvc - readOnly: false + hostPath: + path: /var/lib/docker/log/349553515466-preprod/default-group/all #开发环境 affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: diff --git a/deployment-uat.yaml b/deployment-uat.yaml index 3d2e32d..c166313 100644 --- a/deployment-uat.yaml +++ b/deployment-uat.yaml @@ -38,9 +38,8 @@ spec: # 挂载日志存储 volumes: - name: log - persistentVolumeClaim: - claimName: log-pvc - readOnly: false + hostPath: + path: /var/lib/docker/log/349553515466-uat/default-group/all #开发环境 # 必选,Pod中容器列表 containers: