ZengTao
2025-11-29 4dc1abb37aec033fdbd09d290c6f62d082ba774a
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
<?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.order.mapper.OrdersMapper">
    <resultMap id="baseMap" type="com.mes.order.entity.dto.OrderDTO">
        <result column="order_id" property="orderId"/>
        <result column="customer_name" property="customerName"/>
        <result column="project" property="project"/>
        <result column="area" property="area"/>
        <result column="quantity" property="quantity"/>
        <result column="create_time" property="createTime"/>
        <result column="percent" property="percent"/>
    </resultMap>
    <resultMap id="baseMapHollowDetail" type="com.mes.order.entity.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>
    <select id="selectOrderPercent" resultMap="baseMap">
        SELECT a.order_id,
               a.customer_name,
               a.project,
               a.area,
               a.quantity,
               a.create_time,
               round(ifnull(d.finishNum, 0) / a.quantity * 100) as 'percent', ifnull(d.finishNum, 0)
        from sd.`order` as a
                 LEFT JOIN (
            SELECT sum(c.reporting_work_num) as 'finishNum',order_id
            from sd.order_process_detail as c
            where c.id in (
                SELECT max(id) from sd.order_process_detail as b GROUP BY b.process_id, order_number
            )
            GROUP BY c.order_id
        ) as d
                           on a.order_id = d.order_id
        where a.warehousing != 2 and a.warehousing >= 0
        ORDER BY a.order_id desc
    </select>
    <select id="queryOrderByFlowCardId" resultType="com.mes.order.entity.HollowOrderDTO">
        select t1.*
        from pp.flow_card t
                 inner join sd.order t1 on t.order_id = t1.order_id
        where t.process_id = #{flowCardId} limit 1
    </select>
    <select id="queryFlowCardIdMaxLayerGlassInfo" resultMap="baseMapHollowDetail">
        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="baseMapHollowDetail">
        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="queryProductNameByFlowCardId" resultType="com.mes.order.entity.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}
        ) limit 1
    </select>
    <select id="queryLackByERP" resultType="com.mes.order.entity.ProcessCardReport">
        select a.*,
               (b.quantity - b.termination_quantity) as 'quantity',
                (b.quantity - b.termination_quantity - reporting_work_num) as 'lack_quantity'
        from order_process_detail as a
                 inner join pp.flow_card as b
                            on a.order_id = b.order_id
                                and a.process_id = b.process_id
                                and a.order_number = b.order_number
                                and a.technology_number = b.technology_number
        where termination_status = 0
          and a.process_id = #{flowCardId}
          and a.process = "中空"
          and (b.quantity - b.termination_quantity) > reporting_work_num
    </select>
 
 
    <select id="queryInterlayerByERP" resultType="com.mes.order.entity.dto.InterlayerDTO">
        WITH flow_order AS (
            SELECT ORDER_ID, ORDER_NUMBER
            FROM pp.flow_card
            WHERE process_id = #{flowCardId}
            ORDER BY  ORDER_NUMBER /* 添加适当的排序字段,确保结果确定性 */
            LIMIT 1
        ),
             product_ids AS (
                 SELECT od.PRODUCT_ID
                 FROM sd.order_detail od
                          inner JOIN flow_order fo ON od.ORDER_id = fo.ORDER_ID AND od.ORDER_NUMBER = fo.ORDER_NUMBER
             ),
             ranked AS (
                 SELECT
                     detail_type,
                     LAG(glass_sort) OVER (PARTITION BY prod_id ORDER BY sort_num) AS prev_sort,
                     LEAD(glass_sort) OVER (PARTITION BY prod_id ORDER BY sort_num) AS next_sort
                 FROM sd.product_detail
                 WHERE prod_id IN (SELECT PRODUCT_ID FROM product_ids)
 
             )
        SELECT
            prev_sort,
            next_sort
        FROM ranked
        where detail_type = 'Interlayer'
    </select>
</mapper>