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
<?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="films_id" property="filmsId"/>
        <result column="first_length" property="width"/>
        <result column="second_Length" property="height"/>
        <result column="thickness" property="thickness"/>
        <result column="lack_cout" property="lackCount"/>
    </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="queryLackByFlowCard" resultMap="lackBaseMap">
        with relation_length as (
            select flow_card_id,
                   layer,
                   tempering_layout_id,
                   tempering_feed_sequence,
                   GREATEST(width, height) as first_length,
                   LEAST(width, height)    as second_Length,
                   width,
                   height,
                   thickness,
                   films_id
            from hollow_glass_relation_info
            where flow_card_id = #{flowCardId}
              and tempering_layout_id is null
              and tempering_feed_sequence is null
        )
        select flow_card_id, layer, first_length, films_id, second_Length, thickness, count(*) as lack_cout
        from relation_length
        group by flow_card_id, layer, films_id, first_length, second_Length, thickness
    </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="java.lang.String">
        select product_name
        from sd.order_detail
        where (order_id, order_number) = (
            select min(order_id) as order_id, min(order_number) as order_number
            from pp.flow_card
            where process_id = #{flowCardId}
        )
        limit 1
    </select>
 
    <update id="clearDirtyFlowCardData">
        update hollow_glass_relation_info
        set glass_id                = null,
            tempering_layout_id     = null,
            tempering_feed_sequence = null,
            engineer_id             = null,
            state                   = 0
        where flow_card_id = #{flowCardId}
          and layer = #{layer}
          and glass_id not in (
            select glass_id
            from hollow_big_storage_cage_details
            where flow_card_id = #{flowCardId}
              and layer = #{layer}
              and state in (100, 102, 103, 104)
        )
    </update>
</mapper>