TBusiHiddCountMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.goldenwater.slaj.hidd.mapper.TBusiHiddCountMapper">
  4. <resultMap type="com.goldenwater.slaj.hidd.domain.TBusiHiddCount" id="TBusiHiddCountResult">
  5. <result property="guid" column="guid"/>
  6. <result property="orgGuid" column="org_guid"/>
  7. <result property="createTime" column="create_time"/>
  8. <result property="pcl" column="pcl"/>
  9. <result property="oengOrg" column="oeng_org"/>
  10. <result property="hiddOrg" column="hidd_org"/>
  11. <result property="engNum" column="eng_num"/>
  12. <result property="hiddEng" column="hidd_eng"/>
  13. <result property="hiddZgl" column="hidd_zgl"/>
  14. <result property="ybZgl" column="yb_zgl"/>
  15. <result property="ybHidd" column="yb_hidd"/>
  16. <result property="zgYbHidd" column="zg_yb_hidd"/>
  17. <result property="zdZgl" column="zd_zgl"/>
  18. <result property="zdHidd" column="zd_hidd"/>
  19. <result property="zgZdHidd" column="zg_zd_hidd"/>
  20. </resultMap>
  21. <!-- VO类ResultMap(包含计算字段) -->
  22. <resultMap type="com.goldenwater.slaj.hidd.domain.TBusiHiddCountVo" id="TBusiHiddCountVoResult">
  23. <result property="guid" column="guid"/>
  24. <result property="orgGuid" column="org_guid"/>
  25. <result property="createTime" column="create_time"/>
  26. <result property="pcl" column="pcl"/>
  27. <result property="oengOrg" column="oeng_org"/>
  28. <result property="hiddOrg" column="hidd_org"/>
  29. <result property="engNum" column="eng_num"/>
  30. <result property="hiddEng" column="hidd_eng"/>
  31. <result property="hiddZgl" column="hidd_zgl"/>
  32. <result property="ybZgl" column="yb_zgl"/>
  33. <result property="ybHidd" column="yb_hidd"/>
  34. <result property="zgYbHidd" column="zg_yb_hidd"/>
  35. <result property="zdZgl" column="zd_zgl"/>
  36. <result property="zdHidd" column="zd_hidd"/>
  37. <result property="zgZdHidd" column="zg_zd_hidd"/>
  38. <!-- 计算字段 -->
  39. <result property="orgName" column="org_name"/>
  40. <result property="totalHidd" column="total_hidd"/>
  41. <result property="solvedHidd" column="solved_hidd"/>
  42. <result property="solvingHidd" column="solving_hidd"/>
  43. <result property="unsolvedHidd" column="unsolved_hidd"/>
  44. <result property="solveRate" column="solve_rate"/>
  45. <!-- 逾期统计字段 -->
  46. <result property="zdSolvingHidd" column="zd_solving_hidd"/>
  47. <result property="zdUnsolvedHidd" column="zd_unsolved_hidd"/>
  48. <result property="zdOverTimeHidd" column="zd_overtime_hidd"/>
  49. <result property="ybSolvingHidd" column="yb_solving_hidd"/>
  50. <result property="ybUnsolvedHidd" column="yb_unsolved_hidd"/>
  51. <result property="ybOverTimeHidd" column="yb_overtime_hidd"/>
  52. <result property="overTimeHidd" column="overtime_hidd"/>
  53. </resultMap>
  54. <sql id="selectTBusiHiddCountVo">
  55. select guid, org_guid, create_time, pcl, oeng_org, hidd_org, eng_num, hidd_eng,
  56. hidd_zgl, yb_zgl, yb_hidd, zg_yb_hidd, zd_zgl, zd_hidd, zg_zd_hidd
  57. from t_busi_hidd_count
  58. </sql>
  59. <select id="selectTBusiHiddCountById" parameterType="String" resultMap="TBusiHiddCountResult">
  60. <include refid="selectTBusiHiddCountVo"/>
  61. where guid = #{guid}
  62. </select>
  63. <select id="selectTBusiHiddCountList" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCount" resultMap="TBusiHiddCountResult">
  64. <include refid="selectTBusiHiddCountVo"/>
  65. <where>
  66. <if test="orgGuid != null and orgGuid != ''">AND org_guid = #{orgGuid}</if>
  67. <if test="createTime != null and createTime != ''">AND create_time = #{createTime}</if>
  68. </where>
  69. </select>
  70. <insert id="insertTBusiHiddCount" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCount">
  71. 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)
  72. values (#{guid}, #{orgGuid}, #{createTime}, #{pcl}, #{oengOrg}, #{hiddOrg}, #{engNum}, #{hiddEng}, #{hiddZgl}, #{ybZgl}, #{ybHidd}, #{zgYbHidd}, #{zdZgl}, #{zdHidd}, #{zgZdHidd})
  73. </insert>
  74. <update id="updateTBusiHiddCount" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCount">
  75. update t_busi_hidd_count
  76. <set>
  77. <if test="orgGuid != null">org_guid = #{orgGuid},</if>
  78. <if test="createTime != null">create_time = #{createTime},</if>
  79. <if test="pcl != null">pcl = #{pcl},</if>
  80. <if test="oengOrg != null">oeng_org = #{oengOrg},</if>
  81. <if test="hiddOrg != null">hidd_org = #{hiddOrg},</if>
  82. <if test="engNum != null">eng_num = #{engNum},</if>
  83. <if test="hiddEng != null">hidd_eng = #{hiddEng},</if>
  84. <if test="hiddZgl != null">hidd_zgl = #{hiddZgl},</if>
  85. <if test="ybZgl != null">yb_zgl = #{ybZgl},</if>
  86. <if test="ybHidd != null">yb_hidd = #{ybHidd},</if>
  87. <if test="zgYbHidd != null">zg_yb_hidd = #{zgYbHidd},</if>
  88. <if test="zdZgl != null">zd_zgl = #{zdZgl},</if>
  89. <if test="zdHidd != null">zd_hidd = #{zdHidd},</if>
  90. <if test="zgZdHidd != null">zg_zd_hidd = #{zgZdHidd},</if>
  91. </set>
  92. where guid = #{guid}
  93. </update>
  94. <delete id="deleteTBusiHiddCountById" parameterType="String">
  95. delete from t_busi_hidd_count where guid = #{guid}
  96. </delete>
  97. <delete id="deleteTBusiHiddCountByIds" parameterType="String">
  98. delete from t_busi_hidd_count where guid in
  99. <foreach item="guid" collection="array" open="(" separator="," close=")">
  100. #{guid}
  101. </foreach>
  102. </delete>
  103. <!-- 注意: PG 未加引号的别名会转小写,Map 返回必须用双引号保留驼峰,否则前端取不到字段 -->
  104. <select id="selectReportRateChart" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  105. select c.org_guid as "orgGuid",
  106. org.wiun_name as "orgName",
  107. c.pcl as "rateData",
  108. c.create_time as "repTime"
  109. from t_busi_hidd_count c
  110. left join att_org_ext org on org.org_guid = c.org_guid
  111. <where>
  112. <if test="repTime != null and repTime != ''">AND c.create_time = #{repTime}</if>
  113. </where>
  114. order by c.pcl desc
  115. </select>
  116. <select id="selectRectifyRateChart" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  117. select c.org_guid as "orgGuid",
  118. org.wiun_name as "orgName",
  119. c.hidd_zgl as "rateData",
  120. c.create_time as "repTime"
  121. from t_busi_hidd_count c
  122. left join att_org_ext org on org.org_guid = c.org_guid
  123. <where>
  124. <if test="repTime != null and repTime != ''">AND c.create_time = #{repTime}</if>
  125. </where>
  126. order by c.hidd_zgl desc
  127. </select>
  128. <!-- 隐患统计列表查询(带计算字段) -->
  129. <select id="selectTBusiHiddCountListWithCalc" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCountVo" resultMap="TBusiHiddCountVoResult">
  130. select
  131. c.guid,
  132. c.org_guid,
  133. c.create_time,
  134. c.pcl,
  135. c.oeng_org,
  136. c.hidd_org,
  137. c.eng_num,
  138. c.hidd_eng,
  139. c.hidd_zgl,
  140. c.yb_zgl,
  141. c.yb_hidd,
  142. c.zg_yb_hidd,
  143. c.zd_zgl,
  144. c.zd_hidd,
  145. c.zg_zd_hidd,
  146. org.wiun_name as org_name,
  147. -- 计算字段
  148. (coalesce(c.zd_hidd, 0) + coalesce(c.yb_hidd, 0)) as total_hidd,
  149. (coalesce(c.zg_zd_hidd, 0) + coalesce(c.zg_yb_hidd, 0)) as solved_hidd,
  150. -- 正在整改中 = 重大整改中 + 一般整改中
  151. (case when coalesce(c.zd_hidd, 0) > coalesce(c.zg_zd_hidd, 0)
  152. then coalesce(c.zd_hidd, 0) - coalesce(c.zg_zd_hidd, 0) else 0 end
  153. + case when coalesce(c.yb_hidd, 0) > coalesce(c.zg_yb_hidd, 0)
  154. then coalesce(c.yb_hidd, 0) - coalesce(c.zg_yb_hidd, 0) else 0 end) as solving_hidd,
  155. case when (coalesce(c.zd_hidd, 0) + coalesce(c.yb_hidd, 0)) > 0
  156. then (coalesce(c.zd_hidd, 0) + coalesce(c.yb_hidd, 0)) - (coalesce(c.zg_zd_hidd, 0) + coalesce(c.zg_yb_hidd, 0))
  157. else 0 end as unsolved_hidd,
  158. c.hidd_zgl as solve_rate,
  159. -- 重大隐患-整改中
  160. case when coalesce(c.zd_hidd, 0) > coalesce(c.zg_zd_hidd, 0)
  161. then coalesce(c.zd_hidd, 0) - coalesce(c.zg_zd_hidd, 0)
  162. else 0 end as zd_solving_hidd,
  163. -- 重大隐患-未整改(预留,暂为0)
  164. 0 as zd_unsolved_hidd,
  165. -- 重大隐患-逾期未整改(预留,暂为0)
  166. 0 as zd_overtime_hidd,
  167. -- 一般隐患-整改中
  168. case when coalesce(c.yb_hidd, 0) > coalesce(c.zg_yb_hidd, 0)
  169. then coalesce(c.yb_hidd, 0) - coalesce(c.zg_yb_hidd, 0)
  170. else 0 end as yb_solving_hidd,
  171. -- 一般隐患-未整改(预留,暂为0)
  172. 0 as yb_unsolved_hidd,
  173. -- 一般隐患-逾期未整改(预留,暂为0)
  174. 0 as yb_overtime_hidd,
  175. -- 逾期未整改总数
  176. 0 as overtime_hidd
  177. from t_busi_hidd_count c
  178. left join att_org_ext org on org.org_guid = c.org_guid
  179. <where>
  180. <if test="orgGuid != null and orgGuid != ''">AND c.org_guid = #{orgGuid}</if>
  181. <if test="createTime != null and createTime != ''">AND c.create_time = #{createTime}</if>
  182. <if test="orgName != null and orgName != ''">AND org.org_name like concat('%', #{orgName}, '%')</if>
  183. <if test="unitType != null and unitType != ''">
  184. AND c.org_guid in (
  185. select org_guid from att_org_ext where wiun_code like concat(
  186. case #{unitType}
  187. when '1' then '%000000'
  188. when '2' then '%000'
  189. when '3' then '%0000'
  190. end
  191. )
  192. )
  193. </if>
  194. </where>
  195. order by c.create_time desc
  196. </select>
  197. <!-- 隐患统计列表查询(实时聚合,不依赖 t_busi_hidd_count 表)
  198. 口径:按单位实时统计名下隐患,与旧版 selectHiddCount 一致 -->
  199. <select id="selectTBusiHiddCountRealtimeList" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCountVo" resultMap="TBusiHiddCountVoResult">
  200. select
  201. o.guid as org_guid,
  202. o.org_name as org_name,
  203. -- 排查情况:非工程单位(下级单位中无工程关联的)
  204. coalesce(stat.oeng_org, 0) as oeng_org,
  205. -- 已排查非工程单位(有隐患记录的下级单位)
  206. coalesce(stat.hidd_org, 0) as hidd_org,
  207. -- 工程总数(该单位名下的工程)
  208. coalesce(stat.eng_num, 0) as eng_num,
  209. -- 有隐患的工程数
  210. coalesce(stat.hidd_eng, 0) as hidd_eng,
  211. -- 排查率 = 已排查单位/单位总数
  212. case when coalesce(stat.total_org, 0) > 0
  213. then round(coalesce(stat.hidd_org, 0) * 100.0 / stat.total_org, 2)
  214. else 0 end as pcl,
  215. -- 综合整改率
  216. case when coalesce(stat.total_hidd, 0) > 0
  217. then round(coalesce(stat.solved_hidd, 0) * 100.0 / stat.total_hidd, 2)
  218. else 0 end as hidd_zgl,
  219. -- 一般隐患数
  220. coalesce(stat.yb_hidd, 0) as yb_hidd,
  221. -- 已整改一般隐患数
  222. coalesce(stat.zg_yb_hidd, 0) as zg_yb_hidd,
  223. -- 一般整改率
  224. case when coalesce(stat.yb_hidd, 0) > 0
  225. then round(coalesce(stat.zg_yb_hidd, 0) * 100.0 / stat.yb_hidd, 2)
  226. else 0 end as yb_zgl,
  227. -- 重大隐患数
  228. coalesce(stat.zd_hidd, 0) as zd_hidd,
  229. -- 已整改重大隐患数
  230. coalesce(stat.zg_zd_hidd, 0) as zg_zd_hidd,
  231. -- 重大整改率
  232. case when coalesce(stat.zd_hidd, 0) > 0
  233. then round(coalesce(stat.zg_zd_hidd, 0) * 100.0 / stat.zd_hidd, 2)
  234. else 0 end as zd_zgl
  235. from att_org_base o
  236. left join (
  237. select
  238. u.guid as org_guid,
  239. -- 下级单位总数(非工程单位 = 无工程关联的下级单位)
  240. count(distinct case when e.guid is null then sub.guid end) as total_org,
  241. -- 非工程单位总数
  242. count(distinct case when e.guid is null then sub.guid end) as oeng_org,
  243. -- 有隐患记录的下级单位(已排查)
  244. count(distinct case when e.guid is null and h.guid is not null then sub.guid end) as hidd_org,
  245. -- 该单位名下工程总数
  246. count(distinct e.guid) as eng_num,
  247. -- 有隐患的工程数
  248. count(distinct case when eh.guid is not null then e.guid end) as hidd_eng,
  249. -- 隐患统计(该单位名下)
  250. count(distinct h.guid) as total_hidd,
  251. count(distinct case when h.hidd_grad = '1' then h.guid end) as yb_hidd,
  252. count(distinct case when h.hidd_grad = '1' and h.hidd_stat in ('2','3') then h.guid end) as zg_yb_hidd,
  253. count(distinct case when h.hidd_grad = '2' then h.guid end) as zd_hidd,
  254. count(distinct case when h.hidd_grad = '2' and h.hidd_stat in ('2','3') then h.guid end) as zg_zd_hidd,
  255. count(distinct case when h.hidd_stat in ('2','3') then h.guid end) as solved_hidd
  256. from att_org_base u
  257. left join att_org_base sub on sub.pguid = u.guid
  258. left join att_eng_base e on e.org_guid = sub.guid
  259. left join obj_hidd h on h.org_guid = sub.guid
  260. left join obj_hidd eh on eh.eng_guid = e.guid
  261. group by u.guid
  262. ) stat on stat.org_guid = o.guid
  263. <where>
  264. <if test="orgName != null and orgName != ''">AND o.org_name like concat('%', #{orgName}, '%')</if>
  265. <if test="unitType != null and unitType != ''">
  266. AND o.guid in (
  267. select org_guid from att_org_ext where wiun_code like concat(
  268. case #{unitType}
  269. when '1' then '%000000'
  270. when '2' then '%000'
  271. when '3' then '%0000'
  272. end
  273. )
  274. )
  275. </if>
  276. </where>
  277. order by o.org_name
  278. </select>
  279. <!-- 月度统计列表查询 -->
  280. <select id="selectTBusiHiddCountMonListWithCalc" parameterType="com.goldenwater.slaj.hidd.domain.TBusiHiddCountMonVo" resultType="com.goldenwater.slaj.hidd.domain.TBusiHiddCountMon">
  281. select
  282. m.guid,
  283. m.org_guid,
  284. m.create_time,
  285. m.year,
  286. m.mon,
  287. m.pcl,
  288. m.oeng_org,
  289. m.hidd_org,
  290. m.eng_num,
  291. m.hidd_eng,
  292. m.hidd_zgl,
  293. m.yb_zgl,
  294. m.yb_hidd,
  295. m.zg_yb_hidd,
  296. m.zd_zgl,
  297. m.zd_hidd,
  298. m.zg_zd_hidd,
  299. org.org_name,
  300. -- 计算字段
  301. (coalesce(m.zd_hidd, 0) + coalesce(m.yb_hidd, 0)) as totalHidd,
  302. (coalesce(m.zg_zd_hidd, 0) + coalesce(m.zg_yb_hidd, 0)) as solvedHidd,
  303. case when (coalesce(m.zd_hidd, 0) + coalesce(m.yb_hidd, 0)) > 0
  304. then (coalesce(m.zd_hidd, 0) + coalesce(m.yb_hidd, 0)) - (coalesce(m.zg_zd_hidd, 0) + coalesce(m.zg_yb_hidd, 0))
  305. else 0 end as unsolvedHidd,
  306. m.hidd_zgl as solveRate
  307. from t_busi_hidd_count_mon m
  308. left join att_org_ext org on org.org_guid = m.org_guid
  309. <where>
  310. <if test="orgGuid != null and orgGuid != ''">AND m.org_guid = #{orgGuid}</if>
  311. <if test="year != null and year != ''">AND m.year = #{year}</if>
  312. <if test="mon != null and mon != ''">AND m.mon = #{mon}</if>
  313. <if test="orgName != null and orgName != ''">AND org.org_name like concat('%', #{orgName}, '%')</if>
  314. <if test="unitType != null and unitType != ''">
  315. AND m.org_guid in (
  316. select guid from att_org_base where wiun_code like concat(
  317. case #{unitType}
  318. when '1' then '%000000'
  319. when '2' then '%000'
  320. when '3' then '%0000'
  321. end
  322. )
  323. )
  324. </if>
  325. </where>
  326. order by m.year desc, m.mon desc
  327. </select>
  328. </mapper>