Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialMachineMapper.xml

853 lines
34 KiB
XML
Raw Normal View History

2025-06-27 14:43:33 +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.clz.mapper.MaterialMachineMapper">
<select id="getMachineInfo" resultType="com.bonus.material.ma.domain.Machine">
SELECT
mt3.type_name AS materialName,
mt2.type_name AS typeName,
mt1.type_name AS typeCode,
mt.type_name AS maModel,
mm.ma_code AS maCode,
mm.qr_code AS qrCode,
mm.ma_status AS maStatus,
mm.this_check_time AS thisCheckTime,
mm.next_check_time AS nextCheckTime,
mm.inspect_man AS checkMan,
mm.out_fac_time AS outFacTime,
mm.create_time AS inputTime,
2025-07-08 15:06:27 +08:00
mm.ma_id AS maId,
bp.imp_unit AS impUnit,
2025-07-09 17:46:55 +08:00
bu.bzz_idcard AS idCard,
bp.external_id as externalId
2025-06-27 14:43:33 +08:00
FROM
slt_agreement_info sai
left join ma_machine mm ON sai.type_id = mm.type_id and mm.ma_id = sai.ma_id
left join ma_type mt ON mt.type_id = mm.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 ma_type mt2 ON mt1.parent_id = mt2.type_id and mt2.del_flag = 0
left join ma_type mt3 ON mt3.type_id = mt2.parent_id and mt3.del_flag = 0
2025-07-08 15:06:27 +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 bm_unit bu ON bai.unit_id = bu.unit_id
2025-06-27 14:43:33 +08:00
WHERE sai.`status` = '0' and mm.ma_code is not NULL
<if test="typeCode != null and typeCode != ''">
and mt1.type_name like concat('%', #{typeCode}, '%')
</if>
<if test="maModel != null and maModel != ''">
and mt.type_name like concat('%', #{maModel}, '%')
</if>
2025-08-06 17:50:48 +08:00
<if test="impUnit != null and impUnit != ''">
and bp.imp_unit = #{impUnit}
</if>
2025-07-14 17:27:12 +08:00
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2025-06-27 14:43:33 +08:00
GROUP BY
2025-07-07 19:07:11 +08:00
mm.ma_id
2025-06-27 14:43:33 +08:00
</select>
<select id="getRetainedEquipmentList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
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,
2025-07-05 13:22:39 +08:00
IFNULL(mt.lease_price, 0) AS buyPrice,
2025-07-05 17:27:05 +08:00
subquery1.proId AS proId,
subquery1.proName AS proName,
subquery1.externalId AS externalId,
2025-07-08 14:35:00 +08:00
subquery1.impUnit AS impUnit,
subquery1.idCard AS idCard,
2025-07-05 17:27:05 +08:00
IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0) AS storeNum,
2025-06-27 14:43:33 +08:00
IFNULL(subquery3.usNum, 0) AS usNum,
2025-07-05 17:27:05 +08:00
IFNULL(subquery1.usNum, 0) AS allNum,
2025-06-27 14:43:33 +08:00
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,
2025-07-05 13:22:39 +08:00
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.pro_name as proName,
2025-07-05 17:27:05 +08:00
bp.pro_id as proId,
2025-07-08 14:35:00 +08:00
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard
2025-06-27 14:43:33 +08:00
FROM
slt_agreement_info sai
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-07-05 13:22:39 +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
2025-07-08 14:35:00 +08:00
LEFT JOIN bm_unit bu ON bai.unit_id = bu.unit_id
AND bu.del_flag = '0'
2025-06-27 14:43:33 +08:00
WHERE
sai.`status` = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
2025-07-05 13:22:39 +08:00
GROUP BY mt.type_id, bp.pro_id
2025-06-27 14:43:33 +08:00
) AS subquery1
ON mt.type_id = subquery1.type_id
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
2025-07-05 13:22:39 +08:00
mt4.type_id AS firstTypeId,
2025-06-27 14:43:33 +08:00
mt3.type_name AS materialType,
2025-07-05 13:22:39 +08:00
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,
bp.pro_name as proName,
2025-07-05 17:27:05 +08:00
bp.pro_id as proId,
2025-07-08 14:35:00 +08:00
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard
2025-07-05 13:22:39 +08:00
FROM
clz_slt_agreement_info sai
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
2025-06-27 14:43:33 +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-07-05 13:22:39 +08:00
LEFT JOIN clz_bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2025-07-08 14:35:00 +08:00
LEFT JOIN bm_unit bu ON bai.unit_id = bu.unit_id
AND bu.del_flag = '0'
2025-07-05 13:22:39 +08:00
WHERE
sai.`status` = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
GROUP BY mt.type_id, bp.pro_id
) AS subquery3
2025-06-27 14:43:33 +08:00
ON mt.type_id = subquery3.type_id
2025-07-05 17:27:05 +08:00
AND subquery1.proId = subquery3.proId
2025-06-27 14:43:33 +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
WHERE mt.`level` = 4 and mt.del_flag = '0'
<if test="typeId != null">
<if test="level == 3">
and mt.parent_id = #{typeId}
</if>
<if test="level == 2">
and mt2.parent_id = #{typeId}
</if>
</if>
<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
2025-07-05 17:27:05 +08:00
mt.type_name like concat('%',#{keyWord},'%') or
subquery1.proName like concat('%',#{keyWord},'%')
2025-06-27 14:43:33 +08:00
)
</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>
2025-07-16 11:35:04 +08:00
<if test="impUnit != null and impUnit != ''">
and subquery1.impUnit = #{impUnit}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
and subquery1.externalId in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2025-07-05 13:22:39 +08:00
GROUP BY
mt.type_id,
2025-07-05 17:27:05 +08:00
subquery1.proId
2025-06-27 14:43:33 +08:00
</select>
<select id="getMaCodeList"
resultType="com.bonus.material.clz.domain.machine.MaterialStorageInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.lease_price AS buyPrice,
sai.num AS storeNum,
mm.ma_code AS maCode,
bt.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
2025-07-05 17:27:05 +08:00
lai.code AS code,
sai.ma_id AS maId
2025-06-27 14:43:33 +08:00
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_machine mm ON mm.ma_id = sai.ma_id
LEFT JOIN bm_agreement_info bai ON bai.agreement_id = sai.agreement_id
LEFT JOIN bm_unit bt ON bai.unit_id = bt.unit_id
LEFT JOIN lease_apply_info lai ON lai.id = sai.lease_id
2025-07-05 17:27:05 +08:00
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2025-06-27 14:43:33 +08:00
WHERE
sai.status = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="typeId != null">
AND sai.type_id = #{typeId}
</if>
2025-07-05 17:27:05 +08:00
<if test="proId != null and proId != ''">
AND bp.pro_id = #{proId}
</if>
2025-06-27 14:43:33 +08:00
</select>
<select id="selectInFo" resultType="com.bonus.material.clz.domain.machine.MaterialStorageInfo">
SELECT
lod.create_time as inputTime,
GROUP_CONCAT( DISTINCT su.nick_name ) AS inputUser
FROM
lease_out_details lod
LEFT JOIN sys_user su on su.user_id = lod.create_by
WHERE lod.parent_id = #{leaseId}
GROUP BY lod.parent_id
LIMIT 1
</select>
<select id="getTeamUseNumList"
resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
bt.unit_name AS teamName,
mt.type_name AS typeModelName,
mt2.type_name AS typeName,
SUM(IFNULL(sai.num, 0)) AS usNum,
2025-07-08 14:35:00 +08:00
mt2.type_id AS typeId,
bp.imp_unit AS impUnit,
2025-07-09 17:46:55 +08:00
bt.bzz_idcard AS idCard,
bp.external_id as externalId
2025-06-27 14:43:33 +08:00
FROM
2025-07-08 14:35:00 +08:00
clz_slt_agreement_info sai
LEFT JOIN clz_bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
2025-06-27 14:43:33 +08:00
LEFT JOIN bm_unit bt ON bai.unit_id = bt.unit_id
2025-07-08 14:35:00 +08:00
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2025-06-27 14:43:33 +08:00
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
WHERE
sai.end_time IS NULL
AND sai.back_id IS NULL
2025-07-12 10:21:07 +08:00
<if test="teamId != null and teamId != ''">
2025-06-27 14:43:33 +08:00
AND bt.unit_id = #{teamId}
</if>
2025-07-12 10:21:07 +08:00
<if test="teamName != null and teamName != ''">
2025-06-27 14:43:33 +08:00
AND bt.unit_name LIKE concat('%',#{teamName},'%')
</if>
<if test="keyWord != null and keyWord != ''">
AND (
mt2.type_name LIKE concat('%',#{keyWord},'%')
OR mt.type_name LIKE concat('%',#{keyWord},'%')
OR bt.unit_name LIKE concat('%',#{keyWord},'%')
)
</if>
2025-07-14 17:27:12 +08:00
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2025-06-27 14:43:33 +08:00
GROUP BY
bt.unit_name,
mt2.type_name;
</select>
<select id="getTeamUseNumDetailsList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
bt.unit_name AS teamName,
mt.type_name AS typeModelName,
mt2.type_name AS typeName,
SUM(IFNULL(sai.num, 0)) AS usNum,
mm.ma_code AS maCode,
mm.this_check_time AS thisCheckTime,
mm.next_check_time AS nextCheckTime,
2025-07-08 14:35:00 +08:00
mt.manage_type AS manageType,
bp.imp_unit AS impUnit,
2025-08-05 19:33:56 +08:00
bt.bzz_idcard AS idCard,
2025-08-06 17:50:48 +08:00
bp.pro_name AS proName,
CASE
WHEN mm.next_check_time &lt; CURDATE() THEN 3 -- 已超过当前时间
WHEN DATEDIFF(mm.next_check_time, CURDATE()) &lt;= 30 THEN 2 -- 相差不足1个月
WHEN DATEDIFF(mm.next_check_time, CURDATE()) &lt;= 90 THEN 1 -- 相差不足3个月
ELSE 0 -- 相差3个月以上
END AS status
2025-06-27 14:43:33 +08:00
FROM
clz_slt_agreement_info sai
2025-07-04 18:07:30 +08:00
LEFT JOIN clz_bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
2025-06-27 14:43:33 +08:00
LEFT JOIN bm_unit bt ON bai.unit_id = bt.unit_id
2025-07-08 14:35:00 +08:00
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2025-06-27 14:43:33 +08:00
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_machine mm ON mm.ma_id = sai.ma_id
WHERE
2025-07-09 17:46:55 +08:00
sai.status = '0'
AND sai.end_time IS NULL
2025-06-27 14:43:33 +08:00
AND sai.back_id IS NULL
<if test="typeId != null">
and mt2.type_id = #{typeId}
</if>
2025-08-05 19:33:56 +08:00
<if test="maId != null">
and sai.ma_id = #{maId}
</if>
2025-07-10 09:22:11 +08:00
<if test="teamId != null and teamId != ''">
2025-06-27 14:43:33 +08:00
AND bt.unit_id = #{teamId}
</if>
2025-07-10 09:22:11 +08:00
<if test="teamName != null and teamName != ''">
2025-06-27 14:43:33 +08:00
AND bt.unit_name LIKE concat('%',#{teamName},'%')
</if>
<if test="keyWord != null and keyWord != ''">
AND (
mt2.type_name LIKE concat('%',#{keyWord},'%')
OR mt.type_name LIKE concat('%',#{keyWord},'%')
OR bt.unit_name LIKE concat('%',#{keyWord},'%')
OR mm.ma_code LIKE concat('%',#{keyWord},'%')
)
</if>
2025-08-06 17:50:48 +08:00
<if test="jiJuType != null and jiJuType != 0">
2025-08-05 19:33:56 +08:00
and mt.jiju_type = #{jiJuType}
</if>
2025-06-27 14:43:33 +08:00
GROUP BY
mt.type_name,
mt2.type_name,
2025-07-08 14:35:00 +08:00
mm.ma_id
2025-06-27 14:43:33 +08:00
</select>
<select id="getTeamData" resultType="com.bonus.material.clz.domain.BmTeam">
SELECT
unit_id as id,
unit_name as teamName
FROM
bm_unit
WHERE bzz_idcard = #{username}
LIMIT 1
</select>
<select id="getToolsLedgerList"
resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
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,
2025-07-09 17:46:55 +08:00
IFNULL(mt.lease_price, 0) AS buyPrice,
subquery1.externalId AS externalId,
subquery1.impUnit AS impUnit,
subquery1.idCard AS idCard,
IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0) AS storeNum,
IFNULL(subquery3.usNum, 0) AS usNum,
IFNULL(subquery1.usNum, 0) AS allNum,
2025-06-27 14:43:33 +08:00
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
2025-07-09 17:46:55 +08:00
END manageType
2025-06-27 14:43:33 +08:00
FROM ma_type mt
LEFT JOIN (
SELECT
mt.type_id,
mt4.type_name AS constructionType,
2025-07-08 14:35:00 +08:00
mt4.type_id AS firstTypeId,
2025-06-27 14:43:33 +08:00
mt3.type_name AS materialType,
2025-07-08 14:35:00 +08:00
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,
2025-07-09 17:46:55 +08:00
bp.external_id as externalId,
2025-07-08 14:35:00 +08:00
bp.imp_unit AS impUnit,
2025-07-09 17:46:55 +08:00
bu.bzz_idcard AS idCard
2025-07-08 14:35:00 +08:00
FROM
slt_agreement_info sai
2025-07-09 17:46:55 +08:00
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-07-08 14:35:00 +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
2025-07-09 17:46:55 +08:00
LEFT JOIN bm_unit bu ON bai.unit_id = bu.unit_id
AND bu.del_flag = '0'
WHERE
sai.`status` = '0'
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,
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard
FROM
clz_slt_agreement_info sai
2025-07-08 14:35:00 +08:00
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
2025-06-27 14:43:33 +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-07-09 17:46:55 +08:00
LEFT JOIN clz_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 bm_unit bu ON bai.unit_id = bu.unit_id
AND bu.del_flag = '0'
2025-07-08 14:35:00 +08:00
WHERE
sai.`status` = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
2025-07-09 17:46:55 +08:00
GROUP BY mt.type_id
) AS subquery3
ON mt.type_id = subquery3.type_id
2025-06-27 14:43:33 +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-07-09 17:46:55 +08:00
WHERE mt.`level` = 4 and mt.del_flag = '0'
2025-06-27 14:43:33 +08:00
<if test="keyWord != null and keyWord != ''">
and (mt2.type_name like concat('%',#{keyWord},'%')
OR mt.type_name like concat('%',#{keyWord},'%') )
</if>
2025-07-14 19:22:44 +08:00
<if test="projectIdList != null and projectIdList.size() > 0">
and subquery1.externalId in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2025-07-09 17:46:55 +08:00
GROUP BY
mt.type_id
2025-06-27 14:43:33 +08:00
</select>
<select id="getToolsLedgerDetailsList"
resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
bt.unit_name AS teamName,
mt.type_name AS typeModelName,
mt1.type_name AS typeName,
mm.ma_code AS maCode,
mm.this_check_time AS thisCheckTime,
mm.next_check_time AS nextCheckTime,
2025-07-09 17:46:55 +08:00
mt.manage_type AS manageType,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
2025-08-06 17:50:48 +08:00
bt.bzz_idcard AS idCard,
CASE
WHEN mm.next_check_time &lt; CURDATE() THEN 3 -- 已超过当前时间
WHEN DATEDIFF(mm.next_check_time, CURDATE()) &lt;= 30 THEN 2 -- 相差不足1个月
WHEN DATEDIFF(mm.next_check_time, CURDATE()) &lt;= 90 THEN 1 -- 相差不足3个月
ELSE 0 -- 相差3个月以上
END AS status
2025-06-27 14:43:33 +08:00
FROM
slt_agreement_info sai
LEFT JOIN bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_unit bt ON bai.unit_id = bt.unit_id
2025-07-09 17:46:55 +08:00
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2025-06-27 14:43:33 +08:00
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
LEFT JOIN ma_type mt1 ON mt1.parent_id = mt1.type_id
LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id
WHERE
sai.status = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="typeId != null">
and mt.type_id = #{typeId}
</if>
<if test="maCode != null and maCode != ''">
AND mm.ma_code like concat('%',#{maCode},'%')
</if>
2025-07-14 17:27:12 +08:00
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2025-06-27 14:43:33 +08:00
GROUP BY
mt.type_name,
mt1.type_name,
2025-07-09 17:46:55 +08:00
mm.ma_id
2025-06-27 14:43:33 +08:00
</select>
<select id="getToolsDetailsListByTeam"
resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT aa.typeName,
aa.typeModelName,
mm.ma_code as maCode,
mm.this_check_time as thisCheckTime,
mm.next_check_time as nextCheckTime
FROM (SELECT t1.maId,
t1.typeName,
t1.typeModelName,
t1.typeId,
t1.thirdTypeId,
t1.manageType
FROM (SELECT lod.ma_id as maId,
mt2.type_name as typeName,
mt1.type_name as typeModelName,
lod.type_id as typeId,
mt2.type_id as thirdTypeId,
mt1.manage_type as manageType,
mt1.buy_price as buyPrice,
mt1.unit_name as unit,
COUNT(*) as count
FROM
clz_lease_out_details lod
LEFT JOIN clz_lease_apply_info lai
on lai.id=lod.parent_id
LEFT JOIN ma_type mt1 on mt1.type_id=lod.type_id
LEFT JOIN ma_type mt2 on mt2.type_id=mt1.parent_id
WHERE
lai.team_id = #{teamId}
and lod.is_finished='1'
and lod.type_id = #{typeId}
GROUP BY lod.ma_id, lod.type_id) t1
LEFT JOIN (SELECT bcd.ma_id as maId,
COUNT(*) as count
FROM
clz_back_check_details bcd
LEFT JOIN clz_back_apply_info bai
on bai.id=bcd.parent_id
LEFT JOIN tm_task tt on tt.task_id = bai.task_id
LEFT JOIN tm_task_agreement tta on tta.task_id = tt.task_id
2025-07-04 18:07:30 +08:00
LEFT JOIN clz_bm_agreement_info bagi on bagi.agreement_id = tta.agreement_id
2025-06-27 14:43:33 +08:00
WHERE
bagi.unit_id = #{teamId}
and bcd.is_finished='1'
and bcd.type_id = #{typeId}
GROUP BY bcd.ma_id) t2 ON t1.maId = t2.maId
WHERE t1.count > IFNULL(t2.count, 0)) aa
LEFT JOIN ma_machine mm
on aa.maId = mm.ma_id
</select>
<select id="getToolsDetailsList"
resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
bt.unit_name AS teamName,
mt.type_name AS typeModelName,
mt1.type_name AS typeName,
mm.ma_code AS maCode,
mm.this_check_time AS thisCheckTime,
mm.next_check_time AS nextCheckTime,
2025-08-06 17:50:48 +08:00
mt.manage_type AS manageType,
CASE
WHEN mm.next_check_time &lt; CURDATE() THEN 3 -- 已超过当前时间
WHEN DATEDIFF(mm.next_check_time, CURDATE()) &lt;= 30 THEN 2 -- 相差不足1个月
WHEN DATEDIFF(mm.next_check_time, CURDATE()) &lt;= 90 THEN 1 -- 相差不足3个月
ELSE 0 -- 相差3个月以上
END AS status
2025-06-27 14:43:33 +08:00
FROM
slt_agreement_info sai
LEFT JOIN bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_unit bt ON bai.unit_id = bt.unit_id
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
2025-07-10 09:22:11 +08:00
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
2025-06-27 14:43:33 +08:00
LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id
WHERE
sai.status = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="typeId != null">
and mt.type_id = #{typeId}
</if>
<if test="keyWord != null and keyWord != ''">
AND (mm.ma_code like concat('%',#{keyWord},'%')
OR mt1.type_name like concat('%',#{keyWord},'%')
OR mt.type_name like concat('%',#{keyWord},'%'))
</if>
GROUP BY
mt.type_name,
mt1.type_name,
2025-07-08 15:06:27 +08:00
mm.ma_id
2025-06-27 14:43:33 +08:00
</select>
<select id="selectStatusById" resultType="com.bonus.material.clz.domain.vo.MaterialSltAgreementInfo">
SELECT
type_id as typeId,
ma_id as maId,
status as status
FROM clz_slt_agreement_info
WHERE status = '0' and ma_id = #{maId}
</select>
<select id="getSltAgreementInfo" resultType="com.bonus.material.ma.domain.Machine">
SELECT
mt3.type_name AS materialName,
mt2.type_name AS typeName,
mt1.type_name AS typeCode,
mt.type_name AS maModel,
mm.ma_code AS maCode,
mm.qr_code AS qrCode,
mm.ma_status AS maStatus,
mm.this_check_time AS thisCheckTime,
mm.next_check_time AS nextCheckTime,
mm.inspect_man AS checkMan,
mm.out_fac_time AS outFacTime,
mm.create_time AS inputTime,
2025-07-09 17:46:55 +08:00
mm.ma_id AS maId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
bp.external_id as externalId
2025-06-27 14:43:33 +08:00
FROM
clz_slt_agreement_info sai
left join ma_machine mm ON sai.type_id = mm.type_id and mm.ma_id = sai.ma_id
left join ma_type mt ON mt.type_id = mm.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 ma_type mt2 ON mt1.parent_id = mt2.type_id and mt2.del_flag = 0
left join ma_type mt3 ON mt3.type_id = mt2.parent_id and mt3.del_flag = 0
2025-07-09 17:46:55 +08:00
LEFT JOIN clz_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 bm_unit bu ON bai.unit_id = bu.unit_id
2025-06-27 14:43:33 +08:00
WHERE mm.ma_code is not NULL
<if test="typeCode != null and typeCode != ''">
and mt1.type_name like concat('%', #{typeCode}, '%')
</if>
<if test="maModel != null and maModel != ''">
and mt.type_name like concat('%', #{maModel}, '%')
</if>
2025-07-14 17:27:12 +08:00
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2025-06-27 14:43:33 +08:00
GROUP BY
2025-07-07 19:07:11 +08:00
mm.ma_id
2025-06-27 14:43:33 +08:00
</select>
<select id="getUserRecords" resultType="com.bonus.material.clz.domain.machine.MaterialUseStorageInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.lease_price AS buyPrice,
sai.num AS usNum,
mm.ma_code AS maCode,
bt.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
2025-07-05 17:27:05 +08:00
lai.code AS code,
2025-08-06 17:50:48 +08:00
sai.ma_id AS maId,
bp.pro_name AS proName
2025-06-27 14:43:33 +08:00
FROM
clz_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_machine mm ON mm.ma_id = sai.ma_id
2025-07-04 18:07:30 +08:00
LEFT JOIN clz_bm_agreement_info bai ON bai.agreement_id = sai.agreement_id
2025-06-27 14:43:33 +08:00
LEFT JOIN bm_unit bt ON bai.unit_id = bt.unit_id
LEFT JOIN clz_lease_apply_info lai ON lai.id = sai.lease_id
2025-07-05 17:27:05 +08:00
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
2025-06-27 14:43:33 +08:00
WHERE
sai.status = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="typeId != null">
AND sai.type_id = #{typeId}
</if>
2025-07-05 17:27:05 +08:00
<if test="proId != null and proId != ''">
AND bp.pro_id = #{proId}
</if>
2025-06-27 14:43:33 +08:00
</select>
<select id="selectUseInFo" resultType="com.bonus.material.clz.domain.machine.MaterialUseStorageInfo">
SELECT
2025-08-06 17:50:48 +08:00
cld.create_time as outTime,
GROUP_CONCAT( DISTINCT su.nick_name ) AS creator
2025-06-27 14:43:33 +08:00
FROM
2025-08-06 17:50:48 +08:00
clz_lease_out_details cld
left join sys_user su ON su.user_id = cld.create_by
2025-06-27 14:43:33 +08:00
WHERE parent_id = #{leaseId}
GROUP BY parent_id
LIMIT 1
</select>
2025-07-08 15:06:27 +08:00
2025-08-05 19:33:56 +08:00
<select id="getTotalList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
2025-08-06 17:50:48 +08:00
SELECT * FROM (
-- 原查询包含status计算
2025-08-05 19:33:56 +08:00
SELECT
2025-08-06 17:50:48 +08:00
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
sai.ma_id AS maId,
mm.ma_code AS maCode,
mm.this_check_time AS thisCheckTime,
mm.next_check_time AS nextCheckTime,
bp.imp_unit AS impUnit,
mt.manage_type AS manageType,
-- 计算status的CASE表达式
CASE
WHEN mm.next_check_time &lt; CURDATE() THEN 3 -- 已超过当前时间
WHEN DATEDIFF(mm.next_check_time, CURDATE()) &lt;= 30 THEN 2 -- 相差不足1个月
WHEN DATEDIFF(mm.next_check_time, CURDATE()) &lt;= 90 THEN 1 -- 相差不足3个月
ELSE 0 -- 相差3个月以上
END AS status,
bp.pro_name AS proName,
bu.unit_name AS teamName
2025-08-05 19:33:56 +08:00
FROM
2025-08-06 17:50:48 +08:00
slt_agreement_info sai
2025-08-05 19:33:56 +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 mt.type_id = sai.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id
2025-08-06 17:50:48 +08:00
LEFT JOIN clz_slt_agreement_info csi ON mm.ma_id = csi.ma_id
LEFT JOIN clz_bm_agreement_info cba ON csi.agreement_id = cba.agreement_id
LEFT JOIN bm_unit bu ON cba.unit_id = bu.unit_id
2025-08-05 19:33:56 +08:00
WHERE
2025-08-06 17:50:48 +08:00
sai.`status` = '0'
AND mt.jiju_type = 2
AND sai.ma_id IS NOT NULL
<if test="agreementIdList != null and agreementIdList.size >0">
AND sai.agreement_id IN
<foreach item="item" collection="agreementIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="deptId != null">
AND bp.imp_unit = #{deptId}
</if>
<if test="keyWord != null and keyWord != ''">
and (
bu.unit_name like concat('%',#{keyWord},'%') or
bp.pro_name like concat('%',#{keyWord},'%') or
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
mm.ma_code like concat('%',#{keyWord},'%')
)
</if>
) AS temp -- 子查询别名
-- 对计算出的status进行筛选
<if test="status != null and status != ''">
WHERE temp.status = #{status}
</if>
-- 排序proName和teamName都不为空的排在最前面
ORDER BY
-- 核心排序逻辑:两个字段都不为空的记录优先级最高
CASE
WHEN temp.proName IS NOT NULL AND temp.proName != ''
AND temp.teamName IS NOT NULL AND temp.teamName != '' THEN 0 -- 优先排在前面
ELSE 1 -- 其他情况排在后面
END ASC,
-- 可根据需要添加其他排序字段(如原顺序或时间)
temp.maId ASC -- 示例按maId升序排列可选
2025-08-05 19:33:56 +08:00
</select>
<select id="getTeamNumList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedTeamTotalVo">
SELECT
bu.unit_id as teamId,
bu.unit_name as teamName,
bu.link_man as teamLeaderIdCard,
SUM( sai.num ) as usNum
FROM
bm_unit bu
LEFT JOIN clz_bm_agreement_info bai ON bu.unit_id = bai.unit_id
LEFT JOIN clz_slt_agreement_info sai ON bai.agreement_id = sai.agreement_id
WHERE
sai.`status` = 0 and bu.type_id = 1731
<if test="keyWord != null and keyWord != ''">
and (
bu.unit_name like concat('%',#{keyWord},'%') or
bu.link_man like concat('%',#{keyWord},'%')
)
</if>
GROUP BY
bu.unit_id
</select>
<select id="getTeamNumSecondList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedTeamVo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
SUM(sai.num) AS usNum,
bt.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
lai.code AS code,
lai.lease_person AS leasePerson,
mt.manage_type AS manageType,
sai.agreement_id AS agreementId
FROM
clz_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_machine mm ON mm.ma_id = sai.ma_id
LEFT JOIN clz_bm_agreement_info bai ON bai.agreement_id = sai.agreement_id
LEFT JOIN bm_unit bt ON bai.unit_id = bt.unit_id
LEFT JOIN clz_lease_apply_info lai ON lai.id = sai.lease_id
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
WHERE
sai.status = '0'
AND bt.unit_id = #{teamId}
<if test="keyWord != null and keyWord != ''">
and (
mt2.type_name like concat('%',#{keyWord},'%') or
mt.type_name like concat('%',#{keyWord},'%') or
bt.unit_name like concat('%',#{keyWord},'%') or
lai.code like concat('%',#{keyWord},'%') or
lai.lease_person like concat('%',#{keyWord},'%')
)
</if>
GROUP BY sai.type_id
</select>
<select id="getTeamNumThirdList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
sai.type_id AS typeId,
sai.ma_id AS maId,
mm.ma_code AS maCode
FROM
clz_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_machine mm ON mm.ma_id = sai.ma_id
WHERE
sai.STATUS = '0'
AND sai.agreement_id = #{agreementId}
AND sai.type_id = #{typeId}
<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},'%')
)
</if>
GROUP BY
sai.ma_id
</select>
2025-06-27 14:43:33 +08:00
</mapper>