DeviceMapper.xml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 us.site_id = d.site_Id
  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. c.loop_meter_address,
  79. c.rated_voltage,
  80. c.rated_current,
  81. c.current_load_rate,
  82. c.monitoring_equipment_no,
  83. c.variable_list_id,
  84. c.quality_analysis
  85. FROM
  86. device AS a
  87. JOIN device_status AS b ON a.device_code = b.device_code
  88. LEFT JOIN device_attribute AS c ON a.id = c.device_id
  89. <where>
  90. a.enable =1
  91. <if test="siteId != null and siteId != 0">
  92. and a.site_id = #{siteId}
  93. </if>
  94. </where>
  95. </select>
  96. <select id="CorrespondDeviceList" resultType="com.bizmatics.model.vo.CorrespondDeviceVO">
  97. SELECT
  98. a.id,
  99. a.device_code,
  100. a.device_name,
  101. a.device_address,
  102. a.install_time,
  103. b.device_status,
  104. b.status_time,
  105. a.site_id,
  106. c.site_name,
  107. if (b.device_status=1,timestampdiff(
  108. HOUR,
  109. b.status_time,
  110. now()
  111. ),null) as offlineDuration,
  112. if(b.device_status!=1,timestampdiff(
  113. HOUR,
  114. a.install_time,
  115. now()
  116. ),null) as onlineDuration
  117. FROM
  118. device AS a
  119. JOIN device_status AS b ON a.device_code = b.device_code
  120. JOIN site AS c ON a.site_id = c.id
  121. <where>
  122. a.enable =1
  123. <if test="deviceName != null and deviceName != ''">
  124. and a.device_name LIKE CONCAT(CONCAT('%', #{deviceName}), '%')
  125. </if>
  126. </where>
  127. order by a.id desc
  128. <if test="current != null and current != 0 and startCurrent != null">
  129. LIMIT #{startCurrent},#{current}
  130. </if>
  131. </select>
  132. </mapper>