IotAlarmRuleSourceMapper.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.IotAlarmRuleSourceMapper">
  4. <select id="selectDetailData" resultType="com.xunmei.iot.vo.alarm.IotAlarmRuleSourceDetailVo">
  5. select r.id as ruleId,
  6. r.enabled as enable,
  7. r.name as ruleName,
  8. r.remark as ruleRemark,
  9. r.type as ruleType,
  10. e.source_type as sourceType
  11. from t_app_alarm_rule r
  12. inner join t_app_alarm_rule_express e on r.id = e.rule_id
  13. where r.id = #{ruleId}
  14. </select>
  15. <resultMap id="product_type_data" type="com.xunmei.iot.vo.alarm.ProductTypeDataVo">
  16. <result property="type" column="type"/>
  17. <result property="valueType" column="value_type"/>
  18. <result property="typeText" column="type_text"/>
  19. <collection property="deviceTempList" ofType="com.xunmei.iot.vo.alarm.ProductDeviceTempVo">
  20. <result property="deviceId" column="device_id"/>
  21. <result property="strDeviceId" column="strDeviceId"/>
  22. <result property="orgId" column="org_id"/>
  23. <result property="orgName" column="org_name"/>
  24. <result property="orgPath" column="org_path"/>
  25. </collection>
  26. </resultMap>
  27. <select id="selectRuleDevice" resultMap="product_type_data">
  28. SELECT
  29. a.source_type AS type,
  30. d.source_type_des as type_text,
  31. b.value_type,
  32. b.`value` AS device_id,
  33. concat(b.org_id,'-',b.value) as strDeviceId,
  34. b.org_id,
  35. c.`name` AS org_name,
  36. c.path AS org_path
  37. FROM
  38. ( SELECT rule_id, source_type FROM iot_alarm_rule_express GROUP BY source_type, rule_id ) a
  39. LEFT JOIN iot_alarm_rule_source b ON a.rule_id = b.rule_id AND a.source_type = b.source_type
  40. LEFT JOIN sys_org c ON b.org_id = c.id
  41. LEFT JOIN (select source_type,source_type_des from iot_alarm_system_field GROUP BY source_type,source_type_des) d on a.source_type = d.source_type
  42. where a.rule_id = #{ruleId}
  43. </select>
  44. <!--<select id="selectDeviceList" resultType="com.xunmei.iot.vo.alarm.IotAlarmRuleSourceDeviceVo">
  45. SELECT DISTINCT
  46. d.device_code AS deviceId,
  47. d.device_name AS deviceName,
  48. d.org_id AS orgId,
  49. d.org_path AS orgPath,
  50. b.short_name as org_name
  51. FROM
  52. iot_sensor d
  53. LEFT JOIN sys_org b ON d.org_id = b.id
  54. where 1=1
  55. <if test="param.includeSub == false">
  56. and d.org_id = #{param.orgId}
  57. </if>
  58. <if test="param.includeSub == true">
  59. and b.path like concat((select path from sys_org where id = #{param.orgId} ),'%')
  60. </if>
  61. and d.device_type = #{param.type}
  62. <if test="param.deviceName != null and param.deviceName != ''">
  63. and d.device_name like concat('%',#{param.deviceName},'%')
  64. </if>
  65. </select>-->
  66. <select id="selectDeviceList" resultType="com.xunmei.iot.vo.alarm.IotAlarmRuleSourceDeviceVo">
  67. SELECT DISTINCT
  68. concat(d.iot_token,'_',d.device_product,'_',d.device_code) AS deviceId,
  69. d.device_name AS deviceName,
  70. d.org_id AS orgId,
  71. d.org_path AS orgPath,
  72. b.short_name as org_name
  73. FROM
  74. iot_device_info d
  75. LEFT JOIN sys_org b ON d.org_id = b.id
  76. where 1=1
  77. <if test="param.includeSub == false">
  78. and d.org_id = #{param.orgId}
  79. </if>
  80. <if test="param.includeSub == true">
  81. and b.path like concat((select path from sys_org where id = #{param.orgId} ),'%')
  82. </if>
  83. and d.device_type = #{param.type}
  84. <if test="param.deviceName != null and param.deviceName != ''">
  85. and d.device_name like concat('%',#{param.deviceName},'%')
  86. </if>
  87. </select>
  88. <select id="getRuleSourceSize" resultType="com.xunmei.iot.vo.alarm.IotAlarmRuleSourceTotalVo">
  89. SELECT
  90. a.source_type,
  91. a.source_type_des AS source_name,
  92. IFNULL( b.source_size, 0 ) AS source_size
  93. FROM
  94. ( SELECT source_type, source_type_des FROM iot_alarm_system_field where enable = 1 and alarm_rule_property = 1 GROUP BY source_type, source_type_des ) a
  95. LEFT JOIN ( SELECT rule_id, source_type, count(*) source_size FROM iot_alarm_rule_source WHERE rule_id = #{ruleId} GROUP BY rule_id, source_type ) b ON a.source_type = b.source_type
  96. </select>
  97. </mapper>