Browse Source

[feat]

1、修复预警管理-预警统计按照部门分组查询不出来数据问题
master
杨威 2 months ago
parent
commit
fba48dfd39
  1. 129
      dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml

129
dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml

@ -135,8 +135,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="listDepartAlert" resultType="java.util.Map"> <select id="listDepartAlert" resultType="java.util.Map">
WITH RECURSIVE districts AS ( WITH RECURSIVE sub_depts AS (
SELECT dept_id, dept_name,tenant_id FROM dk_cloud.sys_dept <where> SELECT
dept_id,
dept_name,
parent_id,
tenant_id
FROM
dk_cloud.sys_dept
<where>
<if test="param.deptId != null and param.deptId != ''"> <if test="param.deptId != null and param.deptId != ''">
parent_id = #{param.deptId} parent_id = #{param.deptId}
</if> </if>
@ -144,11 +151,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0') parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
</if> </if>
</where> </where>
UNION ALL
-- 递归查询:获取所有下级部门
SELECT
d.dept_id,
d.dept_name,
d.parent_id,
d.tenant_id
FROM
dk_cloud.sys_dept d
INNER JOIN sub_depts st ON d.parent_id = st.dept_id
), ),
sub_depts AS ( -- 获取直接子部门(用于最终显示)
-- 第一级子部门(包含 dept_name) districts AS (
SELECT dept_id, dept_name, parent_id, tenant_id SELECT
FROM dk_cloud.sys_dept dept_id,
dept_name,
parent_id,
tenant_id
FROM
dk_cloud.sys_dept
<where> <where>
<if test="param.deptId != null and param.deptId != ''"> <if test="param.deptId != null and param.deptId != ''">
parent_id = #{param.deptId} parent_id = #{param.deptId}
@ -157,30 +179,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0') parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
</if> </if>
</where> </where>
UNION ALL
-- 递归查询下级部门(同样包含 dept_name)
SELECT d.dept_id, d.dept_name, d.parent_id, d.tenant_id
FROM dk_cloud.sys_dept d
INNER JOIN sub_depts st ON d.parent_id = st.dept_id
), ),
warning_summary AS ( warning_summary AS (
SELECT SELECT
d.dept_id AS district_id, dc.dept_id AS district_id,
COUNT( ba.id ) AS total_warnings COUNT(ba.id) AS total_warnings
FROM FROM
business_alert ba districts dc
INNER JOIN sub_depts d ON ba.dept_id = d.dept_id LEFT JOIN sub_depts sd ON sd.parent_id = dc.dept_id OR sd.dept_id = dc.dept_id
LEFT JOIN business_alert ba ON ba.dept_id = sd.dept_id
<include refid="searchSql"></include> <include refid="searchSql"></include>
GROUP BY GROUP BY
d.dept_id dc.dept_id
) )
SELECT SELECT
d.dept_id deptId, dc.dept_id deptId,
d.dept_name deptName, dc.dept_name deptName,
COALESCE ( w.total_warnings, 0 ) AS total COALESCE(ws.total_warnings, 0) AS total
FROM FROM
districts d districts dc
LEFT JOIN warning_summary w ON d.dept_id = w.district_id LEFT JOIN warning_summary ws ON dc.dept_id = ws.district_id
</select> </select>
<select id="listMonthAlertStatus" resultType="java.util.Map"> <select id="listMonthAlertStatus" resultType="java.util.Map">
@ -206,8 +224,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="listDepartAlertStatus" resultType="java.util.Map"> <select id="listDepartAlertStatus" resultType="java.util.Map">
WITH RECURSIVE districts AS ( WITH RECURSIVE sub_depts AS (
SELECT dept_id, dept_name,tenant_id FROM dk_cloud.sys_dept <where> SELECT
dept_id,
dept_name,
parent_id,
tenant_id
FROM
dk_cloud.sys_dept
<where>
<if test="param.deptId != null and param.deptId != ''"> <if test="param.deptId != null and param.deptId != ''">
parent_id = #{param.deptId} parent_id = #{param.deptId}
</if> </if>
@ -215,11 +240,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0') parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
</if> </if>
</where> </where>
UNION ALL
-- 递归查询:获取所有下级部门
SELECT
d.dept_id,
d.dept_name,
d.parent_id,
d.tenant_id
FROM
dk_cloud.sys_dept d
INNER JOIN sub_depts st ON d.parent_id = st.dept_id
), ),
sub_depts AS ( -- 获取直接子部门(用于最终显示)
-- 第一级子部门(包含 dept_name) districts AS (
SELECT dept_id, dept_name, parent_id, tenant_id SELECT
FROM dk_cloud.sys_dept dept_id,
dept_name,
parent_id,
tenant_id
FROM
dk_cloud.sys_dept
<where> <where>
<if test="param.deptId != null and param.deptId != ''"> <if test="param.deptId != null and param.deptId != ''">
parent_id = #{param.deptId} parent_id = #{param.deptId}
@ -228,37 +268,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0') parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
</if> </if>
</where> </where>
UNION ALL
-- 递归查询下级部门(同样包含 dept_name)
SELECT d.dept_id, d.dept_name, d.parent_id, d.tenant_id
FROM dk_cloud.sys_dept d
INNER JOIN sub_depts st ON d.parent_id = st.dept_id
), ),
warning_summary AS ( warning_summary AS (
SELECT SELECT
d.dept_id AS district_id, dc.dept_id AS district_id,
COUNT(ba.id) AS total_warnings, COUNT(ba.id) AS total_warnings,
IFNULL(SUM(handle_type = 'waiting'), 0) AS todoCount, IFNULL(SUM(ba.handle_type = 'waiting'), 0) AS todoCount,
IFNULL(SUM(handle_type = 'finish'), 0) AS finishCount, IFNULL(SUM(ba.handle_type = 'finish'), 0) AS finishCount,
IFNULL(SUM(ba.handle_type = 'cancel'), 0) AS cancelCount IFNULL(SUM(ba.handle_type = 'cancel'), 0) AS cancelCount
FROM FROM
business_alert ba districts dc
INNER JOIN sub_depts d ON ba.dept_id = d.dept_id LEFT JOIN sub_depts sd ON sd.parent_id = dc.dept_id OR sd.dept_id = dc.dept_id
AND ba.handle_type != 'verify' LEFT JOIN business_alert ba ON ba.dept_id = sd.dept_id
<include refid="searchSql"></include> <include refid="searchSql"></include>
GROUP BY GROUP BY
d.dept_id dc.dept_id
) )
SELECT SELECT
d.dept_id deptId, dc.dept_id deptId,
d.dept_name deptName, dc.dept_name deptName,
IFNULL(w.total_warnings, 0) AS total, COALESCE(ws.total_warnings, 0) AS total,
IFNULL(w.todoCount, 0) AS todoCount, IFNULL(ws.todoCount, 0) AS todoCount,
IFNULL(w.finishCount, 0) AS finishCount, IFNULL(ws.finishCount, 0) AS finishCount,
IFNULL(w.cancelCount, 0) AS cancelCount IFNULL(ws.cancelCount, 0) AS cancelCount
FROM FROM
districts d districts dc
LEFT JOIN warning_summary w ON d.dept_id = w.district_id LEFT JOIN warning_summary ws ON dc.dept_id = ws.district_id
</select> </select>
<select id="countAlertCompare" resultType="java.util.Map"> <select id="countAlertCompare" resultType="java.util.Map">

Loading…
Cancel
Save