| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- <?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.goldenwater.slaj.hidd.mapper.TBusiHiddCountMapper">
- <resultMap type="com.goldenwater.slaj.hidd.domain.TBusiHiddCount" id="TBusiHiddCountResult">
- <result property="guid" column="guid"/>
- <result property="orgGuid" column="org_guid"/>
- <result property="createTime" column="create_time"/>
- <result property="pcl" column="pcl"/>
- <result property="oengOrg" column="oeng_org"/>
- <result property="hiddOrg" column="hidd_org"/>
- <result property="engNum" column="eng_num"/>
- <result property="hiddEng" column="hidd_eng"/>
- <result property="hiddZgl" column="hidd_zgl"/>
- <result property="ybZgl" column="yb_zgl"/>
- <result property="ybHidd" column="yb_hidd"/>
- <result property="zgYbHidd" column="zg_yb_hidd"/>
- <result property="zdZgl" column="zd_zgl"/>
- <result property="zdHidd" column="zd_hidd"/>
- <result property="zgZdHidd" column="zg_zd_hidd"/>
- </resultMap>
-
- <!-- VO类ResultMap(包含计算字段) -->
- <resultMap type="com.goldenwater.slaj.hidd.domain.TBusiHiddCountVo" id="TBusiHiddCountVoResult">
- <result property="guid" column="guid"/>
- <result property="orgGuid" column="org_guid"/>
- <result property="createTime" column="create_time"/>
- <result property="pcl" column="pcl"/>
- <result property="oengOrg" column="oeng_org"/>
- <result property="hiddOrg" column="hidd_org"/>
- <result property="engNum" column="eng_num"/>
- <result property="hiddEng" column="hidd_eng"/>
- <result property="hiddZgl" column="hidd_zgl"/>
- <result property="ybZgl" column="yb_zgl"/>
- <result property="ybHidd" column="yb_hidd"/>
- <result property="zgYbHidd" column="zg_yb_hidd"/>
- <result property="zdZgl" column="zd_zgl"/>
- <result property="zdHidd" column="zd_hidd"/>
- <result property="zgZdHidd" column="zg_zd_hidd"/>
- <!-- 计算字段 -->
- <result property="orgName" column="org_name"/>
- <result property="totalHidd" column="total_hidd"/>
- <result property="solvedHidd" column="solved_hidd"/>
- <result property="solvingHidd" column="solving_hidd"/>
- <result property="unsolvedHidd" column="unsolved_hidd"/>
- <result property="solveRate" column="solve_rate"/>
- <!-- 逾期统计字段 -->
- <result property="zdSolvingHidd" column="zd_solving_hidd"/>
- <result property="zdUnsolvedHidd" column="zd_unsolved_hidd"/>
- <result property="zdOverTimeHidd" column="zd_overtime_hidd"/>
- <result property="ybSolvingHidd" column="yb_solving_hidd"/>
- <result property="ybUnsolvedHidd" column="yb_unsolved_hidd"/>
- <result property="ybOverTimeHidd" column="yb_overtime_hidd"/>
- <result property="overTimeHidd" column="overtime_hidd"/>
- </resultMap>
- <sql id="selectTBusiHiddCountVo">
- select guid, org_guid, create_time, pcl, oeng_org, hidd_org, eng_num, hidd_eng,
- hidd_zgl, yb_zgl, yb_hidd, zg_yb_hidd, zd_zgl, zd_hidd, zg_zd_hidd
- from t_busi_hidd_count
- </sql>
- <select id="selectTBusiHiddCountById" parameterType="String" resultMap="TBusiHiddCountResult">
- <include refid="selectTBusiHiddCountVo"/>
- where guid = #{guid}
- </select>
- <select id="selectTBusiHiddCountList" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCount" resultMap="TBusiHiddCountResult">
- <include refid="selectTBusiHiddCountVo"/>
- <where>
- <if test="orgGuid != null and orgGuid != ''">AND org_guid = #{orgGuid}</if>
- <if test="createTime != null and createTime != ''">AND create_time = #{createTime}</if>
- </where>
- </select>
- <insert id="insertTBusiHiddCount" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCount">
- insert into t_busi_hidd_count (guid, org_guid, create_time, pcl, oeng_org, hidd_org, eng_num, hidd_eng, hidd_zgl, yb_zgl, yb_hidd, zg_yb_hidd, zd_zgl, zd_hidd, zg_zd_hidd)
- values (#{guid}, #{orgGuid}, #{createTime}, #{pcl}, #{oengOrg}, #{hiddOrg}, #{engNum}, #{hiddEng}, #{hiddZgl}, #{ybZgl}, #{ybHidd}, #{zgYbHidd}, #{zdZgl}, #{zdHidd}, #{zgZdHidd})
- </insert>
- <update id="updateTBusiHiddCount" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCount">
- update t_busi_hidd_count
- <set>
- <if test="orgGuid != null">org_guid = #{orgGuid},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="pcl != null">pcl = #{pcl},</if>
- <if test="oengOrg != null">oeng_org = #{oengOrg},</if>
- <if test="hiddOrg != null">hidd_org = #{hiddOrg},</if>
- <if test="engNum != null">eng_num = #{engNum},</if>
- <if test="hiddEng != null">hidd_eng = #{hiddEng},</if>
- <if test="hiddZgl != null">hidd_zgl = #{hiddZgl},</if>
- <if test="ybZgl != null">yb_zgl = #{ybZgl},</if>
- <if test="ybHidd != null">yb_hidd = #{ybHidd},</if>
- <if test="zgYbHidd != null">zg_yb_hidd = #{zgYbHidd},</if>
- <if test="zdZgl != null">zd_zgl = #{zdZgl},</if>
- <if test="zdHidd != null">zd_hidd = #{zdHidd},</if>
- <if test="zgZdHidd != null">zg_zd_hidd = #{zgZdHidd},</if>
- </set>
- where guid = #{guid}
- </update>
- <delete id="deleteTBusiHiddCountById" parameterType="String">
- delete from t_busi_hidd_count where guid = #{guid}
- </delete>
- <delete id="deleteTBusiHiddCountByIds" parameterType="String">
- delete from t_busi_hidd_count where guid in
- <foreach item="guid" collection="array" open="(" separator="," close=")">
- #{guid}
- </foreach>
- </delete>
- <!-- 注意: PG 未加引号的别名会转小写,Map 返回必须用双引号保留驼峰,否则前端取不到字段 -->
- <select id="selectReportRateChart" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- select c.org_guid as "orgGuid",
- org.wiun_name as "orgName",
- c.pcl as "rateData",
- c.create_time as "repTime"
- from t_busi_hidd_count c
- left join att_org_ext org on org.org_guid = c.org_guid
- <where>
- <if test="repTime != null and repTime != ''">AND c.create_time = #{repTime}</if>
- </where>
- order by c.pcl desc
- </select>
- <select id="selectRectifyRateChart" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
- select c.org_guid as "orgGuid",
- org.wiun_name as "orgName",
- c.hidd_zgl as "rateData",
- c.create_time as "repTime"
- from t_busi_hidd_count c
- left join att_org_ext org on org.org_guid = c.org_guid
- <where>
- <if test="repTime != null and repTime != ''">AND c.create_time = #{repTime}</if>
- </where>
- order by c.hidd_zgl desc
- </select>
- <!-- 隐患统计列表查询(带计算字段) -->
- <select id="selectTBusiHiddCountListWithCalc" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCountVo" resultMap="TBusiHiddCountVoResult">
- select
- c.guid,
- c.org_guid,
- c.create_time,
- c.pcl,
- c.oeng_org,
- c.hidd_org,
- c.eng_num,
- c.hidd_eng,
- c.hidd_zgl,
- c.yb_zgl,
- c.yb_hidd,
- c.zg_yb_hidd,
- c.zd_zgl,
- c.zd_hidd,
- c.zg_zd_hidd,
- org.wiun_name as org_name,
- -- 计算字段
- (coalesce(c.zd_hidd, 0) + coalesce(c.yb_hidd, 0)) as total_hidd,
- (coalesce(c.zg_zd_hidd, 0) + coalesce(c.zg_yb_hidd, 0)) as solved_hidd,
- -- 正在整改中 = 重大整改中 + 一般整改中
- (case when coalesce(c.zd_hidd, 0) > coalesce(c.zg_zd_hidd, 0)
- then coalesce(c.zd_hidd, 0) - coalesce(c.zg_zd_hidd, 0) else 0 end
- + case when coalesce(c.yb_hidd, 0) > coalesce(c.zg_yb_hidd, 0)
- then coalesce(c.yb_hidd, 0) - coalesce(c.zg_yb_hidd, 0) else 0 end) as solving_hidd,
- case when (coalesce(c.zd_hidd, 0) + coalesce(c.yb_hidd, 0)) > 0
- then (coalesce(c.zd_hidd, 0) + coalesce(c.yb_hidd, 0)) - (coalesce(c.zg_zd_hidd, 0) + coalesce(c.zg_yb_hidd, 0))
- else 0 end as unsolved_hidd,
- c.hidd_zgl as solve_rate,
- -- 重大隐患-整改中
- case when coalesce(c.zd_hidd, 0) > coalesce(c.zg_zd_hidd, 0)
- then coalesce(c.zd_hidd, 0) - coalesce(c.zg_zd_hidd, 0)
- else 0 end as zd_solving_hidd,
- -- 重大隐患-未整改(预留,暂为0)
- 0 as zd_unsolved_hidd,
- -- 重大隐患-逾期未整改(预留,暂为0)
- 0 as zd_overtime_hidd,
- -- 一般隐患-整改中
- case when coalesce(c.yb_hidd, 0) > coalesce(c.zg_yb_hidd, 0)
- then coalesce(c.yb_hidd, 0) - coalesce(c.zg_yb_hidd, 0)
- else 0 end as yb_solving_hidd,
- -- 一般隐患-未整改(预留,暂为0)
- 0 as yb_unsolved_hidd,
- -- 一般隐患-逾期未整改(预留,暂为0)
- 0 as yb_overtime_hidd,
- -- 逾期未整改总数
- 0 as overtime_hidd
- from t_busi_hidd_count c
- left join att_org_ext org on org.org_guid = c.org_guid
- <where>
- <if test="orgGuid != null and orgGuid != ''">AND c.org_guid = #{orgGuid}</if>
- <if test="createTime != null and createTime != ''">AND c.create_time = #{createTime}</if>
- <if test="orgName != null and orgName != ''">AND org.org_name like concat('%', #{orgName}, '%')</if>
- <if test="unitType != null and unitType != ''">
- AND c.org_guid in (
- select org_guid from att_org_ext where wiun_code like concat(
- case #{unitType}
- when '1' then '%000000'
- when '2' then '%000'
- when '3' then '%0000'
- end
- )
- )
- </if>
- </where>
- order by c.create_time desc
- </select>
- <!-- 隐患统计列表查询(实时聚合,不依赖 t_busi_hidd_count 表)
- 口径:按单位实时统计名下隐患,与旧版 selectHiddCount 一致 -->
- <select id="selectTBusiHiddCountRealtimeList" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCountVo" resultMap="TBusiHiddCountVoResult">
- select
- o.guid as org_guid,
- o.org_name as org_name,
- -- 排查情况:非工程单位(下级单位中无工程关联的)
- coalesce(stat.oeng_org, 0) as oeng_org,
- -- 已排查非工程单位(有隐患记录的下级单位)
- coalesce(stat.hidd_org, 0) as hidd_org,
- -- 工程总数(该单位名下的工程)
- coalesce(stat.eng_num, 0) as eng_num,
- -- 有隐患的工程数
- coalesce(stat.hidd_eng, 0) as hidd_eng,
- -- 排查率 = 已排查单位/单位总数
- case when coalesce(stat.total_org, 0) > 0
- then round(coalesce(stat.hidd_org, 0) * 100.0 / stat.total_org, 2)
- else 0 end as pcl,
- -- 综合整改率
- case when coalesce(stat.total_hidd, 0) > 0
- then round(coalesce(stat.solved_hidd, 0) * 100.0 / stat.total_hidd, 2)
- else 0 end as hidd_zgl,
- -- 一般隐患数
- coalesce(stat.yb_hidd, 0) as yb_hidd,
- -- 已整改一般隐患数
- coalesce(stat.zg_yb_hidd, 0) as zg_yb_hidd,
- -- 一般整改率
- case when coalesce(stat.yb_hidd, 0) > 0
- then round(coalesce(stat.zg_yb_hidd, 0) * 100.0 / stat.yb_hidd, 2)
- else 0 end as yb_zgl,
- -- 重大隐患数
- coalesce(stat.zd_hidd, 0) as zd_hidd,
- -- 已整改重大隐患数
- coalesce(stat.zg_zd_hidd, 0) as zg_zd_hidd,
- -- 重大整改率
- case when coalesce(stat.zd_hidd, 0) > 0
- then round(coalesce(stat.zg_zd_hidd, 0) * 100.0 / stat.zd_hidd, 2)
- else 0 end as zd_zgl
- from att_org_base o
- left join (
- select
- u.guid as org_guid,
- -- 下级单位总数(非工程单位 = 无工程关联的下级单位)
- count(distinct case when e.guid is null then sub.guid end) as total_org,
- -- 非工程单位总数
- count(distinct case when e.guid is null then sub.guid end) as oeng_org,
- -- 有隐患记录的下级单位(已排查)
- count(distinct case when e.guid is null and h.guid is not null then sub.guid end) as hidd_org,
- -- 该单位名下工程总数
- count(distinct e.guid) as eng_num,
- -- 有隐患的工程数
- count(distinct case when eh.guid is not null then e.guid end) as hidd_eng,
- -- 隐患统计(该单位名下)
- count(distinct h.guid) as total_hidd,
- count(distinct case when h.hidd_grad = '1' then h.guid end) as yb_hidd,
- count(distinct case when h.hidd_grad = '1' and h.hidd_stat in ('2','3') then h.guid end) as zg_yb_hidd,
- count(distinct case when h.hidd_grad = '2' then h.guid end) as zd_hidd,
- count(distinct case when h.hidd_grad = '2' and h.hidd_stat in ('2','3') then h.guid end) as zg_zd_hidd,
- count(distinct case when h.hidd_stat in ('2','3') then h.guid end) as solved_hidd
- from att_org_base u
- left join att_org_base sub on sub.pguid = u.guid
- left join att_eng_base e on e.org_guid = sub.guid
- left join obj_hidd h on h.org_guid = sub.guid
- left join obj_hidd eh on eh.eng_guid = e.guid
- group by u.guid
- ) stat on stat.org_guid = o.guid
- <where>
- <if test="orgName != null and orgName != ''">AND o.org_name like concat('%', #{orgName}, '%')</if>
- <if test="unitType != null and unitType != ''">
- AND o.guid in (
- select org_guid from att_org_ext where wiun_code like concat(
- case #{unitType}
- when '1' then '%000000'
- when '2' then '%000'
- when '3' then '%0000'
- end
- )
- )
- </if>
- </where>
- order by o.org_name
- </select>
- <!-- 月度统计列表查询 -->
- <select id="selectTBusiHiddCountMonListWithCalc" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCountMonVo" resultType="com.goldenwater.slaj.hidd.domain.TBusiHiddCountMon">
- select
- m.guid,
- m.org_guid,
- m.create_time,
- m.year,
- m.mon,
- m.pcl,
- m.oeng_org,
- m.hidd_org,
- m.eng_num,
- m.hidd_eng,
- m.hidd_zgl,
- m.yb_zgl,
- m.yb_hidd,
- m.zg_yb_hidd,
- m.zd_zgl,
- m.zd_hidd,
- m.zg_zd_hidd,
- org.org_name,
- -- 计算字段
- (coalesce(m.zd_hidd, 0) + coalesce(m.yb_hidd, 0)) as totalHidd,
- (coalesce(m.zg_zd_hidd, 0) + coalesce(m.zg_yb_hidd, 0)) as solvedHidd,
- case when (coalesce(m.zd_hidd, 0) + coalesce(m.yb_hidd, 0)) > 0
- then (coalesce(m.zd_hidd, 0) + coalesce(m.yb_hidd, 0)) - (coalesce(m.zg_zd_hidd, 0) + coalesce(m.zg_yb_hidd, 0))
- else 0 end as unsolvedHidd,
- m.hidd_zgl as solveRate
- from t_busi_hidd_count_mon m
- left join att_org_ext org on org.org_guid = m.org_guid
- <where>
- <if test="orgGuid != null and orgGuid != ''">AND m.org_guid = #{orgGuid}</if>
- <if test="year != null and year != ''">AND m.year = #{year}</if>
- <if test="mon != null and mon != ''">AND m.mon = #{mon}</if>
- <if test="orgName != null and orgName != ''">AND org.org_name like concat('%', #{orgName}, '%')</if>
- <if test="unitType != null and unitType != ''">
- AND m.org_guid in (
- select guid from att_org_base where wiun_code like concat(
- case #{unitType}
- when '1' then '%000000'
- when '2' then '%000'
- when '3' then '%0000'
- end
- )
- )
- </if>
- </where>
- order by m.year desc, m.mon desc
- </select>
- </mapper>
|