退役申请及审批

This commit is contained in:
syruan 2025-11-16 23:57:57 +08:00
parent f5c75d7506
commit ed945d0ecc
8 changed files with 895 additions and 1 deletions

View File

@ -13,6 +13,9 @@ public class TypeConstants {
/** 维修单号的开头字母 */
public static final String REPAIR_TASK_TYPE_LABEL = "W";
/** 退役单号的开头字母 */
public static final String SCRAP_TASK_TYPE_LABEL = "Y";
/** 退料单号的开头字母 */
public static final String BACK_TASK_TYPE_LABEL = "T";
}

View File

@ -0,0 +1,62 @@
package com.bonus.material.scrap.controller;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.material.scrap.domain.ToBeScrap;
import com.bonus.material.scrap.service.ToBeScrapService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/deviceRetireApply")
public class ToBeScrapController extends BaseController {
@Resource
private ToBeScrapService toBeScrapService;
@PostMapping("/submitTask")
@ApiOperation(value = "新增退役任务申请")
public AjaxResult submitTask(@RequestBody ToBeScrap bean) {
return toBeScrapService.addScrapData(bean);
}
@GetMapping("/list")
@ApiOperation(value = "获取报废申请列表")
public TableDataInfo getScrapApplyList(ToBeScrap bean) {
return getDataTable(toBeScrapService.getScrapApplyList(bean));
}
@PostMapping("/audit")
@ApiOperation(value = "审批退役任务明细")
public AjaxResult auditData(@RequestBody ToBeScrap bean) {
return toBeScrapService.auditData(bean);
}
@GetMapping("/detail/{id}")
@ApiOperation(value = "获取报废详情明细")
public AjaxResult getScrapDetailsList(@PathVariable("id") Long id) {
ToBeScrap bean = new ToBeScrap();
bean.setId(id);
return AjaxResult.success(toBeScrapService.getScrapDetailsList(bean));
}
@DeleteMapping("/deleteTask/{id}")
@ApiOperation(value = "删除退役任务")
public AjaxResult deleteChangeInfo(@PathVariable("id") Long id) {
return toBeScrapService.deleteChangeInfo(id);
}
@GetMapping("/scrapItemList")
@ApiOperation(value = "获取在库的装备、工具列表")
public TableDataInfo getInStockList(ToBeScrap bean) {
startPage();
List<ToBeScrap> inStockList = toBeScrapService.getInStockList(bean);
return getDataTable(inStockList);
}
}

View File

@ -0,0 +1,167 @@
package com.bonus.material.scrap.domain;
import com.bonus.common.biz.domain.BmFileInfo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class ToBeScrap {
/**
* 设备主键ID
*/
private Long id;
/**
* 变更任务表主键
*/
private Long changeId;
/**
* 用作key
*/
private String keyId;
/**
* 类型工具装备
*/
private String type;
/**
* 类型id
*/
private String typeId;
/**
* 设备类型 1-装备2-工具
*/
private String devType;
/**
* 类目
*/
private String groupName;
/**
* 名称
*/
private String typeName;
/**
* 规格型号
*/
private String typeModelName;
/**
* 管理类型:数量管理编码管理
*/
private String manageMode;
/**
* 设备编码
*/
private String devCode;
/**
* 任务编码
*/
private String code;
/**
* 在库数量
*/
private BigDecimal inStockNum;
/**
* 报废数量
*/
private BigDecimal scrapNum;
/**
* 报废附件URL
*/
private String scrapUrl;
/**
* 创建人昵称
*/
private String createUser;
/**
* 创建人ID
*/
private Long CreateBy;
/**
* 是否报废
*/
private String isScrap;
/**
* 是否报废
*/
private Integer isScrapFilter;
/**
* 退役时间
*/
private String scrapTime;
/**
* 退役原因
*/
private String reasonVal;
/**
* 附件
*/
private List<BmFileInfo> bmFileInfos;
/**
* 退役明细列表
*/
private List<ToBeScrap> toBeScrapList;
/**
* 装备数
*/
private BigDecimal equipmentNum;
/**
* 工具数
*/
private BigDecimal toolNum;
/**
* 状态
*/
private String status;
/**
* 创建时间
*/
private String createTime;
/**
* 开始时间(查询条件)
*/
private String startTime;
/**
* 结束时间(查询条件)
*/
private String endTime;
/**
* 审批状态
*/
private String reviewStatus;
/**
* 操作类型 add新增 edit编辑
*/
private String operationType;
}

View File

@ -0,0 +1,86 @@
package com.bonus.material.scrap.mapper;
import com.bonus.material.devchange.domain.CsDeviceInfo;
import com.bonus.material.repair.domain.ToBeRepair;
import com.bonus.material.scrap.domain.ToBeScrap;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface ScrapMapper {
/**
* 获取申请编号
* @param year
* @param month
* @param type 任务类型
*/
int getMonthMaxOrderByDate(@Param("year") String year, @Param("month") String month, @Param("type") Integer type);
/**
* 审批明细数据
*/
int auditData(ToBeScrap toBeScrap);
/**
* 查询待审批条数
*/
int selectCountByChangeId(@Param("changeId") Long changeId);
/**
* 删除任务
*/
int deleteChangeInfo(@Param("id") Long id);
/**
* 修改任务状态
*/
int updateChangeStatus(@Param("changeId") Long changeId, @Param("reviewStatus") String reviewStatus);
/**
* 新增工具生命周期数据
*/
int addToolLifecycleByRepair(ToBeScrap beScrap);
/**
* 更新装备信息
*/
int updateMaDevInfo(ToBeScrap toBeScrap);
/**
* 更新工具台账
*/
int updateToolLifecycle(ToBeScrap toBeScrap);
/**
* 新增退役任务
*/
int addDeviceChangeApply(CsDeviceInfo deviceInfo);
/**
* 新增退役任务明细
*/
int addScrapChangeApplyDetails(ToBeScrap bean);
/**
* 获取在库的装备工具列表
*/
List<ToBeScrap> getInStockList(ToBeScrap bean);
/**
* 获取报废申请列表
*/
List<ToBeScrap> getScrapApplyList(ToBeScrap bean);
/**
* 获取报废详情明细
*/
List<ToBeScrap> getScrapDetailsList(ToBeScrap bean);
/**
* 根据设备类型和编号查询
*/
ToBeScrap selectByTypeIdAndCode(ToBeScrap toBeScrap);
}

View File

@ -0,0 +1,40 @@
package com.bonus.material.scrap.service;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.repair.domain.ToBeRepair;
import com.bonus.material.scrap.domain.ToBeScrap;
import java.util.List;
public interface ToBeScrapService {
/**
* 删除任务
*/
AjaxResult deleteChangeInfo(Long id);
/**
* 审批任务明细
*/
AjaxResult auditData(ToBeScrap bean);
/**
* 新增报废退役任务
*/
AjaxResult addScrapData(ToBeScrap bean);
/**
* 获取在库的装备工具列表
*/
List<ToBeScrap> getInStockList(ToBeScrap bean);
/**
* 获取报废申请列表
*/
List<ToBeScrap> getScrapApplyList(ToBeScrap bean);
/**
* 获取报废详情明细
*/
List<ToBeScrap> getScrapDetailsList(ToBeScrap bean);
}

View File

@ -0,0 +1,223 @@
package com.bonus.material.scrap.service.impl;
import cn.hutool.core.util.StrUtil;
import com.bonus.common.core.constant.Constants;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.common.constants.TypeConstants;
import com.bonus.material.common.enums.TypeEnums;
import com.bonus.material.devchange.domain.CsDeviceInfo;
import com.bonus.material.repair.domain.ToBeRepair;
import com.bonus.material.scrap.domain.ToBeScrap;
import com.bonus.material.scrap.mapper.ScrapMapper;
import com.bonus.material.scrap.service.ToBeScrapService;
import org.apache.commons.collections4.CollectionUtils;
import org.hibernate.validator.internal.util.StringHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Service
public class ToBeScrapServiceImpl implements ToBeScrapService {
@Resource
private ScrapMapper scrapMapper;
/**
* 删除任务
*/
@Override
public AjaxResult deleteChangeInfo(Long id) {
if (Objects.isNull(id)) {
return AjaxResult.error("请求参数异常!");
}
int deleted = scrapMapper.deleteChangeInfo(id);
return deleted > 0 ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
}
/**
* 审批退役任务明细
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult auditData(ToBeScrap bean) {
try {
if (Objects.isNull(bean)) {
return AjaxResult.error("请求参数异常!");
}
if (CollectionUtils.isEmpty(bean.getToBeScrapList())) {
return AjaxResult.error("请选择要审批的数据");
}
String username = SecurityUtils.getLoginUser().getSysUser().getNickName();
Long userId = SecurityUtils.getLoginUser().getUserid();
for (ToBeScrap toBeScrap : bean.getToBeScrapList()) {
if (StrUtil.isNotBlank(toBeScrap.getReviewStatus())) {
if (!StrUtil.equalsAny(toBeScrap.getReviewStatus(), "1", "2")) {
throw new ServiceException("审批状态异常");
}
toBeScrap.setCreateUser(username);
int res = scrapMapper.auditData(toBeScrap);
if (res < 1) {
throw new ServiceException("数据审批失败");
}
// 如果是审批通过需要增加周期表数据以及更新台账信息
if (Objects.equals("1", toBeScrap.getReviewStatus())) {
if (Objects.equals("工具", toBeScrap.getType())) {
// 根据typeId和code查询台账信息
ToBeScrap bean1 = scrapMapper.selectByTypeIdAndCode(toBeScrap);
if (bean1 != null && bean1.getId() > 0){
//1添加周期表数据
ToBeScrap bean2 = new ToBeScrap();
bean2.setId(bean1.getId());
bean2.setCreateBy(userId);
bean2.setCreateUser(username);
bean2.setCode(toBeScrap.getDevCode());
bean2.setDevCode(toBeScrap.getDevCode());
bean2.setScrapNum(toBeScrap.getScrapNum());
bean2.setIsScrap("1");
bean2.setIsScrapFilter(1);
int addedToolLifecycle = scrapMapper.addToolLifecycleByRepair(bean2);
if (addedToolLifecycle < 1) {
throw new ServiceException("添加工具周期表数据失败");
}
// 2更新工具台账表
int updatedToolLifecycle = scrapMapper.updateToolLifecycle(bean2);
if (updatedToolLifecycle <= 0) {
throw new ServiceException("更新工具台账信息失败");
}
}
} else if (Objects.equals("装备", toBeScrap.getType())) {
//更新台账信息
toBeScrap.setCreateBy(userId);
toBeScrap.setIsScrapFilter(1);
int updateDevInfos = scrapMapper.updateMaDevInfo(toBeScrap);
if (updateDevInfos <= 0){
throw new ServiceException("更新台账信息失败");
}
} else {
throw new ServiceException("设备类型异常");
}
}
} else {
throw new ServiceException("审批状态为空,请检查!");
}
}
// 明细审核完成后根据审批数量去修改外层任务状态
int pendingReviewCount = scrapMapper.selectCountByChangeId(bean.getId());
if (pendingReviewCount > 0) {
int res = scrapMapper.updateChangeStatus(bean.getId(), "1");
if (res < 1) {
throw new ServiceException("更新任务状态失败");
}
} else if (pendingReviewCount == 0) {
int res = scrapMapper.updateChangeStatus(bean.getId(), "2");
if (res < 1) {
throw new ServiceException("更新任务状态失败");
}
}
return AjaxResult.success("审批成功");
} catch (Exception e) {
System.err.println(e.getMessage());
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return AjaxResult.error("审核失败");
}
}
/**
* 新增报废退役任务
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult addScrapData(ToBeScrap bean) {
try {
if (bean.getToBeScrapList().isEmpty()) {
return AjaxResult.error("请添加退役明细数据");
}
if (Objects.isNull(bean.getOperationType()) || !StrUtil.equalsAny(bean.getOperationType(), "add", "edit")) {
return AjaxResult.error("操作类型异常!");
}
// 如果是编辑操作那么就直接把之前的任务删掉重新建立
if (Objects.equals("edit", bean.getOperationType())) {
scrapMapper.deleteChangeInfo(bean.getId());
}
String username = SecurityUtils.getLoginUser().getSysUser().getNickName();
//1创建退役任务单号
int thisMonthMaxOrder = scrapMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TypeEnums.TM_TASK_RETIRE.getTaskTypeId());
String code = genderTaskCode(thisMonthMaxOrder);
CsDeviceInfo deviceInfo = new CsDeviceInfo();
deviceInfo.setType(String.valueOf(TypeEnums.TM_TASK_RETIRE.getTaskTypeId()));
deviceInfo.setCode(code);
deviceInfo.setReviewStatus(Constants.LOGIN_SUCCESS_STATUS);
deviceInfo.setCreateUser(username);
// 添加任务
int num = scrapMapper.addDeviceChangeApply(deviceInfo);
if (num < 1) {
throw new ServiceException("添加任务失败");
}
Long changeId = deviceInfo.getId();
// 保存任务明细
for (ToBeScrap toBeScrap : bean.getToBeScrapList()) {
toBeScrap.setChangeId(changeId);
toBeScrap.setCreateUser(username);
if (CollectionUtils.isNotEmpty(toBeScrap.getBmFileInfos())) {
toBeScrap.setScrapUrl(toBeScrap.getBmFileInfos().get(0).getFileUrl());
}
int res = scrapMapper.addScrapChangeApplyDetails(toBeScrap);
if (res <= 0) {
throw new ServiceException("添加退役明细数据失败");
}
}
return AjaxResult.success("任务提交成功!");
} catch (Exception e) {
System.err.println(e.getMessage());
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return AjaxResult.error("申请失败");
}
}
/**
* 生成退役任务编号
* @param thisMonthMaxOrder 本月最大单号
* @return 任务单号
*/
private String genderTaskCode(int thisMonthMaxOrder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date nowDate = DateUtils.getNowDate();
String format = dateFormat.format(nowDate);
String result = format.replace("-", "");
return TypeConstants.SCRAP_TASK_TYPE_LABEL + result + String.format("-%04d", thisMonthMaxOrder + 1);
}
/**
* 获取在库的装备工具列表
*/
@Override
public List<ToBeScrap> getInStockList(ToBeScrap bean) {
return scrapMapper.getInStockList(bean);
}
/**
* 获取报废申请列表
*/
@Override
public List<ToBeScrap> getScrapApplyList(ToBeScrap bean) {
return scrapMapper.getScrapApplyList(bean);
}
/**
* 获取报废详情明细
*/
@Override
public List<ToBeScrap> getScrapDetailsList(ToBeScrap bean) {
return scrapMapper.getScrapDetailsList(bean);
}
}

View File

@ -3,6 +3,7 @@ package com.bonus.material.upOrDown.tool.entity;
import com.bonus.common.core.annotation.Excel;
import com.bonus.material.device.domain.vo.DevInfoPropertyVo;
import lombok.Data;
import org.apache.ibatis.type.Alias;
import java.math.BigDecimal;
import java.time.LocalDate;
@ -14,7 +15,7 @@ import java.util.List;
* @version 1.0
* Create by 2025/11/15 23:13
*/
@Alias("ToolTwoEntity")
@Data
public class ToolEntity {
/**

View File

@ -0,0 +1,312 @@
<?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.material.scrap.mapper.ScrapMapper">
<select id="getInStockList" resultType="com.bonus.material.scrap.domain.ToBeScrap">
SELECT
CONCAT(tl.id,'-','工具') as keyId,
tl.id,
'工具' AS type,
'2' as devType,
tl.type_id as typeId,
CONCAT(tt2.type_name, '/', tt3.type_name, '/', tt4.type_name) AS groupName,
tt4.type_name as typeName,
tt5.type_name as typeModelName,
CASE tl.manage_mode WHEN 0 THEN '编码管理' ELSE '数量管理' END manageMode,
tl.tool_code as `devCode`,
CASE tl.manage_mode WHEN 0 THEN IFNULL(tl.total_num, 0) ELSE IFNULL(tl.available_num, 0) END inStockNum
FROM
tool_ledger tl
LEFT JOIN tool_type tt5 on tt5.type_id = tl.type_id
LEFT JOIN tool_type tt4 on tt4.type_id = tt5.parent_id
LEFT JOIN tool_type tt3 on tt3.type_id = tt4.parent_id
LEFT JOIN tool_type tt2 on tt2.type_id = tt3.parent_id
WHERE ((tl.manage_mode = '1' AND tl.available_num IS NOT NULL AND tl.available_num > 0)
OR (tl.manage_mode = '0' AND tl.`status` = '0'))
<if test="typeName != null and typeName!=''">
AND tt4.type_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName!=''">
AND tt5.type_name like concat('%',#{typeModelName},'%')
</if>
<if test="code != null and code!=''">
AND tl.tool_code like concat('%',#{code},'%')
</if>
UNION
SELECT
CONCAT(mdi.ma_id,'-','装备') as keyId,
mdi.ma_id as id,
'装备' as type,
'1' as devType,
mdi.type_id as typeId,
CONCAT(mt2.type_name, '/', mt3.type_name, '/', mt4.type_name) AS groupName,
mdi.device_name as typeName,
mdi.item_type_model as typeModelName,
'编码管理' as manageMode,
mdi.`code` as `devCode`,
mdi.device_count as inStockNum
FROM
ma_dev_info mdi
LEFT JOIN ma_type mt5 on mt5.type_id = mdi.type_id
LEFT JOIN ma_type mt4 on mt4.type_id = mt5.parent_id
LEFT JOIN ma_type mt3 on mt3.type_id = mt4.parent_id
LEFT JOIN ma_type mt2 on mt2.type_id = mt3.parent_id
WHERE mdi.ma_status = '1'
<if test="typeName != null and typeName!=''">
AND mdi.device_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName!=''">
AND mdi.item_type_model like concat('%',#{typeModelName},'%')
</if>
<if test="code != null and code!=''">
AND mdi.`code` like concat('%',#{code},'%')
</if>
</select>
<select id="getScrapApplyList" resultType="com.bonus.material.scrap.domain.ToBeScrap">
SELECT
cdc.id,
cdc.code,
SUM(CASE cdcd.dev_type WHEN 1 THEN cdcd.num ELSE 0 END) as equipmentNum,
SUM(CASE cdcd.dev_type WHEN 2 THEN cdcd.num ELSE 0 END) as toolNum,
cdc.review_status as reviewStatus,
cdc.create_user as createUser,
cdc.create_time as createTime
FROM
cs_device_change cdc
LEFT JOIN cs_device_change_details cdcd ON cdcd.change_id = cdc.id
WHERE cdc.type = '3'
and cdc.del_flag='0'
<if test="reviewStatus != null and reviewStatus!=''">
AND cdc.review_status = #{reviewStatus}
</if>
<if test="startTime!=null and startTime!='' and endTime!=null and endTime!='' ">
AND cdc.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
GROUP BY cdc.id
ORDER BY cdc.create_time DESC
</select>
<select id="getScrapDetailsList" resultType="com.bonus.material.scrap.domain.ToBeScrap">
SELECT DISTINCT cdcd.id,cdcd.dev_type_id as typeId, 2 as devType,
'工具' as type,
CONCAT(tt2.type_name, '/', tt3.type_name, '/', tt4.type_name) AS groupName,
tt4.type_name as typeName,
tt5.type_name as typeModelName,
CASE
WHEN cdcd.dev_code is null THEN
'数量管理'
ELSE
'编码管理'
END manageMode,
cdcd.dev_code as `devCode`,
cdcd.num as scrapNum,
cdcd.is_scrap as isScrap,
cdcd.review_status as reviewStatus,
CASE cdcd.review_status
WHEN 0 THEN
'待审核'
WHEN 1 THEN
'通过'
WHEN 2 THEN
'驳回'
END status,
cdcd.repair_time as repairTime,
cdcd.reason_val as reasonVal,
CASE is_scrap
WHEN 0 THEN
repair_url
ELSE
reason_url
END url
FROM cs_device_change_details cdcd
LEFT JOIN tool_type tt5 on tt5.type_id = cdcd.dev_type_id
LEFT JOIN tool_type tt4 on tt4.type_id = tt5.parent_id
LEFT JOIN tool_type tt3 on tt3.type_id = tt4.parent_id
LEFT JOIN tool_type tt2 on tt2.type_id = tt3.parent_id
WHERE cdcd.change_id = #{id}
and cdcd.dev_type = '2'
and cdcd.del_flag = '0'
GROUP BY cdcd.id
UNION
SELECT DISTINCT cdcd.id,cdcd.dev_type_id as typeId, 1 as devType,
'装备' as type,
CONCAT(mt2.type_name, '/', mt3.type_name, '/', mt4.type_name) AS groupName,
mdi.device_name as typeName,
mdi.item_type_model as typeModelName,
CASE
WHEN cdcd.dev_code is null THEN
'数量管理'
ELSE
'编码管理'
END manageMode,
cdcd.dev_code as `devCode`,
cdcd.num as scrapNum,
cdcd.is_scrap as isScrap,
cdcd.review_status as reviewStatus,
CASE cdcd.review_status
WHEN 0 THEN
'待审核'
WHEN 1 THEN
'通过'
WHEN 2 THEN
'驳回'
END status,
cdcd.repair_time as repairTime,
cdcd.reason_val as reasonVal,
CASE is_scrap
WHEN 0 THEN
repair_url
ELSE
reason_url
END url
FROM cs_device_change_details cdcd
LEFT JOIN ma_dev_info mdi on mdi.type_id = cdcd.dev_type_id
LEFT JOIN ma_type mt5 on mt5.type_id = mdi.type_id
LEFT JOIN ma_type mt4 on mt4.type_id = mt5.parent_id
LEFT JOIN ma_type mt3 on mt3.type_id = mt4.parent_id
LEFT JOIN ma_type mt2 on mt2.type_id = mt3.parent_id
WHERE cdcd.change_id = #{id}
and cdcd.dev_type = '1'
and cdcd.del_flag = '0'
GROUP BY cdcd.id
</select>
<insert id="addDeviceChangeApply" keyProperty="id" useGeneratedKeys="true">
insert into cs_device_change(type, code, review_status, create_user, create_time, del_flag)
values (3, #{code}, #{reviewStatus}, #{createUser}, NOW(), '0')
</insert>
<insert id="addScrapChangeApplyDetails">
insert into cs_device_change_details(
change_id,
<if test="devCode != null and devCode!=''">dev_code,</if>
<if test="typeId != null and typeId!=''">dev_type_id,</if>
<if test="devType != null and devType!=''">dev_type,</if>
<if test="scrapNum != null">num,</if>
<if test="scrapNum != null">real_num,</if>
<if test="reasonVal != null and reasonVal!=''">reason_val,</if>
<if test="scrapUrl != null and scrapUrl!=''">reason_url,</if>
is_scrap,
<if test="createUser != null">create_user,</if>
review_status,
create_time
)
values (
#{changeId},
<if test="devCode != null and devCode!=''">#{devCode},</if>
<if test="typeId != null and typeId!=''">#{typeId},</if>
<if test="devType != null and devType!=''">#{devType},</if>
<if test="scrapNum != null">#{scrapNum},</if>
<if test="scrapNum != null">#{scrapNum},</if>
<if test="reasonVal != null and reasonVal!=''">#{reasonVal},</if>
<if test="scrapUrl != null and scrapUrl!=''">#{scrapUrl},</if>
1,
<if test="createUser != null">#{createUser},</if>
'0',
NOW()
)
</insert>
<select id="getMonthMaxOrderByDate" resultType="int">
select COUNT(*)
from cs_device_change
where
month (create_time) = #{month}
and year (create_time) = #{year}
and `type` = #{type}
</select>
<update id="auditData">
update cs_device_change_details
set review_status = #{reviewStatus},
review_by = #{createUser},
review_time = now()
where id = #{id}
</update>
<select id="selectByTypeIdAndCode" resultType="com.bonus.material.scrap.domain.ToBeScrap">
SELECT
tl.id,
CASE tl.manage_mode WHEN 0 THEN '编码管理' WHEN 1 THEN '数量管理' END manageMode
FROM
tool_ledger tl
WHERE
tl.type_id = #{typeId}
<if test="devCode != null and devCode!=''">
and tl.tool_code = #{devCode}
</if>
limit 1
</select>
<insert id="addToolLifecycleByRepair">
insert into tool_lifecycle(
ledger_id,
<if test="devCode != null and devCode != ''">tool_code,</if>
action_type,
<if test="scrapNum != null">change_num,</if>
status_before,
status_after,
<if test="createBy != null">operator_id,</if>
<if test="createUser != null">operator_name,</if>
operate_time,
create_time
)
values (
#{id},
<if test="devCode != null and devCode!=''">#{devCode},</if>
'退役',
<if test="scrapNum != null">#{scrapNum},</if>
'在库',
'退役',
<if test="createBy != null">#{createBy},</if>
<if test="createUser != null">#{createUser},</if>
NOW(),
NOW()
)
</insert>
<update id="updateToolLifecycle">
update
tool_ledger
set
available_num = available_num - #{scrapNum},
scrap_num = scrap_num + #{scrapNum},
status = '3',
update_time = now()
where
id = #{id}
</update>
<update id="updateMaDevInfo">
update
ma_dev_info
set
ma_status = '99',
<if test="createBy != null">
update_by = #{createBy},
</if>
update_time = now()
where
type_id = #{typeId} and code = #{devCode}
</update>
<select id="selectCountByChangeId" resultType="int">
select count(1) from cs_device_change_details where change_id = #{changeId} and review_status = 0
</select>
<update id="updateChangeStatus">
update cs_device_change set review_status = #{reviewStatus} where id = #{changeId}
</update>
<delete id="deleteChangeInfo">
update cs_device_change set del_flag = '2' where id = #{id}
</delete>
</mapper>