ReceiptLedgerInfoMapper.xml
10.9 KB
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
<?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.lframework.xingyun.sc.mappers.ReceiptLedgerInfoMapper">
<resultMap id="ReceiptLedgerInfo" type="com.lframework.xingyun.sc.entity.ReceiptLedgerInfo">
<id column="id" property="id"/>
<result column="type" property="type"/>
<result column="parent_id" property="parentId"/>
<result column="customer_short_id" property="customerShortId"/>
<result column="customer_short_name" property="customerShortName"/>
<result column="customer_type" property="customerType"/>
<result column="quota" property="quota"/>
<result column="settle_term" property="settleTerm"/>
<result column="dept_id" property="deptId"/>
<result column="dept_name" property="deptName"/>
<result column="region" property="region"/>
<result column="region_name" property="regionName"/>
<result column="stock_up_company_id" property="stockUpCompanyId"/>
<result column="stock_up_company_name" property="stockUpCompanyName"/>
<result column="customer_id" property="customerId"/>
<result column="customer_name" property="customerName"/>
<result column="factory_type" property="factoryType"/>
<result column="shipment_date" property="shipmentDate"/>
<result column="start_account_receivable" property="startAccountReceivable"/>
<result column="arrival_date" property="arrivalDate"/>
<result column="processed_date" property="processedDate"/>
<result column="actual_returned_date" property="actualReturnedDate"/>
<result column="returned_amount" property="returnedAmount"/>
<result column="end_account_receivable" property="endAccountReceivable"/>
<result column="apply_status" property="applyStatus"/>
<result column="coordinate_date" property="coordinateDate"/>
<result column="remark" property="remark"/>
<result column="second_coordinate_date" property="secondCoordinateDate"/>
<result column="third_coordinate_date" property="thirdCoordinateDate"/>
<result column="fourth_coordinate_date" property="fourthCoordinateDate"/>
<result column="fifth_coordinate_date" property="fifthCoordinateDate"/>
<result column="description" property="description"/>
<result column="del_flag" property="delFlag"/>
<result column="debt_status" property="debtStatus"/>
<result column="create_by_id" property="createById"/>
<result column="update_by_id" property="updateById"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="ReceiptLedgerInfo_sql">
SELECT
tb.id,
tb.type,
tb.parent_id,
tb.customer_short_id,
cs.short_name as customer_short_name,
cs.type as customer_type,
tb.quota,
tb.settle_term,
tb.dept_id,
d.name as dept_name,
tb.region,
r.name as region_name,
tb.stock_up_company_id,
sc.name as stock_up_company_name,
tb.customer_id,
oc.name as customer_name,
tb.factory_type,
tb.shipment_date,
tb.start_account_receivable,
tb.arrival_date,
tb.processed_date,
tb.actual_returned_date,
tb.returned_amount,
tb.end_account_receivable,
tb.apply_status,
tb.coordinate_date,
tb.remark,
tb.second_coordinate_date,
tb.third_coordinate_date,
tb.fourth_coordinate_date,
tb.fifth_coordinate_date,
tb.description,
tb.del_flag,
tb.debt_status,
tb.create_by_id,
tb.update_by_id,
tb.create_time,
tb.update_time
FROM receipt_ledger_info AS tb
LEFT JOIN base_data_customer_short cs ON tb.customer_short_id = cs.id
LEFT JOIN base_data_customer sc ON tb.stock_up_company_id = sc.id
LEFT JOIN base_data_customer oc ON tb.customer_id = oc.id
LEFT JOIN sys_dept d ON tb.dept_id = d.id
LEFT JOIN sys_dept r ON tb.region = r.id
</sql>
<select id="query" resultMap="ReceiptLedgerInfo">
<include refid="ReceiptLedgerInfo_sql"/>
<where>
AND tb.del_flag = false
<if test="vo.id != null and vo.id != ''">
AND tb.id = #{vo.id}
</if>
<if test="vo.type != null and vo.type != ''">
AND tb.type = #{vo.type}
</if>
<if test="vo.factoryType != null and vo.factoryType != ''">
AND tb.factory_type = #{vo.factoryType}
</if>
<if test="vo.customerShortId != null and vo.customerShortId != ''">
AND tb.customer_short_id = #{vo.customerShortId}
</if>
<if test="vo.deptId != null and vo.deptId != ''">
AND tb.dept_id = #{vo.deptId}
</if>
<if test="vo.customerId != null and vo.customerId != ''">
AND tb.customer_id = #{vo.customerId}
</if>
<if test="vo.createTimeStart != null and vo.createTimeStart != ''">
AND tb.create_time >= #{vo.createTimeStart}
</if>
<if test="vo.createTimeEnd != null and vo.createTimeEnd != ''">
AND tb.create_time <= #{vo.createTimeEnd}
</if>
<if test="vo.customerName != null and vo.customerName != ''">
AND oc.name LIKE CONCAT('%', #{vo.customerName}, '%')
</if>
<if test="vo.customerShortName != null and vo.customerShortName != ''">
AND cs.short_name LIKE CONCAT('%', #{vo.customerShortName}, '%')
</if>
<if test="vo.deptName != null and vo.deptName != ''">
AND d.name LIKE CONCAT('%', #{vo.deptName}, '%')
</if>
</where>
</select>
<select id="queryByCustomerShortName" resultMap="ReceiptLedgerInfo">
<include refid="ReceiptLedgerInfo_sql"/>
<where>
AND tb.del_flag = false
AND tb.end_account_receivable >0
<if test="customerShortName != null and customerShortName != ''">
AND cs.short_name = #{customerShortName}
</if>
</where>
</select>
<insert id="batchAdd">
INSERT INTO receipt_ledger_info (
id,
type,
parent_id,
customer_short_id,
quota,
settle_term,
dept_id,
region,
stock_up_company_id,
customer_id,
factory_type,
shipment_date,
start_account_receivable,
arrival_date,
processed_date,
actual_returned_date,
returned_amount,
end_account_receivable,
apply_status,
coordinate_date,
remark,
second_coordinate_date,
third_coordinate_date,
fourth_coordinate_date,
fifth_coordinate_date,
description,
shipment_order_id,
create_by_id,
update_by_id,
create_time,
update_time
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.id},
#{item.type},
#{item.parentId},
#{item.customerShortId},
#{item.quota},
#{item.settleTerm},
#{item.deptId},
#{item.region},
#{item.stockUpCompanyId},
#{item.customerId},
#{item.factoryType},
#{item.shipmentDate},
#{item.startAccountReceivable},
#{item.arrivalDate},
#{item.processedDate},
#{item.actualReturnedDate},
#{item.returnedAmount},
#{item.endAccountReceivable},
#{item.applyStatus},
#{item.coordinateDate},
#{item.remark},
#{item.secondCoordinateDate},
#{item.thirdCoordinateDate},
#{item.fourthCoordinateDate},
#{item.fifthCoordinateDate},
#{item.description},
#{item.shipmentOrderId},
#{item.createById},
#{item.updateById},
#{item.createTime},
#{item.updateTime}
)
</foreach>
</insert>
<select id="report" resultType="com.lframework.xingyun.sc.bo.ledger.receipt.ReceiptLedgerReportBo">
select tb.short_name as customer_short_name,
case
when tb.type = 'DEALER' then '经销商'
when tb.type = 'TERMINAL' then '终端'
when tb.type = 'FOREIGN' then '外贸'
else tb.type
end as customer_type,
tb.dept_id,
d.name as dept_name,
tb.region,
r.name as region_name,
max(cc.company_credit_limit) as quota,
sum(rl.end_account_receivable) as debtTotal
from base_data_customer_short tb
left join sys_dept d on tb.dept_id = d.id
left join sys_dept r on tb.region = r.id
left join customer_credit cc on tb.customer_id = cc.company_id
left join receipt_ledger_info rl on tb.id = rl.customer_short_id
<where>
<if test="vo.customerType != null and vo.customerType != ''">
and tb.type = #{vo.customerType}
</if>
<if test="vo.debtStatus != null and vo.debtStatus != ''">
and rl.debt_status = #{vo.debtStatus}
</if>
<if test="vo.deptName != null and vo.deptName != ''">
and d.name like concat('%', #{vo.deptName}, '%')
</if>
</where>
group by tb.short_name,tb.type,tb.dept_id,tb.region
having 1=1
<if test="vo.debtStartValue != null">
and sum(rl.end_account_receivable) >= #{debtStartValue}
</if>
<if test="vo.debtEndValue != null">
and sum(rl.end_account_receivable) <= #{debtEndValue}
</if>
</select>
<select id="statisticsDeptByShortName" resultType="java.util.Map">
select c.name,
cs.short_name,
tb.debt_status,
sum(tb.end_account_receivable) as debt_amount
from receipt_ledger_info tb
inner join base_data_customer_short cs on tb.customer_id = cs.customer_id
inner join base_data_customer c on tb.customer_id = c.id
where cs.short_name in
<foreach collection="shortNames" open="(" separator="," close=")" item="item">
#{item}
</foreach>
and tb.debt_status in
<foreach collection="debtStatusList" open="(" separator="," close=")" item="item">
#{item}
</foreach>
and tb.debt_status is not null
group by c.name,cs.short_name,tb.debt_status
</select>
</mapper>