wangfei
2025-10-11 d3df1630ad3e1c71b61d177ee818d5c5c94e97c0
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
<?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.HollowGlassRelationInfoMapper">
 
    <resultMap id="baseMap" type="com.mes.hollow.entity.dto.HollowGlassDetailsDTO">
        <result column="process_id" property="flowCardId"/>
        <result column="child_width" property="width"/>
        <result column="child_height" property="height"/>
        <result column="order_number" property="orderSort"/>
        <result column="technology_number" property="layer"/>
        <result column="quantity" property="quantity"/>
    </resultMap>
    <resultMap id="lackBaseMap" type="com.mes.hollow.entity.dto.LackDetailsDTO">
        <result column="flow_card_id" property="flowCardId"/>
        <result column="layer" property="layer"/>
        <result column="glass_type" property="glassType"/>
        <result column="filmsid" property="filmsId"/>
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="thickness" property="thickness"/>
        <result column="lack_count" property="lackCount"/>
        <result column="damage_count" property="damageCount"/>
    </resultMap>
 
    <select id="queryFlowCardIdMaxLayerGlassInfo" resultMap="baseMap">
        with temp_flow as (SELECT t.process_id,
                                  t.order_id,
                                  t.order_number,
                                  t.technology_number,
                                  t.quantity,
                                  t1.child_width,
                                  t1.child_height
 
                           from pp.flow_card t
                                    LEFT JOIN sd.order_glass_detail t1
                                              on t.order_id = t1.order_id
                                                  and t.order_number = t1.order_number
                                                  and t.technology_number = t1.technology_number
                           where t.process_id = #{flowCardId}),
             glass_info_temp as (
                 select process_id,
                        order_id,
                        GREATEST(child_width, child_height) as first_length,
                        least(child_width, child_height)    as second_length,
                        child_width,
                        child_height,
                        order_number,
                        technology_number,
                        quantity
                 from temp_flow
                 where technology_number = #{totalLayer}
             )
        select row_number() over (order by second_length desc,first_length desc) as rn, t.*
        from glass_info_temp t
    </select>
 
    <select id="queryFlowCardIdLayerGlassInfo" resultMap="baseMap">
        with temp_flow as (SELECT t.process_id,
                                  t.order_id,
                                  t.order_number,
                                  t.technology_number,
                                  t.quantity,
                                  t1.child_width,
                                  t1.child_height
                           from pp.flow_card t
                                    LEFT JOIN sd.order_glass_detail t1
                                              on t.order_id = t1.order_id
                                                  and t.order_number = t1.order_number
                                                  and t.technology_number = t1.technology_number
                           where t.process_id = #{flowCardId}),
             glass_info_max_layer_temp as (
                 select process_id,
                        order_id,
                        GREATEST(child_width, child_height) as first_length,
                        least(child_width, child_height)    as second_length,
                        child_width,
                        child_height,
                        order_number,
                        technology_number,
                        quantity
                 from temp_flow
                 where technology_number = #{totalLayer}
             ),
             glass_info_layer_temp as (
                 select process_id,
                        order_id,
                        GREATEST(child_width, child_height) as first_length,
                        least(child_width, child_height)    as second_length,
                        child_width,
                        child_height,
                        order_number,
                        technology_number,
                        quantity
                 from temp_flow
                 where technology_number = #{layer}
             ),
             max_layer_sequence as (
                 select row_number() over (order by second_length desc,first_length desc) as rn, t.order_number
                 from glass_info_max_layer_temp t
             ),
             result as (select t.*
                        from glass_info_layer_temp t
                                 INNER join max_layer_sequence t1 on t.order_number = t1.order_number
                        order by t1.rn)
        select *
        from result
    </select>
    <select id="queryAllLackByFlowCard" resultMap="lackBaseMap">
        WITH flow_card_id_info AS (
            SELECT DISTINCT flow_card_id
            FROM hollow_big_storage_cage_details
            WHERE state = 100
        ),
             glass_temp AS (
                 SELECT t.*
                 FROM glass_info t
                          INNER JOIN flow_card_id_info t1 ON t.flow_card_id = t1.flow_card_id
             ),
             detail_temp AS (
                 SELECT t.*
                 FROM glass_temp t
                 WHERE NOT EXISTS (
                         SELECT 1
                         FROM hollow_big_storage_cage_details t1
                         WHERE t1.glass_id = t.glass_id
                           AND t1.state NOT IN (8,9)
                     )
             ),
             damage_latest AS (
                 SELECT
                     dr.glass_id,
                     dr.type,
                     dr.status
                 FROM (
                          SELECT
                              t1.glass_id,
                              t1.type,
                              t1.status,
                              ROW_NUMBER() OVER(PARTITION BY t1.glass_id ORDER BY t1.id DESC) as rn
                          FROM detail_temp t
                                   INNER JOIN damage t1 ON t.flow_card_id = t1.process_id
                      ) dr
                 WHERE dr.rn = 1
             ),
             result_temp AS (
                 SELECT
                     t.flow_card_id,
                     t.layer,
                     t.glass_type,
                     t.thickness,
                     t.filmsId,
                     t.width,
                     t.height,
                     COUNT(DISTINCT t.glass_id) as lack_count,
                     COUNT(DISTINCT CASE WHEN t1.type IN (7,8) AND t1.status = 1 THEN t.glass_id END) as damage_count
                 FROM detail_temp t
                          LEFT JOIN damage_latest t1 ON t.glass_id = t1.glass_id
                 GROUP BY
                     t.flow_card_id,
                     t.layer,
                     t.glass_type,
                     t.thickness,
                     t.filmsId,
                     t.width,
                     t.height
             )
        SELECT *
        FROM result_temp
        ORDER BY flow_card_id, layer;
    </select>
    <select id="queryLayerByFlowCardId" resultType="java.lang.Integer">
        select count(distinct layer)
        from hollow_glass_relation_info
        where flow_card_id = #{flowCardId}
    </select>
    <select id="queryProductNameByFlowCardId" resultType="com.mes.hollow.entity.dto.OrderDetailsDTO">
        select t.product_name, t1.customer_name
        from sd.order_detail t
        inner join sd.order t1 on t.order_id = t1.order_id
        where (t.order_id, t.order_number) = (
        select min(order_id) as order_id, min(order_number) as order_number
        from pp.flow_card
        where process_id = #{flowCardId}
        <if test="productName != null and productName != ''">
            and t.product_name like concat('%', #{productName}, '%')
        </if>
        <if test="customerName != null and customerName != ''">
            and t1.customer_name like concat('%', #{customerName}, '%')
        </if>
        )
        limit 1
    </select>
    <select id="queryLackGlassByFlowCard" resultType="com.mes.glassinfo.entity.GlassInfo">
        with glass_id_info as (
        select glass_id,order_sort from hollow_glass_relation_info where flow_card_id=#{flowCardId} and
        order_sort=#{orderSort} and layer=#{layer} and glass_id is not null
        ),
        damage_glass_id as (
        select glass_id from damage where process_id=#{flowCardId} and order_number=#{orderSort} and
        technology_number=#{layer} and type=8 and status &lt; 3 and glass_id is not null
        )
        select t.* from glass_info t left join glass_id_info t1 on t.glass_id=t1.glass_id
        left join damage_glass_id t2 on t.glass_id=t2.glass_id
        where t.flow_card_id=#{flowCardId} and t.glass_type=#{orderSort} and t.layer=#{layer} and t1.glass_id is null
        and t2.glass_id is null
    </select>
    <select id="queryLackByFlowCard" resultType="com.mes.hollow.entity.dto.LackDetailsDTO">
        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 = #{flowCardId}
        </if>
        )
           , glass_temp as (
            select t1.*
            from hollow_flow_temp t
                     INNER JOIN glass_info t1 on t.flow_card_id = t1.flow_card_id
        )
           , detail_temp as (
            select t.*
            from glass_temp t
                     left join hollow_big_storage_cage_details t1 on t.glass_id = t1.glass_id and t1.state  not in (8,9)
            where t1.glass_id is null
        )
           , damage_ranked AS (
            SELECT t.flow_card_id,
                   t.layer,
                   t.glass_id,
                   t.glass_type,
                   t.width,
                   t.height,
                   t.filmsId,
                   t.thickness,
                   case
                       when type in (7, 8) and status = 1 then ''
                       else t1.working_procedure end                                as working_procedure,
                   ROW_NUMBER() OVER (PARTITION BY t1.glass_id ORDER BY t1.id DESC) as rn
            FROM detail_temp t
                     inner join damage t1 on t.glass_id = t1.glass_id
        )
           , damage_latest AS (
            SELECT *
            FROM damage_ranked
            WHERE rn = 1
        )
        select *
        from damage_latest
 
    </select>
 
    <update id="clearDirtyFlowCardData">
        update tempering_glass_relation_info
        set shelf_order = null
          , state       = 0
        where flow_card_id = #{flowCardId}
          and layer = #{layer}
          and shelf_order not in (
            select shelf_order
            from vertical_sheet_cage_details
            where flow_card_id = #{flowCardId}
              and layer = #{layer}
              and state in (100, 102, 103, 104)
        )
    </update>
</mapper>