Browse Source

[feat]

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

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

@ -135,20 +135,14 @@ 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
<if test="param.deptId != null and param.deptId != ''"> dept_id,
parent_id = #{param.deptId} dept_name,
</if> parent_id,
<if test="param.deptId == null or param.deptId == ''"> tenant_id
parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0') FROM
</if> dk_cloud.sys_dept
</where>
),
sub_depts AS (
-- 第一级子部门(包含 dept_name)
SELECT 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}
@ -158,29 +152,53 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
</where> </where>
UNION ALL UNION ALL
-- 递归查询下级部门(同样包含 dept_name) -- 递归查询:获取所有下级部门
SELECT d.dept_id, d.dept_name, d.parent_id, d.tenant_id SELECT
FROM dk_cloud.sys_dept d 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 INNER JOIN sub_depts st ON d.parent_id = st.dept_id
), ),
warning_summary AS ( -- 获取直接子部门(用于最终显示)
SELECT districts AS (
d.dept_id AS district_id,
COUNT( ba.id ) AS total_warnings
FROM
business_alert ba
INNER JOIN sub_depts d ON ba.dept_id = d.dept_id
<include refid="searchSql"></include>
GROUP BY
d.dept_id
)
SELECT SELECT
d.dept_id deptId, dept_id,
d.dept_name deptName, dept_name,
COALESCE ( w.total_warnings, 0 ) AS total parent_id,
tenant_id
FROM FROM
districts d dk_cloud.sys_dept
LEFT JOIN warning_summary w ON d.dept_id = w.district_id <where>
<if test="param.deptId != null and param.deptId != ''">
parent_id = #{param.deptId}
</if>
<if test="param.deptId == null or param.deptId == ''">
parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
</if>
</where>
),
warning_summary AS (
SELECT
dc.dept_id AS district_id,
COUNT(ba.id) AS total_warnings
FROM
districts dc
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>
GROUP BY
dc.dept_id
)
SELECT
dc.dept_id deptId,
dc.dept_name deptName,
COALESCE(ws.total_warnings, 0) AS total
FROM
districts dc
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,20 +224,14 @@ 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
<if test="param.deptId != null and param.deptId != ''"> dept_id,
parent_id = #{param.deptId} dept_name,
</if> parent_id,
<if test="param.deptId == null or param.deptId == ''"> tenant_id
parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0') FROM
</if> dk_cloud.sys_dept
</where>
),
sub_depts AS (
-- 第一级子部门(包含 dept_name)
SELECT 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}
@ -229,36 +241,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
</where> </where>
UNION ALL UNION ALL
-- 递归查询下级部门(同样包含 dept_name) -- 递归查询:获取所有下级部门
SELECT d.dept_id, d.dept_name, d.parent_id, d.tenant_id SELECT
FROM dk_cloud.sys_dept d 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 INNER JOIN sub_depts st ON d.parent_id = st.dept_id
), ),
-- 获取直接子部门(用于最终显示)
districts AS (
SELECT
dept_id,
dept_name,
parent_id,
tenant_id
FROM
dk_cloud.sys_dept
<where>
<if test="param.deptId != null and param.deptId != ''">
parent_id = #{param.deptId}
</if>
<if test="param.deptId == null or param.deptId == ''">
parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
</if>
</where>
),
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