廖井涛
2025-07-21 4b15732ea08d8a75c07cef37f180289e73932783
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<?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.sd.OrderMapper">
 
    <select id="selectOrder">
        select
            *
        from
            sd.`order` as o
        where
            o.quantity=#{order.quantity} and o.area=#{order.area} and trim(o.project)=trim(#{order.project}) and o.customer_id=#{order.customerId}
    </select>
 
    <select id="selectMaxOrderId">
        select
           ifnull(SUBSTR(max(right(order_id,8)) from 7),0)
        from
            `order` as a
        where
            date(a.create_time) = curdate()
        /*order by order_id desc,order_id    desc limit  1*/
    </select>
 
    <select id="selectMaxOrderIdByMonth">
        select
            ifnull(SUBSTR(max(right(order_id,8)) from 5),0)
        from
            `order` as a
        where
            date(a.create_time)  BETWEEN DATE_FORMAT(DATE(NOW()), '%Y-%m-01') AND DATE(NOW())
    </select>
 
    <select id="selectMaxOrderIdByYear">
       select
           ifnull(SUBSTR(max(right(order_id,8)) from 3),0)
        from
            `order` as a
        where
            year(a.create_time)  = year(now())
            and a.id>400
    </select>
 
    <select id="selectOrderIdMin">
        select count(*) from sd.`order` where SUBSTR(order_id,3,11)>#{substringInt}
    </select>
 
    <select id="selectOrderIdIs">
        select count(*) from sd.`order` where SUBSTR(order_id,3,11)=#{substringInt}
    </select>
 
    <select id="selectOrderIdDay">
        select count(*) from sd.`order` where order_id=#{oldOrderId} and SUBSTR(#{oldOrderId},9,2)=01
    </select>
 
    <select id="selectOrderIdMonth">
        select count(*) from sd.`order` where order_id=#{oldOrderId} and SUBSTR(#{oldOrderId},7,4)=0001
    </select>
 
    <select id="selectOrderIdYear">
        select count(*) from sd.`order` where order_id=#{oldOrderId} and SUBSTR(#{oldOrderId},5,2)=000001
    </select>
 
    <select id="selectOrderId">
        select * from sd.`order` where order_id=#{orderId}
    </select>
 
    <update id="updateOrderId">
        update sd.`order` set order_id=#{newOrderId} where order_id=#{oldOrderId}
    </update>
 
    <update id="updateOrderParameter">
        update `order` o
        left join
            (select a.order_id,
                    round(sum(a.perimeter),2) as aa,
                    sum(a.quantity) as b,
                    sum(a.compute_gross_area)  as c,
                   sum(a.gross_amount) as 'detailAmount'
             from sd.order_detail as a group by a.order_id
            ) as od
            on o.order_id = od.order_id
        left join (select oom.order_id,
                          sum(oom.money) as 'money'
                   from order_other_money as oom
                   where
                       oom.order_id = #{orderId}
                   group by oom.order_id
                   ) as c
        on c.order_id = o.order_id
        set
            o.money = ifnull(od.detailAmount,0)+ifnull(c.money,0),
            o.quantity = od.b,
            o.area = od.c,
            o.perimeter= od.aa,
            o.other_money = ifnull(c.money,0),
            o.other_remarks = (select group_concat( distinct edging_type) from order_detail where order_id = #{orderId} and  edging_type is not null)
        where
            o.order_id = #{orderId}
 
    </update>
    
    <select id="getOrderList">
       select * from (select
            o.*,
        ifnull(sum(fgi.quantity_available),0) as goodsQuantity,
        if(DATEDIFF(o.delivery_date, CURDATE()) &lt; 3  and o.delivery &lt; 2, 'timeOut','' ) as timeOut
        from
            sd.`order` as o
        left join mm.finished_goods_inventory as  fgi
        on o.order_id = fgi.order_id
        where  date(o.create_time)>=#{startDate} and date(o.create_time) &lt;= #{endDate}
 
          <if test="orderType!= null and orderType != ''">
               and o.create_order = #{orderType}
           </if>
 
           <if test="order.orderId != null and order.orderId != ''">
               and o.order_id REGEXP #{order.orderId}
           </if>
 
           <if test="order.customerId != null and order.customerId != ''">
               and o.customer_id REGEXP #{order.customerId}
           </if>
           <if test="order.customerName != null and order.customerName != ''">
               and o.customer_name REGEXP #{order.customerName}
           </if>
           <if test="order.project != null and order.project != ''">
               and o.project REGEXP #{order.project}
           </if>
           <if test="order.batch != null and order.batch != ''">
               and o.batch REGEXP #{order.batch}
           </if>
           <if test="order.quantity != null and order.quantity != ''">
               and o.quantity REGEXP #{order.quantity}
           </if>
 
           <if test="order.area != null and order.area != ''">
               and o.area REGEXP REGEXP_REPLACE(#{order.area}, '\\.0+$', '')
           </if>
           <if test="order.createTime != null and order.createTime != ''">
               and date(o.create_time) = #{order.createTime}
           </if>
           <if test="order.packType != null and order.packType != ''">
               and o.pack_type REGEXP #{order.packType}
           </if>
           <if test="order.orderType != null and order.orderType != ''">
               and o.order_type REGEXP #{order.orderType}
           </if>
           <if test="order.salesman != null and order.salesman != ''">
               and o.salesman REGEXP #{order.salesman}
           </if>
 
            <if test="order.creator != null and order.creator != ''">
                and o.creator REGEXP #{order.creator}
            </if>
 
            <if test="order.verifier != null and order.verifier != ''">
                and o.verifier REGEXP #{order.verifier}
            </if>
 
           <if test="order.perimeter != null and order.perimeter != ''">
               and o.perimeter REGEXP #{order.perimeter}
           </if>
           <if test="order.deliveryDate != null and order.deliveryDate != ''">
               and o.delivery_date REGEXP #{order.deliveryDate}
           </if>
           <if test="order.customerBatch != null and order.customerBatch != ''">
               and o.customer_batch REGEXP #{order.customerBatch}
           </if>
           <if test="order.otherRemarks != null and order.otherRemarks != ''">
               and o.other_remarks REGEXP #{order.otherRemarks}
           </if>
           <if test="order.deliveryAddress != null and order.deliveryAddress != ''">
               and o.delivery_address REGEXP #{order.deliveryAddress}
           </if>
        <if test="order.delivery != null ">
            and o.delivery = #{order.delivery}
        </if>
        <if test="order.processReview != null ">
            and o.process_review = #{order.processReview}
        </if>
        <if test="order.orderReview != null ">
            and o.order_review = #{order.orderReview}
        </if>
        <if test="order.productionOrder != null ">
            and o.production_order = #{order.productionOrder}
        </if>
        <if test="order.processingCard != null ">
            and o.processing_card = #{order.processingCard}
        </if>
        <if test="order.warehousing != null ">
            and o.warehousing = #{order.warehousing}
        </if>
        <if test="order.processingNote != null and order.processingNote != ''">
            and o.processing_note REGEXP #{order.processingNote}
        </if>
        group by o.id
        ) as acc
        order by
        <if test="orderBy == null ">
            order_id desc
        </if>
        <if test="orderBy == 'desc'">
            ${field} desc
        </if>
        <if test="orderBy == 'asc'">
            ${field}
        </if>
        limit #{offset},#{pageSize}
    </select>
 
    <select id="getPageTotal">
        select
            CEILING(count(o.id)/#{pageSize}) as 'pageTotal',
            count(o.id) as 'dataTotal',
            sum(o.quantity) as quantity,
            sum(o.area) as area,
            sum(o.money) as money,
            ifnull(fgi.goodsQuantity ,0) as goodsQuantity ,
            ROUND(sum(perimeter),2) as perimeter,
            #{pageSize} as pageSize
        from
        `order` as o
        left join(
                    select order_id,
                           ifnull(sum(quantity_available),0) as goodsQuantity
                    from mm.finished_goods_inventory group by order_id
                    )  as  fgi
        on o.order_id = fgi.order_id
        where date (o.create_time)>=#{startDate} and date(o.create_time) &lt;= #{endDate}
            <if test="orderType!= null and orderType != 0">
                and o.create_order = #{orderType}
            </if>
 
            <if test="order.orderId != null and order.orderId != ''">
                and o.order_id REGEXP #{order.orderId}
            </if>
 
            <if test="order.customerId != null and order.customerId != ''">
                and o.customer_id REGEXP #{order.customerId}
            </if>
            <if test="order.customerName != null and order.customerName != ''">
                and o.customer_name REGEXP #{order.customerName}
            </if>
            <if test="order.project != null and order.project != ''">
                and o.project REGEXP #{order.project}
            </if>
            <if test="order.batch != null and order.batch != ''">
                and o.batch REGEXP #{order.batch}
            </if>
            <if test="order.quantity != null and order.quantity != ''">
                and o.quantity REGEXP #{order.quantity}
            </if>
 
            <if test="order.area != null and order.area != ''">
                and o.area REGEXP #{order.area}
            </if>
            <if test="order.createTime != null and order.createTime != ''">
                and date(o.create_time) = #{order.createTime}
            </if>
            <if test="order.packType != null and order.packType != ''">
                and o.pack_type REGEXP #{order.packType}
            </if>
            <if test="order.orderType != null and order.orderType != ''">
                and o.order_type REGEXP #{order.orderType}
            </if>
            <if test="order.salesman != null and order.salesman != ''">
                and o.salesman REGEXP #{order.salesman}
            </if>
 
            <if test="order.creator != null and order.creator != ''">
                and o.creator REGEXP #{order.creator}
            </if>
 
            <if test="order.verifier != null and order.verifier != ''">
                and o.verifier REGEXP #{order.verifier}
            </if>
 
            <if test="order.perimeter != null and order.perimeter != ''">
                and o.perimeter REGEXP #{order.perimeter}
            </if>
            <if test="order.deliveryDate != null and order.deliveryDate != ''">
                and o.delivery_date REGEXP #{order.deliveryDate}
            </if>
            <if test="order.customerBatch != null and order.customerBatch != ''">
                and o.customer_batch REGEXP #{order.customerBatch}
            </if>
            <if test="order.otherRemarks != null and order.otherRemarks != ''">
                and o.other_remarks REGEXP #{order.otherRemarks}
            </if>
            <if test="order.deliveryAddress != null and order.deliveryAddress != ''">
                and o.delivery_address REGEXP #{order.deliveryAddress}
            </if>
        <if test="order.delivery != null ">
            and o.delivery = #{order.delivery}
        </if>
        <if test="order.processReview != null ">
            and o.process_review = #{order.processReview}
        </if>
        <if test="order.orderReview != null ">
            and o.order_review = #{order.orderReview}
        </if>
        <if test="order.productionOrder != null ">
            and o.production_order = #{order.productionOrder}
        </if>
        <if test="order.processingCard != null ">
            and o.processing_card = #{order.processingCard}
        </if>
        <if test="order.warehousing != null ">
            and o.warehousing = #{order.warehousing}
        </if>
        <if test="order.processingNote != null and order.processingNote != ''">
            and o.processing_note REGEXP #{order.processingNote}
        </if>
        order by o.id desc
    </select>
    
    <update id="reviewOrderById">
        update `order` set order_review = #{status},
                           verifier_id = #{userId},
                           verifier = #{userName},
                           update_time=now()
                           where order_id = #{id}
    </update>
    <update id="reviewOrderByIds">
        update `order` set order_review = #{status},process_review = #{status},
                           verifier_id = null,
                           verifier = null
        where order_id = #{id}
    </update>
 
    <update id="backReviewOrderById">
        update `order` set order_review = 0,
                           verifier_id = null,
                           verifier = null
        where order_id = #{id}
    </update>
 
    <update id="reviewProcessById">
        update `order` set process_review = #{status} where order_id = #{id}
    </update>
 
    <update id="updateMoney">
        update `order` set money = #{order.money},calculate_type = #{order.calculateType},other_money=#{order.otherMoney} where order_id = #{order.orderId}
    </update>
 
    <update id="cancelOrder">
        update `order` as a set
            a.create_order = - a.create_order,
            a.process_review = - a.process_review,
            a.order_review = - a.order_review,
            a.production_order = - a.production_order,
            a.processing_card =  - a.processing_card,
            a.warehousing = - a.warehousing,
            a.delivery = - a.delivery
        where order_id = #{order.orderId}
    </update>
 
    <update id="updateOrderPrintNumber">
        update sd.`order` o
            set o.printing_number=o.printing_number+1
        where
            o.order_id = #{orderId}
 
    </update>
 
    <select id="selectDifferentSize">
    select a.order_number,count(a.order_number),a.order_id from(select order_id,order_number
    from sd.order_glass_detail ogd
    where ogd.order_id = #{orderId}
    group by ogd.order_number,ogd.child_height,child_width)
    as a
    group by a.order_number
    having count(a.order_number) > 1
    </select>
 
    <select id="searchOrderWarehousing">
        select  warehousing from `order`
        where order_id = #{orderId}
    </select>
 
    <select id="getProcessIdByOptimizeHeatDetail">
        select  process_id from pp.optimize_heat_detail as a
        where a.project_no = #{projectId}
          and a.layout_id = #{layoutId}
          and a.sort = #{sort}
    </select>
 
    <select id="scannerGlassInfo">
        select c.order_id as orderId,
               b.order_number as orderNumber,
               b.technology_number as technologyNumber,
               a.process_id as processId,
               c.customer_name as customerName,
               concat(a.width," * " , a.height) as size,
               b.area,
               b.glass_child as glassChild,
               d.product_name as productName,
               d.building_number as buildingNumber,
               d.remarks as remarks,
               d.processing_note as processingNote
        from pp.optimize_heat_detail as a
        left join sd.order_glass_detail as b
            on b.order_number = a.order_sort
            and b.technology_number = a. layer
            and b.order_id = #{orderId}
        left join  sd.order as c
            on c.order_id = b.order_id
        left join sd.order_detail as d
            on c.order_id = d.order_id
            and d.order_number = a.order_sort
        where a.project_no = #{projectNo}
        and a.layout_id = #{layoutId}
        and a.sort = #{sort}
    </select>
 
 
    <insert id="saveOrderFile">
        insert into sd.order_file (order_id,order_number,file_name,file_data,create_time) values(#{orderId},#{orderNumber},#{fileName},#{dxfData},now())
    </insert>
 
    <select id="selectOrderFile">
        select  * from sd.order_file
        where order_id = #{orderId} and order_number = #{orderNumber}
 
    </select>
 
    <select id="selectOrderFileList">
        select  * from sd.order_file
        where order_id = #{orderId}
 
    </select>
 
    <update id="updateOrderFile">
        update sd.order_file set file_name=#{fileName},file_data=#{dxfData},create_time=now() where orderId=#{orderId} and orderNumber=#{orderNumber}
    </update>
</mapper>