Administrator
2024-08-03 d38bb7f88d0c499265e6da62a52686a654834daa
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?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.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper">
  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory">
    <!--@mbg.generated-->
    <!--@Table rm_command_history-->
    <id column="com_id" jdbcType="BIGINT" property="comId" />
    <result column="command_code" jdbcType="VARCHAR" property="commandCode" />
    <result column="command_name" jdbcType="VARCHAR" property="commandName" />
    <result column="intake_id" jdbcType="BIGINT" property="intakeId" />
    <result column="rtu_addr" jdbcType="VARCHAR" property="rtuAddr" />
    <result column="protocol" jdbcType="VARCHAR" property="protocol" />
    <result column="param" property="param" jdbcType="JAVA_OBJECT" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
    <result column="send_time" jdbcType="TIMESTAMP" property="sendTime" />
    <result column="operator" jdbcType="BIGINT" property="operator" />
    <result column="result" jdbcType="TINYINT" property="result" />
    <result column="result_time" jdbcType="TIMESTAMP" property="resultTime" />
    <result column="result_text" jdbcType="LONGVARCHAR" property="resultText" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    com_id, command_code, command_name, intake_id, rtu_addr, protocol, param, send_time, 
    `operator`, `result`, result_time, result_text
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from rm_command_history
    where com_id = #{comId,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from rm_command_history
    where com_id = #{comId,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory">
    <!--@mbg.generated-->
    insert into rm_command_history (com_id, command_code, command_name, 
      intake_id, rtu_addr, protocol, 
      param, send_time, `operator`, 
      `result`, result_time, result_text
      )
    values (#{comId,jdbcType=BIGINT}, #{commandCode,jdbcType=VARCHAR}, #{commandName,jdbcType=VARCHAR}, 
      #{intakeId,jdbcType=BIGINT}, #{rtuAddr,jdbcType=VARCHAR}, #{protocol,jdbcType=VARCHAR},
      #{param,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, #{sendTime,jdbcType=TIMESTAMP}, #{operator,jdbcType=BIGINT},
      #{result,jdbcType=TINYINT}, #{resultTime,jdbcType=TIMESTAMP}, #{resultText,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory">
    <!--@mbg.generated-->
    insert into rm_command_history
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="comId != null">
        com_id,
      </if>
      <if test="commandCode != null">
        command_code,
      </if>
      <if test="commandName != null">
        command_name,
      </if>
      <if test="intakeId != null">
        intake_id,
      </if>
      <if test="rtuAddr != null">
        rtu_addr,
      </if>
      <if test="protocol != null">
        protocol,
      </if>
      <if test="param != null">
        param,
      </if>
      <if test="sendTime != null">
        send_time,
      </if>
      <if test="operator != null">
        `operator`,
      </if>
      <if test="result != null">
        `result`,
      </if>
      <if test="resultTime != null">
        result_time,
      </if>
      <if test="resultText != null">
        result_text,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="comId != null">
        #{comId,jdbcType=BIGINT},
      </if>
      <if test="commandCode != null">
        #{commandCode,jdbcType=VARCHAR},
      </if>
      <if test="commandName != null">
        #{commandName,jdbcType=VARCHAR},
      </if>
      <if test="intakeId != null">
        #{intakeId,jdbcType=BIGINT},
      </if>
      <if test="rtuAddr != null">
        #{rtuAddr,jdbcType=VARCHAR},
      </if>
      <if test="protocol != null">
        #{protocol,jdbcType=VARCHAR},
      </if>
      <if test="param != null">
        #{param,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},
      </if>
      <if test="sendTime != null">
        #{sendTime,jdbcType=TIMESTAMP},
      </if>
      <if test="operator != null">
        #{operator,jdbcType=BIGINT},
      </if>
      <if test="result != null">
        #{result,jdbcType=TINYINT},
      </if>
      <if test="resultTime != null">
        #{resultTime,jdbcType=TIMESTAMP},
      </if>
      <if test="resultText != null">
        #{resultText,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory">
    <!--@mbg.generated-->
    update rm_command_history
    <set>
      <if test="commandCode != null">
        command_code = #{commandCode,jdbcType=VARCHAR},
      </if>
      <if test="commandName != null">
        command_name = #{commandName,jdbcType=VARCHAR},
      </if>
      <if test="intakeId != null">
        intake_id = #{intakeId,jdbcType=BIGINT},
      </if>
      <if test="rtuAddr != null">
        rtu_addr = #{rtuAddr,jdbcType=VARCHAR},
      </if>
      <if test="protocol != null">
        protocol = #{protocol,jdbcType=VARCHAR},
      </if>
      <if test="param != null">
        param = #{param,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},
      </if>
      <if test="sendTime != null">
        send_time = #{sendTime,jdbcType=TIMESTAMP},
      </if>
      <if test="operator != null">
        `operator` = #{operator,jdbcType=BIGINT},
      </if>
      <if test="result != null">
        `result` = #{result,jdbcType=TINYINT},
      </if>
      <if test="resultTime != null">
        result_time = #{resultTime,jdbcType=TIMESTAMP},
      </if>
      <if test="resultText != null">
        result_text = #{resultText,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where com_id = #{comId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoRm.RmCommandHistory">
    <!--@mbg.generated-->
    update rm_command_history
    set command_code = #{commandCode,jdbcType=VARCHAR},
      command_name = #{commandName,jdbcType=VARCHAR},
      intake_id = #{intakeId,jdbcType=BIGINT},
      rtu_addr = #{rtuAddr,jdbcType=VARCHAR},
      protocol = #{protocol,jdbcType=VARCHAR},
      param = #{param,jdbcType= JAVA_OBJECT, typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},
      send_time = #{sendTime,jdbcType=TIMESTAMP},
      `operator` = #{operator,jdbcType=BIGINT},
      `result` = #{result,jdbcType=TINYINT},
      result_time = #{resultTime,jdbcType=TIMESTAMP},
      result_text = #{resultText,jdbcType=LONGVARCHAR}
    where com_id = #{comId,jdbcType=BIGINT}
  </update>
 
  <!--根据操作员ID获取未关阀记录(包含在线情况)-->
  <select id="getUnclosedValves" resultType="com.dy.pipIrrGlobal.voRm.VoUnclosedValve">
    SELECT
        inta.name AS intakeNum,
        rtus.isOnLine,
        com.rtu_addr AS rtuAddr,
        com.param ->>'$.icCardNo' AS vcNum,
        (SELECT param ->>'$.orderNo' AS orderNo FROM rm_command_history WHERE rtu_addr = com.rtu_addr ORDER BY send_time desc LIMIT 0,1) AS orderNo
    FROM rm_command_history com
        INNER JOIN pr_controller con ON com.rtu_addr = con.rtuAddr
        INNER JOIN pr_intake inta ON con.intakeId = inta.id
        INNER JOIN JSON_TABLE(
            <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
            #{onLineMap},
            '$[*]' COLUMNS(
                rtuAddr VARCHAR(20) PATH '$.rtuAddr',
                isOnLine BOOLEAN PATH '$.isOnLine'
            )
        ) rtus ON com.rtu_addr = rtus.rtuAddr
    <where>
      AND (com.command_code = '92' OR com.command_code = 'A2' OR com.command_code = '97')
      AND com.operator = #{operator}
      AND NOT EXISTS (
        SELECT *
        FROM rm_command_history
        WHERE (result IS NULL OR result = 1 )
            AND (command_code = '93' OR command_code = 'A3' OR command_code = '98')
            AND param ->>'$.orderNo' = com.param ->>'$.orderNo'
      )
    </where>
    GROUP BY inta.name, rtus.isOnLine, com.rtu_addr, com.param ->>'$.icCardNo'
  </select>
 
  <!--根据取水口ID获取该取水口未关阀参数-->
  <select id="getUncloseParam" resultType="com.dy.pipIrrGlobal.voRm.VoUnclosedParam">
    SELECT
        com.rtu_addr AS rtuAddr,
        com.param ->>'$.orderNo' AS orderNo,
        com.param ->>'$.icCardNo' AS vcNum
    FROM rm_command_history com
        INNER JOIN pr_controller con ON com.rtu_addr = con.rtuAddr
        INNER JOIN pr_intake inta ON con.intakeId = inta.id
        INNER JOIN JSON_TABLE(
            <!--      '[{"rtuAddr":"620201000029","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
            #{onLineMap},
            '$[*]' COLUMNS(
                rtuAddr VARCHAR(20) PATH '$.rtuAddr',
                isOnLine BOOLEAN PATH '$.isOnLine'
            )
        ) rtus ON com.rtu_addr = rtus.rtuAddr
    WHERE (com.command_code = '92' OR com.command_code = 'A2' OR com.command_code = '97') AND con.intakeId = #{intakeId}
    AND NOT EXISTS (
        SELECT *
        FROM rm_command_history
        WHERE (result IS NULL OR result = 1 )
            AND (command_code = '93' OR command_code = 'A3' OR command_code = '98')
            AND param ->>'$.orderNo' = com.param ->>'$.orderNo'
    )
    ORDER BY com.send_time DESC
    LIMIT 0,1
  </select>
 
  <!--根据指定条件获取命令日志历史记录总数-->
  <select id="getCommandHistoriesCount" resultType="java.lang.Long">
    SELECT
        COUNT(*) AS recordCount
    FROM rm_command_history his
      INNER JOIN pr_intake inta ON inta.id = his.intake_id
      LEFT JOIN se_client cli ON cli.id = his.operator
      LEFT JOIN ba_user  user ON user.id = his.operator
    <where>
      <if test="intakeId != null">
        AND his.intake_id = #{intakeId}
      </if>
      <if test = "commandName != null and commandName !=''">
        AND his.command_name LIKE CONCAT('%',#{commandName},'%')
      </if>
      <if test = "result != null">
        AND his.result = #{result}
      </if>
      <if test = "timeStart != null and timeStop != null">
        AND his.send_time BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
  </select>
 
  <!--根据指定条件获取命令日志历史记录-->
  <select id="getCommandHistories" resultType="com.dy.pipIrrGlobal.voRm.VoCommand">
    SELECT
        his.com_id AS comId,
        his.command_name AS commandName,
        inta.name AS intakeName,
        his.rtu_addr AS rtuAddr,
        his.protocol,
        his.send_time AS sendTime,
        his.result_time AS resultTime,
        (CASE
        WHEN his.result = 1 THEN "成功"
        ELSE "失败"
        END) AS result,
        his.result_text,
        IFNULL(cli.name, user.name) AS userName
    FROM rm_command_history his
        INNER JOIN pr_intake inta ON inta.id = his.intake_id
        LEFT JOIN se_client cli ON cli.id = his.operator
        LEFT JOIN ba_user  user ON user.id = his.operator
    <where>
      <if test="intakeId != null">
        AND his.intake_id = #{intakeId}
      </if>
      <if test = "commandName != null and commandName !=''">
        AND his.command_name LIKE CONCAT('%',#{commandName},'%')
      </if>
      <if test = "result != null">
        AND his.result = #{result}
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND his.send_time BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
    ORDER BY his.send_time DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
</mapper>