2025-07-04 16:37:48 +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.equipment.mapper.SysDeptMapper" >
2025-09-17 18:10:01 +08:00
2025-07-04 16:37:48 +08:00
<sql id= "selectDeptVo" >
select d.dept_id,
d.parent_id,
d.dept_name,
d.order_num,
d.leader,
2025-10-22 16:24:05 +08:00
d.dept_abbreviation,
d.dept_type,
d.location,
2025-07-04 16:37:48 +08:00
d.phone,
d.status,
d.del_flag,
2025-09-16 16:26:10 +08:00
d.city
2025-07-04 16:37:48 +08:00
from sys_dept d
</sql>
2025-09-17 18:10:01 +08:00
2025-07-04 16:37:48 +08:00
<resultMap type= "com.bonus.system.api.domain.SysDept" id= "SysDeptResult" >
<id property= "deptId" column= "dept_id" />
<result property= "parentId" column= "parent_id" />
<result property= "ancestors" column= "ancestors" />
<result property= "deptName" column= "dept_name" />
<result property= "orderNum" column= "order_num" />
<result property= "leader" column= "leader" />
<result property= "phone" column= "phone" />
<result property= "email" column= "email" />
<result property= "status" column= "status" />
<result property= "delFlag" column= "del_flag" />
<result property= "parentName" column= "parent_name" />
<result property= "createBy" column= "create_by" />
<result property= "createTime" column= "create_time" />
<result property= "updateBy" column= "update_by" />
<result property= "updateTime" column= "update_time" />
<result property= "menuTemplateId" column= "menu_template_id" />
<result property= "province" column= "province" />
<result property= "city" column= "city" />
<result property= "district" column= "district" />
<result property= "address" column= "address" />
<result property= "deptAbbreviation" column= "dept_abbreviation" />
<result property= "remark" column= "remark" />
<result property= "logo" column= "logo" />
<result property= "adminUserId" column= "admin_user_id" />
<result property= "initPassword" column= "init_password" />
</resultMap>
2025-09-17 18:10:01 +08:00
<resultMap type= "com.bonus.material.basic.domain.SysDeptVO" id= "SysDeptVOResult" >
<id property= "deptId" column= "dept_id" />
<result property= "parentId" column= "parent_id" />
<result property= "ancestors" column= "ancestors" />
<result property= "deptName" column= "dept_name" />
<result property= "orderNum" column= "order_num" />
<result property= "leader" column= "leader" />
<result property= "phone" column= "phone" />
<result property= "email" column= "email" />
<result property= "status" column= "status" />
<result property= "delFlag" column= "del_flag" />
<result property= "parentName" column= "parent_name" />
<result property= "createBy" column= "create_by" />
<result property= "createTime" column= "create_time" />
<result property= "updateBy" column= "update_by" />
<result property= "updateTime" column= "update_time" />
<result property= "menuTemplateId" column= "menu_template_id" />
<result property= "province" column= "province" />
<result property= "city" column= "city" />
<result property= "district" column= "district" />
<result property= "address" column= "address" />
<result property= "deptAbbreviation" column= "dept_abbreviation" />
<result property= "remark" column= "remark" />
<result property= "logo" column= "logo" />
<result property= "adminUserId" column= "admin_user_id" />
<result property= "initPassword" column= "init_password" />
</resultMap>
<select id= "selectDeptTree" resultType= "com.bonus.material.equipment.domain.SysDept" >
2025-07-07 19:14:16 +08:00
SELECT * FROM sys_dept WHERE del_flag = '0' ORDER BY parent_id, order_num
</select>
2025-09-17 18:10:01 +08:00
2025-07-04 16:37:48 +08:00
<select id= "selectDeptList" parameterType= "com.bonus.system.api.domain.SysDept" resultMap= "SysDeptResult" >
<include refid= "selectDeptVo" />
where d.del_flag = '0'
<if test= "deptName != null and deptName != ''" >
AND dept_name like concat('%', #{deptName}, '%')
</if>
2025-09-17 18:10:01 +08:00
</select>
2025-07-04 16:37:48 +08:00
2025-09-17 18:10:01 +08:00
<select id= "selectDeptVOList" resultMap= "SysDeptVOResult" >
<include refid= "selectDeptVo" />
where d.del_flag = '0'
<if test= "deptName != null and deptName != ''" >
AND dept_name like concat('%', #{deptName}, '%')
</if>
2025-07-04 16:37:48 +08:00
</select>
2025-09-17 18:10:01 +08:00
2025-07-04 16:37:48 +08:00
<select id= "selectUserList" resultType= "com.bonus.material.equipment.domain.DeptEquipmentConfig" >
SELECT
mt.type_id AS equipmentId,
mt2.type_name AS equipmentName,
mt.type_name AS equipmenttype,
2025-12-11 17:54:20 +08:00
mt.jiju_type as jijuType,
2025-07-04 16:37:48 +08:00
CASE
2025-12-11 17:54:20 +08:00
WHEN MAX( mdc.config_value ) IS NOT NULL
AND MAX( mdc.config_value ) != '' THEN
'已配置' ELSE '未配置'
2025-07-04 16:37:48 +08:00
END AS configStatus
2025-12-11 17:54:20 +08:00
FROM
ma_type mt
2025-07-04 16:37:48 +08:00
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
2025-12-11 17:54:20 +08:00
LEFT JOIN ma_dept_config mdc ON mdc.type_id = mt.type_id
AND mdc.dept_id = #{deptId}
WHERE
mt.LEVEL =5
GROUP BY
mt.type_id,
mt2.type_name,
mt.type_name
UNION
SELECT
mt.type_id AS equipmentId,
mt2.type_name AS equipmentName,
mt.type_name AS equipmenttype,
mt.jiju_type as jijuType,
CASE
WHEN MAX( mdc.config_value ) IS NOT NULL
AND MAX( mdc.config_value ) != '' THEN
'已配置' ELSE '未配置'
END AS configStatus
FROM
tool_type mt
LEFT JOIN tool_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN ma_dept_config mdc ON mdc.type_id = mt.type_id
2025-07-04 16:37:48 +08:00
AND mdc.dept_id = #{deptId}
2025-12-11 17:54:20 +08:00
WHERE
mt.LEVEL =4
2025-07-04 16:37:48 +08:00
<if test= "equipmentName != null and equipmentName != ''" >
AND mt.type_name LIKE CONCAT('%', #{equipmentName}, '%')
</if>
<if test= "equipmenttype != null and equipmenttype != ''" >
AND mt2.type_name LIKE CONCAT('%', #{equipmenttype}, '%')
</if>
GROUP BY mt.type_id, mt2.type_name, mt.type_name
</select>
2025-09-17 18:10:01 +08:00
2025-07-04 16:37:48 +08:00
<select id= "selectConfigList" resultType= "com.bonus.material.equipment.domain.ConfigEntity" >
SELECT
config_value AS basicConfig,
config_type AS configurationType,
config_rate AS configurationRate,
config_description AS configurationDescription
FROM ma_dept_config
WHERE dept_id = #{deptId}
AND type_id = #{typeId}
</select>
2025-09-17 18:10:01 +08:00
2025-07-04 16:37:48 +08:00
<select id= "getTree" resultType= "com.bonus.material.equipment.domain.DeptTreeSelect" >
SELECT
mt.type_id AS id,
mt.type_name AS name
FROM ma_type mt
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
2025-09-17 18:10:01 +08:00
LEFT JOIN ma_dept_config mdc ON mdc.type_id = mt.type_id
2025-07-04 16:37:48 +08:00
WHERE mt.level = 3
GROUP BY mt.type_id, mt2.type_name, mt.type_name
</select>
2025-09-17 18:10:01 +08:00
<select id= "selectDeptConfigRatePivot" resultType= "com.bonus.material.equipment.domain.DeptConfigRateSummary" >
2025-07-04 16:37:48 +08:00
SELECT
my.type_name AS deptName,
2025-07-10 18:41:40 +08:00
my.type_id AS typeId,
2025-07-04 16:37:48 +08:00
sd.dept_name AS companyName,
2025-07-07 10:06:32 +08:00
grouped.dept_id AS companyId,
grouped.config_type AS configType,
grouped.config_value AS configValue,
2025-09-16 16:26:10 +08:00
if(grouped.config_rate='/',0,grouped.config_rate) AS configRate,
2025-07-04 16:37:48 +08:00
IFNULL(order_stat.order_count, 0) AS orderCount
FROM
2025-07-07 10:06:32 +08:00
(
SELECT
dept_id,
type_id,
config_type,
SUM(config_value) AS config_value,
2025-09-16 16:26:10 +08:00
SUM(if(config_rate='/',0,config_rate)) AS config_rate
2025-07-07 10:06:32 +08:00
FROM ma_dept_config
2025-12-11 18:48:10 +08:00
where jiju_type =1
2025-07-07 10:06:32 +08:00
GROUP BY dept_id, type_id, config_type
) grouped
LEFT JOIN sys_dept sd ON sd.dept_id = grouped.dept_id
LEFT JOIN ma_type my ON my.type_id = grouped.type_id
2025-07-04 16:37:48 +08:00
-- 设备订单数量子查询
LEFT JOIN (
SELECT
sd.dept_id AS dept_id,
2025-12-11 18:48:10 +08:00
mt.type_id AS parent_type_id,
COUNT(md.num) AS order_count
2025-07-04 16:37:48 +08:00
FROM
ma_order_details md
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
LEFT JOIN ma_type mt ON mdi.type_id = mt.type_id
LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN sys_dept sd ON moi.buyer_company = sd.dept_id
2025-12-11 18:48:10 +08:00
where devType =0
GROUP BY sd.dept_id, mt.type_id
2025-07-04 16:37:48 +08:00
) order_stat
2025-07-07 10:06:32 +08:00
ON order_stat.dept_id = grouped.dept_id
AND order_stat.parent_type_id = grouped.type_id
2025-12-11 18:48:10 +08:00
UNION
SELECT
my.type_name AS deptName,
my.type_id AS typeId,
sd.dept_name AS companyName,
grouped.dept_id AS companyId,
grouped.config_type AS configType,
grouped.config_value AS configValue,
if(grouped.config_rate='/',0,grouped.config_rate) AS configRate,
IFNULL(order_stat.order_count, 0) AS orderCount
FROM
(
SELECT
dept_id,
type_id,
config_type,
SUM(config_value) AS config_value,
SUM(if(config_rate='/',0,config_rate)) AS config_rate
FROM ma_dept_config
where jiju_type =2
GROUP BY dept_id, type_id, config_type
) grouped
LEFT JOIN sys_dept sd ON sd.dept_id = grouped.dept_id
LEFT JOIN tool_type my ON my.type_id = grouped.type_id
-- 设备订单数量子查询
LEFT JOIN (
SELECT
sd.dept_id AS dept_id,
mt.type_id AS parent_type_id,
COUNT(md.num) AS order_count
FROM
ma_order_details md
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
LEFT JOIN tool_type mt ON mdi.type_id = mt.type_id
LEFT JOIN tool_type mt2 ON mt.parent_id = mt2.type_id
LEFT JOIN sys_dept sd ON moi.buyer_company = sd.dept_id
where devType =1
GROUP BY sd.dept_id, mt.type_id
) order_stat
ON order_stat.dept_id = grouped.dept_id
AND order_stat.parent_type_id = grouped.type_id;
2025-07-04 16:37:48 +08:00
</select>
2025-09-17 18:10:01 +08:00
<select id= "selectDeptConfigTypeSummary" resultType= "com.bonus.material.equipment.domain.DeptConfigTypeSummary" >
2025-07-04 16:37:48 +08:00
SELECT mt1.type_name AS typeName,
mt2.type_name AS parentTypeName,
CAST(mdc.config_rate AS DECIMAL(10, 2)) AS configRate,
mdc.config_description AS configDescription
FROM ma_dept_config mdc
LEFT JOIN ma_type mt1 ON mt1.type_id = mdc.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
WHERE mdc.dept_id = #{deptId}
</select>
2025-09-17 18:10:01 +08:00
2025-07-04 16:37:48 +08:00
<select id= "detailsInfo" resultType= "com.bonus.material.equipment.domain.EquipmentDetail" >
SELECT
2025-07-07 19:14:16 +08:00
d.dept_id AS companyId,
2025-07-10 10:46:43 +08:00
d.vol as labelVol,
2025-07-10 17:11:43 +08:00
mt3.type_id as typeId,
2025-07-09 09:42:47 +08:00
mt3.type_name AS NAME,-- 使用层级表当前类型作为名称
2025-07-07 19:14:16 +08:00
d.config_description AS `desc`,
d.config_rate AS `value`,
2025-07-09 09:42:47 +08:00
d.config_type AS configType,
CONCAT_WS( '>', NULLIF( mt1.type_name, '' ), NULLIF( mt2.type_name, '' ), NULLIF( mt3.type_name, '' ) ) AS combinedName,
2025-07-07 19:14:16 +08:00
(
2025-07-09 09:42:47 +08:00
SELECT
COUNT( md.ma_id )
FROM
ma_order_details md
2025-07-07 19:14:16 +08:00
LEFT JOIN ma_order_info moi ON md.order_id = moi.order_id
LEFT JOIN ma_dev_info mdi ON md.ma_id = mdi.ma_id
2025-07-09 09:42:47 +08:00
LEFT JOIN ma_type mto1 ON mdi.type_id = mto1.type_id
LEFT JOIN ma_type mto2 ON mto1.parent_id = mto2.type_id
2025-07-04 16:37:48 +08:00
WHERE
2025-07-09 09:42:47 +08:00
moi.buyer_company = d.dept_id
AND mto2.type_id = d.type_id
2025-07-07 19:14:16 +08:00
) AS orderCount,
2025-07-09 09:42:47 +08:00
SUM(
CAST(
d.config_value AS DECIMAL ( 10, 2 ))) AS standard,
MAX( own_count ) AS own,
MAX( rent_count ) AS rent
2025-07-07 19:14:16 +08:00
FROM
2025-07-09 09:42:47 +08:00
ma_dept_config d -- 层级关系连接(当前类型 → 父级 → 祖父级)
LEFT JOIN ma_type mt3 ON mt3.type_id = d.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id
LEFT JOIN ma_type mt1 ON mt1.type_id = mt2.parent_id -- 自有设备统计子查询(完整语句)
LEFT JOIN ( SELECT ma_name, SUM( ma_num ) AS own_count FROM ma_own_manage WHERE type = '2' AND is_active = '0' AND company_id = #{companyId} GROUP BY ma_name ) own ON CAST( d.type_id AS CHAR ) = own.ma_name -- 租赁设备统计子查询(完整语句)
LEFT JOIN ( SELECT ma_name, SUM( ma_num ) AS rent_count FROM ma_own_manage WHERE type = '1' AND is_active = '0' AND company_id = #{companyId} GROUP BY ma_name ) rent ON CAST( d.type_id AS CHAR ) = rent.ma_name
WHERE
d.dept_id = #{companyId}
2025-07-07 19:14:16 +08:00
<choose >
<when test= "configType == 0" >
AND d.config_type IN (0, 3)
</when>
<when test= "configType == 1" >
AND d.config_type IN (1, 4)
</when>
<when test= "configType == 2" >
AND d.config_type IN (2, 5)
</when>
<otherwise >
<if test= "configType != null" >
AND d.config_type = #{configType}
</if>
</otherwise>
</choose>
2025-07-04 16:37:48 +08:00
GROUP BY
2025-07-09 09:42:47 +08:00
d.dept_id,
d.config_type,
d.type_id
2025-07-04 16:37:48 +08:00
</select>
2025-09-17 18:10:01 +08:00
2025-07-04 16:37:48 +08:00
<select id= "listFromDevInfo" resultType= "com.bonus.material.equipment.domain.NewmydevInfo" >
SELECT
2025-10-13 14:25:44 +08:00
md.on_company AS companyId,
2025-09-17 18:10:01 +08:00
mt2.type_id AS typeId, mt2.type_name as typeName,
2025-07-04 16:37:48 +08:00
SUM( 1 ) AS ownCount
FROM
ma_dev_info md
2025-09-17 18:10:01 +08:00
LEFT JOIN ma_type mt ON mt.type_id = md.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
2025-07-04 16:37:48 +08:00
WHERE
2025-10-13 14:25:44 +08:00
md.is_active = '1' AND md.on_company = #{companyId}
2025-07-04 16:37:48 +08:00
GROUP BY
2025-07-10 17:11:43 +08:00
mt2.type_id
2025-07-04 16:37:48 +08:00
</select>
2025-09-17 18:10:01 +08:00
2025-09-16 16:26:10 +08:00
<select id= "getCityName" resultType= "java.lang.String" >
select name
from base_address where code = #{city}
</select>
2025-07-04 16:37:48 +08:00
</mapper>