Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/push/ProDataUseInfoMapper.xml

1302 lines
60 KiB
XML
Raw Normal View History

2025-08-23 19:18:15 +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.push.mapper.ProDataUseInfoMapper">
<select id="getProDataUseInfo" resultType="com.bonus.material.push.domain.ProIdsBean">
2025-08-26 19:54:22 +08:00
SELECT
2025-09-04 11:28:32 +08:00
ANY_VALUE(bp.pro_name) as proName,
sum(sai.num) typeNum,
ANY_VALUE(mt2.type_id) as typeId,
mt2.is_statics as isStatics,
bp.external_id as externalId
2025-08-26 19:54:22 +08:00
FROM slt_agreement_info sai
LEFT JOIN bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
WHERE
sai.is_slt = 0
AND sai.end_time IS NULL
AND bp.external_id = #{proId}
AND mt2.type_id IN
2025-08-23 19:18:15 +08:00
<foreach collection="typeIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
2025-09-04 11:28:32 +08:00
GROUP BY bp.external_id, mt2.is_statics
2025-08-23 19:18:15 +08:00
</select>
<select id="getTypeId" resultType="java.lang.Integer">
select type_id from ma_type where is_statics in (1,2,3,4,5,6,7)
</select>
<select id="getMachineDetails" resultType="com.bonus.material.push.domain.MachineInfoBean">
select
mt.type_id as typeId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
sai.num as num,
mm.assets_code as assetsCode,
mt.rent_price as rentPrice,
'在用' as status
from slt_agreement_info sai
left join bm_agreement_info bai on sai.agreement_id = bai.agreement_id
left join bm_project bp on bai.project_id = bp.pro_id
left join ma_type mt on sai.type_id = mt.type_id
left join ma_type mt2 on mt.parent_id = mt2.type_id
2025-09-04 11:28:32 +08:00
left join ma_machine mm on sai.ma_id = mm.ma_id
2025-08-23 19:18:15 +08:00
where sai.is_slt = 0 and sai.end_time is null
2025-09-04 11:28:32 +08:00
AND bp.external_id = #{externalId}
2025-08-23 19:18:15 +08:00
AND mt2.is_statics = #{isStatics}
<if test="typeName != null and typeName !=''">
2025-08-28 19:18:31 +08:00
AND mt2.type_name like concat ('%', #{typeName}, '%')
2025-08-23 19:18:15 +08:00
</if>
<if test="typeModelName != null and typeModelName !=''">
2025-08-28 19:18:31 +08:00
AND mt.type_name like concat ('%', #{typeModelName}, '%')
2025-08-23 19:18:15 +08:00
</if>
</select>
<select id="getTypeKeeperName" resultType="java.lang.String">
2025-09-08 19:21:32 +08:00
select group_concat(DISTINCT su.nick_name) from ma_type_keeper mtk
2025-08-23 19:18:15 +08:00
left join sys_user su on mtk.user_id = su.user_id
2025-09-08 19:21:32 +08:00
left join sys_user_post sp on su.user_id = sp.user_id
where mtk.type_id = #{typeId} and sp.post_id = 5
2025-08-23 19:18:15 +08:00
</select>
<select id="getNumsByStatics" resultType="com.bonus.material.push.domain.StaticsNumsBean">
2025-08-24 15:03:03 +08:00
SELECT
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.storage_num, 0)
END AS num,
IFNULL(subquery1.usNum, 0) AS useNum,
IFNULL(subquery2.repairNum, 0) AS repairNum,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0) + IFNULL(subquery1.usNum, 0) + IFNULL(subquery2.repairNum, 0)
2025-09-11 20:02:26 +08:00
+ IFNULL(subquery2.dsNum, 0) + IFNULL(subquery3.repairAuditNum, 0)
2025-08-24 15:03:03 +08:00
ELSE
IFNULL(mt.storage_num, 0) + IFNULL(subquery1.usNum, 0) + IFNULL(subquery2.repairNum, 0)
2025-09-11 20:02:26 +08:00
+ IFNULL(subquery2.dsNum, 0) + IFNULL(subquery3.repairAuditNum, 0)
2025-08-26 09:25:06 +08:00
END AS inventoryNum,
mt2.is_statics AS isStatics
2025-08-24 15:03:03 +08:00
FROM ma_type mt
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
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
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
2025-08-26 09:25:06 +08:00
SUM(IFNULL( sai.num, 0 )) AS usNum,
sd.dept_name AS unitName
2025-08-24 15:03:03 +08:00
FROM
slt_agreement_info sai
left join bm_agreement_info bai on sai.agreement_id = bai.agreement_id
left join bm_project bp on bai.project_id = bp.pro_id
LEFT JOIN ma_type mt ON mt.type_id = sai.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
2025-08-26 09:25:06 +08:00
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
2025-08-24 15:03:03 +08:00
WHERE
sai.`status` = '0' and sai.`is_slt` = '0'
2025-08-26 09:25:06 +08:00
<if test="unitName != null and unitName !=''">
AND sd.dept_name = #{unitName}
</if>
2025-09-04 11:28:32 +08:00
<if test="deptId != null">
AND sd.dept_id = #{deptId}
2025-08-26 09:25:06 +08:00
</if>
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</if>
2025-08-24 15:03:03 +08:00
AND sai.end_time IS NULL
AND sai.back_id IS NULL
GROUP BY mt.type_id
) AS subquery1
ON mt.type_id = subquery1.type_id
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
2025-09-10 18:53:49 +08:00
SUM(CASE WHEN tt.task_status = 0 and rad.is_ds = 1 THEN IFNULL(rad.repair_num, 0) ELSE 0 END) AS dsNum,
SUM(CASE WHEN tt.task_status = 4 and rad.is_ds = 0 THEN (IFNULL(rad.repair_num, 0) - IFNULL(rad.repaired_num, 0) - IFNULL(rad.scrap_num, 0)) ELSE 0 END) AS repairNum
2025-08-24 15:03:03 +08:00
FROM repair_apply_details rad
2025-09-10 18:53:49 +08:00
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
2025-08-24 15:03:03 +08:00
LEFT JOIN tm_task tt ON rad.task_id = tt.task_id
LEFT JOIN tm_task_agreement tta ON tt.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2025-09-10 18:53:49 +08:00
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
WHERE
tt.task_status IN (0, 4)
AND tt.code is not null
<if test="unitName != null and unitName !=''">
AND sd.dept_name = #{unitName}
</if>
<if test="deptId != null">
AND sd.dept_id = #{deptId}
</if>
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</if>
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,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
SUM(IFNULL(rad.repair_num, 0) ) AS repairAuditNum
FROM repair_audit_details rad
2025-08-24 15:03:03 +08:00
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
2025-09-10 18:53:49 +08:00
LEFT JOIN tm_task tt ON rad.task_id = tt.task_id
LEFT JOIN tm_task_agreement tta ON tt.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2025-08-26 09:25:06 +08:00
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
2025-08-24 15:03:03 +08:00
WHERE
2025-09-10 18:53:49 +08:00
tt.code is not null
and rad.`status` = '0'
2025-08-26 09:25:06 +08:00
<if test="unitName != null and unitName !=''">
AND sd.dept_name = #{unitName}
</if>
2025-09-04 11:28:32 +08:00
<if test="deptId != null">
AND sd.dept_id = #{deptId}
2025-08-26 09:25:06 +08:00
</if>
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</if>
2025-08-24 15:03:03 +08:00
GROUP BY
2025-09-10 18:53:49 +08:00
mt.type_id) AS subquery3 ON subquery3.type_id = mt.type_id
2025-08-24 15:03:03 +08:00
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
2025-09-04 19:54:59 +08:00
WHERE mt.del_flag = '0' and mt.`level` = '4' and mt2.is_statics is not null
2025-08-24 15:03:03 +08:00
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</if>
2025-08-23 19:18:15 +08:00
</select>
<select id="getApproachingAndTimeout" resultType="com.bonus.material.push.domain.StaticsNumsBean">
2025-09-08 18:47:39 +08:00
2025-08-23 19:18:15 +08:00
SELECT
COUNT(CASE
WHEN mm.next_check_time BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 30 DAY)
THEN 1
ELSE NULL
END) AS ApproachingNum,
2025-09-19 15:41:34 +08:00
0 AS TimeoutNum
2025-08-23 19:18:15 +08:00
FROM ma_machine mm
2025-09-04 18:26:28 +08:00
LEFT JOIN slt_agreement_info sai on sai.ma_id = mm.ma_id and mm.type_id = sai.type_id
2025-08-23 19:18:15 +08:00
LEFT JOIN bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
2025-09-04 11:28:32 +08:00
left join sys_dept sd ON sd.dept_id = bp.imp_unit
2025-08-26 19:54:22 +08:00
where mm.next_check_time is not null and mt.`level` = '4'
2025-09-04 18:26:28 +08:00
and sai.`status`='0' and sai.end_time is null
2025-09-08 20:26:59 +08:00
2025-09-04 18:26:28 +08:00
and mm.ma_status = 2
2025-09-08 19:32:40 +08:00
and mt2.type_id not in (6032,6008,6270,6012,6761)
2025-09-08 19:36:47 +08:00
and mt.jiju_type =2
2025-09-04 11:28:32 +08:00
<if test="deptId != null">
AND sd.dept_id = #{deptId}
2025-08-23 19:24:46 +08:00
</if>
2025-09-08 18:47:39 +08:00
2025-08-23 19:18:15 +08:00
</select>
<select id="getApproachingDetails" resultType="com.bonus.material.push.domain.MachineInfoBean">
SELECT
2025-08-24 18:02:56 +08:00
sd.dept_name as deptName,
bp.pro_center as proCenter,
bp.pro_name as proName,
2025-08-23 19:18:15 +08:00
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
mm.ma_code as maCode,
sai.start_time as leaseTime,
mm.next_check_time as expireTime,
CASE
WHEN #{type} = 0 THEN DATEDIFF(mm.next_check_time, NOW())
WHEN #{type} = 1 THEN DATEDIFF(NOW(), mm.next_check_time)
ELSE NULL
END AS daysDiff
FROM ma_machine mm
2025-09-04 18:26:28 +08:00
LEFT JOIN slt_agreement_info sai on sai.ma_id = mm.ma_id and mm.type_id = sai.type_id
2025-08-23 19:18:15 +08:00
LEFT JOIN bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN sys_dept sd on bp.imp_unit = sd.dept_id
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
2025-08-26 19:54:22 +08:00
WHERE mm.next_check_time is not null AND mt.`level`=4
2025-09-08 20:26:59 +08:00
2025-09-04 18:26:28 +08:00
and sai.`status`='0' and sai.end_time is null
and mm.ma_status = 2
2025-09-08 19:32:40 +08:00
and mt2.type_id not in (6032,6008,6270,6012,6761)
2025-09-08 19:36:47 +08:00
and mt.jiju_type =2
2025-08-23 19:24:46 +08:00
<if test="proId != null">
2025-08-24 18:02:56 +08:00
AND bp.pro_id = #{proId}
2025-08-23 19:24:46 +08:00
</if>
2025-08-23 19:18:15 +08:00
<if test="type != null and type == 0">
AND mm.next_check_time BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 30 DAY)
</if>
<if test="type != null and type == 1">
AND mm.next_check_time &lt; NOW()
</if>
<if test="deptName != null and deptName !=''">
AND sd.dept_name like concat ('%', #{deptName}, '%')
</if>
<if test="proCenter != null and proCenter !=''">
AND bp.pro_center like concat ('%', #{proCenter}, '%')
</if>
<if test="proName != null and proName !=''">
AND bp.pro_name like concat ('%', #{proName}, '%')
</if>
<if test="typeName != null and typeName !=''">
2025-08-28 19:18:31 +08:00
AND mt2.type_name like concat ('%', #{typeName}, '%')
2025-08-23 19:18:15 +08:00
</if>
<if test="typeModelName != null and typeModelName !=''">
2025-08-28 19:18:31 +08:00
AND mt.type_name like concat ('%', #{typeModelName}, '%')
2025-08-23 19:18:15 +08:00
</if>
2025-08-24 18:02:56 +08:00
<if test="proId != null">
GROUP BY bp.pro_id
</if>
2025-09-04 18:26:28 +08:00
order by mt.jiju_type desc
2025-08-23 19:18:15 +08:00
</select>
2025-08-24 11:27:05 +08:00
<select id="getCompletionNotRefunded" resultType="com.bonus.material.push.domain.MachineInfoBean">
select
count(distinct bp.external_id) num,
sd.dept_name as deptName,
sd.dept_id as deptId
2025-09-05 09:55:19 +08:00
from slt_agreement_info sai
left join bm_agreement_info bai on sai.agreement_id = bai.agreement_id
left join bm_project bp on bai.project_id = bp.pro_id
left join sys_dept sd on bp.imp_unit = sd.dept_id
2025-09-09 09:01:51 +08:00
left join ma_type mt on sai.type_id = mt.type_id
left join ma_type mt2 on mt.parent_id = mt2.type_id
2025-09-17 18:26:44 +08:00
where sai.is_slt = 0 and bp.actual_end_date is not null and bp.pro_center is not null and bp.external_id is not null
2025-09-08 21:31:48 +08:00
and dept_id not in (339,340,342,346)
2025-09-09 09:01:51 +08:00
and mt.jiju_type = 1
and mt2.is_statics != 1
2025-09-08 21:31:24 +08:00
<if test="deptName != null and deptName != ''">
AND sd.dept_name = #{deptName}
</if>
GROUP BY bp.imp_unit
2025-08-24 11:27:05 +08:00
</select>
<select id="getCompletionNotRefundedDetails" resultType="com.bonus.material.push.domain.MachineInfoBean">
select
bp.pro_name as proName,
2025-08-24 18:02:56 +08:00
bp.actual_end_date as actualEndDate,
DATEDIFF(NOW(), bp.actual_end_date) as daysDiff,
2025-09-04 12:51:07 +08:00
sai.num num,
2025-08-24 12:25:38 +08:00
mt.type_name as typeModelName,
2025-08-24 18:02:56 +08:00
mt.unit_name as unit,
2025-08-24 12:25:38 +08:00
mt2.type_name as typeName,
2025-09-04 19:54:59 +08:00
sd.dept_name as deptName,
2025-09-04 21:18:44 +08:00
bp.pro_center as proCenter
2025-08-24 11:27:05 +08:00
from slt_agreement_info sai
left join bm_agreement_info bai on sai.agreement_id = bai.agreement_id
left join bm_project bp on bai.project_id = bp.pro_id
left join sys_dept sd on bp.imp_unit = sd.dept_id
left join ma_type mt on sai.type_id = mt.type_id
left join ma_type mt2 on mt.parent_id = mt2.type_id
2025-09-17 18:26:44 +08:00
where sai.is_slt = 0 and bp.actual_end_date is not null and bp.pro_center is not null and bp.external_id is not null
2025-09-08 21:52:24 +08:00
and mt.jiju_type = 1
2025-09-09 09:01:51 +08:00
and mt2.is_statics != 1
2025-09-12 09:00:58 +08:00
and dept_id not in (339,340,342,346)
2025-09-04 21:18:44 +08:00
<if test="deptId != null">
and sd.dept_id = #{deptId}
</if>
2025-08-24 11:27:05 +08:00
<if test="typeName != null and typeName !=''">
2025-08-28 19:18:31 +08:00
AND mt2.type_name like concat ('%', #{typeName}, '%')
2025-08-24 11:27:05 +08:00
</if>
<if test="typeModelName != null and typeModelName !=''">
2025-08-28 19:18:31 +08:00
AND mt.type_name like concat ('%', #{typeModelName}, '%')
2025-08-24 11:27:05 +08:00
</if>
</select>
<select id="getInventoryAlert" resultType="com.bonus.material.push.domain.InventoryAlertBean">
select
mt.type_name as typeModelName,
mt2.type_name as typeName,
2025-08-26 19:54:22 +08:00
mt.storage_num as num
2025-08-24 11:27:05 +08:00
from ma_type mt
left join ma_type mt2 on mt.parent_id = mt2.type_id
2025-08-26 19:54:22 +08:00
where mt.del_flag = 0 and mt.`level`=4
<if test="typeName != null and typeName !=''">
2025-08-28 19:18:31 +08:00
AND mt2.type_name like concat ('%', #{typeName}, '%')
2025-08-26 19:54:22 +08:00
</if>
<if test="typeModelName != null and typeModelName !=''">
2025-08-28 19:18:31 +08:00
AND mt.type_name like concat ('%', #{typeModelName}, '%')
2025-08-26 19:54:22 +08:00
</if>
</select>
<select id="getInventoryAlertName" resultType="com.bonus.material.push.domain.InventoryAlertBean">
select
mt.type_name as typeModelName,
mt2.type_name as typeName
from ma_type mt
left join ma_type mt2 on mt.parent_id = mt2.type_id
where mt.del_flag = 0 and mt.`level`=4
<if test="typeName != null and typeName !=''">
2025-08-28 19:18:31 +08:00
AND mt2.type_name like concat ('%', #{typeName}, '%')
2025-08-26 19:54:22 +08:00
</if>
<if test="typeModelName != null and typeModelName !=''">
2025-08-28 19:18:31 +08:00
AND mt.type_name like concat ('%', #{typeModelName}, '%')
2025-08-26 19:54:22 +08:00
</if>
</select>
<select id="getApproachingDetailsByUnit" resultType="java.util.Map">
SELECT COUNT(CASE
WHEN mm.next_check_time BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 30 DAY) THEN 1
ELSE NULL END)
2025-08-27 16:05:42 +08:00
AS approachingNum,
COUNT(CASE WHEN mm.next_check_time &lt; NOW() THEN 1 ELSE NULL END) AS timeoutNum,
2025-08-26 19:54:22 +08:00
sd.dept_name as deptName
FROM ma_machine mm
LEFT JOIN slt_agreement_info sai ON sai.ma_id = mm.ma_id
AND mm.type_id = sai.type_id
AND sai.`status` = '0'
AND sai.end_time IS NULL
LEFT JOIN bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN sys_dept sd on bp.imp_unit = sd.dept_id
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
WHERE mm.next_check_time IS NOT NULL
AND mt.`level` = '4'
AND sd.dept_name in
('送电一分公司', '送电二分公司', '检修试验分公司', '建筑分公司(消防分公司)', '安徽宏源电力建设有限公司',
'变电分公司')
GROUP BY bp.imp_unit
</select>
<select id="getMaTypeList" resultType="com.bonus.material.push.domain.MachineInfoBean">
SELECT
2025-09-04 11:28:32 +08:00
mt.type_id AS typeId,
2025-09-04 19:54:59 +08:00
mt.type_name AS specification,
mt2.type_name AS materialName,
mt.unit_name AS materialDw,
mt.storage_num AS subKcNum
2025-08-26 19:54:22 +08:00
FROM
ma_type mt
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
WHERE
mt.del_flag = 0
AND mt.`level` =4
2025-09-04 19:54:59 +08:00
<if test="materialName != null and materialName !=''">
AND mt2.type_name like concat ('%', #{materialName}, '%')
2025-08-24 11:27:05 +08:00
</if>
2025-09-04 19:54:59 +08:00
<if test="specification != null and specification !=''">
AND mt.type_name like concat ('%', #{specification}, '%')
2025-08-26 19:54:22 +08:00
</if>
2025-08-24 11:27:05 +08:00
</select>
2025-09-04 11:28:32 +08:00
<select id="getUseNumsDetails" resultType="com.bonus.material.push.domain.MachineInfoBean">
select
mt.type_id as typeId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
mm.assets_code as assetsCode,
ifnull(mt.lease_price,0) as rentPrice,
SUM(IFNULL( sai.num, 0 )) AS num,
'在用' AS status
FROM
slt_agreement_info sai
left join bm_agreement_info bai on sai.agreement_id = bai.agreement_id
left join bm_project bp on bai.project_id = bp.pro_id
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
left join ma_machine mm ON mm.ma_id = sai.ma_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 sys_dept sd ON sd.dept_id = bp.imp_unit
WHERE
sai.`status` = '0' and sai.`is_slt` = '0'
<if test="unitName != null and unitName !=''">
AND sd.dept_name = #{unitName}
</if>
<if test="deptId != null">
AND sd.dept_id = #{deptId}
</if>
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</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>
AND sai.end_time IS NULL
AND sai.back_id IS NULL
GROUP BY mt.type_id
</select>
<select id="getRepairNumsDetails" resultType="com.bonus.material.push.domain.MachineInfoBean">
SELECT
mt.type_id as typeId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
mm.assets_code as assetsCode,
ifnull(mt.lease_price,0) as rentPrice,
SUM(
IFNULL(rad.repair_num, 0) - IFNULL(rad.repaired_num, 0) -
IFNULL(rad.scrap_num, 0)) AS num,
'在修' AS status
FROM repair_apply_details rad
LEFT JOIN tm_task tt ON rad.task_id = tt.task_id
LEFT JOIN tm_task_agreement tta ON tt.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN ma_type mt ON mt.type_id = rad.type_id
left join ma_machine mm ON mm.ma_id = rad.ma_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 sys_dept sd ON sd.dept_id = bp.imp_unit
WHERE
rad.status = '0'
<if test="unitName != null and unitName !=''">
AND sd.dept_name = #{unitName}
</if>
<if test="deptId != null">
AND sd.dept_id = #{deptId}
</if>
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</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>
GROUP BY
mt.type_id
</select>
<select id="getNumsDetails" resultType="com.bonus.material.push.domain.MachineInfoBean">
SELECT
2025-09-04 21:00:15 +08:00
mt.type_id as typeId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
mm.assets_code as assetsCode,
ifnull(mt.lease_price,0) as rentPrice,
2025-09-04 21:01:32 +08:00
CASE
mt.manage_type
2025-09-04 21:00:15 +08:00
WHEN 0 THEN
2025-09-04 21:01:32 +08:00
IFNULL( COUNT( mm.ma_id ), 0 )
2025-09-04 21:00:15 +08:00
ELSE
2025-09-04 21:01:32 +08:00
IFNULL( mt.storage_num, 0 )
2025-09-04 21:00:15 +08:00
END AS num,
2025-09-04 21:01:32 +08:00
'在库' AS STATUS
2025-09-04 21:00:15 +08:00
FROM
ma_type mt
LEFT JOIN ma_machine mm 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
mt.LEVEL = 4
2025-09-04 11:28:32 +08:00
<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>
2025-09-04 21:01:32 +08:00
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</if>
2025-09-04 21:00:15 +08:00
AND (
mt.manage_type != 0
OR (
mt.manage_type = 0
AND mm.ma_code IS NOT NULL
AND mm.ma_status IN (1)
))
GROUP BY
mt.type_id
2025-09-04 11:28:32 +08:00
</select>
<select id="getAllMacheDetails" resultType="com.bonus.material.push.domain.MachineInfoBean">
( SELECT
mt.type_id as typeId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
mm.assets_code as assetsCode,
ifnull(mt.lease_price,0) as rentPrice,
SUM(
IFNULL( sai.num, 0 )) AS num,
'在用' AS STATUS
FROM
slt_agreement_info sai
LEFT JOIN bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
left join ma_machine mm ON mm.ma_id = sai.ma_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 sys_dept sd ON sd.dept_id = bp.imp_unit
WHERE
sai.STATUS = '0' AND mt.LEVEL = 4
<if test="unitName != null and unitName !=''">
AND sd.dept_name = #{unitName}
</if>
<if test="deptId != null">
AND sd.dept_id = #{deptId}
</if>
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</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>
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
GROUP BY
mt.type_id
) UNION ALL
(
SELECT
mt.type_id as typeId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
mm.assets_code as assetsCode,
ifnull(mt.lease_price,0) as rentPrice,
SUM(
IFNULL( rad.repair_num, 0 ) - IFNULL( rad.repaired_num, 0 ) - IFNULL( rad.scrap_num, 0 )) AS num,
'在修' AS STATUS
FROM
repair_apply_details rad
LEFT JOIN tm_task tt ON rad.task_id = tt.task_id
LEFT JOIN tm_task_agreement tta ON tt.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN ma_type mt ON mt.type_id = rad.type_id
left join ma_machine mm ON mm.ma_id = rad.ma_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 sys_dept sd ON sd.dept_id = bp.imp_unit
WHERE
rad.STATUS = '0' AND mt.LEVEL = 4
<if test="unitName != null and unitName !=''">
AND sd.dept_name = #{unitName}
</if>
<if test="deptId != null">
AND sd.dept_id = #{deptId}
</if>
<if test="isStatics != null">
and mt2.is_statics = #{isStatics}
</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>
GROUP BY
mt.type_id
) UNION ALL
(
2025-09-04 20:57:07 +08:00
SELECT
mt.type_id as typeId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
mm.assets_code as assetsCode,
ifnull(mt.lease_price,0) as rentPrice,
CASE
mt.manage_type
WHEN 0 THEN
IFNULL( COUNT( mm.ma_id ), 0 )
ELSE
IFNULL( mt.storage_num, 0 )
END AS num,
'在库' AS STATUS
FROM
ma_type mt
LEFT JOIN ma_machine mm 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
mt.LEVEL = 4
<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="isStatics != null">
and mt2.is_statics = #{isStatics}
</if>
AND (
mt.manage_type != 0
OR (
mt.manage_type = 0
AND mm.ma_code IS NOT NULL
AND mm.ma_status IN (1)
))
GROUP BY
mt.type_id)
2025-09-04 11:28:32 +08:00
</select>
<select id="getPersonNameAndPhone" resultType="com.bonus.system.api.domain.SysUser">
SELECT
su.nick_name AS nickName,
su.phonenumber
FROM ma_type_keeper mtk
LEFT JOIN sys_user su ON mtk.user_id = su.user_id
WHERE mtk.type_id = #{typeId}
AND su.phonenumber IS NOT NULL
ORDER BY mtk.user_id DESC
LIMIT 1
</select>
<select id="getCompletionNotRefundedSub" resultType="com.bonus.material.push.domain.MachineInfoBean">
select
bp.pro_center as proCenter,
count(distinct bp.external_id) num,
sd.dept_name as deptName,
sd.dept_id as deptId
2025-09-04 11:28:32 +08:00
from slt_agreement_info sai
left join bm_agreement_info bai on sai.agreement_id = bai.agreement_id
left join bm_project bp on bai.project_id = bp.pro_id
left join sys_dept sd on bp.imp_unit = sd.dept_id
where sai.is_slt = 0 and sai.end_time is null and bp.actual_end_date is not null and sd.dept_name = #{deptName} and bp.pro_center is not null and bp.external_id is not null
2025-09-04 11:28:32 +08:00
GROUP BY bp.pro_center
</select>
2025-09-04 15:46:32 +08:00
<select id="getCompletionNotRefundedDetailsSub" resultType="com.bonus.material.push.domain.MachineInfoBean">
select
bp.pro_name as proName,
bp.pro_center as proCenter,
bp.actual_end_date as actualEndDate,
DATEDIFF(NOW(), bp.actual_end_date) as daysDiff,
sai.num num,
mt.type_name as typeModelName,
mt.unit_name as unit,
2025-09-04 21:26:17 +08:00
sd.dept_name as deptName,
2025-09-04 15:46:32 +08:00
mt2.type_name as typeName
from slt_agreement_info sai
left join bm_agreement_info bai on sai.agreement_id = bai.agreement_id
left join bm_project bp on bai.project_id = bp.pro_id
left join sys_dept sd on bp.imp_unit = sd.dept_id
left join ma_type mt on sai.type_id = mt.type_id
left join ma_type mt2 on mt.parent_id = mt2.type_id
2025-09-11 18:16:28 +08:00
where sai.status = 0 and sai.is_slt = 0 and sai.end_time is null and bp.actual_end_date is not null and bp.pro_center is not null
and mt.jiju_type = 1
and mt2.is_statics != 1
2025-09-12 09:00:58 +08:00
and dept_id not in (339,340,342,346)
2025-09-04 21:18:44 +08:00
<if test="proCenter != null and proCenter !=''">
and bp.pro_center= #{proCenter}
</if>
2025-09-04 15:46:32 +08:00
<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>
2025-08-26 19:54:22 +08:00
2025-09-28 17:03:12 +08:00
<select id="getDeviceNumByType" resultType="com.bonus.material.push.domain.TotalNumsBean">
SELECT
res.typeName as deviceName,
SUM( res.storeNum ) + SUM( dsNum )+ SUM( repairNum )+ SUM( repairAuditNum )+ SUM( repairInputNum )+ SUM( inputNum ) AS stNum,
SUM( res.usNum ) AS leaseNum
FROM
(
SELECT
mt.type_id AS typeId,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
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.dsNum, 0 ) AS dsNum,
IFNULL( subquery2.repairNum, 0 ) AS repairNum,
IFNULL( subquery12.repairAuditNum, 0 ) AS repairAuditNum,
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.dsNum, 0 ) + IFNULL( subquery2.repairNum, 0 ) + IFNULL( subquery3.repairInputNum, 0 ) + IFNULL( subquery12.repairAuditNum, 0 ) + IFNULL( subquery4.inputNum, 0 ) ELSE IFNULL( mt.storage_num, 0 )+ IFNULL( subquery1.usNum, 0 ) + IFNULL( subquery2.dsNum, 0 ) + IFNULL( subquery2.repairNum, 0 ) + IFNULL( subquery3.repairInputNum, 0 ) + IFNULL( subquery12.repairAuditNum, 0 ) + IFNULL( subquery4.inputNum, 0 )
END AS allNum,
CASE
mt.manage_type
WHEN 0 THEN
'编码' ELSE '数量'
END manageType
FROM
ma_type mt
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
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
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
SUM(
IFNULL( sai.num, 0 )) AS usNum
FROM
slt_agreement_info sai
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = sai.agreement_id
LEFT JOIN bm_project_info bp ON bp.project_id = bai.project_id
LEFT JOIN ma_type mt ON mt.type_id = sai.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
sai.`status` = '0'
AND sai.`is_slt` = '0'
AND ( sai.source = 1 OR sai.source IS NULL )
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND mt.type_id IN (
2598,
2599,
2600,
2601,
2602,
2603,
2604,
2605,
2606,
2608,
2609,
2610,
2611,
2612,
2613,
2614,
2615,
2616,
2617,
2618,
2619,
2620,
2621,
4341,
4374,
4678,
2624,
2625,
2626,
2627,
2628,
2629,
2630,
2631,
2632,
2633,
2634,
2635,
2636,
2637,
2638,
2639,
2640,
2641,
2623,
2164,
2165,
2166,
4359,
4360,
4519,
2411,
4353,
2404,
2405,
2406,
2407,
2408,
2409,
2410,
2525,
3281
)
<if test="projectIds != null and projectIds.size() > 0">
AND bp.external_id in
<foreach item="item" index="index" collection="projectIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY
mt.type_id
) AS subquery1 ON mt.type_id = subquery1.type_id
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
SUM( CASE WHEN tt.task_status = 0 AND rad.is_ds = 1 THEN IFNULL( rad.repair_num, 0 ) ELSE 0 END ) AS dsNum,
SUM(
CASE
WHEN tt.task_status = 4
AND rad.is_ds = 0 THEN
(
IFNULL( rad.repair_num, 0 ) - IFNULL( rad.repaired_num, 0 ) - IFNULL( rad.scrap_num, 0 )) ELSE 0
END
) AS repairNum
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
INNER JOIN tm_task tt ON rad.task_id = tt.task_id
WHERE
tt.task_status IN ( 0, 4 )
AND tt.CODE IS NOT NULL
AND mt.type_id IN (
2598,
2599,
2600,
2601,
2602,
2603,
2604,
2605,
2606,
2608,
2609,
2610,
2611,
2612,
2613,
2614,
2615,
2616,
2617,
2618,
2619,
2620,
2621,
4341,
4374,
4678,
2624,
2625,
2626,
2627,
2628,
2629,
2630,
2631,
2632,
2633,
2634,
2635,
2636,
2637,
2638,
2639,
2640,
2641,
2623,
2164,
2165,
2166,
4359,
4360,
4519,
2411,
4353,
2404,
2405,
2406,
2407,
2408,
2409,
2410,
2525,
3281
)
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,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
SUM( IFNULL( rad.repair_num, 0 ) ) AS repairAuditNum
FROM
repair_audit_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
LEFT JOIN tm_task tt ON rad.task_id = tt.task_id
WHERE
tt.CODE IS NOT NULL
AND rad.`status` = '0'
GROUP BY
mt.type_id
) AS subquery12 ON subquery12.type_id = mt.type_id
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
SUM(
IFNULL( rid.repair_num, 0 ) - IFNULL( rid.input_num, 0 ) - IFNULL( rid.reject_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
LEFT JOIN tm_task tt ON rid.task_id = tt.task_id
WHERE
IFNULL( rid.repair_num, 0 ) - IFNULL( rid.input_num, 0 ) - IFNULL( rid.reject_num, 0 ) > 0
AND tt.task_status = 0
AND mt.type_id IN (
2598,
2599,
2600,
2601,
2602,
2603,
2604,
2605,
2606,
2608,
2609,
2610,
2611,
2612,
2613,
2614,
2615,
2616,
2617,
2618,
2619,
2620,
2621,
4341,
4374,
4678,
2624,
2625,
2626,
2627,
2628,
2629,
2630,
2631,
2632,
2633,
2634,
2635,
2636,
2637,
2638,
2639,
2640,
2641,
2623,
2164,
2165,
2166,
4359,
4360,
4519,
2411,
4353,
2404,
2405,
2406,
2407,
2408,
2409,
2410,
2525,
3281
)
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,
mt4.type_id AS firstTypeId,
mt3.type_name AS materialType,
mt3.type_id AS secondTypeId,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
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
AND pcd.STATUS IN ( 3, 4, 13, 14 )
AND mt.type_id IN (
2598,
2599,
2600,
2601,
2602,
2603,
2604,
2605,
2606,
2608,
2609,
2610,
2611,
2612,
2613,
2614,
2615,
2616,
2617,
2618,
2619,
2620,
2621,
4341,
4374,
4678,
2624,
2625,
2626,
2627,
2628,
2629,
2630,
2631,
2632,
2633,
2634,
2635,
2636,
2637,
2638,
2639,
2640,
2641,
2623,
2164,
2165,
2166,
4359,
4360,
4519,
2411,
4353,
2404,
2405,
2406,
2407,
2408,
2409,
2410,
2525,
3281
)
GROUP BY
mt.type_id
) AS subquery4 ON subquery4.type_id = 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.del_flag = '0'
AND mt.type_id IN (
2598,
2599,
2600,
2601,
2602,
2603,
2604,
2605,
2606,
2608,
2609,
2610,
2611,
2612,
2613,
2614,
2615,
2616,
2617,
2618,
2619,
2620,
2621,
4341,
4374,
4678,
2624,
2625,
2626,
2627,
2628,
2629,
2630,
2631,
2632,
2633,
2634,
2635,
2636,
2637,
2638,
2639,
2640,
2641,
2623,
2164,
2165,
2166,
4359,
4360,
4519,
2411,
4353,
2404,
2405,
2406,
2407,
2408,
2409,
2410,
2525,
3281
)
) res
GROUP BY
res.typeName
</select>
2025-10-17 11:00:16 +08:00
<select id="getProDataDetails" resultType="com.bonus.material.push.domain.MachineInfoBean">
SELECT
ANY_VALUE(bp.pro_name) as proName,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
sum(sai.num) num,
ANY_VALUE(mt.type_id) as typeId,
mt2.is_statics as isStatics
FROM slt_agreement_info sai
LEFT JOIN bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
WHERE
sai.is_slt = 0
AND sai.end_time IS NULL
AND bp.external_id = #{proId}
<if test="isStatics != null">
AND mt2.is_statics = #{isStatics}
</if>
GROUP BY mt.type_id
</select>
2025-08-23 19:18:15 +08:00
</mapper>