wangmengzhao
2023-12-13 d8228730095cdcaccb40dd2dc290fc44779e340a
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
<?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">
<!--namespace = 所需实现的接口全限定名-->
<!--        package com.ruoyi.iot.mapper;-->
<mapper namespace="com.ruoyi.iot.mapper.DeviceOrderMapper">
    <sql id="selectDeviceOrderVo">
        select d.id,
               d.user_id,
               d.erecto_id,
               d.erecto_name,
               d.user_name,
               d.user_phone,
               d.address,
               d.order_type,
               d.appointment_time,
               d.evaluate,
               d.device_id,
               d.remark,
               d.description,
               u.user_id,
               u.user_name,
               u.is_authentication,
               d.score,
               d.state,
               d.createuser_id,
               d.imgurl,
               de.device_id,
               de.device_name
        from iot_device_order as d
                 left join sys_user as u on d.erecto_id = u.user_id
                 left join iot_device as de on d.device_id = de.device_id
        where d.createuser_id = #{createUserId}
          and d.order_type = #{orderType}
    </sql>
 
    <resultMap id="DeviceOrderResult" type="DeviceOrder">
        <id property="id" column="id"/>
        <result property="erectoId" column="erecto_id"/>
        <result property="deviceId" column="d_deviceid"/>
        <result property="userId" column="did"/>
        <result property="createUserId" column="createuser_id"/>
        <result property="updateUserId" column="updateuser_id"/>
        <result property="erectoName" column="erecto_name"/>
        <result property="erectoPhone" column="erecto_phone"/>
        <result property="userName" column="dusername"/>
        <result property="userPhone" column="user_phone"/>
        <result property="address" column="address"/>
        <result property="orderType" column="order_type"/>
        <result property="remark" column="remark"/>
        <result property="description" column="description"/>
        <result property="appointmentTime" column="appointment_time"/>
        <result property="score" column="score"/>
        <result property="evaluate" column="evaluate"/>
        <result property="isRate" column="is_rate"/>
        <result property="createTime" column="create_time"/>
        <result property="assginTime" column="assgin_time"/>
        <result property="receiveTime" column="receive_time"/>
        <result property="finishTime" column="finish_time"/>
        <result property="state" column="state"/>
        <result property="imgUrl" column="imgurl"/>
        <result property="receiveTimeoutFlag" column="receive_timeout_flag"/>
        <result property="finishTimeoutFlag" column="finish_timeout_flag"/>
        <result property="customFlag" column="custom_flag"/>
        <association property="device" javaType="Device" resultMap="DeviceResult"/>
        <collection property="sysuser" ofType="SysUser" resultMap="UserResult"/>
    </resultMap>
 
    <resultMap id="UserResult" type="SysUser">
        <id property="userId" column="uid"/>
        <result property="userName" column="uusername"/>
        <result property="isAuthentication" column="is_authentication"/>
    </resultMap>
    <resultMap id="DeviceResult" type="Device">
        <id property="deviceId" column="de_deviceid"/>
        <result property="deviceName" column="device_name"/>
    </resultMap>
    <!--id = 所需重写的接口抽象方法,resultType = 查询后所需返回的对象类型-->
    <select id="selectDeviceOrderList" resultMap="DeviceOrderResult">
        select
        d.id,
        d.erecto_id,
        d.device_id as d_deviceid,
        d.user_id as did,
        d.createuser_id,
        d.updateuser_id,
        d.erecto_name,
        d.erecto_phone,
        d.user_name as dusername,
        d.user_phone,
        d.address,
        d.order_type,
        d.remark,
        d.description,
        d.appointment_time,
        d.score,
        d.evaluate,
        d.is_rate,
        d.create_time,
        d.assgin_time,
        d.receive_time,
        d.finish_time,
        d.state,
        d.imgurl,
        d.receive_timeout_flag,
        d.finish_timeout_flag,
        d.custom_flag,
        de.device_id as de_deviceid,
        de.device_name,
        u.user_id as uid,
        u.user_name as uusername,
        u.is_authentication
        from iot_device_order as d
        left join sys_user as u on d.erecto_id = u.user_id
        left join iot_device as de on d.device_id = de.device_id
        where d.order_type = #{orderType}
        <if test=" createUserId  != null and createUserId != 0 ">
            and (d.createuser_id= #{createUserId} or d.erecto_id = #{createUserId})
        </if>
        <if test=" erectoId  != null and erectoId > 0">
            and d.erecto_id= #{erectoId}
        </if>
        <if test=" state != null and state >= 0">
            and d.state = #{state}
        </if>
        <if test="userId != null and userId > 0">
            and d.user_id = #{userId}
        </if>
        <if test=" receiveTimeoutFlag != null and receiveTimeoutFlag != 0">
            and d.receive_timeout_flag = #{receiveTimeoutFlag}
        </if>
        <if test=" finishTimeoutFlag != null and finishTimeoutFlag != 0">
            and d.finish_timeout_flag = #{finishTimeoutFlag}
        </if>
        order by d.create_time desc
        ${params.dataScope}
    </select>
    <select id="selectDeviceOrderById" resultMap="DeviceOrderResult">
        select d.id,
               d.user_id    as did,
               d.erecto_id,
               d.erecto_name,
               d.erecto_phone,
               d.user_name  as dusername,
               d.user_phone,
               d.address,
               d.order_type,
               d.appointment_time,
               d.evaluate,
               d.device_id  as d_deviceid,
               d.remark,
               d.description,
               d.score,
               d.is_rate,
               d.state,
               d.createuser_id,
               d.imgurl,
               d.custom_flag,
               de.device_id as de_deviceid,
               de.device_name,
               u.user_id    as uid,
               u.user_name  as uusername,
               u.is_authentication
        from iot_device_order as d
                 left join sys_user as u on d.erecto_id = u.user_id
                 left join iot_device as de on d.device_id = de.device_id
        where d.id = #{id}
    </select>
    <!--  根据登录的用户来查询自己未派单的安装单/维修单数量  -->
    <select id="selectDeviceOrderCountByUndeliveredorders" resultType="java.lang.Integer">
        select count(*)
        from iot_device_order d where d.state = '0'
        <if test=" orderType != null and orderType != 0 ">
            AND d.order_type = #{orderType}
        </if>
        <if test=" createUserId  != null and createUserId != 0 ">
            and (d.createuser_id= #{createUserId} or d.erecto_id = #{createUserId})
        </if>
        <if test=" erectoId != null and erectoId != 0">
            AND d.erecto_id = #{erectoId}
        </if>
        <if test="userId != null and userId != 0">
            AND d.user_id = #{userId}
        </if>
    </select>
    <!--    根据登录的用户来查询自己已派单的安装单/维修单数量-->
    <select id="selectDeviceOrderCountByDispatchedorders" resultType="java.lang.Integer">
        select count(*)
        from iot_device_order d where d.state = '1'
        <if test=" createUserId  != null and createUserId != 0 ">
            and (d.createuser_id= #{createUserId} or d.erecto_id = #{createUserId})
        </if>
        <if test=" orderType != null and orderType != 0 ">
            AND d.order_type = #{orderType}
        </if>
        <if test=" erectoId != null and erectoId != 0 ">
            AND d.erecto_id = #{erectoId}
        </if>
        <if test="userId != null and userId != 0">
            AND d.user_id = #{userId}
        </if>
    </select>
    <!--    根据登录的用户来查询自己已接单的安装单/维修单数量-->
    <select id="selectDeviceOrderCountByReceivedorders" resultType="java.lang.Integer">
        select count(*)
        from iot_device_order d where d.state = '2'
        <if test=" createUserId  != null and createUserId != 0 ">
            and (d.createuser_id= #{createUserId} or d.erecto_id = #{createUserId})
        </if>
        <if test=" orderType != null and orderType != 0 ">
            AND d.order_type = #{orderType}
        </if>
        <if test=" erectoId != null and erectoId != 0 ">
            AND d.erecto_id = #{erectoId}
        </if>
        <if test="userId != null and userId != 0">
            AND d.user_id = #{userId}
        </if>
    </select>
    <!--    根据登录的用户来查询自己已完成的安装单/维修单数量-->
    <select id="selectDeviceOrderCountByCompleted" resultType="java.lang.Integer">
        select count(*)
        from iot_device_order d where d.state = '3'
        <if test=" createUserId  != null and createUserId != 0 ">
            and (d.createuser_id= #{createUserId} or d.erecto_id = #{createUserId})
        </if>
        <if test=" orderType != null and orderType != 0">
            AND d.order_type = #{orderType}
        </if>
        <if test=" erectoId != null and erectoId != 0">
            AND d.erecto_id = #{erectoId}
        </if>
        <if test="userId != null and userId != 0">
            AND d.user_id = #{userId}
        </if>
    </select>
    <select id="selectDeviceOrderByIdAndErectoName" resultMap="DeviceOrderResult">
        select d.id,
               d.user_id    as did,
               d.erecto_id,
               d.erecto_name,
               d.erecto_phone,
               d.user_name  as dusername,
               d.user_phone,
               d.address,
               d.order_type,
               d.appointment_time,
               d.evaluate,
               d.score,
               d.is_rate,
               d.device_id  as d_deviceid,
               d.remark,
               d.description,
               d.state,
               d.createuser_id,
               d.imgurl,
               d.custom_flag,
               de.device_id as de_deviceid,
               de.device_name,
               u.user_id    as uid,
               u.user_name  as uusername,
               u.is_authentication
        from iot_device_order as d
                 left join sys_user as u on d.erecto_id = u.user_id
                 left join iot_device as de on d.device_id = de.device_id
        where d.id = #{id}
          AND d.erecto_name = #{erectoName}
    </select>
    <select id="selectDeviceOrderAll" resultMap="DeviceOrderResult">
        select d.id,
               d.user_id    as did,
               d.createuser_id,
               d.erecto_id,
               d.erecto_name,
               d.erecto_phone,
               d.user_name  as dusername,
               d.user_phone,
               d.address,
               d.order_type,
               d.appointment_time,
               d.evaluate,
               d.device_id  as d_deviceid,
               d.remark,
               d.description,
               d.score,
               d.is_rate,
               d.create_time,
               d.assgin_time,
               d.receive_time,
               d.finish_time,
               d.state,
               d.imgurl,
               d.custom_flag,
               d.receive_timeout_flag,
               d.finish_timeout_flag,
               u.user_id    as uid,
               u.user_name  as uusername,
               u.is_authentication,
               de.device_id as de_deviceid,
               de.device_name
        from iot_device_order as d
                 left join sys_user as u on d.erecto_id = u.user_id
                 left join iot_device as de on d.device_id = de.device_id
        where d.state in (1, 2)
    </select>
 
    <insert id="insertDeviceOrder" parameterType="DeviceOrder" useGeneratedKeys="true" keyProperty="id">
        insert into iot_device_order(
        <if test="id != null and id != 0">id,</if>
        <if test="erectoId != null">erecto_id,</if>
        <if test="deviceId != null and deviceId != 0">device_id,</if>
        <if test="userId != null and userId != 0">user_id,</if>
        <if test="erectoName != null and erectoName != ''">erecto_name,</if>
        <if test="erectoPhone != null and erectoPhone != ''">erecto_phone,</if>
        <if test="userName != null and userName != ''">user_name,</if>
        <if test="userPhone != null and userPhone != ''">user_phone,</if>
        <if test="address != null and address != ''">address,</if>
        <if test="orderType != null and orderType != ''">order_type,</if>
        <if test="remark != null and remark != ''">remark,</if>
        <if test="description != null and description != ''">description,</if>
        <if test="appointmentTime != null">appointment_time,</if>
        <if test="score != null and score != ''">score,</if>
        <if test="evaluate != null and evaluate != ''">evaluate,</if>
        <if test="assginTime != null">assgin_time,</if>
        <if test="receiveTime != null">receive_time,</if>
        <if test="finishTime != null">finish_time,</if>
        <if test="state != null and state != ''">state,</if>
        <if test="createUserId != null and createUserId != 0">createuser_id,</if>
        <if test="imgUrl != null and imgUrl != ''">imgurl,</if>
        <if test="customFlag != null and customFlag !=''">custom_flag,</if>
        create_time)
        values (
        <if test="id != null and id != ''">#{id},</if>
        <if test="erectoId != null">#{erectoId},</if>
        <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
        <if test="userId != null">#{userId},</if>
        <if test="erectoName!=null">#{erectoName},</if>
        <if test="erectoPhone != null and erectoPhone != ''">#{erectoPhone},</if>
        <if test="userName != null">#{userName},</if>
        <if test="userPhone != null">#{userPhone},</if>
        <if test="address != null">#{address},</if>
        <if test="orderType != null and orderType != ''">#{orderType},</if>
        <if test="remark != null and remark != ''">#{remark},</if>
        <if test="description != null and description != ''">#{description},</if>
        <if test="appointmentTime != null">#{appointmentTime},</if>
        <if test="score != null and score != ''">#{score},</if>
        <if test="evaluate != null and evaluate != ''">#{evaluate},</if>
        <if test="assginTime != null">#{assginTime},</if>
        <if test="receiveTime != null">#{receiveTime},</if>
        <if test="finishTime != null">#{finishTime},</if>
        <if test="state != null and state != ''">#{state},</if>
        <if test="createUserId != null and createUserId != 0">#{createUserId},</if>
        <if test="imgUrl != null and imgUrl != ''">#{imgUrl},</if>
        <if test="customFlag != null and customFlag !=''">#{customFlag},</if>
        sysdate())
    </insert>
    <update id="updateDeviceOrder" parameterType="DeviceOrder">
        update iot_device_order
        <set>
            <if test="id != null and id != 0">
                id = #{id},
            </if>
            <if test=" erectoId!= null and erectoId != 0">
                erecto_id = #{erectoId},
            </if>
            <if test="deviceId != null and deviceId != 0">
                device_id = #{deviceId},
            </if>
            <if test="userId != null and userId != 0">
                user_id = #{userId},
            </if>
            <if test="erectoName!=null and erectoName != ''">
                erecto_name = #{erectoName},
            </if>
            <if test="erectoPhone != null and erectoPhone != ''">
                erecto_phone = #{erectoPhone},
            </if>
            <if test="userName != null and userName != ''">
                user_name = #{userName},
            </if>
            <if test="userPhone != null and userPhone != ''">
                user_phone = #{userPhone},
            </if>
            <if test="address != null and address != ''">
                address = #{address},
            </if>
            <if test="orderType != null and orderType != ''">
                order_type = #{orderType},
            </if>
            <if test="remark != null">
                remark = #{remark},
            </if>
            <if test="description != null">
                description = #{description},
            </if>
            appointment_time = #{appointmentTime},
            <if test="score != null and score != ''">score = #{score},</if>
            <if test="evaluate != null">evaluate = #{evaluate},</if>
            <if test="assginTime!= null">assgin_time = #{assginTime},</if>
            <if test="receiveTime != null">receive_time = #{receiveTime},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="state != null">state = #{state},</if>
            <if test="isRate != null">is_rate= #{isRate},</if>
            <if test="updateUserId != null and updateUserId != 0">updateuser_id = #{updateUserId},</if>
            <if test="imgUrl != null and imgUrl != ''">imgurl = #{imgUrl},</if>
            <if test="receiveTimeoutFlag != null and receiveTimeoutFlag != ''">receive_timeout_flag =
                #{receiveTimeoutFlag},
            </if>
            <if test="finishTimeoutFlag != null and finishTimeoutFlag != ''">finish_timeout_flag =
                #{finishTimeoutFlag},
            </if>
            <if test="customFlag != null and customFlag !=''">custom_flag = #{customFlag},</if>
        </set>
        where id = #{id}
    </update>
    <update id="updateDeviceOrderScoreAndComment" parameterType="DeviceOrder">
        update iot_device_order
        <set>
            <if test="id != null and id != 0">
                id = #{id},
            </if>
            <if test=" erectoId!= null and erectoId != 0">
                erecto_id = #{erectoId},
            </if>
            <if test="deviceId != null and deviceId != 0">
                device_id = #{deviceId},
            </if>
            <if test="userId != null and userId != 0">
                user_id = #{userId},
            </if>
            <if test="erectoName!=null and erectoName != ''">
                erecto_name = #{erectoName},
            </if>
            <if test="erectoPhone != null and erectoPhone != ''">
                erecto_phone = #{erectoPhone},
            </if>
            <if test="userName != null and userName != ''">
                user_name = #{userName},
            </if>
            <if test="score != null and score != ''">
                score = #{score},
            </if>
            <if test="evaluate != null">
                evaluate = #{evaluate},
            </if>
            <if test="isRate != null">
                is_rate = #{isRate},
            </if>
        </set>
        where id = #{id}
    </update>
    <delete id="deleteDeviceOrderById">
        delete
        from iot_device_order
        where id = #{id}
    </delete>
    <delete id="deleteDeviceOrder">
        delete iot_device_order where id in
        <foreach collection="idss" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>