廖井涛
2024-09-25 49ff365a6977628cbb5db0ec5a4a234edd0c91ad
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
<!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.CustomerMapper">
 
    <resultMap id="selectCustomerOrderDetail" type="com.example.erp.entity.sd.OrderDetail">
 
        <result column="order_id" property="orderId"/>
        <result column="order_number" property="orderNumber"/>
        <result column="quantity" property="quantity"/>
        <result column="building_number" property="buildingNumber"/>
        <result column="product_name" property="productName"/>
        <result column="product_id" property="productId"/>
        <result column="price" property="price"/>
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="area" property="area"/>
        <result column="shape" property="shape"/>
        <result column="gross_area" property="grossArea"/>
        <result column="compute_area" property="computeArea"/>
        <result column="compute_gross_area" property="computeGrossArea"/>
        <result column="processing_note" property="processingNote"/>
        <result column="edging_type" property="edgingType"/>
        <result column="perimeter" property="perimeter"/>
 
 
        <result column="batch" property="order.batch"/>
        <result column="project" property="order.project"/>
        <result column="customer_id" property="order.customerId"/>
        <result column="customer_name" property="order.customerName"/>
        <result column="money" property="order.money"/>
        <result column="order_type" property="order.orderType"/>
        <result column="salesman" property="order.salesman"/>
        <result column="create_time" property="order.createTime"/>
 
 
 
 
 
    </resultMap>
 
 
    <select id="getSelectCustomerDeliveryDate" >
        select d.delivery_id,dd.order_id,d.customer_id,d.customer_name,
               d.project,od.product_name,sum(dd.quantity) as quantity,sum(dd.area) as area,dd.price,sum(dd.money) as money,
                date(d.create_time) as create_time
 
        from sd.delivery_detail dd
                 left join sd.delivery d on d.delivery_id = dd.delivery_id
                 left join sd.order_detail od on od.order_id=dd.order_id and od.order_number=dd.order_number
 
                where date(d.create_time)>=#{startDate} and date(d.create_time) &lt;= #{endDate}
                and d.customer_id = #{orderDetail.order.customerId}
        group by od.order_id,od.product_id
        limit #{offset},#{pageSize};
    </select>
 
    <select id="getSelectCustomerDeliveryDatePageTotal" >
        select
        CEILING(count(zu.id)/#{pageSize}) as 'pageTotal',
        count(zu.id) as 'total' from (select od.product_id,od.id
        from sd.delivery_detail dd
        left join sd.delivery d on d.delivery_id = dd.delivery_id
        left join sd.order_detail od on od.order_id=dd.order_id and od.order_number=dd.order_number
        where
             date(d.create_time)>=#{startDate} and date(d.create_time) &lt;= #{endDate}
            and d.customer_id = #{orderDetail.order.customerId}
        group by od.order_id,od.product_id) as zu
    </select>
 
    <select id="getSelectCustomerOderDate" >
        select od.order_id,
        od.order_number,
        o.project,
        od.product_id,
        od.product_name,
        o.customer_id,
        o.customer_name,
        sum(od.quantity) as quantity,
        sum(od.compute_gross_area) as area,
        od.shape,
        od.width,
        od.height,
        o.batch,
        od.price,
        sum(od.gross_amount) as money,
        o.order_type,
        o.salesman,
        date(o.create_time) as create_time
        from order_detail od
        left join `order` o on o.order_id = od.order_id
        <where>
            and date(o.create_time)>=#{startDate} and date(o.create_time) &lt;= #{endDate}
                                   and o.customer_id = #{orderDetail.order.customerId} and o.create_order>0
        </where>
        group by od.order_id,od.product_id
        limit #{offset},#{pageSize};
    </select>
 
    <select id="getSelectCustomerOderDatePageTotal" >
        select
        CEILING(count(zu.id)/#{pageSize}) as 'pageTotal',
        count(zu.id) as 'total' from (select od.product_id,od.id
        from order_detail od
        left join `order` o on o.order_id = od.order_id
        <where>
            and date(o.create_time)>=#{startDate} and date(o.create_time) &lt;= #{endDate}
                and o.customer_id = #{orderDetail.order.customerId} and o.create_order>0
        </where>
        group by od.order_id,od.product_id) as zu
    </select>
 
    <select id="getCustomerList">
        select
            a.*,
            b.project,
            b.salesman_id,
            b.salesman
        from
            sd.customer as a
        left join (SELECT
                       t.*
                   FROM
                       (
                           SELECT
                               ROW_NUMBER() over ( PARTITION BY o.customer_id ORDER BY o.id DESC ) AS rn,
                               o.id,
                               o.project,
                               o.salesman_id,
                               o.salesman,
                               o.customer_id
                           FROM
                               sd.ORDER AS o
                       ) t
                   WHERE
                       rn = 1) as b
        on a.id = b.customer_id
 
    </select>
    <select id="getSelectCustomer">
        select
            *
        from
            sd.customer c
        <where>
            <if test="customer.id != null and customer.id != ''">
                and c.id regexp #{customer.id}
            </if>
            <if test="customer.customerName != null and customer.customerName != ''">
                and c.customer_name regexp #{customer.customerName}
            </if>
            <if test="customer.customerAbbreviation != null and customer.customerAbbreviation != ''">
                and c.customer_abbreviation regexp #{customer.customerAbbreviation}
            </if>
            <if test="customer.grade != null and customer.grade != ''">
                and c.grade regexp #{customer.grade}
            </if>
            <if test="customer.moneyLimit != null and customer.moneyLimit != ''">
                and c.money_limit regexp REGEXP_REPLACE(#{customer.moneyLimit},'\\.0+$','')
            </if>
            <if test="customer.address != null and customer.address != ''">
                and c.address regexp #{customer.address}
            </if>
            <if test="customer.contact != null and customer.contact != ''">
                and c.contact regexp #{customer.contact}
            </if>
            <if test="customer.phone != null and customer.phone != ''">
                and c.phone regexp #{customer.phone}
            </if>
 
        </where>
        limit #{offset},#{pageSize};
    </select>
 
    <select id="getSelectCustomerPageTotal">
        select
            CEILING(count(id)/#{pageSize}) as 'pageTotal',
            count(id) as 'total'
        from
            sd.customer c
        <where>
            <if test="customer.id != null and customer.id != ''">
                and c.id regexp #{customer.id}
            </if>
            <if test="customer.customerName != null and customer.customerName != ''">
                and c.customer_name regexp #{customer.customerName}
            </if>
            <if test="customer.grade != null and customer.grade != ''">
                and c.grade regexp #{customer.grade}
            </if>
            <if test="customer.moneyLimit != null and customer.moneyLimit != ''">
                and c.money_limit regexp REGEXP_REPLACE(#{customer.moneyLimit},'\\.0+$','')
            </if>
            <if test="customer.address != null and customer.address != ''">
                and c.address regexp #{customer.address}
            </if>
            <if test="customer.contact != null and customer.contact != ''">
                and c.contact regexp #{customer.contact}
            </if>
            <if test="customer.phone != null and customer.phone != ''">
                and c.phone regexp #{customer.phone}
            </if>
 
        </where>
        limit #{offset},#{pageSize};
    </select>
 
    <insert id="insertCustomer"  useGeneratedKeys="true" >
        insert into sd.customer(customer_name,customer_abbreviation,grade,money_limit,address,contact,phone)
        values (
                   #{customer.customerName},#{customer.customerAbbreviation},#{customer.grade},#{customer.moneyLimit},
                #{customer.address},#{customer.contact},#{customer.phone}
               )
    </insert>
 
    <update id="updateCustomer"  useGeneratedKeys="true" >
        update sd.customer set customer_name=#{customer.customerName},customer_abbreviation=#{customer.customerAbbreviation},grade=#{customer.grade},
                                    money_limit=#{customer.moneyLimit},address= #{customer.address},
                                    contact=#{customer.contact},phone=#{customer.phone} where id=#{customer.id}
    </update>
 
    <delete id="deleteCustomer" >
        delete from sd.customer  where id=#{customer.id}
    </delete>
 
    <select id="exportSelectCustomerDeliveryDate" >
        select d.delivery_id,
               dd.order_id,
               d.customer_name,
               d.project,
               od.product_name,
               sum(dd.quantity)    as quantity,
               sum(dd.area)        as area,
               dd.price,
               sum(dd.money)       as money,
               date(d.create_time) as create_time
 
        from sd.delivery_detail dd
                 left join sd.delivery d on d.delivery_id = dd.delivery_id
                 left join sd.order_detail od on od.order_id = dd.order_id and od.order_number = dd.order_number
 
        where date(d.create_time) >= #{startDate}
          and date(d.create_time) &lt;= #{endDate}
          and d.customer_id = #{orderDetail.order.customerId}
        group by od.order_id,od.product_id
 
        UNION ALL
 
        select d.delivery_id,
               o.order_id,
               d.customer_name,
               d.project,
               bom.alias           as product_name,
               sum(om.quantity)    as quantity,
               0                   as area,
               om.price,
               sum(om.money)       as money,
               date(d.create_time) as create_time
 
        from (select * from sd.delivery_detail group by order_id) as dd
                 left join sd.delivery d on d.delivery_id = dd.delivery_id
                 left join sd.`order` o on o.order_id = dd.order_id
                 left join sd.order_other_money om on om.order_id = o.order_id
                 left join sd.basic_other_money bom on bom.`column` = om.`column`
 
        where date(d.create_time) >= #{startDate}
          and date(d.create_time) &lt;= #{endDate}
          and d.customer_id = #{orderDetail.order.customerId}
          and om.money is not null
        group by d.delivery_id, o.order_id, om.`column`
    </select>
 
    <select id="exportSelectCustomerOderDate" >
        select od.order_id,
               o.project,
               od.product_name,
               o.customer_name,
               sum(od.quantity)     as quantity,
               sum(od.compute_gross_area)         as area,
               od.price,
               sum(od.gross_amount) as money,
               date(o.create_time)  as create_time
        from order_detail od
                 left join `order` o on o.order_id = od.order_id
        where date(o.create_time) >= #{startDate}
          and date(o.create_time) &lt;= #{endDate}
          and o.customer_id = #{orderDetail.order.customerId}
          and o.create_order>0
        group by od.order_id,od.product_id
 
        UNION ALL
 
        select o.order_id,
               o.project,
               bom.alias           as product_name,
               o.customer_name,
               sum(om.quantity)    as quantity,
               0                   as area,
               om.price,
               sum(om.money)       as money,
               date(o.create_time) as create_time
        from `order` o
                 left join sd.order_other_money om on om.order_id = o.order_id
                 left join sd.basic_other_money bom on bom.`column` = om.`column`
        where date(o.create_time) >= #{startDate}
          and date(o.create_time) &lt;= #{endDate}
          and o.customer_id = #{orderDetail.order.customerId}
          and om.money is not null
        group by o.order_id, om.`column`
 
    </select>
</mapper>