ChecklistHazardRiskMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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.zhyc.xps.aqpt.mapper.ChecklistHazardRiskMapper">
  4. <resultMap id="RiskDtoResultMap" type="com.zhyc.xps.aqpt.dto.ChecklistHazardRiskDto">
  5. <result column="oc_id" property="ocId" jdbcType="BIGINT"/>
  6. <result column="checklist_id" property="checklistId" jdbcType="BIGINT"/>
  7. <result column="hazard_id" property="hazardId" jdbcType="BIGINT"/>
  8. <result column="risk_id" property="riskId" jdbcType="BIGINT"/>
  9. <result column="risk_code" property="riskCode" jdbcType="VARCHAR"/>
  10. <result column="risk_source" property="riskSource" jdbcType="VARCHAR"/>
  11. <result column="risk_reason" property="riskReason" jdbcType="VARCHAR"/>
  12. <result column="risk_consequence" property="riskConsequence" jdbcType="VARCHAR"/>
  13. <result column="risk_level" property="riskLevel" jdbcType="BIGINT"/>
  14. <result column="risk_type_id" property="riskTypeId" jdbcType="BIGINT"/>
  15. <result column="ctrl_level_id" property="ctrlLevelId" jdbcType="BIGINT"/>
  16. <result column="hazard_title" property="hazardTitle" jdbcType="VARCHAR"/>
  17. <result column="position_id_list" property="positionIdList" jdbcType="VARCHAR"/>
  18. <result column="position_name_list" property="positionNameList" jdbcType="VARCHAR"/>
  19. <result column="ctrl_level_title" property="ctrlLevelTitle" jdbcType="VARCHAR"/>
  20. </resultMap>
  21. <sql id="RiskDto_Cols">
  22. A.oc_id,
  23. A.checklist_id,
  24. A.hazard_id,
  25. B.hazard_title,
  26. A.risk_id,
  27. A.risk_code,
  28. A.risk_source,
  29. A.risk_reason,
  30. A.risk_consequence,
  31. A.risk_level,
  32. A.risk_type_id,
  33. A.ctrl_level_id,
  34. C.ctrl_level_title,
  35. E.position_id_list,
  36. E.position_name_list
  37. </sql>
  38. <!--根据ID获取信息-->
  39. <select id="getById" resultMap="RiskDtoResultMap">
  40. SELECT
  41. <include refid="RiskDto_Cols"/>
  42. FROM checklist_hazard_risk AS A
  43. LEFT JOIN checklist_hazard AS B ON ( A.oc_id = B.oc_id AND A.checklist_id = B.checklist_id AND A.hazard_id = B.hazard_id )
  44. LEFT JOIN ent_ctrl_level AS C ON ( A.oc_id = C.oc_id AND A.ctrl_level_id = C.ctrl_level_id )
  45. LEFT JOIN (
  46. SELECT
  47. GROUP_CONCAT( DISTINCT N.position_id ) AS position_id_list,
  48. GROUP_CONCAT( DISTINCT N.position_name ) AS position_name_list,
  49. M.oc_id,
  50. M.checklist_id,
  51. M.hazard_id,
  52. M.risk_id
  53. FROM checklist_hazard_risk_position AS M
  54. LEFT JOIN s_position AS N ON ( M.oc_id = N.oc_id AND M.position_id = N.position_id )
  55. WHERE 1 = 1
  56. <if test="ocId != null">
  57. AND M.oc_id = #{ocId ,jdbcType=BIGINT}
  58. </if>
  59. <if test="checklistId != null">
  60. AND M.checklist_id = #{checklistId ,jdbcType=BIGINT}
  61. </if>
  62. <if test="hazardId != null">
  63. AND M.hazard_id = #{hazardId ,jdbcType=BIGINT}
  64. </if>
  65. <if test="riskId != null">
  66. AND M.risk_id = #{riskId ,jdbcType=BIGINT}
  67. </if>
  68. GROUP BY
  69. M.oc_id,
  70. M.checklist_id,
  71. M.hazard_id,
  72. M.risk_id
  73. ) AS E ON ( A.oc_id = E.oc_id AND A.checklist_id = E.checklist_id AND A.hazard_id = E.hazard_id AND A.risk_id = E.risk_id )
  74. WHERE 1 = 1 AND A.deleted_flag = 0
  75. <if test="ocId != null">
  76. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  77. </if>
  78. <if test="checklistId != null">
  79. AND A.checklist_id = #{checklistId ,jdbcType=BIGINT}
  80. </if>
  81. <if test="hazardId != null">
  82. AND A.hazard_id = #{hazardId ,jdbcType=BIGINT}
  83. </if>
  84. <if test="riskId != null">
  85. AND A.risk_id = #{riskId ,jdbcType=BIGINT}
  86. </if>
  87. </select>
  88. <!--分页查询信息-->
  89. <select id="getByPage" parameterType="java.util.Map" resultMap="RiskDtoResultMap">
  90. SELECT
  91. <include refid="RiskDto_Cols"/>
  92. FROM checklist_hazard_risk AS A
  93. LEFT JOIN checklist_hazard AS B ON ( A.oc_id = B.oc_id AND A.checklist_id = B.checklist_id AND A.hazard_id = B.hazard_id )
  94. LEFT JOIN ent_ctrl_level AS C ON ( A.oc_id = C.oc_id AND A.ctrl_level_id = C.ctrl_level_id )
  95. LEFT JOIN (
  96. SELECT
  97. GROUP_CONCAT( DISTINCT N.position_name ) AS position_name_list,
  98. GROUP_CONCAT( DISTINCT N.position_id ) AS position_id_list,
  99. M.oc_id,
  100. M.checklist_id,
  101. M.hazard_id,
  102. M.risk_id
  103. FROM checklist_hazard_risk_position AS M
  104. LEFT JOIN s_position AS N ON ( M.oc_id = N.oc_id AND M.position_id = N.position_id )
  105. LEFT JOIN checklist_hazard AS K ON ( M.oc_id = K.oc_id AND M.checklist_id = K.checklist_id AND M.hazard_id = K.hazard_id)
  106. WHERE 1 = 1
  107. <if test="ocId != null">
  108. AND M.oc_id = #{ocId ,jdbcType=BIGINT}
  109. </if>
  110. <if test="checklistId != null">
  111. AND M.checklist_id = #{checklistId ,jdbcType=BIGINT}
  112. </if>
  113. <if test="nodeLeft != null and nodeRight != null">
  114. <![CDATA[
  115. AND K.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  116. AND K.node_right <= #{nodeRight ,jdbcType=BIGINT}
  117. ]]>
  118. </if>
  119. <if test="hazardId != null">
  120. AND M.hazard_id = #{hazardId ,jdbcType=BIGINT}
  121. </if>
  122. <if test="riskId != null">
  123. AND M.risk_id = #{riskId ,jdbcType=BIGINT}
  124. </if>
  125. GROUP BY
  126. M.oc_id,
  127. M.checklist_id,
  128. M.hazard_id,
  129. M.risk_id
  130. ) AS E ON ( A.oc_id = E.oc_id AND A.checklist_id = E.checklist_id AND A.hazard_id = E.hazard_id AND A.risk_id = E.risk_id )
  131. WHERE 1 = 1 AND A.deleted_flag = 0
  132. <if test="ocId != null">
  133. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  134. </if>
  135. <if test="checklistId != null">
  136. AND A.checklist_id = #{checklistId ,jdbcType=BIGINT}
  137. </if>
  138. <if test="hazardId != null">
  139. AND A.hazard_id = #{hazardId ,jdbcType=BIGINT}
  140. </if>
  141. <if test="nodeLeft != null and nodeRight != null">
  142. <![CDATA[
  143. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  144. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  145. ]]>
  146. </if>
  147. <if test="riskId != null">
  148. AND A.risk_id = #{riskId ,jdbcType=BIGINT}
  149. </if>
  150. <if test="riskLevel != null and riskLevel > 0">
  151. AND A.risk_level = #{riskLevel ,jdbcType=BIGINT}
  152. </if>
  153. <if test="keywords != null and keywords != ''">
  154. and A.risk_source like "%"#{keywords}"%"
  155. </if>
  156. ORDER BY A.risk_id ASC
  157. </select>
  158. <select id="getByList" parameterType="java.util.Map" resultMap="RiskDtoResultMap">
  159. SELECT
  160. <include refid="RiskDto_Cols"/>
  161. FROM checklist_hazard_risk AS A
  162. LEFT JOIN checklist_hazard AS B ON ( A.oc_id = B.oc_id AND A.checklist_id = B.checklist_id AND A.hazard_id = B.hazard_id )
  163. LEFT JOIN ent_ctrl_level AS C ON ( A.oc_id = C.oc_id AND A.ctrl_level_id = C.ctrl_level_id )
  164. LEFT JOIN (
  165. SELECT
  166. GROUP_CONCAT( DISTINCT N.position_name ) AS position_name_list,
  167. GROUP_CONCAT( DISTINCT N.position_id ) AS position_id_list,
  168. M.oc_id,
  169. M.checklist_id,
  170. M.hazard_id,
  171. M.risk_id
  172. FROM checklist_hazard_risk_position AS M
  173. LEFT JOIN s_position AS N ON ( M.oc_id = N.oc_id AND M.position_id = N.position_id )
  174. LEFT JOIN checklist_hazard AS K ON ( M.oc_id = K.oc_id AND M.checklist_id = K.checklist_id AND M.hazard_id = K.hazard_id)
  175. WHERE 1 = 1
  176. <if test="ocId != null">
  177. AND M.oc_id = #{ocId ,jdbcType=BIGINT}
  178. </if>
  179. <if test="checklistId != null">
  180. AND M.checklist_id = #{checklistId ,jdbcType=BIGINT}
  181. </if>
  182. <if test="nodeLeft != null and nodeRight != null">
  183. <![CDATA[
  184. AND K.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  185. AND K.node_right <= #{nodeRight ,jdbcType=BIGINT}
  186. ]]>
  187. </if>
  188. <if test="hazardId != null">
  189. AND M.hazard_id = #{hazardId ,jdbcType=BIGINT}
  190. </if>
  191. <if test="riskId != null">
  192. AND M.risk_id = #{riskId ,jdbcType=BIGINT}
  193. </if>
  194. GROUP BY
  195. M.oc_id,
  196. M.checklist_id,
  197. M.hazard_id,
  198. M.risk_id
  199. ) AS E ON ( A.oc_id = E.oc_id AND A.checklist_id = E.checklist_id AND A.hazard_id = E.hazard_id AND A.risk_id = E.risk_id )
  200. WHERE 1 = 1 AND A.deleted_flag = 0
  201. <if test="ocId != null">
  202. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  203. </if>
  204. <if test="checklistId != null">
  205. AND A.checklist_id = #{checklistId ,jdbcType=BIGINT}
  206. </if>
  207. <if test="hazardId != null">
  208. AND A.hazard_id = #{hazardId ,jdbcType=BIGINT}
  209. </if>
  210. <if test="nodeLeft != null and nodeRight != null">
  211. <![CDATA[
  212. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  213. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  214. ]]>
  215. </if>
  216. <if test="riskId != null">
  217. AND A.risk_id = #{riskId ,jdbcType=BIGINT}
  218. </if>
  219. <if test="ctrlLevelId != null">
  220. <![CDATA[
  221. AND A.ctrl_level_id <= #{ctrlLevelId ,jdbcType=BIGINT}
  222. ]]>
  223. </if>
  224. <if test="riskPointId != null">
  225. AND EXISTS (
  226. SELECT
  227. *
  228. FROM ent_risk_point_hazard AS R
  229. WHERE R.deleted_flag = 0
  230. AND A.oc_id = R.oc_id
  231. AND A.checklist_id = R.checklist_id
  232. AND A.hazard_id = R.hazard_id
  233. AND R.risk_point_id = #{riskPointId ,jdbcType=BIGINT}
  234. )
  235. </if>
  236. <if test="waitingTaskId != null">
  237. AND EXISTS (
  238. SELECT
  239. *
  240. FROM check_task_doing AS R
  241. WHERE 1 = 1
  242. AND A.oc_id = R.oc_id
  243. AND A.hazard_id = R.hazard_id
  244. AND R.task_id = #{waitingTaskId ,jdbcType=BIGINT}
  245. )
  246. </if>
  247. <if test="handledTaskId != null">
  248. AND EXISTS (
  249. SELECT
  250. *
  251. FROM check_record AS R
  252. WHERE 1 = 1
  253. AND A.oc_id = R.oc_id
  254. AND A.hazard_id = R.hazard_id
  255. AND R.task_id = #{handledTaskId ,jdbcType=BIGINT}
  256. )
  257. </if>
  258. <if test="riskLevel != null and riskLevel > 0">
  259. AND A.risk_level = #{riskLevel ,jdbcType=BIGINT}
  260. </if>
  261. <if test="keywords != null and keywords != ''">
  262. AND A.risk_source like "%"#{keywords}"%"
  263. </if>
  264. ORDER BY A.risk_id ASC
  265. </select>
  266. <insert id="create" parameterType="com.zhyc.xps.aqpt.entity.ChecklistHazardRisk">
  267. INSERT INTO checklist_hazard_risk
  268. <trim prefix="(" suffix=")" suffixOverrides=",">
  269. <if test="ocId != null">
  270. oc_id,
  271. </if>
  272. <if test="checklistId != null">
  273. checklist_id,
  274. </if>
  275. <if test="hazardId != null">
  276. hazard_id,
  277. </if>
  278. <if test="riskId != null">
  279. risk_id,
  280. </if>
  281. <if test="riskCode != null and riskCode != ''">
  282. risk_code,
  283. </if>
  284. <if test="riskSource != null and riskSource != ''">
  285. risk_source,
  286. </if>
  287. <if test="riskReason != null and riskReason != ''">
  288. risk_reason,
  289. </if>
  290. <if test="riskConsequence != null and riskConsequence != ''">
  291. risk_consequence,
  292. </if>
  293. <if test="riskLevel != null">
  294. risk_level,
  295. </if>
  296. <if test="riskTypeId != null">
  297. risk_type_id,
  298. </if>
  299. <if test="ctrlLevelId != null">
  300. ctrl_level_id,
  301. </if>
  302. <if test="createdBy != null">
  303. created_by,
  304. </if>
  305. <if test="createdAt != null">
  306. created_at,
  307. </if>
  308. </trim>
  309. <trim prefix="values (" suffix=")" suffixOverrides=",">
  310. <if test="ocId != null">
  311. #{ocId ,jdbcType=BIGINT},
  312. </if>
  313. <if test="checklistId != null">
  314. #{checklistId ,jdbcType=BIGINT},
  315. </if>
  316. <if test="hazardId != null">
  317. #{hazardId ,jdbcType=BIGINT},
  318. </if>
  319. <if test="riskId != null">
  320. #{riskId ,jdbcType=BIGINT},
  321. </if>
  322. <if test="riskCode != null and riskCode != ''">
  323. #{riskCode ,jdbcType=VARCHAR},
  324. </if>
  325. <if test="riskSource != null and riskSource != ''">
  326. #{riskSource ,jdbcType=VARCHAR},
  327. </if>
  328. <if test="riskReason != null and riskReason != ''">
  329. #{riskReason ,jdbcType=VARCHAR},
  330. </if>
  331. <if test="riskConsequence != null and riskConsequence != ''">
  332. #{riskConsequence ,jdbcType=VARCHAR},
  333. </if>
  334. <if test="riskLevel != null">
  335. #{riskLevel ,jdbcType=BIGINT},
  336. </if>
  337. <if test="riskTypeId != null">
  338. #{riskTypeId ,jdbcType=BIGINT},
  339. </if>
  340. <if test="ctrlLevelId != null">
  341. #{ctrlLevelId,jdbcType=BIGINT},
  342. </if>
  343. <if test="createdBy != null">
  344. #{createdBy ,jdbcType=BIGINT},
  345. </if>
  346. <if test="createdAt != null">
  347. #{createdAt ,jdbcType=TIMESTAMP},
  348. </if>
  349. </trim>
  350. </insert>
  351. <!--更新-->
  352. <update id="update" parameterType="com.zhyc.xps.aqpt.entity.ChecklistHazardRisk">
  353. UPDATE checklist_hazard_risk
  354. <trim suffixOverrides=",">
  355. <set>
  356. <if test="riskCode != null and riskCode != ''">
  357. risk_code = #{riskCode, jdbcType=VARCHAR},
  358. </if>
  359. <if test="riskSource != null and riskSource != ''">
  360. risk_source = #{riskSource, jdbcType=VARCHAR},
  361. </if>
  362. <if test="riskReason != null and riskReason != ''">
  363. risk_reason = #{riskReason, jdbcType=VARCHAR},
  364. </if>
  365. <if test="riskConsequence != null and riskConsequence != ''">
  366. risk_consequence = #{riskConsequence, jdbcType=VARCHAR},
  367. </if>
  368. <if test="riskLevel != null ">
  369. risk_level = #{riskLevel, jdbcType=BIGINT},
  370. </if>
  371. <if test="riskTypeId != null ">
  372. risk_type_id = #{riskTypeId, jdbcType=BIGINT},
  373. </if>
  374. <if test="ctrlLevelId != null">
  375. ctrl_level_id = #{ctrlLevelId,jdbcType=BIGINT},
  376. </if>
  377. <if test="updatedBy != null ">
  378. updated_by = #{updatedBy ,jdbcType=BIGINT},
  379. </if>
  380. <if test="updatedAt != null">
  381. updated_at = #{updatedAt ,jdbcType=TIMESTAMP},
  382. </if>
  383. </set>
  384. </trim>
  385. WHERE 1 = 1
  386. <if test="ocId != null">
  387. AND oc_id = #{ocId ,jdbcType=BIGINT}
  388. </if>
  389. <if test="checklistId != null">
  390. AND checklist_id = #{checklistId ,jdbcType=BIGINT}
  391. </if>
  392. <if test="hazardId != null">
  393. AND hazard_id = #{hazardId ,jdbcType=BIGINT}
  394. </if>
  395. <if test="riskId != null">
  396. AND risk_id = #{riskId ,jdbcType=BIGINT}
  397. </if>
  398. </update>
  399. <!--删除-->
  400. <update id="delete" parameterType="java.util.Map">
  401. UPDATE checklist_hazard_risk
  402. <trim suffixOverrides=",">
  403. <set>
  404. <if test="deletedFlag != null">
  405. deleted_flag = #{deletedFlag,jdbcType=BIGINT},
  406. </if>
  407. <if test="deletedTime != null">
  408. deleted_time = #{deletedTime,jdbcType=VARCHAR},
  409. </if>
  410. <if test="deletedBy != null">
  411. deleted_by = #{deletedBy,jdbcType=BIGINT},
  412. </if>
  413. </set>
  414. </trim>
  415. WHERE 1 = 1
  416. <if test="ocId != null">
  417. AND oc_id = #{ocId ,jdbcType=BIGINT}
  418. </if>
  419. <if test="checklistId != null">
  420. AND checklist_id = #{checklistId ,jdbcType=BIGINT}
  421. </if>
  422. <if test="hazardId != null">
  423. AND hazard_id = #{hazardId ,jdbcType=BIGINT}
  424. </if>
  425. <if test="riskId != null">
  426. AND risk_id = #{riskId ,jdbcType=BIGINT}
  427. </if>
  428. </update>
  429. <!--获取成员数目-->
  430. <select id="getMemberCountOfHazard" parameterType="java.util.Map" resultType="java.lang.Long">
  431. SELECT
  432. count(*)
  433. FROM checklist_hazard_risk AS A
  434. LEFT JOIN checklist_hazard AS B ON ( A.hazard_id = B.hazard_id)
  435. WHERE 1 = 1 AND A.deleted_flag = 0
  436. <if test="ocId != null">
  437. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  438. </if>
  439. <if test="checklistId != null">
  440. AND A.checklist_id = #{checklistId ,jdbcType=BIGINT}
  441. </if>
  442. <if test="hazardId != null ">
  443. AND A.hazard_id = #{hazardId ,jdbcType=BIGINT}
  444. </if>
  445. </select>
  446. </mapper>