OrderDetailReportMapper.xml
16 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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?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.OrderDetailReportMapper">
<resultMap id="OrderDetailReport" type="com.lframework.xingyun.sc.entity.OrderDetailReport">
<id column="id" property="id"/>
<result column="purchase_order_line_id" property="purchaseOrderLineId"/>
<result column="order_no" property="orderNo"/>
<result column="order_date" property="orderDate"/>
<result column="workshop_id" property="workshopId"/>
<result column="workshop_name" property="workshopName"/>
<result column="dept_name" property="deptName"/>
<result column="region_name" property="regionName"/>
<result column="ordering_unit_name" property="orderingUnitName"/>
<result column="industry" property="industry"/>
<result column="brand" property="brand"/>
<result column="thickness" property="thickness"/>
<result column="thickness_tol_pos" property="thicknessTolPos"/>
<result column="thickness_tol_neg" property="thicknessTolNeg"/>
<result column="width" property="width"/>
<result column="width_tol_pos" property="widthTolPos"/>
<result column="width_tol_neg" property="widthTolNeg"/>
<result column="length" property="length"/>
<result column="length_tol_pos" property="lengthTolPos"/>
<result column="length_tol_neg" property="lengthTolNeg"/>
<result column="status" property="status"/>
<result column="quantity" property="quantity"/>
<result column="suggested_price" property="suggestedPrice"/>
<result column="delivery_date" property="deliveryDate"/>
<result column="assessment_exceeds_agreement" property="assessmentExceedsAgreement"/>
<result column="sales_price" property="salesPrice"/>
<result column="price_list_no" property="priceListNo"/>
<result column="packaging_fee" property="packagingFee"/>
<result column="invoicing_status" property="invoicingStatus"/>
<result column="piece_weight_header" property="pieceWeightHeader"/>
<result column="surface" property="surface"/>
<result column="tolerance" property="tolerance"/>
<result column="performance" property="performance"/>
<result column="packaging" property="packaging"/>
<result column="remarks" property="remarks"/>
<result column="shipping_cost" property="shippingCost"/>
<result column="return_shipping_cost" property="returnShippingCost"/>
<result column="customer_type" property="customerType"/>
<result column="quality" property="quality"/>
<result column="contract_type" property="contractType"/>
<result column="stock_up_company_name" property="stockUpCompanyName"/>
<result column="order_type" property="orderType"/>
<result column="show_order" property="showOrder"/>
<result column="type" property="type"/>
<result column="production_process" property="productionProcess"/>
<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="customer_short_name" property="customerShortName"/>
<result column="settlement_terms" property="settlementTerms"/>
<result column="execution_standard" property="executionStandard"/>
<result column="execution_standard_remarks" property="executionStandardRemarks"/>
<result column="structure_report_used" property="structureReportUsed"/>
<result column="contract_type_code" property="contractTypeCode"/>
<result column="special_requirements" property="specialRequirements"/>
<result column="contract_create_by" property="contractCreateBy"/>
</resultMap>
<sql id="OrderDetailReport_sql">
SELECT
tb.id,
tb.purchase_order_line_id,
tb.order_no,
tb.order_date,
tb.workshop_id,
ws.name AS workshop_name,
tb.dept_name,
tb.region_name,
tb.ordering_unit_name,
tb.industry,
tb.brand,
tb.thickness,
tb.thickness_tol_pos,
tb.thickness_tol_neg,
tb.width,
tb.width_tol_pos,
tb.width_tol_neg,
tb.length,
tb.length_tol_pos,
tb.length_tol_neg,
tb.status,
tb.quantity,
tb.suggested_price,
tb.delivery_date,
tb.assessment_exceeds_agreement,
tb.sales_price,
tb.price_list_no,
tb.packaging_fee,
tb.invoicing_status,
tb.piece_weight_header,
tb.surface,
tb.tolerance,
tb.performance,
tb.packaging,
tb.remarks,
tb.shipping_cost,
tb.return_shipping_cost,
tb.customer_type,
tb.quality,
tb.contract_type,
tb.stock_up_company_name,
tb.order_type,
tb.show_order,
tb.type,
tb.create_by_id,
tb.create_by,
tb.update_by_id,
tb.update_by,
tb.create_time,
tb.update_time
FROM order_detail_report AS tb
left join base_data_workshop as ws on ws.id = tb.workshop_id
</sql>
<!-- <select id="query" resultMap="OrderDetailReport">-->
<!-- <include refid="OrderDetailReport_sql"/>-->
<!-- <where>-->
<!-- <if test="vo.purchaseOrderLineId != null and vo.purchaseOrderLineId != ''">-->
<!-- AND tb.purchase_order_line_id = #{vo.purchaseOrderLineId}-->
<!-- </if>-->
<!-- <if test="vo.orderNo != null and vo.orderNo != ''">-->
<!-- AND tb.order_no LIKE CONCAT('%', #{vo.orderNo}, '%')-->
<!-- </if>-->
<!-- <if test="vo.workshopId != null and vo.workshopId != ''">-->
<!-- AND tb.workshop_id = #{vo.workshopId}-->
<!-- </if>-->
<!-- <if test="vo.deptName != null and vo.deptName != ''">-->
<!-- AND tb.dept_name LIKE CONCAT('%', #{vo.deptName}, '%')-->
<!-- </if>-->
<!-- <if test="vo.orderingUnitName != null and vo.orderingUnitName != ''">-->
<!-- AND tb.ordering_unit_name LIKE CONCAT('%', #{vo.orderingUnitName}, '%')-->
<!-- </if>-->
<!-- </where>-->
<!-- </select>-->
<sql id="OrderDetailReport_detail_select_sql">
SELECT
t.id,
t.purchase_order_line_id,
t.order_no,
t.order_date,
t.workshop_id,
ws.name AS workshop_name,
t.dept_name,
t.region_name,
t.ordering_unit_name,
t.industry,
t.brand,
t.thickness,
t.thickness_tol_pos,
t.thickness_tol_neg,
t.width,
t.width_tol_pos,
t.width_tol_neg,
t.length,
t.length_tol_pos,
t.length_tol_neg,
t.status,
t.quantity,
t.suggested_price,
t.delivery_date,
t.assessment_exceeds_agreement,
t.sales_price,
t.price_list_no,
t.packaging_fee,
t.invoicing_status,
t.piece_weight_header,
t.surface,
t.tolerance,
t.performance,
t.packaging,
t.remarks,
t.shipping_cost,
t.return_shipping_cost,
t.customer_type,
t.quality,
t.contract_type,
t.stock_up_company_name,
t.order_type,
t.show_order,
t.type,
t.production_process,
t.create_by_id,
t.create_by,
t.update_by_id,
t.update_by,
t.create_time,
t.update_time,
cs.short_name AS customer_short_name,
poi.settlement_terms AS settlement_terms,
poi.execution_standard AS execution_standard,
poi.execution_standard_remarks AS execution_standard_remarks,
CASE
WHEN c.type = 'PROCESS_STD_AGMT' THEN pl.product_id
ELSE cl.product_id
END AS structure_report_used,
c.type AS contract_type_code,
c.special_terms AS special_requirements,
c.create_by AS contract_create_by
FROM order_detail_report t
LEFT JOIN base_data_workshop ws ON ws.id = t.workshop_id
LEFT JOIN tbl_purchase_order_line pol ON pol.id = t.purchase_order_line_id
LEFT JOIN purchase_order_info poi ON poi.id = pol.purchase_order_id
LEFT JOIN tbl_contract_distributor_standard c ON c.id = poi.contract_id
LEFT JOIN base_data_customer_short cs ON cs.customer_id = poi.ordering_unit
LEFT JOIN tbl_contract_distributor_line cl ON cl.id = pol.contract_distributor_line_id
LEFT JOIN tbl_contract_std_processing_line pl ON pl.id = pol.contract_distributor_line_id
</sql>
<sql id="OrderDetailReport_page_id_from_sql">
FROM order_detail_report tb
LEFT JOIN (
SELECT
order_no,
purchase_order_line_id,
MAX(create_time) AS group_latest_time
FROM order_detail_report
GROUP BY order_no, purchase_order_line_id
) grp ON grp.order_no = tb.order_no
AND grp.purchase_order_line_id = tb.purchase_order_line_id
LEFT JOIN tbl_purchase_order_line pol ON pol.id = tb.purchase_order_line_id
LEFT JOIN purchase_order_info poi ON poi.id = pol.purchase_order_id
LEFT JOIN tbl_contract_distributor_standard c ON c.id = poi.contract_id
</sql>
<sql id="OrderDetailReport_page_id_where_sql">
<where>
<if test="vo.ids != null and !vo.ids.isEmpty()">
AND tb.id IN
<foreach collection="vo.ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="vo.purchaseOrderLineId != null and vo.purchaseOrderLineId != ''">
AND tb.purchase_order_line_id = #{vo.purchaseOrderLineId}
</if>
<if test="vo.orderNo != null and vo.orderNo != ''">
AND tb.order_no LIKE CONCAT('%', #{vo.orderNo}, '%')
</if>
<if test="vo.workshopId != null and vo.workshopId != ''">
AND tb.workshop_id = #{vo.workshopId}
</if>
<if test="vo.deptName != null and vo.deptName != ''">
AND tb.dept_name LIKE CONCAT('%', #{vo.deptName}, '%')
</if>
<if test="vo.orderingUnitName != null and vo.orderingUnitName != ''">
AND tb.ordering_unit_name LIKE CONCAT('%', #{vo.orderingUnitName}, '%')
</if>
<if test="vo.showOrder != null">
AND tb.show_order = #{vo.showOrder}
</if>
<if test="vo.orderNoPrecise != null and vo.orderNoPrecise != ''">
AND tb.order_no = #{vo.orderNoPrecise}
</if>
<if test="vo.type != null and vo.type != ''">
AND tb.type = #{vo.type}
</if>
<if test="vo.orderDateStart != null">
AND tb.order_date >= #{vo.orderDateStart}
</if>
<if test="vo.orderDateEnd != null">
<![CDATA[
AND tb.order_date <= #{vo.orderDateEnd}
]]>
</if>
<if test="vo.createTimeStart != null">
AND tb.create_time >= #{vo.createTimeStart}
</if>
<if test="vo.createTimeEnd != null">
<![CDATA[
AND tb.create_time <= #{vo.createTimeEnd}
]]>
</if>
<if test="vo.thickness != null and vo.thickness != ''">
AND tb.thickness = #{vo.thickness}
</if>
<if test="vo.width != null and vo.width != ''">
AND tb.width = #{vo.width}
</if>
<if test="vo.status != null and vo.status != ''">
AND tb.status = #{vo.status}
</if>
<if test="vo.inventoryUnlockedOnly != null and vo.inventoryUnlockedOnly">
AND c.type IN ('DIST_STOCK_CONTRACT', 'INTL_INVENTORY_AGMT')
AND c.status = 'FORMAL'
AND poi.type = 'PRODUCTION'
AND (c.price_spec_locked = 0 OR c.price_spec_locked IS NULL)
</if>
<if test="vo.excludeInventoryUnlocked != null and vo.excludeInventoryUnlocked">
AND (c.id IS NULL
OR
NOT(
c.type IN ('DIST_STOCK_CONTRACT', 'INTL_INVENTORY_AGMT')
AND c.status = 'FORMAL'
AND poi.type = 'PRODUCTION'
AND (
c.price_spec_locked = 0
OR c.price_spec_locked IS NULL
)
)
)
</if>
<if test="vo.orderCategory != null and vo.orderCategory != ''">
AND poi.examine_status = 'PASS'
<choose>
<when test="vo.orderCategory == 'PRICED'">
AND (
(c.type IN ('DIST_STOCK_CONTRACT', 'INTL_INVENTORY_AGMT') AND poi.type = 'NO_PRODUCTION')
OR (c.type IN ('DRAFT_DIST_AGMT', 'INTL_OPEN_SPEC_AGMT') AND poi.type IN ('PRODUCTION', 'NO_PRODUCTION'))
OR (c.type IN ('DISTRIB_STD', 'INTL_STD_CONTRACT', 'PROCESS_STD_AGMT') AND poi.type = 'PRODUCTION')
)
</when>
<when test="vo.orderCategory == 'INVENTORY'">
AND c.type IN ('DIST_STOCK_CONTRACT', 'INTL_INVENTORY_AGMT')
AND poi.type = 'PRODUCTION'
</when>
<when test="vo.orderCategory == 'OPEN_SPEC'">
AND c.type IN ('DRAFT_DIST_AGMT', 'INTL_OPEN_SPEC_AGMT')
AND poi.type = 'NO_PRODUCTION'
</when>
<otherwise>
AND 1 = 0
</otherwise>
</choose>
</if>
</where>
</sql>
<sql id="OrderDetailReport_page_id_order_sql">
ORDER BY
grp.group_latest_time DESC,
tb.order_no ASC,
tb.purchase_order_line_id ASC,
tb.show_order ASC
</sql>
<select id="findById" resultMap="OrderDetailReport">
<include refid="OrderDetailReport_detail_select_sql"/>
<where>
<if test="id != null and id != ''">
AND t.id = #{id}
</if>
</where>
</select>
<select id="queryPageIds" resultType="java.lang.String">
SELECT tb.id
<include refid="OrderDetailReport_page_id_from_sql"/>
<include refid="OrderDetailReport_page_id_where_sql"/>
<include refid="OrderDetailReport_page_id_order_sql"/>
</select>
<select id="authQueryPageIds" resultType="java.lang.String">
SELECT tb.id
<include refid="OrderDetailReport_page_id_from_sql"/>
<include refid="OrderDetailReport_page_id_where_sql"/>
<include refid="OrderDetailReport_page_id_order_sql"/>
</select>
<select id="queryByIds" resultMap="OrderDetailReport">
<include refid="OrderDetailReport_detail_select_sql"/>
WHERE t.id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
ORDER BY FIELD(t.id,
<foreach collection="ids" item="id" separator=",">
#{id}
</foreach>
)
</select>
</mapper>