OrderBaseInfoMapper.xml
7.36 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.order.erp.mapper.order.OrderBaseInfoMapper">
<select id="queryProjectNoAndInnerNoDto" resultType="com.order.erp.domain.vo.order.QueryProjectNoAndInnerNoDto">
<if test="flag == true">
SELECT DISTINCT project_no
FROM order_base_info
WHERE enable_flag = 10
AND project_no like concat('%',#{dto.projectNo},'%')
</if>
<if test="flag == false">
SELECT DISTINCT inner_no
FROM order_base_info
WHERE enable_flag = 10
AND inner_no like concat('%',#{dto.innerNo},'%')
</if>
</select>
<select id="salesAmountStatistics" resultType="java.lang.Double">
SELECT SUM(opa.customer_total_price) AS total_price
FROM order_base_info obi
JOIN order_profit_analysis opa ON opa.order_id = obi.id and opa.enable_flag = 10
WHERE obi.enable_flag = 10 <!-- 用于动态添加条件 -->
<!-- 动态添加 customer_code 条件 -->
<if test="customerCodeIn != null and customerCodeIn.size() > 0">
AND customer_code IN
<foreach collection="customerCodeIn" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<!-- 动态添加 create_time 范围条件 -->
<if test="begin != null">
AND obi.create_time >= #{begin}
</if>
<if test="end != null">
AND obi.create_time <![CDATA[ <= ]]> #{end}
</if>
</select>
<select id="salesAmountTarget" resultType="java.lang.Double">
SELECT SUM(relation_value) AS total_value
FROM system_setting
WHERE relation_code = 'salesAmount'
and enable_flag = 10
<!-- 动态添加 setting_name 条件 -->
<if test="customerCodeIn != null and customerCodeIn.size() > 0">
AND setting_value IN
<foreach collection="customerCodeIn" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
<resultMap id="mapResult" type="map">
<result property="key" column="k"/>
<result property="value" column="v"/>
</resultMap>
<select id="customerSalesStatus" resultMap="mapResult">
SELECT
obi.customer_code AS k,
SUM(opa.customer_total_price) AS v
FROM
order_base_info obi
JOIN
order_profit_analysis opa ON opa.order_id = obi.id AND opa.enable_flag = 10
WHERE
obi.enable_flag = 10
<if test="customerCodeIn != null and customerCodeIn.size() > 0">
AND obi.customer_code IN
<foreach item="item" index="index" collection="customerCodeIn" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="begin != null">
AND obi.create_time >= #{begin}
</if>
<if test="end != null">
AND obi.create_time <![CDATA[ <= ]]> #{end}
</if>
GROUP BY
obi.customer_code
</select>
<select id="countRecentMonthValueByOrderStatus" resultType="com.order.erp.domain.vo.order.DateYearMonthTimeVO">
SELECT
DATE_FORMAT(obi.create_time, '%Y-%m') AS date,
SUM(opa.customer_total_price) AS totalPrice,
YEAR(obi.create_time) AS yearType
FROM
order_base_info obi
JOIN
order_profit_analysis opa
ON
opa.order_id = obi.id
AND opa.enable_flag = 10
WHERE
obi.enable_flag = 10
AND YEAR(obi.create_time) IN
<foreach item="year" collection="years" open="(" close=")" separator=",">
#{year}
</foreach>
GROUP BY
DATE_FORMAT(obi.create_time, '%Y-%m'),
YEAR(obi.create_time)
ORDER BY
date;
</select>
<select id="sameAttributeOrder" resultType="com.order.erp.domain.dto.order.OrderBaseInfoDO">
SELECT
obi.*
FROM
order_base_info obi
JOIN
order_inspection_stage opa
ON
opa.order_id = obi.id
AND opa.enable_flag = 10
WHERE
obi.enable_flag = 10
AND
obi.customer_style = #{customerStyle}
AND
obi.inner_no = #{innerNo}
AND
obi.return_order = #{isReturnOrder}
AND
obi.create_time BETWEEN #{monthsAgo} AND #{now}
</select>
<select id="countRecentYearByOrderInit" resultType="java.lang.Long">
SELECT COUNT(*)
FROM (SELECT project_no, inner_no
FROM order_base_info
WHERE enable_flag = 10
AND (return_order != '1' OR return_order IS NULL)
GROUP BY project_no, inner_no) AS unique_combinations;
</select>
<select id="countRecentMonthValueByOrderInit" resultType="java.lang.Long">
SELECT COUNT(*)
FROM (
SELECT project_no, inner_no
FROM order_base_info
WHERE enable_flag = 10
AND (return_order != '1' OR return_order IS NULL) -- 处理 NULL 值
AND inner_no LIKE CONCAT('_____', #{dataYear}, '%') -- 直接匹配年份
GROUP BY project_no, inner_no
) AS unique_combinations;
</select>
<select id="countRecentDayByOrderInit" resultType="java.lang.Long">
SELECT COUNT(*)
FROM (
SELECT project_no, inner_no
FROM order_base_info
WHERE enable_flag = 10
AND (return_order != '1' OR return_order IS NULL)
AND create_time >= #{startDate}
AND create_time <![CDATA[ < ]]> #{endDate}
AND inner_no LIKE CONCAT('_____', #{year}, '%')
GROUP BY project_no, inner_no
) AS unique_combinations;
</select>
<select id="countAllYearByOrderStatus" resultType="java.lang.Long">
SELECT COUNT(*)
FROM (
SELECT project_no, inner_no
FROM order_base_info
WHERE enable_flag = 10
AND (return_order != '1' OR return_order IS NULL)
AND order_status=#{orderStatus}
GROUP BY project_no, inner_no
) AS unique_combinations;
</select>
<select id="countAllMonthByOrderStatus" resultType="java.lang.Long">
SELECT COUNT(*)
FROM (
SELECT project_no, inner_no
FROM order_base_info
WHERE enable_flag = 10
AND (return_order != '1' OR return_order IS NULL)
AND order_status=#{orderStatus}
AND inner_no LIKE CONCAT('_____', #{dataYear}, '%') -- 直接匹配年份
GROUP BY project_no, inner_no
) AS unique_combinations;
</select>
<select id="countAllDayvalueByOrderStatus" resultType="java.lang.Long">
SELECT COUNT(*)
FROM (
SELECT project_no, inner_no
FROM order_base_info
WHERE enable_flag = 10
AND (return_order != '1' OR return_order IS NULL)
AND create_time >= #{startDate}
AND create_time <![CDATA[ < ]]> #{endDate}
AND order_status=#{orderStatus}
AND inner_no LIKE CONCAT('_____', #{year}, '%')
GROUP BY project_no, inner_no
) AS unique_combinations;
</select>
</mapper>