EntRiskPointMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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.EntRiskPointMapper">
  4. <resultMap id="RiskPointDtoResultMap" type="com.zhyc.xps.aqpt.dto.EntRiskPointDto">
  5. <result column="oc_id" property="ocId" jdbcType="BIGINT" />
  6. <result column="group_id" property="groupId" jdbcType="BIGINT" />
  7. <result column="risk_point_id" property="riskPointId" jdbcType="BIGINT" />
  8. <result column="risk_point_title" property="riskPointTitle" jdbcType="VARCHAR" />
  9. <result column="risk_point_code" property="riskPointCode" jdbcType="VARCHAR" />
  10. <result column="risk_point_addr" property="riskPointAddr" jdbcType="VARCHAR" />
  11. <result column="risk_point_desc" property="riskPointDesc" jdbcType="VARCHAR" />
  12. <result column="risk_point_logo" property="riskPointLogo" jdbcType="VARCHAR" />
  13. <result column="risk_point_photo" property="riskPointPhoto" jdbcType="VARCHAR" />
  14. <result column="risk_point_level" property="riskPointLevel" jdbcType="BIGINT" />
  15. <result column="risk_point_cat_id" property="riskPointCatId" jdbcType="BIGINT" />
  16. <result column="is_major_hazard" property="isMajorHazard" jdbcType="BIGINT" />
  17. <result column="is_active" property="isActive" jdbcType="BIGINT" />
  18. <result column="active_start_time" property="activeStartTime" jdbcType="TIMESTAMP"/>
  19. <result column="active_end_time" property="activeEndTime" jdbcType="TIMESTAMP"/>
  20. <result column="status" property="status" jdbcType="BIGINT" />
  21. <result column="alert_num" property="alertNum" jdbcType="BIGINT" />
  22. <result column="danger_num" property="dangerNum" jdbcType="BIGINT" />
  23. <result column="checklist_num" property="checklistNum" jdbcType="BIGINT" />
  24. <result column="group_name" property="groupName" jdbcType="VARCHAR" />
  25. <result column="risk_point_cat_title" property="riskPointCatTitle" jdbcType="VARCHAR" />
  26. <result column="grid_id" property="gridId" jdbcType="BIGINT" />
  27. <result column="grid_title" property="gridTitle" jdbcType="VARCHAR" />
  28. </resultMap>
  29. <sql id="RiskPointDto_Cols">
  30. A.oc_id,
  31. A.group_id,
  32. B.group_name,
  33. A.risk_point_id,
  34. A.risk_point_title,
  35. A.risk_point_code,
  36. A.risk_point_addr,
  37. A.risk_point_desc,
  38. A.risk_point_logo,
  39. A.risk_point_photo,
  40. A.risk_point_level,
  41. A.risk_point_cat_id,
  42. C.risk_point_Cat_title,
  43. A.is_major_hazard,
  44. A.is_active,
  45. A.active_start_time,
  46. A.active_end_time,
  47. A.status,
  48. A.grid_id,
  49. D.grid_title,
  50. E.alert_num,
  51. F.danger_num,
  52. IFNULL(G.checklist_num, 0) AS checklist_num
  53. </sql>
  54. <!--根据ID获取信息-->
  55. <select id="getById" resultMap="RiskPointDtoResultMap">
  56. SELECT
  57. <include refid="RiskPointDto_Cols"/>
  58. FROM ent_risk_point AS A
  59. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
  60. LEFT JOIN ent_risk_point_cat AS C ON (A.oc_id = C.oc_id AND A.risk_point_cat_id = C.risk_point_cat_id)
  61. LEFT JOIN ent_grid AS D ON (A.oc_id = D.oc_id AND A.grid_id = D.grid_id)
  62. LEFT JOIN (
  63. SELECT oc_id,
  64. risk_point_id,
  65. COUNT(alert_id) AS alert_num
  66. FROM alert
  67. WHERE status = 0 AND oc_id = #{ocId, jdbcType=BIGINT}
  68. GROUP BY risk_point_id
  69. ) AS E ON (A.oc_id = E.oc_id AND A.risk_point_id = E.risk_point_id)
  70. LEFT JOIN (
  71. SELECT oc_id,
  72. risk_point_id,
  73. COUNT(danger_id) AS danger_num
  74. FROM ent_danger
  75. WHERE status = 0 AND oc_id = #{ocId, jdbcType=BIGINT}
  76. ) AS F ON (A.oc_id = F.oc_id AND A.risk_point_id = F.risk_point_id)
  77. LEFT JOIN (
  78. SELECT oc_id,
  79. target_id,
  80. count(*) AS checklist_num
  81. FROM checklist_target
  82. WHERE oc_id = #{ocId ,jdbcType=BIGINT} AND target_type = 2
  83. GROUP BY target_id
  84. ) AS G ON (A.oc_id = G.oc_id AND A.risk_point_id = G.target_id)
  85. WHERE A.deleted_flag = 0
  86. AND A.oc_id = #{ocId, jdbcType=BIGINT}
  87. AND A.risk_point_id = #{riskPointId, jdbcType=BIGINT}
  88. </select>
  89. <!--根据ID获取信息-->
  90. <select id="getByCode" resultMap="RiskPointDtoResultMap">
  91. SELECT
  92. <include refid="RiskPointDto_Cols"/>
  93. FROM ent_risk_point AS A
  94. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
  95. LEFT JOIN ent_risk_point_cat AS C ON (A.oc_id = C.oc_id AND A.risk_point_cat_id = C.risk_point_cat_id)
  96. LEFT JOIN ent_grid AS D ON (A.oc_id = D.oc_id AND A.grid_id = D.grid_id)
  97. LEFT JOIN (
  98. SELECT oc_id,
  99. risk_point_id,
  100. COUNT(alert_id) AS alert_num
  101. FROM alert
  102. WHERE status = 0 AND oc_id = #{ocId, jdbcType=BIGINT}
  103. GROUP BY risk_point_id
  104. ) AS E ON (A.oc_id = E.oc_id AND A.risk_point_id = E.risk_point_id)
  105. LEFT JOIN (
  106. SELECT oc_id,
  107. risk_point_id,
  108. COUNT(danger_id) AS danger_num
  109. FROM ent_danger
  110. WHERE status = 0 AND oc_id = #{ocId, jdbcType=BIGINT}
  111. ) AS F ON (A.oc_id = F.oc_id AND A.risk_point_id = F.risk_point_id)
  112. LEFT JOIN (
  113. SELECT oc_id,
  114. target_id,
  115. count(*) AS checklist_num
  116. FROM checklist_target
  117. WHERE oc_id = #{ocId ,jdbcType=BIGINT} AND target_type = 2
  118. GROUP BY target_id
  119. ) AS G ON (A.oc_id = G.oc_id AND A.risk_point_id = G.target_id)
  120. WHERE A.deleted_flag = 0
  121. AND A.oc_id = #{ocId, jdbcType=BIGINT}
  122. AND A.risk_point_code = #{riskPointCode, jdbcType=VARCHAR}
  123. </select>
  124. <!--分页查询信息-->
  125. <select id="getByPage" parameterType="java.util.Map" resultMap="RiskPointDtoResultMap">
  126. SELECT
  127. <include refid="RiskPointDto_Cols"/>
  128. FROM ent_risk_point AS A
  129. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
  130. LEFT JOIN ent_risk_point_cat AS C ON (A.oc_id = C.oc_id AND A.risk_point_cat_id = C.risk_point_cat_id)
  131. LEFT JOIN ent_grid AS D ON (A.oc_id = D.oc_id AND A.grid_id = D.grid_id)
  132. LEFT JOIN (
  133. SELECT oc_id,
  134. risk_point_id,
  135. COUNT(alert_id) AS alert_num
  136. FROM alert
  137. WHERE status = 0 AND oc_id = #{ocId, jdbcType=BIGINT}
  138. GROUP BY risk_point_id
  139. ) AS E ON (A.oc_id = E.oc_id AND A.risk_point_id = E.risk_point_id)
  140. LEFT JOIN (
  141. SELECT oc_id,
  142. risk_point_id,
  143. COUNT(danger_id) AS danger_num
  144. FROM ent_danger
  145. WHERE status = 0 AND oc_id = #{ocId, jdbcType=BIGINT}
  146. ) AS F ON (A.oc_id = F.oc_id AND A.risk_point_id = F.risk_point_id)
  147. LEFT JOIN (
  148. SELECT oc_id,
  149. target_id,
  150. count(*) AS checklist_num
  151. FROM checklist_target
  152. WHERE oc_id = #{ocId ,jdbcType=BIGINT} AND target_type = 2
  153. GROUP BY target_id
  154. ) AS G ON (A.oc_id = G.oc_id AND A.risk_point_id = G.target_id)
  155. WHERE 1 = 1 AND A.deleted_flag = 0
  156. <if test="ocId != null">
  157. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  158. </if>
  159. <if test="groupId != null and groupId !=''">
  160. AND A.group_id = #{groupId ,jdbcType=BIGINT}
  161. </if>
  162. <if test="riskPointLevel != null and riskPointLevel > 0">
  163. AND A.risk_point_level = #{riskPointLevel ,jdbcType=BIGINT}
  164. </if>
  165. <if test="nodeLeft != null and nodeRight != null">
  166. <![CDATA[
  167. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  168. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  169. ]]>
  170. </if>
  171. <if test="riskPointId != null">
  172. AND A.risk_point_id = #{riskPointId ,jdbcType=BIGINT}
  173. </if>
  174. <if test="keywords != null and keywords !=''">
  175. AND A.risk_point_title LIKE "%"#{keywords, jdbcType=VARCHAR}"%"
  176. OR A.risk_point_addr LIKE "%"#{keywords, jdbcType=VARCHAR}"%"
  177. </if>
  178. ORDER BY A.created_at desc
  179. </select>
  180. <select id="getByList" parameterType="java.util.Map" resultMap="RiskPointDtoResultMap">
  181. SELECT
  182. <include refid="RiskPointDto_Cols"/>
  183. FROM ent_risk_point AS A
  184. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
  185. LEFT JOIN ent_risk_point_cat AS C ON (A.oc_id = C.oc_id AND A.risk_point_cat_id = C.risk_point_cat_id)
  186. LEFT JOIN ent_grid AS D ON (A.oc_id = D.oc_id AND A.grid_id = D.grid_id)
  187. LEFT JOIN (
  188. SELECT oc_id,
  189. risk_point_id,
  190. COUNT(alert_id) AS alert_num
  191. FROM alert
  192. WHERE status = 0 AND oc_id = #{ocId, jdbcType=BIGINT}
  193. GROUP BY risk_point_id
  194. ) AS E ON (A.oc_id = E.oc_id AND A.risk_point_id = E.risk_point_id)
  195. LEFT JOIN (
  196. SELECT oc_id,
  197. risk_point_id,
  198. COUNT(danger_id) AS danger_num
  199. FROM ent_danger
  200. WHERE status = 0 AND oc_id = #{ocId, jdbcType=BIGINT}
  201. ) AS F ON (A.oc_id = F.oc_id AND A.risk_point_id = F.risk_point_id)
  202. LEFT JOIN (
  203. SELECT oc_id,
  204. target_id,
  205. count(*) AS checklist_num
  206. FROM checklist_target
  207. WHERE oc_id = #{ocId ,jdbcType=BIGINT} AND target_type = 2
  208. GROUP BY target_id
  209. ) AS G ON (A.oc_id = G.oc_id AND A.risk_point_id = G.target_id)
  210. WHERE 1 = 1 AND A.deleted_flag = 0
  211. <if test="ocId != null">
  212. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  213. </if>
  214. <if test="groupId != null">
  215. AND A.group_id = #{groupId ,jdbcType=BIGINT}
  216. </if>
  217. <if test="isActive != null">
  218. AND A.is_active = #{isActive ,jdbcType=BIGINT}
  219. </if>
  220. <if test="riskPointLevel != null and riskPointLevel > 0">
  221. AND A.risk_point_level = #{riskPointLevel ,jdbcType=BIGINT}
  222. </if>
  223. <if test="riskPointId != null">
  224. AND A.risk_point_id = #{riskPointId ,jdbcType=BIGINT}
  225. </if>
  226. <if test="nodeLeft != null and nodeRight != null">
  227. <![CDATA[
  228. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  229. AND B.node_right <= #{nodeRight ,jdbcType=BIGINT}
  230. ]]>
  231. </if>
  232. ORDER BY A.risk_point_id ASC
  233. </select>
  234. <insert id="create" parameterType="com.zhyc.xps.aqpt.entity.EntRiskPoint">
  235. INSERT INTO ent_risk_point
  236. <trim prefix="(" suffix=")" suffixOverrides=",">
  237. <if test="ocId != null">
  238. oc_id,
  239. </if>
  240. <if test="groupId != null">
  241. group_id,
  242. </if>
  243. <if test="riskPointId != null">
  244. risk_point_id,
  245. </if>
  246. <if test="riskPointTitle != null and riskPointTitle != ''">
  247. risk_point_title,
  248. </if>
  249. <if test="riskPointCode != null and riskPointCode != ''">
  250. risk_point_code,
  251. </if>
  252. <if test="riskPointAddr != null and riskPointAddr != ''">
  253. risk_point_addr,
  254. </if>
  255. <if test="riskPointDesc != null and riskPointDesc != ''">
  256. risk_point_desc,
  257. </if>
  258. <if test="riskPointLogo != null and riskPointLogo != ''">
  259. risk_point_logo,
  260. </if>
  261. <if test="riskPointPhoto != null and riskPointPhoto != ''">
  262. risk_point_photo,
  263. </if>
  264. <if test="riskPointLevel != null">
  265. risk_point_level,
  266. </if>
  267. <if test="riskPointCatId != null">
  268. risk_point_cat_id,
  269. </if>
  270. <if test="isMajorHazard != null">
  271. is_major_hazard,
  272. </if>
  273. <if test="isActive != null">
  274. is_active,
  275. </if>
  276. <if test="activeStartTime != null">
  277. active_start_time,
  278. </if>
  279. <if test="activeEndTime != null">
  280. active_end_time,
  281. </if>
  282. <if test="status != null">
  283. status,
  284. </if>
  285. <if test="gridId != null">
  286. grid_id,
  287. </if>
  288. <if test="createdBy != null">
  289. created_by,
  290. </if>
  291. <if test="createdAt != null">
  292. created_at,
  293. </if>
  294. </trim>
  295. <trim prefix="values (" suffix=")" suffixOverrides=",">
  296. <if test="ocId != null">
  297. #{ocId ,jdbcType=BIGINT},
  298. </if>
  299. <if test="groupId != null">
  300. #{groupId ,jdbcType=BIGINT},
  301. </if>
  302. <if test="riskPointId != null">
  303. #{riskPointId ,jdbcType=BIGINT},
  304. </if>
  305. <if test="riskPointTitle != null and riskPointTitle != ''">
  306. #{riskPointTitle ,jdbcType=VARCHAR},
  307. </if>
  308. <if test="riskPointCode != null and riskPointCode != ''">
  309. #{riskPointCode ,jdbcType=VARCHAR},
  310. </if>
  311. <if test="riskPointAddr != null and riskPointAddr != ''">
  312. #{riskPointAddr ,jdbcType=VARCHAR},
  313. </if>
  314. <if test="riskPointDesc != null and riskPointDesc != ''">
  315. #{riskPointDesc ,jdbcType=VARCHAR},
  316. </if>
  317. <if test="riskPointLogo != null and riskPointLogo != ''">
  318. #{riskPointLogo ,jdbcType=VARCHAR},
  319. </if>
  320. <if test="riskPointPhoto != null and riskPointPhoto != ''">
  321. #{riskPointPhoto ,jdbcType=VARCHAR},
  322. </if>
  323. <if test="riskPointLevel != null">
  324. #{riskPointLevel ,jdbcType=BIGINT},
  325. </if>
  326. <if test="riskPointCatId != null">
  327. #{riskPointCatId ,jdbcType=BIGINT},
  328. </if>
  329. <if test="isMajorHazard != null">
  330. #{isMajorHazard ,jdbcType=BIGINT},
  331. </if>
  332. <if test="isActive != null">
  333. #{isActive ,jdbcType=BIGINT},
  334. </if>
  335. <if test="activeStartTime != null">
  336. #{activeStartTime ,jdbcType=TIMESTAMP},
  337. </if>
  338. <if test="activeEndTime != null">
  339. #{activeEndTime ,jdbcType=TIMESTAMP},
  340. </if>
  341. <if test="status != null">
  342. #{status ,jdbcType=BIGINT},
  343. </if>
  344. <if test="gridId != null">
  345. #{gridId ,jdbcType=BIGINT},
  346. </if>
  347. <if test="createdBy != null">
  348. #{createdBy ,jdbcType=BIGINT},
  349. </if>
  350. <if test="createdAt != null">
  351. #{createdAt ,jdbcType=TIMESTAMP},
  352. </if>
  353. </trim>
  354. </insert>
  355. <!--更新-->
  356. <update id="update" parameterType="com.zhyc.xps.aqpt.entity.EntRiskPoint">
  357. UPDATE ent_risk_point
  358. <trim suffixOverrides=",">
  359. <set>
  360. <if test="riskPointTitle != null and riskPointTitle != ''">
  361. risk_point_title = #{riskPointTitle ,jdbcType=VARCHAR},
  362. </if>
  363. <if test="riskPointCode != null and riskPointCode != ''">
  364. risk_point_code = #{riskPointCode, jdbcType=VARCHAR},
  365. </if>
  366. <if test="riskPointAddr != null and riskPointAddr != ''">
  367. risk_point_addr = #{riskPointAddr, jdbcType=VARCHAR},
  368. </if>
  369. <if test="riskPointDesc != null and riskPointDesc != ''">
  370. risk_point_desc = #{riskPointDesc, jdbcType=VARCHAR},
  371. </if>
  372. <if test="riskPointLogo != null and riskPointLogo != ''">
  373. risk_point_logo = #{riskPointLogo, jdbcType=VARCHAR},
  374. </if>
  375. <if test="riskPointPhoto != null and riskPointPhoto != ''">
  376. risk_point_photo = #{riskPointPhoto ,jdbcType=VARCHAR},
  377. </if>
  378. <if test="riskPointLevel != null ">
  379. risk_point_level = #{riskPointLevel, jdbcType=BIGINT},
  380. </if>
  381. <if test="groupId != null ">
  382. group_id = #{groupId, jdbcType=BIGINT},
  383. </if>
  384. <if test="riskPointCatId != null ">
  385. risk_point_cat_id = #{riskPointCatId, jdbcType=BIGINT},
  386. </if>
  387. <if test="isMajorHazard != null">
  388. is_major_hazard = #{isMajorHazard ,jdbcType=BIGINT},
  389. </if>
  390. <if test="isActive != null">
  391. is_active= #{isActive ,jdbcType=BIGINT},
  392. </if>
  393. <if test="activeStartTime != null">
  394. active_start_time = #{activeStartTime ,jdbcType=TIMESTAMP},
  395. </if>
  396. <if test="activeEndTime != null">
  397. active_end_time = #{activeEndTime ,jdbcType=TIMESTAMP},
  398. </if>
  399. <if test="status != null">
  400. status = #{status ,jdbcType=BIGINT},
  401. </if>
  402. <if test="gridId != null">
  403. grid_id = #{gridId ,jdbcType=BIGINT},
  404. </if>
  405. <if test="updatedBy != null ">
  406. updated_by = #{updatedBy ,jdbcType=BIGINT},
  407. </if>
  408. <if test="updatedAt != null">
  409. updated_at = #{updatedAt ,jdbcType=TIMESTAMP},
  410. </if>
  411. </set>
  412. </trim>
  413. WHERE 1 = 1
  414. <if test="ocId != null">
  415. AND oc_id = #{ocId ,jdbcType=BIGINT}
  416. </if>
  417. <if test="riskPointId != null">
  418. AND risk_point_id = #{riskPointId ,jdbcType=BIGINT}
  419. </if>
  420. </update>
  421. <!--删除-->
  422. <update id="delete" parameterType="java.util.Map">
  423. UPDATE ent_risk_point
  424. <trim suffixOverrides=",">
  425. <set>
  426. <if test="deletedFlag != null">
  427. deleted_flag = #{deletedFlag,jdbcType=BIGINT},
  428. </if>
  429. <if test="deletedAt != null">
  430. deleted_at = #{deletedAt,jdbcType=VARCHAR},
  431. </if>
  432. <if test="deletedBy != null">
  433. deleted_by = #{deletedBy,jdbcType=BIGINT},
  434. </if>
  435. </set>
  436. </trim>
  437. WHERE 1 = 1
  438. <if test="ocId != null">
  439. AND oc_id = #{ocId ,jdbcType=BIGINT}
  440. </if>
  441. <if test="riskPointId != null">
  442. AND risk_point_id = #{riskPointId ,jdbcType=BIGINT}
  443. </if>
  444. </update>
  445. <!-- 根据条件统计风险点数据 -->
  446. <select id="getRiskPointStaticsData" resultType="java.util.Map" parameterType="java.util.Map">
  447. SELECT count(0) AS "total",
  448. SUM(IF ( A.risk_point_level = 1, 1, 0 )) AS "one",
  449. SUM(IF ( A.risk_point_level = 1 AND A.STATUS = 2, 1, 0 )) AS "wone",
  450. SUM(IF ( A.risk_point_level = 2, 1, 0 )) AS "two",
  451. SUM(IF ( A.risk_point_level = 2 AND A.STATUS = 2, 1, 0 )) AS "wtwo",
  452. SUM(IF ( A.risk_point_level = 3, 1, 0 )) AS "three",
  453. SUM(IF ( A.risk_point_level = 3 AND A.STATUS = 2, 1, 0 )) AS "wthree",
  454. SUM(IF ( A.risk_point_level = 4, 1, 0 )) AS "four" ,
  455. SUM(IF ( A.risk_point_level = 4 AND A.STATUS = 2, 1, 0 )) AS "wfour"
  456. FROM ent_risk_point AS A
  457. WHERE IF( A.is_active = 1,
  458. (
  459. A.active_end_time > NOW()
  460. OR A.active_end_time IS NULL
  461. ),
  462. '1=1'
  463. )
  464. AND A.deleted_flag = 0
  465. <if test="ocId != null">
  466. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  467. </if>
  468. </select>
  469. </mapper>