diff --git a/cf-framework/cf-spring-boot-starter-biz-id/src/main/java/com/cf/imes/framework/id/core/util/SnowflakeIdWorker3rd.java b/cf-framework/cf-spring-boot-starter-biz-id/src/main/java/com/cf/imes/framework/id/core/util/SnowflakeIdWorker3rd.java index cdd3fb530..c2bbe3684 100644 --- a/cf-framework/cf-spring-boot-starter-biz-id/src/main/java/com/cf/imes/framework/id/core/util/SnowflakeIdWorker3rd.java +++ b/cf-framework/cf-spring-boot-starter-biz-id/src/main/java/com/cf/imes/framework/id/core/util/SnowflakeIdWorker3rd.java @@ -70,6 +70,19 @@ public class SnowflakeIdWorker3rd { return Integer.parseInt(formatted_date); } + /** + * 生成小板短编号。 + * + *

编号以固定的 {@code 1} 开始,再拼接五位组织编号,避免其他系统截取前五位时出现前导零。

+ * + * @param organId 组织编号 + * @param id 小板序列号 + * @return 小板短编号 + */ + public static String generatePlateNo(Long organId, long id) { + return "1" + String.format("%05d", organId) + obtainingTime() + Long.toString(id).substring(2); + } + /** * 获得下一个ID (该方法是线程安全) * diff --git a/cf-framework/cf-spring-boot-starter-biz-id/src/test/java/com/cf/imes/framework/id/core/util/SnowflakeIdWorker3rdTest.java b/cf-framework/cf-spring-boot-starter-biz-id/src/test/java/com/cf/imes/framework/id/core/util/SnowflakeIdWorker3rdTest.java new file mode 100644 index 000000000..3f28c9e38 --- /dev/null +++ b/cf-framework/cf-spring-boot-starter-biz-id/src/test/java/com/cf/imes/framework/id/core/util/SnowflakeIdWorker3rdTest.java @@ -0,0 +1,17 @@ +package com.cf.imes.framework.id.core.util; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SnowflakeIdWorker3rdTest { + + @Test + void generatePlateNoStartsWithOneAndKeepsFiveDigitOrganId() { + String plateNo = SnowflakeIdWorker3rd.generatePlateNo(7L, 123456L); + + assertTrue(plateNo.startsWith("1")); + assertEquals("00007", plateNo.substring(1, 6)); + } +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plate/PlateServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plate/PlateServiceImpl.java index b489b3187..2a48e13b9 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plate/PlateServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plate/PlateServiceImpl.java @@ -569,6 +569,8 @@ public class PlateServiceImpl implements PlateService { Map orderGoodsPlanPlateNumAndAreaRespVOMap = new HashMap<>(); + Long organId = getUserOrganId(); + // 组装新增数据 reqVO.forEach(f -> { @@ -584,9 +586,7 @@ public class PlateServiceImpl implements PlateService { .build()); // 生成板编号 - long obtainingTime = SnowflakeIdWorker3rd.obtainingTime(); - - String plateNo = (obtainingTime) + Long.toString(idWorker.nextId()).substring(2); + String plateNo = SnowflakeIdWorker3rd.generatePlateNo(organId, idWorker.nextId()); String remake1 = f.getRemake1() == null ? "" : f.getRemake1() + ";"; @@ -603,6 +603,7 @@ public class PlateServiceImpl implements PlateService { plateDOS.add(PlateDO.builder() .id(plateId) .orderId(orderId) + .organId(organId) .name(f.getName()) .plateNo(plateNo) .type(OrderPlateTypeEnum.SELFINCREASINGBOARD.getType()) @@ -1227,8 +1228,8 @@ public class PlateServiceImpl implements PlateService { @Override public OrderPlateWechatMiniProgramCadInfoRespVO getPlateInfoByPlateNo(String plateNo) { // 1、解析组织id,查询板件信息 - Integer organId = Integer.parseInt(plateNo.substring(0, 5)); - organApi.validOrgan(organId.longValue()).checkError(); + Long organId = parseOrganId(plateNo); + organApi.validOrgan(organId).checkError(); PlateDO plateDO = plateMapper.selectOne(new LambdaQueryWrapper() .eq(PlateDO::getOrganId, organId) @@ -1293,9 +1294,8 @@ public class PlateServiceImpl implements PlateService { public OrderWechatMiniProgramCadInfoRespVO getOrderInfoByPlateNo(String plateNo) { OrderWechatMiniProgramCadInfoRespVO result = new OrderWechatMiniProgramCadInfoRespVO(); // 1、解析组织id,查询板件信息 - Integer organId = Integer.parseInt(plateNo.substring(0, 5)); - Long organIdLong = organId.longValue(); - organApi.validOrgan(organId.longValue()).checkError(); + Long organIdLong = parseOrganId(plateNo); + organApi.validOrgan(organIdLong).checkError(); PlateDO plateDO = plateMapper.selectOne(new LambdaQueryWrapper() .eq(PlateDO::getOrganId, organIdLong) @@ -1324,9 +1324,8 @@ public class PlateServiceImpl implements PlateService { @Override public OrdersViewCadViewInfoRespVO getOrderDetailsByPlateNo(String plateNo, OrderWechatMiniProgramDetailReqVO reqVO) { // 1、解析组织id,查询板件信息 - Integer organId = Integer.parseInt(plateNo.substring(0, 5)); - Long organIdLong = organId.longValue(); - organApi.validOrgan(organId.longValue()).checkError(); + Long organIdLong = parseOrganId(plateNo); + organApi.validOrgan(organIdLong).checkError(); OrganContextHolder.setIgnore(false); OrganContextHolder.setOrganId(organIdLong); @@ -1357,4 +1356,21 @@ public class PlateServiceImpl implements PlateService { return orderComponentService.getOrderViewCadInfo(detailReqVO); } + + /** + * 从板件短编号解析组织编号,同时兼容旧版未增加固定前缀的编号。 + * + * @param plateNo 板件短编号 + * @return 组织编号 + */ + private Long parseOrganId(String plateNo) { + if (plateNo.length() >= 10 && plateNo.charAt(0) == '1') { + int year = Integer.parseInt(plateNo.substring(6, 8)); + int month = Integer.parseInt(plateNo.substring(8, 10)); + if (year >= 20 && month >= 1 && month <= 12) { + return Long.parseLong(plateNo.substring(1, 6)); + } + } + return Long.parseLong(plateNo.substring(0, 5)); + } } diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/api/webcad/ApiTypeRealize.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/api/webcad/ApiTypeRealize.java index 60942aa5a..b502ffef0 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/api/webcad/ApiTypeRealize.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/api/webcad/ApiTypeRealize.java @@ -966,7 +966,6 @@ public class ApiTypeRealize { for (int i = 0; i < plateLists.size(); i++) { long plateNo = idWorker.nextId(); - long obtainingTime = idWorker.obtainingTime(); JSONObject plate = plateLists.getJSONObject(i); @@ -984,7 +983,7 @@ public class ApiTypeRealize { .id(plateId) .orderId(orderId) .name(plate.getString(ProduceApiConstants.BD_BOARD_NAME)) - .plateNo((obtainingTime) + Long.toString(plateNo).substring(2)) + .plateNo(SnowflakeIdWorker3rd.generatePlateNo(organId, plateNo)) .type(type) .goodsId(plate.getLong(ProduceApiConstants.BD_GOODS_ID)) .splitHeight(BigDecimal.valueOf(plate.getDouble(ProduceApiConstants.BD_SPLIT_HEIGHT))) @@ -1561,4 +1560,4 @@ public class ApiTypeRealize { .collect(Collectors.toSet()); } -} \ No newline at end of file +} diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/files/excel/ExcelTypeRealize.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/files/excel/ExcelTypeRealize.java index 56995c22b..c18f5789b 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/files/excel/ExcelTypeRealize.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/files/excel/ExcelTypeRealize.java @@ -274,7 +274,6 @@ public class ExcelTypeRealize { for (int i = 0; i < Integer.parseInt(combination.getGoodsNumber()); i++) { long plateNo = idWorker.nextId(); - long obtainingTime = idWorker.obtainingTime(); // 计算面积 BigDecimal area = BigDecimal.valueOf(Double.parseDouble(combination.getWidth())) @@ -293,7 +292,7 @@ public class ExcelTypeRealize { .plateNo(combination.getPlateNo()) .goodsId(combination.getGoodId()) .width(BigDecimal.valueOf(Double.parseDouble(combination.getWidth()))) - .plateNo(((obtainingTime) + Long.toString(plateNo).substring(2))) + .plateNo(SnowflakeIdWorker3rd.generatePlateNo(organId, plateNo)) .height(BigDecimal.valueOf(Double.parseDouble(combination.getHeight()))) .thickness(BigDecimal.valueOf(Double.parseDouble(combination.getThickness()))) .splitWidth(BigDecimal.valueOf(Double.parseDouble(combination.getSplitWidth()))) diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/files/xml/XmlTypeRealize.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/files/xml/XmlTypeRealize.java index 58b53fd40..5dec43740 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/files/xml/XmlTypeRealize.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/util/fileConversion/admin/files/xml/XmlTypeRealize.java @@ -809,7 +809,6 @@ public class XmlTypeRealize { for (BlockXmlVO blockXmlVO : blockXmlVOS.getBlockXmlVOList()) { long plateNo = idWorker.nextId(); - long obtainingTime = idWorker.obtainingTime(); Long plateId = (Long) identifierGenerator.nextId(null); // 成品面积 @@ -865,7 +864,7 @@ public class XmlTypeRealize { .organId(organId) .orderId(orderId) .name(blockXmlVO.getName()) - .plateNo((obtainingTime) + Long.toString(plateNo).substring(2)) + .plateNo(SnowflakeIdWorker3rd.generatePlateNo(organId, plateNo)) .type(plateType) .goodsId(goodsId) .width(BigDecimal.valueOf(Double.parseDouble(blockXmlVO.getWidth()))) diff --git a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/DefaultExcelOrderImportFactory.java b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/DefaultExcelOrderImportFactory.java index ff3337a60..68beed941 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/DefaultExcelOrderImportFactory.java +++ b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/DefaultExcelOrderImportFactory.java @@ -655,7 +655,6 @@ public class DefaultExcelOrderImportFactory { // 根据数量生成num个小板数据 for (int i = 0; i < num; i++) { long plateNo = idWorker.nextId(); - long obtainingTime = idWorker.obtainingTime(); long goodsId = Long.parseLong(tempDataDO.getInnerGoodsId()); // 成品宽 String width = combination.getWidth(); @@ -674,7 +673,7 @@ public class DefaultExcelOrderImportFactory { .name(combination.getName()) .type(OrderPlateTypeEnum.LAYERBOARD.getType()) .goodsId(goodsId) - .plateNo(String.format("%05d", organId) + ((obtainingTime) + Long.toString(plateNo).substring(2))) + .plateNo(SnowflakeIdWorker3rd.generatePlateNo(organId, plateNo)) .height(BigDecimal.valueOf(Double.parseDouble(height))) .width(BigDecimal.valueOf(Double.parseDouble(width))) .thickness(BigDecimal.valueOf(Double.parseDouble(combination.getThickness()))) diff --git a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/DefaultXmlOrderImportFactory.java b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/DefaultXmlOrderImportFactory.java index 34c5dedf4..d504f7bc9 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/DefaultXmlOrderImportFactory.java +++ b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/DefaultXmlOrderImportFactory.java @@ -465,7 +465,6 @@ public class DefaultXmlOrderImportFactory { BlockXmlVO blockXmlVO = JSON.parseObject(detail, BlockXmlVO.class); long plateNo = idWorker.nextId(); - long obtainingTime = idWorker.obtainingTime(); Long plateId = (Long) snowFlakeGenerator.nextId(null); // 成品面积 @@ -515,7 +514,7 @@ public class DefaultXmlOrderImportFactory { .id(plateId) .orderId(orderId) .name(blockXmlVO.getName()) - .plateNo(String.format("%05d", organId) + (obtainingTime) + Long.toString(plateNo).substring(2)) + .plateNo(SnowflakeIdWorker3rd.generatePlateNo(organId, plateNo)) .type(plateType) .goodsId(goodsId) .width(BigDecimal.valueOf(Double.parseDouble(blockXmlVO.getWidth()))) diff --git a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/ProducingOrderImportFactory.java b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/ProducingOrderImportFactory.java index cf7377426..f9a3c6f71 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/ProducingOrderImportFactory.java +++ b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/ProducingOrderImportFactory.java @@ -1244,7 +1244,6 @@ public class ProducingOrderImportFactory { Long plateId = (Long) snowFlakeGenerator.nextId(null); long plateNo = idWorker.nextId(); - long obtainingTime = idWorker.obtainingTime(); // 从info.remarks中获取备注相关 ProducingImportBlockRemark plateRemark = getPlateRemark(block); @@ -1269,7 +1268,7 @@ public class ProducingOrderImportFactory { .id(plateId) .orderId(orderId) .name(block.getName()) - .plateNo(String.format("%05d", organId) + obtainingTime + Long.toString(plateNo).substring(2)) + .plateNo(SnowflakeIdWorker3rd.generatePlateNo(organId, plateNo)) .type(block.getType()) .goodsId(goodsDO.getId()) .width(getBigDecimalOrNull(block.getWidth())) diff --git a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/WebCadOrderImportAsyncFactory.java b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/WebCadOrderImportAsyncFactory.java index 381f22bb1..e494cc156 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/WebCadOrderImportAsyncFactory.java +++ b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/WebCadOrderImportAsyncFactory.java @@ -770,7 +770,6 @@ public class WebCadOrderImportAsyncFactory { Long plateId = (Long) snowFlakeGenerator.nextId(null); long plateNo = idWorker.nextId(); - long obtainingTime = idWorker.obtainingTime(); // 从info.remarks中获取备注相关 WebCadDataBlockRemarkVO plateRemark = getPlateRemark(block); @@ -797,7 +796,7 @@ public class WebCadOrderImportAsyncFactory { .id(plateId) .orderId(orderId) .name(block.getName()) - .plateNo(String.format("%05d", organId) + obtainingTime + Long.toString(plateNo).substring(2)) + .plateNo(SnowflakeIdWorker3rd.generatePlateNo(organId, plateNo)) .type(block.getType()) .goodsId(goodsDO.getId()) .width(getBigDecimalOrNull(block.getWidth())) diff --git a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/WebCadOrderImportFactory.java b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/WebCadOrderImportFactory.java index 961c9a979..a246cfaef 100644 --- a/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/WebCadOrderImportFactory.java +++ b/cf-module-prod-plan/cf-module-prod-plan-biz/src/main/java/com/cf/imes/module/plan/service/orderImport/factory/WebCadOrderImportFactory.java @@ -953,7 +953,6 @@ public class WebCadOrderImportFactory { Long plateId = (Long) snowFlakeGenerator.nextId(null); long plateNo = idWorker.nextId(); - long obtainingTime = idWorker.obtainingTime(); // 从info.remarks中获取备注相关 WebCadDataBlockRemarkVO plateRemark = getPlateRemark(block); @@ -978,7 +977,7 @@ public class WebCadOrderImportFactory { .id(plateId) .orderId(orderId) .name(block.getName()) - .plateNo(String.format("%05d", organId) + obtainingTime + Long.toString(plateNo).substring(2)) + .plateNo(SnowflakeIdWorker3rd.generatePlateNo(organId, plateNo)) .type(block.getType()) .goodsId(goodsDO.getId()) .width(getBigDecimalOrNull(block.getWidth()))