chenlu
2024-06-07 2f640b1038fa331954f78ed1f4317212cf5bb34d
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
<?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="selectMaxOrderId">
        select
           ifnull(SUBSTR(max(order_id) from 9),0)
        from
            `order` as a
        where
            date(a.create_time) = curdate()
        order by id desc,order_id    desc limit  1
    </select>
    
 
    <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)
        where
            o.order_id = #{orderId}
 
    </update>
    
    <select id="getOrderList">
        select
            *,
        ifnull(sum(fgi.quantity_available),0) as goodsQuantity
        from
            `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.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>
        group by o.id
        order by o.id desc
        limit #{offset},#{pageSize}
    </select>
 
    <select id="getPageTotal">
        select
            CEILING(count(o.id)/#{pageSize}) as 'pageTotal',
            count(o.id) as 'total'
        from
        `order` as o
        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 #{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.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>
        order by o.id desc
        limit #{offset},#{pageSize}
    </select>
    
    <update id="reviewOrderById">
        update `order` set order_review = #{status} 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} 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>
 
</mapper>