ShipmentQuantityIndustryStatisticsMapper.xml
9.01 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
<?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.ShipmentQuantityIndustryStatisticsMapper">
<resultMap id="ShipmentQuantityIndustryStatisticsDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsDto">
<result column="shipment_date" property="shipmentDate"/>
<result column="industry" property="industry"/>
<result column="workshop_id" property="workshopId"/>
<result column="workshop_code" property="workshopCode"/>
<result column="workshop_name" property="workshopName"/>
<result column="shipment_quantity" property="shipmentQuantity"/>
</resultMap>
<resultMap id="ShipmentQuantityStatisticsDateRangeDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityStatisticsDateRangeDto">
<result column="start_date" property="startDate"/>
<result column="end_date" property="endDate"/>
</resultMap>
<resultMap id="ShipmentQuantityIndustryStatisticsInvalidDto" type="com.lframework.xingyun.sc.dto.statistics.ShipmentQuantityIndustryStatisticsInvalidDto">
<result column="order_id" property="orderId"/>
<result column="order_no" property="orderNo"/>
<result column="line_id" property="lineId"/>
<result column="shipment_date" property="shipmentDate"/>
<result column="industry" property="industry"/>
<result column="workshop_id" property="workshopId"/>
<result column="quantity" property="quantity"/>
</resultMap>
<sql id="ShipmentQuantityIndustryStatistics_base_where">
o.type = 'PRODUCTION'
AND o.examine_status = 'PASS'
AND (o.status IS NULL OR o.status != 'CANCEL')
AND (ol.del_flag IS NULL OR ol.del_flag = 0)
</sql>
<select id="query" resultMap="ShipmentQuantityIndustryStatisticsDto">
SELECT
t.shipment_date,
t.industry,
t.workshop_id,
t.workshop_code,
t.shipment_quantity
FROM (
SELECT
ol.delivery_date AS shipment_date,
ol.industry AS industry,
o.workshop_id AS workshop_id,
ws.code AS workshop_code,
ws.name AS workshop_name,
SUM(ol.quantity) AS shipment_quantity
FROM tbl_purchase_order_line ol
INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id
LEFT JOIN base_data_workshop ws ON ws.id = o.workshop_id
WHERE
<include refid="ShipmentQuantityIndustryStatistics_base_where"/>
AND ol.delivery_date IS NOT NULL
AND ol.industry IS NOT NULL AND ol.industry != ''
AND o.workshop_id IS NOT NULL AND o.workshop_id != ''
AND ol.quantity IS NOT NULL
<if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''">
AND ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart}
</if>
<if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''">
AND ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd}
</if>
<if test="vo.industry != null and vo.industry != ''">
AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%')
</if>
<if test="vo.workshopId != null and vo.workshopId != ''">
AND o.workshop_id = #{vo.workshopId}
</if>
GROUP BY ol.delivery_date, ol.industry, o.workshop_id
) t
ORDER BY
t.shipment_date DESC,
CASE t.workshop_code
WHEN 'yfc' THEN 1
WHEN 'efc' THEN 2
WHEN 'sfc' THEN 3
WHEN 'ztfc' THEN 4
ELSE 99
END,
t.industry
</select>
<select id="queryDateRange" resultMap="ShipmentQuantityStatisticsDateRangeDto">
SELECT
MIN(t.shipment_date) AS start_date,
MAX(t.shipment_date) AS end_date
FROM (
SELECT
ol.delivery_date AS shipment_date
FROM tbl_purchase_order_line ol
INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id
WHERE
<include refid="ShipmentQuantityIndustryStatistics_base_where"/>
AND ol.delivery_date IS NOT NULL
AND ol.industry IS NOT NULL AND ol.industry != ''
AND o.workshop_id IS NOT NULL AND o.workshop_id != ''
AND ol.quantity IS NOT NULL
<if test="vo.industry != null and vo.industry != ''">
AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%')
</if>
<if test="vo.workshopId != null and vo.workshopId != ''">
AND o.workshop_id = #{vo.workshopId}
</if>
) t
</select>
<select id="queryIndustryDim" resultType="java.lang.String">
SELECT DISTINCT
ol.industry AS industry
FROM tbl_purchase_order_line ol
INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id
WHERE
<include refid="ShipmentQuantityIndustryStatistics_base_where"/>
AND ol.delivery_date IS NOT NULL
AND ol.industry IS NOT NULL AND ol.industry != ''
AND o.workshop_id IS NOT NULL AND o.workshop_id != ''
AND ol.quantity IS NOT NULL
<if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''">
AND ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart}
</if>
<if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''">
AND ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd}
</if>
<if test="vo.industry != null and vo.industry != ''">
AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%')
</if>
<if test="vo.workshopId != null and vo.workshopId != ''">
AND o.workshop_id = #{vo.workshopId}
</if>
ORDER BY ol.industry
</select>
<select id="queryWorkshopDimByCodes" resultMap="ShipmentQuantityIndustryStatisticsDto">
SELECT
w.id AS workshop_id,
w.code AS workshop_code,
w.name AS workshop_name
FROM base_data_workshop w
WHERE w.code IN
<foreach collection="codes" item="code" open="(" close=")" separator=",">
#{code}
</foreach>
ORDER BY
CASE w.code
WHEN 'yfc' THEN 1
WHEN 'efc' THEN 2
WHEN 'sfc' THEN 3
WHEN 'ztfc' THEN 4
ELSE 99
END,
w.name
</select>
<select id="queryWorkshopDimById" resultMap="ShipmentQuantityIndustryStatisticsDto">
SELECT
w.id AS workshop_id,
w.code AS workshop_code,
w.name AS workshop_name
FROM base_data_workshop w
WHERE w.id = #{workshopId}
</select>
<select id="queryInvalid" resultMap="ShipmentQuantityIndustryStatisticsInvalidDto">
SELECT
t.order_id,
t.order_no,
t.line_id,
t.shipment_date,
t.industry,
t.workshop_id,
t.quantity
FROM (
SELECT
o.id AS order_id,
o.order_no AS order_no,
ol.id AS line_id,
ol.delivery_date AS shipment_date,
ol.industry AS industry,
o.workshop_id AS workshop_id,
ol.quantity AS quantity,
o.create_time AS create_time
FROM tbl_purchase_order_line ol
INNER JOIN purchase_order_info o ON o.id = ol.purchase_order_id
WHERE
<include refid="ShipmentQuantityIndustryStatistics_base_where"/>
AND (
ol.delivery_date IS NULL
OR ol.industry IS NULL OR ol.industry = ''
OR o.workshop_id IS NULL OR o.workshop_id = ''
OR ol.quantity IS NULL
)
<if test="vo.shipmentDateStart != null and vo.shipmentDateStart != ''">
AND (ol.delivery_date IS NULL OR ol.delivery_date <![CDATA[>=]]> #{vo.shipmentDateStart})
</if>
<if test="vo.shipmentDateEnd != null and vo.shipmentDateEnd != ''">
AND (ol.delivery_date IS NULL OR ol.delivery_date <![CDATA[<=]]> #{vo.shipmentDateEnd})
</if>
<if test="vo.industry != null and vo.industry != ''">
AND ol.industry LIKE CONCAT('%', #{vo.industry}, '%')
</if>
<if test="vo.workshopId != null and vo.workshopId != ''">
AND o.workshop_id = #{vo.workshopId}
</if>
) t
ORDER BY t.create_time DESC
LIMIT 200
</select>
</mapper>