IotSensorMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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.xunmei.iot.mapper.IotCommonSensorMapper">
  4. <select id="selectPageData" resultType="com.xunmei.iot.vo.sensor.SensorPageVo">
  5. <choose>
  6. <when test=" request.deviceTypeList!= null and request.deviceTypeList.size() > 0 ">
  7. <choose>
  8. <when test=" request.inputTypeList!= null and request.inputTypeList.size() > 0">
  9. select c.* from
  10. ( select s.id,ds.id as device_status_id, s.org_id, s.org_name,s.org_path, s.device_name,
  11. s.device_type, ds.info as info,s.device_code, ds.state_update_time as update_time,ds.state
  12. from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
  13. where s.deleted=0 and s.device_type in
  14. <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
  15. #{item}
  16. </foreach>
  17. union all
  18. select s.id,ds.id as device_status_id, s.org_id, s.org_name,s.org_path, s.defence_area_name as device_name,
  19. s.sensor_type as device_type, ds.info as info,s.alarm_host_code as device_code,ds.state_update_time as update_time,ds.state
  20. from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
  21. where s.deleted=0 and s.sensor_type in
  22. <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator=","
  23. close=")">
  24. #{item}
  25. </foreach>) c where 1=1
  26. <if test="request.orgId!= null">
  27. and c.org_id=#{request.orgId}
  28. </if>
  29. <if test="request.orgPath!= null">
  30. and c.org_path like CONCAT(#{request.orgPath}, '%')
  31. </if>
  32. <if test="request.deviceName != null and request.deviceName!= ''">
  33. and c.device_name like CONCAT('%',#{request.deviceName},'%')
  34. </if>
  35. <if test="request.state!= null">
  36. and c.state = #{request.state}
  37. </if>
  38. <if test="request.startTime!= null">
  39. and c.update_time >=#{request.startTime}
  40. </if>
  41. <if test="request.endTime!= null">
  42. and c.update_time <![CDATA[<=]]> #{request.endTime}
  43. </if>
  44. order by c.update_time desc
  45. </when>
  46. <otherwise>
  47. select s.id,ds.id as device_status_id, s.org_id, s.org_name,s.org_path, s.device_name,
  48. s.device_type, ds.info as info,s.device_code, ds.state_update_time as update_time,ds.state
  49. from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
  50. where s.deleted=0 and s.device_type in
  51. <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
  52. #{item}
  53. </foreach>
  54. <if test="request.orgId!= null">
  55. and s.org_id=#{request.orgId}
  56. </if>
  57. <if test="request.orgPath!= null">
  58. and s.org_path like CONCAT(#{request.orgPath}, '%')
  59. </if>
  60. <if test="request.deviceName != null and request.deviceName!= ''">
  61. and s.device_name like CONCAT('%',#{request.deviceName},'%')
  62. </if>
  63. <if test="request.state!= null">
  64. and ds.state = #{request.state}
  65. </if>
  66. <if test="request.startTime!= null">
  67. and ds.state_update_time >=#{request.startTime}
  68. </if>
  69. <if test="request.endTime!= null">
  70. and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
  71. </if>
  72. order by ds.state_update_time desc
  73. </otherwise>
  74. </choose>
  75. </when>
  76. <otherwise>
  77. select s.id,ds.id as device_status_id, s.org_id, s.org_name,s.org_path, s.defence_area_name as device_name,
  78. s.sensor_type as device_type, ds.info as info,s.alarm_host_code as device_code, ds.state_update_time as update_time,ds.state
  79. from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
  80. where s.deleted=0 and s.sensor_type in
  81. <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator="," close=")">
  82. #{item}
  83. </foreach>
  84. <if test="request.orgId!= null">
  85. and s.org_id=#{request.orgId}
  86. </if>
  87. <if test="request.orgPath!= null">
  88. and s.org_path like CONCAT(#{request.orgPath}, '%')
  89. </if>
  90. <if test="request.deviceName != null and request.deviceName!= ''">
  91. and s.defence_area_name like CONCAT('%',#{request.deviceName},'%')
  92. </if>
  93. <if test="request.state!= null">
  94. and ds.state = #{request.state}
  95. </if>
  96. <if test="request.startTime!= null">
  97. and ds.state_update_time >=#{request.startTime}
  98. </if>
  99. <if test="request.endTime!= null">
  100. and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
  101. </if>
  102. order by ds.state_update_time desc
  103. </otherwise>
  104. </choose>
  105. </select>
  106. <select id="selectAppPageData" resultType="com.xunmei.iot.vo.sensor.SensorAppPageVo">
  107. select s.id, s.org_id, s.org_name, s.device_name, ds.device_type, ds.info as info, ds.state_update_time,ds.state
  108. from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
  109. where s.deleted=0
  110. <if test="request.orgId!= null">
  111. and s.org_id=#{request.orgId}
  112. </if>
  113. <if test="request.orgPath!= null">
  114. and s.org_path like CONCAT(#{request.orgPath}, '%')
  115. </if>
  116. <if test="request.state!= null">
  117. and ds.state = #{request.state}
  118. </if>
  119. <if test="request.deviceType!= null and request.deviceType!= ''">
  120. and s.device_product = #{request.deviceType}
  121. </if>
  122. <if test="request.defenceAreaType != null and request.defenceAreaType.size()>0">
  123. UNION ALL
  124. SELECT a.id,
  125. a.org_id,
  126. a.org_name,
  127. a.defence_area_name,
  128. a.sensor_type,
  129. a.state_text as info,
  130. a.state_update_time,
  131. if(a.state='alarm',1,0) as state
  132. FROM `iot_alarm_defence_area` a
  133. where a.deleted=0
  134. <if test="request.orgId!= null">
  135. and a.org_id=#{request.orgId}
  136. </if>
  137. <if test="request.orgPath!= null">
  138. and a.org_path like CONCAT(#{request.orgPath}, '%')
  139. </if>
  140. <if test="request.state!= null">
  141. and a.state = #{request.state}
  142. </if>
  143. and a.sensor_type in
  144. <foreach collection="request.defenceAreaType" index="index" item="item" open="(" separator="," close=")">
  145. #{item}
  146. </foreach>
  147. </if>
  148. </select>
  149. <select id="stateStatistic" resultType="com.xunmei.iot.vo.sensor.SensorAppStateVo">
  150. SELECT sum(state=0) as normal,
  151. sum(state=1) as alarm
  152. from iot_sensor s
  153. where s.deleted=0
  154. <if test="request.orgId!= null">
  155. and s.org_id=#{request.orgId}
  156. </if>
  157. <if test="request.orgPath!= null">
  158. and s.org_path like CONCAT(#{request.orgPath}, '%')
  159. </if>
  160. <!-- <if test="request.deviceType!= null and request.deviceType!= ''">-->
  161. <!-- and s.device_type = #{request.deviceType}-->
  162. <!-- </if>-->
  163. </select>
  164. <select id="selectSensorLogDataPage" resultType="com.xunmei.iot.vo.sensor.SensorPageVo">
  165. select s.id, org_id, org_name, device_name, infos as info,device_code,state_update_time as updateTime from
  166. iot_sensor_log s
  167. <where>
  168. <if test="request.orgId!= null">
  169. and s.org_id=#{request.orgId}
  170. </if>
  171. <if test="request.orgPath!= null">
  172. and s.org_path like CONCAT(#{request.orgPath}, '%')
  173. </if>
  174. <if test="request.deviceName != null and request.deviceName!= ''">
  175. and s.device_name like CONCAT('%',#{request.deviceName},'%')
  176. </if>
  177. <if test="request.deviceCode != null and request.deviceCode!= ''">
  178. and s.device_code =#{request.deviceCode}
  179. </if>
  180. <if test="request.startTime!= null">
  181. and s.state_update_time >=#{request.startTime}
  182. </if>
  183. <if test="request.endTime!= null">
  184. and s.state_update_time <![CDATA[<=]]> #{request.endTime}
  185. </if>
  186. </where>
  187. order by s.create_time desc
  188. </select>
  189. <select id="selectByIds" resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
  190. SELECT
  191. org_id,
  192. org_path,
  193. b.short_name as org_name,
  194. device_name as deviceName,
  195. infos AS info,
  196. CONCAT(org_id,'-',device_code) as deviceCode
  197. FROM
  198. iot_sensor a
  199. LEFT JOIN sys_org b ON a.org_id = b.id
  200. where a.deleted=0 and a.device_code in
  201. <foreach collection="deviceIds" index="index" item="item" open="(" separator="," close=")">
  202. #{item}
  203. </foreach>
  204. </select>
  205. <select id="selectListData" resultType="com.xunmei.iot.vo.sensor.SensorExportVo">
  206. <choose>
  207. <when test=" request.deviceTypeList!= null and request.deviceTypeList.size() > 0 ">
  208. <choose>
  209. <when test=" request.inputTypeList!= null and request.inputTypeList.size() > 0">
  210. select c.* from
  211. ( select s.org_id,s.org_path,s.org_name,s.device_name, s.device_type, ds.info as info,ds.state_update_time as update_time,ds.state
  212. from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
  213. where s.deleted=0 and s.device_type in
  214. <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
  215. #{item}
  216. </foreach>
  217. union all
  218. select s.org_id,s.org_path,s.org_name,s.defence_area_name as device_name,s.sensor_type as device_type, ds.info as info,ds.state_update_time as update_time,ds.state
  219. from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
  220. where s.deleted=0 and s.sensor_type in
  221. <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator="," close=")">
  222. #{item}
  223. </foreach> ) c where 1=1
  224. <if test="request.orgId!= null">
  225. and c.org_id=#{request.orgId}
  226. </if>
  227. <if test="request.orgPath!= null">
  228. and c.org_path like CONCAT(#{request.orgPath}, '%')
  229. </if>
  230. <if test="request.deviceName != null and request.deviceName!= ''">
  231. and c.device_name like CONCAT('%',#{request.deviceName},'%')
  232. </if>
  233. <if test="request.state!= null">
  234. and c.state = #{request.state}
  235. </if>
  236. <if test="request.startTime!= null">
  237. and c.update_time >=#{request.startTime}
  238. </if>
  239. <if test="request.endTime!= null">
  240. and c.update_time <![CDATA[<=]]> #{request.endTime}
  241. </if>
  242. order by c.update_time desc
  243. </when>
  244. <otherwise>
  245. select s.org_name,s.device_name, s.device_type, ds.info as info,ds.state_update_time as update_time,ds.state
  246. from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
  247. where s.deleted=0 and s.device_type in
  248. <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
  249. #{item}
  250. </foreach>
  251. <if test="request.orgId!= null">
  252. and s.org_id=#{request.orgId}
  253. </if>
  254. <if test="request.orgPath!= null">
  255. and s.org_path like CONCAT(#{request.orgPath}, '%')
  256. </if>
  257. <if test="request.deviceName != null and request.deviceName!= ''">
  258. and s.device_name like CONCAT('%',#{request.deviceName},'%')
  259. </if>
  260. <if test="request.state!= null">
  261. and ds.state = #{request.state}
  262. </if>
  263. <if test="request.startTime!= null">
  264. and ds.state_update_time >=#{request.startTime}
  265. </if>
  266. <if test="request.endTime!= null">
  267. and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
  268. </if>
  269. order by ds.state_update_time desc
  270. </otherwise>
  271. </choose>
  272. </when>
  273. <otherwise>
  274. select s.org_name,s.defence_area_name as device_name,
  275. s.sensor_type as device_type, ds.info as info,ds.state_update_time as update_time,ds.state
  276. from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
  277. where s.deleted=0 and s.sensor_type in
  278. <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator="," close=")">
  279. #{item}
  280. </foreach>
  281. <if test="request.orgId!= null">
  282. and s.org_id=#{request.orgId}
  283. </if>
  284. <if test="request.orgPath!= null">
  285. and s.org_path like CONCAT(#{request.orgPath}, '%')
  286. </if>
  287. <if test="request.deviceName != null and request.deviceName!= ''">
  288. and s.defence_area_name like CONCAT('%',#{request.deviceName},'%')
  289. </if>
  290. <if test="request.state!= null">
  291. and ds.state = #{request.state}
  292. </if>
  293. <if test="request.startTime!= null">
  294. and ds.state_update_time >=#{request.startTime}
  295. </if>
  296. <if test="request.endTime!= null">
  297. and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
  298. </if>
  299. order by ds.state_update_time desc
  300. </otherwise>
  301. </choose>
  302. </select>
  303. <select id="selectListSensor" resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
  304. SELECT id,org_id,org_path,device_name,device_type,device_code,ifnull(a.state,0) as state
  305. FROM
  306. iot_sensor a
  307. where a.org_path like concat(#{orgPath},'%') and a.deleted=0
  308. </select>
  309. </mapper>