DeviceMapper.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.mhfire.persistence.mapper.DeviceMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.bizmatics.mhfire.model.Device">
  6. <id column="id" property="id" />
  7. <result column="name" property="name" />
  8. <result column="code" property="code" />
  9. <result column="device_type" property="deviceType" />
  10. <result column="create_time" property="createTime" />
  11. <result column="longitude" property="longitude" />
  12. <result column="latitude" property="latitude" />
  13. <result column="device_flag" property="deviceFlag" />
  14. <result column="del_flag" property="delFlag" />
  15. <result column="firm" property="firm" />
  16. <result column="describe" property="describe" />
  17. <result column="address" property="address" />
  18. <result column="device_duty" property="deviceDuty" />
  19. <result column="property" property="property" />
  20. </resultMap>
  21. <select id="selectCollect" resultType="com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO">
  22. select d.device_type as deviceType,count(d.id) as deviceCount,count(da.id) as alertCount,
  23. count(if(d.device_flag = 1, 1, null)) as lineCount,
  24. (
  25. select
  26. ROUND(COUNT(CASE WHEN dd.device_flag=1 THEN dd.device_flag END)/COUNT(*),2) AS rate_a
  27. FROM device as dd
  28. where dd.device_type = d.device_type
  29. ) as lineRate,
  30. (
  31. select
  32. ROUND(COUNT(CASE WHEN dan.id != null THEN dan.id END)/COUNT(*),2) AS rate_a
  33. FROM device as dd
  34. left join device_alert as dan
  35. on dd.`code` = dan.device_code
  36. where dd.device_type = d.device_type
  37. ) as alertRate,
  38. (
  39. select
  40. ROUND(COUNT(CASE WHEN dan.aj_flag=3 THEN dan.aj_flag END)/COUNT(*),2)
  41. FROM device_aj as dan
  42. where dan.device_type = d.device_type
  43. ) as checkRate
  44. from device as d
  45. left join device_alert as da
  46. on d.code = da.device_code
  47. left join device_aj as aj
  48. on d.code = aj.device_code
  49. <where>
  50. <if test="deviceType != null and deviceType != ''">
  51. and d.device_type = #{deviceType}
  52. </if>
  53. <if test="deviceCode != null and deviceCode != ''">
  54. and d.code = #{deviceCode}
  55. </if>
  56. <if test="startTime != null and endTime != null ">
  57. and d.create_time between #{startTime} and #{endTime}
  58. </if>
  59. </where>
  60. GROUP BY d.device_type
  61. </select>
  62. <select id="selectCollectOne" resultType="com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO">
  63. select d.device_type as deviceType,count(d.id) as deviceCount,count(da.id) as alertCount,
  64. count(if(d.device_flag = 1, 1, null)) as lineCount,
  65. (
  66. select
  67. ROUND(COUNT(CASE WHEN dd.device_flag=1 THEN dd.device_flag END)/COUNT(*),2) AS rate_a
  68. FROM device as dd
  69. where dd.device_type = d.device_type
  70. ) as lineRate,
  71. (
  72. select
  73. ROUND(COUNT(CASE WHEN dan.id != null THEN dan.id END)/COUNT(*),2) AS rate_a
  74. FROM device as dd
  75. left join device_alert as dan
  76. on dd.`code` = dan.device_code
  77. where dd.device_type = d.device_type
  78. ) as alertRate,
  79. (
  80. select
  81. ROUND(COUNT(CASE WHEN dan.aj_flag=3 THEN dan.aj_flag END)/COUNT(*),2)
  82. FROM device_aj as dan
  83. where dan.device_type = d.device_type
  84. ) as checkRate
  85. from device as d
  86. left join device_alert as da
  87. on d.code = da.device_code
  88. left join device_aj as aj
  89. on d.code = aj.device_code
  90. <where>
  91. <if test="deviceType != null and deviceType != ''">
  92. and d.device_type = #{deviceType}
  93. </if>
  94. <if test="deviceCode != null and deviceCode != ''">
  95. and d.code = #{deviceCode}
  96. </if>
  97. <if test="startTime != null and endTime != null ">
  98. and d.create_time between #{startTime} and #{endTime}
  99. </if>
  100. </where>
  101. </select>
  102. </mapper>