diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/FieldGenerator.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/FieldGenerator.java index da8d57a3..d50f0ce7 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/FieldGenerator.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/FieldGenerator.java @@ -3,7 +3,6 @@ package com.bonus.sgzb.material.config; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; /** * 后端生产随机编码通用方法(格式:今日年月日日期-随机4位编码 20240328-0001) @@ -17,8 +16,8 @@ public class FieldGenerator { String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd")); // 生成UUID并取后4位,转换为纯数字类型 String uuid = UUID.randomUUID().toString().replaceAll("-", ""); - String uuidLast4Digits = uuid.substring(uuid.length() - 4); + String uuidLast4Digits = uuid.substring(uuid.length() - 7); int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16); - return currentDate + "-" + String.format("%04d", uuidLast4DigitsNumeric % 10000); + return currentDate + "-" + String.format("%07d", uuidLast4DigitsNumeric % 10000); } } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/MachIneDto.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/MachIneDto.java index 759d7e81..2e16225d 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/MachIneDto.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/MachIneDto.java @@ -81,6 +81,10 @@ public class MachIneDto { @ApiModelProperty(value = "编码") private String code; + /** 二维码 */ + @ApiModelProperty(value = "二维码") + private String qrCode; + /** * 创建者 */ diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/InventoryAndWarehousingMapper.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/InventoryAndWarehousingMapper.java index db0c20d9..03bf00af 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/InventoryAndWarehousingMapper.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/mapper/InventoryAndWarehousingMapper.java @@ -72,4 +72,6 @@ public interface InventoryAndWarehousingMapper { * @return */ int selectTaskNumByMonth(@Param("date") Date nowDate); + + int selectByCode(String code); } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/InventoryAndWarehousingServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/InventoryAndWarehousingServiceImpl.java index ba462f7c..d4791707 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/InventoryAndWarehousingServiceImpl.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/InventoryAndWarehousingServiceImpl.java @@ -4,6 +4,7 @@ import com.bonus.sgzb.common.core.utils.DateUtils; import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.security.utils.SecurityUtils; import com.bonus.sgzb.material.config.ExceptionEnum; +import com.bonus.sgzb.material.config.FieldGenerator; import com.bonus.sgzb.material.domain.MachIneDto; import com.bonus.sgzb.material.domain.PutInStorageBean; import com.bonus.sgzb.material.domain.SavePutInfoDto; @@ -74,13 +75,23 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi log.info("新增入库盘点入参dto:{}", dto); Long userId = SecurityUtils.getLoginUser().getUserid(); dto.setCreator(userId); + List codeList = new ArrayList<>(); + if (dto.getNum() != null) { + while (codeList.size() < dto.getNum()) { + String code = FieldGenerator.generateField(); + int count = selectByCode(code); + if (count == 0 && !codeList.contains(code)) { + codeList.add(code); + } + } + } String code = genderBackCode(); int res; try { //1. 判断是数量还是编号入库,保存到不同表 //1.1 如果是编号入库 if (dto.getIsCode()) { - res = insertMaMachineInfo(dto, code); + res = insertMaMachineInfo(dto, codeList, code); if (res == 0) { log.error("insertMaMachineInfo方法插入异常"); throw new RuntimeException("insertMaMachineInfo方法插入异常"); @@ -108,13 +119,22 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi return AjaxResult.success(res); } + /** + * 根据code从ma_machine表查询是否有数据,去重 + * @param code + * @return + */ + private int selectByCode(String code) { + return inventoryAndWarehousingMapper.selectByCode(code); + } + /** * 编号新增,插入ma_machine、ma_machine_label和ma_label_bind * @param dto * @param code * @return */ - private int insertMaMachineInfo(SavePutInfoDto dto, String code) { + private int insertMaMachineInfo(SavePutInfoDto dto, List codeList, String code) { int res = 0; if (dto.getNum() != null) { MachIneDto machIneDto = dto.getMachIneDtoList().get(0); @@ -129,6 +149,8 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi for (int i = 0; i < dto.getMachIneDtoList().size(); i++) { MachIneDto machIneDto = dto.getMachIneDtoList().get(i); machIneDto.setCode(code); + String qrCode = codeList.get(i); + machIneDto.setQrCode(qrCode); machIneDto.setIsCode(dto.getIsCode()); machIneDto.setTypeId(dto.getTypeId()); machIneDto.setCreator(dto.getCreator()); diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/InventoryAndWarehousingMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/InventoryAndWarehousingMapper.xml index eee98fba..bc8fca7a 100644 --- a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/InventoryAndWarehousingMapper.xml +++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/InventoryAndWarehousingMapper.xml @@ -128,7 +128,7 @@ type_id, ma_code, ma_status, - qr_code, + qr_code, buy_price, ma_vender, check_man, @@ -140,7 +140,7 @@ #{typeId}, #{maCode}, 15, - #{code}, + #{qrCode}, #{buyPrice}, #{maVender}, #{checkMan}, @@ -153,14 +153,14 @@ insert into ma_machine_label - label_code, + label_code, ma_id, is_bind, label_type, create_time - #{code}, + #{qrCode}, #{maId}, 1, 9, @@ -171,7 +171,7 @@ insert into ma_label_bind ma_id, - label_code, + label_code, type_id, binder, label_type, @@ -180,7 +180,7 @@ #{maId}, - #{code}, + #{qrCode}, #{typeId}, #{creator}, 9, @@ -231,4 +231,11 @@ + \ No newline at end of file