diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java new file mode 100644 index 00000000..5e3fa242 --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/ExceptionEnum.java @@ -0,0 +1,28 @@ +package com.bonus.sgzb.material.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 返回异常枚举类 + * @Author ma_sh + * @create 2024/3/29 14:43 + */ +@Getter +@AllArgsConstructor +public enum ExceptionEnum { + + SAVE_TO_DATABASE(500, "盘点入库新增保存失败,请联系管理员!!!"); + + private Integer code; + + private String msg; + + public Integer getCode() { + return code; + } + + public String getMsg() { + return msg; + } +} 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 new file mode 100644 index 00000000..da8d57a3 --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/config/FieldGenerator.java @@ -0,0 +1,24 @@ +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) + * @Author ma_sh + * @create 2024/3/28 17:42 + */ +public class FieldGenerator { + + public static String generateField() { + LocalDate today = LocalDate.now(); + String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd")); + // 生成UUID并取后4位,转换为纯数字类型 + String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + String uuidLast4Digits = uuid.substring(uuid.length() - 4); + int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16); + return currentDate + "-" + String.format("%04d", uuidLast4DigitsNumeric % 10000); + } +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/InventoryAndWarehousingController.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/InventoryAndWarehousingController.java index e9111005..590f0df9 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/InventoryAndWarehousingController.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/controller/InventoryAndWarehousingController.java @@ -1,8 +1,10 @@ package com.bonus.sgzb.material.controller; import com.bonus.sgzb.common.core.web.controller.BaseController; +import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.core.web.page.TableDataInfo; import com.bonus.sgzb.material.domain.PutInStorageBean; +import com.bonus.sgzb.material.domain.SavePutInfoDto; import com.bonus.sgzb.material.service.InventoryAndWarehousingService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -33,4 +35,16 @@ public class InventoryAndWarehousingController extends BaseController { List list = inventoryAndWarehousingService.getList(bean); return getDataTable(list); } + + /** + * 新增入库盘点 + * @param dto + * @return + */ + @ApiOperation(value = "新增入库盘点") + @PostMapping("/addList") + public AjaxResult savePutInfo(@RequestBody SavePutInfoDto dto) { + return inventoryAndWarehousingService.savePutInfo(dto); + } + } 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 new file mode 100644 index 00000000..77da40fc --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/MachIneDto.java @@ -0,0 +1,78 @@ +package com.bonus.sgzb.material.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author ma_sh + * @create 2024/3/28 17:53 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MachIneDto { + + /** + * 主键id + */ + private Integer id; + + /** 机具ID */ + @ApiModelProperty(value = "机具ID") + private Long maId; + + /** + * 类型id + */ + private String typeId; + + /** 设备编号 */ + @ApiModelProperty(value = "设备编号") + private String maCode; + + /** 出厂编码 */ + @ApiModelProperty(value = "出厂编码") + private String outFacCode; + + /** 生产厂家 */ + @ApiModelProperty(value = "生产厂家") + private String maVender; + + /** 本次检修日期 */ + @ApiModelProperty(value = "本次检修日期") + private String thisCheckTime; + + /** 下次检修日期 */ + @ApiModelProperty(value = "下次检修日期") + private String nextCheckTime; + + /** 单价 */ + @ApiModelProperty(value = "单价") + private String buyPrice; + + /** 编码 */ + @ApiModelProperty(value = "编码") + private String code; + + /** + * 创建者 + */ + @ApiModelProperty(value = "创建者") + private String creator; + + /** + * 入库形式 + */ + @ApiModelProperty(value = "入库形式") + private String putInType; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remarks; +} diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SavePutInfoDto.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SavePutInfoDto.java new file mode 100644 index 00000000..76e1021c --- /dev/null +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/domain/SavePutInfoDto.java @@ -0,0 +1,100 @@ +package com.bonus.sgzb.material.domain; + +import com.bonus.sgzb.common.core.web.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 新增盘点入库接口实体类dto + * @Author ma_sh + * @create 2024/3/28 14:22 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SavePutInfoDto extends BaseEntity { + + /** + * 判断为数量还是编号,true为编号 + */ + private Boolean isCode; + + /** + * 主键id + */ + private Integer id; + + /** + * 类型id + */ + private String typeId; + + /** + * 主信息 + */ + private Integer info; + + /** + * 数量 + */ + private Double num; + + /** + * 库房 + */ + private Integer ram; + + /** + * 设备工器具类型 + */ + private Integer type; + + /** + * 设备主键 + */ + private Integer machine; + + /** + * 入库形式 + */ + private String putInType; + + /** + * 盘点入库单号 + */ + private String code; + + /** + * 单位名称 + */ + private String unitId; + + /** + * 工程名称 + */ + private String projectId; + + /** + * 创建者 + */ + private String creator; + + /** + * 创建时间 + */ + private String createDate; + + /** + * 备注 + */ + private String remarks; + + /** + * 表单类型集合 + */ + private List machIneDtoList; + +} 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 1b0a8047..c176453d 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 @@ -1,7 +1,9 @@ package com.bonus.sgzb.material.mapper; +import com.bonus.sgzb.material.domain.MachIneDto; import com.bonus.sgzb.material.domain.PutInStorageBean; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -20,4 +22,41 @@ public interface InventoryAndWarehousingMapper { */ List getList(PutInStorageBean bean); + /** + * ma_type_put_in_storage_details表 + * @param machIneDto + * @return + */ + Integer saveDetails(MachIneDto machIneDto); + + /** + * 插入ma_type_put_in_storage_info表 + * @param machIneDto + * @return + */ + int saveInfo(MachIneDto machIneDto); + + /** + * 更新matype表中num数量 + * @param + */ + int updateMaType(@Param("typeId") String typeId, @Param("num") Double num); + + /** + * 新增ma_machine表 + * @param + * @return + */ + int insertMachine(MachIneDto machIneDtoy); + + int insertMachineLabel(MachIneDto machIneDto); + + int insertLabelBind(MachIneDto machIneDto); + + /** + * 根据code从ma_machine表查询是否有数据,去重 + * @param code + * @return + */ + int selectById(String code); } diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/InventoryAndWarehousingService.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/InventoryAndWarehousingService.java index 1f4eab8c..b073f114 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/InventoryAndWarehousingService.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/InventoryAndWarehousingService.java @@ -1,7 +1,9 @@ package com.bonus.sgzb.material.service; +import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.material.domain.PutInStorageBean; +import com.bonus.sgzb.material.domain.SavePutInfoDto; import java.util.List; @@ -18,4 +20,11 @@ public interface InventoryAndWarehousingService { * @return 结果 */ List getList(PutInStorageBean bean); + + /** + * 新增入库盘点 + * @param dto + * @return + */ + AjaxResult savePutInfo(SavePutInfoDto dto); } 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 974a1d22..1d490fdd 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 @@ -1,26 +1,189 @@ package com.bonus.sgzb.material.service.impl; +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.domain.MachIneDto; import com.bonus.sgzb.material.domain.PutInStorageBean; +import com.bonus.sgzb.material.domain.SavePutInfoDto; import com.bonus.sgzb.material.mapper.InventoryAndWarehousingMapper; import com.bonus.sgzb.material.service.InventoryAndWarehousingService; +import com.bonus.sgzb.material.config.FieldGenerator; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; -import java.util.List; +import java.util.*; /** -* @description 入库盘点 -* @author hay -* @date 2024/3/27 13:32 -*/ + * @author hay + * @description 入库盘点 + * @date 2024/3/27 13:32 + */ @Service +@Slf4j public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousingService { @Autowired private InventoryAndWarehousingMapper inventoryAndWarehousingMapper; + /** + * 查询入库盘点列表 + * @param bean + * @return + */ @Override public List getList(PutInStorageBean bean) { return inventoryAndWarehousingMapper.getList(bean); } + + /** + * 新增入库盘点 + * @param dto + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult savePutInfo(SavePutInfoDto dto) { + Long userId = SecurityUtils.getLoginUser().getUserid(); + dto.setCreator(userId.toString()); + List codeList = new ArrayList<>(); + while (codeList.size() < dto.getNum()) { + String code = FieldGenerator.generateField(); + int count = selectById(code); + if (count == 0) { + codeList.add(code); + } + } + int res = 0; + try { + //1. 判断是数量还是编号,保存到不同表 + //1.1 如果是编号 + if (dto.getIsCode()) { + /*插入ma_machine、ma_machine_label和ma_label_bind以及 + ma_type_put_in_storage_info表和ma_type_put_in_storage_details表*/ + res = insertMaMachineInfo(dto, codeList); + if (res == 0) { + log.error("insertMaMachineInfo方法插入异常"); + throw new RuntimeException("insertMaMachineInfo方法插入异常"); + } + } else { + //2.插入ma_type_put_in_storage_info表和ma_type_put_in_storage_details表 + res = insertPutInfo(dto, codeList); + if (res == 0) { + log.error("insertPutInfo方法插入异常"); + throw new RuntimeException("insertPutInfo方法插入异常"); + } + } + //去修改ma_type里面的库存num,根据前端传的数量追加 + res = updateMaTypeInfo(dto.getTypeId(), dto.getNum()); + if (res == 0) { + log.error("updateMaTypeInfo方法修改异常"); + throw new RuntimeException("updateMaTypeInfo方法修改异常"); + } + } catch (Exception e) { + log.error(e.getMessage()); + // 添加事务回滚逻辑 + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + } + if (res == 0) { + return AjaxResult.error(ExceptionEnum.SAVE_TO_DATABASE.getCode(), ExceptionEnum.SAVE_TO_DATABASE.getMsg()); + } + return AjaxResult.success(res); + } + + /** + * 根据code从ma_machine表查询是否有数据,去重 + * @param code + * @return + */ + private int selectById(String code) { + return inventoryAndWarehousingMapper.selectById(code); + } + + /** + * 编号新增,插入ma_machine、ma_machine_label和ma_label_bind + * @param dto + * @param codeList + * @return + */ + private int insertMaMachineInfo(SavePutInfoDto dto, List codeList) { + int num = 0; + for (int i = 0; i < dto.getMachIneDtoList().size(); i++) { + MachIneDto machIneDto = dto.getMachIneDtoList().get(i); + String code = codeList.get(i); + machIneDto.setCode(code); + machIneDto.setTypeId(dto.getTypeId()); + machIneDto.setCreator(dto.getCreator()); + machIneDto.setRemarks(dto.getRemarks()); + machIneDto.setPutInType(dto.getPutInType()); + num = inventoryAndWarehousingMapper.insertMachine(machIneDto); + if (num == 0) { + throw new RuntimeException("新增到ma_machine表失败"); + } + num = inventoryAndWarehousingMapper.insertMachineLabel(machIneDto); + if (num == 0) { + throw new RuntimeException("新增到ma_machine_label表失败"); + } + num = inventoryAndWarehousingMapper.insertLabelBind(machIneDto); + if (num == 0) { + throw new RuntimeException("新增到ma_label_bind表失败"); + } + //ma_type_put_in_storage_details表,返回主键id + num = inventoryAndWarehousingMapper.saveDetails(machIneDto); + if (num == 0) { + throw new RuntimeException("新增到ma_type_put_in_storage_details表失败"); + } + //插入ma_type_put_in_storage_info表 + num = inventoryAndWarehousingMapper.saveInfo(machIneDto); + if (num == 0) { + throw new RuntimeException("新增到ma_type_put_in_storage_info表失败"); + } + } + return num; + } + + + /** + * 方法抽取,追加ma_type表里面的num + * + * @param typeId + * @param num + * @return + */ + private int updateMaTypeInfo(String typeId, Double num) { + return inventoryAndWarehousingMapper.updateMaType(typeId, num); + } + + + /** + * 插入表方法 + * @param dto + * @return + */ + private int insertPutInfo(SavePutInfoDto dto, List codeList) { + int num = 0; + for (int i = 0; i < dto.getMachIneDtoList().size(); i++) { + MachIneDto machIneDto = dto.getMachIneDtoList().get(i); + String code = codeList.get(i); + machIneDto.setCode(code); + machIneDto.setTypeId(dto.getTypeId()); + machIneDto.setCreator(dto.getCreator()); + machIneDto.setRemarks(dto.getRemarks()); + machIneDto.setPutInType(dto.getPutInType()); + //ma_type_put_in_storage_details表,返回主键id + num = inventoryAndWarehousingMapper.saveDetails(machIneDto); + if (num == 0) { + throw new RuntimeException("新增到ma_type_put_in_storage_details表失败"); + } + //插入ma_type_put_in_storage_info表 + num = inventoryAndWarehousingMapper.saveInfo(machIneDto); + if (num == 0) { + throw new RuntimeException("新增到ma_type_put_in_storage_info表失败"); + } + } + return num; + } } 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 3f06814d..3097e42e 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 @@ -3,6 +3,124 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + INSERT INTO ma_type_put_in_storage_details (NUM, + + + MACHINE, + + + REMARKS, + + + MA_CODE, + + + ) + VALUES (1, + + + #{maId}, + + + #{remarks}, + + + #{maCode}, + + + ) + + + INSERT INTO ma_type_put_in_storage_info + + ID, + PUT_IN_TYPE, + NUM, + CREATOR, + CREATE_DATE, + REMARKS + + VALUES + + #{id}, + #{putInType}, + 1, + #{creator}, + sysdate(), + #{remarks} + + + + insert into ma_machine ( + type_id, + ma_code, + ma_status, + qr_code, + buy_price, + ma_vender, + out_fac_code, + this_check_time, + next_check_time, + create_time + )values( + #{typeId}, + #{maCode}, + 15, + #{code}, + #{buyPrice}, + #{maVender}, + #{outFacCode}, + #{thisCheckTime}, + #{nextCheckTime}, + sysdate() + ) + + + insert into ma_machine_label + + label_id, + label_code, + ma_id, + is_bind, + label_type, + create_time + + + #{maId}, + #{code}, + #{maId}, + 1, + 9, + now() + + + + insert into ma_label_bind + + ma_id, + label_code, + type_id, + label_type, + bind_time, + status + + + #{maId}, + #{code}, + #{typeId}, + 9, + now(), + 1 + + + + UPDATE ma_type + SET num = num + #{num} + + and type_id = #{typeId} + + + \ No newline at end of file diff --git a/sgzb-ui/src/api/store/putInStore.js b/sgzb-ui/src/api/store/putInStore.js index ebe7e699..5e185b4b 100644 --- a/sgzb-ui/src/api/store/putInStore.js +++ b/sgzb-ui/src/api/store/putInStore.js @@ -55,6 +55,14 @@ export function getDeviceTypeTree(params = {}){ }) } +// 提交编码入库 +export function inputByCode(data) { + return request({ + url: '/material/inventoryAndWarehousing/addList', + method: 'post', + data: data + }) +} diff --git a/sgzb-ui/src/views/store/warehousing/putInStore.vue b/sgzb-ui/src/views/store/warehousing/putInStore.vue index 0755cf96..3169ccca 100644 --- a/sgzb-ui/src/views/store/warehousing/putInStore.vue +++ b/sgzb-ui/src/views/store/warehousing/putInStore.vue @@ -56,7 +56,7 @@ 查询 重置 数量盘点 - 编号盘点 + 编码盘点 @@ -157,142 +157,178 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 点击填充 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 点击填充 + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + -