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 id="listDepartAlert" resultType="java.util.Map">
WITH RECURSIVE districts AS (
SELECT dept_id, dept_name,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>
),
sub_depts AS (
-- 第一级子部门(包含 dept_name)
SELECT dept_id, dept_name, parent_id, tenant_id
FROM dk_cloud.sys_dept
WITH RECURSIVE sub_depts 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}
@ -158,29 +152,53 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</where>
UNION ALL
-- 递归查询下级部门(同样包含 dept_name)
SELECT d.dept_id, d.dept_name, d.parent_id, d.tenant_id
FROM dk_cloud.sys_dept d
-- 递归查询:获取所有下级部门
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 (
SELECT
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
)
-- 获取直接子部门(用于最终显示)
districts AS (
SELECT
d.dept_id deptId,
d.dept_name deptName,
COALESCE ( w.total_warnings, 0 ) AS total
dept_id,
dept_name,
parent_id,
tenant_id
FROM
districts d
LEFT JOIN warning_summary w ON d.dept_id = w.district_id
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 (
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 id="listMonthAlertStatus" resultType="java.util.Map">
@ -206,20 +224,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="listDepartAlertStatus" resultType="java.util.Map">
WITH RECURSIVE districts AS (
SELECT dept_id, dept_name,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>
),
sub_depts AS (
-- 第一级子部门(包含 dept_name)
SELECT dept_id, dept_name, parent_id, tenant_id
FROM dk_cloud.sys_dept
WITH RECURSIVE sub_depts 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}
@ -229,36 +241,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</where>
UNION ALL
-- 递归查询下级部门(同样包含 dept_name)
SELECT d.dept_id, d.dept_name, d.parent_id, d.tenant_id
FROM dk_cloud.sys_dept d
-- 递归查询:获取所有下级部门
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
),
-- 获取直接子部门(用于最终显示)
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 (
SELECT
d.dept_id AS district_id,
dc.dept_id AS district_id,
COUNT(ba.id) AS total_warnings,
IFNULL(SUM(handle_type = 'waiting'), 0) AS todoCount,
IFNULL(SUM(handle_type = 'finish'), 0) AS finishCount,
IFNULL(SUM(ba.handle_type = 'waiting'), 0) AS todoCount,
IFNULL(SUM(ba.handle_type = 'finish'), 0) AS finishCount,
IFNULL(SUM(ba.handle_type = 'cancel'), 0) AS cancelCount
FROM
business_alert ba
INNER JOIN sub_depts d ON ba.dept_id = d.dept_id
AND ba.handle_type != 'verify'
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
d.dept_id
dc.dept_id
)
SELECT
d.dept_id deptId,
d.dept_name deptName,
IFNULL(w.total_warnings, 0) AS total,
IFNULL(w.todoCount, 0) AS todoCount,
IFNULL(w.finishCount, 0) AS finishCount,
IFNULL(w.cancelCount, 0) AS cancelCount
dc.dept_id deptId,
dc.dept_name deptName,
COALESCE(ws.total_warnings, 0) AS total,
IFNULL(ws.todoCount, 0) AS todoCount,
IFNULL(ws.finishCount, 0) AS finishCount,
IFNULL(ws.cancelCount, 0) AS cancelCount
FROM
districts d
LEFT JOIN warning_summary w ON d.dept_id = w.district_id
districts dc
LEFT JOIN warning_summary ws ON dc.dept_id = ws.district_id
</select>
<select id="countAlertCompare" resultType="java.util.Map">

Loading…
Cancel
Save