This commit is contained in:
mashuai 2024-05-27 17:40:18 +08:00
parent 6b4e876aee
commit 3ebb67dd24
5 changed files with 45 additions and 11 deletions

View File

@ -3,7 +3,6 @@ package com.bonus.sgzb.material.config;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* 后端生产随机编码通用方法格式今日年月日日期-随机4位编码 20240328-0001 * 后端生产随机编码通用方法格式今日年月日日期-随机4位编码 20240328-0001
@ -17,8 +16,8 @@ public class FieldGenerator {
String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd")); String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
// 生成UUID并取后4位转换为纯数字类型 // 生成UUID并取后4位转换为纯数字类型
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); 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); int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16);
return currentDate + "-" + String.format("%04d", uuidLast4DigitsNumeric % 10000); return currentDate + "-" + String.format("%07d", uuidLast4DigitsNumeric % 10000);
} }
} }

View File

@ -81,6 +81,10 @@ public class MachIneDto {
@ApiModelProperty(value = "编码") @ApiModelProperty(value = "编码")
private String code; private String code;
/** 二维码 */
@ApiModelProperty(value = "二维码")
private String qrCode;
/** /**
* 创建者 * 创建者
*/ */

View File

@ -72,4 +72,6 @@ public interface InventoryAndWarehousingMapper {
* @return * @return
*/ */
int selectTaskNumByMonth(@Param("date") Date nowDate); int selectTaskNumByMonth(@Param("date") Date nowDate);
int selectByCode(String code);
} }

View File

@ -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.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.security.utils.SecurityUtils; import com.bonus.sgzb.common.security.utils.SecurityUtils;
import com.bonus.sgzb.material.config.ExceptionEnum; 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.MachIneDto;
import com.bonus.sgzb.material.domain.PutInStorageBean; import com.bonus.sgzb.material.domain.PutInStorageBean;
import com.bonus.sgzb.material.domain.SavePutInfoDto; import com.bonus.sgzb.material.domain.SavePutInfoDto;
@ -74,13 +75,23 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
log.info("新增入库盘点入参dto{}", dto); log.info("新增入库盘点入参dto{}", dto);
Long userId = SecurityUtils.getLoginUser().getUserid(); Long userId = SecurityUtils.getLoginUser().getUserid();
dto.setCreator(userId); dto.setCreator(userId);
List<String> 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(); String code = genderBackCode();
int res; int res;
try { try {
//1. 判断是数量还是编号入库保存到不同表 //1. 判断是数量还是编号入库保存到不同表
//1.1 如果是编号入库 //1.1 如果是编号入库
if (dto.getIsCode()) { if (dto.getIsCode()) {
res = insertMaMachineInfo(dto, code); res = insertMaMachineInfo(dto, codeList, code);
if (res == 0) { if (res == 0) {
log.error("insertMaMachineInfo方法插入异常"); log.error("insertMaMachineInfo方法插入异常");
throw new RuntimeException("insertMaMachineInfo方法插入异常"); throw new RuntimeException("insertMaMachineInfo方法插入异常");
@ -108,13 +119,22 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
return AjaxResult.success(res); return AjaxResult.success(res);
} }
/**
* 根据code从ma_machine表查询是否有数据去重
* @param code
* @return
*/
private int selectByCode(String code) {
return inventoryAndWarehousingMapper.selectByCode(code);
}
/** /**
* 编号新增插入ma_machinema_machine_label和ma_label_bind * 编号新增插入ma_machinema_machine_label和ma_label_bind
* @param dto * @param dto
* @param code * @param code
* @return * @return
*/ */
private int insertMaMachineInfo(SavePutInfoDto dto, String code) { private int insertMaMachineInfo(SavePutInfoDto dto, List<String> codeList, String code) {
int res = 0; int res = 0;
if (dto.getNum() != null) { if (dto.getNum() != null) {
MachIneDto machIneDto = dto.getMachIneDtoList().get(0); MachIneDto machIneDto = dto.getMachIneDtoList().get(0);
@ -129,6 +149,8 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
for (int i = 0; i < dto.getMachIneDtoList().size(); i++) { for (int i = 0; i < dto.getMachIneDtoList().size(); i++) {
MachIneDto machIneDto = dto.getMachIneDtoList().get(i); MachIneDto machIneDto = dto.getMachIneDtoList().get(i);
machIneDto.setCode(code); machIneDto.setCode(code);
String qrCode = codeList.get(i);
machIneDto.setQrCode(qrCode);
machIneDto.setIsCode(dto.getIsCode()); machIneDto.setIsCode(dto.getIsCode());
machIneDto.setTypeId(dto.getTypeId()); machIneDto.setTypeId(dto.getTypeId());
machIneDto.setCreator(dto.getCreator()); machIneDto.setCreator(dto.getCreator());

View File

@ -128,7 +128,7 @@
<if test="typeId != null and typeId != '' ">type_id,</if> <if test="typeId != null and typeId != '' ">type_id,</if>
<if test="maCode != null and maCode != '' ">ma_code,</if> <if test="maCode != null and maCode != '' ">ma_code,</if>
ma_status, ma_status,
<if test="code != null and code != ''">qr_code,</if> <if test="qrCode != null and qrCode != ''">qr_code,</if>
<if test="buyPrice != null and buyPrice != ''">buy_price,</if> <if test="buyPrice != null and buyPrice != ''">buy_price,</if>
<if test="maVender != null and maVender != ''">ma_vender,</if> <if test="maVender != null and maVender != ''">ma_vender,</if>
<if test="checkMan != null and checkMan != ''">check_man,</if> <if test="checkMan != null and checkMan != ''">check_man,</if>
@ -140,7 +140,7 @@
<if test="typeId != null and typeId != ''">#{typeId},</if> <if test="typeId != null and typeId != ''">#{typeId},</if>
<if test="maCode != null and maCode != ''">#{maCode},</if> <if test="maCode != null and maCode != ''">#{maCode},</if>
15, 15,
<if test="code != null and code != ''">#{code},</if> <if test="qrCode != null and qrCode != ''">#{qrCode},</if>
<if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if> <if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if>
<if test="maVender != null and maVender != ''">#{maVender},</if> <if test="maVender != null and maVender != ''">#{maVender},</if>
<if test="checkMan != null and checkMan != ''">#{checkMan},</if> <if test="checkMan != null and checkMan != ''">#{checkMan},</if>
@ -153,14 +153,14 @@
<insert id="insertMachineLabel"> <insert id="insertMachineLabel">
insert into ma_machine_label insert into ma_machine_label
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="code != null">label_code,</if> <if test="qrCode != null">label_code,</if>
<if test="maId != null">ma_id,</if> <if test="maId != null">ma_id,</if>
is_bind, is_bind,
label_type, label_type,
create_time create_time
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="code != null">#{code},</if> <if test="qrCode != null">#{qrCode},</if>
<if test="maId != null">#{maId},</if> <if test="maId != null">#{maId},</if>
1, 1,
9, 9,
@ -171,7 +171,7 @@
insert into ma_label_bind insert into ma_label_bind
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="maId != null">ma_id,</if> <if test="maId != null">ma_id,</if>
<if test="code != null">label_code,</if> <if test="qrCode != null">label_code,</if>
<if test="typeId != null">type_id,</if> <if test="typeId != null">type_id,</if>
<if test="creator != null">binder,</if> <if test="creator != null">binder,</if>
label_type, label_type,
@ -180,7 +180,7 @@
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="maId != null">#{maId},</if> <if test="maId != null">#{maId},</if>
<if test="code != null">#{code},</if> <if test="qrCode != null">#{qrCode},</if>
<if test="typeId != null">#{typeId},</if> <if test="typeId != null">#{typeId},</if>
<if test="creator != null">#{creator},</if> <if test="creator != null">#{creator},</if>
9, 9,
@ -231,4 +231,11 @@
<select id="selectTaskNumByMonth" resultType="java.lang.Integer"> <select id="selectTaskNumByMonth" resultType="java.lang.Integer">
select count(*) from ma_type_put_in_storage_info where DATE_FORMAT(CREATE_DATE,'%y%m') = DATE_FORMAT(#{date},'%y%m') select count(*) from ma_type_put_in_storage_info where DATE_FORMAT(CREATE_DATE,'%y%m') = DATE_FORMAT(#{date},'%y%m')
</select> </select>
<select id="selectByCode" resultType="java.lang.Integer">
select count(*)
from ma_machine
<where>
<if test="code != null ">and qr_code = #{code}</if>
</where>
</select>
</mapper> </mapper>