廖井涛
2024-11-05 ab6e2f8fb15bf4ddb8e940ab6b979c111130df4d
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
<?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.DeliveryMapper">
 
    <resultMap id="selectOrderInventory" type="com.example.erp.entity.sd.Order">
 
        <result column="create_order" property="createOrder"/>
        <result column="process_review" property="processReview"/>
        <result column="order_review" property="orderReview"/>
        <result column="production_order" property="productionOrder"/>
        <result column="processing_card" property="processingCard"/>
        <result column="warehousing" property="warehousing"/>
        <result column="delivery" property="delivery"/>
        <result column="order_id" property="orderId"/>
        <result column="customer_id" property="customerId"/>
        <result column="customer_name" property="customerName"/>
        <result column="quantity" property="quantity"/>
        <result column="project" property="project"/>
        <result column="batch" property="batch"/>
        <result column="money" property="money"/>
        <result column="area" property="area"/>
        <result column="create_time" property="createTime"/>
        <result column="pack_type" property="packType"/>
        <result column="order_type" property="orderType"/>
        <result column="creator" property="creator"/>
        <result column="quantity_available" property="finishedGoodsInventory.quantityAvailable"/>
    </resultMap>
 
 
    <delete id="deleteDelivery">
        delete from sd.delivery where delivery_id=#{deliveryId}
    </delete>
    <update id="updateDeliveryToExamine">
        update sd.delivery set delivery_state=#{deliveryState} where delivery_id=#{deliveryId}
    </update>
 
    <update id="updatedelivery">
        update sd.delivery set area=#{area},quantity=#{quantity},money=#{money},other_money=#{otherMoney} where delivery_id=#{oddNumber}
    </update>
 
 
    <select id="getmaximum" >
        select count(*) from sd.delivery where  date(create_time)=CURDATE()
    </select>
 
    <select id="getmaximumMonth">
        select
            ifnull(SUBSTR(max(delivery_id) from 7),0)
        from
            sd.delivery as a
        where
            date(a.create_time)  BETWEEN DATE_FORMAT(DATE(NOW()), '%Y-%m-01') AND DATE(NOW())
    </select>
 
    <select id="getDeliveryConut" >
        select count(*) from sd.delivery where  delivery_id=#{deliveryId}
    </select>
 
 
    <insert id="insertDelivery"  useGeneratedKeys="true" >
        insert into sd.delivery(delivery_state,stock_state,payment_terms,delivery_id,order_id,project,customer_id,customer_name,
            delivery_date,pay_method,pay_date,salesman_id,salesman,creator_id,creator,contacts,contact_number,delivery_address,
                                area,quantity,money,remarks,create_time,freight,freight_price,freight_quantity)
        values (
                   0,0,#{delivery.paymentTerms},#{number} ,#{orderId},#{delivery.project},#{delivery.customerId},#{delivery.customerName},#{delivery.deliveryDate},#{delivery.payMethod},
                #{delivery.payDate},#{delivery.salesmanId},#{delivery.salesman},#{delivery.creatorId},#{delivery.creator},#{delivery.contacts},#{delivery.contactNumber},#{delivery.deliveryAddress},
                   0,0,0,#{delivery.remarks},now(),#{delivery.freightPrice}*#{delivery.freightQuantity},#{delivery.freightPrice},#{delivery.freightQuantity}
               )
    </insert>
 
    <update id="updateDelivery" >
        update  sd.delivery set payment_terms=#{delivery.paymentTerms},
                                delivery_date=#{delivery.deliveryDate},
                                pay_method=#{delivery.payMethod},
                                pay_date=#{delivery.payDate},contacts=#{delivery.creator},contact_number=#{delivery.contactNumber},
                                delivery_address=#{delivery.deliveryAddress},
                                freight=#{delivery.freightPrice}*#{delivery.freightQuantity},
                                freight_price=#{delivery.freightPrice},
                                freight_quantity=#{delivery.freightQuantity}
                                where delivery_id=#{number}
    </update>
 
    <select id="getSelectOrderInventory" resultMap="selectOrderInventory">
        select o.create_order,
        o.process_review,
        o.order_review,
        o.production_order,
        o.processing_card,
        o.warehousing,
        o.delivery,
        o.order_id,
        o.customer_id,
        o.customer_name,
        o.quantity,
        sum(fgi.quantity_available) as quantity_available,
        o.project,
        o.batch,
        o.money,
        o.area,
        o.create_time,
        o.pack_type,
        o.order_type,
        o.creator
        from sd.`order` o
        left join mm.finished_goods_inventory fgi on o.order_id = fgi.order_id
        <where>
            fgi.quantity_available > 0 and date(o.create_time)>=#{startDate} and date(o.create_time) &lt;= #{endDate} and o.create_order>0
            <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.quantity != null and order.quantity != ''">
                and o.quantity REGEXP #{order.quantity}
            </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.money != null and order.money != ''">
                and o.money REGEXP REGEXP_REPLACE(#{order.money},'\\.0+$','')
            </if>
            <if test="order.area != null and order.area != ''">
                and o.area REGEXP REGEXP_REPLACE(#{order.area},'\\.0+$','')
            </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.creator != null and order.creator != ''">
                and o.creator REGEXP #{order.creator}
            </if>
            <if test="order.createTime != null and order.createTime != ''">
                and o.create_time REGEXP #{order.createTime}
            </if>
            <if test="order.finishedGoodsInventory.quantityAvailable != null and order.finishedGoodsInventory.quantityAvailable != ''">
                and fgi.quantity_available REGEXP #{order.finishedGoodsInventory.quantityAvailable}
            </if>
        </where>
        group by o.order_id order by o.id desc
        limit #{offset},#{pageSize};
    </select>
 
    <select id="selectOrderId" >
        select * from sd.`order` where order_id=#{orderId}
    </select>
 
    <select id="getSelectOrderInventoryPageTotal" >
        select CEILING(count(zu.order_id)/#{pageSize}) as 'pageTotal',
        count(zu.order_id) as 'total' from
        (select o.create_order,o.process_review,o.order_review,o.production_order,
        o.processing_card,o.warehousing,o.delivery,o.order_id,o.customer_id,
        o.customer_name,o.quantity,sum(fgi.quantity_available),o.project,o.batch,
        o.money,o.area,o.create_time,o.pack_type,o.order_type,o.creator
        from sd.`order` o left join mm.finished_goods_inventory fgi on o.order_id=fgi.order_id
        <where>
            fgi.quantity_available > 0 and date(o.create_time)>=#{startDate} and date(o.create_time) &lt;= #{endDate} and o.create_order>0
            <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.quantity != null and order.quantity != ''">
                and o.quantity REGEXP #{order.quantity}
            </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.money != null and order.money != ''">
                and o.money REGEXP REGEXP_REPLACE(#{order.money},'\\.0+$','')
            </if>
            <if test="order.area != null and order.area != ''">
                and o.area REGEXP REGEXP_REPLACE(#{order.area},'\\.0+$','')
            </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.creator != null and order.creator != ''">
                and o.creator REGEXP #{order.creator}
            </if>
            <if test="order.createTime != null and order.createTime != ''">
                and o.create_time REGEXP #{order.createTime}
            </if>
            <if test="order.finishedGoodsInventory.quantityAvailable != null and order.finishedGoodsInventory.quantityAvailable != ''">
                and fgi.quantity_available REGEXP #{order.finishedGoodsInventory.quantityAvailable}
            </if>
        </where>
        group by o.order_id limit #{offset},#{pageSize}) as zu;
 
 
 
 
    </select>
 
    <select id="getSelectShippingOrderDetailDelivery" >
        select
        d.delivery_state,d.stock_state,d.payment_terms,
        d.customer_id,d.customer_name,d.project,d.pay_method,d.pay_date,d.contacts,d.contact_number,
        d.delivery_address,d.remarks,d.create_time,d.delivery_date,d.creator,d.salesman,d.salesman_id,d.freight,d.freight_price,d.freight_quantity
        from sd.delivery d
        <where>
            <if test="orderDetail.deliveryDetail.deliveryId != null and orderDetail.deliveryDetail.deliveryId != ''">
                and d.delivery_id regexp #{orderDetail.deliveryDetail.deliveryId}
            </if>
 
        </where>
        limit 0,1
    </select>
 
    <select id="getSelectShippingOrderDetailDeliveryPrinting" >
        select
        d.delivery_id,d.quantity,d.money,d.area,d.project,
        d.customer_id,d.customer_name,d.project,d.pay_method,d.pay_date,d.contacts,d.contact_number,
        d.delivery_address,d.remarks,d.create_time,d.delivery_date,d.creator,d.salesman,d.salesman_id,d.freight,d.freight_price,d.freight_quantity
        from sd.delivery d
        <where>
            <if test="deliveryDetail.deliveryId != null and deliveryDetail.deliveryId != ''">
                and d.delivery_id like concat('%',#{deliveryDetail.deliveryId},'%')
            </if>
 
        </where>
    </select>
 
    <select id="getSelectShippingOrderDetailPrinting" >
        select
        d.order_id,d.quantity,round(d.money,0) as money ,d.area,d.project,
        d.customer_id,d.customer_name,d.creator,d.salesman,d.salesman_id
        from sd.`order` d
        <where>
            <if test="orderDetail.orderId != null and orderDetail.orderId != ''">
                and d.order_id like concat('%',#{orderDetail.orderId},'%')
            </if>
 
        </where>
    </select>
 
 
    <select id="getSelectShippingOrderDetailDeliverys" >
        select customer_id,customer_name,project,salesman,salesman_id,contacts,contact_number,delivery_address from sd.`order`
        <where>
            <if test="orderDetail.orderId != null and orderDetail.orderId != ''">
                and order_id regexp #{orderDetail.orderId}
            </if>
 
         </where>
        limit 0,1
    </select>
 
    <select id="getSelectShippingOrder">
        select * from sd.delivery d left join sd.delivery_detail dd on d.delivery_id=dd.delivery_id
        <where>
            date(d.create_time)>=#{startDate} and date(d.create_time) &lt;= #{endDate}
            <if test="delivery.deliveryId != null and delivery.deliveryId != ''">
                and d.delivery_id regexp #{delivery.deliveryId}
            </if>
            <if test="delivery.creator != null and delivery.creator != ''">
                and d.creator regexp #{delivery.creator}
            </if>
            <if test="delivery.deliveryDate != null and delivery.deliveryDate != ''">
                and d.delivery_date regexp #{delivery.deliveryDate}
            </if>
            <if test="delivery.customerId != null and delivery.customerId != ''">
                and d.customer_id regexp #{delivery.customerId}
            </if>
            <if test="delivery.customerName != null and delivery.customerName != ''">
                and d.customer_name regexp #{delivery.customerName}
            </if>
            <if test="delivery.project != null and delivery.project != ''">
                and d.project regexp #{delivery.project}
            </if>
            <if test="delivery.orderId != null and delivery.orderId != ''">
                and dd.order_id regexp #{delivery.orderId}
            </if>
            <if test="delivery.payMethod != null and delivery.payMethod != ''">
                and d.pay_method regexp #{delivery.payMethod}
            </if>
            <if test="delivery.quantity != null and delivery.quantity != ''">
                and d.quantity regexp #{delivery.quantity}
            </if>
            <if test="delivery.area != null and delivery.area != ''">
                and d.area regexp REGEXP_REPLACE(#{delivery.area},'\\.0+$','')
            </if>
            <if test="delivery.deliveryState != null ">
                and d.delivery_state = #{delivery.deliveryState}
            </if>
            <if test="delivery.stockState != null ">
                and d.stock_state = #{delivery.stockState}
            </if>
 
            </where>
        group by d.delivery_id
        order by d.id desc
        limit #{offset},#{pageSize};
    </select>
 
    <select id="getSelectShippingOrderPageTotal">
        select
            CEILING(count(id)/#{pageSize}) as 'pageTotal',
            count(id) as 'total'
        from sd.delivery d
        <where>
            date(d.create_time)>=#{startDate} and date(d.create_time) &lt;= #{endDate}
            <if test="delivery.deliveryId != null and delivery.deliveryId != ''">
                and d.delivery_id regexp #{delivery.deliveryId}
            </if>
            <if test="delivery.creator != null and delivery.creator != ''">
                and d.creator regexp #{delivery.creator}
            </if>
            <if test="delivery.deliveryDate != null and delivery.deliveryDate != ''">
                and d.delivery_date regexp #{delivery.deliveryDate}
            </if>
            <if test="delivery.customerId != null and delivery.customerId != ''">
                and d.customer_id regexp #{delivery.customerId}
            </if>
            <if test="delivery.customerName != null and delivery.customerName != ''">
                and d.customer_name regexp #{delivery.customerName}
            </if>
            <if test="delivery.project != null and delivery.project != ''">
                and d.project regexp #{delivery.project}
            </if>
            <if test="delivery.orderId != null and delivery.orderId != ''">
                and d.order_id regexp #{delivery.orderId}
            </if>
            <if test="delivery.payMethod != null and delivery.payMethod != ''">
                and d.pay_method regexp #{delivery.payMethod}
            </if>
            <if test="delivery.quantity != null and delivery.quantity != ''">
                and d.quantity regexp #{delivery.quantity}
            </if>
            <if test="delivery.area != null and delivery.area != ''">
                and d.area regexp REGEXP_REPLACE(#{delivery.area},'\\.0+$','')
            </if>
            <if test="delivery.deliveryState != null ">
                and d.delivery_state = #{delivery.deliveryState}
            </if>
            <if test="delivery.stockState != null ">
                and d.stock_state = #{delivery.stockState}
            </if>
        </where>
        limit #{offset},#{pageSize};
</select>
 
    <update id="updateDeliveryPrintNumber">
        update sd.delivery
        set printing_number=printing_number+1
        where delivery_id = #{deliveryId}
 
    </update>
</mapper>