Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml

474 lines
17 KiB
XML
Raw Normal View History

2024-11-11 14:00:09 +08:00
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.material.common.mapper.SelectMapper">
<!--往来单位-->
2024-11-15 15:13:15 +08:00
<select id="getUnitList" resultType="com.bonus.common.biz.domain.ProjectTreeNode">
2024-11-11 14:00:09 +08:00
/*根据标段工程id关联协议查询往来单位*/
2024-11-15 15:13:15 +08:00
SELECT
*
FROM
(
SELECT
CONCAT( 'dw', sd.dept_id ) AS id,
sd.dept_name AS NAME,
0 AS parentId,
2025-01-08 13:33:45 +08:00
1 AS LEVEL,
null AS typeKey
2024-11-15 15:13:15 +08:00
FROM
sys_dept sd
LEFT JOIN bm_unit bu ON sd.dept_id = bu.dept_id
LEFT JOIN bm_agreement_info bai ON bu.unit_id = bai.unit_id
AND bai.`status` = '1'
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
AND bp.del_flag = '0'
WHERE
bu.del_flag = '0'
AND sd.del_flag = '0'
AND sd.`status` = '0'
2024-11-12 12:55:48 +08:00
<if test="projectId != null">
2024-11-15 15:13:15 +08:00
AND bp.pro_id = #{projectId}
2024-11-11 14:00:09 +08:00
</if>
<if test="deptId != null">
AND bu.dept_id = #{deptId}
</if>
2024-11-15 15:13:15 +08:00
UNION
2024-11-15 15:13:15 +08:00
SELECT DISTINCT
CONCAT( 'lx', bu.dept_id, '-', sda.dict_code ) AS id,
sda.dict_label AS NAME,
CONCAT( 'dw', bu.dept_id ) AS parentId,
2025-01-08 13:33:45 +08:00
2 AS LEVEL,
sda.dict_value AS typeKey
2024-11-15 15:13:15 +08:00
FROM
bm_unit bu
2025-01-08 13:33:45 +08:00
LEFT JOIN sys_dict_data sda ON bu.type_id = sda.dict_code
2024-11-15 15:13:15 +08:00
AND sda.dict_type = 'bm_unit_type'
LEFT JOIN bm_agreement_info bai ON bu.unit_id = bai.unit_id
AND bai.`status` = '1'
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
AND bp.del_flag = '0'
WHERE
bu.del_flag = '0'
AND sda.STATUS = '0'
<if test="projectId != null">
AND bp.pro_id = #{projectId}
2024-11-11 14:00:09 +08:00
</if>
<if test="deptId != null">
AND bu.dept_id = #{deptId}
</if>
2024-11-15 15:13:15 +08:00
UNION
SELECT
bu.unit_id AS id,
bu.unit_name AS NAME,
CONCAT( 'lx', bu.dept_id, '-', sda.dict_code ) AS parentId,
2025-01-08 13:33:45 +08:00
3 AS LEVEL,
sda.dict_value AS typeKey
2024-11-15 15:13:15 +08:00
FROM
bm_unit bu
2025-01-08 13:33:45 +08:00
LEFT JOIN sys_dict_data sda ON bu.type_id = sda.dict_code
2024-11-15 15:13:15 +08:00
AND sda.dict_type = 'bm_unit_type'
LEFT JOIN bm_agreement_info bai ON bu.unit_id = bai.unit_id
AND bai.`status` = '1'
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
AND bp.del_flag = '0'
WHERE
bu.del_flag = '0'
AND sda.STATUS = '0'
<if test="projectId != null">
AND bp.pro_id = #{projectId}
2024-11-11 14:00:09 +08:00
</if>
<if test="deptId != null">
AND bu.dept_id = #{deptId}
</if>
2024-11-15 15:13:15 +08:00
) ff
ORDER BY
LEVEL
2024-11-11 14:00:09 +08:00
</select>
2024-11-15 15:13:15 +08:00
2024-11-11 14:00:09 +08:00
<!--机具类型-->
<select id="getMaTypeData" resultType="com.bonus.material.common.domain.vo.SelectVo">
SELECT type_id AS id,
type_name AS `name`
FROM ma_type
WHERE `level` = #{type} AND del_flag = '0'
</select>
2024-11-12 12:20:43 +08:00
2024-11-11 14:00:09 +08:00
<!--设备类型树-->
<select id="getDeviceTypeTree" resultType="com.bonus.common.biz.domain.TreeNode">
SELECT mt.type_id AS id,
mt.type_name AS label,
mt.parent_id AS parentId,
mt.unit_name AS unitName,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
2024-11-11 14:51:58 +08:00
IFNULL(mt.storage_num, 0)
2024-11-11 14:00:09 +08:00
END as num,
mt.model_code AS modelCode,
mt.manage_type AS manageType
FROM ma_type mt
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
2024-11-13 16:02:59 +08:00
WHERE mm.ma_code is not null and mm.ma_status in (1)
2024-11-11 14:00:09 +08:00
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
2024-11-11 14:51:58 +08:00
WHERE mt.del_flag = '0'
2024-11-11 14:00:09 +08:00
<if test="level!=null and level!=''">
<if test="level == 2">
AND mt.level IN ('1','2')
</if>
<if test="level == 3">
AND mt.level IN ('1','2','3')
</if>
<if test="level == 4">
AND mt.level IN ('1','2','3','4')
</if>
</if>
</select>
2024-11-12 12:20:43 +08:00
2024-11-11 14:00:09 +08:00
<!--资产属性-->
<select id="getAssetAttributesCbx" resultType="com.bonus.material.common.domain.vo.SelectVo">
SELECT prop_id AS id,
prop_name AS `name`
FROM ma_prop_info
WHERE del_flag = '0'
ORDER BY create_time
</select>
2024-11-12 12:20:43 +08:00
2024-11-11 14:00:09 +08:00
<!--机具厂家-->
<select id="getDeviceFactoryCbx" resultType="com.bonus.material.common.domain.vo.SelectVo">
SELECT supplier_id AS id,
supplier AS `name`
FROM ma_supplier_info
WHERE del_flag = '0'
ORDER BY create_time
</select>
2024-11-12 12:20:43 +08:00
2024-11-11 14:00:09 +08:00
<!--配件所属上级树-->
<select id="getAccessoryTree" resultType="com.bonus.common.biz.domain.TreeNode">
SELECT pa_id AS id,
pa_name AS label,
parent_id AS parentId,
unit_id as unitName,
level
FROM ma_part_type
WHERE del_flag = '0'
ORDER BY create_time
</select>
<select id="getPartTree" resultType="com.bonus.common.biz.domain.TreeNode">
SELECT pa_id AS id,
pa_name AS label,
parent_id AS parentId,
level
FROM ma_part_type
WHERE del_flag = '0' and level != '3'
ORDER BY create_time
</select>
2024-11-12 12:20:43 +08:00
2024-11-11 14:00:09 +08:00
<!--货架-->
<select id="getGoodsShelvesCbx" resultType="com.bonus.common.biz.domain.TreeNode">
SELECT house_id AS id,
house_name AS label,
parent_id AS parentId
FROM ma_house_info
WHERE del_flag = '0' AND status = '0'
</select>
2024-11-12 12:20:43 +08:00
2024-11-11 14:00:09 +08:00
<!--往来单位id和标段工程id获取协议信息-->
<select id="getAgreementInfoById" resultType="com.bonus.material.common.domain.vo.AgreementVo">
SELECT agreement_id AS agreementId,
agreement_code AS agreementCode,
is_slt AS isSlt
FROM bm_agreement_info
WHERE unit_id = #{unitId} AND project_id = #{projectId} AND status = '1'
</select>
2024-11-13 18:01:55 +08:00
<select id="getUseTypeTreeL4" resultType="com.bonus.common.biz.domain.TypeTreeNode">
SELECT
mt.type_id as typeId,
2024-11-21 17:43:05 +08:00
mt1.type_name as materialName,
2024-11-13 18:01:55 +08:00
mt.type_name as typeName,
mt.parent_id as parentId,
mt.unit_name as unitName,
2024-12-06 18:02:55 +08:00
mt.unit_value as unitValue,
2024-11-13 18:01:55 +08:00
mt.manage_type as manageType,
SUM( CASE WHEN sai.agreement_id = #{agreementId} AND sai.STATUS = '0' THEN sai.num ELSE 0 END ) AS num,
mt.LEVEL as level
FROM
ma_type mt
LEFT JOIN slt_agreement_info sai ON mt.type_id = sai.type_id
2024-11-21 17:43:05 +08:00
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id and mt1.del_flag = '0'
2024-11-13 18:01:55 +08:00
WHERE
EXISTS ( SELECT 1 FROM slt_agreement_info sai2 WHERE sai2.type_id = mt.type_id AND sai2.agreement_id = #{agreementId}
2024-11-16 16:42:54 +08:00
AND sai2.STATUS = '0' and IFNULL(sai.lease_type,0) = 0 and sai2.num > 0)
2024-11-13 18:01:55 +08:00
GROUP BY
mt.type_id
</select>
<select id="getUseTypeTreeL3" resultType="com.bonus.common.biz.domain.TypeTreeNode">
SELECT
mt3.type_id as typeId,
2024-11-21 17:43:05 +08:00
NULL as materialName,
2024-11-13 18:01:55 +08:00
mt3.type_name as typeName,
mt3.parent_id as parentId,
mt3.unit_name as unitName,
NULL as manageType,
0 AS num,
mt3.LEVEL as level
FROM
ma_type mt3 where type_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getUseTypeTreeL21" resultType="com.bonus.common.biz.domain.TypeTreeNode">
SELECT
mt2.type_id as typeId,
2024-11-21 17:43:05 +08:00
NULL as materialName,
2024-11-13 18:01:55 +08:00
mt2.type_name as typeName,
mt2.parent_id as parentId,
mt2.unit_name as unitName,
NULL as manageType,
0 AS num,
mt2.LEVEL as level
FROM
ma_type mt2 where type_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
union
SELECT
mt1.type_id as typeId,
2024-11-21 17:43:05 +08:00
NULL as materialName,
2024-11-13 18:01:55 +08:00
mt1.type_name as typeName,
mt1.parent_id as parentId,
mt1.unit_name as unitName,
NULL as manageType,
0 AS num,
mt1.LEVEL as level
FROM
ma_type mt1 left join (
SELECT
mt2.type_id as typeId,
2024-11-21 17:43:05 +08:00
NULL as materialName,
2024-11-13 18:01:55 +08:00
mt2.type_name as typeName,
mt2.parent_id as parentId,
mt2.unit_name as unitName,
NULL as manageType,
0 AS num,
mt2.LEVEL as level
FROM
ma_type mt2) mt2 on mt2.parentId = mt1.type_id where mt2.typeId in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
2024-11-15 15:13:15 +08:00
<select id="getProjectList" resultType="com.bonus.common.biz.domain.ProjectTreeNode">
/*根据往来单位id关联协议查询工程*/
SELECT
*
FROM
(
SELECT
bmp.pro_id AS id,
bmp.pro_name AS name,
concat( 'gs', bmp.imp_unit ) AS parentId,
2 AS level
FROM
bm_project bmp
LEFT JOIN sys_dept sd ON sd.dept_id = bmp.imp_unit
LEFT JOIN bm_agreement_info bai ON bai.project_id = bmp.pro_id
AND bai.`status` = '1'
LEFT JOIN bm_unit bu ON bu.unit_id = bai.unit_id
AND bu.del_flag = '0'
WHERE
sd.del_flag = '0'
AND sd.`status` = '0'
AND bmp.del_flag = '0'
<if test="unitId != null">
AND bu.unit_id = #{unitId}
</if>
<if test="deptId != null">
AND bu.dept_id = #{deptId}
</if>
2024-11-15 15:13:15 +08:00
UNION
SELECT DISTINCT
concat( 'gs', sd.dept_id ) AS id,
sd.dept_name AS proName,
'0' AS parentId,
1 AS level
FROM
sys_dept sd
LEFT JOIN bm_project bmp ON sd.dept_id = bmp.imp_unit
LEFT JOIN bm_agreement_info bai ON bai.project_id = bmp.pro_id
AND bai.`status` = '1'
LEFT JOIN bm_unit bu ON bu.unit_id = bai.unit_id
WHERE
bmp.pro_id IS NOT NULL
AND sd.del_flag = '0'
AND sd.`status` = '0'
AND bmp.del_flag = '0'
<if test="unitId != null">
AND bu.unit_id = #{unitId}
</if>
<if test="deptId != null">
AND bu.dept_id = #{deptId}
</if>
2024-11-15 15:13:15 +08:00
) a
ORDER BY
level
</select>
2024-11-19 17:03:01 +08:00
<select id="getUnitListApp" resultType="com.bonus.material.basic.domain.BmUnit">
/*根据标段工程id关联协议查询往来单位*/
<if test="projectId != null">
SELECT DISTINCT bu.unit_id AS unitId,
bu.unit_name AS unitName
FROM bm_project bpl
LEFT JOIN bm_agreement_info bai ON bpl.pro_id = bai.project_id AND bai.`status` = '1'
LEFT JOIN bm_unit bu ON bai.unit_id = bu.unit_id AND bu.del_flag = '0'
WHERE bpl.pro_id = #{projectId} AND bpl.del_flag = '0'
<if test="deptId != null and deptId != 0">
AND bpl.imp_unit = #{deptId}
</if>
2024-11-19 17:03:01 +08:00
</if>
<if test="projectId == null">
SELECT unit_id AS unitId,
unit_name AS unitName
FROM bm_unit
WHERE del_flag = '0'
<if test="deptId != null and deptId != 0">
AND dept_id = #{deptId}
</if>
2024-11-19 17:03:01 +08:00
</if>
</select>
<select id="getProjectListApp" resultType="com.bonus.material.basic.domain.BmProject">
/*根据往来单位id关联协议查询工程*/
<if test="unitId != null">
SELECT DISTINCT bp.pro_id AS proId,
bp.pro_name AS proName
FROM bm_unit bu
LEFT JOIN bm_agreement_info bai ON bu.unit_id = bai.unit_id AND bai.`status` = '1'
LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id AND bp.del_flag = '0'
WHERE bu.unit_id = #{unitId} AND bu.del_flag = '0'
</if>
<if test="unitId == null">
SELECT pro_id AS proId,
pro_name AS proName
FROM bm_project
WHERE del_flag = '0'
</if>
</select>
2024-11-21 17:43:05 +08:00
<select id="getUseTypeTreeApp" resultType="com.bonus.common.biz.domain.TypeTreeNode">
SELECT
mt.type_id as typeId,
mt1.type_name as materialName,
mt.type_name as typeName,
mt.parent_id as parentId,
mt.unit_name as unitName,
mt.manage_type as manageType,
SUM( CASE WHEN sai.agreement_id = #{agreementId} AND sai.STATUS = '0' THEN sai.num ELSE 0 END ) AS num,
mt.LEVEL as level
FROM
ma_type mt
LEFT JOIN slt_agreement_info sai ON mt.type_id = sai.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id and mt1.del_flag = '0'
WHERE
EXISTS ( SELECT 1 FROM slt_agreement_info sai2 WHERE sai2.type_id = mt.type_id AND sai2.agreement_id = #{agreementId}
AND sai2.STATUS = '0' and IFNULL(sai.lease_type,0) = 0 and sai2.num > 0)
and mt.manage_type = '1'
GROUP BY
mt.type_id
</select>
2025-01-22 09:38:30 +08:00
<select id="getMaType" resultType="com.bonus.material.common.domain.vo.SelectVo">
SELECT type_id AS typeId,
type_name AS name,
parent_id AS parentId,
2025-02-28 18:20:55 +08:00
level AS level,
unit_name AS unitName
2025-01-22 09:38:30 +08:00
FROM ma_type
WHERE del_flag = '0'
<if test="level != null and level != ''">
and level = #{level}
</if>
<if test="typeId != null">
and parent_id = #{typeId}
</if>
</select>
2025-02-14 18:12:43 +08:00
<select id="getConfigList" resultType="com.bonus.common.biz.domain.ProjectTreeNode">
SELECT id,
`name`,
parent_id AS parentId,
`level`
FROM bm_standard_config
WHERE del_flag = 0
</select>
2025-03-20 16:11:17 +08:00
<select id="getBranchProject" resultType="com.bonus.material.common.domain.vo.SelectVo">
SELECT dict_code as id,
dict_label as `name`
FROM sys_dict_data
WHERE dict_type = 'branch_project'
and `status` = 0
</select>
2025-06-27 14:43:33 +08:00
<select id="getProjectInfo" resultType="com.bonus.material.basic.domain.BmProject">
SELECT
pro_id AS proId,
pro_name AS proName,
external_id AS projectId
FROM
bm_project
WHERE
del_flag = '0'
</select>
2025-06-26 13:06:20 +08:00
<!-- <select id="getTeamList" resultType="com.bonus.material.common.domain.vo.SelectVo">-->
<!-- /*根据工程id查询班组*/-->
<!-- select bzgl_bz.id,-->
<!-- bzgl_bz.bzmc as name,-->
<!-- bzgl_bz.bzz_name as teamLeaderName,-->
<!-- bzgl_bz.bzz_idcard as teamLeaderIdCard,-->
<!-- bzgl_bz.bz as remark,-->
<!-- bzgl_bz.bz_status as teamStatus,-->
<!-- bzgl_bz.project_id as projectId,-->
<!-- bzgl_bz.project_name as projectName,-->
<!-- org_user.mobile as teamLeaderPhone-->
<!-- from `micro-tool`.bzgl_bz bzgl_bz-->
<!-- left join `uni_org`.org_user org_user on bzgl_bz.bzz_idcard = org_user.id_card-->
<!-- WHERE bzgl_bz.project_id = #{externalId}-->
<!-- </select>-->
2025-07-03 09:36:37 +08:00
<select id="getTeamList" resultType="com.bonus.material.common.domain.vo.SelectVo">
select bzgl_bz.id,
bzgl_bz.bzmc as name,
bzgl_bz.bzz_name as teamLeaderName,
bzgl_bz.bzz_idcard as teamLeaderIdCard,
bzgl_bz.bz as remark,
bzgl_bz.bz_status as teamStatus,
bzgl_bz.project_id as projectId,
bzgl_bz.project_name as projectName
from `micro-tool`.bzgl_bz bzgl_bz
</select>
<!-- <select id="getTeamList" resultType="com.bonus.material.common.domain.vo.SelectVo">-->
<!-- SELECT id,-->
<!-- team_name as `name`-->
<!-- FROM `lease_team_info`-->
<!-- </select>-->
2025-06-27 14:43:33 +08:00
</mapper>