RescueInfoDao.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.inspur.idm.media.dao.RescueInfoDao">
  4. <sql id="data_auth">
  5. <choose>
  6. <when test="ccType == 'none'">
  7. and 1=2
  8. </when>
  9. <when test="ccType == 'estate'">
  10. <!-- 物业 estate -->
  11. and rescue_info.elevator_id in (select elevator_id from ele_info_usage where estate_company_id = #{ccId})
  12. </when>
  13. <when test="ccType == 'mainten'">
  14. <!-- 维保 mainten -->
  15. and rescue_info.elevator_id in (select elevator_id from ele_info_mainten where mainten_company_id = #{ccId})
  16. </when>
  17. <when test="ccType == 'insure'">
  18. <!-- 保险 insure -->
  19. and rescue_info.elevator_id in (select elevator_id from fault_insure_elevator where insure_id in (select insure_id from fault_insure where insure_company_id = #{ccId}))
  20. </when>
  21. <when test="ccType == 'quality'">
  22. <!-- 质监 quality 政府人员 -->
  23. and rescue_info.elevator_id in (select elevator_id from ele_info_basic where quality_company_id = #{ccId})
  24. </when>
  25. <when test="ccType == 'inspect'">
  26. <!-- 检验 inspect 电梯评估机构人员 -->
  27. and rescue_info.elevator_id in (select elevator_id from ele_info_basic where inspect_company_id = #{ccId})
  28. </when>
  29. <otherwise>
  30. <!--
  31. 安装 install install_company_id
  32. select elevator_id from ele_info_install where install_company_id = '';
  33. 验收单位 accept accept_company_id
  34. select elevator_id from ele_info_install where accept_company_id = '';
  35. 制造单位 manufact manufact_company_id
  36. select elevator_id from ele_info_manufact where manufact_company_id = '';
  37. -->
  38. </otherwise>
  39. </choose>
  40. </sql>
  41. <sql id="data_auth_by_user">
  42. <if test="limitUser != null">
  43. and rescue_info.elevator_id in (select elevator_id from pf_user_elevator where user_id = #{limitUser})
  44. </if>
  45. </sql>
  46. <select id="selectByQuery" parameterType="com.inspur.idm.media.vo.rescue.RescueInfoQuery" resultType="com.inspur.idm.media.vo.rescue.RescueInfoVO">
  47. select
  48. rescue_info.*,
  49. ele_info_basic.registration_code,ele_info_basic.elevator_name,ele_info_usage.estate_id,
  50. pf_auth_user.real_name rescueUserName,pf_auth_user.phone rescueUserPhone,
  51. ele_company.company_name rescueCompanyName
  52. from `rescue_info`
  53. left join ele_info_basic on rescue_info.elevator_id = ele_info_basic.elevator_id
  54. left join pf_auth_user on rescue_info.rescue_user = pf_auth_user.user_id
  55. left join ele_info_usage on rescue_info.elevator_id = ele_info_usage.elevator_id
  56. left join ele_company on rescue_info.rescue_company = ele_company.company_id
  57. <where>
  58. <if test="querySearch != null and querySearch != ''.toString()">
  59. and (ele_info_basic.elevator_name like concat('%',#{querySearch,jdbcType=VARCHAR},'%')
  60. or rescue_info.elevator_id like concat('%',#{querySearch,jdbcType=VARCHAR},'%')
  61. or rescue_info.rescue_id like concat('%',#{querySearch,jdbcType=VARCHAR},'%') )
  62. </if>
  63. <if test="elevatorId != null">
  64. and rescue_info.elevator_id = #{elevatorId,jdbcType=VARCHAR}
  65. </if>
  66. <if test="cityId != null">
  67. and ele_info_usage.city_id like concat(#{cityId,jdbcType=VARCHAR},'%')
  68. </if>
  69. <if test="estateId != null">
  70. and ele_info_usage.estate_id = #{estateId,jdbcType=VARCHAR}
  71. </if>
  72. <if test="elevatorId != null">
  73. and rescue_info.elevator_id = #{elevatorId}
  74. </if>
  75. <if test="estateIds != null and estateIds.length > 0">
  76. and ele_info_usage.estate_id in
  77. <foreach collection="estateIds" item="estateId" open="(" close=")" separator=",">
  78. #{estateId}
  79. </foreach>
  80. </if>
  81. <if test="rescueSource != null">
  82. and rescue_source = #{rescueSource,jdbcType=VARCHAR}
  83. </if>
  84. <if test="eventStatus != null">
  85. and event_status = #{eventStatus,jdbcType=INTEGER}
  86. </if>
  87. <if test="sendTimeStart != null">
  88. and date(send_time) >= #{sendTimeStart,jdbcType=VARCHAR}
  89. </if>
  90. <if test="sendTimeEnd != null">
  91. and date(send_time) &lt;= #{sendTimeEnd,jdbcType=VARCHAR}
  92. </if>
  93. <if test="catchTimeStart != null">
  94. and date(catch_time) >= #{catchTimeStart,jdbcType=VARCHAR}
  95. </if>
  96. <if test="catchTimeEnd != null">
  97. and date(catch_time) &lt;= #{catchTimeEnd,jdbcType=VARCHAR}
  98. </if>
  99. <if test="arrivalTimeStart != null">
  100. and date(arrival_time) >= #{arrivalTimeStart,jdbcType=VARCHAR}
  101. </if>
  102. <if test="arrivalTimeEnd != null">
  103. and date(arrival_time) &lt;= #{arrivalTimeEnd,jdbcType=VARCHAR}
  104. </if>
  105. <if test="getoutTimeStart != null">
  106. and date(getout_time) >= #{getoutTimeStart,jdbcType=VARCHAR}
  107. </if>
  108. <if test="getoutTimeEnd != null">
  109. and date(getout_time) &lt;= #{getoutTimeEnd,jdbcType=VARCHAR}
  110. </if>
  111. <if test="eventTimeStart != null">
  112. and date(event_time) >= #{eventTimeStart,jdbcType=VARCHAR}
  113. </if>
  114. <if test="eventTimeEnd != null">
  115. and date(event_time) &lt;= #{eventTimeEnd,jdbcType=VARCHAR}
  116. </if>
  117. <if test="eventEndTimeStart != null">
  118. and date(event_end_time) >= #{eventEndTimeStart,jdbcType=VARCHAR}
  119. </if>
  120. <if test="eventEndTimeEnd != null">
  121. and date(event_end_time) &lt;= #{eventEndTimeEnd,jdbcType=VARCHAR}
  122. </if>
  123. <if test="eventStatuses != null and eventStatuses.length > 0">
  124. and event_status in
  125. <foreach collection="eventStatuses" item="status" open="(" close=")" separator=",">
  126. #{status}
  127. </foreach>
  128. </if>
  129. <if test="arrivalTimeOut != null or outOfTrapTimeOut != null">
  130. and (
  131. <if test="arrivalTimeOut != null">
  132. (arrival_time is null and TIMESTAMPDIFF(MINUTE,event_time,sysdate()) >= #{arrivalTimeOut})
  133. or (arrival_time is not null and TIMESTAMPDIFF(MINUTE,event_time,arrival_time) >= #{arrivalTimeOut})
  134. </if>
  135. <if test="arrivalTimeOut != null and outOfTrapTimeOut != null">
  136. or
  137. </if>
  138. <if test="outOfTrapTimeOut != null">
  139. (getout_time is null and TIMESTAMPDIFF(MINUTE,event_time,sysdate()) >= #{outOfTrapTimeOut})
  140. or (getout_time is not null and TIMESTAMPDIFF(MINUTE,event_time,getout_time) >= #{outOfTrapTimeOut})
  141. </if>
  142. )
  143. </if>
  144. <include refid="data_auth_by_user"></include>
  145. </where>
  146. <choose>
  147. <when test="orderByClause == 'elevatorId'.toString()">
  148. order by rescue_info.elevator_id
  149. </when>
  150. <when test="orderByClause == 'elevatorName'.toString()">
  151. order by elevator_name
  152. </when>
  153. <when test="orderByClause == 'rerunTime'.toString()">
  154. order by rerun_time
  155. </when>
  156. <when test="orderByClause == 'eventTime'.toString()">
  157. order by event_time
  158. </when>
  159. <when test="orderByClause == 'arrivalTime'.toString()">
  160. order by arrival_time
  161. </when>
  162. <when test="orderByClause == 'getoutTime'.toString()">
  163. order by getout_time
  164. </when>
  165. <when test="orderByClause == 'elevatorIdDesc'.toString()">
  166. order by rescue_info.elevator_id desc
  167. </when>
  168. <when test="orderByClause == 'elevatorNameDesc'.toString()">
  169. order by elevator_name desc
  170. </when>
  171. <when test="orderByClause == 'rerunTimeDesc'.toString()">
  172. order by rerun_time desc
  173. </when>
  174. <when test="orderByClause == 'eventTimeDesc'.toString()">
  175. order by event_time desc
  176. </when>
  177. <when test="orderByClause == 'arrivalTimeDesc'.toString()">
  178. order by arrival_time desc
  179. </when>
  180. <when test="orderByClause == 'getoutTimeDesc'.toString()">
  181. order by getout_time desc
  182. </when>
  183. <otherwise>
  184. order by create_time desc
  185. </otherwise>
  186. </choose>
  187. <!-- <if test='orderByClause.contains("Desc")'> desc</if>-->
  188. <!-- ,rescue_id asc-->
  189. </select>
  190. <select id="selectMaxId" resultType="string">
  191. select rescue_id from `rescue_info`
  192. where rescue_id like concat(#{rescueId,jdbcType=VARCHAR},'%') order by LENGTH(rescue_id) desc,rescue_id desc limit 1
  193. </select>
  194. <select id="getTotalPersonNum" resultType="Integer">
  195. SELECT IFNULL(SUM(personal_num),0) FROM rescue_info
  196. <where>
  197. <if test="elevatorId != null">
  198. and elevator_id = #{elevatorId,jdbcType=VARCHAR}
  199. </if>
  200. <include refid="data_auth_by_user"></include>
  201. </where>
  202. </select>
  203. <select id="countByQuery" resultType="Integer">
  204. select count(0) from `rescue_info`
  205. <where>
  206. <if test="querySearch != null and querySearch != ''.toString()">
  207. and elevator_id = #{querySearch,jdbcType=VARCHAR}
  208. </if>
  209. <if test="eventStatus != null">
  210. and event_status = #{eventStatus,jdbcType=INTEGER}
  211. </if>
  212. <if test="arrivalTimeOut != null">
  213. and ((arrival_time is null and TIMESTAMPDIFF(MINUTE,event_time,sysdate()) >= #{arrivalTimeOut})
  214. or (arrival_time is not null and TIMESTAMPDIFF(MINUTE,event_time,arrival_time) >= #{arrivalTimeOut}))
  215. </if>
  216. <if test="outOfTrapTimeOut != null">
  217. and ((getout_time is null and TIMESTAMPDIFF(MINUTE,event_time,sysdate()) >= #{outOfTrapTimeOut})
  218. or (getout_time is not null and TIMESTAMPDIFF(MINUTE,event_time,getout_time) >= #{outOfTrapTimeOut}))
  219. </if>
  220. <if test="eventTimeStart != null">
  221. and date(event_time) = #{eventTimeStart,jdbcType=VARCHAR}
  222. </if>
  223. <include refid="data_auth_by_user"></include>
  224. </where>
  225. </select>
  226. <select id="getWaitRecordList" resultType="com.inspur.idm.media.vo.rescue.RescueInfoVO">
  227. select * from `rescue_info`
  228. <where>
  229. elevator_id = #{elevatorId,jdbcType=VARCHAR} and getout_time is not null and getout_time &lt; now() and video_path is null and getout_time > timestampadd(day, -1, now())
  230. and event_time > timestampadd(day, -1, now())
  231. <!-- 先查24h以内的,太久远的不处理 -->
  232. </where>
  233. order by getout_time
  234. </select>
  235. <update id="updateRescueVideo">
  236. update `rescue_info`
  237. <set>
  238. <if test="videoPath != null">
  239. `video_path` = #{videoPath,jdbcType=VARCHAR},
  240. </if>
  241. <if test="imgPath != null">
  242. `img_path` = #{imgPath,jdbcType=VARCHAR}
  243. </if>
  244. </set>
  245. <where>
  246. rescue_id = #{rescueId,jdbcType=VARCHAR}
  247. </where>
  248. </update>
  249. <update id="updateTrapVideo">
  250. update `rescue_info`
  251. <set>
  252. <if test="trapVideoPath != null">
  253. `trap_video_path` = #{trapVideoPath,jdbcType=VARCHAR},
  254. </if>
  255. <if test="imgPath != null">
  256. `img_path` = #{imgPath,jdbcType=VARCHAR}
  257. </if>
  258. </set>
  259. <where>
  260. rescue_id = #{rescueId,jdbcType=VARCHAR}
  261. </where>
  262. </update>
  263. <update id="updateFaultId">
  264. update `rescue_info`
  265. <set>
  266. `fault_id` = #{faultId,jdbcType=VARCHAR}
  267. </set>
  268. <where>
  269. rescue_id = #{rescueId,jdbcType=VARCHAR}
  270. </where>
  271. </update>
  272. <select id="getLastTrapStatus" resultType="java.lang.Integer">
  273. select IFNULL(event_status, 0) from `rescue_info`
  274. <where>
  275. `elevator_id` = #{elevatorId,jdbcType=VARCHAR} and `create_time` >= timestampadd(day, -1, now())
  276. </where>
  277. order by create_time desc limit 1
  278. </select>
  279. <select id="selectInfoById" resultType="com.inspur.idm.media.po.rescue.RescueInfo">
  280. select * from `rescue_info`
  281. <where>
  282. rescue_id = #{rescueId,jdbcType=VARCHAR}
  283. </where>
  284. <include refid="data_auth_by_user"></include>
  285. </select>
  286. </mapper>