liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dingzhuo.energy.data.monitoring.device.mapper.DeviceStatusHistoryMapper">
 
  <resultMap type="DeviceStatusHistory" id="DeviceStatusHistoryResult">
    <result property="id" column="id"/>
    <result property="deviceId" column="device_id"/>
    <result property="statusId" column="status_id"/>
    <result property="statusName" column="status_name"/>
    <result property="statusCode" column="status_code"/>
    <result property="beginTime" column="begin_time"/>
    <result property="endTime" column="end_time"/>
    <result property="devBeginTime" column="begin_time"/>
    <result property="devEndTime" column="end_time"/>
    <result property="duration" column="duration"/>
  </resultMap>
 
  <sql id="selectDeviceStatusHistoryVo">
    select id,
           device_id,
           status_id,
           status_name,
           status_code,
           begin_time,
           end_time,
           duration
    from device_status_history
  </sql>
 
  <select id="selectDeviceStatusHistoryList" parameterType="DeviceStatusHistory"
    resultMap="DeviceStatusHistoryResult">
    <include refid="selectDeviceStatusHistoryVo"/>
    <where>
      <if test="statusName != null  and statusName != ''">and status_name like concat('%',
        #{statusName}, '%')
      </if>
      <if test="statusCode != null  and statusCode != ''">and status_code like concat('%',
        #{statusCode}, '%')
      </if>
      <if test="beginTime != null and beginTime != ''">and begin_time &gt;=
        to_timestamp(#{beginTime},'yyyy-mm-dd hh24:mi:ss')
      </if>
      <if test="endTime != null and endTime != ''">and begin_time &lt;=
        to_timestamp(#{endTime},'yyyy-mm-dd hh24:mi:ss')
      </if>
      <if test="duration != null ">and duration like concat('%', #{duration}, '%')</if>
    </where>
  </select>
 
  <select id="selectDeviceStatusHistoryById" parameterType="String"
    resultMap="DeviceStatusHistoryResult">
    <include refid="selectDeviceStatusHistoryVo"/>
    where id = #{id}
  </select>
 
  <insert id="insertDeviceStatusHistory" parameterType="DeviceStatusHistory">
    insert into device_status_history
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null  and id != ''">id,</if>
      <if test="deviceId != null  and deviceId != ''">device_id,</if>
      <if test="statusId != null  and statusId != ''">status_id,</if>
      <if test="statusName != null  and statusName != ''">status_name,</if>
      <if test="statusCode != null  and statusCode != ''">status_code,</if>
      <if test="beginTime != null ">begin_time,</if>
      <if test="endTime != null ">end_time,</if>
      <if test="duration != null ">duration,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null  and id != ''">#{id},</if>
      <if test="deviceId != null  and deviceId != ''">#{deviceId},</if>
      <if test="statusId != null  and statusId != ''">#{statusId},</if>
      <if test="statusName != null  and statusName != ''">#{statusName},</if>
      <if test="statusCode != null  and statusCode != ''">#{statusCode},</if>
      <if test="beginTime != null ">#{beginTime},</if>
      <if test="endTime != null ">#{endTime},</if>
      <if test="duration != null ">#{duration},</if>
    </trim>
  </insert>
  <insert id="saveHistoryStatus">
    delete from device_status_live where device_id = #{deviceId} and status_id = #{statusId};
    insert into device_status_history
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null  and id != ''">id,</if>
      <if test="deviceId != null  and deviceId != ''">device_id,</if>
      <if test="statusId != null  and statusId != ''">status_id,</if>
      <if test="statusName != null  and statusName != ''">status_name,</if>
      <if test="statusCode != null  and statusCode != ''">status_code,</if>
      <if test="beginTime != null ">begin_time,</if>
      <if test="endTime != null ">end_time,</if>
      <if test="duration != null ">duration,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null  and id != ''">#{id},</if>
      <if test="deviceId != null  and deviceId != ''">#{deviceId},</if>
      <if test="statusId != null  and statusId != ''">#{statusId},</if>
      <if test="statusName != null  and statusName != ''">#{statusName},</if>
      <if test="statusCode != null  and statusCode != ''">#{statusCode},</if>
      <if test="beginTime != null ">#{beginTime},</if>
      <if test="endTime != null ">#{endTime},</if>
      <if test="duration != null ">#{duration},</if>
    </trim>
  </insert>
 
  <update id="updateDeviceStatusHistory" parameterType="DeviceStatusHistory">
    update device_status_history
    <trim prefix="SET" suffixOverrides=",">
      <if test="deviceId != null  and deviceId != ''">device_id = #{deviceId},</if>
      <if test="statusId != null  and statusId != ''">status_id = #{statusId},</if>
      <if test="statusName != null  and statusName != ''">status_name = #{statusName},</if>
      <if test="statusCode != null  and statusCode != ''">status_code = #{statusCode},</if>
      <if test="beginTime != null ">begin_time = #{beginTime},</if>
      <if test="endTime != null ">end_time = #{endTime},</if>
      <if test="duration != null ">duration = #{duration},</if>
    </trim>
    where id = #{id}
  </update>
 
  <delete id="deleteDeviceStatusHistoryById" parameterType="String">
    delete
    from device_status_history
    where id = #{id}
  </delete>
 
  <delete id="deleteDeviceStatusHistoryByIds" parameterType="String">
    delete from device_status_history where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
 
  <select id="selectDeviceStatusHistoryListNew" parameterType="DeviceStatusHistory"
    resultMap="DeviceStatusHistoryResult">
    select
    dsh.id,
    dsh.device_id,
    status_id,
    status_name,
    status_code,
    begin_time,
    end_time,
    duration,
    mo."name" as indexName
    FROM
    device_status_history dsh,
    energy_index ei,
    node_index ni,
    model_node mo
    <where>
      ni.node_id IN ( SELECT node_id FROM model_node WHERE address LIKE ( SELECT address FROM
      model_node WHERE node_id = #{deviceId})
      <if test='eierarchyFlag=="ALL"'>
        || '%'
      </if>
      )
      AND ei.index_id = ni.index_id
      AND mo.node_id = ni.node_id
      AND dsh.device_id = mo.node_id
      <if test="indexType != null  and indexType != ''">AND ei.index_type = #{indexType}</if>
      <if test="statusName != null  and statusName != ''">and status_name like concat('%',
        #{statusName}, '%')
      </if>
      <if test="statusCode != null  and statusCode != ''">and status_code like concat('%',
        #{statusCode}, '%')
      </if>
      <if test="beginTime != null and beginTime != ''">and begin_time &gt;=
        to_timestamp(#{beginTime},'yyyy-mm-dd hh24:mi:ss')
      </if>
      <if test="endTime != null and endTime != ''">and begin_time &lt;=
        to_timestamp(#{endTime},'yyyy-mm-dd hh24:mi:ss')
      </if>
      <if test="duration != null ">and duration like concat('%', #{duration}, '%')</if>
    </where>
    order by begin_time asc
  </select>
</mapper>