From f2e30333202fee12711eef48eccf7e08a811a607 Mon Sep 17 00:00:00 2001 From: liyj <1003249715@qq.com> Date: Mon, 02 Sep 2024 16:33:26 +0800 Subject: [PATCH] 1、新增sys服务获取id模块 --- dyh-service/dyh-utils/src/main/java/cn/huge/module/sys/controller/client/SysUtilsController.java | 45 +++++++++++++++ dyh-service/dyh-utils/src/main/java/cn/huge/module/sys/utils/SysIdUtils.java | 103 ++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 0 deletions(-) diff --git a/dyh-service/dyh-utils/src/main/java/cn/huge/module/sys/controller/client/SysUtilsController.java b/dyh-service/dyh-utils/src/main/java/cn/huge/module/sys/controller/client/SysUtilsController.java new file mode 100644 index 0000000..a4a2665 --- /dev/null +++ b/dyh-service/dyh-utils/src/main/java/cn/huge/module/sys/controller/client/SysUtilsController.java @@ -0,0 +1,45 @@ +package cn.huge.module.sys.controller.client; + +import cn.huge.base.common.utils.ReturnFailUtils; +import cn.huge.base.common.utils.ReturnSucUtils; +import cn.huge.module.sys.utils.SysIdUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +/** + * @title: 公共参数-id工具接口api-sys服务专用 + * @description: 公共参数-id工具接口api-sys服务专用 + * @company: hugeinfo + * @author: liyj + * @time: 2022-04-29 10:12:39 + * @version: 1.0.0 + */ +@Slf4j +@RestController +@RequestMapping("/api/client/sysUtils") +public class SysUtilsController { + + @Autowired(required = false) + private HttpServletRequest request; + + + /** + * 公共id-获取时间Id,后四位常量 + * @url {ctx}/api/client/sysUtils/getNewTimeId + * @return Object + */ + @GetMapping("/getNewTimeId") + public Object getNewTimeId() { + try { + return ReturnSucUtils.getRepInfo(SysIdUtils.getNewTimeId()); + } catch (Exception e) { + return ReturnFailUtils.getRepInfo(); + } + } + +} diff --git a/dyh-service/dyh-utils/src/main/java/cn/huge/module/sys/utils/SysIdUtils.java b/dyh-service/dyh-utils/src/main/java/cn/huge/module/sys/utils/SysIdUtils.java new file mode 100644 index 0000000..0ca28cc --- /dev/null +++ b/dyh-service/dyh-utils/src/main/java/cn/huge/module/sys/utils/SysIdUtils.java @@ -0,0 +1,103 @@ +package cn.huge.module.sys.utils; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @title: 公共ID生成工具 + * @description: 公共ID生成工具 + * @company: hugeinfo + * @author: liyj + * @time: 2021-11-05 16:51:48 + * @version: 1.0.0 + */ +public class SysIdUtils { + + /** + * 时间Id统计常量 + */ + private static int COUNT_NUM = 10000; + + /** + * 时间Id统计常量,常量前缀 + */ + private static int SIGN_COUNT_NUM = 10000; + + /** + * 时间Id统计常量,常量后缀 + */ + private static int COUNT_NUM_SIGN = 10000; + + /** + * 获取时间Id,后四位常量 + * @return String + */ + public synchronized static String getNewTimeId(){ + String timeId = getNowTime() + (COUNT_NUM++); + if(COUNT_NUM > 99999){ + COUNT_NUM = 10000; + } + timeId=timeId.substring(2, timeId.length()); + return timeId; + } + + /** + * 获取时间Id,常量前缀 + * @param sign 常量前缀 + * @return String + */ + public synchronized static String getSignNewTimeId(String sign){ + String timeId = getNowTime() + sign + (SIGN_COUNT_NUM++); + if(SIGN_COUNT_NUM > 99999){ + SIGN_COUNT_NUM = 10000; + } + timeId=timeId.substring(2, timeId.length()); + return timeId; + } + + /** + * 获取带有后缀的时间Id,常量后缀 + * @param sign 常量后缀 + * @return String + */ + public synchronized static String getNewTimeIdSign(String sign){ + String timeId = getNowTime() + (COUNT_NUM_SIGN++) + sign; + if(COUNT_NUM_SIGN > 99999){ + COUNT_NUM_SIGN = 10000; + } + timeId=timeId.substring(2, timeId.length()); + return timeId; + } + + /** + * 获取时间Id,后四位常量 + * @return String + */ + public synchronized static String getNowTime(){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String nowTime = sdf.format(new Date()); + return nowTime; + } +} +/** + * -------------------_ooOoo_------------------- + * ------------------o8888888o------------------ + * ------------------88" . "88------------------ + * ------------------(| -_- |)------------------ + * ------------------O\ = /O------------------ + * ---------------____/`---'\____--------------- + * -------------.' \\| |// `.------------- + * ------------/ \\||| : |||// \------------ + * -----------/ _||||| -:- |||||- \----------- + * -----------| | \\\ - /// | |----------- + * -----------| \_| ''\---/'' | |----------- + * -----------\ .-\__ `-` ___/-. /----------- + * ---------___`. .' /--.--\ `. . __---------- + * ------."" '< `.___\_<|>_/___.' >'"".------- + * -----| | : `- \`.;`\ _ /`;.`/ - ` : | |----- + * -----\ \ `-. \_ __\ /__ _/ .-` / /----- + * ======`-.____`-.___\_____/___.-`____.-'====== + * -------------------`=---=' + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ---------佛祖保佑---hugeinfo---永无BUG---------- + */ \ No newline at end of file -- Gitblit v1.8.0