ProcurementWeighingTicketMapper.xml
17.5 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
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
<?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.procurement.mappers.weighing.ProcurementWeighingTicketMapper">
<resultMap id="ProcurementWeighingTicketResult" type="com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicket">
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="type" property="type"/>
<result column="origin_weighing_ticket_id" property="originWeighingTicketId"/>
<result column="unit" property="unit"/>
<result column="first_gross_weight_time" property="firstGrossWeightTime"/>
<result column="complete_time" property="completeTime"/>
<result column="supplier_id" property="supplierId"/>
<result column="supplier_name" property="supplierName"/>
<result column="company_short_id" property="companyShortId"/>
<result column="company_short_name" property="companyShortName"/>
<result column="workshop_id" property="workshopId"/>
<result column="workshop_name" property="workshopName"/>
<result column="workshop_code" property="workshopCode"/>
<result column="buyout" property="buyout"/>
<result column="material_name" property="materialName"/>
<result column="total_gross_weight" property="totalGrossWeight"/>
<result column="actual_impurity_weight" property="actualImpurityWeight"/>
<result column="net_weight" property="netWeight"/>
<result column="net_weight_upper" property="netWeightUpper"/>
<result column="deduction_types" property="deductionTypes"/>
<result column="supplier_stock_material" property="supplierStockMaterial"/>
<result column="logistics_stock_material" property="logisticsStockMaterial"/>
<result column="plate_number" property="plateNumber"/>
<result column="business_summary" property="businessSummary"/>
<result column="special_note" property="specialNote"/>
<result column="document_remark" property="documentRemark"/>
<result column="approval_status" property="approvalStatus"/>
<result column="sign_attachment_file_ids" property="signAttachmentFileIds"/>
<result column="sign_attachment_file_names" property="signAttachmentFileNames"/>
<result column="delay_attachment_file_ids" property="delayAttachmentFileIds"/>
<result column="delay_attachment_file_names" property="delayAttachmentFileNames"/>
<result column="reweigh_attachment_file_ids" property="reweighAttachmentFileIds"/>
<result column="reweigh_attachment_file_names" property="reweighAttachmentFileNames"/>
<result column="deleted" property="deleted"/>
<result column="create_by_id" property="createById"/>
<result column="create_by" property="createBy"/>
<result column="update_by_id" property="updateById"/>
<result column="update_by" property="updateBy"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="plan_codes" property="planCodes"/>
<result column="plan_ids" property="planIds"/>
</resultMap>
<sql id="PWT_sql">
SELECT
pwt.id,
pwt.code,
pwt.type,
pwt.origin_weighing_ticket_id,
pwt.unit,
pwt.first_gross_weight_time,
pwt.complete_time,
pwt.supplier_id,
pwt.supplier_name,
pwt.company_short_id,
pwt.company_short_name,
pwt.workshop_id,
pwt.workshop_name,
ws.code AS workshop_code,
pwt.buyout,
pwt.material_name,
pwt.total_gross_weight,
pwt.actual_impurity_weight,
pwt.net_weight,
pwt.net_weight_upper,
pwt.deduction_types,
pwt.supplier_stock_material,
pwt.logistics_stock_material,
pwt.plate_number,
pwt.business_summary,
pwt.special_note,
pwt.document_remark,
pwt.approval_status,
pwt.sign_attachment_file_ids,
pwt.sign_attachment_file_names,
pwt.delay_attachment_file_ids,
pwt.delay_attachment_file_names,
pwt.reweigh_attachment_file_ids,
pwt.reweigh_attachment_file_names,
pwt.deleted,
pwt.create_by_id,
pwt.create_by,
pwt.update_by_id,
pwt.update_by,
pwt.create_time,
pwt.update_time,
(
SELECT GROUP_CONCAT(DISTINCT pwtp.plan_code ORDER BY pwtp.order_no SEPARATOR ',')
FROM procurement_weighing_ticket_plan pwtp
WHERE pwtp.weighing_ticket_id = pwt.id
) AS plan_codes,
(
SELECT GROUP_CONCAT(DISTINCT pwtpi.procurement_plan_id SEPARATOR ',')
FROM procurement_weighing_ticket_plan pwtpi
WHERE pwtpi.weighing_ticket_id = pwt.id
) AS plan_ids
FROM procurement_weighing_ticket AS pwt
LEFT JOIN base_data_workshop ws ON ws.id = pwt.workshop_id
</sql>
<select id="query" resultMap="ProcurementWeighingTicketResult">
<include refid="PWT_sql"/>
<where>
<choose>
<when test="vo.deleted != null">
AND pwt.deleted = #{vo.deleted}
</when>
<otherwise>
AND pwt.deleted = 0
</otherwise>
</choose>
<if test="vo != null">
<if test="vo.code != null and vo.code != ''">
AND pwt.code LIKE CONCAT('%', #{vo.code}, '%')
</if>
<if test="vo.planCode != null and vo.planCode != ''">
AND EXISTS (
SELECT 1 FROM procurement_weighing_ticket_plan pwtp
WHERE pwtp.weighing_ticket_id = pwt.id
AND pwtp.plan_code LIKE CONCAT('%', #{vo.planCode}, '%')
)
</if>
<if test="vo.supplierName != null and vo.supplierName != ''">
AND pwt.supplier_name LIKE CONCAT('%', #{vo.supplierName}, '%')
</if>
<if test="vo.companyShortId != null and vo.companyShortId != ''">
AND pwt.company_short_id = #{vo.companyShortId}
</if>
<if test="vo.approvalStatus != null and vo.approvalStatus != ''">
AND pwt.approval_status = #{vo.approvalStatus}
</if>
<if test="vo.startTime != null">
AND pwt.first_gross_weight_time <![CDATA[ >= ]]> #{vo.startTime}
</if>
<if test="vo.endTime != null">
AND pwt.first_gross_weight_time <![CDATA[ <= ]]> #{vo.endTime}
</if>
<if test="vo.createBy != null and vo.createBy != ''">
AND pwt.create_by LIKE CONCAT('%', #{vo.createBy}, '%')
</if>
<if test="vo.createById != null and vo.createById != ''">
AND pwt.create_by_id = #{vo.createById}
</if>
<if test="vo.createByIdList != null and vo.createByIdList.size() > 0">
AND pwt.create_by_id IN
<foreach collection="vo.createByIdList" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</if>
</if>
</where>
ORDER BY pwt.create_time DESC
</select>
<select id="findById" resultMap="ProcurementWeighingTicketResult">
<include refid="PWT_sql"/>
WHERE pwt.id = #{id}
</select>
<!-- 查询以指定前缀开头的最大编号(用于生成当日流水号),不过滤 deleted 避免与作废单据重复 -->
<select id="findMaxCodeByPrefix" resultType="java.lang.String">
SELECT MAX(pwt.code)
FROM procurement_weighing_ticket pwt
WHERE pwt.code LIKE CONCAT(#{prefix}, '%')
</select>
<!-- 可关联过磅码单的采购计划(新增过磅码单选择计划弹窗) -->
<resultMap id="WeighingTicketPlanResult" type="com.lframework.xingyun.sc.bo.procurement.WeighingTicketPlanBo">
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="company_short_id" property="companyShortId"/>
<result column="company_name" property="companyName"/>
<result column="supplier_id" property="supplierId"/>
<result column="supplier_name" property="supplierName"/>
<result column="purchase_department" property="purchaseDepartment"/>
<result column="purchase_department_name" property="purchaseDepartmentName"/>
<result column="region" property="region"/>
<result column="region_name" property="regionName"/>
<result column="process_status" property="processStatus"/>
<result column="plan_type" property="planType"/>
<result column="total_quantity" property="totalQuantity"/>
<result column="buyout" property="buyout"/>
<result column="workshop_id" property="workshopId"/>
<result column="workshop_name" property="workshopName"/>
<result column="create_by" property="createBy"/>
<result column="create_time" property="createTime"/>
</resultMap>
<select id="queryWeighingTicketPlans" resultMap="WeighingTicketPlanResult">
SELECT
pp.id,
pp.code,
pp.company_short_id,
bdcs.company_name AS company_name,
pp.supplier_id,
pdc.unit_name AS supplier_name,
pp.purchase_department,
sd.name AS purchase_department_name,
pp.region,
sd1.name AS region_name,
pp.process_status,
pp.plan_type,
pp.total_quantity,
CASE WHEN pp.commodity_buyout = 1 OR pp.quality_buyout = 1 OR pp.quantity_buyout = 1
THEN 1 ELSE 0 END AS buyout,
pp.workshop_id,
ws.name AS workshop_name,
pp.create_by,
pp.create_time
FROM procurement_plan AS pp
LEFT JOIN base_data_company_short AS bdcs ON bdcs.id = pp.company_short_id
LEFT JOIN procurement_domestic_customer_credit pdc ON pdc.id = pp.supplier_id
LEFT JOIN sys_dept sd ON sd.id = pp.purchase_department
LEFT JOIN sys_dept sd1 ON sd1.id = pp.region
LEFT JOIN base_data_workshop AS ws ON ws.id = pp.workshop_id
<where>
AND pp.deleted = 0
<!-- 未冻结 -->
AND (pp.frozen = 0 OR pp.frozen IS NULL)
<!-- 流程状态已完成 -->
AND pp.process_status = 'COMPLETED'
<!-- 不在变更中(空或变更完成可选) -->
AND (pp.change_status = '' OR pp.change_status IS NULL OR pp.change_status = 'CHANGED')
<!-- 不在补单中(空或补单完成可选) -->
AND (pp.replenishment_status = '' OR pp.replenishment_status IS NULL
OR pp.replenishment_status = 'REPLENISHED')
<!-- 多计划一致性:非买断/买断、供料单位、收料单位保持一致 -->
<if test="vo != null">
<if test="vo.code != null and vo.code != ''">
AND pp.code LIKE CONCAT('%', #{vo.code}, '%')
</if>
<if test="vo.companyName != null and vo.companyName != ''">
AND bdcs.company_name LIKE CONCAT('%', #{vo.companyName}, '%')
</if>
<if test="vo.purchaseDeptId != null and vo.purchaseDeptId != ''">
AND pp.purchase_department = #{vo.purchaseDeptId}
</if>
<if test="vo.supplierName != null and vo.supplierName != ''">
AND pdc.unit_name LIKE CONCAT('%', #{vo.supplierName}, '%')
</if>
<if test="vo.planType != null and vo.planType != ''">
AND pp.plan_type = #{vo.planType}
</if>
<if test="vo.buyout != null">
<choose>
<when test="vo.buyout">
AND (pp.commodity_buyout = 1 OR pp.quality_buyout = 1 OR pp.quantity_buyout = 1)
</when>
<otherwise>
AND pp.commodity_buyout = 0
AND pp.quality_buyout = 0
AND pp.quantity_buyout = 0
</otherwise>
</choose>
</if>
<if test="vo.supplierId != null and vo.supplierId != ''">
AND pp.supplier_id = #{vo.supplierId}
</if>
<if test="vo.companyShortId != null and vo.companyShortId != ''">
AND pp.company_short_id = #{vo.companyShortId}
</if>
<if test="vo.workshopId != null and vo.workshopId != ''">
AND pp.workshop_id = #{vo.workshopId}
</if>
</if>
</where>
ORDER BY pp.create_time DESC
</select>
<!-- 过磅码单可选采购计划:复用 ProcurementPlan 的 JOIN 取名称,供新增/修改校验与数据带出 -->
<resultMap id="WeighCandidatePlanResult" type="com.lframework.xingyun.sc.procurement.entity.ProcurementPlan">
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="parent_id" property="parentId"/>
<result column="company_short_id" property="companyShortId"/>
<result column="company_short_name" property="companyShortName"/>
<result column="supplier_id" property="supplierId"/>
<result column="supplier_name" property="supplierName"/>
<result column="workshop_id" property="workshopId"/>
<result column="workshop_name" property="workshopName"/>
<result column="date" property="date"/>
<result column="quoter_name" property="quoterName"/>
<result column="total_quantity" property="totalQuantity"/>
<result column="commodity_buyout" property="commodityBuyout"/>
<result column="quality_buyout" property="qualityBuyout"/>
<result column="quantity_buyout" property="quantityBuyout"/>
<result column="approval_status" property="approvalStatus"/>
<result column="process_status" property="processStatus"/>
<result column="change_status" property="changeStatus"/>
<result column="replenishment_status" property="replenishmentStatus"/>
<result column="deleted" property="deleted"/>
<result column="create_by_id" property="createById"/>
<result column="create_by" property="createBy"/>
<result column="create_time" property="createTime"/>
</resultMap>
<!-- 按计划ID批量查询满足过磅码单条件的采购计划(新增/修改时的选择校验与自动带出) -->
<select id="getCandidatePlansByIds" resultMap="WeighCandidatePlanResult">
SELECT
pp.id,
pp.code,
pp.parent_id,
pp.company_short_id,
bdcs.short_name AS company_short_name,
pp.supplier_id,
pdc.unit_name AS supplier_name,
pp.workshop_id,
ws.name AS workshop_name,
pp.date,
pp.quoter_name,
pp.total_quantity,
pp.commodity_buyout,
pp.quality_buyout,
pp.quantity_buyout,
pp.approval_status,
pp.process_status,
pp.change_status,
pp.replenishment_status,
pp.deleted,
pp.create_by_id,
pp.create_by,
pp.create_time
FROM procurement_plan AS pp
LEFT JOIN base_data_company_short AS bdcs ON bdcs.id = pp.company_short_id
LEFT JOIN procurement_domestic_customer_credit pdc ON pdc.id = pp.supplier_id
LEFT JOIN base_data_workshop AS ws ON ws.id = pp.workshop_id
WHERE pp.id IN
<foreach collection="ids" open="(" separator="," close=")" item="item">
#{item}
</foreach>
AND pp.deleted = 0
<!-- 未冻结 -->
AND (pp.frozen = 0 OR pp.frozen IS NULL)
<!-- 流程状态已完成 -->
AND pp.process_status = 'COMPLETED'
<!-- 不在变更中(空或变更完成可选) -->
AND (pp.change_status = '' OR pp.change_status IS NULL OR pp.change_status = 'CHANGED')
<!-- 不在补单中(空或补单完成可选) -->
AND (pp.replenishment_status = '' OR pp.replenishment_status IS NULL
OR pp.replenishment_status = 'REPLENISHED')
</select>
<!-- 按采购计划ID聚合已过磅数量(仅统计未作废且已完成,即完成时间不为空的过磅码单;单位:公斤) -->
<select id="sumWeighedQuantityByPlanIds" resultType="com.lframework.xingyun.sc.dto.PlanWeighedQuantityDto">
SELECT
pwtl.procurement_plan_id AS planId,
SUM(pwtl.quantity) AS totalQuantity
FROM procurement_weighing_ticket_line pwtl
INNER JOIN procurement_weighing_ticket pwt ON pwt.id = pwtl.weighing_ticket_id
WHERE pwt.deleted = 0
AND pwt.complete_time IS NOT NULL
AND pwtl.procurement_plan_id IN
<foreach collection="planIds" open="(" separator="," close=")" item="item">
#{item}
</foreach>
GROUP BY pwtl.procurement_plan_id
</select>
</mapper>