Bonus-Cloud-Material-Mall/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devchange/DevChangeMapper.xml

1268 lines
52 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.devchange.mapper.DevChangeMapper">
<insert id="addChangeInfo" keyProperty="id" useGeneratedKeys="true">
insert into cs_device_change(change_status, type, status, pro_code, pro_name,
pro_type, dev_num, voltage_level, use_unit, pro_province, pro_city,
pro_county, pro_location, create_time, create_user, del_flag, user_name,
user_phone, change_unit)
values ( #{changeStatus}, #{type}, #{status}, #{proCode}, #{proName}, #{proType}, #{devNum}, #{voltageLevel}
, #{useUint}
, #{proProvince}, #{proCity}, #{proCounty}, #{proLocation}, now(), #{createUser}, 0, #{userName}
, #{userName}, #{changeUnit})
</insert>
<insert id="addDetailsInfo">
insert into cs_device_change_details(change_id, dev_id, use_time, reason_id,
reason_val, remark,
repairman, repair_time, repair_content, del_flag, num, status)
values (#{changeId}, #{devId}, #{useTime}, #{reasonId}, #{reasonVal}, #{remark}, #{repairman}, #{repairTime},
#{repairContent}, 0, #{num}, #{status})
</insert>
<insert id="addDevChangeDetails">
insert into cs_device_detials(pro_id, dev_id, num, type, create_time, update_time)
values (#{proId}, #{devId}, #{num}, #{type}, now(), now())
</insert>
<update id="updateJson">
update ma_dev_info
set json_data=#{jsonData}
where ma_id = #{devId}
</update>
<update id="updateDevInfo">
update ma_dev_info
set xq_unit=#{useUint},
on_project=#{proCode},
change_status=#{changeStatus},
ma_status = #{changeStatus}
where ma_id = #{devId}
</update>
<update id="updateDevInfoData">
update ma_dev_info
set expiration_time = #{useTime}
where ma_id = #{devId}
</update>
<delete id="deleteDevChangeDetails">
delete
from cs_device_detials
where id = #{id}
</delete>
<!--xiugao1-->
<update id="updateChangeDetailsNum">
update cs_device_detials
set num=#{num}
where id = #{id}
</update>
<select id="getMaxFeature" resultType="java.lang.Integer">
select count(1) num
from ma_dev_info_properties
GROUP BY ma_id
ORDER BY num desc
limit 1
</select>
<select id="selectDevInfoList" resultType="com.bonus.material.devchange.domain.DevChangeVo">
select dev.ma_id devId,dev.device_name devName,dev.code devCode,dev.json_data,DATE(dev.production_date )
productDate ,dev.buy_price buyPrice ,dev.brand ,
mdq.next_check_time nextDate,mt.typeId, mt.unit_name unit,mt.maintenance_alarm_day ,
mt.proType,mt.level,mt.mainGx,mt.childGx,mt.devCategory ,mt.devSubcategory ,mt.devName,
mt.devModel ,bci.company_name compName,bci.operate_address orgName,IFNULL(pro.pro_name,'-') proName,
dev.on_project proId,dev.change_status AS status
FROM ma_dev_info dev
left join bm_company_info bci on bci.company_id=dev.on_company
INNER join ma_type_view mt on mt.typeId=dev.type_id
LEFT JOIN (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on
dev.ma_id=mdq.ma_id
left join jj_sing_project pro on pro.pro_code=dev.on_project
where is_active=1
<if test="proId!=null and proId!=''">
and dev.on_project=#{proId}
</if>
<if test="devName!=null and devName!=''">
and dev.device_name like concat('%',#{devName},'%')
</if>
<if test="typeId!=null and typeId!=''">
and mt.typeId=#{typeId}
</if>
<if test="status!=null and status!=''">
<if test='status=="2"'>
and dev.change_status in(2,3)
</if>
<if test='status!="2"'>
AND dev.change_status=#{status}
</if>
</if>
</select>
<select id="getDevPropertyList" resultType="com.bonus.material.device.domain.vo.DevInfoPropertyVo">
select property_name propertyName, property_value propertyValue
from ma_dev_info_properties
where ma_id = #{devId}
</select>
<select id="getProList" resultType="com.bonus.material.devchange.domain.JjProjectVo">
select pro_code proCode,
pro_name proName,
voltage,
org_name orgName,
mechanize_rate,
project_type proType,
project_type_name proTypeName,
province,
city,
county
from jj_sing_project
</select>
<select id="getChangeStatus" resultType="java.lang.String">
select change_status
from ma_dev_info
where ma_id = #{devId}
</select>
<select id="getDevChangeList" resultType="com.bonus.material.devchange.domain.CsDeviceChangeVo">
SELECT
cds.id,
cds.change_status AS changeStatus,
cds.type,
cds.lease_type,
cds.pro_code AS proCode,
cds.pro_name AS proName,
cds.pro_type AS proType,
cds.voltage_level AS voltageLevel,
cds.use_unit AS useUint,
cds.pro_province AS proProvince,
cds.pro_city AS proCity,
cds.pro_county AS proCounty,
CONCAT_WS('·', cds.pro_province, cds.pro_city, cds.pro_county) AS proLocation,
cds.create_time AS createTime,
cds.create_user AS createUser,
cds.del_flag,
cds.user_name AS userName,
cds.user_phone AS userPhone,
cds.change_unit AS changeUnit,
-- 修正点:使用 SUM 计算数量总和,并用 IFNULL 处理没有明细的情况
IFNULL(SUM(dcd.num), 0) AS devNum,
CASE
WHEN cds.change_status = 1 THEN '在库'
WHEN cds.change_status = 2 THEN '再用'
WHEN cds.change_status = 3 THEN '退役'
WHEN cds.change_status = 4 THEN '维修'
ELSE '未知'
END AS changeStatusName,
CASE
WHEN cds.type = 1 THEN '退库'
WHEN cds.type = 2 THEN '出库'
WHEN cds.type = 3 THEN '退役'
WHEN cds.type = 4 THEN '维修'
ELSE '未知'
END AS typeName
FROM
cs_device_change cds
LEFT JOIN cs_device_change_details dcd ON dcd.change_id = cds.id
WHERE
cds.del_flag = 0
<if test="keyWord!=null and keyWord!=''">
and (
cds.pro_name like concat('%',#{keyWord},'%') or
cds.voltage_level like concat('%',#{keyWord},'%') or
cds.use_unit like concat('%',#{keyWord},'%') or
cds.pro_province like concat('%',#{keyWord},'%') or
cds.pro_city like concat('%',#{keyWord},'%') or
cds.pro_county like concat('%',#{keyWord},'%') or
cds.create_user like concat('%',#{keyWord},'%') or
cds.pro_location like concat('%',#{keyWord},'%') or
cds.pro_code like concat('%',#{keyWord},'%')
)
</if>
<if test="type!=null and type!=''">
and cds.type=#{type}
</if>
<if test="startTime!=null and startTime!='' and endTime!=null and endTime!='' ">
and cds.create_time between #{startTime} and #{endTime}
</if>
GROUP BY
cds.id,
cds.change_status,
cds.type,
cds.lease_type,
cds.pro_code,
cds.pro_name,
cds.pro_type,
cds.voltage_level,
cds.use_unit,
cds.pro_province,
cds.pro_city,
cds.pro_county,
cds.pro_location,
cds.create_time,
cds.create_user,
cds.del_flag,
cds.user_name,
cds.user_phone,
cds.change_unit
ORDER BY
cds.create_time DESC
</select>
<select id="getChangeUnit" resultType="java.lang.String">
select bci.company_name compName
FROM ma_dev_info dev
left join bm_company_info bci on bci.company_id = dev.on_company
where is_active = 1
and bci.company_name is not null
and dev.ma_id = #{devId}
</select>
<select id="getChangeUnitById" resultType="java.lang.String">
select xq_unit
from ma_dev_info
where ma_id = #{devId}
</select>
<select id="getDevDetails" resultType="com.bonus.material.devchange.domain.DevChangeVo">
SELECT
dev.ma_id devId,
dev.device_name devName,
dev.CODE devCode,
dev.json_data,
DATE(dev.production_date) productDate,
dev.buy_price buyPrice,
dev.brand,
mdq.next_check_time nextDate,
mt.typeId,
mt.unit_name unit,
mt.maintenance_alarm_day,
mt.proType,
mt.LEVEL,
mt.mainGx,
mt.childGx,
mt.devCategory,
mt.devSubcategory,
dev.item_type_model AS devModel,
dcd.dev_type as type,
dcd.num as devNum,
dcd.use_start_time as useStartTime,
dcd.use_end_time as useEndTime,
dcd.use_time as useTime,
bci.company_name compName,
bci.operate_address orgName,
IFNULL(pro.pro_name, '-') proName,
dev.on_project proId,
dev.working_hours as workingHours,
dev.max_working_hours as maxWorkingHours
FROM
cs_device_change_details dcd
LEFT JOIN ma_dev_info dev ON dcd.dev_code = dev.code
LEFT JOIN bm_company_info bci ON bci.company_id = dev.on_company
INNER JOIN ma_type_view mt ON mt.typeId = dev.type_id
LEFT JOIN (SELECT max(next_check_time) next_check_time, ma_id FROM ma_dev_qc GROUP BY ma_id) mdq ON dev.ma_id = mdq.ma_id
LEFT JOIN jj_sing_project pro ON pro.pro_code = dev.on_project
WHERE
is_active = 1
AND dcd.change_id = #{id}
UNION ALL
SELECT
tl.id AS devId,
tt1.type_name AS devName,
ifnull (tl.tool_code,'/') AS devCode,
NULL AS json_data,
DATE(tl.production_date) AS productDate,
tl.origin_cost AS buyPrice,
NULL AS brand,
tl.next_check_date AS nextDate,
tl.type_id AS typeId,
tt.unit_name AS unit,
NULL AS maintenance_alarm_day,
NULL AS proType,
tt.`level` AS `LEVEL`,
tt4.type_name AS mainGx,
tt3.type_name AS childGx,
tt2.type_name AS devCategory,
tt1.type_name AS devSubcategory,
tt.type_name AS devModel,
dcd.dev_type AS type,
dcd.num AS devNum,
dcd.use_start_time AS useStartTime,
dcd.use_end_time AS useEndTime,
dcd.use_time as useTime,
bci.company_name AS compName,
bci.operate_address AS orgName,
-- 工具无项目关联,默认显示'-'
IFNULL(dc.pro_name, '-') proName,
dc.pro_code AS proId,
'' AS workingHours,
'' AS maxWorkingHours
FROM
cs_device_change_details dcd -- 关联工具台账(变更详情的设备编码 = 工具编码)
LEFT JOIN cs_device_change dc on dc.id=dcd.change_id
LEFT JOIN tool_ledger tl
ON dcd.dev_type = '2'
AND dcd.dev_type_id = tl.type_id
AND (dcd.dev_code = '/' OR dcd.dev_code = tl.tool_code)
LEFT JOIN tool_type tt ON tl.type_id = tt.type_id
LEFT JOIN tool_type tt1 on tt.parent_id=tt1.type_id
LEFT JOIN tool_type tt2 on tt1.parent_id=tt2.type_id
LEFT JOIN tool_type tt3 on tt2.parent_id=tt3.type_id
LEFT JOIN tool_type tt4 on tt3.parent_id=tt4.type_id
AND tt.del_flag = '0' -- 关联公司信息(工具所属公司)
LEFT JOIN bm_company_info bci ON tl.company_id = bci.company_id
WHERE
dcd.change_id = #{id}
and dcd.dev_type='2'
</select>
<select id="getDevChangeDetailsList" resultType="com.bonus.material.devchange.domain.DevChangeDetailsVo">
select id,
pro_id proId,
dev_id devId,
num ,
type,
create_time,
update_time
from cs_device_detials
where dev_id=#{devId} and type=#{type}
<if test="proId!=null and proId!=''">
pro_id=#{proId}
</if>
</select>
<select id="getDevDetailsInfo" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
<!-- 装备部分:原有递归查询逻辑不变 -->
WITH RECURSIVE category_tree AS (
SELECT type_id FROM ma_type
WHERE type_id = #{categoryEquipment}
UNION ALL
SELECT t.type_id FROM ma_type t
INNER JOIN category_tree ct ON t.parent_id = ct.type_id
),
-- 工具分类递归查询独立CTE
tool_category_tree AS (
SELECT type_id FROM tool_type
WHERE type_id = #{toolTypeId}
UNION ALL
SELECT t.type_id FROM tool_type t
INNER JOIN tool_category_tree tct ON t.parent_id = tct.type_id
)
-- 装备表查询(原有逻辑不变)
SELECT
CASE
WHEN mt.level = 1 THEN mt.type_name
WHEN mt.level = 2 THEN CONCAT(mt1.type_name, '>', mt.type_name)
WHEN mt.level = 3 THEN CONCAT(mt2.type_name, '>', mt1.type_name, '>', mt.type_name)
WHEN mt.level = 4 THEN CONCAT(mt3.type_name, '>', mt2.type_name, '>', mt1.type_name, '>', mt.type_name)
WHEN mt.level = 5 THEN CONCAT(mt4.type_name, '>', mt3.type_name, '>', mt2.type_name, '>', mt1.type_name,'>',
mt.type_name)
WHEN mt.level = 6 THEN CONCAT(mt5.type_name, '>', mt4.type_name, '>', mt3.type_name, '>', mt2.type_name,'>',
mt1.type_name, '>', mt.type_name)
ELSE mt.type_name
END AS category,
mdi.device_name AS typeName,
mdi.item_type_model AS typeModelName,
mdi.manage_type AS manageType,
mdi.code AS devCode,
mdi.device_count AS storageNum,
1 AS devType,
mdi.type_id AS typeId,
mdi.ma_id AS id,
mdq.next_check_time AS nextMaintenanceDate,
IF(DATEDIFF(STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d'),
CURDATE()) &lt; 0,'已超过最大使用年限',CONCAT(IF(STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL
mdi.max_working_hours YEAR), '%Y-%m-%d') IS NOT
NULL
AND STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d') >= CURDATE(),
DATEDIFF(STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d'),
CURDATE()), 0), '天(',
IF(STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d') IS NOT NULL
AND STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d') >= CURDATE(),
TIMESTAMPDIFF(YEAR, CURDATE(),
STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d')), 0), '年)'
)) AS
remainingYears
FROM ma_dev_info mdi
LEFT JOIN (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on
mdi.ma_id=mdq.ma_id
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id
LEFT JOIN ma_type mt4 ON mt3.parent_id = mt4.type_id
LEFT JOIN ma_type mt5 ON mt4.parent_id = mt5.type_id
<where>
mdi.is_active = '1' AND mdi.ma_status = 1
<if test="categoryEquipment != null and categoryEquipment != ''">
AND mdi.type_id IN (SELECT type_id FROM category_tree)
</if>
<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="devCode!=null and devCode!=''">
AND mdi.code LIKE CONCAT('%',#{devCode},'%')
</if>
<if test="companyId!=null">
AND mdi.on_company = #{companyId}
</if>
<if test='devType == "2"'>
AND 1=0
</if>
</where>
UNION ALL
-- 工具表查询修复WHERE子句语法
SELECT
CONCAT(tt4.type_name, '>', tt3.type_name, '>', tt2.type_name) as category,
tt1.type_name AS typeName,
tt.type_name AS typeModelName,
tl.manage_mode AS manageType,
IFNULL(tl.tool_code,'/') AS devCode,
IFNULL(tl.available_num, 0) AS storageNum,
2 AS devType,
tl.type_id AS typeId,
tl.id AS id,
null AS nextMaintenanceDate,
'-' AS remainingYears
FROM tool_ledger tl
LEFT JOIN tool_type tt ON tl.type_id = tt.type_id
LEFT JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
LEFT JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
LEFT JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
LEFT JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
<where>
-- 核心修复先加一个恒成立条件避免WHERE后直接接AND
1 = 1
-- 工具分类递归筛选(可选)
<if test="toolTypeId != null and toolTypeId != ''">
AND tl.type_id IN (SELECT type_id FROM tool_category_tree)
</if>
-- 原有查询条件保留均用AND连接
<if test="typeName!=null and typeName!=''">
AND tt1.type_name LIKE CONCAT('%',#{typeName},'%')
</if>
<if test="typeModelName!=null and typeModelName!=''">
AND tt.type_name LIKE CONCAT('%',#{typeModelName},'%')
</if>
<if test="devCode!=null and devCode!=''">
AND tl.tool_code LIKE CONCAT('%',#{devCode},'%')
</if>
<if test="companyId!=null">
AND tl.company_id = #{companyId}
</if>
<if test="manageType!=null">
AND tl.manage_mode = #{manageType}
</if>
<if test='devType == "1"'>
AND 1=0
</if>
</where>
</select>
<select id="getMonthMaxOrderByDate" resultType="java.lang.Integer">
select COUNT(*) from cs_device_change
where
month(create_time) = #{month} and year(create_time) = #{year}
<if test="taskType != null and taskType !=''">
and type = #{taskType}
</if>
</select>
<select id="getDevInfoById" resultType="com.bonus.material.devchange.domain.CsDeviceInfo">
select
id as id,
type as type,
lease_type as leaseType,
pro_code as proCode,
pro_name as proName,
pro_type as proType,
voltage_level as voltageLevel,
use_unit as useUnit,
pro_province as proProvince,
pro_city as proCity,
pro_county as proCounty,
use_time as useTime,
code as code,
use_start_time as useStartTime,
use_end_time as useEndTime,
CASE
-- 已完成:所有子表记录 is_finished = 1
WHEN NOT EXISTS (
SELECT 1
FROM cs_device_change_details cdc1
WHERE cdc1.change_id = #{id}
AND cdc1.del_flag = '0'
AND cdc1.is_finished &lt;&gt; '1' -- 不存在非1的记录
) THEN '3'
-- 待出库:所有子表记录 is_finished = 0
WHEN NOT EXISTS (
SELECT 1
FROM cs_device_change_details cdc2
WHERE cdc2.change_id = #{id}
AND cdc2.del_flag = '0'
AND cdc2.is_finished &lt;&gt; '0' -- 不存在非0的记录
) THEN '1'
-- 其余情况:出库中(包含 is_finished=2 或其他值)
ELSE '2'
END AS taskStatus
from cs_device_change
where id = #{id}
</select>
<select id="getDevDetailsById" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
SELECT id AS detailsId,
dev_code AS devCode,
dev_type AS devType,
dev_type_id AS typeId,
num AS num,
use_time AS useTime,
use_start_time AS useStartTime,
use_end_time AS useEndTime,
IFNULL(real_num, 0) AS realNum,
is_finished AS isFinished
FROM cs_device_change_details
where change_id = #{id}
and del_flag = '0'
</select>
<select id="getList" resultType="com.bonus.material.devchange.domain.CsDeviceInfo">
SELECT
cd.id AS id,
cd.type AS type,
cd.lease_type AS leaseType,
cd.pro_code AS proCode,
cd.pro_name AS proName,
cd.pro_type AS proType,
cd.voltage_level AS voltageLevel,
cd.use_unit AS useUnit,
cd.pro_province AS proProvince,
cd.pro_city AS proCity,
cd.pro_county AS proCounty,
cd.use_time AS useTime,
cd.CODE AS CODE,
cd.review_status AS taskStatus,
cd.create_user AS createBy,
cd.create_time AS createTime,
SUM(IF( cdc.dev_type = '1', cdc.num, 0 )) AS devNum,
SUM(IF( cdc.dev_type = '2', cdc.num, 0 )) AS toolNum,
cd.company_id AS companyId
FROM
cs_device_change cd
LEFT JOIN cs_device_change_details cdc ON cd.id = cdc.change_id
WHERE
cdc.del_flag = '0' and cd.type = '2'
and cd.del_flag = '0'
<if test="taskStatus != null and taskStatus != ''">
and cd.review_status = #{taskStatus}
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND cd.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
<if test="proName != null and proName != ''">
and cd.pro_name = #{proName}
</if>
<if test="proCode != null and proCode != ''">
and cd.pro_code = #{proCode}
</if>
<if test="companyId != null">
and cd.company_id = #{companyId}
</if>
GROUP BY
cd.id
ORDER BY
-- 实现自定义状态排序:审核中(2) > 已驳回(1) > 已通过(0)
CASE cd.review_status
WHEN 2 THEN 1 -- 已驳回 -> 排序值为 0
WHEN 1 THEN 2 -- 已通过 -> 排序值为 2
WHEN 0 THEN 0 -- 待审核 -> 排序值为 1
ELSE 3 -- 其他状态排在最后
END ASC,
-- 按申请时间降序排序(后申请的在前)
cd.create_time DESC
</select>
<select id="getTypeMaDevInfo" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
SELECT
CASE
WHEN mt.level = 1 THEN mt.type_name
WHEN mt.level = 2 THEN CONCAT(mt1.type_name, '>', mt.type_name)
WHEN mt.level = 3 THEN CONCAT(mt2.type_name, '>', mt1.type_name, '>', mt.type_name)
WHEN mt.level = 4 THEN CONCAT(mt3.type_name, '>', mt2.type_name, '>', mt1.type_name, '>',
mt.type_name)
WHEN mt.level = 5 THEN CONCAT(mt4.type_name, '>', mt3.type_name, '>', mt2.type_name, '>',
mt1.type_name,'>', mt.type_name)
WHEN mt.level = 6 THEN CONCAT(mt5.type_name, '>', mt4.type_name, '>', mt3.type_name, '>',
mt2.type_name,'>', mt1.type_name, '>', mt.type_name)
ELSE mt.type_name
END AS category,
mdi.device_name AS typeName,
mdi.item_type_model AS typeModelName,
mdi.manage_type AS manageType,
mdi.code AS devCode,
SUM(CASE WHEN mdi.ma_status = 1 THEN 1 ELSE 0 END) AS storageNum,
1 AS devType,
mdi.type_id AS typeId,
mdi.ma_id AS id,
IF(DATEDIFF(STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d'),
CURDATE()) &lt; 0,'已超过最大使用年限',CONCAT(IF(STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL
mdi.max_working_hours YEAR), '%Y-%m-%d') IS NOT
NULL
AND STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d') >= CURDATE(),
DATEDIFF(STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d'),
CURDATE()), 0), '天(',
IF(STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d') IS NOT NULL
AND STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d') >= CURDATE(),
TIMESTAMPDIFF(YEAR, CURDATE(),
STR_TO_DATE(DATE_ADD(mdi.production_date, INTERVAL mdi.max_working_hours YEAR), '%Y-%m-%d')), 0), '年)'
)) AS
remainingYears
FROM ma_dev_info mdi
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id
LEFT JOIN ma_type mt4 ON mt3.parent_id = mt4.type_id
LEFT JOIN ma_type mt5 ON mt4.parent_id = mt5.type_id
where
mdi.is_active = '1' and mdi.type_id = #{typeId}
<if test="devCode != null and devCode != ''">
and mdi.code = #{devCode}
</if>
LIMIT 1
</select>
<select id="getTypeToolInfo" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
SELECT CONCAT(tt4.type_name, '>', tt3.type_name, '>', tt2.type_name) as category,
tt1.type_name as typeName,
tt.type_name as typeModelName,
tl.manage_mode as manageType,
IFNULL(tl.tool_code,'/') as devCode,
tl.available_num as storageNum,
2 as devType,
tl.type_id as typeId,
tl.id as id
FROM tool_ledger tl
LEFT JOIN tool_type tt ON tl.type_id = tt.type_id
LEFT JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
LEFT JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
LEFT JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
LEFT JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
where
tl.type_id = #{typeId}
<if test="devCode != null and devCode != ''">
and tl.tool_code = #{devCode}
</if>
LIMIT 1
</select>
<select id="getOutboundList" resultType="com.bonus.material.devchange.domain.CsDeviceInfo">
SELECT *
FROM (
-- 原查询(包含 outStockStatus 计算)
SELECT
cd.id AS id,
cd.type AS type,
cd.lease_type AS leaseType,
cd.pro_code AS proCode,
cd.pro_name AS proName,
cd.pro_type AS proType,
cd.voltage_level AS voltageLevel,
cd.use_unit AS useUnit,
cd.pro_province AS proProvince,
cd.pro_city AS proCity,
cd.pro_county AS proCounty,
cd.use_time AS useTime,
cd.CODE AS CODE,
cd.create_user AS createBy,
cd.create_time AS createTime,
SUM(IF(cdc.dev_type = '1', cdc.num, 0)) AS devNum,
SUM(IF(cdc.dev_type = '2', cdc.num, 0)) AS toolNum,
CASE
-- 已完成:所有子表记录 is_finished = 1
WHEN NOT EXISTS (
SELECT 1
FROM cs_device_change_details cdc1
WHERE cdc1.change_id = cd.id
AND cdc1.del_flag = '0'
AND cdc1.is_finished &lt;&gt; '1' -- 不存在非1的记录
) THEN '3'
-- 待出库:所有子表记录 is_finished = 0
WHEN NOT EXISTS (
SELECT 1
FROM cs_device_change_details cdc2
WHERE cdc2.change_id = cd.id
AND cdc2.del_flag = '0'
AND cdc2.is_finished &lt;&gt; '0' -- 不存在非0的记录
) THEN '1'
-- 其余情况:出库中(包含 is_finished=2 或其他值)
ELSE '2'
END AS taskStatus,
cd.company_id AS companyId
FROM cs_device_change cd
LEFT JOIN cs_device_change_details cdc
ON cd.id = cdc.change_id
AND cdc.del_flag = '0'
WHERE cd.review_status = '2'
AND cd.type = '2'
AND cd.lease_type = '0'
GROUP BY
cd.id
) AS temp
<where>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND temp.createTime BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
<if test="proName != null and proName != ''">
AND temp.proName LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="taskStatus != null and taskStatus != ''">
AND temp.taskStatus = #{taskStatus}
</if>
<if test="companyId != null and taskStatus != ''">
AND temp.companyId = #{companyId}
</if>
</where>
GROUP BY temp.id
ORDER BY temp.createTime
DESC
</select>
<select id="getOutAllList" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
SELECT COALESCE(
CASE
WHEN cdcd.dev_type = '1' THEN CONCAT(a.ma_id, '')
WHEN cdcd.dev_type = '2' THEN CONCAT(b.id, '')
ELSE ''
END, ''
) AS id,
cdcd.dev_type AS devType,
COALESCE(
CASE
WHEN cdcd.dev_type = '1' THEN CONCAT(a.device_name, '')
WHEN cdcd.dev_type = '2' THEN CONCAT(tt1.type_name, '')
ELSE ''
END, ''
) AS typeName,
COALESCE(cdcd.num, 0) - COALESCE(cdcd.real_num, 0) AS outNum
FROM cs_device_change_details cdcd
LEFT JOIN ma_dev_info a
ON cdcd.dev_type = '1'
AND cdcd.dev_code = a.`code`
LEFT JOIN tool_ledger b
ON cdcd.dev_type = '2'
AND cdcd.dev_type_id = b.type_id
AND (cdcd.dev_code = '/' OR cdcd.dev_code = b.tool_code)
LEFT JOIN tool_type tt ON tt.type_id = b.type_id
LEFT JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
WHERE cdcd.del_flag = 0
AND cdcd.dev_type IN ('1', '2')
AND cdcd.is_finished != '1'
AND cdcd.change_id = #{id}
</select>
<select id="getDevDetailsInfoTool" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
WITH RECURSIVE tool_category_tree AS (
SELECT type_id FROM tool_type
WHERE type_id = #{toolTypeId}
UNION ALL
SELECT t.type_id FROM tool_type t
INNER JOIN tool_category_tree tct ON t.parent_id = tct.type_id
)
SELECT
CONCAT(tt4.type_name, '>', tt3.type_name, '>', tt2.type_name, '>', tt1.type_name, '>', tt.type_name) as category,
tt1.type_name AS typeName,
tt.type_name AS typeModelName,
tl.manage_mode AS manageType,
IFNULL(tl.tool_code,'/') AS devCode,
IFNULL(tl.available_num, 0) AS storageNum,
2 AS devType,
tl.type_id AS typeId,
tl.id AS id
FROM tool_ledger tl
LEFT JOIN tool_type tt ON tl.type_id = tt.type_id
LEFT JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
LEFT JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
LEFT JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
LEFT JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
<where>
1 = 1
<if test="toolTypeId != null and toolTypeId != ''">
AND tl.type_id IN (SELECT type_id FROM tool_category_tree)
</if>
<if test="typeName != null and typeName != ''">
AND tt1.type_name LIKE CONCAT('%', #{typeName}, '%')
</if>
<if test="typeModelName != null and typeModelName != ''">
AND tt.type_name LIKE CONCAT('%', #{typeModelName}, '%')
</if>
<if test="devCode != null and devCode != ''">
AND tl.tool_code LIKE CONCAT('%', #{devCode}, '%')
</if>
<if test="companyId != null">
AND tl.company_id = #{companyId}
</if>
</where>
</select>
<select id="getDevDetailsInfoEquipment" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
WITH RECURSIVE category_tree AS (
SELECT type_id FROM ma_type
WHERE type_id = #{categoryEquipment}
UNION ALL
SELECT t.type_id FROM ma_type t
INNER JOIN category_tree ct ON t.parent_id = ct.type_id
)
SELECT
CASE
WHEN mt.level = 1 THEN mt.type_name
WHEN mt.level = 2 THEN CONCAT(mt1.type_name, '>', mt.type_name)
WHEN mt.level = 3 THEN CONCAT(mt2.type_name, '>', mt1.type_name, '>', mt.type_name)
WHEN mt.level = 4 THEN CONCAT(mt3.type_name, '>', mt2.type_name, '>', mt1.type_name, '>', mt.type_name)
WHEN mt.level = 5 THEN CONCAT(mt4.type_name, '>', mt3.type_name, '>', mt2.type_name, '>', mt1.type_name,'>', mt.type_name)
WHEN mt.level = 6 THEN CONCAT(mt5.type_name, '>', mt4.type_name, '>', mt3.type_name, '>', mt2.type_name,'>', mt1.type_name, '>', mt.type_name)
ELSE mt.type_name
END AS category,
mdi.device_name AS typeName,
mdi.item_type_model AS typeModelName,
mdi.manage_type AS manageType,
mdi.code AS devCode,
mdi.device_count AS storageNum,
1 AS devType,
mdi.type_id AS typeId,
mdi.ma_id AS id
FROM ma_dev_info mdi
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id
LEFT JOIN ma_type mt4 ON mt3.parent_id = mt4.type_id
LEFT JOIN ma_type mt5 ON mt4.parent_id = mt5.type_id
<where>
mdi.is_active = '1' AND mdi.ma_status = 1
<if test="categoryEquipment != null and categoryEquipment != ''">
AND mdi.type_id IN (SELECT type_id FROM category_tree)
</if>
<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="devCode != null and devCode != ''">
AND mdi.code LIKE CONCAT('%', #{devCode}, '%')
</if>
<if test="companyId != null">
AND mdi.on_company = #{companyId}
</if>
</where>
</select>
<select id="getVoltageLevel" resultType="java.util.Map">
SELECT DISTINCT voltage AS value,
CONCAT(voltage, 'kv') AS label
FROM jj_sing_project
ORDER BY CAST(voltage AS UNSIGNED); -- 将字符串转换为无符号整数
</select>
<select id="getDevChangeRList" resultType="com.bonus.material.devchange.domain.CsDeviceChange">
SELECT
cds.id,
cds.change_status AS changeStatus,
cds.type,
cds.lease_type,
cds.pro_code AS proCode,
cds.pro_name AS proName,
cds.pro_type AS proType,
cds.voltage_level AS voltageLevel,
cds.use_unit AS useUint,
cds.pro_province AS proProvince,
cds.pro_city AS proCity,
cds.pro_county AS proCounty,
cds.pro_location AS proLocation,
cds.create_time AS createTime,
cds.create_user AS createUser,
cds.del_flag,
cds.user_name AS userName,
cds.user_phone AS userPhone,
cds.change_unit AS changeUnit,
-- 修正点:使用 SUM 计算数量总和,并用 IFNULL 处理没有明细的情况
IFNULL(SUM(dcd.num), 0) AS devNum,
CASE
WHEN cds.change_status = 1 THEN '在库'
WHEN cds.change_status = 2 THEN '再用'
WHEN cds.change_status = 3 THEN '退役'
WHEN cds.change_status = 4 THEN '维修'
ELSE '未知'
END AS changeStatusName,
CASE
WHEN cds.type = 1 THEN '入库'
WHEN cds.type = 2 THEN '出库'
WHEN cds.type = 3 THEN '退役'
WHEN cds.type = 4 THEN '维修'
ELSE '未知'
END AS typeName
FROM
cs_device_change cds
LEFT JOIN cs_device_change_details dcd ON dcd.change_id = cds.id
WHERE
cds.del_flag = 0
<if test="keyWord!=null and keyWord!=''">
and (
cds.pro_name like concat('%',#{keyWord},'%') or
cds.voltage_level like concat('%',#{keyWord},'%') or
cds.use_unit like concat('%',#{keyWord},'%') or
cds.pro_province like concat('%',#{keyWord},'%') or
cds.pro_city like concat('%',#{keyWord},'%') or
cds.pro_county like concat('%',#{keyWord},'%') or
cds.create_user like concat('%',#{keyWord},'%') or
cds.pro_location like concat('%',#{keyWord},'%') or
cds.pro_code like concat('%',#{keyWord},'%')
)
</if>
<if test="type!=null and type!=''">
and cds.type=#{type}
</if>
<if test="startTime!=null and startTime!='' and endTime!=null and endTime!='' ">
and cds.create_time between #{startTime} and #{endTime}
</if>
GROUP BY
cds.id,
cds.change_status,
cds.type,
cds.lease_type,
cds.pro_code,
cds.pro_name,
cds.pro_type,
cds.voltage_level,
cds.use_unit,
cds.pro_province,
cds.pro_city,
cds.pro_county,
cds.pro_location,
cds.create_time,
cds.create_user,
cds.del_flag,
cds.user_name,
cds.user_phone,
cds.change_unit
ORDER BY
cds.create_time DESC
</select>
<select id="getOrderById" resultType="com.bonus.material.devchange.domain.CsDeviceInfo">
select order_id as id,
pro_code as proCode,
pro_name as proName,
pro_type as proType,
voltage_level as voltageLevel,
use_unit as useUnit,
pro_province as proProvince,
pro_city as proCity,
pro_county as proCounty,
use_time as useTime,
code as code,
CASE
-- 已完成:所有子表记录 is_finished = 1
WHEN NOT EXISTS (
SELECT 1
FROM ma_order_details cdc1
WHERE cdc1.order_id = #{id}
AND cdc1.is_finished &lt;&gt; '1' -- 不存在非1的记录
) THEN '3'
-- 待出库:所有子表记录 is_finished = 0
WHEN NOT EXISTS (
SELECT 1
FROM ma_order_details cdc2
WHERE cdc2.order_id = #{id}
AND cdc2.is_finished &lt;&gt; '0' -- 不存在非0的记录
) THEN '1'
-- 其余情况:出库中(包含 is_finished=2 或其他值)
ELSE '2'
END AS taskStatus
from ma_order_info
where order_id = #{id}
</select>
<select id="getOrderDetailsById" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
SELECT id AS detailsId,
devType AS devType,
ma_id AS typeId,
num AS num,
rent_begin_time AS useStartTime,
IFNULL(real_num, 0) AS realNum,
rent_end_time AS useEndTime,
is_finished AS isFinished
FROM ma_order_details
where order_id = #{id}
</select>
<select id="getOrderDetailsMaDevInfo" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
SELECT CASE
WHEN mt.level = 1 THEN mt.type_name
WHEN mt.level = 2 THEN CONCAT(mt1.type_name, '>', mt.type_name)
WHEN mt.level = 3 THEN CONCAT(mt2.type_name, '>', mt1.type_name, '>', mt.type_name)
WHEN mt.level = 4 THEN CONCAT(mt3.type_name, '>', mt2.type_name, '>', mt1.type_name, '>',
mt.type_name)
WHEN mt.level = 5 THEN CONCAT(mt4.type_name, '>', mt3.type_name, '>', mt2.type_name, '>',
mt1.type_name, '>', mt.type_name)
WHEN mt.level = 6 THEN CONCAT(mt5.type_name, '>', mt4.type_name, '>', mt3.type_name, '>',
mt2.type_name, '>', mt1.type_name, '>', mt.type_name)
ELSE mt.type_name
END AS category,
mdi.device_name AS typeName,
mdi.item_type_model AS typeModelName,
mdi.manage_type AS manageType,
mdi.code AS devCode,
SUM(CASE WHEN mdi.ma_status = 1 THEN 1 ELSE 0 END) AS storageNum,
1 AS devType,
mdi.type_id AS typeId,
mdi.ma_id AS id
FROM ma_dev_info mdi
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id
LEFT JOIN ma_type mt4 ON mt3.parent_id = mt4.type_id
LEFT JOIN ma_type mt5 ON mt4.parent_id = mt5.type_id
where mdi.is_active = '1'
and mdi.ma_id = #{typeId}
</select>
<select id="getOrderDetailsTypeToolInfo" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
SELECT CONCAT(tt4.type_name, '>', tt3.type_name, '>', tt2.type_name) as category,
tt1.type_name as typeName,
tt.type_name as typeModelName,
tl.manage_mode as manageType,
IFNULL(tl.tool_code,'/') as devCode,
tl.available_num as storageNum,
2 as devType,
tl.type_id as typeId,
tl.id as id
FROM tool_ledger tl
LEFT JOIN tool_type tt ON tl.type_id = tt.type_id
LEFT JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
LEFT JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
LEFT JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
LEFT JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
where
tl.id = #{typeId}
</select>
<select id="getOrderOutAllList" resultType="com.bonus.material.devchange.domain.CsDeviceDetails">
SELECT COALESCE(
CASE
WHEN cdcd.devType = '0' THEN CONCAT(a.ma_id, '')
WHEN cdcd.devType = '1' THEN CONCAT(b.id, '')
ELSE ''
END, ''
) AS id,
cdcd.devType AS devType,
COALESCE(cdcd.num, 0) - COALESCE(cdcd.real_num, 0) AS outNum
FROM ma_order_details cdcd
LEFT JOIN ma_dev_info a
ON cdcd.devType = '0'
AND cdcd.ma_id = a.ma_id
LEFT JOIN tool_ledger b
ON cdcd.devType = '1'
AND cdcd.ma_id = b.id
WHERE cdcd.order_id = #{id}
</select>
<select id="getToolNum" resultType="java.math.BigDecimal">
SELECT available_num
FROM tool_ledger
WHERE id = #{id}
</select>
<insert id="addChangeInfoNew" keyProperty="id" useGeneratedKeys="true">
insert into cs_device_change(change_status, type, lease_type, pro_code, pro_name,
pro_type, voltage_level, use_unit, pro_province, pro_city,
pro_county, create_time, create_user, del_flag, change_unit, code, use_time,review_status,
use_start_time, use_end_time, company_id)
values ( #{changeStatus}, #{type}, #{leaseType}, #{proCode}, #{proName}, #{proType},
#{voltageLevel}, #{useUnit}, #{proProvince}, #{proCity}, #{proCounty},
now(), #{createBy}, 0, #{changeUnit}, #{code}, #{useTime}, #{taskStatus}, #{useStartTime}, #{useEndTime}, #{companyId})
</insert>
<insert id="addDetails">
insert into cs_device_change_details(change_id, dev_code, dev_type_id, dev_type, num, use_time,use_start_time,use_end_time,
create_user, create_time, update_user, update_time, del_flag)
values
<foreach collection="list" item="item" separator=",">
(#{item.changeId},#{item.devCode},#{item.typeId},#{item.devType},#{item.num},#{item.useTime},#{item.useStartTime},#{item.useEndTime},
#{item.createBy}, #{item.createTime},#{item.updateBy}, #{item.updateTime}, 0)
</foreach>
</insert>
<update id="updateCsDevInfo">
update cs_device_change
<set>
<if test="proCode != null and proCode != ''">
pro_code = #{proCode},
</if>
<if test="proName != null and proName != ''">
pro_name = #{proName},
</if>
<if test="proType != null and proType != ''">
pro_type = #{proType},
</if>
<if test="voltageLevel != null and voltageLevel != ''">
voltage_level = #{voltageLevel},
</if>
<if test="useUnit != null and useUnit != ''">
use_unit = #{useUnit},
</if>
<if test="proProvince != null and proProvince != ''">
pro_province = #{proProvince},
</if>
<if test="proCity != null and proCity != ''">
pro_city = #{proCity},
</if>
<if test="proCounty != null and proCounty != ''">
pro_county = #{proCounty},
</if>
<if test="useTime != null">
use_time = #{useTime},
</if>
<if test="useStartTime != null">
use_start_time = #{useStartTime},
</if>
<if test="useEndTime != null">
use_end_time = #{useEndTime},
</if>
<if test="updateBy != null and updateBy != ''">
update_user = #{updateBy},
</if>
<if test="taskStatus != null and taskStatus != ''">
review_status = #{taskStatus},
</if>
<if test="companyId != null">
company_id = #{companyId},
</if>
update_time = NOW()
</set>
where id = #{id}
</update>
<update id="approve">
update cs_device_change
<set>
<if test="taskStatus != null and taskStatus != ''">
review_status = #{taskStatus},
</if>
<if test="updateBy != null and updateBy != ''">
review_by = #{updateBy},
</if>
review_time = NOW()
</set>
where id = #{id}
</update>
<update id="out">
UPDATE cs_device_change_details
SET is_finished = CASE
WHEN (IFNULL(real_num, 0) + #{outNum}) = num THEN '1'
WHEN (IFNULL(real_num, 0) + #{outNum}) &gt; 0 AND
(IFNULL(real_num, 0) + #{outNum}) &lt; num THEN '2'
ELSE '0'
END,
real_num = IFNULL(real_num, 0) + #{outNum}
WHERE id = #{detailsId}
AND del_flag = '0'
-- 可选:防止超量出库(若业务不允许实际数量超过申请数量,添加此条件)
AND (IFNULL(real_num, 0) + #{outNum}) &lt;= num
</update>
<update id="outCancel">
UPDATE cs_device_change_details
SET is_finished ='1'
WHERE id = #{detailsId}
AND del_flag = '0'
</update>
<update id="outCancelAll">
UPDATE cs_device_change_details
SET is_finished ='1'
WHERE change_id = #{id}
AND del_flag = '0'
</update>
<update id="outAll">
UPDATE cs_device_change_details
SET is_finished ='1',
real_num = num
WHERE change_id = #{id}
AND is_finished != '1'
AND del_flag = '0'
</update>
<update id="updateGj">
UPDATE tool_ledger
set available_num = IFNULL(available_num, 0) - #{outNum},
in_num = IFNULL(in_num, 0) + #{outNum},
status ='1'
WHERE id = #{id}
</update>
<update id="updateZb">
UPDATE ma_dev_info
set ma_status = '2',
change_status = '2'
WHERE ma_id = #{id}
</update>
<update id="updateOrderZb">
UPDATE ma_dev_info
set ma_status = '3',
change_status = '3'
WHERE ma_id = #{id}
</update>
<update id="updateOrderGj">
UPDATE tool_ledger
set available_num = IFNULL(available_num, 0) - #{outNum},
share_num = IFNULL(share_num, 0) + #{outNum},
status ='1'
WHERE id = #{id}
</update>
<update id="orderOut">
UPDATE ma_order_details
SET is_finished = CASE
WHEN (IFNULL(real_num, 0) + #{outNum}) = num THEN '1'
WHEN (IFNULL(real_num, 0) + #{outNum}) &gt; 0 AND
(IFNULL(real_num, 0) + #{outNum}) &lt; num THEN '2'
ELSE '0'
END,
real_num = IFNULL(real_num, 0) + #{outNum}
WHERE id = #{detailsId}
-- 可选:防止超量出库(若业务不允许实际数量超过申请数量,添加此条件)
AND (IFNULL(real_num, 0) + #{outNum}) &lt;= num
</update>
<update id="orderOutAll">
UPDATE ma_order_details
SET is_finished ='1',
real_num = num
WHERE order_id = #{id}
</update>
<update id="orderOutCancel">
UPDATE ma_order_details
SET is_finished ='1'
WHERE id = #{detailsId}
</update>
<update id="orderOutCancelAll">
UPDATE ma_order_details
SET is_finished ='1'
WHERE order_id = #{id}
</update>
<delete id="deleteChangeDetails">
update cs_device_change_details set del_flag = '1' where change_id = #{id}
</delete>
<delete id="deleteChangeInfo">
update cs_device_change set del_flag = '1' where id = #{id}
</delete>
</mapper>