diff --git a/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml b/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml
index 4377ea6..2c11122 100644
--- a/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml
+++ b/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml
@@ -68,14 +68,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
uu.processed_by approver,
a.id flowTaskId,
b.id instanceId,
- fn.permissions,
+ fnData.permissions,
a.node_type
from dk_business.business_alert ba
inner join dk_workflow.flow_instance b on ba.id = b.business_id
left join dk_workflow.flow_task a on a.instance_id = b.id
left join dk_workflow.flow_user uu on uu.associated = a.id
left join dk_workflow.flow_definition c on a.definition_id = c.id
- left join dk_workflow.flow_node fn on fn.node_code = b.node_code
+ LEFT JOIN LATERAL (
+ SELECT
+ fn.permissions
+ FROM dk_workflow.flow_node fn
+ WHERE
+ fn.node_code = b.node_code
+ and fn.definition_id = c.id
+ and fn.del_flag = '0'
+ LIMIT 1
+ ) AS fnData ON TRUE
where a.node_type = 1
and a.del_flag = '0'
and uu.del_flag = '0'
@@ -135,20 +144,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- WITH RECURSIVE districts AS (
- SELECT dept_id, dept_name,tenant_id FROM dk_cloud.sys_dept
-
- parent_id = #{param.deptId}
-
-
- parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
-
-
- ),
- 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
parent_id = #{param.deptId}
@@ -158,29 +161,53 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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
-
- 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
+
+
+ parent_id = #{param.deptId}
+
+
+ parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
+
+
+ ),
+ 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
+
+ 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
@@ -206,20 +233,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- WITH RECURSIVE districts AS (
- SELECT dept_id, dept_name,tenant_id FROM dk_cloud.sys_dept
-
- parent_id = #{param.deptId}
-
-
- parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
-
-
- ),
- 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
parent_id = #{param.deptId}
@@ -229,36 +250,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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
+
+
+ parent_id = #{param.deptId}
+
+
+ parent_id in (select dsd.dept_id from dk_cloud.sys_dept dsd where dsd.parent_id = '0')
+
+
+ ),
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
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