MerchantStatic.java
13.6 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
package com.glsk.compute;
import com.glsk.compute.brand.PlatformMerchantBrand;
import com.glsk.entity.EmployeeFlowData;
import com.glsk.entity.MerchantStaticData;
import com.glsk.mapper.DatavMapper;
import com.glsk.util.DateUtils;
import com.glsk.util.MybatisUtil;
import com.glsk.util.MysqlUtils;
import org.apache.ibatis.session.SqlSession;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author fangfang
* @create 2024-03-27 13:54
*/
public class MerchantStatic {
public static void main(String[] args)throws Exception {
System.out.println("门店统计开始。。。。。。。。");
queryMerchantData("1970-01-01", DateUtils.getToday());
queryMerchantSupervision();
queryMerchantStaffFlowData("1970-01-01",DateUtils.getToday());
System.out.println("门店统计完成。。。。。。。。");
}
public static void queryMerchantData (String startdate,String enddate ) throws Exception {
Connection connQuery = MysqlUtils.getConnection("dj_smartcarlife");
Connection connInsert = MysqlUtils.getConnection("insert");
Connection connQuery02 = MysqlUtils.getConnection("scrm_account");
String sql00 = QuerySql.getqueryMerchantDatasql00(startdate, enddate);
//获取sql
String sql01 = QuerySql.getqueryMerchantDatasql01(startdate, enddate);
ResultSet rs00 = connQuery.prepareStatement(sql00).executeQuery(sql00);
ArrayList<String> merchantNoList =new ArrayList<>();
while (rs00.next()){
merchantNoList.add(rs00.getString("merchant_id"));
}
String merchantNo = merchantNoList.stream().map(String::valueOf).collect(Collectors.joining("','", "('", "')"));
String sql02 = QuerySql.getqueryMerchantDatasql02(startdate, enddate,merchantNo);
ResultSet rs02 = connQuery02.prepareStatement(sql02).executeQuery(sql02);
//预编译
PreparedStatement st = connQuery.prepareStatement(sql01);
// 执行查询并获取结果
ResultSet rs = st.executeQuery(sql01);
//品牌
List<Map<String, String>> merBrandMap = PlatformMerchantBrand.queryBrandByMerchantNo();
//插入sql
String insertsql = "INSERT INTO business_analysis_overview (stat_date, merchant_id, merchant_name, business_type, item_name, output, ordernum, total_ordernum, to_store, aftersales_to_store, buynum, quotation_director_name,service_boss,created_date,province_code,province_name,city_code,city_name) " +
" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) " +
"ON DUPLICATE KEY UPDATE " +
"stat_date=VALUES(stat_date), " +
"merchant_id=VALUES(merchant_id), " +
"merchant_name=VALUES(merchant_name), " +
"business_type=VALUES(business_type), " +
"item_name=VALUES(item_name), " +
"output=VALUES(output), " +
"ordernum=VALUES(ordernum), " +
"total_ordernum=VALUES(total_ordernum), " +
"to_store=VALUES(to_store), " +
"aftersales_to_store=VALUES(aftersales_to_store), " +
"buynum=VALUES(buynum), " +
"quotation_director_name=VALUES(quotation_director_name), " +
"service_boss=VALUES(service_boss), " +
"created_date=VALUES(created_date)," +
"province_code=VALUES(province_code)," +
"province_name=VALUES(province_name)," +
"city_code=VALUES(city_code)," +
"city_name=VALUES(city_name)";
PreparedStatement ps = connInsert.prepareStatement(insertsql);
String created_date="";
// 遍历结果集
while (rs.next()) {
created_date=rs.getString("created_date");
String merchant_id=rs.getString("4s店商户号");
ps.setString(1, rs.getString("statdate"));
ps.setString(2, rs.getString("4s店商户号"));
ps.setString(3, rs.getString("服务门店"));
ps.setString(4, rs.getString("业务类型"));
ps.setString(5, null);
ps.setString(6, rs.getString("个人产值"));
ps.setString(7, rs.getString("升级订单数"));
ps.setString(8, rs.getString("升级战败订单总数"));
ps.setString(9, rs.getString("新车到店流量"));
ps.setString(10, rs.getString("售后到店流量"));
ps.setString(11, rs.getString("新车交付数"));
ps.setString(12, rs.getString("业务负责人姓名"));
ps.setString(13, rs.getString("服务商负责人姓名"));
ps.setString(14, rs.getString("created_date"));
ps.setString(15, null);
ps.setString(16, null);
ps.setString(17, null);
ps.setString(18, null);
//品牌赋值
for (Map<String, String> stringStringMap : merBrandMap) {
if(stringStringMap.get(merchant_id)!=""&&stringStringMap.get(merchant_id)!=null
&&stringStringMap.get(merchant_id).equals("鸿蒙智行")){
ps.setString(5, "赛力斯项目");
break;
}
}
while (rs02.next()){
if(merchant_id.equals(rs02.getString("merchantNo"))){
ps.setString(15, rs02.getString("province_code"));
ps.setString(16, rs02.getString("province_name"));
ps.setString(17, rs02.getString("city_code"));
ps.setString(18, rs02.getString("city_name"));
break;
}
}
// System.out.println("insertSql=" + insertsql);
//6.执行操作
ps.executeUpdate();
}
if(created_date==null||created_date.equals("")){created_date=DateUtils.getToday(); }
String deleteSql="delete from business_analysis_overview where created_date!='"+created_date+"'";
connInsert.prepareStatement(deleteSql).executeUpdate();
System.out.println("统计完成>>>>>>>>>>>>");
String update01="update business_analysis_overview a,\n" +
"(select distinct province_code,province_name from business_analysis_province_city_district) b\n" +
"set a.province_name=b.province_name\n" +
"where a.province_code=b.province_code";
String update02="update business_analysis_overview a,\n" +
"(select distinct city_code,city_name from business_analysis_province_city_district) b\n" +
"set a.city_code=b.city_code\n" +
"where a.city_name=b.city_name";
connInsert.prepareStatement(update01).executeUpdate();
connInsert.prepareStatement(update02).executeUpdate();
// 关闭结果集、Statement和连接
rs.close();
rs02.close();
rs00.close();
//关闭PreparedStatement
ps.close();
st.close();
//关闭连接
connQuery.close();
connInsert.close();
System.out.println("已关闭");
}
//business_analysis_merchant_supervision_relation
public static void queryMerchantSupervision () throws Exception {
Connection connQuery = MysqlUtils.getConnection("dj_smartcarlife");
Connection connInsert = MysqlUtils.getConnection("insert");
//获取sql
String sql01 = QuerySql.queryMerchantSupervision01();
//预编译
PreparedStatement st = connQuery.prepareStatement(sql01);
// 执行查询并获取结果
ResultSet rs = st.executeQuery(sql01);
//插入sql
String insertsql = "INSERT INTO business_analysis_merchant_supervision_relation (data_month, merchant_id, area_supervision, area_supervision_phone,created_date) " +
" VALUES (?,?,?,?,?) " +
"ON DUPLICATE KEY UPDATE " +
"data_month=VALUES(data_month), " +
"merchant_id=VALUES(merchant_id), " +
"area_supervision=VALUES(area_supervision), " +
"area_supervision_phone=VALUES(area_supervision_phone) ,"+
"created_date=VALUES(created_date) " ;
PreparedStatement ps = connInsert.prepareStatement(insertsql);
String created_date="";
// 遍历结果集
while (rs.next()) {
created_date=rs.getString("created_date");
ps.setString(1, rs.getString("data_month"));
ps.setString(2, rs.getString("merchant_id"));
ps.setString(3, rs.getString("区域督导"));
ps.setString(4, rs.getString("区域督导电话"));
ps.setString(5, rs.getString("created_date"));
// System.out.println("insertSql=" + insertsql);
//6.执行操作
ps.executeUpdate();
}
if(created_date==null||created_date.equals("")){created_date=DateUtils.getToday(); }
String deleteSql="delete from business_analysis_merchant_supervision_relation where created_date!='"+created_date+"'";
connInsert.prepareStatement(deleteSql).executeUpdate();
System.out.println("统计完成>>>>>>>>>>>>");
// 关闭结果集、Statement和连接
rs.close();
//关闭PreparedStatement
ps.close();
st.close();
//关闭连接
connQuery.close();
connInsert.close();
System.out.println("已关闭");
}
public static void queryMerchantStaffFlowData (String startdate,String enddate )throws Exception {
Connection connQuery = MysqlUtils.getConnection("dj_smartcarlife");
Connection connQuery02 = MysqlUtils.getConnection("scrm_account");
Connection connInsert = MysqlUtils.getConnection("insert");
//获取sql
String sql01 = QuerySql.getqueryMerchantStaffFlowDatasql01(startdate, enddate);
//预编译
PreparedStatement st = connQuery.prepareStatement(sql01);
// 执行查询并获取结果
ResultSet rs = st.executeQuery(sql01);
//获取sql
String sql02 = QuerySql.getqueryMerchantStaffFlowDatasql02(startdate, enddate);
//预编译
PreparedStatement st02 = connQuery02.prepareStatement(sql02);
// 执行查询并获取结果
ResultSet rs2 = st02.executeQuery(sql02);
//插入sql
String insertsql = "INSERT INTO business_analysis_employee_flow (stat_date, staff_id, staff_name, staff_phone, merchant_id, merchant_name, business_type, ordernum, total_ordernum, daily_contribution_traffic, created_date)" +
" VALUES (?,?,?,?,?,?,?,?,?,?,?) " +
"ON DUPLICATE KEY UPDATE " +
"stat_date=VALUES(stat_date), " +
"staff_id=VALUES(staff_id), " +
"staff_name=VALUES(staff_name), " +
"staff_phone=VALUES(staff_phone), " +
"merchant_id=VALUES(merchant_id), " +
"merchant_name=VALUES(merchant_name), " +
"business_type=VALUES(business_type), " +
"ordernum=VALUES(ordernum), " +
"total_ordernum=VALUES(total_ordernum), " +
"daily_contribution_traffic=VALUES(daily_contribution_traffic), " +
"created_date=VALUES(created_date)";
PreparedStatement ps = connInsert.prepareStatement(insertsql);
String created_date="";
// 遍历结果集
while (rs.next()) {
created_date=rs.getString("created_date");
String staff_id=rs.getString("user_id");
ps.setString(1, rs.getString("statdate"));//stat_date
ps.setString(2, rs.getString("user_id"));//staff_id
ps.setString(3, rs.getString("employee_name"));//staff_name
ps.setString(4, null);//staff_phone
ps.setString(5, rs.getString("merchant_id"));//merchant_id
ps.setString(6, rs.getString("merchant_name"));//merchant_name
ps.setString(7, rs.getString("业务类型"));//business_type
ps.setString(8, rs.getString("升级订单数"));//ordernum
ps.setString(9, rs.getString("升级战败订单总数"));//total_ordernum
ps.setString(10, rs.getString("升级战败订单总数"));//daily_contribution_traffic
ps.setString(11, rs.getString("created_date"));//created_date
while (rs2.next()) {
if(rs2.getString("staff_uuid").equals(staff_id)){
ps.setString(3,rs2.getString("staff_name"));//员工姓名 (以账户中心为主,若账户中心被删了(个别),就直接取订单表里的)
ps.setString(4,rs2.getString("staff_phone"));//staff_phone
}
}
rs2.beforeFirst();
System.out.println("insertSql=" + insertsql);
//6.执行操作
ps.executeUpdate();
}
if(created_date==null||created_date.equals("")){ created_date=DateUtils.getToday();}
String deleteSql="delete from business_analysis_employee_flow where created_date!='"+created_date+"'";
connInsert.prepareStatement(deleteSql).executeUpdate();
System.out.println("统计完成>>>>>>>>>>>>");
// 关闭结果集、Statement和连接
rs.close();
rs2.close();
//关闭PreparedStatement
ps.close();
st.close();
st02.close();
//关闭连接
connQuery.close();
connQuery02.close();
connInsert.close();
System.out.println("已关闭");
}
}