InfoQueryMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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.infoquery.mapper.InfoQueryMapper">
  4. <!--
  5. 按单位查询:只查本单位和下级单位(subOrgs 递归范围)。
  6. 单位 = att_org_base;所辖工程 = att_eng_base.org_guid;
  7. 重大危险源 = obj_haz.hidd_grad='2';重大隐患 = obj_hidd.hidd_grad='2'。
  8. -->
  9. <select id="selectOrgStatList"
  10. parameterType="com.goldenwater.slaj.infoquery.domain.OrgStatVo"
  11. resultType="com.goldenwater.slaj.infoquery.domain.OrgStatVo">
  12. WITH RECURSIVE subOrgs AS (
  13. SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
  14. UNION ALL
  15. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
  16. UNION ALL
  17. SELECT b.guid FROM att_org_base b
  18. INNER JOIN subOrgs s ON b.pguid = s.guid
  19. )
  20. SELECT
  21. o.guid AS org_guid,
  22. o.org_name AS org_name,
  23. o.org_code AS org_code,
  24. e.wiun_prop AS wiun_prop,
  25. coalesce(stat.eng_count, 0) AS eng_count,
  26. coalesce(stat.major_haz_count, 0) AS major_haz_count,
  27. coalesce(stat.major_hidd_count, 0) AS major_hidd_count
  28. FROM att_org_base o
  29. INNER JOIN subOrgs so ON so.guid = o.guid
  30. LEFT JOIN att_org_ext e ON e.org_guid = o.guid
  31. LEFT JOIN (
  32. SELECT
  33. u.guid AS org_guid,
  34. count(DISTINCT eb.guid) AS eng_count,
  35. count(DISTINCT CASE WHEN hz.hidd_grad = '2' THEN hz.guid END) AS major_haz_count,
  36. count(DISTINCT CASE WHEN hd.hidd_grad = '2' THEN hd.guid END) AS major_hidd_count
  37. FROM att_org_base u
  38. LEFT JOIN att_eng_base eb ON eb.org_guid = u.guid
  39. LEFT JOIN obj_haz hz ON hz.org_guid = u.guid
  40. LEFT JOIN obj_hidd hd ON hd.org_guid = u.guid
  41. GROUP BY u.guid
  42. ) stat ON stat.org_guid = o.guid
  43. <where>
  44. <if test="orgName != null and orgName != ''">AND o.org_name LIKE '%' || #{orgName} || '%'</if>
  45. </where>
  46. ORDER BY o.org_name
  47. </select>
  48. <!-- 单位详情-工程信息:att_eng_base.org_guid = 单位 -->
  49. <select id="selectOrgEngList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  50. SELECT
  51. e.guid AS "guid",
  52. e.eng_name AS "engName",
  53. e.eng_type AS "engType",
  54. e.impo_grad AS "impoGrad",
  55. e.eng_stat AS "engStat",
  56. -- 主管单位:优先管辖单位(org_jurd),其次管理单位(org_rest)
  57. coalesce(oj.wiun_name, orr.wiun_name, jd.org_name, rd.org_name) AS "supOrgName"
  58. FROM att_eng_base e
  59. LEFT JOIN att_org_ext oj ON oj.org_guid = e.org_jurd
  60. LEFT JOIN att_org_ext orr ON orr.org_guid = e.org_rest
  61. LEFT JOIN att_org_base jd ON jd.guid = e.org_jurd
  62. LEFT JOIN att_org_base rd ON rd.guid = e.org_rest
  63. <where>
  64. <if test="orgGuid != null and orgGuid != ''">AND e.org_guid = #{orgGuid}::text</if>
  65. <if test="engName != null and engName != ''">AND e.eng_name LIKE '%' || #{engName} || '%'</if>
  66. </where>
  67. ORDER BY e.coll_time DESC
  68. </select>
  69. <!-- 按工程查询列表:数据范围=本单位和下级单位(subOrgs),工程 = att_eng_base -->
  70. <select id="selectEngList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  71. WITH RECURSIVE subOrgs AS (
  72. SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
  73. UNION ALL
  74. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
  75. UNION ALL
  76. SELECT b.guid FROM att_org_base b
  77. INNER JOIN subOrgs s ON b.pguid = s.guid
  78. )
  79. SELECT
  80. e.guid AS "guid",
  81. e.eng_name AS "engName",
  82. e.eng_type AS "engType",
  83. e.impo_grad AS "impoGrad",
  84. e.eng_stat AS "engStat",
  85. -- 主管单位:优先管辖单位(org_jurd),其次管理单位(org_rest)
  86. coalesce(oj.wiun_name, orr.wiun_name, jd.org_name, rd.org_name) AS "supOrgName"
  87. FROM att_eng_base e
  88. LEFT JOIN att_org_ext oj ON oj.org_guid = e.org_jurd
  89. LEFT JOIN att_org_ext orr ON orr.org_guid = e.org_rest
  90. LEFT JOIN att_org_base jd ON jd.guid = e.org_jurd
  91. LEFT JOIN att_org_base rd ON rd.guid = e.org_rest
  92. <where>
  93. <if test="orgGuid != null and orgGuid != ''">
  94. AND e.org_guid IN (SELECT guid FROM subOrgs)
  95. </if>
  96. <if test="engName != null and engName != ''">AND e.eng_name LIKE '%' || #{engName} || '%'</if>
  97. <if test="engType != null and engType != ''">AND e.eng_type = #{engType}</if>
  98. <if test="impoGrad != null and impoGrad != ''">AND e.impo_grad = #{impoGrad}</if>
  99. <if test="engStat != null and engStat != ''">AND e.eng_stat = #{engStat}</if>
  100. </where>
  101. ORDER BY e.coll_time DESC
  102. </select>
  103. <!--
  104. 应急预案信息查询:预案 = t_busi_conplan_basic,数据范围 = 本单位和下级单位(subOrgs)。
  105. 评审/备案取最新一条 t_busi_review_info,公开取最新一条 t_busi_plan_disclosure,
  106. 周期内评估取最新一条 t_busi_regular_evalu(eva_status:1未评估 2已评估)。
  107. -->
  108. <select id="selectPlanQueryList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  109. WITH RECURSIVE subOrgs AS (
  110. SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
  111. UNION ALL
  112. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
  113. UNION ALL
  114. SELECT b.guid FROM att_org_base b
  115. INNER JOIN subOrgs s ON b.pguid = s.guid
  116. )
  117. SELECT
  118. b.guid AS "guid",
  119. b.plan_name AS "planName",
  120. b.plan_type AS "planType",
  121. b.entry_time AS "entryTime",
  122. d.dept_name AS "orgName",
  123. rv.review_status AS "reviewStatus",
  124. rv.keep_status AS "keepStatus",
  125. ds.public_status AS "publicStatus",
  126. ev.eva_status AS "evaStatus"
  127. FROM t_busi_conplan_basic b
  128. LEFT JOIN sys_dept d ON d.dept_id = b.org_guid
  129. LEFT JOIN (
  130. SELECT DISTINCT ON (basic_id) basic_id, review_status, keep_status
  131. FROM t_busi_review_info
  132. ORDER BY basic_id, create_time DESC
  133. ) rv ON rv.basic_id = b.guid
  134. LEFT JOIN (
  135. SELECT DISTINCT ON (basic_id) basic_id, public_status
  136. FROM t_busi_plan_disclosure
  137. ORDER BY basic_id, create_time DESC
  138. ) ds ON ds.basic_id = b.guid
  139. LEFT JOIN (
  140. SELECT DISTINCT ON (basic_id) basic_id, eva_status
  141. FROM t_busi_regular_evalu
  142. ORDER BY basic_id, create_time DESC
  143. ) ev ON ev.basic_id = b.guid
  144. <where>
  145. <if test="orgGuid != null and orgGuid != ''">
  146. AND b.org_guid IN (SELECT guid FROM subOrgs)
  147. </if>
  148. <if test="planName != null and planName != ''">AND b.plan_name LIKE '%' || #{planName} || '%'</if>
  149. <if test="reviewStatus != null and reviewStatus != ''">AND rv.review_status = #{reviewStatus}</if>
  150. <if test="keepStatus != null and keepStatus != ''">AND rv.keep_status = #{keepStatus}</if>
  151. <if test="evaStatus != null and evaStatus != ''">AND ev.eva_status = #{evaStatus}</if>
  152. </where>
  153. ORDER BY b.create_time DESC
  154. </select>
  155. <!--
  156. 应急演练信息查询:演练 = t_busi_drill_record,数据范围 = 本单位和下级单位(subOrgs)。
  157. -->
  158. <select id="selectDrillQueryList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  159. WITH RECURSIVE subOrgs AS (
  160. SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
  161. UNION ALL
  162. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
  163. UNION ALL
  164. SELECT b.guid FROM att_org_base b
  165. INNER JOIN subOrgs s ON b.pguid = s.guid
  166. )
  167. SELECT
  168. r.dr_guid AS "drGuid",
  169. r.basic_id AS "basicId",
  170. r.drill_name AS "drillName",
  171. r.drill_type AS "drillType",
  172. r.drill_time AS "drillTime",
  173. r.partake_org AS "partakeOrg",
  174. r.partake_num AS "partakeNum",
  175. b.plan_name AS "planName",
  176. d.dept_name AS "orgName"
  177. FROM t_busi_drill_record r
  178. LEFT JOIN t_busi_conplan_basic b ON b.guid = r.basic_id
  179. LEFT JOIN sys_dept d ON d.dept_id = r.org_guid
  180. <where>
  181. <if test="orgGuid != null and orgGuid != ''">
  182. AND r.org_guid IN (SELECT guid FROM subOrgs)
  183. </if>
  184. </where>
  185. ORDER BY r.create_time DESC
  186. </select>
  187. <!--
  188. 应急队伍信息查询:队伍 = t_busi_team_info,数据范围 = 本单位和下级单位(subOrgs)。
  189. -->
  190. <select id="selectTeamQueryList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  191. WITH RECURSIVE subOrgs AS (
  192. SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
  193. UNION ALL
  194. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
  195. UNION ALL
  196. SELECT b.guid FROM att_org_base b
  197. INNER JOIN subOrgs s ON b.pguid = s.guid
  198. )
  199. SELECT
  200. t.guid AS "guid",
  201. t.team_name AS "teamName",
  202. t.team_pernum AS "teamPernum",
  203. t.team_leader AS "teamLeader",
  204. t.team_res AS "teamRes",
  205. d.dept_name AS "orgName"
  206. FROM t_busi_team_info t
  207. LEFT JOIN sys_dept d ON d.dept_id = t.org_guid
  208. <where>
  209. <if test="orgGuid != null and orgGuid != ''">
  210. AND t.org_guid IN (SELECT guid FROM subOrgs)
  211. </if>
  212. </where>
  213. ORDER BY t.create_time DESC
  214. </select>
  215. <!--
  216. 应急物资及装备查询(按单位汇总):物资 = t_busi_supplies_reserve,数据范围 = 本单位和下级单位(subOrgs)。
  217. 列表按填报机构分组,返回物资种类总数与数量总数。
  218. -->
  219. <select id="selectSuppliesQueryList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  220. WITH RECURSIVE subOrgs AS (
  221. SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
  222. UNION ALL
  223. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
  224. UNION ALL
  225. SELECT b.guid FROM att_org_base b
  226. INNER JOIN subOrgs s ON b.pguid = s.guid
  227. )
  228. SELECT
  229. s.org_guid AS "orgGuid",
  230. d.dept_name AS "orgName",
  231. COUNT(DISTINCT s.material_type) AS "materialTypeTotal",
  232. COALESCE(SUM(s.material_num), 0) AS "materialNumTotal"
  233. FROM t_busi_supplies_reserve s
  234. LEFT JOIN sys_dept d ON d.dept_id = s.org_guid
  235. <where>
  236. <if test="orgGuid != null and orgGuid != ''">
  237. AND s.org_guid IN (SELECT guid FROM subOrgs)
  238. </if>
  239. </where>
  240. GROUP BY s.org_guid, d.dept_name
  241. ORDER BY d.dept_name
  242. </select>
  243. <!--
  244. 应急物资及装备明细:点击汇总行的“详情”查看该单位具体物资记录,
  245. 数据范围同样限定在本单位和下级单位(scopeOrgGuid)。
  246. -->
  247. <select id="selectSuppliesDetailList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  248. WITH RECURSIVE subOrgs AS (
  249. SELECT guid FROM att_org_base WHERE guid = #{scopeOrgGuid}
  250. UNION ALL
  251. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{scopeOrgGuid}
  252. UNION ALL
  253. SELECT b.guid FROM att_org_base b
  254. INNER JOIN subOrgs s ON b.pguid = s.guid
  255. )
  256. SELECT
  257. s.guid AS "guid",
  258. s.material_type AS "materialType",
  259. s.material_name AS "materialName",
  260. s.material_num AS "materialNum",
  261. s.specs AS "specs",
  262. s.company AS "company",
  263. s.provide_time AS "provideTime",
  264. s.desposit_site AS "despositSite",
  265. d.dept_name AS "orgName"
  266. FROM t_busi_supplies_reserve s
  267. LEFT JOIN sys_dept d ON d.dept_id = s.org_guid
  268. WHERE s.org_guid = #{orgGuid}
  269. AND s.org_guid IN (SELECT guid FROM subOrgs)
  270. ORDER BY s.create_time DESC
  271. </select>
  272. <!--
  273. 预案统计分析:预案填报/演练统计 = t_busi_plan_count(各单位月度填报数据),
  274. 数据范围 = 本单位和下级单位(subOrgs)。
  275. 统计时间(yyyy-MM)按填报记录的 create_time 月份过滤。
  276. -->
  277. <select id="selectPlanStatList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  278. WITH RECURSIVE subOrgs AS (
  279. SELECT guid FROM att_org_base WHERE guid = #{orgGuid}
  280. UNION ALL
  281. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}
  282. UNION ALL
  283. SELECT b.guid FROM att_org_base b
  284. INNER JOIN subOrgs s ON b.pguid = s.guid
  285. )
  286. SELECT
  287. p.guid AS "guid",
  288. p.org_guid AS "orgGuid",
  289. o.org_name AS "orgName",
  290. p.zh_plan AS "zhPlan",
  291. p.zx_plan AS "zxPlan",
  292. p.xc_plan AS "xcPlan",
  293. p.org_num AS "orgNum",
  294. p.report_plan_org AS "reportPlanOrg",
  295. p.org_plan_ra AS "orgPlanRa",
  296. p.drill_num AS "drillNum",
  297. p.plan_drill_ra AS "planDrillRa",
  298. p.create_time AS "createTime"
  299. FROM t_busi_plan_count p
  300. LEFT JOIN att_org_base o ON o.guid = p.org_guid
  301. LEFT JOIN att_org_ext e ON e.org_guid = p.org_guid
  302. <where>
  303. <if test="orgGuid != null and orgGuid != ''">
  304. AND p.org_guid IN (SELECT guid FROM subOrgs)
  305. </if>
  306. <if test="wiunProp != null and wiunProp != ''">AND e.wiun_prop = #{wiunProp}</if>
  307. <if test="orgName != null and orgName != ''">AND o.org_name LIKE '%' || #{orgName} || '%'</if>
  308. <if test="statMonth != null and statMonth != ''">AND left(p.create_time::text, 7) = #{statMonth}</if>
  309. </where>
  310. ORDER BY o.org_name
  311. </select>
  312. <!-- 单位详情-危险源信息:obj_haz.org_guid = 单位 -->
  313. <select id="selectOrgHazList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  314. SELECT
  315. h.guid AS "guid",
  316. o.org_name AS "orgName",
  317. e.eng_name AS "engName",
  318. h.haz_name AS "hazName",
  319. h.hidd_grad AS "hiddGrad",
  320. h.risk_grad AS "riskGrad",
  321. h.monitor_means AS "monitorMeans",
  322. h.monitor_measure AS "monitorMeasure",
  323. h.if_control AS "ifControl",
  324. h.safe_prec AS "safePrec",
  325. h.emer_prec AS "emerPrec",
  326. -- 一源一案:该危险源所属单位存在应急预案则视为已落实(无专用字段,按此口径推导)
  327. CASE WHEN EXISTS (SELECT 1 FROM t_busi_conplan_basic cp WHERE cp.org_guid = h.org_guid)
  328. THEN 'Y' ELSE 'N' END AS "oneSourceOneCase",
  329. h.haz_stat AS "hazStat",
  330. h.sup_org AS "supOrg",
  331. h.sup_pers AS "supPers",
  332. h.offi_tel AS "supPersTel",
  333. h.coll_time AS "collTime"
  334. FROM obj_haz h
  335. LEFT JOIN att_org_base o ON h.org_guid = o.guid
  336. LEFT JOIN att_eng_base e ON h.eng_guid = e.guid
  337. <where>
  338. <if test="orgGuid != null and orgGuid != ''">AND h.org_guid = #{orgGuid}::text</if>
  339. <if test="engGuid != null and engGuid != ''">AND h.eng_guid = #{engGuid}::text</if>
  340. </where>
  341. ORDER BY h.coll_time DESC
  342. </select>
  343. <!-- 单位详情-隐患信息:obj_hidd.org_guid = 单位,关联排查/整改(最新)/验收(最新) -->
  344. <select id="selectOrgHiddList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  345. SELECT
  346. h.guid AS "guid",
  347. o.org_name AS "orgName",
  348. e.eng_name AS "engName",
  349. h.hidd_name AS "hiddName",
  350. bi.insp_date AS "inspDate",
  351. h.hidd_grad AS "hiddGrad",
  352. h.hidd_clas AS "hiddClas",
  353. h.hidd_stat AS "hiddStat",
  354. coalesce(rio.org_name, ri.gover_resp_wiun) AS "rectOrgName",
  355. ri.rect_leg_pers AS "rectLegPers",
  356. -- 验收单位:验收记录创建人(rec_pers)所在单位(无专用字段,按此口径推导)
  357. ud.dept_name AS "acceOrgName",
  358. ra.accep_pers AS "accepPers",
  359. h.coll_time AS "collTime"
  360. FROM obj_hidd h
  361. LEFT JOIN att_org_base o ON h.org_guid = o.guid
  362. LEFT JOIN att_eng_base e ON h.eng_guid = e.guid
  363. LEFT JOIN bis_hidd_inve bi ON h.insp_rec_guid = bi.guid
  364. LEFT JOIN (
  365. SELECT DISTINCT ON (hidd_guid) hidd_guid, gover_resp_wiun_guid, gover_resp_wiun, rect_leg_pers
  366. FROM bis_hidd_rect_impl
  367. ORDER BY hidd_guid, coll_time DESC
  368. ) ri ON ri.hidd_guid = h.guid
  369. LEFT JOIN att_org_base rio ON rio.guid = ri.gover_resp_wiun_guid
  370. LEFT JOIN (
  371. SELECT DISTINCT ON (hidd_guid) hidd_guid, accep_pers, rec_pers
  372. FROM bis_hidd_rect_acce
  373. ORDER BY hidd_guid, coll_time DESC
  374. ) ra ON ra.hidd_guid = h.guid
  375. LEFT JOIN sys_user u ON u.user_id = CASE WHEN ra.rec_pers ~ '^[0-9]+$' THEN ra.rec_pers::bigint ELSE NULL END
  376. LEFT JOIN sys_dept ud ON ud.dept_id = u.dept_id
  377. <where>
  378. <if test="orgGuid != null and orgGuid != ''">AND h.org_guid = #{orgGuid}::text</if>
  379. <if test="engGuid != null and engGuid != ''">AND h.eng_guid = #{engGuid}::text</if>
  380. </where>
  381. ORDER BY h.coll_time DESC
  382. </select>
  383. <!-- 单位详情-事故信息:obj_acci.acci_wiun_guid = 单位 -->
  384. <select id="selectOrgAcciList" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  385. SELECT
  386. a.guid AS "guid",
  387. a.sgdw_name || '事故' AS "acciName",
  388. a.acci_grad AS "acciGrad",
  389. a.acci_cate AS "acciCate",
  390. a.cas_num AS "casNum",
  391. a.ser_inj_num AS "serInjNum",
  392. a.econ_loss AS "econLoss",
  393. a.rep_stat AS "repStat"
  394. FROM obj_acci a
  395. <where>
  396. <if test="orgGuid != null and orgGuid != ''">AND a.acci_wiun_guid = #{orgGuid}::text</if>
  397. <if test="engGuid != null and engGuid != ''">AND a.eng_guid = #{engGuid}::text</if>
  398. </where>
  399. ORDER BY a.occu_time DESC
  400. </select>
  401. </mapper>