ZengTao
2025-10-12 28682bccf1d24f53be9d03236984caa8b2ea798e
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
<?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.mes.hollow.mapper.HollowBigStorageCageDetailsMapper">
 
    <resultMap id="baseMap" type="com.mes.hollow.entity.dto.FlowCardGlassInfoDTO">
        <result column="engineer_id" property="engineerId"/>
        <result column="flow_card_id" property="flowCardId"/>
        <result column="layer" property="layer"/>
        <result column="films_id" property="filmsId"/>
        <result column="thickness" property="thickness"/>
        <result column="sum_count" property="sumCount"/>
        <result column="pair_count" property="pairCount"/>
        <result column="real_count" property="realCount"/>
        <result column="damage_count" property="damageCount"/>
        <result column="lack_count" property="lackCount"/>
    </resultMap>
    <resultMap id="virtualSlotSequenceDTO" type="com.mes.hollow.entity.dto.FlowCardVirtualSlotDTO">
        <result column="flow_card_id" property="flowCardId"/>
        <result column="layer" property="layer"/>
        <result column="virtual_slot" property="virtualSlot"/>
    </resultMap>
    <resultMap id="baseSlotSequenceDTO" type="com.mes.hollow.entity.dto.BigStorageSequenceDTO">
        <result column="slot" property="slot"/>
        <result column="max_sequence" property="maxSequence"/>
        <result column="min_sequence" property="minSequence"/>
    </resultMap>
 
    <update id="updateBySlot">
        update hollow_big_storage_cage_details
        <set>
            state = #{state}
        </set>
        <where>
            (glass_id,slot) in (
            <foreach collection="list" item="item" separator=",">
                (#{item.glassId}, #{item.targetSlot})
            </foreach>
            )
            and state not in (8, 9, 101)
        </where>
    </update>
    <update id="updateDeviceIdBySlot">
        update big_storage_cage_details t inner join big_storage_cage t1 on t.slot = t1.slot
        set t.device_id = t1.device_id
        where t.slot in (
        <foreach collection="list" item="item" separator=",">
            #{item}
        </foreach>
        )
    </update>
 
    <select id="hollowIsAll" resultMap="baseMap">
        WITH flow_layer_stats AS (
        SELECT
        h.flow_card_id,
        h.layer,
        MIN(r.films_id) AS films_id,
        MIN(r.thickness) AS thickness,
        COUNT(*) AS sum_count,
        COUNT(DISTINCT h.slot) AS slot_count,
        SUM(CASE WHEN h.state = 100 THEN 1 ELSE 0 END) AS real_count
        FROM hollow_glass_relation_info r
        LEFT JOIN hollow_big_storage_cage_details h
        ON r.flow_card_id = h.flow_card_id AND r.layer = h.layer
        WHERE r.flow_card_id = #{flowCardId}
        GROUP BY h.flow_card_id, h.layer
        ),
        damage_stats AS (
        SELECT
        process_id AS flow_card_id,
        technology_number AS layer,
        COUNT(*) AS damage_count
        FROM damage
        WHERE type IN (8,9) AND process_id = #{flowCardId}
        GROUP BY process_id, technology_number
        ),
        pair_stats AS (
        SELECT
        t1.flow_card_id,
        COUNT(*) AS pair_count
        FROM hollow_big_storage_cage_details t1
        INNER JOIN hollow_big_storage_cage_details t2
        ON t1.flow_card_id = t2.flow_card_id
        AND t1.virtual_slot = t2.virtual_slot
        AND t1.sequence = t2.sequence
        AND t1.layer = 1 AND t2.layer = 2
        AND t1.state = 100 AND t2.state = 100
        <if test="totalLayer == 3">
            INNER JOIN hollow_big_storage_cage_details t3
            ON t1.flow_card_id = t3.flow_card_id
            AND t1.virtual_slot = t3.virtual_slot
            AND t1.sequence = t3.sequence
            AND t3.layer = 3 AND t3.state = 100
        </if>
        WHERE t1.flow_card_id = #{flowCardId}
        GROUP BY t1.flow_card_id
        )
        SELECT
        f.flow_card_id,
        f.layer,
        f.films_id,
        f.thickness,
        f.sum_count,
        COALESCE(p.pair_count, 0) AS pair_count,
        COALESCE(f.real_count, 0) AS real_count,
        COALESCE(d.damage_count, 0) AS damage_count,
        (f.sum_count - COALESCE(f.real_count, 0) - COALESCE(d.damage_count, 0)) AS lack_count,
        f.slot_count
        FROM flow_layer_stats f
        LEFT JOIN damage_stats d
        ON f.flow_card_id = d.flow_card_id AND f.layer = d.layer
        LEFT JOIN pair_stats p
        ON f.flow_card_id = p.flow_card_id
        WHERE 1=1
        <if test="flag == true">
            AND f.sum_count = COALESCE(p.pair_count, 0)
        </if>
        ORDER BY f.layer;
    </select>
 
    <select id="queryIsAllNeedDispatchVirtualSlot" resultMap="virtualSlotSequenceDTO">
        with relation_temp as (
            select flow_card_id, layer, virtual_slot, count(1) as slot_count
            from hollow_glass_relation_info
            group by flow_card_id, layer, virtual_slot
        ),
             details_temp as (
                 select flow_card_id, layer, virtual_slot, count(1) as slot_count
                 from hollow_big_storage_cage_details
                 where state = 100
                 group by flow_card_id, layer, virtual_slot
             ),
             result_one as (
                 select t.*, t1.slot_count as tslot_count
                 from relation_temp t
                          INNER JOIN details_temp t1 on t.flow_card_id = t1.flow_card_id and
                                                        t.layer = t1.layer and
                                                        t.virtual_slot = t1.virtual_slot
                 where t.slot_count = t1.slot_count
             )
        select flow_card_id, layer, virtual_slot
        from result_one
        order by flow_card_id, layer, virtual_slot
    </select>
 
    <select id="queryNeedDispatchSlot" resultMap="baseSlotSequenceDTO">
        select slot, max(sequence) as max_sequence, min(sequence) as min_sequence
        from hollow_big_storage_cage_details
        where (flow_card_id, layer, virtual_slot) = (#{flowCardId}, #{layer}, #{virtualSlot})
        group by slot
        order by max_sequence
    </select>
    <select id="queryOutGlassList" resultType="com.mes.hollow.entity.HollowBigStorageCageDetails">
        with flow_card_id_layer as (
        select flow_card_id, max(total_layer) as total_layer
        FROM hollow_big_storage_cage_details
        group by flow_card_id
        ),
        details_sequence_count_temp as (
        SELECT flow_card_id, hollow_sequence, count(1) as max_count
        FROM hollow_big_storage_cage_details
        where state = 100
        group by flow_card_id, hollow_sequence
        ),
        glass_out_temp as (
        select t1.*, case when t.total_layer = t1.max_count then 1 else 0 end is_pair
        from flow_card_id_layer t
        inner join details_sequence_count_temp t1 on t.flow_card_id = t1.flow_card_id
        ),
        result_detail as (
        select t.id,
        t.device_id,
        t.virtual_slot,
        t.slot,
        t.glass_id,
        t.sequence,
        t.flow_card_id,
        t.glass_type,
        t.width,
        t.height,
        t.thickness,
        t.tempering_layout_id,
        t.tempering_feed_sequence,
        t.state,
        t.gap,
        t.engineer_id,
        t.total_layer,
        t.layer,
        t.create_time,
        t.update_time,
        t.hollow_sequence,
        t.films_id,
        t1.is_pair
        from hollow_big_storage_cage_details t
        INNER JOIN glass_out_temp t1
        on t.flow_card_id = t1.flow_card_id and t.hollow_sequence = t1.hollow_sequence
        where t.state = 100
        and t.flow_card_id = #{flowCardId}
        )
        select *
        from result_detail
        order by flow_card_id, hollow_sequence,layer
        <if test="cell != 931">
            desc
        </if>
    </select>
    <select id="queryHollowbigStorageCageDetail" resultType="com.mes.base.entity.vo.BigStorageVO">
        select hbsc.device_id, hbsc.slot, count(hbscd.glass_id) as count
        from hollow_big_storage_cage hbsc
                 left join hollow_big_storage_cage_details hbscd
                           on hbsc.slot = hbscd.slot and hbscd.state in (100, 102, 103, 104)
        group by hbsc.device_id, hbsc.slot
        order by hbsc.device_id, hbsc.slot
    </select>
    <select id="querySlotMaxSequence" resultType="com.mes.hollow.entity.HollowBigStorageCageDetails">
        select max(sequence) as sequence, device_id, slot
        from hollow_big_storage_cage_details
        where (flow_card_id, total_layer, layer, virtual_slot) =
              (#{flowCardId}, #{totalLayer}, #{layer}, #{virtualSlot})
          and state in (0, 100, 102, 103, 104)
        group by device_id, slot
        order by sequence
    </select>
    <select id="queryPairGlassList" resultType="com.mes.hollow.entity.HollowBigStorageCageDetails">
        with hollow_sequence_temp as (
        SELECT hollow_sequence, count(distinct layer) as count
        FROM hollow_big_storage_cage_details
        WHERE flow_card_id = #{flowCardId}
        <if test="isOut == 0">
            AND STATE = 100
        </if>
 
        GROUP BY hollow_sequence
        having count = #{totalLayer}
        limit #{totalPairQuantity}
        ),
        hollow_details as (select *
        from hollow_big_storage_cage_details
        WHERE flow_card_id = #{flowCardId}
        <if test="isOut == 0">
            AND STATE = 100
        </if>
        )
        select *
        from hollow_details t
        inner join hollow_sequence_temp t1 on t.hollow_sequence = t1.hollow_sequence
        ORDER BY t.hollow_sequence
    </select>
    <select id="queryFlowCardIdsAndLayer" resultType="com.mes.hollow.entity.dto.FlowCardVirtualSlotDTO">
        select flow_card_id, layer
        from hollow_big_storage_cage_details
        where state in (100, 102, 103, 104)
        group by flow_card_id, layer
    </select>
 
    <select id="queryHollowAllFlowCard" resultType="com.mes.hollow.entity.dto.FlowCardGlassInfoDTO">
        WITH hollow_flow_temp AS (
        SELECT DISTINCT flow_card_id
        FROM hollow_big_storage_cage_details
        WHERE state = 100
        <if test="flowCardId != null and flowCardId != ''">
            AND flow_card_id LIKE CONCAT('%', #{flowCardId}, '%')
        </if>
        <if test="filmsId != null and filmsId != ''">
            AND films_id LIKE CONCAT('%', #{filmsId}, '%')
        </if>
        <if test="thickness != 0">
            AND thickness = #{thickness}
        </if>
        ),
        hollow_details_temp AS (
        SELECT
        flow_card_id,
        glass_id,
        virtual_slot,
        sequence,
        layer,
        total_layer,
        hollow_sequence
        FROM hollow_big_storage_cage_details
        WHERE state = 100
        <if test="flowCardId != null and flowCardId != ''">
            AND flow_card_id LIKE CONCAT('%', #{flowCardId}, '%')
        </if>
        <if test="filmsId != null and filmsId != ''">
            AND films_id LIKE CONCAT('%', #{filmsId}, '%')
        </if>
        <if test="thickness != 0">
            AND thickness = #{thickness}
        </if>
        ),
        hollow_through_temp AS (
        SELECT
        flow_card_id,
        MIN(hollow_sequence) as hollow_sequence,
        MAX(total_layer) as total_layer
        FROM hollow_details_temp
        GROUP BY flow_card_id
        ),
        hollow_pair_temp AS (
        SELECT
        t1.flow_card_id,
        COUNT(*) AS pair_count
        FROM hollow_details_temp t1
        INNER JOIN hollow_details_temp t2
        ON t1.flow_card_id = t2.flow_card_id
        AND t1.virtual_slot = t2.virtual_slot
        AND t1.sequence = t2.sequence
        AND t1.layer = 1 AND t2.layer = 2
        WHERE NOT EXISTS (
        SELECT 1
        FROM hollow_through_temp ht
        WHERE ht.flow_card_id = t1.flow_card_id
        AND ht.total_layer = 3
        ) OR EXISTS (
        SELECT 1
        FROM hollow_details_temp t3
        WHERE t3.flow_card_id = t1.flow_card_id
        AND t3.virtual_slot = t1.virtual_slot
        AND t3.sequence = t1.sequence
        AND t3.layer = 3
        )
        GROUP BY t1.flow_card_id
        ),
        glass_info_temp AS (
        SELECT
        gi.id,
        gi.glass_id,
        gi.flow_card_id,
        gi.layer,
        gi.thickness,
        gi.filmsId
        FROM hollow_flow_temp hft
        INNER JOIN glass_info gi ON hft.flow_card_id = gi.flow_card_id
        ),
        damage_ranked AS (
        SELECT
        d.glass_id,
        d.type,
        d.status,
        ROW_NUMBER() OVER(PARTITION BY d.glass_id ORDER BY d.id DESC) as rn
        FROM hollow_flow_temp hft
        INNER JOIN damage d ON hft.flow_card_id = d.process_id
        ),
        damage_latest AS (
        SELECT
        glass_id,
        type,
        status
        FROM damage_ranked
        WHERE rn = 1
        ),
        result_temp AS (
        SELECT
        t.flow_card_id,
        t.layer,
        t.thickness,
        t.filmsId,
        COUNT(DISTINCT t.id) as sum_count,
        COUNT(DISTINCT t1.glass_id) as real_count,
        COUNT(DISTINCT t.id) - COUNT(DISTINCT t1.glass_id) as lack_count,
        COUNT(DISTINCT CASE WHEN t2.type IN (8,9) AND t2.status = 1 THEN t.glass_id END) as damage_count
        FROM glass_info_temp t
        LEFT JOIN hollow_details_temp t1 ON t.glass_id = t1.glass_id
        LEFT JOIN damage_latest t2 ON t.glass_id = t2.glass_id
        GROUP BY t.flow_card_id, t.layer, t.thickness, t.filmsId
        )
        SELECT
        t.*,
        COALESCE(t1.pair_count, 0) as pair_count,
        t2.hollow_sequence,
        t2.total_layer
        FROM result_temp t
        LEFT JOIN hollow_pair_temp t1 ON t.flow_card_id = t1.flow_card_id
        LEFT JOIN hollow_through_temp t2 ON t.flow_card_id = t2.flow_card_id
        ORDER BY t.flow_card_id
    </select>
 
 
</mapper>