DeviceMapper.xml 5.8 KB

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