盘点入库-数量入库

This commit is contained in:
mashuai 2024-04-02 13:19:59 +08:00
parent 956cfee621
commit a053608b78
5 changed files with 205 additions and 79 deletions

View File

@ -1,5 +1,6 @@
package com.bonus.sgzb.material.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -7,6 +8,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 表单类型表单集合
* @Author ma_sh
* @create 2024/3/28 17:53
*/
@ -14,26 +16,41 @@ import lombok.NoArgsConstructor;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("表单类型表单集合")
public class MachIneDto {
/**
* 判断为数量还是编号true为编号
*/
@ApiModelProperty(value = "判断为数量还是编号true为编号")
private Boolean isCode;
/**
* 主键id
*/
@ApiModelProperty(value = "主键id")
private Integer id;
/** 机具ID */
@ApiModelProperty(value = "机具ID")
private Long maId;
/**
* 类型id
*/
private String typeId;
/** 设备编号 */
@ApiModelProperty(value = "设备编号")
private String maCode;
/**
* 类型id
*/
@ApiModelProperty(value = "类型id")
private String typeId;
/**
* 主信息
*/
@ApiModelProperty(value = "主信息")
private Integer info;
/** 出厂编码 */
@ApiModelProperty(value = "出厂编码")
private String outFacCode;
@ -75,4 +92,28 @@ public class MachIneDto {
*/
@ApiModelProperty(value = "备注")
private String remarks;
/**
* 表单备注
*/
@ApiModelProperty(value = "表单备注")
private String remark;
/**
* 数量
*/
@ApiModelProperty(value = "数量")
private Double num;
/**
* 检验人
*/
@ApiModelProperty(value = "检验人")
private String checkMan;
/**
* 入库数量
*/
@ApiModelProperty(value = "入库数量")
private Double putInStoreNum;
}

View File

@ -1,6 +1,8 @@
package com.bonus.sgzb.material.domain;
import com.bonus.sgzb.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -15,85 +17,107 @@ import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("新增盘点入库接口实体类dto")
public class SavePutInfoDto extends BaseEntity {
/**
* 判断为数量还是编号true为编号
*/
@ApiModelProperty(value = "判断为数量还是编号true为编号")
private Boolean isCode;
/**
* 主键id
*/
@ApiModelProperty(value = "主键id")
private Integer id;
/**
* 类型id
*/
@ApiModelProperty(value = "类型id")
private String typeId;
/**
* 主信息
*/
@ApiModelProperty(value = "主信息")
private Integer info;
/**
* 数量
*/
@ApiModelProperty(value = "数量")
private Double num;
/**
* 库房
*/
@ApiModelProperty(value = "库房")
private Integer ram;
/**
* 设备工器具类型
*/
@ApiModelProperty(value = "设备工器具类型")
private Integer type;
/**
* 设备主键
*/
@ApiModelProperty(value = "设备主键")
private Integer machine;
/**
* 入库形式
*/
@ApiModelProperty(value = "入库形式")
private String putInType;
/**
* 盘点入库单号
*/
@ApiModelProperty(value = "盘点入库单号")
private String code;
/**
* 单位名称
*/
@ApiModelProperty(value = "单位名称")
private String unitId;
/**
* 工程名称
*/
@ApiModelProperty(value = "工程名称")
private String projectId;
/**
* 创建者
*/
@ApiModelProperty(value = "创建者")
private String creator;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
private String createDate;
/**
* 备注
*/
@ApiModelProperty(value = "备注")
private String remarks;
/**
* 表单类型集合
* 检验人
*/
@ApiModelProperty(value = "检验人")
private String checkMan;
/**
* 表单类型表单集合
*/
private List<MachIneDto> machIneDtoList;

View File

@ -47,7 +47,7 @@ public interface InventoryAndWarehousingMapper {
* @param
* @return
*/
int insertMachine(MachIneDto machIneDtoy);
int insertMachine(MachIneDto machIneDto);
int insertMachineLabel(MachIneDto machIneDto);
@ -58,5 +58,7 @@ public interface InventoryAndWarehousingMapper {
* @param code
* @return
*/
int selectById(String code);
int selectByCode(String code);
int selectById(Integer id);
}

View File

@ -47,20 +47,23 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult savePutInfo(SavePutInfoDto dto) {
log.info("新增入库盘点入参dto{}", dto);
Long userId = SecurityUtils.getLoginUser().getUserid();
dto.setCreator(userId.toString());
List<String> codeList = new ArrayList<>();
if (dto.getNum() != null) {
while (codeList.size() < dto.getNum()) {
String code = FieldGenerator.generateField();
int count = selectById(code);
int count = selectByCode(code);
if (count == 0) {
codeList.add(code);
}
}
}
int res = 0;
try {
//1. 判断是数量还是编号保存到不同表
//1.1 如果是编号
//1. 判断是数量还是编号入库保存到不同表
//1.1 如果是编号入库
if (dto.getIsCode()) {
/*插入ma_machinema_machine_label和ma_label_bind以及
ma_type_put_in_storage_info表和ma_type_put_in_storage_details表*/
@ -69,20 +72,20 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
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方法修改异常");
}
} else {
//2.插入ma_type_put_in_storage_info表和ma_type_put_in_storage_details表
res = insertPutInfo(dto);
if (res == 0) {
log.error("insertPutInfo方法插入异常");
throw new RuntimeException("insertPutInfo方法插入异常");
}
}
} catch (Exception e) {
log.error(e.getMessage());
// 添加事务回滚逻辑
@ -99,8 +102,8 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
* @param code
* @return
*/
private int selectById(String code) {
return inventoryAndWarehousingMapper.selectById(code);
private int selectByCode(String code) {
return inventoryAndWarehousingMapper.selectByCode(code);
}
/**
@ -115,10 +118,13 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
MachIneDto machIneDto = dto.getMachIneDtoList().get(i);
String code = codeList.get(i);
machIneDto.setCode(code);
machIneDto.setIsCode(dto.getIsCode());
machIneDto.setTypeId(dto.getTypeId());
machIneDto.setCreator(dto.getCreator());
machIneDto.setRemarks(dto.getRemarks());
machIneDto.setPutInType(dto.getPutInType());
machIneDto.setNum(dto.getNum());
machIneDto.setCheckMan(dto.getCheckMan());
num = inventoryAndWarehousingMapper.insertMachine(machIneDto);
if (num == 0) {
throw new RuntimeException("新增到ma_machine表失败");
@ -131,16 +137,27 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
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表失败");
num = getAnInt(machIneDto);
}
//插入ma_type_put_in_storage_info表
return num;
}
/**
* 方法抽取
* @param machIneDto
* @return
*/
private int getAnInt(MachIneDto machIneDto) {
int num;
//插入ma_type_put_in_storage_info表,返回主键id
num = inventoryAndWarehousingMapper.saveInfo(machIneDto);
if (num == 0) {
throw new RuntimeException("新增到ma_type_put_in_storage_info表失败");
}
//ma_type_put_in_storage_details表
num = inventoryAndWarehousingMapper.saveDetails(machIneDto);
if (num == 0) {
throw new RuntimeException("新增到ma_type_put_in_storage_details表失败");
}
return num;
}
@ -148,7 +165,6 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
/**
* 方法抽取追加ma_type表里面的num
*
* @param typeId
* @param num
* @return
@ -163,26 +179,16 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
* @param dto
* @return
*/
private int insertPutInfo(SavePutInfoDto dto, List<String> codeList) {
private int insertPutInfo(SavePutInfoDto dto) {
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表失败");
}
machIneDto.setRemarks(dto.getRemarks());
getAnInt(machIneDto);
//根据类型追加ma_type表里面的num
num = updateMaTypeInfo(machIneDto.getTypeId(), machIneDto.getPutInStoreNum());
}
return num;
}

View File

@ -1,11 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.sgzb.material.mapper.InventoryAndWarehousingMapper">
<insert id="saveDetails" useGeneratedKeys="true" keyProperty="id">
INSERT INTO ma_type_put_in_storage_details (NUM,
<trim prefix="" suffixOverrides=",">
<if test="id != null and id != ''">
INFO,
</if>
<if test="typeId != null and typeId != ''">
TYPE,
</if>
<if test="maId != null and maId != ''">
MACHINE,
</if>
@ -19,6 +25,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
VALUES (1,
<trim prefix="" suffixOverrides=",">
<if test="id != null and id != ''">
#{id},
</if>
<if test="typeId != null and typeId != ''">
#{typeId},
</if>
<if test="maId != null and maId != ''">
#{maId},
</if>
@ -31,24 +43,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
)
</insert>
<insert id="saveInfo">
<insert id="saveInfo" useGeneratedKeys="true" keyProperty="id">
INSERT INTO ma_type_put_in_storage_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != 0">ID,</if>
<if test="putInType != null and putInType != ''">PUT_IN_TYPE,</if>
<choose>
<when test="isCode and num != null and num != 0">
NUM,
</when>
<otherwise>
<if test="putInStoreNum != null and putInStoreNum != 0">
NUM,
</if>
</otherwise>
</choose>
<if test="creator != null and creator != ''">CREATOR,</if>
CREATE_DATE,
<if test="remarks != null and remarks != ''">REMARKS</if>
<choose>
<when test="isCode and remarks != null and remarks != ''">
REMARKS
</when>
<otherwise>
<if test="remark != null and remark != ''">
REMARKS
</if>
</otherwise>
</choose>
</trim>
VALUES
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != 0">#{id},</if>
<if test="putInType != null and putInType != ''">#{putInType},</if>
1,
<choose>
<when test="isCode and num != null and num != 0">
#{num},
</when>
<otherwise>
<if test="putInStoreNum != null and putInStoreNum != 0">
#{putInStoreNum},
</if>
</otherwise>
</choose>
<if test="creator != null and creator != ''">#{creator},</if>
sysdate(),
<if test="remarks != null and remarks != ''">#{remarks}</if>
<choose>
<when test="isCode and remarks != null and remarks != ''">
#{remarks}
</when>
<otherwise>
<if test="remark != null and remark != ''">
#{remark}
</if>
</otherwise>
</choose>
</trim>
</insert>
<insert id="insertMachine" useGeneratedKeys="true" keyProperty="maId">
@ -59,6 +105,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="code != null and code != ''">qr_code,</if>
<if test="buyPrice != null and buyPrice != ''">buy_price,</if>
<if test="maVender != null and maVender != ''">ma_vender,</if>
<if test="checkMan != null and checkMan != ''">check_man,</if>
<if test="outFacCode != null and outFacCode != ''">out_fac_code,</if>
<if test="thisCheckTime != null and thisCheckTime != ''">this_check_time,</if>
<if test="nextCheckTime != null and nextCheckTime != ''">next_check_time,</if>
@ -70,6 +117,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="code != null and code != ''">#{code},</if>
<if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if>
<if test="maVender != null and maVender != ''">#{maVender},</if>
<if test="checkMan != null and checkMan != ''">#{checkMan},</if>
<if test="outFacCode != null and outFacCode != ''">#{outFacCode},</if>
<if test="thisCheckTime != null and thisCheckTime != ''">#{thisCheckTime},</if>
<if test="nextCheckTime != null and nextCheckTime != ''">#{nextCheckTime},</if>
@ -116,35 +164,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert>
<update id="updateMaType">
UPDATE ma_type
SET num = num + #{num}
SET num = num + #{num},
update_time = now()
<where>
<if test="typeId != null "> and type_id = #{typeId}</if>
<if test="typeId != null ">and type_id = #{typeId}</if>
</where>
</update>
<select id="getList" resultType="com.bonus.sgzb.material.domain.PutInStorageBean">
SELECT
pisi.PUT_IN_TYPE as putInType,
SELECT pisi.PUT_IN_TYPE as putInType,
lot.lot_name as projectName,
bui.unit_name as unitName,
pisi.`CODE` as code,
mt2.type_name as typeName,
su.user_name as userName,
pisi.CREATE_DATE as createDate
FROM
ma_type_put_in_storage_info pisi
LEFT JOIN ma_type_put_in_storage_details pisd on pisi.id=pisd.INFO
LEFT JOIN bm_project_lot lot on lot.lot_id=pisi.PROJECT_ID
LEFT JOIN bm_unit_info bui on bui.unit_id=pisi.UNIT_ID
LEFT JOIN ma_type mt on mt.type_id=pisd.TYPE
LEFT JOIN ma_type mt2 on mt2.type_id=mt.parent_id
LEFT JOIN sys_user su on su.user_id=pisi.CREATOR
FROM ma_type_put_in_storage_info pisi
LEFT JOIN ma_type_put_in_storage_details pisd on pisi.id = pisd.INFO
LEFT JOIN bm_project_lot lot on lot.lot_id = pisi.PROJECT_ID
LEFT JOIN bm_unit_info bui on bui.unit_id = pisi.UNIT_ID
LEFT JOIN ma_type mt on mt.type_id = pisd.TYPE
LEFT JOIN ma_type mt2 on mt2.type_id = mt.parent_id
LEFT JOIN sys_user su on su.user_id = pisi.CREATOR
</select>
<select id="selectById" resultType="java.lang.Integer">
<select id="selectByCode" resultType="java.lang.Integer">
select count(*)
from ma_machine
<where>
<if test="code != null "> and qr_code = #{code}</if>
<if test="code != null ">and qr_code = #{code}</if>
</where>
</select>
<select id="selectById" resultType="java.lang.Integer">
select info from ma_type_put_in_storage_details
<where>
<if test="id != null">and ID = #{id}</if>
</where>
</select>
</mapper>