diff --git a/src/main/java/com/glxp/api/controller/trace/UdiTraceController.java b/src/main/java/com/glxp/api/controller/trace/UdiTraceController.java index 63afcb8..b62904f 100644 --- a/src/main/java/com/glxp/api/controller/trace/UdiTraceController.java +++ b/src/main/java/com/glxp/api/controller/trace/UdiTraceController.java @@ -1,5 +1,6 @@ package com.glxp.api.controller.trace; +import cn.hutool.core.util.IdUtil; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; @@ -7,9 +8,15 @@ import com.glxp.api.constant.Constant; import com.glxp.api.controller.BaseController; import com.glxp.api.entity.basic.UdiEntity; import com.glxp.api.entity.sup.UserCompanyEntity; +import com.glxp.api.entity.trace.TraceProductDetailEntity; +import com.glxp.api.entity.trace.TraceRecordLogEntity; +import com.glxp.api.entity.trace.TraceTaskNoticeEntity; import com.glxp.api.req.trace.TraceRecordRequest; +import com.glxp.api.res.basic.BasicUdiRelResponse; import com.glxp.api.service.basic.BasicUdiRelService; +import com.glxp.api.service.trace.TraceProductDetailService; import com.glxp.api.service.trace.TraceRecordService; +import com.glxp.api.util.GennerOrderUtils; import com.glxp.api.util.udi.FilterUdiUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; @@ -17,6 +24,8 @@ import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; import javax.annotation.Resource; +import java.util.Date; +import java.util.List; @ApiIgnore @RestController @@ -27,7 +36,11 @@ public class UdiTraceController extends BaseController { @Resource TraceRecordService traceRecordService; @Resource + TraceProductDetailService traceProductDetailService; + @Resource BasicUdiRelService basicUdiRelService; + @Resource + GennerOrderUtils gennerOrderUtils; /** * 源头追溯查询 @@ -54,6 +67,45 @@ public class UdiTraceController extends BaseController { return ResultVOUtils.error(500, "生产企业未关联该产品信息!"); } + //3.查询产品信息 + BasicUdiRelResponse basicUdiRelResponse = basicUdiRelService.findByProductNameCode(traceRecordRequest.getNameCode()); + if (basicUdiRelResponse == null) { + return ResultVOUtils.error(500, "未查询到产品信息"); + } + + //4.生成查询记录 + String userId = getUserId() + ""; + TraceRecordLogEntity traceRecordLogEntity = new TraceRecordLogEntity(); + traceRecordLogEntity.setId(IdUtil.getSnowflakeNextId()); + traceRecordLogEntity.setRecordCode(gennerOrderUtils.getRecordNo()); + traceRecordLogEntity.setCreateTime(new Date()); + traceRecordLogEntity.setUpdateTime(new Date()); + traceRecordLogEntity.setStatus(1); + traceRecordLogEntity.setCreateUser(userId); + traceRecordLogEntity.setFromType(traceRecordRequest.getFromType()); + traceRecordLogEntity.setTraceType(traceRecordRequest.getTraceType()); + + + //4.创建查询详情记录,若存在相同查询记录则直接获取 + if (traceRecordRequest.getTraceType() == 1) {//按UDI码查询 + TraceProductDetailEntity traceProductDetailEntity = traceProductDetailService.findUniqueByCode(1, traceRecordRequest.getUdiCode()); + if (traceProductDetailEntity == null) { + + } + + } else { //按批次号查询 + + } + + + //5.创建查询任务表 + TraceTaskNoticeEntity traceTaskNoticeEntity = new TraceTaskNoticeEntity(); + traceTaskNoticeEntity.setId(IdUtil.getSnowflakeNextId()); + traceTaskNoticeEntity.setCreateTime(new Date()); + List diList = basicUdiRelService.getBaseMapper().findDiList(basicUdiRelResponse.getUuid()); + traceTaskNoticeEntity.setDiList(diList); + traceTaskNoticeEntity.setTaskType(1); + traceTaskNoticeEntity.setStatus(1); } else if (traceRecordRequest.getTraceType() == Constant.UDI_BATCHNO) { diff --git a/src/main/java/com/glxp/api/dao/basic/BasicUdiRelMapper.java b/src/main/java/com/glxp/api/dao/basic/BasicUdiRelMapper.java index 56824ee..ccab3d1 100644 --- a/src/main/java/com/glxp/api/dao/basic/BasicUdiRelMapper.java +++ b/src/main/java/com/glxp/api/dao/basic/BasicUdiRelMapper.java @@ -18,4 +18,6 @@ public interface BasicUdiRelMapper extends BaseMapper { UserCompanyEntity findByNameCode(@Param("nameCode") String nameCode); + + List findDiList(@Param("nameCode") String uuid); } diff --git a/src/main/java/com/glxp/api/dao/trace/TraceRecordDetailMapper.java b/src/main/java/com/glxp/api/dao/trace/TraceRecordDetailMapper.java index 67fc507..9fe484e 100644 --- a/src/main/java/com/glxp/api/dao/trace/TraceRecordDetailMapper.java +++ b/src/main/java/com/glxp/api/dao/trace/TraceRecordDetailMapper.java @@ -1,9 +1,9 @@ package com.glxp.api.dao.trace; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.glxp.api.entity.trace.TraceRecordDetailEntity; +import com.glxp.api.entity.trace.TraceProductDetailEntity; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface TraceRecordDetailMapper extends BaseMapper { +public interface TraceRecordDetailMapper extends BaseMapper { } diff --git a/src/main/java/com/glxp/api/dao/trace/TraceRecordMapper.java b/src/main/java/com/glxp/api/dao/trace/TraceRecordMapper.java index 211d823..6fcdfe1 100644 --- a/src/main/java/com/glxp/api/dao/trace/TraceRecordMapper.java +++ b/src/main/java/com/glxp/api/dao/trace/TraceRecordMapper.java @@ -1,7 +1,7 @@ package com.glxp.api.dao.trace; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.glxp.api.entity.trace.TraceRecordEntity; +import com.glxp.api.entity.trace.TraceRecordLogEntity; import com.glxp.api.req.trace.TraceRecordRequest; import com.glxp.api.res.trace.TraceRecordResponse; import org.apache.ibatis.annotations.Mapper; @@ -9,7 +9,7 @@ import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper -public interface TraceRecordMapper extends BaseMapper { +public interface TraceRecordMapper extends BaseMapper { List filterTraces(TraceRecordRequest traceRecordRequest); diff --git a/src/main/java/com/glxp/api/entity/trace/TraceRecordDetailEntity.java b/src/main/java/com/glxp/api/entity/trace/TraceProductDetailEntity.java similarity index 77% rename from src/main/java/com/glxp/api/entity/trace/TraceRecordDetailEntity.java rename to src/main/java/com/glxp/api/entity/trace/TraceProductDetailEntity.java index f8f0cdb..a9ddb4b 100644 --- a/src/main/java/com/glxp/api/entity/trace/TraceRecordDetailEntity.java +++ b/src/main/java/com/glxp/api/entity/trace/TraceProductDetailEntity.java @@ -4,27 +4,28 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; + import java.io.Serializable; + import lombok.Data; /** - * 查询记录子表 - */ + * 查询记录详情表,每次查询都会来查询该表 + */ @Data @TableName(value = "trace_record_detail") -public class TraceRecordDetailEntity implements Serializable { +public class TraceProductDetailEntity implements Serializable { @TableId(value = "id", type = IdType.INPUT) private Long id; /** - * 查询记录主表ID外键 - + * 查询方式(1:源头查询;2:现在检查查询) */ - @TableField(value = "recordIdFk") - private String recordIdFk; + @TableField(value = "traceSource") + private Integer traceSource; /** - * 查询方案(按UDI码查询/按批次号查询) + * 查询方案(1:按UDI码查询;2:按批次号查询) */ @TableField(value = "traceType") private Integer traceType; @@ -89,5 +90,12 @@ public class TraceRecordDetailEntity implements Serializable { @TableField(value = "serialNo") private String serialNo; + + /** + * 查询状态 1:未处理;2.未完结;3.已完成 + */ + @TableField(value = "status") + private Integer status; + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/glxp/api/entity/trace/TraceRecordEntity.java b/src/main/java/com/glxp/api/entity/trace/TraceRecordLogEntity.java similarity index 70% rename from src/main/java/com/glxp/api/entity/trace/TraceRecordEntity.java rename to src/main/java/com/glxp/api/entity/trace/TraceRecordLogEntity.java index 010af79..6223408 100644 --- a/src/main/java/com/glxp/api/entity/trace/TraceRecordEntity.java +++ b/src/main/java/com/glxp/api/entity/trace/TraceRecordLogEntity.java @@ -4,21 +4,24 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; + import java.io.Serializable; import java.util.Date; + import lombok.Data; /** - * 查询记录表 - */ + * 查询记录表 + */ @Data -@TableName(value = "trace_record") -public class TraceRecordEntity implements Serializable { +@TableName(value = "trace_record_log") +public class TraceRecordLogEntity implements Serializable { + @TableId(value = "id", type = IdType.INPUT) private Long id; /** - * 查询记录号 + * 查询记录流水号 */ @TableField(value = "recordCode") private String recordCode; @@ -53,5 +56,18 @@ public class TraceRecordEntity implements Serializable { @TableField(value = "remark") private String remark; + /** + * 查询状态 1:未处理;2.未完结;3.已完成 + */ + @TableField(value = "status") + private Integer status; + + /** + * 查询方案(1:按UDI码查询; 2:按批次号查询) + */ + @TableField(value = "traceType") + private Integer traceType; + + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/glxp/api/entity/trace/TraceTaskNoticeEntity.java b/src/main/java/com/glxp/api/entity/trace/TraceTaskNoticeEntity.java index 0dc7505..a28db79 100644 --- a/src/main/java/com/glxp/api/entity/trace/TraceTaskNoticeEntity.java +++ b/src/main/java/com/glxp/api/entity/trace/TraceTaskNoticeEntity.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; import java.util.Date; +import java.util.List; import lombok.Data; @@ -29,14 +30,13 @@ public class TraceTaskNoticeEntity implements Serializable { * 任务类型1:关联关系;2:入库;3:出库 */ @TableField(value = "taskType") - private Byte taskType; + private Integer taskType; /** - * 任务状态(未处理/正在处理(任务被下载)/ - * 已处理(任务已提交) + * 任务状态(1.未处理;2正在处理(任务被下载)3:已处理(任务已提交);4:超时处理失败 */ @TableField(value = "`status`") - private Byte status; + private Integer status; /** * 企业信息ID外键 @@ -103,6 +103,9 @@ public class TraceTaskNoticeEntity implements Serializable { @TableField(value = "updateTime") private Date updateTime; + @TableField(value = "diList") + private List diList; + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/glxp/api/res/trace/TraceManuOrderResponse.java b/src/main/java/com/glxp/api/res/trace/TraceManuOrderResponse.java index fd2acb1..dea1168 100644 --- a/src/main/java/com/glxp/api/res/trace/TraceManuOrderResponse.java +++ b/src/main/java/com/glxp/api/res/trace/TraceManuOrderResponse.java @@ -84,7 +84,7 @@ public class TraceManuOrderResponse { private String companyName; /** - * 查询记录号 + * 查询记录详情号 */ private String recordCode; diff --git a/src/main/java/com/glxp/api/res/trace/TraceTaskDlResponse.java b/src/main/java/com/glxp/api/res/trace/TraceTaskDlResponse.java index af6fa8e..9b86d30 100644 --- a/src/main/java/com/glxp/api/res/trace/TraceTaskDlResponse.java +++ b/src/main/java/com/glxp/api/res/trace/TraceTaskDlResponse.java @@ -1,9 +1,5 @@ package com.glxp.api.res.trace; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import io.swagger.models.auth.In; import lombok.Data; import java.util.Date; diff --git a/src/main/java/com/glxp/api/service/basic/BasicUdiRelService.java b/src/main/java/com/glxp/api/service/basic/BasicUdiRelService.java index 9c3ee7d..c8c3466 100644 --- a/src/main/java/com/glxp/api/service/basic/BasicUdiRelService.java +++ b/src/main/java/com/glxp/api/service/basic/BasicUdiRelService.java @@ -1,5 +1,7 @@ package com.glxp.api.service.basic; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; import com.glxp.api.entity.sup.UserCompanyEntity; @@ -35,4 +37,15 @@ public class BasicUdiRelService extends ServiceImpl udiRelResponses = basicUdiRelMapper.filterList(filterUdiRelRequest); + if (CollUtil.isNotEmpty(udiRelResponses)) + return udiRelResponses.get(0); + return null; + } + } diff --git a/src/main/java/com/glxp/api/service/trace/RabbitPushService.java b/src/main/java/com/glxp/api/service/trace/RabbitPushService.java new file mode 100644 index 0000000..1eec54d --- /dev/null +++ b/src/main/java/com/glxp/api/service/trace/RabbitPushService.java @@ -0,0 +1,40 @@ +package com.glxp.api.service.trace; + +import cn.hutool.core.lang.UUID; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; +import com.glxp.api.config.rabbit.TopicRabbitConfig; +import com.glxp.api.entity.trace.MqTraceMessage; +import com.glxp.api.util.DateUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.GetMapping; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@Service +@RequiredArgsConstructor +public class RabbitPushService { + + @Resource + private final RabbitTemplate rabbitTemplate; + + public BaseResponse send(MqTraceMessage mqTraceMessage) { + rabbitTemplate.convertAndSend("topicExchange", TopicRabbitConfig.trace, mqTraceMessage); + return ResultVOUtils.success("发送成功"); + } + + public BaseResponse sendCommon(String key) { + String messageId = String.valueOf(UUID.randomUUID()); + Map messageMap = new HashMap<>(); + messageMap.put("messageId", messageId); + messageMap.put("messageData", key); + messageMap.put("createTime", DateUtil.formatDate(new Date())); + rabbitTemplate.convertAndSend("topicExchange", TopicRabbitConfig.common, messageMap); + return ResultVOUtils.success("发送成功"); + } +} diff --git a/src/main/java/com/glxp/api/service/trace/TraceProductDetailService.java b/src/main/java/com/glxp/api/service/trace/TraceProductDetailService.java new file mode 100644 index 0000000..171bce4 --- /dev/null +++ b/src/main/java/com/glxp/api/service/trace/TraceProductDetailService.java @@ -0,0 +1,42 @@ +package com.glxp.api.service.trace; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.glxp.api.dao.trace.TraceRecordDetailMapper; +import com.glxp.api.entity.trace.TraceProductDetailEntity; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class TraceProductDetailService extends ServiceImpl { + + @Resource + TraceRecordDetailMapper traceRecordDetailMapper; + + public TraceProductDetailEntity findUniqueByCode(Integer traceType, String udiCode) { + List traceRecordDetailEntities = traceRecordDetailMapper.selectList(new QueryWrapper() + .eq("traceType", traceType) + .eq("udiCode", udiCode).last("limit 1")); + if (CollUtil.isNotEmpty(traceRecordDetailEntities)) + return traceRecordDetailEntities.get(0); + else return null; + } + + public TraceProductDetailEntity findUniqueByData(Integer traceType, String ylqxzcrbarmc, String cpmctymc, String ggxh, String nameCode, String batchNo) { + List traceRecordDetailEntities = traceRecordDetailMapper.selectList(new QueryWrapper() + .eq("traceType", traceType) + .eq("ylqxzcrbarmc", ylqxzcrbarmc) + .eq("cpmctymc", cpmctymc) + .eq("ggxh", ggxh) + .eq("nameCode", nameCode) + .eq("batchNo", batchNo) + .last("limit 1")); + if (CollUtil.isNotEmpty(traceRecordDetailEntities)) + return traceRecordDetailEntities.get(0); + else return null; + } + +} diff --git a/src/main/java/com/glxp/api/service/trace/TraceRecordDetailService.java b/src/main/java/com/glxp/api/service/trace/TraceRecordDetailService.java deleted file mode 100644 index 81e3254..0000000 --- a/src/main/java/com/glxp/api/service/trace/TraceRecordDetailService.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.glxp.api.service.trace; - -import com.glxp.api.entity.trace.TraceRecordDetailEntity; -import com.baomidou.mybatisplus.extension.service.IService; -public interface TraceRecordDetailService extends IService{ - - -} diff --git a/src/main/java/com/glxp/api/service/trace/TraceRecordService.java b/src/main/java/com/glxp/api/service/trace/TraceRecordService.java index c47c9f9..3178dbd 100644 --- a/src/main/java/com/glxp/api/service/trace/TraceRecordService.java +++ b/src/main/java/com/glxp/api/service/trace/TraceRecordService.java @@ -1,13 +1,35 @@ package com.glxp.api.service.trace; -import com.glxp.api.entity.trace.TraceRecordEntity; -import com.baomidou.mybatisplus.extension.service.IService; +import com.github.pagehelper.PageHelper; import com.glxp.api.req.trace.TraceRecordRequest; import com.glxp.api.res.trace.TraceRecordResponse; +import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.glxp.api.dao.trace.TraceRecordMapper; +import com.glxp.api.entity.trace.TraceRecordLogEntity; +import javax.annotation.Resource; +import java.util.Collections; import java.util.List; -public interface TraceRecordService extends IService { +@Service +public class TraceRecordService extends ServiceImpl { + + + @Resource + TraceRecordMapper traceRecordMapper; + + public List filterTraces(TraceRecordRequest traceRecordRequest) { + if (traceRecordRequest == null) { + return Collections.emptyList(); + } + if (traceRecordRequest.getPage() != null) { + int offset = (traceRecordRequest.getPage() - 1) * traceRecordRequest.getLimit(); + PageHelper.offsetPage(offset, traceRecordRequest.getLimit()); + } + return traceRecordMapper.filterTraces(traceRecordRequest); + } + + - List filterTraces(TraceRecordRequest traceRecordRequest); } diff --git a/src/main/java/com/glxp/api/service/trace/impl/TraceRecordDetailServiceImpl.java b/src/main/java/com/glxp/api/service/trace/impl/TraceRecordDetailServiceImpl.java deleted file mode 100644 index e90c398..0000000 --- a/src/main/java/com/glxp/api/service/trace/impl/TraceRecordDetailServiceImpl.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.glxp.api.service.trace.impl; - -import com.glxp.api.service.trace.TraceRecordDetailService; -import org.springframework.stereotype.Service; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.glxp.api.dao.trace.TraceRecordDetailMapper; -import com.glxp.api.entity.trace.TraceRecordDetailEntity; - -@Service -public class TraceRecordDetailServiceImpl extends ServiceImpl implements TraceRecordDetailService { - -} diff --git a/src/main/java/com/glxp/api/service/trace/impl/TraceRecordServiceImpl.java b/src/main/java/com/glxp/api/service/trace/impl/TraceRecordServiceImpl.java deleted file mode 100644 index bfe84b2..0000000 --- a/src/main/java/com/glxp/api/service/trace/impl/TraceRecordServiceImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.glxp.api.service.trace.impl; - -import com.github.pagehelper.PageHelper; -import com.glxp.api.req.trace.TraceRecordRequest; -import com.glxp.api.res.trace.TraceRecordResponse; -import com.glxp.api.service.trace.TraceRecordService; -import org.springframework.stereotype.Service; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.glxp.api.dao.trace.TraceRecordMapper; -import com.glxp.api.entity.trace.TraceRecordEntity; - -import javax.annotation.Resource; -import java.util.Collections; -import java.util.List; - -@Service -public class TraceRecordServiceImpl extends ServiceImpl implements TraceRecordService { - - - @Resource - TraceRecordMapper traceRecordMapper; - - @Override - public List filterTraces(TraceRecordRequest traceRecordRequest) { - if (traceRecordRequest == null) { - return Collections.emptyList(); - } - if (traceRecordRequest.getPage() != null) { - int offset = (traceRecordRequest.getPage() - 1) * traceRecordRequest.getLimit(); - PageHelper.offsetPage(offset, traceRecordRequest.getLimit()); - } - return traceRecordMapper.filterTraces(traceRecordRequest); - } -} diff --git a/src/main/java/com/glxp/api/util/GennerOrderUtils.java b/src/main/java/com/glxp/api/util/GennerOrderUtils.java index b2f884b..85f9504 100644 --- a/src/main/java/com/glxp/api/util/GennerOrderUtils.java +++ b/src/main/java/com/glxp/api/util/GennerOrderUtils.java @@ -110,6 +110,16 @@ public class GennerOrderUtils { return sb.toString(); } + /** + * 获取查询记录流水号 + * + * @return + */ + public String getRecordNo() { + String orderNo = createRecordOrderNo(new OrderNoTypeBean("T", "yyyyMMdd")); + return orderNo; + } + /** * @param orderNoTypeEnum: * @Description 基于redis生成单号(时间格式 + 自增数) @@ -118,7 +128,7 @@ public class GennerOrderUtils { * @time: 14:15 * @return: java.lang.String **/ - public String createScOrderNo(OrderNoTypeBean orderNoTypeEnum) { + public String createRecordOrderNo(OrderNoTypeBean orderNoTypeEnum) { //获得单号前缀 //格式 固定前缀 +时间前缀 示例 String formNoPrefix = getFormNoPrefix(orderNoTypeEnum); @@ -137,44 +147,6 @@ public class GennerOrderUtils { return completionRandom(serialWithPrefix, orderNoTypeEnum); } - public String createStOrderNo(OrderNoTypeBean orderNoTypeEnum) { - //获得单号前缀 - //格式 固定前缀 +时间前缀 示例 - String formNoPrefix = getFormNoPrefix(orderNoTypeEnum); - //获得缓存key - String cacheKey = getStCacheKey(formNoPrefix); - //获得当日自增数 - Long incrementalSerial = redisUtil.incr(cacheKey, 1); - // 设置key过期时间, 保证每天的流水号从1开始 - if (incrementalSerial == 1) { - //设置失效时间 凌晨过期 - redisUtil.expire(cacheKey, getSecondsNextEarlyMorning()); - } - //组合单号并补全流水号 - String serialWithPrefix = completionSerial(formNoPrefix, incrementalSerial, orderNoTypeEnum); - //补全随机数 - return completionRandom(serialWithPrefix, orderNoTypeEnum); - } - - public String createPurOrderNo(OrderNoTypeBean orderNoTypeEnum) { - //获得单号前缀 - //格式 固定前缀 +时间前缀 示例 - String formNoPrefix = getFormNoPrefix(orderNoTypeEnum); - //获得缓存key - String cacheKey = getStCacheKey(formNoPrefix); - //获得当日自增数 - Long incrementalSerial = redisUtil.incr(cacheKey, 1); - // 设置key过期时间, 保证每天的流水号从1开始 - if (incrementalSerial == 1) { - //设置失效时间 凌晨过期 - redisUtil.expire(cacheKey, getSecondsNextEarlyMorning()); - } - //组合单号并补全流水号 - String serialWithPrefix = completionSerial(formNoPrefix, incrementalSerial, orderNoTypeEnum); - //补全随机数 - return completionRandom(serialWithPrefix, orderNoTypeEnum); - } - private Long getSecondsNextEarlyMorning() { Calendar cal = Calendar.getInstance(); diff --git a/src/main/resources/mybatis/mapper/basic/BasicUdiRelMapper.xml b/src/main/resources/mybatis/mapper/basic/BasicUdiRelMapper.xml index 69d4b7f..11a8b76 100644 --- a/src/main/resources/mybatis/mapper/basic/BasicUdiRelMapper.xml +++ b/src/main/resources/mybatis/mapper/basic/BasicUdiRelMapper.xml @@ -4,55 +4,55 @@ + +