ReportWaterPumpStateMapper.xml 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.huaxu.dao.ReportWaterPumpStateMapper">
  4. <resultMap id="DeviceMonitorInfo" type="com.huaxu.dto.watePump.ReprotWaterPumpDto">
  5. <result property="year" column="year" jdbcType="INTEGER"/>
  6. <result property="month" column="month" jdbcType="INTEGER"/>
  7. <result property="day" column="day" jdbcType="INTEGER"/>
  8. <collection property="deviceList" resultMap="deviceListMap"></collection>
  9. </resultMap>
  10. <resultMap id="deviceListMap" type="com.huaxu.dto.watePump.WaterPumpDataDto">
  11. <result property="tenantId" column="tenantId" jdbcType="INTEGER"/>
  12. <result property="deviceId" column="deviceId" jdbcType="INTEGER"/>
  13. <result property="deviceCode" column="deviceCode" jdbcType="INTEGER"/>
  14. <result property="attributeId" column="attributeId" jdbcType="INTEGER"/>
  15. <result property="attributeName" column="attributeName" jdbcType="INTEGER"/>
  16. <collection property="stateList" resultMap="stateListMap"></collection>
  17. </resultMap>
  18. <resultMap id="stateListMap" type="com.huaxu.dto.watePump.WaterPumpStateDto">
  19. <result property="state" column="state" jdbcType="INTEGER"/>
  20. <result property="beginTime" column="beginTime" jdbcType="INTEGER"/>
  21. <result property="endTime" column="endTime" jdbcType="INTEGER"/>
  22. </resultMap>
  23. <select id="findReportWaterPumpStateList" resultMap="DeviceMonitorInfo">
  24. SELECT
  25. a.year as "year",
  26. a.month as "month",
  27. a.day as "day",
  28. a.state as "state",
  29. a.tenant_id as "tenantId",
  30. a.DEVICE_CODE as "deviceCode",
  31. a.DEVICE_NAME as "deviceName",
  32. a.DEVICE_ID as "deviceId",
  33. a.attribute_id as "attributeId",
  34. IFNULL(b.REMARK,a.`attribute_name`) AS "attributeName",
  35. a.state_begin_time as "beginTime",
  36. a.state_end_time as "endTime"
  37. FROM sms_report_water_pump_state a
  38. inner join sms_device d on d.id = a.DEVICE_ID
  39. inner join sms_device_parm b
  40. on a.DEVICE_ID = b.DEVICE_ID and a.ATTRIBUTE_ID=b.ATTRIBUTE_ID and b.`STATUS`=1 and b.PARM_TYPE = 2
  41. <where>
  42. <if test="waterPump.tenantId != null and waterPump.tenantId != ''">
  43. and a.tenant_id = #{waterPump.tenantId}
  44. </if>
  45. and b.PARENT_SCENE_ID = #{waterPump.sceneId}
  46. <if test="waterPump.deviceIds !=null and waterPump.deviceIds.size > 0">
  47. and a.DEVICE_ID in
  48. <foreach collection="waterPump.deviceIds" item="dramaId" open="(" close=")" separator=",">
  49. #{dramaId.id}
  50. </foreach>
  51. </if>
  52. and a.state_begin_time > #{waterPump.beginTime}
  53. </where>
  54. <!--order by a.DEVICE_ID,a.state_begin_time -->
  55. </select>
  56. <insert id="insertReportWaterPumpState">
  57. INSERT INTO sms_report_water_pump_state
  58. (`state`,state_begin_time,state_end_time,tenant_id,device_id,device_name,
  59. device_code,attribute_id,attribute_name,`year`,`month`,
  60. `day`,date_create,date_update,md5_query)
  61. VALUES
  62. (#{waterPump.state},#{waterPump.stateBeginTime},#{waterPump.stateEndTime},#{waterPump.tenantId},#{waterPump.deviceId},#{waterPump.deviceName},
  63. #{waterPump.deviceCode},#{waterPump.attributeId},#{waterPump.attributeName},#{waterPump.year},#{waterPump.month},
  64. #{waterPump.day},#{waterPump.dateCreate},#{waterPump.dateUpdate},#{waterPump.md5Query})
  65. </insert>
  66. <insert id="batchInsertReportWaterPumpState">
  67. INSERT INTO sms_report_water_pump_state
  68. (`state`,state_begin_time,state_end_time,tenant_id,device_id,device_name,
  69. device_code,attribute_id,attribute_name,`year`,`month`,
  70. `day`,date_create,date_update,md5_query)
  71. VALUES
  72. <foreach collection="waterPumpList" item="waterPump" index="index" separator=",">
  73. (#{waterPump.state},#{waterPump.stateBeginTime},#{waterPump.stateEndTime},#{waterPump.tenantId},#{waterPump.deviceId},#{waterPump.deviceName},
  74. #{waterPump.deviceCode},#{waterPump.attributeId},#{waterPump.attributeName},#{waterPump.year},#{waterPump.month},
  75. #{waterPump.day},#{waterPump.dateCreate},#{waterPump.dateUpdate},#{waterPump.md5Query})
  76. </foreach>
  77. </insert>
  78. <select id="findReportWaterPumpState" resultType="com.huaxu.entity.ReportWaterPumpStateEntity">
  79. select id,`state`,state_begin_time as "stateBeginTime" from sms_report_water_pump_state s
  80. where md5_query = #{md5Query}
  81. order by s.state_begin_time desc limit 1
  82. </select>
  83. <update id="updateReportWaterPumpState">
  84. update sms_report_water_pump_state
  85. set state_end_time = #{endTime},
  86. date_update = #{updateTime}
  87. where id = #{id}
  88. </update>
  89. </mapper>