diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplateno/CustomPlateNoGenerateServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplateno/CustomPlateNoGenerateServiceImpl.java index 10b63186f..0b8f76fc3 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplateno/CustomPlateNoGenerateServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplateno/CustomPlateNoGenerateServiceImpl.java @@ -60,7 +60,9 @@ public class CustomPlateNoGenerateServiceImpl implements CustomPlateNoGenerateSe CustomPlateNoGenerateConfigVO generateConfig = getGenerateConfig(orderId); // 如果没有查到配置规则就不做后续生成操作了 List orgCustomPlateNoRuleVOList = generateConfig.getOrgCustomPlateNoRuleVOList(); - if (CollUtil.isEmpty(orgCustomPlateNoRuleVOList)) { + // 如果没有查到机构下配置就不做后续生成操作了 + Long orgCustomPlateNoConfigId = generateConfig.getOrgCustomPlateNoConfigId(); + if (ObjectUtil.isNull(orgCustomPlateNoConfigId) || CollUtil.isEmpty(orgCustomPlateNoRuleVOList)) { return; } @@ -69,12 +71,15 @@ public class CustomPlateNoGenerateServiceImpl implements CustomPlateNoGenerateSe orgCustomPlateNoRuleVOList.forEach(rule -> rule.setNow(now)); // 2、遍历小板列表,生成板编号 - for (PlateDO plateDO : plateDOList) { - loopGenerateNo(orderId, plateDO, orgCustomPlateNoRuleVOList, generateConfig); + for (int i = 0; i < plateDOList.size(); i++) { + PlateDO plateDO = plateDOList.get(i); + loopGenerateNo(orderId, plateDO, orgCustomPlateNoRuleVOList, generateConfig, i == 0); } - // 3、保存生产单序号json + // 3、保存生产单序号json、设置生产单所用配置id orderDO.setCustomPlatenoSeq(JSON.toJSONString(generateConfig.getOrderCustomPlateNoSeqVO())); + orderDO.setCustomPlatenoConfigId(orgCustomPlateNoConfigId); + // 机构下序号配置同步 CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO(); orgCustomPlateNoSeqRespDTO.setLastOrderNo(orderId); orgCustomPlateNoSeqRespDTO.setLastYear(Integer.parseInt(YEAR_FORMATTER.format(now))); @@ -94,8 +99,9 @@ public class CustomPlateNoGenerateServiceImpl implements CustomPlateNoGenerateSe * @param plateDO * @param orgCustomPlateNoRuleVOList * @param generateConfig + * @param */ - private void loopGenerateNo(Long orderId, PlateDO plateDO, List orgCustomPlateNoRuleVOList, CustomPlateNoGenerateConfigVO generateConfig) { + private void loopGenerateNo(Long orderId, PlateDO plateDO, List orgCustomPlateNoRuleVOList, CustomPlateNoGenerateConfigVO generateConfig, boolean firstPlate) { // 遍历规则列表 for (CustomPlateNoRuleVO plateNoRule : orgCustomPlateNoRuleVOList) { if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.CUSTOM.getRuleCode(), plateNoRule.getRuleCode())) { @@ -107,7 +113,7 @@ public class CustomPlateNoGenerateServiceImpl implements CustomPlateNoGenerateSe // 遍历规则生成服务列表,获取对应的规则服务 for (CustomPlateNoGenerateRuleService ruleService : ruleServices) { if (ruleService.match(plateNoRule.getRuleCode())) { - generateConfig = ruleService.generateNo(orderId, plateNoRule, generateConfig, plateDO); + generateConfig = ruleService.generateNo(orderId, plateNoRule, generateConfig, plateDO, firstPlate); break; } } @@ -115,6 +121,14 @@ public class CustomPlateNoGenerateServiceImpl implements CustomPlateNoGenerateSe plateDO.setPlateNo(plateDO.getCustomPlateNo().toString()); } + /** + * 根据生产单id获取生成需要的配置 + * + * @param orderId + * @return 1、生产单下的序号 + * 2、机构下的序号 + * 3、机构下全局配置的规则 + */ private CustomPlateNoGenerateConfigVO getGenerateConfig(Long orderId) { // 生成自定义版编号所需配置 CustomPlateNoGenerateConfigVO customPlateNoGenerateConfigVO = new CustomPlateNoGenerateConfigVO(); @@ -132,6 +146,7 @@ public class CustomPlateNoGenerateServiceImpl implements CustomPlateNoGenerateSe customPlateNoRuleVOS = Optional.ofNullable(orgCustomPlateNoConfig) .map(config -> JSON.parseArray(config.getSetting(), CustomPlateNoRuleVO.class)) .orElse(List.of()); + customPlateNoGenerateConfigVO.setOrgCustomPlateNoConfigId(orgCustomPlateNoConfig.getId()); } OrderDO order = orderService.getOrder(orderId); diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplateno/vo/CustomPlateNoGenerateConfigVO.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplateno/vo/CustomPlateNoGenerateConfigVO.java index 411687dc9..4513aed43 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplateno/vo/CustomPlateNoGenerateConfigVO.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplateno/vo/CustomPlateNoGenerateConfigVO.java @@ -24,6 +24,11 @@ public class CustomPlateNoGenerateConfigVO implements Serializable { */ private List orgCustomPlateNoRuleVOList; + /** + * 机构下自定义板编号-系统配置id + */ + private Long orgCustomPlateNoConfigId; + /** * 机构下的自定义板编号序号 */ diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/BodyNoGenerateRuleServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/BodyNoGenerateRuleServiceImpl.java index 65aed1fe1..34add4c97 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/BodyNoGenerateRuleServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/BodyNoGenerateRuleServiceImpl.java @@ -33,22 +33,6 @@ public class BodyNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.BODYNO.getRuleCode(), ruleCode); } - @Override - public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) { - // 初始化配置 - initConfig(generateConfig); - // 按复位模式走不同的生成方式 - ResetModeEnum resetModeEnum = ResetModeEnum.getByMode(plateNoRule.getResetMode()); - if (ObjectUtil.equal(ResetModeEnum.ORDER, resetModeEnum)) { - generateConfig = generateNoByOrderResetMode(orderId, plateNoRule, generateConfig, plateDO); - } else if (ObjectUtil.equal(ResetModeEnum.ROOM, resetModeEnum)) { - generateConfig = generateNoByRoomResetMode(plateNoRule, generateConfig, plateDO); - } else { - throw ServiceExceptionUtil.exception(CUSTOM_PLATENO_GENERATE_BODY_RULE_NOT_SUPPORT_RESETMODE, plateNoRule.getResetMode()); - } - return generateConfig; - } - /** * 初始化生成所需配置 * @@ -72,6 +56,22 @@ public class BodyNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS } } + @Override + public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO, boolean firstPlate) { + // 初始化配置 + initConfig(generateConfig); + // 按复位模式走不同的生成方式 + ResetModeEnum resetModeEnum = ResetModeEnum.getByMode(plateNoRule.getResetMode()); + if (ObjectUtil.equal(ResetModeEnum.ORDER, resetModeEnum)) { + generateConfig = generateNoByOrderResetMode(orderId, plateNoRule, generateConfig, plateDO, firstPlate); + } else if (ObjectUtil.equal(ResetModeEnum.ROOM, resetModeEnum)) { + generateConfig = generateNoByRoomResetMode(plateNoRule, generateConfig, plateDO); + } else { + throw ServiceExceptionUtil.exception(CUSTOM_PLATENO_GENERATE_BODY_RULE_NOT_SUPPORT_RESETMODE, plateNoRule.getResetMode()); + } + return generateConfig; + } + /** * 按生产单复位模式下的板编号生成 * @@ -81,7 +81,7 @@ public class BodyNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS * @param plateDO 板件列表 * @return */ - private CustomPlateNoGenerateConfigVO generateNoByOrderResetMode(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) { + private CustomPlateNoGenerateConfigVO generateNoByOrderResetMode(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO, boolean firstPlate) { Integer incrementStep = plateNoRule.getIncrementStep(); Integer initValue = plateNoRule.getInitValue() - incrementStep; // 生产单下的序号 @@ -94,7 +94,7 @@ public class BodyNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS List bodys = orderCustomPlateNoSeqVO.getBodys(); // 上次导入的生产单号 Long lastOrderNo = orgCustomPlateNoSeqRespDTO.getLastOrderNo(); - if (ObjectUtil.isNotNull(lastOrderNo) && ObjectUtil.notEqual(orderId, lastOrderNo)) { + if (firstPlate && (ObjectUtil.isNull(lastOrderNo) || ObjectUtil.notEqual(orderId, lastOrderNo))) { // 跨单复位到初始值 orderBodyNoSeq = initValue; } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/CustomPlateNoGenerateRuleService.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/CustomPlateNoGenerateRuleService.java index 8c7f4ac38..8747eaaf0 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/CustomPlateNoGenerateRuleService.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/CustomPlateNoGenerateRuleService.java @@ -23,11 +23,13 @@ public interface CustomPlateNoGenerateRuleService { * 生成编号 * * @param orderId 生产单号 - * @param plateDO 板材列表 + * @param plateNoRule 生成规则 * @param generateConfig 生成所需要的配置 + * @param plateDO 板材列表 + * @param firstPlate 是否循环的第一块板,只有第一块板需要做是否跨单判断,后续都是一个单内 * @return 生成后改变的配置 */ - CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO); + CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO, boolean firstPlate); /** * 左补零 diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/OrderNoGenerateRuleServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/OrderNoGenerateRuleServiceImpl.java index fd4bbe703..ed1f60f82 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/OrderNoGenerateRuleServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/OrderNoGenerateRuleServiceImpl.java @@ -11,7 +11,6 @@ import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum; import com.cf.imes.module.system.enums.customplateno.ResetModeEnum; import org.springframework.stereotype.Service; -import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Optional; @@ -49,7 +48,7 @@ public class OrderNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule } @Override - public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) { + public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO, boolean firstPlate) { // 初始化配置 initConfig(generateConfig); // 生产单下的序号 @@ -68,8 +67,7 @@ public class OrderNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule int currOrderNoSeq = Optional.ofNullable(orgCustomPlateNoSeqRespDTO.getOrderNoSeq()).orElse(plateNoRule.getInitValue() - plateNoRule.getIncrementStep()); // 上次导入的生产单号 Long lastOrderNo = orgCustomPlateNoSeqRespDTO.getLastOrderNo(); - if (ObjectUtil.isNull(lastOrderNo) || ObjectUtil.notEqual(orderId, lastOrderNo)) { - // 跨单 + if (firstPlate && (ObjectUtil.isNull(lastOrderNo) || ObjectUtil.notEqual(orderId, lastOrderNo))) { // 根据复位模式计算序号 currOrderNoSeq = generateNoByResetMode(currOrderNoSeq, ResetModeEnum.getByMode(plateNoRule.getResetMode()), plateNoRule, orgCustomPlateNoSeqRespDTO); } @@ -93,20 +91,15 @@ public class OrderNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule * @return 循环累加后的序号 */ private int generateNoByResetMode(int orderNoSeq, ResetModeEnum resetModeEnum, CustomPlateNoRuleVO plateNoRule, CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO) { - // 机构全局序号下的上一次年月日记录 - int year = orgCustomPlateNoSeqRespDTO.getLastYear(); - int month = orgCustomPlateNoSeqRespDTO.getLastMonth(); - int day = orgCustomPlateNoSeqRespDTO.getLastDay(); - // 根据不同复位模式生成序号 if (ObjectUtil.equal(ResetModeEnum.DIGIT, resetModeEnum)) { orderNoSeq = resetByLength(orderNoSeq, plateNoRule); } else if (ObjectUtil.equal(ResetModeEnum.YEAR, resetModeEnum)) { - orderNoSeq = resetByYear(orderNoSeq, year, plateNoRule); + orderNoSeq = resetByYear(orderNoSeq, orgCustomPlateNoSeqRespDTO, plateNoRule); } else if (ObjectUtil.equal(ResetModeEnum.MONTH, resetModeEnum)) { - orderNoSeq = resetByMonth(orderNoSeq, month, plateNoRule); + orderNoSeq = resetByMonth(orderNoSeq, orgCustomPlateNoSeqRespDTO, plateNoRule); } else if (ObjectUtil.equal(ResetModeEnum.DAY, resetModeEnum)) { - orderNoSeq = resetByDay(orderNoSeq, day, plateNoRule); + orderNoSeq = resetByDay(orderNoSeq, orgCustomPlateNoSeqRespDTO, plateNoRule); } else { throw ServiceExceptionUtil.exception(CUSTOM_PLATENO_GENERATE_ORDERNO_RULE_NOT_SUPPORT_RESETMODE, plateNoRule.getResetMode()); } @@ -136,14 +129,19 @@ public class OrderNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule * 按年复位 * * @param curr - * @param year + * @param orgCustomPlateNoSeqRespDTO * @param plateNoRule * @return */ - private int resetByYear(int curr, int year, CustomPlateNoRuleVO plateNoRule) { - LocalDateTime now = plateNoRule.getNow(); + private int resetByYear(int curr, CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO, CustomPlateNoRuleVO plateNoRule) { + // 上一次的年 + Integer lastYear = orgCustomPlateNoSeqRespDTO.getLastYear(); Integer initValue = plateNoRule.getInitValue(); - if (ObjectUtil.notEqual(String.valueOf(year), now.format(YEAR_FORMATTER))) { + String nowYearFormat = plateNoRule.getNow().format(YEAR_FORMATTER); + if (ObjectUtil.notEqual(String.valueOf(lastYear), nowYearFormat)) { + // 跨年,把上一次的年设成当前年,后续不再跨年 + orgCustomPlateNoSeqRespDTO.setLastYear(Integer.parseInt(nowYearFormat)); + // 复位 return initValue; } return curr + plateNoRule.getIncrementStep(); @@ -153,14 +151,19 @@ public class OrderNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule * 按月复位 * * @param curr - * @param month + * @param orgCustomPlateNoSeqRespDTO * @param plateNoRule * @return */ - private int resetByMonth(int curr, int month, CustomPlateNoRuleVO plateNoRule) { - LocalDateTime now = plateNoRule.getNow(); + private int resetByMonth(int curr, CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO, CustomPlateNoRuleVO plateNoRule) { + // 上一次的月 + Integer lastMonth = orgCustomPlateNoSeqRespDTO.getLastMonth(); Integer initValue = plateNoRule.getInitValue(); - if (ObjectUtil.notEqual(String.valueOf(month), now.format(MONTH_FORMATTER))) { + String nowMonthFormat = plateNoRule.getNow().format(MONTH_FORMATTER); + if (ObjectUtil.notEqual(String.valueOf(lastMonth), nowMonthFormat)) { + // 跨月,把上一次的月设成当前月,后续不再跨月 + orgCustomPlateNoSeqRespDTO.setLastMonth(Integer.parseInt(nowMonthFormat)); + // 复位 return initValue; } return curr + plateNoRule.getIncrementStep(); @@ -170,14 +173,19 @@ public class OrderNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule * 按天复位 * * @param curr - * @param day + * @param orgCustomPlateNoSeqRespDTO * @param plateNoRule * @return */ - private int resetByDay(int curr, int day, CustomPlateNoRuleVO plateNoRule) { - LocalDateTime now = plateNoRule.getNow(); + private int resetByDay(int curr, CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO, CustomPlateNoRuleVO plateNoRule) { + // 上一次的天 + Integer lastDay = orgCustomPlateNoSeqRespDTO.getLastDay(); Integer initValue = plateNoRule.getInitValue(); - if (ObjectUtil.notEqual(String.valueOf(day), now.format(DAY_FORMATTER))) { + String nowDayFormat = plateNoRule.getNow().format(DAY_FORMATTER); + if (ObjectUtil.notEqual(String.valueOf(lastDay), nowDayFormat)) { + // 跨月,把上一次的月设成当前月,后续不再跨月 + orgCustomPlateNoSeqRespDTO.setLastDay(Integer.parseInt(nowDayFormat)); + // 复位 return initValue; } return curr + plateNoRule.getIncrementStep(); diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/PlateNoGenerateRuleServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/PlateNoGenerateRuleServiceImpl.java index d3030838f..7a0286c06 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/PlateNoGenerateRuleServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/PlateNoGenerateRuleServiceImpl.java @@ -14,7 +14,6 @@ import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum; import com.cf.imes.module.system.enums.customplateno.ResetModeEnum; import org.springframework.stereotype.Service; -import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -38,14 +37,32 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.PLATENO.getRuleCode(), ruleCode); } + /** + * 初始化生成所需配置 + * + * @param generateConfigVO + */ + private void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) { + OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO(); + if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) { + orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO(); + generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO); + } + List rooms = orderCustomPlateNoSeqVO.getRooms(); + if (CollUtil.isEmpty(rooms)) { + rooms = new ArrayList<>(); + orderCustomPlateNoSeqVO.setRooms(rooms); + } + } + @Override - public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) { + public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO, boolean firstPlate) { // 初始化配置 initConfig(generateConfig); // 按复位模式走不同的生成方式 ResetModeEnum resetModeEnum = ResetModeEnum.getByMode(plateNoRule.getResetMode()); if (ObjectUtil.equal(ResetModeEnum.ORDER, resetModeEnum)) { - return generateNoByOrderResetMode(orderId, plateNoRule, generateConfig, plateDO); + return generateNoByOrderResetMode(orderId, plateNoRule, generateConfig, plateDO, firstPlate); } else if (ObjectUtil.equal(ResetModeEnum.ROOM, resetModeEnum)) { return generateNoByRoomResetMode(plateNoRule, generateConfig, plateDO); } else if (ObjectUtil.equal(ResetModeEnum.BODY, resetModeEnum)) { @@ -63,10 +80,6 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule private CustomPlateNoGenerateConfigVO generateNoByDateResetMode(ResetModeEnum resetModeEnum, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) { // 机构下的自定义板编号序号 CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO(); - // 上一次自定义编号生成的年月日 - int year = orgCustomPlateNoSeqRespDTO.getLastYear(); - int month = orgCustomPlateNoSeqRespDTO.getLastMonth(); - int day = orgCustomPlateNoSeqRespDTO.getLastDay(); // 从全局配置获取当前序号,取不到用初始值 Integer orderNoSeq = orgCustomPlateNoSeqRespDTO.getPlateNoSeq(); if (ObjectUtil.isNull(orderNoSeq)) { @@ -74,14 +87,13 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule } if (ObjectUtil.equal(ResetModeEnum.YEAR, resetModeEnum)) { - orderNoSeq = resetByYear(orderNoSeq, year, plateNoRule); + orderNoSeq = resetByYear(orderNoSeq, orgCustomPlateNoSeqRespDTO, plateNoRule); } else if (ObjectUtil.equal(ResetModeEnum.MONTH, resetModeEnum)) { - orderNoSeq = resetByMonth(orderNoSeq, month, plateNoRule); + orderNoSeq = resetByMonth(orderNoSeq, orgCustomPlateNoSeqRespDTO, plateNoRule); } else if (ObjectUtil.equal(ResetModeEnum.DAY, resetModeEnum)) { - orderNoSeq = resetByDay(orderNoSeq, day, plateNoRule); + orderNoSeq = resetByDay(orderNoSeq, orgCustomPlateNoSeqRespDTO, plateNoRule); } - // 跨板件累加步长,补零 - orderNoSeq += plateNoRule.getIncrementStep(); + // 补零 String noPartAfterFillZero = fillZero(orderNoSeq, plateNoRule); plateDO.getCustomPlateNo().append(noPartAfterFillZero); @@ -97,7 +109,7 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule * @param generateConfig * @param plateDO */ - private CustomPlateNoGenerateConfigVO generateNoByOrderResetMode(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) { + private CustomPlateNoGenerateConfigVO generateNoByOrderResetMode(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO, boolean firstPlate) { Integer incrementStep = plateNoRule.getIncrementStep(); Integer initValue = plateNoRule.getInitValue() - incrementStep; // 生产单下的序号 @@ -108,7 +120,7 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule Integer orderPlateNoSeq = Optional.ofNullable(orderCustomPlateNoSeqVO.getPlateNoSeq()).orElse(initValue); // 上次导入的生产单号 Long lastOrderNo = orgCustomPlateNoSeqRespDTO.getLastOrderNo(); - if (ObjectUtil.isNotNull(lastOrderNo) && ObjectUtil.notEqual(orderId, lastOrderNo)) { + if (firstPlate && (ObjectUtil.isNull(lastOrderNo) || ObjectUtil.notEqual(orderId, lastOrderNo))) { // 跨单复位到初始值 orderPlateNoSeq = initValue; } @@ -240,36 +252,23 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule return null; } - /** - * 初始化生成所需配置 - * - * @param generateConfigVO - */ - private void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) { - OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO(); - if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) { - orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO(); - generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO); - } - List rooms = orderCustomPlateNoSeqVO.getRooms(); - if (CollUtil.isEmpty(rooms)) { - rooms = new ArrayList<>(); - orderCustomPlateNoSeqVO.setRooms(rooms); - } - } - /** * 按年复位 * * @param curr - * @param year + * @param orgCustomPlateNoSeqRespDTO * @param plateNoRule * @return */ - private int resetByYear(int curr, int year, CustomPlateNoRuleVO plateNoRule) { - LocalDateTime now = plateNoRule.getNow(); + private int resetByYear(int curr, CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO, CustomPlateNoRuleVO plateNoRule) { + // 上一次的年 + Integer lastYear = orgCustomPlateNoSeqRespDTO.getLastYear(); Integer initValue = plateNoRule.getInitValue(); - if (ObjectUtil.notEqual(String.valueOf(year), now.format(YEAR_FORMATTER))) { + String nowYearFormat = plateNoRule.getNow().format(YEAR_FORMATTER); + if (ObjectUtil.notEqual(String.valueOf(lastYear), nowYearFormat)) { + // 跨年,把上一次的年设成当前年,后续不再跨年 + orgCustomPlateNoSeqRespDTO.setLastYear(Integer.parseInt(nowYearFormat)); + // 复位 return initValue; } return curr + plateNoRule.getIncrementStep(); @@ -279,14 +278,19 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule * 按月复位 * * @param curr - * @param month + * @param orgCustomPlateNoSeqRespDTO * @param plateNoRule * @return */ - private int resetByMonth(int curr, int month, CustomPlateNoRuleVO plateNoRule) { - LocalDateTime now = plateNoRule.getNow(); + private int resetByMonth(int curr, CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO, CustomPlateNoRuleVO plateNoRule) { + // 上一次的月 + Integer lastMonth = orgCustomPlateNoSeqRespDTO.getLastMonth(); Integer initValue = plateNoRule.getInitValue(); - if (ObjectUtil.notEqual(String.valueOf(month), now.format(MONTH_FORMATTER))) { + String nowMonthFormat = plateNoRule.getNow().format(MONTH_FORMATTER); + if (ObjectUtil.notEqual(String.valueOf(lastMonth), nowMonthFormat)) { + // 跨月,把上一次的月设成当前月,后续不再跨月 + orgCustomPlateNoSeqRespDTO.setLastMonth(Integer.parseInt(nowMonthFormat)); + // 复位 return initValue; } return curr + plateNoRule.getIncrementStep(); @@ -296,14 +300,19 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule * 按天复位 * * @param curr - * @param day + * @param orgCustomPlateNoSeqRespDTO * @param plateNoRule * @return */ - private int resetByDay(int curr, int day, CustomPlateNoRuleVO plateNoRule) { - LocalDateTime now = plateNoRule.getNow(); + private int resetByDay(int curr, CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO, CustomPlateNoRuleVO plateNoRule) { + // 上一次的天 + Integer lastDay = orgCustomPlateNoSeqRespDTO.getLastDay(); Integer initValue = plateNoRule.getInitValue(); - if (ObjectUtil.notEqual(String.valueOf(day), now.format(DAY_FORMATTER))) { + String nowDayFormat = plateNoRule.getNow().format(DAY_FORMATTER); + if (ObjectUtil.notEqual(String.valueOf(lastDay), nowDayFormat)) { + // 跨月,把上一次的月设成当前月,后续不再跨月 + orgCustomPlateNoSeqRespDTO.setLastDay(Integer.parseInt(nowDayFormat)); + // 复位 return initValue; } return curr + plateNoRule.getIncrementStep(); diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/RoomNoGenerateRuleServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/RoomNoGenerateRuleServiceImpl.java index bb25a254b..3e456e0ec 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/RoomNoGenerateRuleServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/customplatenorule/RoomNoGenerateRuleServiceImpl.java @@ -1,5 +1,6 @@ package com.cf.imes.module.executor.service.customplatenorule; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO; import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO; @@ -27,8 +28,26 @@ public class RoomNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.ROOMNO.getRuleCode(), ruleCode); } + /** + * 初始化生成所需配置 + * + * @param generateConfigVO + */ + private static void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) { + OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO(); + if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) { + orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO(); + generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO); + } + List rooms = orderCustomPlateNoSeqVO.getRooms(); + if (CollUtil.isEmpty(rooms)) { + rooms = new ArrayList<>(); + orderCustomPlateNoSeqVO.setRooms(rooms); + } + } + @Override - public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) { + public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO, boolean firstPlate) { Integer incrementStep = plateNoRule.getIncrementStep(); Integer initValue = plateNoRule.getInitValue() - incrementStep; // 初始化配置 @@ -43,7 +62,7 @@ public class RoomNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS List rooms = orderCustomPlateNoSeqVO.getRooms(); // 上次导入的生产单号 Long lastOrderNo = orgCustomPlateNoSeqRespDTO.getLastOrderNo(); - if (ObjectUtil.isNotNull(lastOrderNo) && ObjectUtil.notEqual(orderId, lastOrderNo)) { + if (firstPlate && (ObjectUtil.isNull(lastOrderNo) || ObjectUtil.notEqual(orderId, lastOrderNo))) { // 跨单复位到初始值 orderRoomNoSeq = initValue; } @@ -81,19 +100,6 @@ public class RoomNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS return generateConfig; } - /** - * 初始化生成所需配置 - * - * @param generateConfigVO - */ - private static void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) { - OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO(); - if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) { - orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO(); - generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO); - } - } - /** * 根据房间名从生产单序号json中获取房间序号列表 * diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/dal/dataobject/customplateno/CustomPlateNoSeqDO.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/dal/dataobject/customplateno/CustomPlateNoSeqDO.java index 57ae61c42..3b889bf2d 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/dal/dataobject/customplateno/CustomPlateNoSeqDO.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/dal/dataobject/customplateno/CustomPlateNoSeqDO.java @@ -19,7 +19,7 @@ import java.io.Serializable; * @author Gqr * @since 2024/11/11 18:31 */ -@TableName(value = "custom_plateno_seq", autoResultMap = true) +@TableName(value = "custom_plateno_seq") @KeySequence("custom_plateno_seq_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @ToString(callSuper = true) diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/config/factory/service/impl/CustomPlateNoServiceHandler.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/config/factory/service/impl/CustomPlateNoServiceHandler.java index 760807c23..47a4e6105 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/config/factory/service/impl/CustomPlateNoServiceHandler.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/config/factory/service/impl/CustomPlateNoServiceHandler.java @@ -15,14 +15,17 @@ import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigDeleteRe import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigPageReqVO; import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigSaveReqVO; import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigUpdateStatusReqVO; +import com.cf.imes.module.system.dal.dataobject.customplateno.CustomPlateNoSeqDO; import com.cf.imes.module.system.dal.dataobject.systemconfig.SystemConfigDO; import com.cf.imes.module.system.dal.dataobject.dict.DictDataDO; +import com.cf.imes.module.system.dal.mysql.customplateno.CustomPlateNoSeqMapper; import com.cf.imes.module.system.dal.mysql.systemconfig.SystemConfigMapper; import com.cf.imes.module.system.dal.redis.RedisKeyConstants; import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum; import com.cf.imes.module.system.enums.config.SystemConfigTypeEnum; import com.cf.imes.module.system.enums.customplateno.ResetModeEnum; import com.cf.imes.module.system.service.config.factory.service.AbstractSystemConfigServiceHandler; +import com.cf.imes.module.system.service.customplateno.CustomPlateNoSeqService; import com.cf.imes.module.system.service.dict.DictDataService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -52,10 +55,10 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_RULECODE_NOT_MATCH_ERROR = new ErrorCode(1_002_040_003, "规则编码【{}】不合法,请检查配置规则"); public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_DATE_TYPE_FORMAT_ERROR = new ErrorCode(1_002_040_003, "时间格式【{}】不合法,请检查配置规则"); public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_CUSTOM_VALUE_EMPTY_ERROR = new ErrorCode(1_002_040_003, "自定义字符值不能为空,请检查配置规则"); - public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_RESETMODE_ERROR = new ErrorCode(1_002_040_003, "规则【{}】复位/清零模式【{}】不合法,请检查配置规则"); - public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY = new ErrorCode(1_002_040_003, "参数【{}】不能为空,请检查配置规则"); - public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_ERROR = new ErrorCode(1_002_040_003, "数值类型参数{}:【{}】转换异常,请检查配置规则"); - public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_BOL_TYPE_ERROR = new ErrorCode(1_002_040_003, "布尔类型参数{}:【{}】转换异常,请检查配置规则"); + public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_RESETMODE_ERROR = new ErrorCode(1_002_040_003, "规则【{}】复位/清零模式不合法,请检查配置规则"); + public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY = new ErrorCode(1_002_040_003, "【{}】下的【{}】不能为空,请检查配置规则"); + public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_ERROR = new ErrorCode(1_002_040_003, "【{}】下的数值类型参数{}:【{}】转换异常,请检查配置规则"); + public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_BOL_TYPE_ERROR = new ErrorCode(1_002_040_003, "【{}】下的布尔类型参数{}:【{}】转换异常,请检查配置规则"); @Resource @@ -67,6 +70,12 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand @Resource private StringRedisTemplate stringRedisTemplate; + @Resource + private CustomPlateNoSeqService customPlateNoSeqService; + + @Resource + private CustomPlateNoSeqMapper customPlateNoSeqMapper; + @Override public List selectList(ConfigPageReqVO pageReqVO) { return null; @@ -172,8 +181,9 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand Map bolTypeFieldMap = new HashMap<>() {{ put("left_fill_zero", "是否左补零"); }}; - intTypeFieldMap.forEach((k, v) -> checkInt(object.get(k), v)); - bolTypeFieldMap.forEach((k, v) -> checkBol(object.get(k), v)); + String ruleName = object.getString("ruleName"); + intTypeFieldMap.forEach((k, v) -> checkInt(object.get(k), v, ruleName)); + bolTypeFieldMap.forEach((k, v) -> checkBol(object.get(k), v, ruleName)); } } @@ -183,12 +193,12 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand * @param intObj * @param fieldName */ - private void checkInt(Object intObj, String fieldName) { - if (ObjectUtil.isNull(intObj)) { - throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY, fieldName); + private void checkInt(Object intObj, String fieldName, String ruleName) { + if (ObjectUtil.isEmpty(intObj)) { + throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY, ruleName, fieldName); } if (!NumberUtil.isInteger(intObj.toString())) { - throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_ERROR, fieldName, intObj); + throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_ERROR, ruleName, fieldName, intObj); } } @@ -198,12 +208,12 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand * @param bolObj * @param fieldName */ - private void checkBol(Object bolObj, String fieldName) { - if (ObjectUtil.isNull(bolObj)) { - throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY, fieldName); + private void checkBol(Object bolObj, String fieldName, String ruleName) { + if (ObjectUtil.isEmpty(bolObj)) { + throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY, ruleName, fieldName); } if (!(bolObj instanceof Boolean)) { - throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_BOL_TYPE_ERROR, fieldName, bolObj); + throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_BOL_TYPE_ERROR, ruleName, fieldName, bolObj); } } @@ -219,8 +229,8 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand || ObjectUtil.equal(resetMode, ResetModeEnum.MONTH.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.DAY.getMode()); } else if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.PLATENO, custBoardRuleCodeEnum)) { checkSuccess = ObjectUtil.equal(resetMode, ResetModeEnum.ORDER.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.YEAR.getMode()) - || ObjectUtil.equal(resetMode, ResetModeEnum.MONTH.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.ROOM.getMode()) - || ObjectUtil.equal(resetMode, ResetModeEnum.BODY.getMode()); + || ObjectUtil.equal(resetMode, ResetModeEnum.MONTH.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.DAY.getMode()) + || ObjectUtil.equal(resetMode, ResetModeEnum.BODY.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.ROOM.getMode()); } else if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.ROOMNO, custBoardRuleCodeEnum)) { checkSuccess = ObjectUtil.equal(resetMode, ResetModeEnum.ORDER.getMode()); } else if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.BODYNO, custBoardRuleCodeEnum)) { @@ -269,6 +279,13 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand String redisKey = String.format("%s:%d:%s", RedisKeyConstants.SYSTEM_CONFIG, OrganContextHolder.getOrganId(), RedisKeyConstants.CUSTOM_PLATE_NO); Boolean delete = stringRedisTemplate.delete(redisKey); log.info("[CustomPlateNoGenerateService][afterUpdateStatus]key:{}缓存删除结果:{}", redisKey, delete); + + // 查询机构下全局序号 + CustomPlateNoSeqDO plateNoSeqByConfigId = customPlateNoSeqService.getOrgCustomPlateNoSeq(); + // 提前生成板编号序号,存在则不处理 + if (ObjectUtil.isNull(plateNoSeqByConfigId)) { + customPlateNoSeqMapper.insert(new CustomPlateNoSeqDO()); + } } @Override