ObjHiddMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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.ObjHiddMapper">
  4. <resultMap type="com.goldenwater.slaj.hidd.domain.ObjHiddVo" id="ObjHiddResult">
  5. <result property="guid" column="guid"/>
  6. <result property="hiddName" column="hidd_name"/>
  7. <result property="engGuid" column="eng_guid"/>
  8. <result property="tendGuid" column="tend_guid"/>
  9. <result property="tendName" column="tend_name"/>
  10. <result property="seGuid" column="se_guid"/>
  11. <result property="orgGuid" column="org_guid"/>
  12. <result property="hiddSour" column="hidd_sour"/>
  13. <result property="hiddGrad" column="hidd_grad"/>
  14. <result property="hiddClas" column="hidd_clas"/>
  15. <result property="ifFound" column="if_found"/>
  16. <result property="proPart" column="pro_part"/>
  17. <result property="partLong" column="part_long"/>
  18. <result property="partLat" column="part_lat"/>
  19. <result property="otlcolQiffFnvu" column="otlcol_qiff_fnvu"/>
  20. <result property="inspRecGuid" column="insp_rec_guid"/>
  21. <result property="seCheckItemGuid" column="se_check_item_guid"/>
  22. <result property="hiddStat" column="hidd_stat"/>
  23. <result property="hiddMergGuid" column="hidd_merg_guid"/>
  24. <result property="recOrgGuid" column="rec_org_guid"/>
  25. <result property="note" column="note"/>
  26. <result property="collTime" column="coll_time"/>
  27. <result property="updTime" column="upd_time"/>
  28. <result property="recPers" column="rec_pers"/>
  29. <result property="hiddsGuid" column="hidds_guid"/>
  30. <result property="occuNum" column="occu_num"/>
  31. <result property="sinsScheGuid" column="sins_sche_guid"/>
  32. <result property="groupGuid" column="group_guid"/>
  33. <result property="temp" column="temp"/>
  34. <result property="toDate" column="to_date"/>
  35. <result property="dictGuid" column="dict_guid"/>
  36. <result property="engName" column="eng_name"/>
  37. <result property="orgName" column="org_name"/>
  38. <result property="inspDate" column="insp_date"/>
  39. <result property="requCompDate" column="requ_comp_date"/>
  40. <result property="supStat" column="sup_stat"/>
  41. <result property="cancelState" column="cancel_state"/>
  42. <result property="repAct" column="rep_act"/>
  43. <result property="returnDesc" column="return_desc"/>
  44. </resultMap>
  45. <sql id="selectObjHiddVo">
  46. select h.guid, h.hidd_name, h.eng_guid, h.tend_guid, h.se_guid, h.org_guid, h.hidd_sour, h.hidd_grad, h.hidd_clas, h.if_found, h.pro_part, h.part_long, h.part_lat, h.otlcol_qiff_fnvu, h.insp_rec_guid, h.se_check_item_guid, h.hidd_stat, h.hidd_merg_guid, h.rec_org_guid, h.note, h.coll_time, h.upd_time, h.rec_pers, h.hidds_guid, h.occu_num, h.sins_sche_guid, h.group_guid, h.temp, h.to_date, h.dict_guid,
  47. e.eng_name,
  48. o.org_name,
  49. bi.insp_date,
  50. ri.requ_comp_date,
  51. t.tend_name,
  52. COALESCE(CASE WHEN ms.hidd_guid IS NOT NULL THEN '1' ELSE '0' END, '0') as sup_stat,
  53. COALESCE(ra.cancel_state, '0') as cancel_state,
  54. rr.rep_act,
  55. rr.return_desc
  56. from obj_hidd h
  57. left join obj_eng e on h.eng_guid = e.guid
  58. left join att_org_base o on h.org_guid = o.guid
  59. left join bis_hidd_inve bi on h.insp_rec_guid = bi.guid
  60. left join bis_hidd_rect_impl ri on h.guid = ri.hidd_guid
  61. left join bis_hidd_rect_acce ra on h.guid = ra.hidd_guid
  62. left join bis_maj_hidd_sup ms on h.guid = ms.hidd_guid
  63. left join obj_tend t on h.tend_guid = t.guid
  64. -- 最新一条上报记录(上报/退回状态与原因)
  65. left join (
  66. select distinct on (rrx.hidd_guid) rrx.hidd_guid, rrx.rep_act, rrx.return_desc
  67. from bis_hidd_rec_rep rrx
  68. order by rrx.hidd_guid, rrx.coll_time desc
  69. ) rr on rr.hidd_guid = h.guid
  70. </sql>
  71. <select id="selectObjHiddByGuid" parameterType="String" resultMap="ObjHiddResult">
  72. <include refid="selectObjHiddVo"/>
  73. where h.guid = #{guid}
  74. </select>
  75. <select id="selectObjHiddList" parameterType="com.goldenwater.slaj.hidd.domain.ObjHidd" resultMap="ObjHiddResult">
  76. <include refid="selectObjHiddVo"/>
  77. <where>
  78. <if test="hiddName != null and hiddName != ''">AND h.hidd_name like '%' || #{hiddName}::text || '%'</if>
  79. <if test="hiddGrad != null and hiddGrad != ''">AND h.hidd_grad = #{hiddGrad}::text</if>
  80. <if test="hiddStat != null and hiddStat != ''">AND h.hidd_stat = #{hiddStat}::text</if>
  81. <if test="orgGuid != null and orgGuid != ''">
  82. <choose>
  83. <!-- consEng(7)/partEng(6): 两角度归并 - 自己的 + 关联施工单位/参建单位的 -->
  84. <when test="wiunProp == '6'.toString() or wiunProp == '7'.toString()">
  85. AND (
  86. h.org_guid = #{orgGuid}::text
  87. OR h.org_guid IN (
  88. -- 关联单位: rel_tend_org(标段关联) → att_org_uwat_base → org_code → att_org_base
  89. select b.guid from att_org_base b
  90. where b.org_code in (
  91. select u.org_code from att_org_uwat_base u
  92. where u.guid in (
  93. select r.org_uwat_guid from rel_tend_org r
  94. join obj_tend t on t.guid = r.tend_guid
  95. where t.eng_guid in (
  96. -- 当前用户(法人)的工程: att_eng_base.org_guid
  97. select e.eng_guid from att_eng_base e where e.org_guid = #{orgGuid}::text
  98. union
  99. -- 当前用户(监理/施工)经标段关联的工程
  100. select t2.eng_guid from obj_tend t2
  101. where t2.guid in (
  102. select r2.tend_guid from rel_tend_org r2
  103. where r2.org_uwat_guid = #{orgGuid}::text
  104. )
  105. )
  106. )
  107. )
  108. )
  109. )
  110. </when>
  111. <otherwise>
  112. AND h.org_guid = #{orgGuid}::text
  113. </otherwise>
  114. </choose>
  115. </if>
  116. <if test="engGuid != null and engGuid != ''">AND h.eng_guid = #{engGuid}::text</if>
  117. <if test="guid != null and guid != ''">AND h.guid = #{guid}::text</if>
  118. <if test="hiddSour != null and hiddSour != ''">AND h.hidd_sour = #{hiddSour}::text</if>
  119. <if test="orgName != null and orgName != ''">AND o.org_name like '%' || #{orgName}::text || '%'</if>
  120. <if test="engName != null and engName != ''">AND e.eng_name like '%' || #{engName}::text || '%'</if>
  121. <if test="drillHiddClas != null and drillHiddClas != ''">
  122. <choose>
  123. <when test='drillHiddClas == "2"'>AND (h.hidd_clas = '2' OR h.hidd_clas IS NULL)</when>
  124. <otherwise>AND h.hidd_clas = #{drillHiddClas}::text</otherwise>
  125. </choose>
  126. </if>
  127. <if test="collTime != null and collTime != ''">AND h.coll_time >= CAST(#{collTime}::text AS timestamp) AND h.coll_time &lt; CAST(#{collTime}::text AS timestamp) + INTERVAL '1 day'</if>
  128. <if test="wiunProp != null and wiunProp != ''">AND EXISTS (SELECT 1 FROM att_org_ext ext WHERE ext.org_guid = h.org_guid AND ext.wiun_prop = #{wiunProp}::text)</if>
  129. </where>
  130. </select>
  131. <!-- 钻取明细查询:CTE范围 + 工程名称/单位名称精确过滤 -->
  132. <select id="selectObjHiddDrillList" parameterType="java.util.Map" resultMap="ObjHiddResult">
  133. WITH RECURSIVE subOrgs AS (
  134. SELECT guid FROM att_org_base WHERE guid = #{orgGuid}::text
  135. UNION ALL
  136. SELECT e.org_guid FROM att_org_ext e WHERE e.admin_wiun_guid = #{orgGuid}::text
  137. UNION ALL
  138. SELECT b.guid FROM att_org_base b
  139. INNER JOIN subOrgs s ON b.pguid = s.guid
  140. )
  141. <include refid="selectObjHiddVo"/>
  142. <where>
  143. h.org_guid IN (SELECT guid FROM subOrgs)
  144. <if test="engName != null and engName != ''">AND e.eng_name like '%' || #{engName}::text || '%'</if>
  145. <if test="orgName != null and orgName != ''">AND o.org_name like '%' || #{orgName}::text || '%'</if>
  146. <if test="hiddClas != null and hiddClas != ''">
  147. <choose>
  148. <when test='hiddClas == "2"'>AND (h.hidd_clas = '2' OR h.hidd_clas IS NULL)</when>
  149. <otherwise>AND h.hidd_clas = #{hiddClas}::text</otherwise>
  150. </choose>
  151. </if>
  152. <if test="collTime != null and collTime != ''">AND h.coll_time >= CAST(#{collTime}::text AS timestamp) AND h.coll_time &lt; CAST(#{collTime}::text AS timestamp) + INTERVAL '1 day'</if>
  153. </where>
  154. order by h.coll_time desc
  155. </select>
  156. <insert id="insertObjHidd" parameterType="com.goldenwater.slaj.hidd.domain.ObjHidd">
  157. insert into obj_hidd (guid, hidd_name, eng_guid, tend_guid, se_guid, org_guid, hidd_sour, hidd_grad, hidd_clas, if_found, pro_part, part_long, part_lat, otlcol_qiff_fnvu, insp_rec_guid, se_check_item_guid, hidd_stat, hidd_merg_guid, rec_org_guid, note, coll_time, upd_time, rec_pers, hidds_guid, occu_num, sins_sche_guid, group_guid, temp, to_date, dict_guid)
  158. values (#{guid}, #{hiddName}, #{engGuid}, #{tendGuid}, #{seGuid}, #{orgGuid}, #{hiddSour}, #{hiddGrad}, #{hiddClas}, #{ifFound}, #{proPart}, #{partLong}, #{partLat}, #{otlcolQiffFnvu}, #{inspRecGuid}, #{seCheckItemGuid}, #{hiddStat}, #{hiddMergGuid}, #{recOrgGuid}, #{note}, #{collTime}, #{updTime}, #{recPers}, #{hiddsGuid}, #{occuNum}, #{sinsScheGuid}, #{groupGuid}, #{temp}, #{toDate}, #{dictGuid})
  159. </insert>
  160. <update id="updateObjHidd" parameterType="com.goldenwater.slaj.hidd.domain.ObjHidd">
  161. update obj_hidd
  162. <set>
  163. <if test="hiddName != null">hidd_name = #{hiddName},</if>
  164. <if test="engGuid != null">eng_guid = #{engGuid},</if>
  165. <if test="tendGuid != null">tend_guid = #{tendGuid},</if>
  166. <if test="seGuid != null">se_guid = #{seGuid},</if>
  167. <if test="orgGuid != null">org_guid = #{orgGuid},</if>
  168. <if test="hiddSour != null">hidd_sour = #{hiddSour},</if>
  169. <if test="hiddGrad != null">hidd_grad = #{hiddGrad},</if>
  170. <if test="hiddClas != null">hidd_clas = #{hiddClas},</if>
  171. <if test="ifFound != null">if_found = #{ifFound},</if>
  172. <if test="proPart != null">pro_part = #{proPart},</if>
  173. <if test="partLong != null">part_long = #{partLong},</if>
  174. <if test="partLat != null">part_lat = #{partLat},</if>
  175. <if test="otlcolQiffFnvu != null">otlcol_qiff_fnvu = #{otlcolQiffFnvu},</if>
  176. <if test="inspRecGuid != null">insp_rec_guid = #{inspRecGuid},</if>
  177. <if test="seCheckItemGuid != null">se_check_item_guid = #{seCheckItemGuid},</if>
  178. <if test="hiddStat != null">hidd_stat = #{hiddStat},</if>
  179. <if test="hiddMergGuid != null">hidd_merg_guid = #{hiddMergGuid},</if>
  180. <if test="recOrgGuid != null">rec_org_guid = #{recOrgGuid},</if>
  181. <if test="note != null">note = #{note},</if>
  182. <if test="collTime != null">coll_time = #{collTime},</if>
  183. <if test="updTime != null">upd_time = #{updTime},</if>
  184. <if test="recPers != null">rec_pers = #{recPers},</if>
  185. <if test="hiddsGuid != null">hidds_guid = #{hiddsGuid},</if>
  186. <if test="occuNum != null">occu_num = #{occuNum},</if>
  187. <if test="sinsScheGuid != null">sins_sche_guid = #{sinsScheGuid},</if>
  188. <if test="groupGuid != null">group_guid = #{groupGuid},</if>
  189. <if test="temp != null">temp = #{temp},</if>
  190. <if test="toDate != null">to_date = #{toDate},</if>
  191. <if test="dictGuid != null">dict_guid = #{dictGuid},</if>
  192. </set>
  193. where guid = #{guid}
  194. </update>
  195. <delete id="deleteObjHiddByGuid" parameterType="String">
  196. delete from obj_hidd where guid = #{guid}
  197. </delete>
  198. <delete id="deleteObjHiddByGuids" parameterType="String">
  199. delete from obj_hidd where guid in
  200. <foreach item="guid" collection="array" open="(" separator="," close=")">
  201. #{guid}
  202. </foreach>
  203. </delete>
  204. <select id="selectObjHiddListByName" parameterType="com.goldenwater.slaj.hidd.domain.ObjHidd" resultMap="ObjHiddResult">
  205. <include refid="selectObjHiddVo"/>
  206. <where>
  207. <if test="hiddName != null and hiddName != ''">AND hidd_name like '%' || #{hiddName} || '%'</if>
  208. <if test="hiddGrad != null and hiddGrad != ''">AND hidd_grad = #{hiddGrad}</if>
  209. <if test="hiddStat != null and hiddStat != ''">AND hidd_stat = #{hiddStat}</if>
  210. <if test="orgGuid != null and orgGuid != ''">AND org_guid = #{orgGuid}</if>
  211. <if test="engGuid != null and engGuid != ''">AND eng_guid = #{engGuid}</if>
  212. <if test="wiunProp != null and wiunProp != ''">AND EXISTS (SELECT 1 FROM att_org_ext ext WHERE ext.org_guid = org_guid AND ext.wiun_prop = #{wiunProp})</if>
  213. </where>
  214. order by coll_time desc
  215. </select>
  216. <select id="selectNextDepHiddList" parameterType="com.goldenwater.slaj.hidd.domain.ObjHidd" resultMap="ObjHiddResult">
  217. <include refid="selectObjHiddVo"/>
  218. <where>
  219. <if test="orgGuid != null and orgGuid != ''">AND h.org_guid in (select guid from att_org_base where pguid = #{orgGuid})</if>
  220. <if test="hiddName != null and hiddName != ''">AND hidd_name like '%' || #{hiddName} || '%'</if>
  221. <if test="hiddGrad != null and hiddGrad != ''">AND hidd_grad = #{hiddGrad}</if>
  222. <if test="hiddStat != null and hiddStat != ''">AND hidd_stat = #{hiddStat}</if>
  223. <if test="wiunProp != null and wiunProp != ''">AND EXISTS (SELECT 1 FROM att_org_ext ext WHERE ext.org_guid = h.org_guid AND ext.wiun_prop = #{wiunProp})</if>
  224. </where>
  225. order by coll_time desc
  226. </select>
  227. <insert id="insertNextHidd" parameterType="com.goldenwater.slaj.hidd.domain.ObjHidd">
  228. insert into obj_hidd (guid, hidd_name, eng_guid, tend_guid, se_guid, org_guid, hidd_sour, hidd_grad, hidd_clas, if_found, pro_part, part_long, part_lat, otlcol_qiff_fnvu, insp_rec_guid, se_check_item_guid, hidd_stat, hidd_merg_guid, rec_org_guid, note, coll_time, upd_time, rec_pers, hidds_guid, occu_num, sins_sche_guid, group_guid, temp, to_date, dict_guid)
  229. values (#{guid}, #{hiddName}, #{engGuid}, #{tendGuid}, #{seGuid}, #{orgGuid}, #{hiddSour}, #{hiddGrad}, #{hiddClas}, #{ifFound}, #{proPart}, #{partLong}, #{partLat}, #{otlcolQiffFnvu}, #{inspRecGuid}, #{seCheckItemGuid}, #{hiddStat}, #{hiddMergGuid}, #{recOrgGuid}, #{note}, #{collTime}, #{updTime}, #{recPers}, #{hiddsGuid}, #{occuNum}, #{sinsScheGuid}, #{groupGuid}, #{temp}, #{toDate}, #{dictGuid})
  230. </insert>
  231. <!-- 工程隐患聚合查询:当前单位及下级单位范围(orgName 模糊筛选),按工程名称+管理单位分组 -->
  232. <select id="selectHiddGroupBy" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  233. WITH RECURSIVE subOrgs AS (
  234. SELECT guid, org_name FROM att_org_base WHERE guid = #{orgGuid}
  235. UNION ALL
  236. SELECT e.org_guid, o.org_name FROM att_org_ext e
  237. LEFT JOIN att_org_base o ON o.guid = e.org_guid
  238. WHERE e.admin_wiun_guid = #{orgGuid}
  239. UNION ALL
  240. SELECT b.guid, b.org_name FROM att_org_base b
  241. INNER JOIN subOrgs s ON b.pguid = s.guid
  242. )
  243. SELECT
  244. e.eng_name AS "engName",
  245. s.org_name AS "orgName",
  246. COUNT(h.guid) AS "totalCount",
  247. coalesce(sum(case when h.hidd_grad = '1' then 1 else 0 end), 0) AS "normalCount",
  248. coalesce(sum(case when h.hidd_grad = '2' then 1 else 0 end), 0) AS "majorCount",
  249. coalesce(sum(case when h.hidd_stat in ('2','3') then 1 else 0 end), 0) AS "solvedCount"
  250. FROM subOrgs s
  251. LEFT JOIN obj_hidd h ON h.org_guid = s.guid
  252. LEFT JOIN obj_eng e ON h.eng_guid = e.guid
  253. WHERE EXISTS (SELECT 1 FROM obj_hidd h1 WHERE h1.org_guid = s.guid)
  254. <if test="engName != null and engName != ''">AND e.eng_name LIKE '%' || #{engName} || '%'</if>
  255. <if test="orgName != null and orgName != ''">AND s.org_name LIKE '%' || #{orgName} || '%'</if>
  256. <if test="collTime != null and collTime != ''">AND h.coll_time >= CAST(#{collTime} AS timestamp) AND h.coll_time &lt; CAST(#{collTime} AS timestamp) + INTERVAL '1 day'</if>
  257. <if test="hiddClas != null and hiddClas != ''">AND h.hidd_clas = #{hiddClas}</if>
  258. GROUP BY e.eng_name
  259. ORDER BY "totalCount" DESC
  260. </select>
  261. <!-- 非工程隐患聚合查询:当前单位及下级单位范围(orgName 模糊筛选),按管理单位分组 -->
  262. <select id="selectHiddGroupByNonEng" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
  263. WITH RECURSIVE subOrgs AS (
  264. SELECT guid, org_name FROM att_org_base WHERE guid = #{orgGuid}
  265. UNION ALL
  266. SELECT e.org_guid, o.org_name FROM att_org_ext e
  267. LEFT JOIN att_org_base o ON o.guid = e.org_guid
  268. WHERE e.admin_wiun_guid = #{orgGuid}
  269. UNION ALL
  270. SELECT b.guid, b.org_name FROM att_org_base b
  271. INNER JOIN subOrgs s ON b.pguid = s.guid
  272. )
  273. SELECT
  274. s.org_name AS "orgName",
  275. COUNT(h.guid) AS "totalCount",
  276. coalesce(sum(case when h.hidd_grad = '1' then 1 else 0 end), 0) AS "normalCount",
  277. coalesce(sum(case when h.hidd_grad = '2' then 1 else 0 end), 0) AS "majorCount",
  278. coalesce(sum(case when h.hidd_stat in ('2','3') then 1 else 0 end), 0) AS "solvedCount"
  279. FROM subOrgs s
  280. LEFT JOIN obj_hidd h ON h.org_guid = s.guid
  281. WHERE EXISTS (SELECT 1 FROM obj_hidd h1 WHERE h1.org_guid = s.guid)
  282. <if test="orgName != null and orgName != ''">AND s.org_name LIKE '%' || #{orgName} || '%'</if>
  283. <if test="collTime != null and collTime != ''">AND h.coll_time >= CAST(#{collTime} AS timestamp) AND h.coll_time &lt; CAST(#{collTime} AS timestamp) + INTERVAL '1 day'</if>
  284. AND (h.hidd_clas = '2' OR h.hidd_clas IS NULL)
  285. GROUP BY s.org_name
  286. ORDER BY "totalCount" DESC
  287. </select>
  288. </mapper>