chenlu
2025-11-24 943e4b59e43ce34d5b0967c8b73fef76eefe68bb
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
<?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.example.erp.mapper.pp.ProductionSchedulingMapper">
    <resultMap id="productionSchedulingMap" type="com.example.erp.entity.pp.ProductionScheduling">
        <result column="processes" property="processes"/>
        <result column="scheduling_quantity" property="schedulingQuantity"/>
        <result column="order_number" property="orderNumber"/>
        <result column="scheduling_id" property="schedulingId"/>
        <result column="order_id" property="order.orderId"/>
        <result column="technology_number" property="technologyNumber"/>
        <result column="pendingProductionQuantity" property="pendingProductionQuantity"/>
        <result column="pendingProductionArea" property="pendingProductionArea"/>
        <result column="productionScheduledQuantity" property="productionScheduledQuantity"/>
        <result column="productionScheduledArea" property="productionScheduledArea"/>
        <result column="review_status" property="reviewStatus"/>
        <result column="scheduled_start_time" property="scheduledStartTime"/>
        <result column="plan_end_time" property="planEndTime"/>
        <result column="reviewer" property="reviewer"/>
        <!--接收其他外键实体类数据-->
        <result column="project" property="order.project"/>
        <result column="customer_name" property="order.customerName"/>
        <result column="batch" property="order.batch"/>
        <result column="other_remarks" property="order.otherRemarks"/>
        <result column="icon" property="order.icon"/>
        <result column="order_type" property="order.orderType"/>
        <result column="salesman" property="order.salesman"/>
        <result column="processing_note" property="order.processingNote"/>
        <result column="delivery_address" property="order.deliveryAddress"/>
        <result column="product_id" property="orderDetail.productId"/>
        <result column="product_name" property="orderDetail.productName"/>
        <result column="compute_gross_area" property="orderDetail.computeGrossArea"/>
        <result column="quantity" property="orderDetail.quantity"/>
        <result column="perimeter" property="orderDetail.perimeter"/>
        <result column="width" property="orderDetail.width"/>
        <result column="height" property="orderDetail.height"/>
        <result column="shape" property="orderDetail.shape"/>
        <result column="weight" property="orderDetail.weight"/>
        <result column="child_width" property="orderGlassDetail.childWidth"/>
        <result column="child_height" property="orderGlassDetail.childHeight"/>
        <result column="area" property="orderGlassDetail.area"/>
        <result column="glass_child" property="orderGlassDetail.glassChild"/>
    </resultMap>
 
 
    <!--    查询已排版数据-->
    <select id="selectOkSchedulingMp" resultMap="productionSchedulingMap">
        select date(ps.scheduled_start_time) as scheduled_start_time,
        date(ps.plan_end_time) as plan_end_time,
        od.order_id,
        o.customer_name,
        o.project,
        ps.order_number,
        ps.technology_number,
        ogd.child_width,
        ogd.child_height,
        od.quantity,
        round(od.width * od.height * od.quantity / 1000000, 2) as area,
        ps.scheduling_quantity,
        (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) as pendingProductionQuantity,
        round(od.width * od.height * (od.quantity - IFNULL(sum(ps.scheduling_quantity), 0)) / 1000000,
        2) as pendingProductionArea,
        IFNULL(ps.scheduling_quantity, 0) as productionScheduledQuantity,
        round(od.width * od.height * (IFNULL(ps.scheduling_quantity, 0)) / 1000000,
        2) as productionScheduledArea,
        IF(ps.review_status = 0, "未审核", "已审核") as review_status,
        ps.reviewer,
        od.product_name,
        if(od.shape=1,'普形',if(od.shape=2,'异形','')) as shape,
        ps.scheduling_id,
        ps.notes
        from sd.order_detail as od
        left join sd.order as o on od.order_id = o.order_id
        left join production_scheduling as ps
        on ps.order_id = od.order_id and ps.order_number = od.order_number
        left join sd.order_glass_detail as ogd on ogd.order_id=od.order_id and ogd.order_number=od.order_number and
        ogd.technology_number=ps.technology_number
        where ps.scheduling_id IS NOT NULL
          and o.create_order>0
        and  DATE_FORMAT((od.create_time), '%Y-%m-%d') between #{selectTime1} and #{selectTime2}
        and position(#{processes} in ps.processes)
        and position(#{orderIds} in ps.order_id)
        <if test="productionScheduling.order.orderId != null and productionScheduling.order.orderId != ''">
            and ogd.order_id regexp #{productionScheduling.order.orderId}
        </if>
        <if test="productionScheduling.order.customerName != null and productionScheduling.order.customerName != ''">
            and o.customer_name regexp #{productionScheduling.order.customerName}
        </if>
        <if test="productionScheduling.order.project != null and productionScheduling.order.project != ''">
            and o.project regexp #{productionScheduling.order.project}
        </if>
        <if test="productionScheduling.orderNumber != null and productionScheduling.orderNumber != ''">
            and ogd.order_number regexp #{productionScheduling.orderNumber}
        </if>
        <if test="productionScheduling.technologyNumber != null and productionScheduling.technologyNumber != ''">
            and ogd.technology_number regexp #{productionScheduling.technologyNumber}
        </if>
        group by ps.id
        order by ps.id desc
        limit #{offset},#{pageSize};
    </select>
 
 
    <!--    查询未排产数据-->
    <select id="selectNoSchedulingMp" resultMap="productionSchedulingMap">
        select ogd.order_id,
        o.customer_name,
        o.project,
        ogd.order_number,
        ogd.technology_number,
        ogd.child_width,
        ogd.child_height,
        od.quantity,
        round(ogd.child_width * ogd.child_height * od.quantity / 1000000, 2) as area,
        (od.quantity - IFNULL((ps.schedulingQuantity), 0)) as schedulingQuantity,
        (od.quantity - IFNULL((ps.schedulingQuantity), 0)) as pendingProductionQuantity,
        round(ogd.child_width * ogd.child_height * (od.quantity - IFNULL((ps.schedulingQuantity), 0)) / 1000000,
        2)
        as pendingProductionArea,
        IFNULL(ps.schedulingQuantity, 0) as productionScheduledQuantity,
        round(ogd.child_width * ogd.child_height * (IFNULL(ps.schedulingQuantity, 0)) / 1000000,
        2) as productionScheduledArea,
        od.product_name,
        if(od.shape=1,'普形',if(od.shape=2,'异形','')) as shape
        from sd.order_glass_detail as ogd
 
        left join sd.order as o on ogd.order_id = o.order_id
        left join sd.order_detail as od on od.order_id = ogd.order_id and od.order_number = ogd.order_number
        left join sd.order_process_detail as opd
        on opd.order_id = ogd.order_id and opd.order_number = ogd.order_number and
        opd.technology_number = ogd.technology_number
        left join
        (select order_id, order_number, technology_number, SUM(scheduling_quantity) as schedulingQuantity
        from production_scheduling
        where processes = #{processes}
        group by order_id, order_number, technology_number) as ps
        on ps.order_id = ogd.order_id and ps.order_number = ogd.order_number and
        ps.technology_number = ogd.technology_number
 
        where (od.quantity - IFNULL((ps.schedulingQuantity), 0)) > 0
        and  DATE_FORMAT((od.create_time), '%Y-%m-%d') between #{selectTime1} and #{selectTime2}
        and opd.reporting_work_num_count = 0
        and o.create_order>0
        and position(#{orderIds} in ogd.order_id)
        -- and position("切割" in ps.processes)
        <if test="productionScheduling.order.orderId != null and productionScheduling.order.orderId != ''">
            and ogd.order_id regexp #{productionScheduling.order.orderId}
        </if>
        <if test="productionScheduling.order.customerName != null and productionScheduling.order.customerName != ''">
            and o.customer_name regexp #{productionScheduling.order.customerName}
        </if>
        <if test="productionScheduling.order.project != null and productionScheduling.order.project != ''">
            and o.project regexp #{productionScheduling.order.project}
        </if>
        <if test="productionScheduling.orderNumber != null and productionScheduling.orderNumber != ''">
            and ogd.order_number regexp #{productionScheduling.orderNumber}
        </if>
        <if test="productionScheduling.technologyNumber != null and productionScheduling.technologyNumber != ''">
            and ogd.technology_number regexp #{productionScheduling.technologyNumber}
        </if>
        group by ogd.order_id, ogd.order_number, ogd.technology_number
        order by ogd.order_id desc
        limit #{offset},#{pageSize};
    </select>
 
 
    <select id="selectMaxId">
        select COUNT(ps.scheduling_id)
        from `production_scheduling` as ps
        where date(ps.create_time) = curdate()
    </select>
 
    <insert id="insertSelective">
        insert into production_scheduling(scheduling_id,
                                          order_id,
                                          order_number,
                                          technology_number,
                                          processes,
                                          scheduling_quantity,
                                          scheduled_start_time,
                                          plan_end_time,
                                          notes,
                                          create_time)
        VALUES (#{schedulingId},
                #{orderId},
                #{orderNumber},
                #{technologyNumber},
                #{processes},
                #{schedulingQuantity},
                #{scheduledStartTime},
                #{planEndTime},
                #{notes},
                now())
    </insert>
 
    <update id="examineSchedulingMp">
        update production_scheduling
        set review_status=1,
            reviewer=#{userName},
            scheduling_quantity=#{schedulingQuantity},
            notes=#{notes}
        where scheduling_id = #{schedulingId}
    </update>
 
    <delete id="deleteSchedulingMp">
        delete
        from production_scheduling
        where scheduling_id = #{schedulingId}
    </delete>
 
    <select id="selectProcess">
        SELECT *
        FROM sd.basic_data as bd
        where bd.basic_category = 'process'
          and bd.basic_type = 'product'
    </select>
 
    <select id="getPageTotal">
        select CEILING(count(ogd.id)/#{pageSize}) as 'pageTotal',
        count(distinct ogd.id) as 'total'
        from sd.order_glass_detail as ogd
 
        left join sd.order as o on ogd.order_id = o.order_id
        left join sd.order_detail as od on od.order_id = ogd.order_id and od.order_number = ogd.order_number
        left join sd.order_process_detail as opd
        on opd.order_id = ogd.order_id and opd.order_number = ogd.order_number and
        opd.technology_number = ogd.technology_number
        left join
        (select order_id, order_number, technology_number, SUM(scheduling_quantity) as schedulingQuantity
        from production_scheduling
        where processes = #{processes}
        group by order_id, order_number, technology_number) as ps
        on ps.order_id = ogd.order_id and ps.order_number = ogd.order_number and
        ps.technology_number = ogd.technology_number
 
        where (od.quantity - IFNULL((ps.schedulingQuantity), 0)) > 0
        and  DATE_FORMAT((od.create_time), '%Y-%m-%d') between #{selectTime1} and #{selectTime2}
        and opd.reporting_work_num_count = 0
        and o.create_order>0
        and position(#{orderId} in ogd.order_id)
        -- and position("切割" in ps.processes)
        <if test="productionScheduling.orderId != null and productionScheduling.orderId != ''">
            and ogd.order_id regexp #{productionScheduling.orderId}
        </if>
        <if test="productionScheduling.order.customerName != null and productionScheduling.order.customerName != ''">
            and o.customer_name regexp #{productionScheduling.order.customerName}
        </if>
        <if test="productionScheduling.order.project != null and productionScheduling.order.project != ''">
            and o.project regexp #{productionScheduling.order.project}
        </if>
        <if test="productionScheduling.orderNumber != null and productionScheduling.orderNumber != ''">
            and ogd.order_number regexp #{productionScheduling.orderNumber}
        </if>
        <if test="productionScheduling.technologyNumber != null and productionScheduling.technologyNumber != ''">
            and ogd.technology_number regexp #{productionScheduling.technologyNumber}
        </if>
        order by ogd.order_id desc
        limit #{offset},#{pageSize};
    </select>
 
    <select id="getOkPageTotal">
        select CEILING(count(ps.id)/#{pageSize}) as 'pageTotal',
        count(distinct ps.id) as 'total'
        from sd.order_detail as od
        left join sd.order as o on od.order_id = o.order_id
        left join production_scheduling as ps
        on ps.order_id = od.order_id and ps.order_number = od.order_number
        left join sd.order_glass_detail as ogd on ogd.order_id=od.order_id and ogd.order_number=od.order_number and
        ogd.technology_number=ps.technology_number
        where ps.scheduling_id IS NOT NULL
        and  DATE_FORMAT((od.create_time), '%Y-%m-%d') between #{selectTime1} and #{selectTime2}
        and o.create_order>0
        and position(#{processes} in ps.processes)
        and position(#{orderId} in ps.order_id)
        <if test="productionScheduling.orderId != null and productionScheduling.orderId != ''">
            and ogd.order_id regexp #{productionScheduling.orderId}
        </if>
        <if test="productionScheduling.order.customerName != null and productionScheduling.order.customerName != ''">
            and o.customer_name regexp #{productionScheduling.order.customerName}
        </if>
        <if test="productionScheduling.order.project != null and productionScheduling.order.project != ''">
            and o.project regexp #{productionScheduling.order.project}
        </if>
        <if test="productionScheduling.orderNumber != null and productionScheduling.orderNumber != ''">
            and ogd.order_number regexp #{productionScheduling.orderNumber}
        </if>
        <if test="productionScheduling.technologyNumber != null and productionScheduling.technologyNumber != ''">
            and ogd.technology_number regexp #{productionScheduling.technologyNumber}
        </if>
        order by ps.id desc
        limit #{offset},#{pageSize};
    </select>
 
    <update id="cancelReviewSchedulingMp">
        update production_scheduling set   review_status=0    where scheduling_id = #{schedulingId}
    </update>
</mapper>