IotSensorMapper.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. ( select s.id,ds.id as deviceStatusId, s.org_id, s.org_name,s.org_path, s.device_name, s.device_type, ds.info as info,s.device_code, ds.state_update_time as updateTime,ds.state
  6. from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
  7. where s.deleted=0
  8. <if test="request.orgId!= null">
  9. and s.org_id=#{request.orgId}
  10. </if>
  11. <if test="request.orgPath!= null">
  12. and s.org_path like CONCAT(#{request.orgPath}, '%')
  13. </if>
  14. <if test="request.deviceName != null and request.deviceName!= ''">
  15. and s.device_name like CONCAT('%',#{request.deviceName},'%')
  16. </if>
  17. <if test="request.state!= null">
  18. and ds.state = #{request.state}
  19. </if>
  20. <if test="request.startTime!= null">
  21. and ds.state_update_time >=#{request.startTime}
  22. </if>
  23. <if test="request.endTime!= null">
  24. and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
  25. </if>
  26. <if test="request.deviceTypeList!= null and request.deviceTypeList.size() > 0">
  27. and s.device_type in
  28. <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
  29. #{item}
  30. </foreach>
  31. </if>
  32. order by state_update_time desc )
  33. union all
  34. ( select s.id,ds.id as deviceStatusId, s.org_id, s.org_name,s.org_path, concat(s.defence_area_name,'(报警主机)') as device_name,
  35. s.sensor_type as device_type, ds.info as info,s.alarm_host_code as device_code, ds.state_update_time as updateTime,ds.state
  36. from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
  37. where s.deleted=0
  38. <if test="request.orgId!= null">
  39. and s.org_id=#{request.orgId}
  40. </if>
  41. <if test="request.orgPath!= null">
  42. and s.org_path like CONCAT(#{request.orgPath}, '%')
  43. </if>
  44. <if test="request.deviceName != null and request.deviceName!= ''">
  45. and s.defence_area_name like CONCAT('%',#{request.deviceName},'%')
  46. </if>
  47. <if test="request.state!= null">
  48. and ds.state = #{request.state}
  49. </if>
  50. <if test="request.startTime!= null">
  51. and ds.state_update_time >=#{request.startTime}
  52. </if>
  53. <if test="request.endTime!= null">
  54. and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
  55. </if>
  56. <if test="request.inputTypeList!= null and request.inputTypeList.size() > 0">
  57. and s.sensor_type in
  58. <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator="," close=")">
  59. #{item}
  60. </foreach>
  61. </if>
  62. order by ds.state_update_time desc )
  63. </select>
  64. <select id="selectAppPageData" resultType="com.xunmei.iot.vo.sensor.SensorAppPageVo">
  65. 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
  66. from iot_device_info s inner join iot_device_status ds on s.id=ds.device_id
  67. where s.deleted=0
  68. <if test="request.orgId!= null">
  69. and s.org_id=#{request.orgId}
  70. </if>
  71. <if test="request.orgPath!= null">
  72. and s.org_path like CONCAT(#{request.orgPath}, '%')
  73. </if>
  74. <if test="request.state!= null">
  75. and ds.state = #{request.state}
  76. </if>
  77. <if test="request.deviceType!= null and request.deviceType!= ''">
  78. and ds.device_type = #{request.deviceType}
  79. </if>
  80. <if test="request.defenceAreaType != null and request.defenceAreaType.size()>0">
  81. UNION ALL
  82. SELECT a.id,
  83. a.org_id,
  84. a.org_name,
  85. a.defence_area_name,
  86. a.sensor_type,
  87. a.state_text as info,
  88. a.state_update_time,
  89. if(a.state='alarm',1,0) as state
  90. FROM `iot_alarm_defence_area` a
  91. where a.deleted=0
  92. <if test="request.orgId!= null">
  93. and a.org_id=#{request.orgId}
  94. </if>
  95. <if test="request.orgPath!= null">
  96. and a.org_path like CONCAT(#{request.orgPath}, '%')
  97. </if>
  98. <if test="request.state!= null">
  99. and a.state = #{request.state}
  100. </if>
  101. and a.sensor_type in
  102. <foreach collection="request.defenceAreaType" index="index" item="item" open="(" separator="," close=")">
  103. #{item}
  104. </foreach>
  105. </if>
  106. </select>
  107. <select id="stateStatistic" resultType="com.xunmei.iot.vo.sensor.SensorAppStateVo">
  108. SELECT sum(state=0) as normal,
  109. sum(state=1) as alarm
  110. from iot_sensor s
  111. where s.deleted=0
  112. <if test="request.orgId!= null">
  113. and s.org_id=#{request.orgId}
  114. </if>
  115. <if test="request.orgPath!= null">
  116. and s.org_path like CONCAT(#{request.orgPath}, '%')
  117. </if>
  118. <!-- <if test="request.deviceType!= null and request.deviceType!= ''">-->
  119. <!-- and s.device_type = #{request.deviceType}-->
  120. <!-- </if>-->
  121. </select>
  122. <select id="selectSensorLogDataPage" resultType="com.xunmei.iot.vo.sensor.SensorPageVo">
  123. select s.id, org_id, org_name, device_name, infos as info,device_code,state_update_time as updateTime from
  124. iot_sensor_log s
  125. <where>
  126. <if test="request.orgId!= null">
  127. and s.org_id=#{request.orgId}
  128. </if>
  129. <if test="request.orgPath!= null">
  130. and s.org_path like CONCAT(#{request.orgPath}, '%')
  131. </if>
  132. <if test="request.deviceName != null and request.deviceName!= ''">
  133. and s.device_name like CONCAT('%',#{request.deviceName},'%')
  134. </if>
  135. <if test="request.deviceCode != null and request.deviceCode!= ''">
  136. and s.device_code =#{request.deviceCode}
  137. </if>
  138. <if test="request.startTime!= null">
  139. and s.state_update_time >=#{request.startTime}
  140. </if>
  141. <if test="request.endTime!= null">
  142. and s.state_update_time <![CDATA[<=]]> #{request.endTime}
  143. </if>
  144. </where>
  145. order by s.create_time desc
  146. </select>
  147. <select id="selectByIds" resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
  148. SELECT
  149. org_id,
  150. org_path,
  151. b.short_name as org_name,
  152. device_name as deviceName,
  153. infos AS info,
  154. CONCAT(org_id,'-',device_code) as deviceCode
  155. FROM
  156. iot_sensor a
  157. LEFT JOIN sys_org b ON a.org_id = b.id
  158. where a.deleted=0 and a.device_code in
  159. <foreach collection="deviceIds" index="index" item="item" open="(" separator="," close=")">
  160. #{item}
  161. </foreach>
  162. </select>
  163. <select id="selectListData" resultType="com.xunmei.iot.vo.sensor.SensorExportVo">
  164. select org_name, device_name, device_type, infos as info,update_time,state
  165. from iot_sensor s
  166. where s.deleted=0
  167. <if test="request.orgId!= null">
  168. and s.org_id=#{request.orgId}
  169. </if>
  170. <if test="request.orgPath!= null">
  171. and s.org_path like CONCAT(#{request.orgPath}, '%')
  172. </if>
  173. <if test="request.deviceName != null and request.deviceName!= ''">
  174. and s.device_name like CONCAT('%',#{request.deviceName},'%')
  175. </if>
  176. <if test="request.state!= null">
  177. and s.state = #{request.state}
  178. </if>
  179. <if test="request.deviceType!= null">
  180. and s.device_type = #{request.deviceType}
  181. </if>
  182. <if test="request.startTime!= null">
  183. and s.state_update_time >=#{request.startTime}
  184. </if>
  185. <if test="request.endTime!= null">
  186. and s.state_update_time <![CDATA[<=]]> #{request.endTime}
  187. </if>
  188. </select>
  189. <select id="selectListSensor" resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
  190. SELECT id,org_id,org_path,device_name,device_type,device_code,ifnull(a.state,0) as state
  191. FROM
  192. iot_sensor a
  193. where a.org_path like concat(#{orgPath},'%') and a.deleted=0
  194. </select>
  195. </mapper>