Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/ComplexQueryMapper.xml

757 lines
33 KiB
XML
Raw Normal View History

2024-12-17 09:34:07 +08:00
<?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.basic.mapper.ComplexQueryMapper">
<select id="getProjUsingRecordList" resultType="com.bonus.material.basic.domain.ProjUsingRecord">
SELECT
subquery1.agreementCode as agreementCode,
subquery1.unitName as unitName,
subquery1.proName as proName,
2025-01-08 13:33:45 +08:00
subquery1.contractPart as contractPart,
subquery1.impUnitName as impUnitName,
2024-12-17 09:34:07 +08:00
subquery1.typeName as typeName,
subquery1.typeModelName as typeModelName,
subquery1.unit as unit,
IFNULL(subquery1.leaseNum, 0) as leaseNum,
IFNULL(subquery2.backNum, 0) as backNum,
CASE
WHEN IFNULL(subquery1.leaseNum, 0) - IFNULL(subquery2.backNum, 0) > 0
THEN IFNULL(subquery1.leaseNum, 0) - IFNULL(subquery2.backNum, 0)
ELSE 0.000
END as usNum,
CASE
WHEN IFNULL(subquery1.leaseNum, 0) - IFNULL(subquery2.backNum, 0) > 0 THEN
ROUND(IFNULL(subquery1.buy_price, 0) *
(IFNULL(subquery1.leaseNum, 0) - IFNULL(subquery2.backNum, 0)), 2)
ELSE
0.00
END as usPrice,
ROUND(IFNULL(subquery1.leaseNum, 0) * IFNULL(subquery1.buy_price, 0), 2) as totalPrice,
subquery1.isSlt as isSlt,
subquery1.isSltName as isSltName
FROM (SELECT bai.agreement_id,
mt.type_id,
mt.buy_price,
bai.agreement_code AS agreementCode,
bui.unit_name AS unitName,
bpl.pro_name AS proName,
2025-01-08 13:33:45 +08:00
bpl.contract_part as contractPart,
sd.dept_name as impUnitName,
2024-12-17 09:34:07 +08:00
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
SUM(IFNULL(lod.out_num, 0)) AS leaseNum,
sai.is_slt as isSlt,
CASE
sai.is_slt
WHEN '0' then '未结算'
WHEN '1' then '已结算'
ELSE ''
END as isSltName
FROM lease_out_details lod
LEFT JOIN lease_apply_info lai ON lai.id = lod.parent_id
LEFT JOIN tm_task_agreement tta ON tta.task_id = lai.task_id
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = tta.agreement_id
LEFT JOIN (
SELECT agreement_id, is_slt
FROM slt_agreement_info
GROUP BY agreement_id
) sai ON bai.agreement_id = sai.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
2025-01-08 13:33:45 +08:00
LEFT JOIN sys_dept sd on sd.dept_id = bpl.imp_unit
2024-12-17 09:34:07 +08:00
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN ma_type mt ON mt.type_id = lod.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = lod.ma_id
where 1=1
<if test="keyWord != null and keyWord != ''">
and (bai.agreement_code like concat('%',#{keyWord},'%') or
bui.unit_name like concat('%',#{keyWord},'%') or
bpl.pro_name like concat('%',#{keyWord},'%') or
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
2025-01-08 13:33:45 +08:00
mt.unit_name like concat('%',#{keyWord},'%') or
bpl.contract_part like concat('%', #{keyWord}, '%') or
sd.dept_name like concat('%', #{keyWord}, '%')
2024-12-17 09:34:07 +08:00
)
</if>
<if test="unitId != null">
and bui.unit_id = #{unitId}
</if>
<if test="proId != null">
and bpl.pro_id = #{proId}
</if>
<if test="typeName != null and typeName != ''">
and mt2.type_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and mt.type_name like concat('%',#{typeModelName},'%')
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND bai.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
<if test="isSlt != null and isSlt != ''">
and sai.is_slt = #{isSlt}
</if>
GROUP BY bai.agreement_id,
mt.type_id ORDER BY bai.agreement_code) AS subquery1
LEFT JOIN (SELECT bai.agreement_id,
mt.type_id,
mt.rent_price,
bai.agreement_code AS agreementCode,
bui.unit_name AS unitName,
bpl.pro_name AS proName,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
2025-01-08 13:33:45 +08:00
bpl.contract_part as contractPart,
sd.dept_name as impUnitName,
2024-12-17 09:34:07 +08:00
SUM(IFNULL(bcd.back_num, 0)) backNum,
sai.is_slt as isSlt,
CASE
sai.is_slt
WHEN '0' then '未结算'
WHEN '1' then '已结算'
ELSE ''
END as isSltName
FROM back_check_details bcd
LEFT JOIN back_apply_info baif ON baif.id = bcd.parent_id
LEFT JOIN tm_task_agreement tta ON tta.task_id = baif.task_id
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = tta.agreement_id
LEFT JOIN (
SELECT agreement_id, is_slt
FROM slt_agreement_info
GROUP BY agreement_id
) sai ON bai.agreement_id = sai.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
2025-01-08 13:33:45 +08:00
LEFT JOIN sys_dept sd on sd.dept_id = bpl.imp_unit
2024-12-17 09:34:07 +08:00
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN ma_type mt ON mt.type_id = bcd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = bcd.ma_id
where 1=1 and bcd.is_finished = '1'
<if test="keyWord != null and keyWord != ''">
and (bai.agreement_code like concat('%',#{keyWord},'%') or
bui.unit_name like concat('%',#{keyWord},'%') or
bpl.pro_name like concat('%',#{keyWord},'%') or
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
2025-01-08 13:33:45 +08:00
mt.unit_name like concat('%',#{keyWord},'%') or
bpl.contract_part like concat('%', #{keyWord}, '%') or
sd.dept_name like concat('%', #{keyWord}, '%')
2024-12-17 09:34:07 +08:00
)
</if>
<if test="unitId != null">
and bui.unit_id = #{unitId}
</if>
<if test="proId != null">
and bpl.pro_id = #{proId}
</if>
<if test="typeName != null and typeName != ''">
and mt2.type_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and mt.type_name like concat('%',#{typeModelName},'%')
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND bai.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
<if test="isSlt != null and isSlt != ''">
and sai.is_slt = #{isSlt}
</if>
GROUP BY bai.agreement_id,
mt.type_id ORDER BY bai.agreement_code) AS subquery2 ON subquery1.type_id = subquery2.type_id
AND subquery1.agreement_id = subquery2.agreement_id
</select>
<select id="getMachineHistoryRecordList" resultType="com.bonus.material.basic.domain.MachineHistoryRecordBean">
SELECT
2024-12-18 13:24:57 +08:00
bai.agreement_id as agreementId,
mt.type_id as typeId,
2024-12-17 09:34:07 +08:00
bai.agreement_code AS agreementCode,
bui.unit_name AS unitName,
bpl.pro_name AS proName,
2025-01-08 13:33:45 +08:00
bpl.contract_part as contractPart,
sd.dept_name as impUnitName,
2024-12-17 09:34:07 +08:00
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
lai.lease_person AS leaseMan,
lod.create_time AS leaseDate,
mm.ma_code AS maCode,
baif.back_person AS backMan,
bcd.create_time AS backDate,
CASE
2024-12-20 16:14:23 +08:00
WHEN baif.back_person IS NULL THEN '在用'
ELSE '已退'
2024-12-17 09:34:07 +08:00
END AS statusName
FROM
lease_out_details lod
LEFT JOIN lease_apply_info lai ON lai.id = lod.parent_id
LEFT JOIN tm_task_agreement tta ON tta.task_id = lai.task_id
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = tta.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
2025-01-08 13:33:45 +08:00
LEFT JOIN sys_dept sd on sd.dept_id = bpl.imp_unit
2024-12-17 09:34:07 +08:00
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN ma_type mt ON mt.type_id = lod.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = lod.ma_id
LEFT JOIN back_check_details bcd ON bcd.ma_id = lod.ma_id
LEFT JOIN back_apply_info baif ON baif.id = bcd.parent_id
WHERE
1 = 1
AND lod.ma_id IS NOT NULL
<if test="keyWord != null and keyWord != ''">
and (bai.agreement_code like concat('%',#{keyWord},'%') or
bui.unit_name like concat('%',#{keyWord},'%') or
bpl.pro_name like concat('%',#{keyWord},'%') or
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
mt.unit_name like concat('%',#{keyWord},'%') or
mm.ma_code like concat('%',#{keyWord},'%') or
lai.lease_person like concat('%',#{keyWord},'%') or
2025-01-08 13:33:45 +08:00
baif.back_person like concat('%',#{keyWord},'%') or
bpl.contract_part like concat('%', #{keyWord}, '%') or
sd.dept_name like concat('%', #{keyWord}, '%')
2024-12-17 09:34:07 +08:00
)
</if>
<if test="unitId != null">
and bui.unit_id = #{unitId}
</if>
<if test="proId != null">
and bpl.pro_id = #{proId}
</if>
<if test="typeName != null and typeName != ''">
and mt2.type_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and mt.type_name like concat('%',#{typeModelName},'%')
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND (lod.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
or bcd.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59'))
</if>
<if test="statusName != null and statusName != ''">
AND (
CASE
2024-12-20 16:14:23 +08:00
WHEN baif.back_person IS NULL THEN '在用'
ELSE '已退'
2024-12-17 09:34:07 +08:00
END = #{statusName}
)
</if>
GROUP BY
mm.ma_code
ORDER BY
2024-12-27 09:32:07 +08:00
bcd.create_time
2024-12-17 09:34:07 +08:00
</select>
2024-12-18 09:15:58 +08:00
<select id="getInputRecordList" resultType="com.bonus.material.basic.domain.InputRecordInfo">
SELECT
2024-12-18 17:56:45 +08:00
mt1.type_name as typeName,
mt.type_name as typeModelName,
2024-12-18 09:15:58 +08:00
bs.ma_code as maCode,
mt.unit_name as unit,
bs.in_num as inputNum,
bs.creator as inputUser,
bs.create_time as inputTime,
tt.`code` as inputCode,
CASE
WHEN tt.`code` LIKE 'XG%' THEN '新购入库'
2024-12-26 18:47:11 +08:00
WHEN tt.`code` LIKE 'R%' THEN '修试入库'
2024-12-18 09:15:58 +08:00
WHEN tt.`code` LIKE 'PD%' THEN '盘点入库'
ELSE '未知入库类型'
END AS inputType,
CASE
WHEN bs.input_type = '0' THEN '编码'
WHEN bs.input_type = '1' THEN '数量'
WHEN bs.input_type = '2' THEN '二维码'
WHEN bs.input_type = '3' THEN '标准箱'
ELSE '未知入库方式'
END AS inputStyle
FROM
bm_storage_log bs
LEFT JOIN ma_type mt ON bs.type_id = mt.type_id
AND mt.del_flag = '0'
2024-12-18 17:56:45 +08:00
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
2024-12-18 09:15:58 +08:00
LEFT JOIN tm_task tt ON bs.task_id = tt.task_id
WHERE bs.in_num != 0
<if test="inputType != null and inputType != ''">
and (
CASE
WHEN tt.`code` LIKE 'XG%' THEN '新购入库'
2024-12-26 18:47:11 +08:00
WHEN tt.`code` LIKE 'R%' THEN '修试入库'
2024-12-18 09:15:58 +08:00
WHEN tt.`code` LIKE 'PD%' THEN '盘点入库'
ELSE '未知入库类型'
END = #{inputType}
)
</if>
<if test="typeName != null and typeName != ''">
and bs.type_name like CONCAT('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and bs.type_model_name like CONCAT('%',#{typeModelName},'%')
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND bs.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
2024-12-27 09:32:07 +08:00
order by bs.create_time desc
2024-12-18 09:15:58 +08:00
</select>
2024-12-18 13:24:57 +08:00
<select id="getOutRecordList" resultType="com.bonus.material.basic.domain.OutRecordInfo">
SELECT
bpl.pro_name AS proName,
bui.unit_name AS unitName,
2025-01-08 13:33:45 +08:00
bpl.contract_part as contractPart,
sd.dept_name as impUnitName,
2024-12-18 13:24:57 +08:00
bai.agreement_code AS agreementCode,
2024-12-18 17:56:45 +08:00
mt1.type_name as typeName,
mt.type_name as typeModelName,
2024-12-18 13:24:57 +08:00
bs.ma_code as maCode,
mt.unit_name as unit,
bs.out_num as outNum,
bs.creator as outUser,
bs.create_time as outTime,
tt.`code` as leaseCode,
CASE
WHEN bs.out_type = '0' THEN '编码'
WHEN bs.out_type = '1' THEN '数量'
WHEN bs.out_type = '2' THEN '二维码'
WHEN bs.out_type = '3' THEN '标准箱'
ELSE '未知入库方式'
END AS outStyle
FROM
bm_storage_log bs
LEFT JOIN tm_task_agreement tta ON tta.task_id = bs.task_id
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = tta.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
2025-01-08 13:33:45 +08:00
LEFT JOIN sys_dept sd on sd.dept_id = bpl.imp_unit
2024-12-18 13:24:57 +08:00
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN ma_type mt ON bs.type_id = mt.type_id
AND mt.del_flag = '0'
2024-12-18 17:56:45 +08:00
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
2024-12-18 13:24:57 +08:00
LEFT JOIN tm_task tt ON bs.task_id = tt.task_id
WHERE bs.out_num != 0
<if test="unitId != null">
and bui.unit_id = #{unitId}
</if>
<if test="proId != null">
and bpl.pro_id = #{proId}
</if>
<if test="outStyle != null and outStyle != ''">
and (
CASE
WHEN bs.out_type = '0' THEN '编码'
WHEN bs.out_type = '1' THEN '数量'
WHEN bs.out_type = '2' THEN '二维码'
WHEN bs.out_type = '3' THEN '标准箱'
ELSE '未知入库方式'
END = #{outStyle}
)
</if>
<if test="typeName != null and typeName != ''">
and bs.type_name like CONCAT('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and bs.type_model_name like CONCAT('%',#{typeModelName},'%')
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND bs.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
</if>
2024-12-27 09:32:07 +08:00
order by bs.create_time desc
2024-12-18 13:24:57 +08:00
</select>
2024-12-18 17:56:45 +08:00
<select id="getRetainedEquipmentList" resultType="com.bonus.material.basic.domain.RetainedEquipmentInfo">
SELECT
2024-12-20 13:02:17 +08:00
mt.type_id AS typeId,
2024-12-18 17:56:45 +08:00
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
IFNULL(mt.buy_price, 0) AS buyPrice,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.storage_num, 0)
END AS storeNum,
IFNULL(subquery1.usNum, 0) AS usNum,
IFNULL(subquery2.repairNum, 0) AS repairNum,
IFNULL(subquery3.repairInputNum, 0) AS repairInputNum,
IFNULL(subquery4.inputNum, 0) AS inputNum,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)+ IFNULL(subquery1.usNum, 0) + IFNULL(subquery2.repairNum, 0) + IFNULL(subquery3.repairInputNum, 0)
+ IFNULL(subquery4.inputNum, 0)
ELSE
IFNULL(mt.storage_num, 0)+ IFNULL(subquery1.usNum, 0) + IFNULL(subquery2.repairNum, 0) + IFNULL(subquery3.repairInputNum, 0)
+ IFNULL(subquery4.inputNum, 0)
END AS allNum,
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
END manageType,
IFNULL(subquery5.fiveReplacementNum, 0) AS fiveReplacementNum,
IFNULL(subquery5.tenReplacementNum, 0) AS tenReplacementNum,
IFNULL(subquery5.tenPlusReplacementNum, 0) AS tenPlusReplacementNum
FROM ma_type mt
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) AS num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (1)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
LEFT JOIN (
SELECT
subquery1.type_id,
subquery1.typeName,
subquery1.typeModelName,
IFNULL(subquery1.outNum, 0) AS outNum,
IFNULL(subquery2.backNum, 0) AS backNum,
CASE
WHEN IFNULL(subquery1.outNum, 0) - IFNULL(subquery2.backNum, 0) > 0 THEN
IFNULL(subquery1.outNum, 0) - IFNULL(subquery2.backNum, 0)
ELSE 0
END AS usNum
FROM (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(IFNULL(lod.out_num, 0)) AS outNum
FROM lease_out_details lod
LEFT JOIN ma_type mt ON mt.type_id = lod.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
GROUP BY mt.type_id) AS subquery1
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(IFNULL(bcd.back_num, 0)) backNum
FROM back_check_details bcd
LEFT JOIN ma_type mt ON mt.type_id = bcd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
LEFT JOIN ma_machine mm ON mm.ma_id = bcd.ma_id
GROUP BY mt.type_id) AS subquery2
ON subquery1.type_id = subquery2.type_id) AS subquery1
ON mt.type_id = subquery1.type_id
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(
2024-12-20 13:02:17 +08:00
IFNULL(rad.repair_num, 0) - IFNULL(rad.repaired_num, 0) -
IFNULL(rad.scrap_num, 0)) AS repairNum
2024-12-18 17:56:45 +08:00
FROM repair_apply_details rad
LEFT JOIN ma_type mt ON mt.type_id = rad.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
WHERE
rad.status = '0'
GROUP BY
mt.type_id) AS subquery2 ON subquery2.type_id = mt.type_id
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(
IFNULL(rid.repair_num, 0) - IFNULL(rid.input_num, 0)) AS repairInputNum
FROM repair_input_details rid
LEFT JOIN ma_type mt ON mt.type_id = rid.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
WHERE IFNULL(rid.repair_num, 0) - IFNULL(rid.input_num, 0) > 0
GROUP BY
mt.type_id) AS subquery3 ON subquery3.type_id = mt.type_id
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(
IFNULL(pcd.check_num, 0) - IFNULL(pcd.input_num, 0)) AS inputNum
FROM purchase_check_details pcd
LEFT JOIN ma_type mt ON mt.type_id = pcd.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
WHERE IFNULL(pcd.check_num, 0) - IFNULL(pcd.input_num, 0) > 0
2024-12-25 18:33:19 +08:00
and pcd.status in (3,4, 13,14)
2024-12-18 17:56:45 +08:00
GROUP BY
mt.type_id) AS subquery4 ON subquery4.type_id = mt.type_id
LEFT JOIN (
SELECT
mt.type_id AS typeId,
IFNULL(SUM(IF(TIMESTAMPDIFF(YEAR,pcd.create_time,now()) &lt; 5, pcd.input_num,0)),0) AS fiveReplacementNum,
IFNULL(SUM(IF(TIMESTAMPDIFF(YEAR,pcd.create_time,now()) &gt;= 5 and TIMESTAMPDIFF(YEAR,pcd.create_time,now()) &lt; 10, pcd.input_num,0)),0) AS tenReplacementNum,
IFNULL(SUM(IF(TIMESTAMPDIFF(YEAR,pcd.create_time,now()) &gt;= 10, pcd.input_num,0)),0) AS tenPlusReplacementNum
FROM purchase_check_details pcd
LEFT JOIN ma_type mt ON pcd.type_id = mt.type_id
GROUP BY mt.type_id
) subquery5 ON subquery5.typeId = mt.type_id
LEFT JOIN ma_type mt2 on mt2.type_id = mt.parent_id
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
WHERE mt.`level` = 4
and mt.del_flag = '0'
<if test="keyWord != null and keyWord != ''">
and (
mt4.type_name like concat('%',#{keyWord},'%') or
mt3.type_name like concat('%',#{keyWord},'%') or
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%')
)
</if>
<if test="typeName != null and typeName != ''">
and mt2.type_name like concat('%',#{typeName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
and mt.type_name like concat('%',#{typeModelName},'%')
</if>
</select>
2024-12-20 13:02:17 +08:00
<select id="getMaCodeList" resultType="com.bonus.material.basic.domain.StorageInfo">
SELECT
bs.type_id as typeId,
mt1.type_name as typeName,
mt.type_name as typeModelName,
bs.ma_code as maCode,
bs.in_num as storeNum,
bs.creator as inputUser,
bs.create_time as inputTime,
CASE
WHEN tt.`code` LIKE 'XG%' THEN '新购入库'
WHEN tt.`code` LIKE 'R%' THEN '修饰入库'
WHEN tt.`code` LIKE 'PD%' THEN '盘点入库'
ELSE '未知入库类型'
END AS inputType,
mt.buy_price as buyPrice,
GROUP_CONCAT( DISTINCT su.nick_name ORDER BY su.nick_name SEPARATOR ', ' ) AS maKeeper
FROM
bm_storage_log bs
LEFT JOIN ma_type mt ON bs.type_id = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
LEFT JOIN tm_task tt ON bs.task_id = tt.task_id
LEFT JOIN ma_type_keeper mtk ON mtk.type_id = bs.type_id
LEFT JOIN sys_user su ON mtk.user_id = su.user_id
WHERE bs.in_num != 0
<if test="typeId != null">
AND bs.type_id = #{typeId}
</if>
GROUP BY bs.ma_code, mt.type_id, mt1.type_name, mt.type_name, bs.ma_code,
bs.in_num, bs.creator, bs.create_time, tt.CODE, mt.buy_price
</select>
<select id="getUserRecords" resultType="com.bonus.material.basic.domain.UseStorageInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.buy_price AS buyPrice,
sai.num AS usNum,
mm.ma_code AS maCode,
2024-12-25 18:33:19 +08:00
lai.`code` AS code,
2024-12-26 12:41:39 +08:00
bp.pro_name AS projectName,
2024-12-20 13:02:17 +08:00
GROUP_CONCAT(DISTINCT su.nick_name ORDER BY su.nick_name SEPARATOR ', ') AS maKeeper,
lod.create_by AS creator,
lod.create_time AS outTime
FROM
slt_agreement_info sai
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN ma_type_keeper mtk ON mtk.type_id = sai.type_id
LEFT JOIN sys_user su ON mtk.user_id = su.user_id
LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id
LEFT JOIN lease_apply_info lai ON lai.id = sai.lease_id
2024-12-26 12:41:39 +08:00
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = sai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2024-12-20 13:02:17 +08:00
LEFT JOIN ( SELECT parent_id, create_time, create_by FROM lease_out_details GROUP BY parent_id, create_by ) AS lod ON lod.parent_id = lai.id
WHERE
sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="typeId != null">
AND sai.type_id = #{typeId}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
mm.ma_code like concat('%',#{keyWord},'%') or
lai.`code` like concat('%',#{keyWord},'%') or
lod.create_by like concat('%',#{keyWord},'%') or
2024-12-26 12:41:39 +08:00
su.nick_name like concat('%',#{keyWord},'%') or
bp.pro_name like concat('%',#{keyWord},'%')
2024-12-20 13:02:17 +08:00
)
</if>
GROUP BY mm.ma_code,lai.`code`,mt.type_id
</select>
<select id="getRepairRecordList" resultType="com.bonus.material.basic.domain.RepairStorageInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.buy_price AS buyPrice,
IFNULL( rad.repair_num, 0 ) - IFNULL( rad.repaired_num, 0 ) - IFNULL( rad.scrap_num, 0 ) AS repairNum,
tt.`code` AS repairCode,
bai.create_time AS leaseTime,
GROUP_CONCAT(DISTINCT su.nick_name ORDER BY su.nick_name SEPARATOR ', ') AS repairer,
bai.back_person AS creator,
mm.ma_code as maCode
FROM
repair_apply_details rad
LEFT JOIN ma_type mt ON mt.type_id = rad.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN ma_type_repair mtr ON mtr.type_id = rad.type_id
LEFT JOIN sys_user su ON mtr.user_id = su.user_id
LEFT JOIN ma_machine mm ON mm.ma_id = rad.ma_id
LEFT JOIN tm_task tt ON rad.task_id = tt.task_id
LEFT JOIN back_apply_info bai ON rad.back_id = bai.id
WHERE rad.`status` = '0'
<if test="typeId != null">
AND rad.type_id = #{typeId}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
mm.ma_code like concat('%',#{keyWord},'%') or
tt.`code` like concat('%',#{keyWord},'%') or
rad.repairer like concat('%',#{keyWord},'%') or
bai.back_person like concat('%',#{keyWord},'%') or
su.nick_name like concat('%',#{keyWord},'%')
)
</if>
GROUP BY mm.ma_code,tt.`code`,mt.type_id
</select>
<select id="getPurchaseRecordList" resultType="com.bonus.material.basic.domain.PurchaseInputInfo">
SELECT
2024-12-24 10:59:54 +08:00
pcd.task_id as taskId,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.buy_price AS buyPrice,
IFNULL( pcd.check_num, 0 ) - IFNULL( pcd.input_num, 0 ) AS inputNum,
2024-12-25 18:33:19 +08:00
tt.`code` AS code,
2024-12-24 10:59:54 +08:00
GROUP_CONCAT( DISTINCT su.nick_name ORDER BY su.nick_name SEPARATOR ', ' ) AS maKeeper,
2024-12-25 18:33:19 +08:00
pcd.check_time AS checkTime,
mt.manage_type as manageType
2024-12-20 13:02:17 +08:00
FROM
2024-12-24 10:59:54 +08:00
purchase_check_details pcd
2024-12-20 13:02:17 +08:00
LEFT JOIN ma_type mt ON mt.type_id = pcd.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN tm_task tt ON pcd.task_id = tt.task_id
LEFT JOIN ma_type_keeper mtk ON mtk.type_id = pcd.type_id
LEFT JOIN sys_user su ON mtk.user_id = su.user_id
WHERE
2024-12-24 10:59:54 +08:00
pcd.`status` IN ( 3, 4, 13, 14 )
2024-12-20 13:02:17 +08:00
<if test="typeId != null">
AND pcd.type_id = #{typeId}
</if>
GROUP BY tt.`code`,
mt.type_id
</select>
<select id="getRepairInputList" resultType="com.bonus.material.basic.domain.RepairInputRecord">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.buy_price AS buyPrice,
IFNULL(rid.repair_num, 0) - IFNULL(rid.input_num, 0) AS repairInputNum,
2024-12-25 18:33:19 +08:00
tt.`code` AS inputCode,
2024-12-20 13:02:17 +08:00
GROUP_CONCAT(DISTINCT su.nick_name ORDER BY su.nick_name SEPARATOR ', ') AS maKeeper,
GROUP_CONCAT(DISTINCT su2.nick_name ORDER BY su2.nick_name SEPARATOR ', ') AS repairer,
rid.create_time as repairInputTime,
mm.ma_code as maCode
FROM
repair_input_details rid
LEFT JOIN ma_type mt ON mt.type_id = rid.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN tm_task tt ON rid.task_id = tt.task_id
LEFT JOIN ma_type_keeper mtk ON mtk.type_id = rid.type_id
LEFT JOIN sys_user su ON mtk.user_id = su.user_id
LEFT JOIN ma_type_repair mtr ON mtr.type_id = rid.type_id
LEFT JOIN sys_user su2 ON mtr.user_id = su2.user_id
LEFT JOIN repair_apply_details rad ON rid.repair_id = rad.id
LEFT JOIN ma_machine mm ON mm.ma_id = rid.ma_id
WHERE
rid.`status` IN (0)
<if test="typeId != null">
AND rid.type_id = #{typeId}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
tt.`code` like concat('%',#{keyWord},'%') or
su.nick_name like concat('%',#{keyWord},'%') or
su2.nick_name like concat('%',#{keyWord},'%') or
mm.ma_code like concat('%',#{keyWord},'%')
)
</if>
GROUP BY mm.ma_code,tt.`code`,mt.type_id
</select>
<select id="selectMaCodeByTaskIdAndTypeId" resultType="com.bonus.material.basic.domain.PurchaseInputInfo">
SELECT
pmi.id as id,
pmi.task_id as taskId,
pmi.type_id as typeId,
pmi.ma_code as maCode
FROM
2024-12-24 10:59:54 +08:00
bm_qrcode_info pmi
LEFT JOIN ma_machine mm ON pmi.ma_code = mm.ma_code AND mm.type_id = #{typeId}
2024-12-20 13:02:17 +08:00
WHERE
pmi.task_id = #{taskId}
2024-12-24 10:59:54 +08:00
AND pmi.type_id = #{typeId}
AND mm.ma_code IS NULL
AND pmi.ma_code IS NOT NULL
2024-12-20 13:02:17 +08:00
</select>
2024-12-26 12:41:39 +08:00
<select id="selectMaCodeByTypeId" resultType="com.bonus.material.basic.domain.StorageInfo">
SELECT
type_id as typeId,
ma_code as maCode
FROM
ma_machine
WHERE
ma_status = '1' and type_id = #{typeId}
</select>
2024-12-17 09:34:07 +08:00
</mapper>