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 20761e3..3f300f2 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 @@ -123,16 +123,16 @@ public class TimeServiceConstant { String timestamp = this.signTimeStamp(data); TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp); Date date = verifyResult.getSignedTime(); - return verifyResult.getSignedTime(); + return date; }catch (Exception e){ log.error("获取时间戳异常", e); } return null; } /** - * 直接获取获取时间戳 时间1 + * 获取年月日时分秒分割存储对象 * @param data 待申请时间戳的原文 - * @return date时间 + * @return SystemTime */ public SystemTime getServiceSystemTime(String data){ try{ @@ -140,7 +140,7 @@ public class TimeServiceConstant { TSAVerifyResult verifyResult = this.verifyTimeStamp(timestamp); Date date = verifyResult.getSignedTime(); SystemTime systemTime = new SystemTime() - .setYear(date.getYear()) + .setYear(date.getYear()+1900) .setMonth(date.getMonth()+1) .setDate(date.getDate()) .setHour(date.getHours()) @@ -155,7 +155,11 @@ public class TimeServiceConstant { public static void main(String arge[]){ Date date = new Date(); - System.out.println("-----------"+date.getYear()); - System.out.println("-----------"+date.getMonth()); + 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()); } } 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 5c3b55f..a221903 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 @@ -3,11 +3,18 @@ package com.chinaunicom.mall.ebtp.extend.timeService.controller; import cn.com.jit.tsa.client.TSAVerifyResult; import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; 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.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + @RestController @Api(tags = "") @@ -20,7 +27,7 @@ public class TimeServiceController { * @return 时间戳加密原文 */ @GetMapping(value = "/signTimeStamp") - public BaseResponse signTimeStamp(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data") String data) { + public BaseResponse signTimeStamp(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data",required = false) String data) { TimeServiceConstant constant = new TimeServiceConstant(); return BaseResponse.success(constant.signTimeStamp(data)); } @@ -42,7 +49,7 @@ public class TimeServiceController { * @return 时间戳对象 */ @PostMapping(value = "/getServiceTimeObj") - public BaseResponse getServiceTimeObj(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data") String data) { + public BaseResponse getServiceTimeObj(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data",required = false) String data) { TimeServiceConstant constant = new TimeServiceConstant(); return BaseResponse.success(constant.getServiceTimeObj(data)); } @@ -52,8 +59,49 @@ public class TimeServiceController { * @return 时间戳对象 */ @GetMapping(value = "/getServiceTime") - public BaseResponse getServiceTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data") String data) { + public BaseResponse getServiceTime(@ApiParam(value = "待申请时间戳的原文", required = false) @RequestParam(name = "data",required = false) String data) { TimeServiceConstant constant = new TimeServiceConstant(); return BaseResponse.success(constant.getServiceTime(data)); } + /** + * 获取年月日时分秒分割存储对象 + * @param data 待申请时间戳的原文 + * @return 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)); + } + /** + * 获取开标剩余时间倒数 + * @return + */ + @ApiOperation("获取开标剩余时间倒数") + @GetMapping("/getDescOpenRoomTime") + @PreAuthorize("hasAnyAuthority('ebtp-agency-project-manager','ebtp-purchase','ebtp-supplier')") + 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(); + + Date now = constant.getServiceDate("getDescOpenRoomTime");;//当前时间 + Date date = df.parse(openTime);//过去 + long l = date.getTime()-now.getTime(); + long day = l / (24 * 60 * 60 * 1000); + long hour = (l / (60 * 60 * 1000) - day * 24); + long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60); + long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60); + + SystemTime systemTime = new SystemTime() + .setDate((int) day) + .setHour((int) hour) + .setMinute((int)min) + .setSecond((int)s); + return BaseResponse.success(systemTime); + } catch (ParseException e) { + e.printStackTrace(); + } + return BaseResponse.success(new SystemTime()); + } }