修试入库接口

This commit is contained in:
cwchen 2023-12-17 13:21:21 +08:00
parent 64ea54cb06
commit f7ea60d1aa
9 changed files with 606 additions and 0 deletions

View File

@ -0,0 +1,50 @@
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.RepairTestInputDetailVo;
import com.bonus.sgzb.material.domain.RepairTestInputDto;
import com.bonus.sgzb.material.domain.RepairTestInputVo;
import com.bonus.sgzb.material.service.RepairTestInputService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* @author 10488
* 修试入库
*/
@RestController
@RequestMapping("/RepairTestInput/")
public class RepairTestInputController extends BaseController {
@Resource(name = "RepairTestInputService")
private RepairTestInputService service;
@ApiOperation(value = "获取修试后入库列表")
@PostMapping("getRepairedList")
public TableDataInfo getRepairedList(RepairTestInputDto dto){
startPage();
List<RepairTestInputVo> list = service.getRepairedList(dto);
return getDataTable(list);
}
@ApiOperation(value = "获取修试后入库列表-详情")
@PostMapping("getRepairedDetailList")
public TableDataInfo getRepairedDetailList(RepairTestInputDto dto){
startPage();
List<RepairTestInputDetailVo> list = service.getRepairedDetailList(dto);
return getDataTable(list);
}
@ApiOperation(value = "修试后入库-入库操作")
@PostMapping("inputByType")
public AjaxResult inputByType(String params){
return service.inputByType(params);
}
}

View File

@ -0,0 +1,47 @@
package com.bonus.sgzb.material.domain;
import lombok.Data;
/**
* @author 10488
* 修试入库详细
*/
@Data
public class RepairTestInputDetailVo {
private int id;
/** 机具id*/
private Integer maId;
/** 规格ID*/
private Integer typeId;
/** 设备类型*/
private String typeName;
/** 规格型号*/
private String typeName2;
/** 管理方式(0编号 1计数)*/
private String manageType;
/** 数量*/
private double repairNum;
/** 编号*/
private String maCode;
/** 提交入库人员*/
private String updateBy;
/** 提交入库时间*/
private String updateTime;
/** 不通过原因*/
private String remark;
/** 状态*/
private String status;
}

View File

@ -0,0 +1,18 @@
package com.bonus.sgzb.material.domain;
import lombok.Data;
/**
* @author 10488
* 修试入库-前端传参
*/
@Data
public class RepairTestInputDto {
/** 任务id*/
private int taskId;
/** 关键字*/
private String keyWord;
}

View File

@ -0,0 +1,28 @@
package com.bonus.sgzb.material.domain;
import lombok.Data;
/**
* @author 10488
* 修试入库-Vo
*/
@Data
public class RepairTestInputVo {
private int id;
/** 维修单号*/
private String repairCode;
/** 工器具类型*/
private String maTypeName;
/** 维修人员*/
private String wxName;
/** 维修时间*/
private String wxTime;
/** 状态*/
private String taskStatus;
}

View File

@ -0,0 +1,45 @@
package com.bonus.sgzb.material.domain;
import lombok.Data;
/**
* @author 10488
* 修试入库-审核入库-前端传参
*/
@Data
public class RepairTestWarehousingDto {
/** 任务id*/
private String taskId;
/** id*/
private String id;
/** 审核类型 1 审核通过 2 驳回*/
private String checkType;
/** 类型 0.编号 1.计数*/
private String type;
/** 机具id*/
private String maId;
/** 类型规格id*/
private String typeId;
/** 不通过原因*/
private String remark;
/** 数量*/
private String repairNum;
/**更新时间*/
private String updateTime;
/** 更新者*/
private String updateBy;
/** 数据所属组织*/
private long companyId;
}

View File

@ -0,0 +1,108 @@
package com.bonus.sgzb.material.mapper;
import com.bonus.sgzb.material.domain.RepairTestInputDetailVo;
import com.bonus.sgzb.material.domain.RepairTestInputDto;
import com.bonus.sgzb.material.domain.RepairTestInputVo;
import com.bonus.sgzb.material.domain.RepairTestWarehousingDto;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
/**
* @author 10488
* 修试入库
*/
@Repository("RepairTestInputMapper")
public interface RepairTestInputMapper {
/**
* @param dto
* @return List<RepairTestInputVo>
* @description 获取修试后入库列表
* @author cwchen
* @date 2023/12/16 16:05
*/
List<RepairTestInputVo> getRepairedList(RepairTestInputDto dto);
/**
* @param dto
* @return List<RepairTestInputVo>
* @description 获取修试后入库-详情列表
* @author cwchen
* @date 2023/12/16 17:34
*/
List<RepairTestInputDetailVo> getRepairedDetailList(RepairTestInputDto dto);
/**
* @param dto
* @description 更新修试后入库-数据
* @author cwchen
* @date 2023/12/16 19:17
*/
void updateRepairInputDetails(RepairTestWarehousingDto dto);
/**
* @param dto
* @description 新增入库任务详细表-数据
* @author cwchen
* @date 2023/12/16 19:33
*/
void addInputApplyDetails(RepairTestWarehousingDto dto);
/**
* @param typeId
* @return Map<Object>
* @description 查询机具类型-库存数量
* @author cwchen
* @date 2023/12/16 20:24
*/
Map<String, Object> getMaTypeByNum(String typeId);
/**
* @param typeId
* @param num
* @description 更新机具类型-库存数量
* @author cwchen
* @date 2023/12/16 20:45
*/
void updateMaTypeNum(@Param("typeId") String typeId, @Param("num") double num);
/**
* @param ma_status
* @param status
* @return int
* @description 查询机具状态-在库的id
* @author cwchen
* @date 2023/12/16 20:52
*/
int getDicByMaStatusId(@Param("maStatus") String ma_status, @Param("status") String status);
/**
* @param dicId
* @param maId
* @description 管理方式为编号的需更新机具设备的机具状态
* @author cwchen
* @date 2023/12/16 20:59
*/
void updateMaMachineStatus(@Param("dicId") int dicId, @Param("maId") String maId);
/**
* @param dto
* @return List<Integer>
* @description 查询修试后入库的状态是否全部更新
* @author cwchen
* @date 2023/12/16 21:03
*/
Map<String, Object> getIsAllUpdate(RepairTestWarehousingDto dto);
/**
* @param dto
* @param dicId
* @description 更新任务表状态
* @author cwchen
* @date 2023/12/16 21:19
*/
void updateTmTaskStatus(@Param("params") RepairTestWarehousingDto dto, @Param("dictId") int dicId);
}

View File

@ -0,0 +1,41 @@
package com.bonus.sgzb.material.service;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.RepairTestInputDetailVo;
import com.bonus.sgzb.material.domain.RepairTestInputDto;
import com.bonus.sgzb.material.domain.RepairTestInputVo;
import java.util.List;
/**
* @author 10488
* 修试入库
*/
public interface RepairTestInputService {
/**
* @param dto
* @return List<RepairTestInputVo>
* @description 获取修试后入库列表
* @author cwchen
* @date 2023/12/16 16:03
*/
List<RepairTestInputVo> getRepairedList(RepairTestInputDto dto);
/**
* @param dto
* @return List<RepairTestInputDetailVo>
* @description 获取修试后入库列表-详情
* @author cwchen
* @date 2023/12/16 17:33
*/
List<RepairTestInputDetailVo> getRepairedDetailList(RepairTestInputDto dto);
/**
* @param params
* @return AjaxResult
* @description 修试后入库-入库操作
* @author cwchen
* @date 2023/12/16 18:35
*/
AjaxResult inputByType(String params);
}

View File

@ -0,0 +1,125 @@
package com.bonus.sgzb.material.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.bonus.sgzb.common.core.constant.HttpStatus;
import com.bonus.sgzb.common.core.utils.DateTimeHelper;
import com.bonus.sgzb.common.core.utils.StringUtils;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.security.utils.SecurityUtils;
import com.bonus.sgzb.material.domain.RepairTestInputDetailVo;
import com.bonus.sgzb.material.domain.RepairTestInputDto;
import com.bonus.sgzb.material.domain.RepairTestInputVo;
import com.bonus.sgzb.material.domain.RepairTestWarehousingDto;
import com.bonus.sgzb.material.mapper.RepairTestInputMapper;
import com.bonus.sgzb.material.service.RepairTestInputService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @author 10488
* 修试入库
*/
@Service("RepairTestInputService")
@Slf4j
public class RepairTestInputServiceImpl implements RepairTestInputService {
@Resource(name = "RepairTestInputMapper")
private RepairTestInputMapper mapper;
@Override
public List<RepairTestInputVo> getRepairedList(RepairTestInputDto dto) {
return mapper.getRepairedList(dto);
}
@Override
public List<RepairTestInputDetailVo> getRepairedDetailList(RepairTestInputDto dto) {
return mapper.getRepairedDetailList(dto);
}
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult inputByType(String params) {
try {
if (StringUtils.isEmpty(params)) {
return AjaxResult.error(HttpStatus.ERROR, "参数类型不正确");
}
List<RepairTestWarehousingDto> list = JSONObject.parseArray(params, RepairTestWarehousingDto.class);
Long companyId = SecurityUtils.getLoginUser().getSysUser().getCompanyId();
String updateTime = DateTimeHelper.getNowTime();
String updateBy = SecurityUtils.getLoginUser().getUsername();
for (RepairTestWarehousingDto dto : list) {
dto.setCompanyId(companyId);
dto.setUpdateTime(updateTime);
dto.setUpdateBy(updateBy);
if (Objects.equals("2", dto.getCheckType())) {
// 审核不通过-入库数量修改为0
dto.setRepairNum("0");
}
// 更新修试后入库数据
mapper.updateRepairInputDetails(dto);
if (Objects.equals("1", dto.getCheckType())) {
// 审核通过-更新入库任务详细表
mapper.addInputApplyDetails(dto);
// 查询机具类型-现有库存
Map<String, Object> map = mapper.getMaTypeByNum(dto.getTypeId());
// 更新机具类型-库存
String repairNum = StringUtils.isNotEmpty(dto.getRepairNum()) ? dto.getRepairNum() : "0";
double num = countNum(map.get("num"), repairNum);
mapper.updateMaTypeNum(dto.getTypeId(),num);
if(Objects.equals("0", dto.getType())){
// 查询机具状态-在库的id管理方式为编号的需更新机具设备的机具状态
int dicId = mapper.getDicByMaStatusId("ma_status","在库");
mapper.updateMaMachineStatus(dicId,dto.getMaId());
}
}
// 查询修试后入库的状态是否全部更新更新任务表状态
Map<String, Object> numMap = mapper.getIsAllUpdate(dto);
// 总量未审核数量入库数量驳回数量
int totalNum = Integer.parseInt(String.valueOf(numMap.get("num")));
int noCheckNum = Integer.parseInt(String.valueOf(numMap.get("noCheckNum")));
int passNum = Integer.parseInt(String.valueOf(numMap.get("passNum")));
int noPassNum = Integer.parseInt(String.valueOf(numMap.get("noPassNum")));
if(passNum == totalNum){
int dicId = mapper.getDicByMaStatusId("rk_task","入库完成");
mapper.updateTmTaskStatus(dto,dicId);
}else if(noPassNum > 0){
int dicId = mapper.getDicByMaStatusId("rk_task","入库驳回");
mapper.updateTmTaskStatus(dto,dicId);
}
}
} catch (Exception e) {
//手动回滚异常
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
log.error("修试后入库-入库操作", e);
return AjaxResult.error();
}
return AjaxResult.success();
}
/**
* @param num
* @param repairNum
* @return double
* @description 添加库存
* @author cwchen
* @date 2023/12/16 20:43
*/
public double countNum(Object num, String repairNum) {
BigDecimal value = new BigDecimal(new Double(0).toString());
BigDecimal repairNumValue = new BigDecimal(new Double(repairNum).toString());
value = value.add(repairNumValue);
if (Objects.nonNull(num)) {
BigDecimal numValue = new BigDecimal(new Double(String.valueOf(num)).toString());
value.add(numValue);
}
return value.doubleValue();
}
}

View File

@ -0,0 +1,144 @@
<?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">
<mapper namespace="com.bonus.sgzb.material.mapper.RepairTestInputMapper">
<!--新增入库任务详细表-数据-->
<insert id="addInputApplyDetails">
INSERT INTO input_apply_details
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="taskId != null and taskId != ''">task_id,</if>
<if test="maId != null and maId!=''">ma_id,</if>
<if test="typeId != null and typeId !=''">type_id,</if>
<if test="repairNum != null and repairNum!=''">input_num,</if>
input_type,
<if test="updateBy != null and updateBy != ''">create_by,</if>
<if test="updateTime != null and updateTime != ''">create_time,</if>
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null and updateTime != ''">update_time,</if>
<if test="companyId != null">company_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="taskId != null and taskId != ''">#{taskId},</if>
<if test="maId != null and maId!=''">#{maId},</if>
<if test="typeId != null and typeId !=''">#{typeId},</if>
<if test="repairNum != null and repairNum!=''">#{repairNum},</if>
'3',
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null and updateTime != ''">#{updateTime},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null and updateTime != ''">#{updateTime},</if>
<if test="companyId != null">#{companyId},</if>
</trim>
</insert>
<!--更新修试后入库-数据-->
<update id="updateRepairInputDetails">
UPDATE repair_input_details
<set>
<if test="repairNum != null and repairNum != ''">input_num = #{repairNum},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null and updateTime != ''">update_time = #{status},</if>
<if test="checkType != null and checkType != ''">`status` = #{checkType},</if>
<if test="remark != null and remark != ''">`remark` = #{remark}</if>
</set>
WHERE id = #{id}
</update>
<!--更新机具类型-库存数量-->
<update id="updateMaTypeNum">
UPDATE ma_type SET num = #{num} WHERE type_id = #{typeId}
</update>
<!--管理方式为编号的需更新机具设备的机具状态-->
<update id="updateMaMachineStatus">
UPDATE ma_machine SET ma_status = #{dicId} WHERE ma_id = #{maId}
</update>
<!--更新任务表状态-->
<update id="updateTmTaskStatus">
UPDATE tm_task SET task_status = #{dictId} WHERE task_id = #{params.taskId}
</update>
<!--获取修试后入库列表-->
<select id="getRepairedList" resultType="com.bonus.sgzb.material.domain.RepairTestInputVo">
SELECT ANY_VALUE(rid.task_id) AS id,
ANY_VALUE(tt.`code`) AS repairCode,
ANY_VALUE(GROUP_CONCAT(a.typeName)) AS maTypeName,
ANY_VALUE(tt2.create_by) AS wxName,
ANY_VALUE(tt2.create_time) AS wxTime,
ANY_VALUE(IFNULL(sd.`name`,'入库进行中')) AS taskStatus
FROM repair_input_details rid
LEFT JOIN tm_task tt ON rid.task_id = tt.task_id
LEFT JOIN sys_dic sd ON tt.task_status = sd.id
LEFT JOIN tm_task tt2 ON rid.repair_id = tt2.task_id
LEFT JOIN (
SELECT mt.type_id,mt3.type_name AS typeName,mt.manage_type
FROM ma_type mt
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id AND mt2.`level` = '3'
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id AND mt3.`level` = '2'
LEFT JOIN ma_type mt4 ON mt3.parent_id = mt4.type_id AND mt4.`level` = '1'
WHERE mt.`level` = '4'
)a ON rid.type_id = a.type_id
<where>
<if test="keyWord!=null and keyWord!=''">
(
INSTR(tt.`code`,#{keyWord}) > 0 OR
INSTR(tt2.create_by,#{keyWord}) > 0
)
</if>
</where>
GROUP BY rid.task_id
</select>
<!--获取修试后入库-详情列表-->
<select id="getRepairedDetailList" resultType="com.bonus.sgzb.material.domain.RepairTestInputDetailVo">
SELECT rid.id,
rid.ma_id AS maId,
rid.type_id AS typeId,
a.typeName,
a.typeName2,
rid.repair_num AS repairNum,
a.manage_type AS manageType,
mm.ma_code AS maCode,
rid.update_by AS updateBy,
rid.update_time AS updateTime,
rid.remark,
CASE rid.`status` WHEN '0' THEN '进行中' WHEN '1' THEN '已入库' WHEN '2' THEN '驳回' ELSE '进行中' END AS `status`
FROM repair_input_details rid
LEFT JOIN ma_machine mm ON rid.ma_id = mm.ma_id
LEFT JOIN (
SELECT mt.type_id,mt.type_name AS typeName,mt2.type_name AS typeName2,mt.manage_type
FROM ma_type mt
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id AND mt2.`level` = '3'
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id AND mt3.`level` = '2'
LEFT JOIN ma_type mt4 ON mt3.parent_id = mt4.type_id AND mt4.`level` = '1'
WHERE mt.`level` = '4'
)a ON rid.type_id = a.type_id
WHERE rid.task_id = #{taskId}
<if test="keyWord!=null and keyWord!=''">
AND (
INSTR(a.typeName,#{keyWord}) > 0 OR
INSTR(a.typeName2,#{keyWord}) > 0
)
</if>
</select>
<!--查询机具类型-库存数量-->
<select id="getMaTypeByNum" resultType="java.util.Map">
SELECT type_name AS typeName,
num
FROM ma_type WHERE type_id = #{typeId}
</select>
<!--查询机具状态-在库的id-->
<select id="getDicByMaStatusId" resultType="java.lang.Integer">
SELECT sd2.id,sd2.`name`
FROM sys_dic sd
LEFT JOIN sys_dic sd2 ON sd.id = sd2.p_id AND sd2.`name` = #{status}
WHERE sd.`value` = #{maStatus} AND sd.p_id = 0
</select>
<!--查询修试后入库的状态是否全部更新-->
<select id="getIsAllUpdate" resultType="java.util.Map">
SELECT COUNT(IF(status = '0' OR status IS NULL OR status = '',1,NULL)) AS noCheckNum,
COUNT(IF(status = '1',1,NULL)) AS passNum,
COUNT(IF(status = '2',1,NULL)) AS noPassNum,
COUNT(*) AS totalNum
FROM repair_input_details WHERE task_id = #{taskId}
</select>
</mapper>