DeviceMapper.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.bizmatics.persistence.mapper.DeviceMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.bizmatics.model.Device">
  6. <id column="id" property="id" />
  7. <result column="device_code" property="deviceCode" />
  8. <result column="device_name" property="deviceName" />
  9. <result column="site_id" property="siteId" />
  10. <result column="device_address" property="deviceAddress" />
  11. <result column="device_type" property="deviceType" />
  12. <result column="install_time" property="installTime" />
  13. <result column="creator" property="creator" />
  14. <result column="enable" property="enable" />
  15. </resultMap>
  16. <select id="selectCount" resultType="java.lang.Integer">
  17. select count(1)
  18. from user_site as us
  19. inner join device_status as ds
  20. on us.site_id = ds.site_id
  21. inner join device as d
  22. on ds.device_code = d.device_code
  23. <where>
  24. d.enable = 1
  25. <if test="userId != null and userId != 0">
  26. and us.user_id = #{userId}
  27. </if>
  28. <if test="siteId != null and siteId != 0">
  29. and us.site_id = #{siteId}
  30. </if>
  31. <if test="deviceStatus != null">
  32. and ds.device_status = #{deviceStatus}
  33. </if>
  34. <if test="startTime != null">
  35. and ds.status_time >= #{startTime}
  36. </if>
  37. <if test="endTime != null">
  38. and ds.status_time &lt;= #{endTime}
  39. </if>
  40. <if test="type != null">
  41. and d.device_type = #{type}
  42. </if>
  43. </where>
  44. </select>
  45. <select id="list" resultType="com.bizmatics.model.Device">
  46. select d.id,d.device_code,d.device_name,d.site_id,d.device_address,d.device_type,d.install_time,ds.device_status as deviceStatus,
  47. s.installed_capacity as installedCapacity
  48. from user_site as us
  49. inner join device_status as ds
  50. on us.site_id = ds.site_id
  51. inner join device as d
  52. on us.site_id = d.site_Id
  53. inner join site as s
  54. on s.id = us.site_id
  55. <where>
  56. <if test="userId != null and userId != 0">
  57. and us.user_id = #{userId}
  58. </if>
  59. <if test="siteId != null and siteId != 0">
  60. and us.site_id = #{siteId}
  61. </if>
  62. <if test="deviceStatus != null">
  63. and ds.device_status = #{deviceStatus}
  64. </if>
  65. <if test="startTime != null">
  66. and ds.status_time >= #{startTime}
  67. </if>
  68. <if test="endTime != null">
  69. and ds.status_time &lt;= #{endTime}
  70. </if>
  71. <if test="type != null">
  72. and d.device_type = #{type}
  73. </if>
  74. </where>
  75. </select>
  76. <select id="DeviceList" resultType="com.bizmatics.model.DeviceList">
  77. SELECT
  78. a.*, b.device_status
  79. FROM
  80. device AS a
  81. JOIN device_status AS b ON a.device_code = b.device_code
  82. <where>
  83. a.enable =1
  84. <if test="siteId != null and siteId != 0">
  85. and a.site_id = #{siteId}
  86. </if>
  87. </where>
  88. </select>
  89. <select id="CorrespondDeviceList" resultType="com.bizmatics.model.vo.CorrespondDeviceVO">
  90. SELECT
  91. a.id,
  92. a.device_code,
  93. a.device_name,
  94. a.device_address,
  95. a.install_time,
  96. b.device_status,
  97. b.status_time,
  98. a.site_id,
  99. c.site_name,
  100. if (b.device_status=1,timestampdiff(
  101. HOUR,
  102. b.status_time,
  103. now()
  104. ),null) as offlineDuration,
  105. if(b.device_status!=1,timestampdiff(
  106. HOUR,
  107. a.install_time,
  108. now()
  109. ),null) as onlineDuration,
  110. a.sim,a.floor,a.device_type
  111. FROM
  112. device AS a
  113. JOIN device_status AS b ON a.device_code = b.device_code
  114. JOIN site AS c ON a.site_id = c.id
  115. <where>
  116. a.enable =1
  117. and c.tenant_id=#{tenantId}
  118. <if test="deviceName != null and deviceName != ''">
  119. and a.device_name LIKE CONCAT(CONCAT('%', #{deviceName}), '%')
  120. </if>
  121. </where>
  122. order by a.id desc
  123. <if test="size != null and size != 0 and startCurrent != null">
  124. LIMIT #{startCurrent},#{size}
  125. </if>
  126. </select>
  127. <select id="deviceAnalogVariableList" resultType="com.bizmatics.model.DeviceAnalogVariableList">
  128. SELECT
  129. a.*
  130. FROM
  131. device_analog_variable_list AS a
  132. JOIN device_attribute AS b ON a.monitoring_equipment = b.id
  133. <where>
  134. a.status = 1
  135. AND b.status = 1
  136. AND a.data_area = 1
  137. AND a.monitoring_equipment != 0
  138. <if test="siteId != null and siteId != 0">
  139. AND b.site_id = #{siteId}
  140. </if>
  141. </where>
  142. </select>
  143. <select id="deviceBoxList" resultType="com.bizmatics.model.vo.DeviceOneVo">
  144. SELECT
  145. a.monitor_device_name as device_name, c.device_code
  146. FROM
  147. device_attribute AS a
  148. LEFT JOIN device_analog_variable_list AS b ON a.id = b.monitoring_equipment
  149. JOIN device AS c ON b.communication_equipment = c.id
  150. <where>
  151. a.status = 1
  152. AND b.status = 1
  153. AND c.enable = 1
  154. <if test="siteId != null and siteId != 0">
  155. AND a.site_id = #{siteId}
  156. </if>
  157. </where>
  158. GROUP BY
  159. a.id
  160. </select>
  161. </mapper>