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
<?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="org.jeecg.modules.mdc.mapper.MdcEquipmentMapper">
 
    <!--查询设备的所属部门名称信息-->
    <select id="getDepNamesByEquipmentIds" resultType="org.jeecg.modules.mdc.vo.MdcEquipmentDepVo">
        SELECT d.depart_name, ed.equipment_id FROM mdc_equipment_depart ed, sys_depart d WHERE d.id = ed.dep_id AND ed.equipment_id IN
        <foreach collection="equipmentIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <!--查询设备的所属产线名称信息-->
    <select id="getProNamesByEquipmentIds" resultType="org.jeecg.modules.mdc.vo.MdcEquipmentProVo">
        SELECT p.production_name, pe.equipment_id FROM mdc_production_equipment pe, mdc_production p WHERE p.id = pe.production_id AND pe.equipment_id IN
        <foreach collection="equipmentIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <!--根据部门id查询设备列表-->
    <select id="pageListByDepId" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            me.*
        FROM
            mdc_equipment_depart med,
            mdc_equipment me
        WHERE
            med.equipment_id = me.id
            AND med.dep_id = #{ departId }
        <if test="equipmentId != null and equipmentId != '' ">
            AND me.equipment_id = #{equipmentId}
        </if>
    </select>
 
    <!--根据产线id查询设备列表-->
    <select id="pageListByProId" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            me.*
        FROM
            mdc_production_equipment mpe,
            mdc_equipment me
        WHERE
            mpe.equipment_id = me.id
            AND mpe.production_id = #{ productionId }
        <if test="equipmentId != null and equipmentId != '' ">
            AND me.equipment_id = #{equipmentId}
        </if>
    </select>
 
    <!--根据部门id查询设备-->
    <select id="queryByDepartId" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            me.*
        FROM
            mdc_equipment_depart med,
            mdc_equipment me
        WHERE
            med.equipment_id = me.id
            AND med.dep_id = #{ departId }
        ORDER BY me.equipment_id
    </select>
 
    <!--根据产线id查询设备-->
    <select id="queryByProductionId" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            me.*
        FROM
            mdc_production_equipment mpe,
            mdc_equipment me
        WHERE
            mpe.equipment_id = me.id
            AND mpe.production_id = #{ productionId }
            AND me.device_type_mdc = '1'
        ORDER BY me.equipment_id
    </select>
 
    <!--根据产线id查询设备id集合-->
    <select id="queryIdsByProductions" resultType="java.lang.String">
        SELECT
            me.equipment_id
        FROM
            mdc_equipment me
            LEFT JOIN mdc_production_equipment mpe ON me.id = mpe.equipment_id
        WHERE
            mpe.production_id IN
        <foreach collection="allProductionIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <!--根据产线id查询设备id集合-->
    <select id="getEquipmentList" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
        me.*
        FROM
        mdc_equipment me
        LEFT JOIN mdc_production_equipment mpe ON me.id = mpe.equipment_id
        WHERE
        mpe.production_id IN
        <foreach collection="allProductionIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <!--查询设备监控信息-->
    <select id="checkStatusFromEquipmentIds" resultType="org.jeecg.modules.mdc.entity.MdcEquipmentMonitor">
        SELECT
          t1.equipment_id,
          t2.CollectTime,
          t1.equipment_name,
        CASE
 
            WHEN repair.count > 0 THEN
            '5' ELSE t2.Oporation
          END AS Oporation,
          t1.id,
          t1.equipment_status,
          t1.equipment_type equipmentType,
          t1.equipment_image equipmentTypePictures
 
        FROM
          mdc_equipment t1
          LEFT JOIN Equipment t2 ON t1.equipment_id = t2.EquipmentID
          LEFT JOIN (
            SELECT
              e1.equipment_code,
              COUNT(1) COUNT
            FROM
              eam_report_repair r1
              INNER JOIN eam_equipment e1 ON e1.id = r1.equipment_id
            WHERE
              r1.report_status NOT IN ('COMPLETE', 'ABOLISH')
          GROUP BY
            e1.equipment_code) repair ON repair.equipment_code = t1.equipment_id
        WHERE t1.equipment_id IN
        <foreach collection="equipmentIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <!--根据部门id查询设备id集合-->
    <select id="queryIdsByDeparts" resultType="java.lang.String">
        SELECT
            me.equipment_id
        FROM
            mdc_equipment me
            LEFT JOIN mdc_equipment_depart med ON me.id = med.equipment_id
        WHERE
        med.dep_id IN
        <foreach collection="allDepartIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <!--根据设备编号查询设备信息和部门信息-->
    <select id="findEquDepList" resultType="org.jeecg.modules.mdc.dto.MdcEquDepDto">
        SELECT
            sd.id,
            sd.parent_id,
            sd.depart_name,
            sd.org_type,
            me.equipment_id,
            me.equipment_name,
            me.equipment_type
        FROM
            mdc_equipment_depart med
            LEFT JOIN sys_depart sd ON med.dep_id = sd.id
            LEFT JOIN mdc_equipment me ON me.id = med.equipment_id
        <where>
            me.equipment_id IN
            <foreach collection="equipmentIdList" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>
        ORDER BY sd.depart_order
    </select>
 
    <!--根据设备编号查询设备信息和产线信息-->
    <select id="findEquProList" resultType="org.jeecg.modules.mdc.dto.MdcEquProDto">
        SELECT
            mp.id,
            mp.parent_id,
            mp.production_name,
            mp.org_type,
            me.equipment_id,
            me.equipment_name,
            me.equipment_type
        FROM
            mdc_production_equipment mpe
            LEFT JOIN mdc_production mp ON mpe.production_id = mp.id
            LEFT JOIN mdc_equipment me ON me.id = mpe.equipment_id
        <where>
            me.equipment_id IN
            <foreach collection="equipmentIdList" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>
        ORDER BY mp.production_order
    </select>
 
    <!--根据大屏车间id查询设备列表-->
    <select id="getEquipmentByWorkshopId" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            me.*
        FROM
            mdc_workshop_equipment mwe
            LEFT JOIN mdc_equipment me ON me.equipment_id = mwe.equipment_id
        <where>
            AND mwe.workshop_id = #{ workshopEquipmentVo.workshopId }
            <if test="workshopEquipmentVo.equipmentId != null and workshopEquipmentVo.equipmentId != ''">
                AND mwe.equipment_id = #{ workshopEquipmentVo.equipmentId }
            </if>
        </where>
        ORDER BY me.equipment_id
    </select>
 
    <!--分页列表-->
    <select id="pageList" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            t1.*
        FROM
            mdc_equipment t1
            LEFT JOIN mdc_production_equipment t2 ON t1.id = t2.equipment_id
            LEFT JOIN mdc_production t3 ON t2.production_id = t3.id
        <where>
            <if test="mdcEquipment.equipmentId != null and mdcEquipment.equipmentId != '' ">
                AND t1.equipment_id LIKE CONCAT(CONCAT('%',#{mdcEquipment.equipmentId}),'%')
            </if>
            <if test="mdcEquipment.equipmentName != null and mdcEquipment.equipmentName != '' ">
                AND t1.equipment_name LIKE CONCAT(CONCAT('%',#{mdcEquipment.equipmentName}),'%')
            </if>
            <if test="mdcEquipment.equipmentModel != null and mdcEquipment.equipmentModel != '' ">
                AND t1.equipment_name = #{mdcEquipment.equipmentModel}
            </if>
            <if test="mdcEquipment.equipmentType != null and mdcEquipment.equipmentType != '' ">
                AND t1.equipmentType = #{mdcEquipment.equipmentType}
            </if>
            <if test="mdcEquipment.driveType != null and mdcEquipment.driveType != '' ">
                AND t1.drive_type = #{mdcEquipment.driveType}
            </if>
            <if test="mdcEquipment.deviceLevel != null and mdcEquipment.deviceLevel != '' ">
                AND t1.device_level = #{mdcEquipment.deviceLevel}
            </if>
            <if test="mdcEquipment.deviceCategory != null and mdcEquipment.deviceCategory != '' ">
                AND t1.device_category = #{mdcEquipment.deviceCategory}
            </if>
            <if test="mdcEquipment.productionIds != null and mdcEquipment.productionIds.size() > 0 ">
                AND t3.id IN
                <foreach collection="mdcEquipment.productionIds" index="index" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
        order by t1.sort_no
    </select>
 
    <select id="exportXlsList" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            t1.*
        FROM
            mdc_equipment t1
            LEFT JOIN mdc_production_equipment t2 ON t1.id = t2.equipment_id
            LEFT JOIN mdc_production t3 ON t2.production_id = t3.id
        <where>
            <if test="mdcEquipment.equipmentId != null and mdcEquipment.equipmentId != '' ">
                AND t1.equipment_id LIKE CONCAT(CONCAT('%',#{mdcEquipment.equipmentId}),'%')
            </if>
            <if test="mdcEquipment.equipmentName != null and mdcEquipment.equipmentName != '' ">
                AND t1.equipment_name LIKE CONCAT(CONCAT('%',#{mdcEquipment.equipmentName}),'%')
            </if>
            <if test="mdcEquipment.equipmentModel != null and mdcEquipment.equipmentModel != '' ">
                AND t1.equipment_name = #{mdcEquipment.equipmentModel}
            </if>
            <if test="mdcEquipment.equipmentType != null and mdcEquipment.equipmentType != '' ">
                AND t1.equipment_type = #{mdcEquipment.equipmentType}
            </if>
            <if test="mdcEquipment.driveType != null and mdcEquipment.driveType != '' ">
                AND t1.drive_type = #{mdcEquipment.driveType}
            </if>
            <if test="mdcEquipment.productionIds != null and mdcEquipment.productionIds.size() > 0 ">
                AND t3.id IN
                <foreach collection="mdcEquipment.productionIds" index="index" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
        order by t1.sort_no
    </select>
 
    <!--查询单表数据-->
    <select id="findWorkLineLast" resultType="org.jeecg.modules.mdc.dto.MdcEquipmentDto">
        select top 1 spindlespeed, actualspindlespeed from [${tableName}] order by CollectTime  desc
    </select>
 
    <!--根据id获取设备信息-->
    <select id="findById" resultType="org.jeecg.modules.mdc.dto.MdcEquipmentDetailedDto">
        SELECT
            t1.*,
            t2.MaxAxis maxAxis,
            t2.ValidAxis validAxis
        FROM
            mdc_equipment t1
                LEFT JOIN EquipmentBaseInfo t2 ON t1.equipment_id = t2.EquipmentID
        WHERE
            t1.id = #{ id }
    </select>
 
    <select id="queryByProductionIdAndType" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
        me.*,
        mpe.production_id
        FROM
        mdc_production_equipment mpe,
        mdc_equipment me
        WHERE
        mpe.equipment_id = me.id
        AND mpe.production_id = #{ productionId }
        AND me.device_type_dnc = '1'
        <if test="deviceIds != null and deviceIds.size() > 0">
            AND me.id IN
            <foreach collection = "deviceIds" item = "id" index = "index" open = "(" close= ")" separator = ",">
                #{id}
            </foreach>
        </if>
        ORDER BY me.equipment_id
    </select>
 
    <select id="findByProductionIds" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            t1.*
        FROM
            mdc_equipment t1
                LEFT JOIN mdc_production_equipment t2 ON t1.id = t2.equipment_id
        WHERE t2.production_id IN
        <foreach collection="mdcProductionIds" item = "productionId" index = "index" open = "(" close= ")" separator = ",">
            #{productionId}
        </foreach>
    </select>
 
    <select id="findByProIdsAndTeamCode" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            t1.*
        FROM
            mdc_equipment t1
                LEFT JOIN mdc_production_equipment t2 ON t1.id = t2.equipment_id
        WHERE t2.production_id IN
        <foreach collection="mdcProductionIds" item = "productionId" index = "index" open = "(" close= ")" separator = ",">
            #{productionId}
        </foreach>
        AND t1.team_code IN
        <foreach collection="teamCodeList" item = "teamCode" index = "index" open = "(" close= ")" separator = ",">
            #{teamCode}
        </foreach>
    </select>
 
    <select id="findByProIdsAndType" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            t1.*
        FROM
            mdc_equipment t1
                LEFT JOIN mdc_production_equipment t2 ON t1.id = t2.equipment_id
        WHERE t2.production_id IN
        <foreach collection="mdcProductionIds" item = "productionId" index = "index" open = "(" close= ")" separator = ",">
            #{productionId}
        </foreach>
        AND t1.equipment_type IN
        <foreach collection="typeList" item = "equipmentType" index = "index" open = "(" close= ")" separator = ",">
            #{equipmentType}
        </foreach>
    </select>
 
    <select id="queryByDepartIdsAndType" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
            e.*,
        ep.production_id
        FROM
        mdc_equipment e
        INNER JOIN mdc_production_equipment ep ON e.id = ep.equipment_id
        WHERE
        ep.production_id IN
        <foreach collection='productionIds' item='id' open='(' separator=',' close=')'>
            #{id}
        </foreach>
        AND e.id IN
        <foreach collection='deviceIds' item='deviceId' open='(' separator=',' close=')'>
            #{deviceId}
        </foreach>
    </select>
 
    <select id="getEquIdsByProIds" resultType="java.lang.String">
        SELECT
        t1.equipment_id
        FROM
        mdc_equipment t1
        LEFT JOIN mdc_production_equipment t2 ON t1.id = t2.equipment_id
        <where>
            t2.production_id IN
            <foreach collection="proIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>
    </select>
 
</mapper>