zhoushihao
4 天以前 4e3b8155722b66e25df3c6fd42cc586b68dea391
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
<?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.bigstorage.mapper.BigStorageCageDetailsMapper">
 
    <resultMap id="temperingLayoutDTO" type="com.mes.bigstorage.entity.dto.TemperingLayoutDTO">
        <result column="engineer_id" property="engineerId"/>
        <result column="tempering_layout_id" property="temperingLayoutId"/>
        <result column="count" property="count"/>
        <result column="slot_count" property="slotCount"/>
    </resultMap>
 
    <resultMap id="slotSequenceDTO" type="com.mes.bigstorage.entity.dto.SlotSequenceDTO">
        <result column="engineer_id" property="engineerId"/>
        <result column="tempering_layout_id" property="temperingLayoutId"/>
        <result column="slot" property="slot"/>
        <result column="glass_count" property="glassCount"/>
        <result column="max_sequence" property="maxSequence"/>
        <result column="min_sequence" property="minSequence"/>
        <result column="remain_width" property="remainWidth"/>
    </resultMap>
 
    <resultMap id="virtualSlotSequenceDTO" type="com.mes.bigstorage.entity.dto.BigStorageRelationDTO">
        <result column="engineer_id" property="engineerId"/>
        <result column="tempering_layout_id" property="temperingLayoutId"/>
        <result column="virtual_slot" property="virtualSlot"/>
    </resultMap>
    <resultMap id="baseSlotSequenceDTO" type="com.mes.bigstorage.entity.dto.BigStorageSequenceDTO">
        <result column="slot" property="slot"/>
        <result column="max_sequence" property="maxSequence"/>
        <result column="min_sequence" property="minSequence"/>
    </resultMap>
 
    <resultMap id="temperingGlassCount" type="com.mes.bigstorage.entity.dto.TemperingGlassCountDTO">
        <result column="engineer_id" property="engineerId"/>
        <result column="tempering_layout_id" property="temperingLayoutId"/>
        <result column="films_id" property="filmsId"/>
        <result column="thickness" property="thickness"/>
        <result column="total_count" property="totalCount"/>
        <result column="real_count" property="realCount"/>
        <result column="damage_count" property="damageCount"/>
        <result column="lack_count" property="lackCount"/>
    </resultMap>
 
    <resultMap id="glassInfoLackDTO" type="com.mes.bigstorage.entity.dto.GlassInfoLackDTO">
        <result column="flow_card_id" property="flowCardId"/>
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="thickness" property="thickness"/>
        <result column="filmsid" property="filmsid"/>
        <result column="total_layer" property="totalLayer"/>
        <result column="layer" property="layer"/>
        <result column="tempering_layout_id" property="temperingLayoutId"/>
        <result column="tempering_feed_sequence" property="temperingFeedSequence"/>
        <result column="x_coordinate" property="xCoordinate"/>
        <result column="y_coordinate" property="yCoordinate"/>
        <result column="angle" property="angle"/>
        <result column="engineer_id" property="engineerId"/>
        <result column="glass_id" property="glassId"/>
        <result column="is_damage" property="isDamage"/>
    </resultMap>
 
    <select id="temperingIsAll" resultMap="temperingLayoutDTO">
        SELECT T2.*
        FROM (
                 SELECT T.ENGINEER_ID,
                        T.TEMPERING_LAYOUT_ID,
                        COUNT(T.TEMPERING_FEED_SEQUENCE) AS COUNT
                 FROM GLASS_INFO T
                          LEFT JOIN DAMAGE T1
                                    ON T.ENGINEER_ID = T1.ENGINEER_ID
                                        AND T.GLASS_ID = T1.GLASS_ID
                                        AND (T1.TYPE = 8
                                            OR T1.TYPE = 9)
                 WHERE T1.GLASS_ID IS NULL
                 GROUP BY T.ENGINEER_ID,
                          T.TEMPERING_LAYOUT_ID
             ) T2
                 INNER JOIN (SELECT ENGINEER_ID, TEMPERING_LAYOUT_ID, COUNT(TEMPERING_FEED_SEQUENCE) AS COUNT
                             FROM BIG_STORAGE_CAGE_DETAILS
                             WHERE STATE in (100)
                             GROUP BY ENGINEER_ID, TEMPERING_LAYOUT_ID) T3 ON T2.ENGINEER_ID = T3.ENGINEER_ID
            AND T2.TEMPERING_LAYOUT_ID = T3.TEMPERING_LAYOUT_ID
            AND T2.COUNT = T3.COUNT
                 INNER JOIN ENGINEERING T4 ON T2.ENGINEER_ID = T4.ENGINEER_ID
        ORDER BY T4.ID, T2.TEMPERING_LAYOUT_ID
    </select>
 
    <select id="queryTemperingOccupySlot" resultMap="temperingLayoutDTO">
        SELECT ENGINEER_ID,
               TEMPERING_LAYOUT_ID,
               COUNT(DISTINCT SLOT) as SLOT_COUNT
        FROM BIG_STORAGE_CAGE_DETAILS
        WHERE STATE = 100
        GROUP BY ENGINEER_ID,
                 TEMPERING_LAYOUT_ID
        HAVING SLOT_COUNT &gt;= #{count}
        ORDER BY SLOT_COUNT DESC
    </select>
    <select id="queryGlassMaxAndMin" resultMap="slotSequenceDTO">
        SELECT T.*,
               T1.REMAIN_WIDTH
        FROM (
                 SELECT ENGINEER_ID,
                        TEMPERING_LAYOUT_ID,
                        SLOT,
                        count(*)                     as glass_count,
                        MAX(TEMPERING_FEED_SEQUENCE) AS MAX_SEQUENCE,
                        MIN(TEMPERING_FEED_SEQUENCE) AS MIN_SEQUENCE
                 FROM BIG_STORAGE_CAGE_DETAILS
                 WHERE ENGINEER_ID = #{engineerId}
                   AND TEMPERING_LAYOUT_ID = #{temperingLayoutId}
                 GROUP BY ENGINEER_ID,
                          TEMPERING_LAYOUT_ID,
                          SLOT
             ) T
                 INNER JOIN BIG_STORAGE_CAGE T1 ON T.SLOT = T1.SLOT
        ORDER BY T.MAX_SEQUENCE DESC
    </select>
 
    <update id="updateBySlot">
        update 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 !=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="selectTemperingGlassCount" resultMap="temperingGlassCount">
        with glass_info_temp as (
        select engineer_id, tempering_layout_id, count(*) as total_count
        from glass_info
        group by engineer_id, tempering_layout_id
        ),
        big_details_temp as (
        select engineer_id, tempering_layout_id, count(*) as real_count, films_id, thickness
        from big_storage_cage_details
        where state = 100
        <if test="isTempering == 0">
            and tempering_layout_id = 0
        </if>
        <if test="isTempering == 1">
            and tempering_layout_id != 0
        </if>
 
        group by engineer_id, tempering_layout_id, films_id, thickness
        ),
        damage_temp as (
        select engineer_id, tempering_layout_id, count(*) as damage_count
        from damage
        where type in(8,9)
        group by engineer_id, tempering_layout_id
        ),
        result as (
        select t.engineer_id,
        t.tempering_layout_id,
        t.films_id,
        t.thickness,
        total_count,
        real_count,
        ifnull(damage_count, 0) as damage_count,
        case when total_count - real_count - ifnull(damage_count, 0) &lt; 0 then 0 else
        total_count - real_count - ifnull(damage_count, 0) end as lack_count
        from big_details_temp t
        inner join glass_info_temp t1 on t.engineer_id = t1.engineer_id and
        t.tempering_layout_id = t1.tempering_layout_id
        left join damage_temp t2
        on t.engineer_id = t2.engineer_id and t.tempering_layout_id = t2.tempering_layout_id
        )
        select *
        from result
        order by engineer_id,tempering_layout_id
    </select>
 
    <select id="queryIsAllNeedDispatchVirtualSlot" resultMap="virtualSlotSequenceDTO">
        with relation_temp as (
            select engineer_id, tempering_layout_id, virtual_slot, count(1) as slot_count
            from big_storage_glass_relation_info
            group by engineer_id, tempering_layout_id, virtual_slot
        ),
             details_temp as (
                 select t.engineer_id, t.tempering_layout_id, t.virtual_slot, count(1) as slot_count
                 from big_storage_glass_relation_info t
                          left join big_storage_cage_details t1 on
                         t.engineer_id = t1.engineer_id and t.tempering_layout_id = t1.tempering_layout_id and
                         t.tempering_feed_sequence = t1.tempering_feed_sequence
                 where t1.state = 100
                 group by t.engineer_id, t.tempering_layout_id, t.virtual_slot
             ),
             result_one as (
                 select t.*, t1.slot_count as tslot_count
                 from relation_temp t
                          INNER JOIN details_temp t1 on t.engineer_id = t1.engineer_id and
                                                        t.tempering_layout_id = t1.tempering_layout_id and
                                                        t.virtual_slot = t1.virtual_slot
                 where t.slot_count = t1.slot_count
             )
        select engineer_id, tempering_layout_id, virtual_slot
        from result_one
        order by engineer_id, tempering_layout_id
    </select>
 
    <select id="queryNeedDispatchSlot" resultMap="baseSlotSequenceDTO">
        with glass_id_temp as (
            select engineer_id, tempering_layout_id, tempering_feed_sequence
            from big_storage_glass_relation_info
            where (engineer_id, tempering_layout_id, virtual_slot) =
                  (#{engineerId}, #{temperingLayoutId}, #{virtualSlot})
        )
        select t.slot, max(t1.tempering_feed_sequence) as max_sequence, min(t1.tempering_feed_sequence) as min_sequence
        from big_storage_cage_details t
                 inner join big_storage_glass_relation_info t1
                            on t.engineer_id = t1.engineer_id and t.tempering_layout_id = t1.tempering_layout_id and
                               t.tempering_feed_sequence = t1.tempering_feed_sequence
        where (t.engineer_id, t.tempering_layout_id, t.tempering_feed_sequence) in
              (select engineer_id, tempering_layout_id, tempering_feed_sequence from glass_id_temp)
          and t.state = 100
        group by t.slot
        order by max_sequence desc
    </select>
    <select id="queryLackGlassInfo" resultMap="glassInfoLackDTO">
        WITH glass_info_temp AS (SELECT *
                                 FROM glass_info
                                 WHERE engineer_id = #{engineerId}
                                   AND tempering_layout_id = #{temperingLayoutId}),
             big_details_temp AS (SELECT *
                                  FROM big_storage_cage_details
                                  WHERE state = 100
                                    AND engineer_id = #{engineerId}
                                    AND tempering_layout_id = #{temperingLayoutId}),
             damage_temp AS (SELECT *
                             FROM damage
                             WHERE type IN (8, 9)
                               AND engineer_id = #{engineerId}
                               AND tempering_layout_id = #{temperingLayoutId}),
             result_lack AS (SELECT t.*
                             FROM glass_info_temp t
                                      LEFT JOIN big_details_temp t1 ON t.glass_id = t1.glass_id
                             WHERE t1.glass_id IS NULL),
             result AS (
                 SELECT t.*,
                        CASE
 
                            WHEN t1.glass_id is null THEN
                                0
                            ELSE 1
                            END AS is_damage
                 FROM result_lack t
                          LEFT JOIN damage_temp t1 ON t.glass_id = t1.glass_id
             )
        SELECT *
        FROM result
    </select>
    <select id="querybigStorageCageDetail" resultType="com.mes.base.entity.vo.BigStorageVO">
        select bsc.device_id, bsc.slot, count(bscd.glass_id) as count
        from big_storage_cage bsc
                 left join big_storage_cage_details bscd
                           on bsc.slot = bscd.slot and bscd.state in (100, 102, 103, 104)
        group by bsc.device_id, bsc.slot
        order by bsc.device_id, bsc.slot
    </select>
</mapper>