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

3132 lines
127 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

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

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.material.clz.mapper.MaterialMachineMapper">
<update id="updateMachine">
UPDATE ma_machine
SET qr_code = #{qrCode}
WHERE ma_code = #{maCode}
and type_id = #{typeId}
</update>
<select id="getMachineInfo" resultType="com.bonus.material.ma.domain.Machine">
SELECT
sd.dept_name AS impUnitName,
bu.unit_name as leaseUnit,
bp.pro_name as leaseProject,
bp.pro_center AS departName,
mt3.type_name AS materialName,
mt1.type_name AS typeName,
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.check_man AS checkMan,
mm.out_fac_time AS outFacTime,
sai.start_time AS inputTime,
mm.ma_id AS maId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
bp.external_id as externalId
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
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
left join sys_dept sd on sd.dept_id = bp.imp_unit
WHERE sai.`status` = '0' and mm.ma_code is not NULL
<if test="keyWord != null and keyWord != ''">
and (
mt1.type_name like concat('%',#{keyWord},'%') or
mm.inspect_man like concat('%',#{keyWord},'%') or
mm.ma_code like concat('%',#{keyWord},'%')
)
</if>
<if test="impUnitName != null and impUnitName != ''">
and sd.dept_name like concat('%', #{impUnitName}, '%')
</if>
<if test="departName != null and departName != ''">
and bp.pro_center like concat('%', #{departName}, '%')
</if>
<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>
<if test="impUnit != null and impUnit != ''">
and bp.imp_unit = #{impUnit}
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
<![CDATA[and DATE_FORMAT( mm.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime} ]]>
</if>
<if test="checkStartTime != null and checkStartTime != '' and checkEndTime != null and checkEndTime != ''">
<![CDATA[and DATE_FORMAT( mm.this_check_time, '%Y-%m-%d' ) BETWEEN #{checkStartTime} AND #{checkEndTime} ]]>
</if>
<if test="nextStartTime != null and nextStartTime != '' and nextEndTime != null and nextEndTime != ''">
<![CDATA[and DATE_FORMAT( mm.next_check_time, '%Y-%m-%d' ) BETWEEN #{nextStartTime} AND #{nextEndTime} ]]>
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY
mm.ma_id
</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,
IFNULL(mt.lease_price, 0) AS buyPrice,
subquery1.proId AS proId,
subquery1.proName AS proName,
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,
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
END manageType,
subquery1.proCenter AS proCenter
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,
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
bp.pro_center AS proCenter
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
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
AND bu.del_flag = '0'
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
GROUP BY mt.type_id, bp.pro_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.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
bp.pro_center AS proCenter
FROM
clz_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
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'
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
GROUP BY mt.type_id, bp.pro_id
) AS subquery3
ON mt.type_id = subquery3.type_id
AND subquery1.proId = subquery3.proId
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="proId != null">
and subquery1.proId = #{proId}
</if>
<if test="proCenter != null and proCenter != ''">
and subquery1.proCenter like concat('%',#{proCenter},'%')
</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
mt.type_name like concat('%',#{keyWord},'%') or
subquery1.proName 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>
<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>
GROUP BY
mt.type_id,
subquery1.proId,
subquery1.proCenter
</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,
SUM(IFNULL( sai.num, 0 )) AS storeNum,
mm.ma_code AS maCode,
bt.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
lai.code AS code,
sai.ma_id AS maId,
bp.pro_name AS proName,
CASE WHEN
lai.direct_id IS NULL
THEN '1' ELSE '0'
END AS directFlag,
mt.manage_type AS manageType
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
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
WHERE
sai.status = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bt.type_id = 36
<if test="typeId != null">
AND sai.type_id = #{typeId}
</if>
<if test="proId != null and proId != ''">
AND bp.pro_id = #{proId}
</if>
GROUP BY
sai.type_id,
sai.ma_id,
lai.direct_id
</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,
mt2.type_id AS typeId,
bp.imp_unit AS impUnit,
bt.bzz_idcard AS idCard,
bp.external_id AS externalId,
bp.pro_id AS proId
FROM
clz_slt_agreement_info sai
LEFT JOIN clz_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 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
WHERE
sai.end_time IS NULL
AND sai.back_id IS NULL
AND sai.is_slt = '0'
<if test="teamId != null and teamId != ''">
AND bt.unit_id = #{teamId}
</if>
<if test="teamName != null and teamName != ''">
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>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
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,
mt.manage_type AS manageType,
bp.imp_unit AS impUnit,
bt.bzz_idcard AS idCard,
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
FROM
clz_slt_agreement_info sai
LEFT JOIN clz_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 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
WHERE
sai.status = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND sai.ma_id IS NOT NULL
<if test="typeId != null">
and mt2.type_id = #{typeId}
</if>
<if test="maId != null">
and sai.ma_id = #{maId}
</if>
<if test="teamId != null and teamId != ''">
AND bt.unit_id = #{teamId}
</if>
<if test="teamName != null and teamName != ''">
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>
<if test="jiJuType != null and jiJuType != 0">
and mt.jiju_type = #{jiJuType}
</if>
GROUP BY
mt.type_name,
mt2.type_name,
mm.ma_id
</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}
</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,
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,
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,
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard
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
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
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
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
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'
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
GROUP BY mt.type_id
) AS subquery3
ON mt.type_id = subquery3.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 (mt2.type_name like concat('%',#{keyWord},'%')
OR mt.type_name like concat('%',#{keyWord},'%') )
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
and subquery1.externalId in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY
mt.type_id
</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,
mt.manage_type AS manageType,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
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
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 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 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.is_slt = '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>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY
mt.type_name,
mt1.type_name,
mm.ma_id
</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
LEFT JOIN clz_bm_agreement_info bagi on bagi.agreement_id = tta.agreement_id
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,
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
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
LEFT JOIN ma_type mt1 ON mt.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="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,
mm.ma_id
</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}
AND is_slt = '0'
</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,
mm.ma_id AS maId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
bp.external_id as externalId
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
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
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>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY
mm.ma_id
</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,
lai.code AS code,
sai.ma_id AS maId,
bp.pro_name AS proName
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 sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="typeId != null">
AND sai.type_id = #{typeId}
</if>
<if test="proId != null and proId != ''">
AND bp.pro_id = #{proId}
</if>
</select>
<select id="selectUseInFo" resultType="com.bonus.material.clz.domain.machine.MaterialUseStorageInfo">
SELECT
cld.create_time as outTime,
GROUP_CONCAT( DISTINCT su.nick_name ) AS creator
FROM
clz_lease_out_details cld
left join sys_user su ON su.user_id = cld.create_by
WHERE parent_id = #{leaseId}
GROUP BY parent_id
LIMIT 1
</select>
<select id="getTotalList" resultType="com.bonus.material.clz.domain.vo.SafeMaterialEquipmentInfo">
SELECT * FROM (
-- 原查询包含status计算
SELECT
sd.dept_name as impUnitName,
bp.pro_center AS departName,
mt3.type_name as materialName,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
sai.ma_id AS maId,
mm.ma_code AS maCode,
mm.ex_code AS reportCode,
mm.ex_url AS reportUrl,
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_id AS proId,
bp.pro_name AS proName,
IF(csi.`status` = 0,bu.unit_name,"") AS teamName,
bu.bzz_idcard AS idCard,
mm.qr_code AS qrCode,
IF(csi.`status` = 0,bz.ssfbdw,"") AS subUnitName
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 mt.parent_id = mt2.type_id
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id
LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id
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
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN `micro-tool`.bzgl_bz bz ON bp.external_id = bz.project_id
AND bz.bzmc = bu.unit_name
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND mm.ma_status = 2
AND sai.ma_id IS NOT NULL
AND mt2.type_id not in (6032,6008,6270)
AND bp.pro_id not in (3414,1192,3321,3595)
AND mm.this_check_time is not null
AND mm.next_check_time is not null
AND mt.jiju_type = 2
<if test="impUnitName != null and impUnitName != ''">
and sd.dept_name LIKE CONCAT('%', #{impUnitName}, '%')
</if>
<if test="departName != null and departName != ''">
and bp.pro_center LIKE CONCAT('%', #{departName}, '%')
</if>
<if test="proName != null and proName != ''">
and bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="typeName != null and typeName != ''">
and mt2.type_name LIKE CONCAT('%', #{typeName}, '%')
</if>
<if test="teamName != null and teamName != ''">
and bu.unit_name LIKE CONCAT('%', #{teamName}, '%')
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
<![CDATA[ AND DATE_FORMAT( mm.this_check_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime} ]]>
</if>
<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="subUnitName != null and subUnitName != ''">
AND bz.ssfbdw LIKE CONCAT('%', #{subUnitName}, '%')
</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},'%') or
mm.ex_code like concat('%',#{keyWord},'%')
)
</if>
) AS temp -- 子查询别名
-- 对计算出的status进行筛选
<if test="status != null and status != ''">
WHERE temp.status = #{status}
</if>
GROUP BY
temp.typeName,
temp.typeModelName ,
temp.maId
-- 排序proName和teamName都不为空的排在最前面
ORDER BY
-- 核心排序逻辑:两个字段都不为空的记录优先级最高
SUBSTRING( temp.typeName, 1, 1 ) ASC ,
temp.nextCheckTime ASC
</select>
<select id="getTeamNumList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedTeamTotalVo">
SELECT
sd.dept_name AS impUnitName,
bp.pro_center AS departName,
bu.unit_id as teamId,
bu.unit_name as teamName,
bu.link_man as teamLeaderIdCard,
SUM( sai.num ) as usNum,
bu.bzz_idcard as idCard,
bp.imp_unit as impUnit,
bp.pro_id AS proId,
bp.pro_name as proName,
IFNULL(bz.ssfbdw,cai.sub_unit_name) AS subUnitName
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
LEFT JOIN clz_lease_apply_info cai on sai.lease_id = cai.id
LEFT JOIN bm_project bp ON bp.pro_id = bai.project_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN `micro-tool`.bzgl_bz bz ON bp.external_id = bz.project_id
AND bz.bzmc = bu.unit_name
WHERE
sai.`status` = 0 and bu.type_id = 1731 and bp.pro_id is not null
AND sai.is_slt = '0'
and bp.pro_id not in (3414,1192,3321,3595)
<if test="keyWord != null and keyWord != ''">
and (
bu.unit_name like concat('%',#{keyWord},'%') or
bu.link_man like concat('%',#{keyWord},'%')
)
</if>
<if test="impUnitName != null and impUnitName != ''">
and sd.dept_name LIKE CONCAT('%', #{impUnitName}, '%')
</if>
<if test="subUnitName != null and subUnitName != ''">
and (
bz.ssfbdw LIKE CONCAT('%', #{subUnitName}, '%') or
cai.sub_unit_name like concat('%',#{subUnitName},'%')
)
</if>
<if test="departName != null and departName != ''">
and bp.pro_center LIKE CONCAT('%', #{departName}, '%')
</if>
<if test="proName != null and proName != ''">
and bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="teamName != null and teamName != ''">
and bu.unit_name LIKE CONCAT('%', #{teamName}, '%')
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY
bu.unit_id,
bp.pro_id
ORDER BY sai.ID desc
</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,
mt.unit_name as unitName
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 sai.is_slt = '0'
AND bt.unit_id = #{teamId}
AND bai.project_id = #{proId}
<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.is_slt = '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>
<select id="getTotalInfoList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
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,
CASE mt.manage_type WHEN 0 THEN '编码' ELSE '数量' END AS manageType,
subquery1.proId AS proId,
subquery1.proName AS proName,
subquery1.proCenter AS proCenter
FROM ma_type mt
LEFT JOIN (
SELECT
mt.type_id,
SUM(IFNULL(sai.num, 0)) AS usNum,
bp.pro_name AS proName,
bp.pro_id AS proId,
bp.external_id AS externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
bp.pro_center AS proCenter
FROM slt_agreement_info sai
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
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 AND bu.del_flag = '0'
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="proId != null">
AND bp.pro_id = #{proId}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id IN
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY mt.type_id, bp.pro_id, bp.pro_name, bp.external_id, bp.imp_unit, bu.bzz_idcard, bp.pro_center
) AS subquery1 ON mt.type_id = subquery1.type_id
LEFT JOIN (
SELECT
mt.type_id,
SUM(IFNULL(sai.num, 0)) AS usNum,
bp.pro_id AS proId
FROM clz_slt_agreement_info sai
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
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'
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="proId != null">
AND bp.pro_id = #{proId}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id IN
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY mt.type_id, bp.pro_id
) AS subquery3
ON mt.type_id = subquery3.type_id
AND subquery1.proId IS NOT NULL
AND subquery1.proId = subquery3.proId
WHERE
mt.`level` = 4
AND mt.del_flag = '0'
AND subquery1.usNum > 0
<if test="impUnit != null and impUnit != ''">
AND subquery1.impUnit = #{impUnit}
</if>
</select>
<select id="getTeamInOrOutInfo" resultType="com.bonus.material.clz.domain.TeamVo">
SELECT DISTINCT
sd.dept_name AS impUnitName,
df.project_dept AS departName,
bzgl_bz.ssfbdw AS subcontractor,
bzgl_bz.bzmc AS teamName,
bzgl_bz.bzz_name AS teamLeaderName,
bzgl_bz.bz_status AS teamStatus,
CASE bzgl_bz.bz_status
WHEN '1' THEN '空闲'
WHEN '2' THEN '申报'
WHEN '3' THEN '进场'
ELSE '未知'
END AS teamStatusName,
bp.pro_id AS proId,
bzgl_bz.project_name AS projectName,
bzgl_bz.sfjs AS isDismiss,
CASE bzgl_bz.sfjs
WHEN '0' THEN '否'
WHEN '1' THEN '是'
ELSE '未知'
END AS isDismissName,
bzgl_bz.sjjcsj AS actualProcessTime,
bzgl_bz.sjccsj AS actualExitTime,
bp.imp_unit AS impUnit
FROM
`micro-tool`.bzgl_bz bzgl_bz
LEFT JOIN bm_project bp ON bp.external_id = bzgl_bz.project_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE 1 = 1
<if test="proId != null and proId != ''">
AND bp.pro_id = #{proId}
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="departName != null and departName != ''">
AND df.project_dept = #{departName}
</if>
<if test="teamName != null and teamName != ''">
AND bzgl_bz.bzmc = #{teamName}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
bzgl_bz.ssfbdw like concat('%',#{keyWord},'%') or
bzgl_bz.bzmc like concat('%',#{keyWord},'%') or
bzgl_bz.bzz_name like concat('%',#{keyWord},'%') or
bzgl_bz.project_name like concat('%',#{keyWord},'%')
)
</if>
GROUP BY bzgl_bz.bzmc
</select>
<select id="selectDepartNum" resultType="java.lang.Integer">
SELECT
COUNT( DISTINCT project_dept_id )
FROM
bm_project bp
LEFT JOIN data_center.dx_fb_son dx ON dx.id = bp.external_id
LEFT JOIN sys_dept sd ON bp.imp_unit = sd.dept_id
WHERE
bp.external_id IS NOT NULL
AND bp.actual_end_date IS NULL
<if test="proName != null and proName != ''">
AND bp.pro_name like concat('%',#{proName},'%')
</if>
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name like concat('%',#{impUnitName},'%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center like concat('%',#{departName},'%')
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
<select id="selectProjectNum" resultType="java.lang.Integer">
SELECT
count( DISTINCT bp.external_id ) AS total_external_id
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 sd.dept_id = bp.imp_unit
WHERE
sai.is_slt = 0
AND bp.external_id IS NOT NULL
<if test="proName != null and proName != ''">
AND bp.pro_name like concat('%',#{proName},'%')
</if>
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name like concat('%',#{impUnitName},'%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center like concat('%',#{departName},'%')
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
<select id="selectTeamNum" resultType="java.lang.Integer">
SELECT
COUNT( DISTINCT bz.id )
FROM
`micro-tool`.bzgl_bz bz
LEFT JOIN bm_project bp ON bp.external_id = bz.project_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
WHERE
bp.external_id IS NOT NULL
AND bp.actual_end_date IS NULL
<if test="proName != null and proName != ''">
AND bp.pro_name like concat('%',#{proName},'%')
</if>
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name like concat('%',#{impUnitName},'%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center like concat('%',#{departName},'%')
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="teamName != null and teamName != ''">
AND bz.bzmc = #{teamName}
</if>
</select>
<select id="getRetainStoreInfo" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
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 storeNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
bp.pro_center AS proCenter
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
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 AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name like concat('%',#{impUnitName},'%')
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name like concat('%',#{proName},'%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center like concat('%',#{departName},'%')
</if>
<if test="teamName != null and teamName != ''">
AND bu.unit_name like concat('%',#{teamName},'%')
</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="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
</select>
<select id="getRetainInfoList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
mt.type_id AS typeId,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
subquery1.proId AS proId,
subquery1.proName AS proName,
subquery1.externalId AS externalId,
subquery1.impUnit AS impUnit,
subquery1.idCard AS idCard,
IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0) AS allNum,
subquery1.proCenter AS departName,
subquery1.departName AS impUnitName,
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
END manageType,
subquery1.teamName AS teamName,
'/' AS subUnitName,
mt.unit_value AS unitValue,
CASE mt.jiju_type
WHEN 2 THEN
'安全工器具'
ELSE
'施工机具'
END jiJuType,
'1' as bzFlag,
mt.buy_price AS buyPrice,
(IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0)) * mt.buy_price / 10000 AS totalPrice
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,
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName,
'站内库存' AS teamName
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
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bp.external_id IS NOT NULL
AND bu.type_id = 36
and sd.dept_id not in (342,345,347,348,101,344)
and bp.pro_id not in (3414,1192,3321,3595)
and bp.pro_center IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="teamName != null and teamName != ''">
AND '站内库存' like concat('%',#{teamName},'%')
</if>
<if test="subUnitName != null and subUnitName != ''">
AND '站内库存' like concat('%',#{subUnitName},'%')
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
and bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="projectId != null and projectId !=''">
AND bp.external_id = #{projectId}
</if>
<if test="projectName != null and projectName !=''">
AND bp.pro_name like concat ('%', #{projectName}, '%')
</if>
GROUP BY mt.type_id,
bp.pro_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.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName,
'站内库存' AS teamName
FROM
clz_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
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'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
and sd.dept_id not in (342,345,347,348,101,344)
and bp.pro_id not in (3414,1192,3321,3595)
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="teamName != null and teamName != ''">
AND '站内库存' like concat('%',#{teamName},'%')
</if>
<if test="subUnitName != null and subUnitName != ''">
AND '站内库存' like concat('%',#{subUnitName},'%')
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
and bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="projectId != null and projectId !=''">
AND bp.external_id = #{projectId}
</if>
<if test="projectName != null and projectName !=''">
AND bp.pro_name like concat ('%', #{projectName}, '%')
</if>
GROUP BY mt.type_id,
bp.pro_id
) AS subquery3
ON mt.type_id = subquery3.type_id
AND subquery1.proId = subquery3.proId
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'
and mt2.type_name not in ('安全围栏(三角旗)', '安全围网', '标牌', '标识卡', '彩旗', '冲锋衣', '春秋装(管理)'
, '春秋装(一线)', '电力复合脂', '胶鞋', '救生衣', '军棉袄', '劳保鞋', '铝包带', '滤盒', '滤芯', '马夹', '毛巾'
, '棉村', '棉大衣', '手电筒', '手套', '洗衣粉', '夏装(管理)', '夏装(一线)', '雨衣')
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY mt.type_id,
subquery1.proId
HAVING allNum > 0
</select>
<select id="getUsInfoList" 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,
SUM(IFNULL( sai.num, 0 )) AS allNum,
bu.unit_id as teamId,
bu.unit_name AS teamName,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS departName,
mt.unit_name AS unit,
sd.dept_name AS impUnitName,
CASE mt.manage_type WHEN 0 THEN '编码' ELSE '数量' END manageType,
mt.unit_value AS unitValue,
cla.sub_unit_name AS subUnitName,
CASE mt.jiju_type WHEN 2 THEN '安全工器具' ELSE '施工机具' END jiJuType,
'0' as bzFlag,
mt.buy_price AS buyPrice,
SUM(IFNULL(sai.num, 0)) * mt.buy_price / 10000 AS totalPrice
FROM
clz_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
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'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN clz_lease_apply_info cla ON cla.id = sai.lease_id
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bu.unit_name is not null
AND bp.external_id is not NULL
and sd.dept_id not in (342,345,347,348,101,344)
and bp.pro_id not in (3414,1192,3321,3595)
and bp.pro_center IS NOT NULL
and mt2.type_name not in ('安全围栏(三角旗)', '安全围网', '标牌', '标识卡', '彩旗', '冲锋衣', '春秋装(管理)'
, '春秋装(一线)', '电力复合脂', '胶鞋', '救生衣', '军棉袄', '劳保鞋', '铝包带', '滤盒', '滤芯', '马夹', '毛巾'
, '棉村', '棉大衣', '手电筒', '手套', '洗衣粉', '夏装(管理)', '夏装(一线)', '雨衣')
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="teamName != null and teamName != ''">
AND bu.unit_name = #{teamName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="subUnitName != null and subUnitName != ''">
AND cla.sub_unit_name = #{subUnitName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="projectId != null and projectId !=''">
AND bp.external_id = #{projectId}
</if>
<if test="projectName != null and projectName !=''">
AND bp.pro_name like concat ('%', #{projectName}, '%')
</if>
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY
mt.type_id, bu.unit_id, bp.pro_id
</select>
<select id="getMaCodeDetails" resultType="com.bonus.material.clz.domain.machine.MaterialStorageInfo">
SELECT mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.lease_price AS buyPrice,
SUM(IFNULL( sai.num, 0 )) AS storeNum,
mm.ma_code AS maCode,
bt.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
lai.code AS code,
sai.ma_id AS maId,
bp.pro_name AS proName,
CASE WHEN
lai.direct_id IS NULL
THEN '1' ELSE '0'
END AS directFlag
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 AND bt.del_flag = '0'
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 sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="typeId !=null ">
AND sai.type_id = #{typeId}
</if>
<if test="proId !=null ">
AND bp.pro_id = #{proId}
</if>
<if test="teamId !=null ">
AND bt.unit_id = #{teamId}
</if>
GROUP BY
sai.type_id,
sai.ma_id,
lai.direct_id
</select>
<select id="getImpUnitNameList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
DISTINCT sd.dept_name AS impUnitName,sd.dept_id as impUnit
FROM
bm_project bp
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
WHERE
sd.dept_name IS NOT NULL
and sd.dept_id not in (342,345,347,348,101,344)
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name LIKE CONCAT('%', #{impUnitName}, '%')
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
GROUP BY sd.dept_name
ORDER BY
sd.order_num
</select>
<select id="getDepartNameList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT DISTINCT
sp.`name` AS departName
FROM
bm_project bp
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN sbd_audit.sg_project_department sp ON sd.company_code = sp.parent_id
WHERE
sp.`name` IS NOT NULL
and sp.`name` not in ('第一项目管理部(金上)','第十项目管理部(川渝)','第十项目管理部','运维管理部2023年度合肥公司220kV输电线路线路瓷绝缘子清扫与检测')
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name LIKE CONCAT('%', #{impUnitName}, '%')
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="departName != null and departName != ''">
AND sp.`name` LIKE CONCAT('%', #{departName}, '%')
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="departIdList != null and departIdList.size() > 0">
AND sp.id in
<foreach item="item" collection="departIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
GROUP BY sp.`name`
ORDER BY
-- 先判断是否是数字部门(排在前面)
CASE WHEN SUBSTRING(sp.name,2,1) IN ('一','二','三','四','五','六','七','八','九','十') THEN 0 ELSE 1 END,
-- 数字部门按中文数字排序
field(SUBSTRING(sp.name,2,1),'一','二','三','四','五','六','七','八','九','十'),
-- 处理十一、十二等
field(SUBSTRING(sp.name,3,1),'一','二','三','四','五','六','七','八','九','十'),
sp.name
</select>
<select id="getProjectList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
DISTINCT bp.pro_name AS proName,bp.pro_id AS proId,bp.external_id AS projectId
FROM
bm_project bp
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
bp.pro_center IS NOT NULL
AND bp.external_id IS NOT NULL
and bp.pro_id not in (3414,1192,3321,3595)
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND df.project_dept = #{departName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
and bp.del_flag='0'
GROUP BY bp.pro_name
ORDER BY sd.order_num,
CASE
WHEN df.voltage_level = '其他' THEN 999 -- 其他放在最后
WHEN df.voltage_level LIKE '%kV' THEN
CASE
WHEN df.voltage_level LIKE '±%' THEN
CAST(REPLACE(REPLACE(df.voltage_level, '±', ''), 'kV', '') AS DECIMAL) + 1000 -- 直流电压特殊处理
ELSE
CAST(REPLACE(df.voltage_level, 'kV', '') AS DECIMAL)
END
ELSE 998 -- 其他未知格式
END ASC
</select>
<select id="getTeamList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT DISTINCT
bz.bzmc AS teamName,
bz.project_name AS proName,
bp.external_id AS externalId
FROM
`micro-tool`.bzgl_bz bz
LEFT JOIN bm_project bp ON bz.project_id = bp.external_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
bz.bzmc IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="departName != null and departName != ''">
AND df.project_dept = #{departName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="subUnitName != null and subUnitName != ''">
AND bz.ssfbdw LIKE CONCAT('%', #{subUnitName}, '%')
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
GROUP BY bz.bzmc
</select>
<select id="getSubUnitList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT DISTINCT
bu.unit_name AS teamName,
bp.external_id AS externalId,
bz.ssfbdw AS subUnitName
FROM
clz_slt_agreement_info sai
LEFT JOIN ma_type mt ON mt.type_id = sai.type_id
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'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN `micro-tool`.bzgl_bz bz ON bp.external_id = bz.project_id AND bz.bzmc = bu.unit_name
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bu.unit_name is not null
AND bp.external_id is not NULL
and sd.dept_id not in (342,345,347,348,101,344)
and bp.pro_id not in (3414,1192,3321,3595)
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center LIKE CONCAT('%', #{departName}, '%')
</if>
<if test="teamName != null and teamName != ''">
AND bu.unit_name LIKE CONCAT('%', #{teamName}, '%')
</if>
<if test="subUnitName != null and subUnitName != ''">
AND bz.ssfbdw LIKE CONCAT('%', #{subUnitName}, '%')
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
GROUP BY
mt.type_id, bu.unit_name, bp.pro_name, bz.ssfbdw
</select>
<select id="getStoreNumAndUseList" resultType="com.bonus.material.clz.domain.vo.MaterialStorageAndUseNumInfo">
SELECT
mt.type_id AS typeId,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
subquery1.proId AS proId,
subquery1.proName AS proName,
subquery1.externalId AS externalId,
subquery1.impUnit AS impUnit,
subquery1.idCard AS idCard,
CASE
WHEN IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0) &lt; 0
THEN 0
ELSE IFNULL(subquery1.usNum, 0) - IFNULL(subquery3.usNum, 0)
END
AS storeNum,
IFNULL(subquery3.usNum, 0) AS usNum,
subquery1.proCenter AS departName,
subquery1.departName AS impUnitName,
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
END manageType,
mt.unit_value AS unitValue,
CASE mt.jiju_type
WHEN 2 THEN
'安全工器具'
ELSE
'施工机具'
END jiJuType
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,
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName
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
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bp.external_id IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name like concat('%',#{impUnitName},'%')
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name like concat('%',#{proName},'%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center like concat('%',#{departName},'%')
</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="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
and bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</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
mt.type_name like concat('%', #{keyWord}, '%') or
bp.pro_name like concat('%', #{keyWord}, '%')
)
</if>
GROUP BY mt.type_id,
bp.pro_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.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName
FROM
clz_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
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'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name like concat('%',#{impUnitName},'%')
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name like concat('%',#{proName},'%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center like concat('%',#{departName},'%')
</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="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
and bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</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
mt.type_name like concat('%', #{keyWord}, '%') or
bp.pro_name like concat('%', #{keyWord}, '%')
)
</if>
GROUP BY mt.type_id,
bp.pro_id
) AS subquery3
ON mt.type_id = subquery3.type_id
AND subquery1.proId = subquery3.proId
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'
and subquery1.proName is not null
GROUP BY mt.type_id,
subquery1.proId
</select>
<select id="getPickDepartList" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT DISTINCT
df.project_dept_id as departId,
df.project_dept AS departName
FROM
bm_project bp
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
bp.external_id = #{proId}
</select>
<select id="getDemandAndSupply" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
SELECT
mt.type_id AS typeId,
mt4.type_name AS constructionType,
mt3.type_name AS materialType,
mt2.type_name AS typeName,
mt2.type_id AS thirdTypeId,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
subquery1.proId AS proId,
subquery1.proName AS proName,
subquery1.externalId AS externalId,
subquery1.impUnit AS impUnit,
subquery3.idCard AS idCard,
GREATEST(IFNULL(subquery1.useNum, 0) - IFNULL(subquery3.useNum, 0), 0) AS storeNum,
IFNULL(subquery3.useNum, 0) AS useNum,
IFNULL(subquery1.supplyNum, 0) AS supplyNum,
IFNULL(subquery1.backNum, 0) AS backNum,
subquery1.proCenter AS departName,
subquery1.departName AS impUnitName,
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
END manageType,
mt.unit_value AS unitValue,
CASE mt.jiju_type
WHEN 2 THEN
'安全工器具'
ELSE
'施工机具'
END jiJuType,
subquery1.agreementId AS agreementIds
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,
SUM(CASE WHEN sai.`status` = '0' THEN IFNULL(sai.num, 0) ELSE 0 END) AS useNum,
SUM(CASE WHEN sai.`status` = '1' THEN IFNULL(sai.num, 0) ELSE 0 END) AS backNum,
SUM(IFNULL( sai.num, 0 )) AS supplyNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName,
GROUP_CONCAT(DISTINCT sai.agreement_id) AS agreementId
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
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.is_slt = '0'
AND bp.external_id IS NOT NULL
and bp.pro_id not in (3414,1192,3321,3595)
and bp.pro_center IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND df.project_dept = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
sd.dept_name like concat('%', #{keyWord}, '%') or
df.project_dept like concat('%', #{keyWord}, '%') or
mt2.type_name like concat('%', #{keyWord}, '%') or
mt.type_name like concat('%', #{keyWord}, '%') or
bp.pro_name like concat('%', #{keyWord}, '%')
)
</if>
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY mt.type_id,
bp.pro_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 useNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName
FROM
clz_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
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'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
and bp.pro_id not in (3414,1192,3321,3595)
and bp.pro_center IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND df.project_dept = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
sd.dept_name like concat('%', #{keyWord}, '%') or
df.project_dept like concat('%', #{keyWord}, '%') or
mt2.type_name like concat('%', #{keyWord}, '%') or
mt.type_name like concat('%', #{keyWord}, '%') or
bp.pro_name like concat('%', #{keyWord}, '%')
)
</if>
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY mt.type_id,
bp.pro_id
) AS subquery3
ON mt.type_id = subquery3.type_id
AND subquery1.proId = subquery3.proId
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'
AND subquery1.proName IS NOT NULL
GROUP BY
subquery1.proId,
mt.type_id
ORDER BY
subquery1.proId
DESC
</select>
<select id="getLeaseDemandNum" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
SELECT
IFNULL( sum( lad.pre_num ), 0 ) AS businessNum
FROM
lease_apply_info lai
LEFT JOIN lease_apply_details lad ON lai.id = lad.parent_id
LEFT JOIN tm_task tt ON tt.task_id = lai.task_id
LEFT JOIN tm_task_agreement tta on tta.task_id = lai.task_id
LEFT JOIN bm_agreement_info bagi on bagi.agreement_id = tta.agreement_id
AND bagi.`status` = '1'
LEFT JOIN bm_project bp on bp.pro_id = bagi.project_id
AND bp.del_flag = '0'
WHERE
tt.task_status IN (3, 4)
AND tt.task_type = 2
<if test="typeId != null ">
AND lad.type_id = #{typeId}
</if>
<if test="proId != null and proId != '' ">
AND bp.pro_id = #{proId}
</if>
</select>
<select id="getUseDemandNum" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
select
IFNULL(sum(lpd.num),0) as businessNum
from
lease_publish_details lpd
<where>
<if test="typeId != null ">
AND lpd.type_id = #{typeId}
</if>
<if test="proId != null and proId != '' ">
AND lpd.project_id = #{proId}
</if>
</where>
</select>
<select id="getUseDemandAndSupply" resultType="com.bonus.material.clz.domain.vo.MaterialSecondInfo">
SELECT
bui.unit_name AS teamName,
bp.pro_name AS proName,
sai.type_id AS typeId,
mt1.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
SUM( sai.num ) AS leaseNum,
SUM( CASE WHEN sai.STATUS = 0 THEN sai.num ELSE 0 END ) AS useNum,
SUM( CASE WHEN sai.STATUS = 1 THEN sai.num ELSE 0 END ) AS backNum,
cla.sub_unit_name AS subUnitName
FROM
clz_slt_agreement_info sai
LEFT JOIN clz_bm_agreement_info bai ON sai.agreement_id = bai.agreement_id
LEFT JOIN bm_project bp ON bp.pro_id = bai.project_id
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN clz_lease_apply_info cla ON sai.lease_id = cla.id
WHERE
bp.pro_id = #{proId}
AND sai.type_id = #{typeId}
<if test="keyWord != null and keyWord != ''">
AND (
mt1.type_name LIKE CONCAT('%',#{keyWord},'%') OR
mt.type_name LIKE CONCAT('%',#{keyWord},'%') OR
bui.unit_name LIKE CONCAT('%',#{keyWord},'%') OR
bp.pro_name LIKE CONCAT('%',#{keyWord},'%') OR
cla.sub_unit_name LIKE CONCAT('%',#{keyWord},'%')
)
</if>
GROUP BY
bp.pro_id,
sai.type_id,
bui.unit_name
</select>
<select id="batchQueryLeaseDemand" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
SELECT
bp.pro_id AS proId,
lad.type_id AS typeId,
IFNULL(SUM(lad.pre_num), 0) AS businessNum
FROM
lease_apply_info lai
LEFT JOIN lease_apply_details lad ON lai.id = lad.parent_id
LEFT JOIN tm_task tt ON tt.task_id = lai.task_id
LEFT JOIN tm_task_agreement tta ON tta.task_id = lai.task_id
LEFT JOIN bm_agreement_info bagi ON bagi.agreement_id = tta.agreement_id
AND bagi.`status` = '1'
LEFT JOIN bm_project bp ON bp.pro_id = bagi.project_id
AND bp.del_flag = '0'
WHERE
tt.task_type = 2
AND lad.type_id IS NOT NULL
<foreach collection="list" item="item" separator="OR" open="AND (" close=")">
(
lad.type_id = #{item.typeId}
AND tta.agreement_id IN (
<foreach collection="item.agreementIds" item="aid" separator=",">
#{aid}
</foreach>
)
)
</foreach>
GROUP BY
bp.pro_id,
lad.type_id
</select>
<select id="batchQueryUseDemand" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
select
bai.project_id AS proId,
lpd.new_type AS typeId,
IFNULL(sum(lpd.num),0) AS businessNum
from
lease_publish_details lpd
LEFT JOIN (SELECT lease_id,agreement_id FROM slt_agreement_info GROUP BY lease_id,agreement_id) sai ON sai.lease_id = lpd.parent_id
left join bm_agreement_info bai on sai.agreement_id = bai.agreement_id
WHERE
lpd.new_type IS NOT NULL
<foreach collection="list" item="item" separator="OR" open="AND (" close=")">
(
lpd.new_type = #{item.typeId}
AND bai.agreement_id IN (
<foreach collection="item.agreementIds" item="aid" separator=",">
#{aid}
</foreach>
)
)
</foreach>
GROUP BY
bai.project_id,
lpd.new_type
</select>
<select id="getSubInfoList" 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,
SUM(IFNULL( sai.num, 0 )) AS allNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS departName,
sd.dept_name AS impUnitName,
bu.unit_name AS teamName,
'分包直领' AS subUnitName,
mt.unit_name AS unit,
mt.unit_value AS unitValue,
CASE mt.jiju_type
WHEN 2 THEN
'安全工器具'
ELSE
'施工机具'
END jiJuType,
'1' as bzFlag,
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
END manageType,
mt.buy_price AS buyPrice,
SUM(IFNULL( sai.num, 0 )) * mt.buy_price / 10000 AS totalPrice
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
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bp.external_id IS NOT NULL
AND bu.type_id in(32,33)
and bp.pro_id not in (3414,1192,3321,3595)
and bp.pro_center IS NOT NULL
and mt2.type_name not in ('安全围栏(三角旗)', '安全围网', '标牌', '标识卡', '彩旗', '冲锋衣', '春秋装(管理)'
, '春秋装(一线)', '电力复合脂', '胶鞋', '救生衣', '军棉袄', '劳保鞋', '铝包带', '滤盒', '滤芯', '马夹', '毛巾'
, '棉村', '棉大衣', '手电筒', '手套', '洗衣粉', '夏装(管理)', '夏装(一线)', '雨衣')
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
and bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="subUnitName != null and subUnitName != ''">
AND '分包直领' like concat('%',#{subUnitName},'%')
</if>
<if test="teamName != null and teamName != ''">
AND bu.unit_name = #{teamName}
</if>
<if test="projectId != null and projectId !=''">
AND bp.external_id = #{projectId}
</if>
<if test="projectName != null and projectName !=''">
AND bp.pro_name like concat ('%', #{projectName}, '%')
</if>
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY
mt.type_id,
bp.pro_id,
bu.unit_id
</select>
<select id="getSubDemandAndSupply" resultType="com.bonus.material.clz.domain.vo.MaterialSecondInfo">
SELECT
bu.unit_name AS subUnitName,
bp.pro_name AS proName,
sai.type_id AS typeId,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
SUM( sai.num ) AS leaseNum,
SUM( CASE WHEN sai.STATUS = 0 THEN sai.num ELSE 0 END ) AS useNum,
SUM( CASE WHEN sai.STATUS = 1 THEN sai.num ELSE 0 END ) AS backNum,
'/' AS teamName
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
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.is_slt = '0'
AND bu.type_id in(32,33)
AND bp.pro_id = #{proId}
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
bu.unit_name LIKE CONCAT('%',#{keyWord},'%') OR
bp.pro_name LIKE CONCAT('%',#{keyWord},'%')
)
</if>
GROUP BY
bp.pro_id,
sai.type_id,
bu.unit_name
</select>
<select id="getSubAgreementIds" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
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,
SUM(IFNULL( sai.num, 0 )) AS usNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS proCenter,
sd.dept_name AS departName,
GROUP_CONCAT(DISTINCT sai.agreement_id) AS agreementIds
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
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bp.external_id IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
mt2.type_name like concat('%', #{keyWord}, '%') or
mt.type_name like concat('%', #{keyWord}, '%') or
bp.pro_name like concat('%', #{keyWord}, '%')
)
</if>
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY mt.type_id,
bp.pro_id
</select>
<select id="getSubList" resultType="com.bonus.material.clz.domain.machine.MaterialStorageInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.lease_price AS buyPrice,
SUM(IFNULL( sai.num, 0 )) AS storeNum,
mm.ma_code AS maCode,
bt.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
lai.code AS code,
sai.ma_id AS maId,
bp.pro_name AS proName,
CASE WHEN
lai.direct_id IS NULL
THEN '1' ELSE '0'
END AS directFlag
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
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
WHERE
sai.status = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bt.type_id in (32,33)
<if test="typeId != null">
AND sai.type_id = #{typeId}
</if>
<if test="proId != null and proId != ''">
AND bp.pro_id = #{proId}
</if>
GROUP BY
sai.type_id,
sai.ma_id
</select>
<select id="getLeaseInfo" resultType="com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo">
SELECT
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS departName,
sd.dept_name AS impUnitName,
bu.unit_name AS teamName,
mt.unit_name AS unit,
mt.unit_value AS unitValue,
CASE mt.jiju_type
WHEN 2 THEN
'安全工器具'
ELSE
'施工机具'
END jiJuType,
CASE mt.manage_type
WHEN 0 THEN
'编码'
ELSE
'数量'
END manageType,
(DATEDIFF(
COALESCE(sai.end_time, NOW()), -- 若end_time为null则用当前时间
sai.start_time
) + 1) * sai.num * sai.lease_price / 10000 AS rentPrice,
CASE
WHEN bu.type_id IN (32, 33) THEN '分包直领'
ELSE bz.ssfbdw
END AS subUnitName
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
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN `micro-tool`.bzgl_bz bz ON bp.external_id = bz.project_id AND bz.bzmc = bu.unit_name
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.is_slt = '0'
AND bu.type_id in (32, 33, 36)
AND bp.external_id IS NOT NULL
AND sd.dept_id not in (342,345,347,348,101,344)
AND bp.pro_id not in (3414,1192,3321,3595)
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center like concat('%',#{departName},'%')
</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="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="subUnitName != null and subUnitName != ''">
AND (
(
#{subUnitName} = '分包直领'
AND bu.type_id IN (32, 33)
)
OR
(
#{subUnitName} != '分包直领'
AND bz.ssfbdw LIKE CONCAT('%', #{subUnitName}, '%')
)
)
</if>
<if test="teamName != null and teamName != ''">
AND bu.unit_name LIKE CONCAT('%', #{teamName}, '%')
</if>
GROUP BY
sai.id
</select>
<select id="getSubNumList" resultType="com.bonus.material.clz.domain.vo.MaterialProvideNumInfo">
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,
SUM(CASE WHEN sai.`status` = '0' THEN IFNULL(sai.num, 0) ELSE 0 END) AS useNum,
SUM(CASE WHEN sai.`status` = '1' THEN IFNULL(sai.num, 0) ELSE 0 END) AS backNum,
SUM(IFNULL( sai.num, 0 )) AS supplyNum,
bp.pro_name as proName,
bp.pro_id as proId,
bp.external_id as externalId,
bp.imp_unit AS impUnit,
bu.bzz_idcard AS idCard,
df.project_dept AS departName,
sd.dept_name AS impUnitName,
GROUP_CONCAT(DISTINCT sai.agreement_id) AS agreementId
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
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.is_slt = '0'
AND bp.external_id IS NOT NULL
and bp.pro_id not in (3414,1192,3321,3595)
and bp.pro_center IS NOT NULL
and bu.type_id in (32,33)
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name = #{proName}
</if>
<if test="departName != null and departName != ''">
AND df.project_dept = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
sd.dept_name like concat('%', #{keyWord}, '%') or
df.project_dept like concat('%', #{keyWord}, '%') or
mt2.type_name like concat('%', #{keyWord}, '%') or
mt.type_name like concat('%', #{keyWord}, '%') or
bp.pro_name like concat('%', #{keyWord}, '%')
)
</if>
<if test="unitValue != null and unitValue != ''">
AND mt.unit_value = #{unitValue}
</if>
GROUP BY mt.type_id,
bp.pro_id
</select>
<select id="getUseDetailsList" resultType="com.bonus.material.clz.domain.machine.MaterialStorageExportInfo">
SELECT mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.lease_price AS buyPrice,
SUM(IFNULL( sai.num, 0 )) AS storeNum,
mm.ma_code AS maCode,
bu.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
lai.code AS code,
sai.ma_id AS maId,
bp.pro_name AS proName,
CASE WHEN
lai.direct_id IS NULL
THEN '1' ELSE '0'
END AS directFlag,
df.project_dept AS departName,
sd.dept_name AS impUnitName,
cla.sub_unit_name AS subUnitName,
mt.unit_name AS unit
FROM clz_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
LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id
LEFT JOIN clz_lease_apply_info lai ON lai.id = sai.lease_id
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'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN clz_lease_apply_info cla ON cla.id = sai.lease_id
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bu.unit_name is not null
AND bp.external_id is not NULL
and sd.dept_id not in (342,345,347,348,101,344)
and bp.pro_id not in (3414,1192,3321,3595)
and bp.pro_center IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="teamName != null and teamName != ''">
AND bu.unit_name = #{teamName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="subUnitName != null and subUnitName != ''">
AND cla.sub_unit_name = #{subUnitName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
GROUP BY
sai.type_id,
sai.ma_id,
bu.unit_id
</select>
<select id="getSubInfoDetailsList" resultType="com.bonus.material.clz.domain.machine.MaterialStorageExportInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.lease_price AS buyPrice,
SUM(IFNULL( sai.num, 0 )) AS storeNum,
mm.ma_code AS maCode,
bu.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
lai.code AS code,
sai.ma_id AS maId,
bp.pro_name AS proName,
CASE WHEN
lai.direct_id IS NULL
THEN '1' ELSE '0'
END AS directFlag,
df.project_dept AS departName,
sd.dept_name AS impUnitName,
mt.unit_name AS unit
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
LEFT JOIN ma_machine mm ON mm.ma_id = sai.ma_id
LEFT JOIN lease_apply_info lai ON lai.id = sai.lease_id
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
AND bu.del_flag = '0'
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.`status` = '0'
AND sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bp.external_id IS NOT NULL
AND bu.type_id in(32,33)
and bp.pro_id not in (3414,1192,3321,3595)
and bp.pro_center IS NOT NULL
<if test="impUnitName != null and impUnitName != ''">
AND sd.dept_name = #{impUnitName}
</if>
<if test="proName != null and proName != ''">
AND bp.pro_name LIKE CONCAT('%', #{proName}, '%')
</if>
<if test="departName != null and departName != ''">
AND bp.pro_center = #{departName}
</if>
<if test="typeName != null and typeName != ''">
AND mt2.type_name = #{typeName}
</if>
<if test="typeModelName != null and typeModelName != ''">
AND mt.type_name = #{typeModelName}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
and bp.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
and bp.imp_unit = #{impUnit}
</if>
<if test="jiJuType != null and jiJuType != ''">
AND mt.jiju_type = #{jiJuType}
</if>
<if test="subUnitName != null and subUnitName != ''">
AND '分包直领' like concat('%',#{subUnitName},'%')
</if>
<if test="teamName != null and teamName != ''">
AND bu.unit_name = #{teamName}
</if>
GROUP BY
sai.type_id,
sai.ma_id,
bp.pro_id,
bu.unit_id
</select>
<select id="batchGetMaCodeExportList"
resultType="com.bonus.material.clz.domain.machine.MaterialStorageExportInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.lease_price AS buyPrice,
SUM(IFNULL( sai.num, 0 )) AS storeNum,
mm.ma_code AS maCode,
bt.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
lai.code AS code,
sai.ma_id AS maId,
bp.pro_name AS proName,
CASE WHEN
lai.direct_id IS NULL
THEN '1' ELSE '0'
END AS directFlag,
mt.manage_type AS manageType,
bp.pro_id AS proId,
df.project_dept AS departName,
sd.dept_name AS impUnitName,
mt.unit_name AS unit
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
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN `micro-tool`.bzgl_bz bz ON bp.external_id = bz.project_id AND bz.bzmc = bt.unit_name
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
sai.status = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
AND bt.type_id = 36
<if test="list != null and list.size() > 0">
AND (
<foreach collection="list" item="param" separator="OR">
<!-- 关键修改在这里 -->
<trim prefix="(" suffix=")" prefixOverrides="AND" suffixOverrides="AND">
<if test="param.proId != null">AND bp.pro_id = #{param.proId}</if>
<if test="param.typeId != null">AND sai.type_id = #{param.typeId}</if>
</trim>
</foreach>
)
</if>
GROUP BY
sai.type_id,
sai.ma_id,
lai.direct_id
</select>
<select id="batchGetMaCodeDetails" resultType="com.bonus.material.clz.domain.machine.MaterialStorageInfo">
SELECT mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.lease_price AS buyPrice,
SUM(IFNULL( sai.num, 0 )) AS storeNum,
mm.ma_code AS maCode,
bt.unit_name AS teamName,
sai.lease_id AS leaseId,
sai.type_id AS typeId,
lai.code AS code,
sai.ma_id AS maId,
bp.pro_name AS proName,
CASE WHEN
lai.direct_id IS NULL
THEN '1' ELSE '0'
END AS directFlag,
bp.pro_id AS proId,
mt.unit_name AS unit
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 AND bt.del_flag = '0'
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 sai.is_slt = '0'
AND sai.end_time IS NULL
AND sai.back_id IS NULL
<if test="list != null and list.size() > 0">
AND (
<foreach collection="list" item="param" separator="OR">
<!-- 关键修改在这里 -->
<trim prefix="(" suffix=")" prefixOverrides="AND" suffixOverrides="AND">
<if test="param.proId != null">AND bp.pro_id = #{param.proId}</if>
<if test="param.typeId != null">AND sai.type_id = #{param.typeId}</if>
</trim>
</foreach>
)
</if>
GROUP BY
sai.type_id,
sai.ma_id,
lai.direct_id
</select>
</mapper>