实现结果总览风险接口并完成回写联调

This commit is contained in:
wkc
2026-03-19 15:23:52 +08:00
parent 8ff6570ba8
commit cb8e144564
23 changed files with 1172 additions and 0 deletions

View File

@@ -40,4 +40,15 @@
</where>
ORDER BY p.update_time DESC
</select>
<update id="updateRiskCountsByProjectId">
update ccdi_project
set high_risk_count = #{highRiskCount},
medium_risk_count = #{mediumRiskCount},
low_risk_count = #{lowRiskCount},
update_by = #{updateBy},
update_time = now()
where project_id = #{projectId}
and del_flag = '0'
</update>
</mapper>

View File

@@ -0,0 +1,175 @@
<?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.ruoyi.ccdi.project.mapper.CcdiProjectOverviewMapper">
<resultMap id="EmployeeRiskAggregateResultMap" type="com.ruoyi.ccdi.project.domain.vo.CcdiProjectEmployeeRiskAggregateVO">
<result property="staffIdCard" column="staff_id_card"/>
<result property="staffName" column="staff_name"/>
<result property="deptId" column="dept_id"/>
<result property="deptName" column="dept_name"/>
<result property="ruleCount" column="rule_count"/>
<result property="modelCount" column="model_count"/>
<result property="topRuleCode" column="top_rule_code"/>
<result property="topRuleName" column="top_rule_name"/>
<result property="riskLevelCode" column="risk_level_code"/>
<result property="riskLevelName" column="risk_level_name"/>
<result property="riskLevelSort" column="risk_level_sort"/>
</resultMap>
<sql id="resolvedEmployeeRiskBaseSql">
select distinct
tr.id,
tr.project_id,
coalesce(direct_staff.id_card, statement_staff.id_card, family_staff.id_card) as staff_id_card,
coalesce(direct_staff.name, statement_staff.name, family_staff.name) as staff_name,
coalesce(direct_staff.dept_id, statement_staff.dept_id, family_staff.dept_id) as dept_id,
tr.rule_code,
tr.rule_name,
tr.model_code
from ccdi_bank_statement_tag_result tr
left join ccdi_base_staff direct_staff
on tr.object_type = 'STAFF_ID_CARD'
and tr.object_key = direct_staff.id_card
left join ccdi_bank_statement bs
on tr.bank_statement_id = bs.bank_statement_id
left join ccdi_base_staff statement_staff
on (tr.object_key is null or tr.object_key = '')
and bs.cret_no = statement_staff.id_card
left join ccdi_staff_fmy_relation relation
on relation.status = 1
and (
((tr.object_key is null or tr.object_key = '') and bs.cret_no = relation.relation_cert_no)
or ((tr.object_key is not null and tr.object_key != '') and tr.object_type != 'STAFF_ID_CARD'
and tr.object_key = relation.relation_cert_no)
)
left join ccdi_base_staff family_staff
on relation.person_id = family_staff.id_card
where tr.project_id = #{projectId}
and coalesce(direct_staff.id_card, statement_staff.id_card, family_staff.id_card) is not null
</sql>
<sql id="employeeRiskAggregateSql">
select
agg.staff_id_card,
agg.staff_name,
agg.dept_id,
dept.dept_name,
agg.rule_count,
agg.model_count,
rule_pick.rule_code as top_rule_code,
rule_pick.rule_name as top_rule_name,
case
when agg.rule_count >= 5 then 'HIGH'
when agg.rule_count between 2 and 4 then 'MEDIUM'
else 'LOW'
end as risk_level_code,
case
when agg.rule_count >= 5 then '高风险'
when agg.rule_count between 2 and 4 then '中风险'
else '低风险'
end as risk_level_name,
case
when agg.rule_count >= 5 then 1
when agg.rule_count between 2 and 4 then 2
else 3
end as risk_level_sort
from (
select
base.staff_id_card,
max(base.staff_name) as staff_name,
max(base.dept_id) as dept_id,
count(distinct base.rule_code) as rule_count,
count(distinct base.model_code) as model_count
from (
<include refid="resolvedEmployeeRiskBaseSql"/>
) base
group by base.staff_id_card
) agg
left join sys_dept dept on agg.dept_id = dept.dept_id
left join (
select
chosen.staff_id_card,
chosen.rule_code,
chosen.rule_name
from (
select
grouped.staff_id_card,
grouped.rule_code,
grouped.rule_name,
grouped.hit_count
from (
select
base.staff_id_card,
base.rule_code,
max(base.rule_name) as rule_name,
count(1) as hit_count
from (
<include refid="resolvedEmployeeRiskBaseSql"/>
) base
group by base.staff_id_card, base.rule_code
) grouped
where not exists (
select 1
from (
select
base.staff_id_card,
base.rule_code,
max(base.rule_name) as rule_name,
count(1) as hit_count
from (
<include refid="resolvedEmployeeRiskBaseSql"/>
) base
group by base.staff_id_card, base.rule_code
) challenger
where challenger.staff_id_card = grouped.staff_id_card
and (
challenger.hit_count > grouped.hit_count
or (challenger.hit_count = grouped.hit_count
and challenger.rule_code &lt; grouped.rule_code)
)
)
) chosen
) rule_pick on rule_pick.staff_id_card = agg.staff_id_card
</sql>
<select id="selectDashboardBaseByProjectId" resultType="com.ruoyi.ccdi.project.domain.CcdiProject">
select
project_id,
project_name,
target_count,
high_risk_count,
medium_risk_count,
low_risk_count
from ccdi_project
where project_id = #{projectId}
and del_flag = '0'
</select>
<select id="selectRiskPeopleOverviewByProjectId" resultMap="EmployeeRiskAggregateResultMap">
<include refid="employeeRiskAggregateSql"/>
order by risk_level_sort asc, model_count desc, rule_count desc, staff_id_card asc
</select>
<select id="selectTopRiskPeopleByProjectId" resultMap="EmployeeRiskAggregateResultMap">
<include refid="employeeRiskAggregateSql"/>
where rule_count >= 2
order by risk_level_sort asc, model_count desc, rule_count desc, staff_id_card asc
limit 10
</select>
<select id="selectRiskCountSummaryByProjectId" resultType="map">
select
coalesce(sum(case when agg.rule_count >= 5 then 1 else 0 end), 0) as highRiskCount,
coalesce(sum(case when agg.rule_count between 2 and 4 then 1 else 0 end), 0) as mediumRiskCount,
coalesce(sum(case when agg.rule_count = 1 then 1 else 0 end), 0) as lowRiskCount
from (
select
base.staff_id_card,
count(distinct base.rule_code) as rule_count
from (
<include refid="resolvedEmployeeRiskBaseSql"/>
) base
group by base.staff_id_card
) agg
</select>
</mapper>