TestAutoconfigure.java
37.8 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
package com.taover.repository.test;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.taover.repository.jdbctemplate.JdbcTemplateBroadcast;
import com.taover.repository.jdbctemplate.JdbcTemplateWrapperTenant;
@SpringBootApplication
@EnableScheduling
public class TestAutoconfigure {
private static JdbcTemplateBroadcast jdbcTemplateBroadcast;
private static JdbcTemplateWrapperTenant jdbcTemplateWrapperTenant;
private static JdbcTemplate jdbcTemplate;
public static void main(String args[]) {
ConfigurableApplicationContext context = SpringApplication.run(TestAutoconfigure.class, args);
jdbcTemplateBroadcast = context.getBean(JdbcTemplateBroadcast.class);
jdbcTemplateWrapperTenant = context.getBean(JdbcTemplateWrapperTenant.class);
jdbcTemplate = context.getBean(JdbcTemplate.class);
// testBroadCast();
//testSelectSubQuery();
//select子查询包含分片表
//testSelectShardingSubQuery();
//where中包含子查询
//testWhereSubquery();
//testWarePaymentSelectSql();
//testExportPaymentDetailData();
//testTenantWithRootUser();
//testDayOrderInfoExcelData();
//testDayOrderInfoAPI();
//testWeekOrderInfoExcelData();
//testOrderPrintExcelData();
//testRefundCoreSqlForOrderList();
//testSelectSqlForDeliveryExcel();
//testDeliveryExpressNumber();
//testDeliveryGoodsExcel();
//testExcelSelectForSale();
//testChannelPrintSelect();
//testWarePaymentExport();
//testChannelDeliveryOrderQuery();
// testKeyHolder();
// testKeyHolderWithoutId();
// testKeyHolderWithMultiInsert();
//testExpressSql();
testSimpleQuery();
}
private static void testSimpleQuery() {
String sql = "select id from demo limit 1; ";
System.out.println(jdbcTemplate.queryForObject(sql, BigDecimal.class));
}
private static void testExpressSql() {
String basicSql = " SELECT sum(wog.`goods_base_sku_price` * wog.`goods_number`+wog.`ware_shipping_price`) as newWareMoneyPaid "
+ " FROM wxorder_order wo INNER JOIN `wxorder_order_goods` wog on wog.`order_id` = wo.id "
+ " where wo.id = 16"
+ " and wo.tenant_id= 16"
+ " and wog.tenant_id= 16";
System.out.println(jdbcTemplate.queryForObject(basicSql, BigDecimal.class));
}
private static void testKeyHolderWithMultiInsert() {
KeyHolder keyHolder = new GeneratedKeyHolder();
String exeSql = "insert into demo(`name`) values(?),(?),(?),(?),(?),(?);";
jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement stat = con.prepareStatement(exeSql.toString(), new String[] {"id"});
PreparedStatementSetter setter = new ArgumentPreparedStatementSetter(new String[] {"Jack", "Lucy", "Lily", "Mary", "Carlin", "Michael"});
setter.setValues(stat);
return stat;
}
}, keyHolder);
System.out.println(keyHolder.getKey());
}
private static void testKeyHolderWithoutId() {
String sql = "insert into demo(`id`,`name`) values(100,'zhangfei');";
jdbcTemplate.update(
new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement psst = connection.prepareStatement(sql);
return psst;
}
});
}
private static void testKeyHolder() {
KeyHolder keyHolder = new GeneratedKeyHolder();
String sql = "insert into demo(`name`) values(?);";
jdbcTemplate.update(
new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement psst = connection.prepareStatement(sql, new String[] { "id" });
psst.setString(1, "wangbin");
return psst;
}
}
, keyHolder);
System.out.println(keyHolder.getKey().longValue());
}
private static void testChannelDeliveryOrderQuery() {
String sql = "SELECT * FROM ( (SELECT wxorder_order.id FROM wxorder_order wxorder_order "
+ "WHERE wxorder_order.tenant_id = 16 AND wxorder_order.control_status = 3"
+" AND wxorder_order.consignee = '13621051230' AND wxorder_order.channel_id = 20)"
+" UNION ALL "
+ "(SELECT wxorder_order.id FROM wxorder_order wxorder_order WHERE 1 = 1 AND wxorder_order.tenant_id = 16"
+" AND wxorder_order.control_status = 3"
+" AND wxorder_order.mobile = '13621051230' AND wxorder_order.channel_id = 20)"
+ " UNION ALL (SELECT wxorder_order.id FROM wxorder_order wxorder_order WHERE wxorder_order.tenant_id = 16"
+" AND wxorder_order.control_status = 3"
+" AND wxorder_order.express_number = '13621051230' AND wxorder_order.channel_id = 20"
+")) aa LIMIT 1,10";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testWarePaymentExport() {
String sql = "SELECT wc.manager_nickname,cp.id as paymentId, wo.order_sn,wo.`upload_sn`,wo.consignee,wo.mobile,"
+ " wgbs.sku_unit_num as skuUnitNum, wgbs.unit, "
+ " ifnull((SELECT wc.`refund_to_channel` FROM `wxorder_compensate` AS wc WHERE wc.`order_id` = cp.`order_id` LIMIT 1),0) AS refundToChannel, "
+ " ifnull((SELECT wc.`refund_instructions` FROM `wxorder_compensate` AS wc WHERE wc.`order_id` = cp.`order_id` LIMIT 1),'') AS refundRemark, "
+ " (SELECT wpb.`pay_result` from wxorder_ware_payment_batch wpb WHERE wpb.`batch_no`= cp.`pay_batch_no` ORDER BY wpb.`pay_result` asc LIMIT 1) as pay_result,"
+ "CONCAT(wo.province_name,wo.city_name,wo.district_name,wo.address) fullAddress,wo.`progress_delivery`,wo.`real_delivery_time`,"
+ "wo.`express_number`,wc.`name`,wc.wx_group_nickname,wog.`goods_name`,wog.`sku_name`,wog.`sku_code`,"
+ "wog.`goods_base_sku_price`,wog.`goods_number`, wog.`goods_base_sku_price`*wog.`goods_number` as goodsMoney,"
+ "wog.ware_shipping_price as shipping_price,wo.`customer_remark`,wo.`channel_remark`,wo.`control_status`,wog.`ware_refund_money` as refund_money, wog.ware_money_loss as moneyLoss, "
+ "wog.`ware_money_paid` as money_paid,wo.`pay_time`,wo.`create_time`, wo.`latest_distribute_time`, "
+ "cp.`deal_progress`, cp.`check_date`,cp.deal_check_date "
+ " FROM `wxorder_ware_payment` cp "
+ " INNER JOIN `wxorder_order` AS wo ON wo.`id`=cp.order_id "
+ " INNER JOIN `wxorder_order_goods` wog ON wog.`order_id`=wo.id "
+ " INNER JOIN `wxorder_goods_base_sku` wgbs ON wgbs.`id`=wog.goods_sku_id "
+ " INNER JOIN `wxorder_ware` wc ON wc.`id`=wo.`ware_id` "
+ "WHERE cp.id in (30617) "
+ " and cp.tenant_id=16"
+ " and wo.tenant_id=16"
+ " and wog.tenant_id=16";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testChannelPrintSelect() {
String sql = "select wxorder_order.id woId,if(locate('(规格:', wxorder_order_goods.channel_goods_name)>0,left(substring_index( wxorder_order_goods.channel_goods_name, '(规格:', -1), char_length(substring_index( wxorder_order_goods.channel_goods_name, '(规格:', -1)) -1),substring_index( wxorder_order_goods.channel_goods_name, '(规格:', -1)),(SELECT GROUP_CONCAT(wn.`name`) FROM wxorder_tag wt INNER JOIN `wxorder_name_tag` wn ON wn.`id`=wt.`tag_name_id` WHERE wn.`table_name`='wxorder_channel' AND wt.`tenant_id`=wxorder_order.tenant_id AND wt.`table_id`=wxorder_order.`channel_id`) as channelTag "
+ " from wxorder_order inner join wxorder_order_goods on wxorder_order.id=wxorder_order_goods.order_id limit 10 ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testExcelSelectForSale() {
String sql = " SELECT wxorder_order.tenant_id ,"
+ " IFNULL((select GROUP_CONCAT(wxorder_order_express.express_number) from wxorder_order_express AS wxorder_order_express where wxorder_order_express.order_id=wxorder_order.id and wxorder_order_express.tenant_id=16),'') AS express_number, "
+ " wxorder_order.`refund_instructions`, wxorder_order.`refund_money`,wxorder_order.ware_refund_money, wxorder_order.`refund_type`, wxorder_order.`customer_network_name`, "
+ "(SELECT sum(wc.`refund_money`) from `wxorder_compensate` as wc WHERE wc.order_id = wxorder_order.id)as compesateChannelRefundMoney, "
+ "(SELECT sum(wc.`ware_refund_money`) from `wxorder_compensate` as wc WHERE wc.order_id = wxorder_order.id)as compesateWareRefundMoney, "
+ " wxorder_order_wxtext.sender_payload, wxorder_excel_data.payload, "
+ " wxorder_order.order_sn, wxorder_order.upload_sn, wxorder_order.control_status, wxorder_order.progress_delivery, wxorder_order.consignee, "
+ " wxorder_order.mobile,wxorder_order.create_time, wxorder_order.province_name, wxorder_order.city_name, wxorder_order.district_name, wxorder_order.address, "
+ " wxorder_order.money_paid, wxorder_order.shipping_price, "
+ " wxorder_order.sender_name, wxorder_order.sender_mobile, "
+ " wxorder_order.real_delivery_time, wxorder_order.pay_time, wxorder_order.expect_delivery_time, "
+ " IF(wxorder_order_goods.goods_name=wxorder_order_goods.sku_name,group_concat(concat(wxorder_order_goods.goods_name,'*',wxorder_order_goods.goods_number) SEPARATOR '; '),group_concat(concat(wxorder_order_goods.goods_name,'(',wxorder_order_goods.sku_name,')','*',wxorder_order_goods.goods_number) SEPARATOR '; ')) groupGoodsDetail, sum(wxorder_order_goods.goods_number) sumGoodsNumber, "
+ " wxorder_order.express_name, "
+ " group_concat(wxorder_order_goods.goods_code separator '; ') goodsCode,group_concat(wxorder_order_goods.sku_code separator '; ') skuCode, "
+ " group_concat(wxorder_goods_base_sku.sku_unit_num separator '; ') skuUnitNum,"
+ " group_concat(wxorder_goods_base_sku.unit separator '; ') unit,"
+ " wxorder_order.channel_remark, wxorder_order.customer_remark,wxorder_order.buyer_remark, wxorder_order.action_from, "
+ " CONCAT(wxorder_order.province_name,wxorder_order.city_name, wxorder_order.district_name,wxorder_order.address) detailAddress, "
+ " wxorder_channel.name 'channelName', wxorder_channel.contact_user,wxorder_channel.manager_nickname as managerNickname, wxorder_channel.wx_group_nickname 'wxGroupNickname' , "
+ " wxorder_order.operate_refund_time refundTime,wxorder_order_goods.channel_goods_name , "
+ " wxorder_channel.id 'channelId', wxorder_ware.name 'wareName' ,group_concat(wxorder_order_goods.channel_goods_price separator '; ') as channelGoodsPrice ";
sql += " FROM wxorder_order wxorder_order "
+ " INNER JOIN wxorder_order_goods_origin wxorder_order_goods ON wxorder_order_goods.order_id=wxorder_order.id and wxorder_order.tenant_id=16 and wxorder_order_goods.tenant_id=16"
+ " INNER JOIN wxorder_channel wxorder_channel ON wxorder_channel.id=wxorder_order.channel_id "
+ " INNER JOIN wxorder_ware wxorder_ware ON wxorder_ware.id=wxorder_order.ware_id "
+ " INNER JOIN wxorder_goods_base_sku as wxorder_goods_base_sku ON wxorder_goods_base_sku.id=wxorder_order_goods.goods_sku_id "
//修改处4:导出销售单
+ " LEFT JOIN wxorder_order_wxtext wxorder_order_wxtext ON wxorder_order_wxtext.id=wxorder_order.wxtext_order_id"
+ " LEFT JOIN wxorder_excel_data ON wxorder_excel_data.id=wxorder_order.excel_data_id ";
sql += " WHERE wxorder_order.id in (208925) ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testDeliveryGoodsExcel() {
String sql = "SELECT wxorder_order.order_sn,wxorder_order.upload_sn,wxorder_order.control_status,"
+ "wxorder_order.progress_delivery,wxorder_order.consignee,wxorder_order.mobile,"
+ "wxorder_order.province_name,wxorder_order.city_name,wxorder_order.district_name,wxorder_order.address,"
+ "wxorder_order.sender_name,wxorder_order.sender_mobile,wxorder_channel.sender_man,"
+ "wxorder_channel.sender_phone,wxorder_ware.sender_man,wxorder_ware.sender_phone,"
+ "wxorder_order.real_delivery_time,wxorder_order.expect_delivery_time,wxorder_order.create_time,"
+ "wxorder_order.pay_time,wxorder_order.channel_remark,wxorder_order.customer_remark,wxorder_order.buyer_remark,"
+ "wxorder_order.express_name, wxorder_order.latest_distribute_time, "
+ "(select group_concat(wxorder_order_express.express_number) from wxorder_order_express where wxorder_order_express.order_goods_id = wxorder_order_goods.id and wxorder_order_express.tenant_id=16)as express_number,wxorder_order.action_from,"
+ "wxorder_order_goods.goods_name,wxorder_order_goods.sku_name,wxorder_order_goods.goods_number,"
+ "wxorder_order_goods.goods_code goodsCode,wxorder_order_goods.sku_code skuCode,"
+ "wxorder_order_goods.`goods_base_sku_price` AS goodsBasePrice,"
+ "`wxorder_order_goods`.`goods_base_sku_price`*`wxorder_order_goods`.`goods_number` AS basicPrice,"
+ "`wxorder_order_goods`.`refund_money`,`wxorder_order_goods`.`shipping_price`,"
+ "CONCAT(wxorder_order.province_name,wxorder_order.city_name,wxorder_order.district_name,"
+ "wxorder_order.address) detailAddress,wxorder_ware.NAME 'wareName',wxorder_channel.NAME 'channelName',"
+ "wxorder_channel.manager_nickname 'managerNickname',wxorder_channel.wx_group_nickname 'wxGroupNickname',"
+ "wxorder_order.operate_refund_time refundTime,wxorder_channel.id 'channelId',wxorder_order_goods.channel_goods_price as channelGoodsPrice,wxorder_order.customer_network_name as customerNetworkName, "
+ "(SELECT group_concat(distinct(delivery_sn)) from wxorder_order_distribute_log odl where wxorder_order.id=odl.order_id and wxorder_order_goods.id=odl.order_goods_id and odl.tenant_id=16) delivery_sn_list ";
sql += " FROM wxorder_order wxorder_order "
+ " INNER JOIN wxorder_channel wxorder_channel ON wxorder_order.channel_id = wxorder_channel.id and wxorder_order.tenant_id=16"
+ " INNER JOIN wxorder_ware wxorder_ware ON wxorder_order.ware_id= wxorder_ware.id "
+ " INNER JOIN wxorder_order_goods wxorder_order_goods ON wxorder_order.id = wxorder_order_goods.order_id and wxorder_order_goods.tenant_id=16"
+ " INNER JOIN wxorder_goods_base_sku wxorder_goods_base_sku ON wxorder_goods_base_sku.id = wxorder_order_goods.goods_sku_id ";
sql += " WHERE wxorder_order.id in (208925) ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testDeliveryExpressNumber() {
String sql = " SELECT "
+ " wxorder_goods_base_sku.sku_unit_num as skuUnitNum , "
+ " wxorder_goods_base_sku.unit, "
+ " wxorder_order.order_sn, "
+ " wxorder_order.customer_network_name, "
+ " wxorder_order.upload_sn, "
+ " wxorder_order.control_status, "
+ " wxorder_order.progress_delivery, "
+ " wxorder_order.consignee, "
+ " wxorder_order.mobile, "
+ " wxorder_order.province_name, "
+ " wxorder_order.city_name,"
+ " wxorder_order.district_name, "
+ " wxorder_order.address, "
+ " wxorder_order.sender_name, "
+ " wxorder_order.sender_mobile, "
+ " wxorder_channel.sender_man,"
+ " wxorder_channel.sender_phone, "
+ " wxorder_ware.sender_man, "
+ " wxorder_ware.sender_phone, "
+ " wxorder_order.real_delivery_time, "
+ " wxorder_order.expect_delivery_time, "
+ " wxorder_order.create_time, "
+ " wxorder_order.pay_time, "
+ " wxorder_order.channel_remark, "
+ " wxorder_order.customer_remark, "
+ " wxorder_order.buyer_remark, "
+ " wxorder_order.express_name, "
+ " wxorder_order.action_from, "
+ " wxorder_order.latest_distribute_time, "
//+ " IF(wxorder_order_goods.goods_name= wxorder_order_goods.sku_name,(concat(wxorder_order_goods.goods_name, '*', wxorder_order_goods.goods_number)),(concat(wxorder_order_goods.goods_name, '(', wxorder_order_goods.sku_name, ')', '*', wxorder_order_goods.goods_number))) groupGoodsDetail, "
+ " IF(wxorder_order_goods.goods_name= wxorder_order_goods.sku_name,wxorder_order_goods.goods_name,(concat(wxorder_order_goods.goods_name, '(', wxorder_order_goods.sku_name, ')'))) groupGoodsDetail, "
+ " wxorder_order_goods.goods_code goodsCode, "
+ " wxorder_order_goods.sku_code skuCode, "
+ " wxorder_order_goods.goods_number orderGoodsNumber, "
+ " wxorder_order_goods.channel_goods_name,"
+ " CONCAT(wxorder_order.province_name, wxorder_order.city_name, wxorder_order.district_name, wxorder_order.address) detailAddress, "
+ " wxorder_ware.name 'wareName', "
+ " wxorder_channel.name 'channelName', "
+ " wxorder_channel.manager_nickname 'managerNickname', "
+ " wxorder_channel.wx_group_nickname 'wxGroupNickname', "
+ " wxorder_order.operate_refund_time refundTime, "
+ " wxorder_channel.id 'channelId' ,"
+ " wxorder_order_goods.id order_goods_id, "
+ " (SELECT group_concat(distinct(delivery_sn)) from wxorder_order_distribute_log odl where wxorder_order.id=odl.order_id and wxorder_order_goods.id=odl.order_goods_id and odl.tenant_id=16) delivery_sn_list ";
sql += " FROM wxorder_order wxorder_order "
+ " INNER JOIN wxorder_channel wxorder_channel ON wxorder_order.channel_id = wxorder_channel.id and wxorder_order.tenant_id=16"
+ " INNER JOIN wxorder_ware wxorder_ware ON wxorder_order.ware_id= wxorder_ware.id "
+ " INNER JOIN wxorder_order_goods wxorder_order_goods ON wxorder_order.id = wxorder_order_goods.order_id and wxorder_order_goods.tenant_id=16"
+ " INNER JOIN wxorder_goods_base_sku wxorder_goods_base_sku ON wxorder_goods_base_sku.id = wxorder_order_goods.goods_sku_id ";
sql += " WHERE wxorder_order.id in (208925) ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testSelectSqlForDeliveryExcel() {
String sql = " SELECT IFNULL((select GROUP_CONCAT(wxorder_order_express.express_number) from wxorder_order_express AS wxorder_order_express where wxorder_order_express.order_id=wxorder_order.id and wxorder_order_express.tenant_id=16), '') AS express_number,"
+ " wxorder_order.order_sn, wxorder_order.upload_sn, wxorder_order.customer_network_name, "
+ " wxorder_order.control_status, wxorder_order.progress_delivery, "
+ " wxorder_order.consignee, wxorder_order.mobile, wxorder_order.province_name, wxorder_order.city_name, wxorder_order.district_name, wxorder_order.address, "
+ " wxorder_order.sender_name, wxorder_order.sender_mobile, wxorder_channel.sender_man, wxorder_channel.sender_phone, wxorder_ware.sender_man, wxorder_ware.sender_phone, "
+ " wxorder_order.real_delivery_time, wxorder_order.expect_delivery_time, wxorder_order.create_time, wxorder_order.pay_time, "
+ " wxorder_order.channel_remark, wxorder_order.customer_remark,wxorder_order.buyer_remark, "
+ " wxorder_order.express_name, wxorder_order.action_from, wxorder_order.latest_distribute_time,wxorder_order_goods.channel_goods_name , "
+ " IF(wxorder_order_goods.goods_name=wxorder_order_goods.sku_name,group_concat(concat(wxorder_order_goods.goods_name,'*',wxorder_order_goods.goods_number) SEPARATOR '; '),group_concat(concat(wxorder_order_goods.goods_name,'(',wxorder_order_goods.sku_name,')','*',wxorder_order_goods.goods_number) SEPARATOR '; ')) groupGoodsDetail,GROUP_CONCAT(wxorder_order_goods.goods_code SEPARATOR '; ') goodsCode, "
+ " GROUP_CONCAT(wxorder_goods_base_sku.sku_unit_num SEPARATOR '; ') skuUnitNum, "
+ " GROUP_CONCAT(wxorder_goods_base_sku.unit SEPARATOR '; ') unit, "
+ " GROUP_CONCAT(wxorder_order_goods.sku_code SEPARATOR '; ') skuCode, "
+ " (SELECT group_concat(distinct(delivery_sn)) from wxorder_order_distribute_log odl where wxorder_order.id=odl.order_id and odl.tenant_id=16) delivery_sn_list, "
+ " sum(wxorder_order_goods.goods_number) sumGoodsNumber, "
+ " CONCAT(wxorder_order.province_name,wxorder_order.city_name, wxorder_order.district_name,wxorder_order.address) detailAddress, "
+ " wxorder_ware.name 'wareName', wxorder_channel.name 'channelName' ,wxorder_channel.manager_nickname 'managerNickname',wxorder_channel.wx_group_nickname 'wxGroupNickname' ,"
+ " wxorder_order.operate_refund_time refundTime, "
+ " wxorder_channel.id 'channelId' ";
sql += " FROM wxorder_order wxorder_order "
+ " INNER JOIN wxorder_channel wxorder_channel ON wxorder_order.channel_id=wxorder_channel.id and wxorder_order.tenant_id=16"
+ " INNER JOIN wxorder_ware wxorder_ware ON wxorder_order.ware_id=wxorder_ware.id and wxorder_ware.tenant_id=16"
+ " INNER JOIN wxorder_order_goods wxorder_order_goods ON wxorder_order.id=wxorder_order_goods.order_id and wxorder_order_goods.tenant_id=16"
+ " INNER JOIN wxorder_goods_base_sku wxorder_goods_base_sku ON wxorder_goods_base_sku.id=wxorder_order_goods.goods_sku_id ";
sql += " WHERE wxorder_order.id in (208925) and wxorder_order.tenant_id=16";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testRefundCoreSqlForOrderList() {
String selectSql = " SELECT wxorder_order.refund_way refundWay,wxorder_order.refund_delivery_sn refundDeliverySn, "
+ "(SELECT sum(wxorder_compensate.`ware_refund_money`) from `wxorder_compensate` where wxorder_compensate.`order_id` = wxorder_order.id) as wareRefundMoney,"
+ "(SELECT sum(wxorder_compensate.`refund_money`) from `wxorder_compensate` where wxorder_compensate.`order_id` = wxorder_order.id) as refundMoney, "
+ " wxorder_order.operate_refund_time applyCompensateTime,wxorder_order.refund_instructions refundInstructions, wxorder_order.channel_id channelId, wxorder_channel.name channelName, wxorder_channel.platform_code platformCode, "
+ " wxorder_order.pre_control_status as refundPreStatus, wxorder_order.ware_id wareId, wxorder_ware.name wareName, "
+ " wxorder_order.id, wxorder_order.order_sn orderSn, wxorder_order.upload_sn uploadSn, wxorder_order.money_paid moneyPaid, "
+ " wxorder_order.consignee, wxorder_order.mobile, wxorder_order.province_name provinceName, wxorder_order.city_name cityName, wxorder_order.district_name districtName, wxorder_order.address, "
+ " wxorder_order.channel_remark channelRemark, wxorder_order.customer_remark customerRemark, wxorder_order.platform_customer_remark platformCustomerRemark, "
+ " wxorder_order.sender_name senderName, wxorder_order.sender_mobile senderMobile, "
+ " date_format(wxorder_order.create_time, '%Y-%m-%d %H:%i:%s') createTime, date_format(wxorder_order.real_delivery_time, '%Y-%m-%d %H:%i:%s') realDeliveryTime, "
+ " wxorder_order.progress_distribute progressDistribute, wxorder_order.progress_delivery progressDelivery, wxorder_order.control_status controlStatus, "
+ " wxorder_order.express_name expressName, wxorder_order.express_number expressNumber,wxorder_order.shipping_price shippingPrice,"
+ " wxorder_order.customer_network_name ,"
+ "(select count(*) from wxorder_compensate WHERE wxorder_compensate.order_id = wxorder_order.id) as compensateCountAll,"
+ "(select count(*) from wxorder_compensate WHERE wxorder_compensate.order_id = wxorder_order.id and wxorder_compensate.progress_status =2) as compensateCountDealed ,"
+ "(select count(*) from wxorder_channel_refund_payment where wxorder_channel_refund_payment.order_id = wxorder_order.id) as channelRefundPaymentStatus,"
+ "(select count(*) from wxorder_ware_refund_payment where wxorder_ware_refund_payment.order_id = wxorder_order.id) as wareRefundPaymentStatus ";
String whereSql = " WHERE wxorder_order.id=208925 ";
String fromSql = " FROM wxorder_order wxorder_order "
+ " INNER JOIN wxorder_channel wxorder_channel ON wxorder_order.channel_id=wxorder_channel.id and wxorder_channel.tenant_id=16 and wxorder_order.tenant_id=16"
+ " INNER JOIN wxorder_ware wxorder_ware ON wxorder_order.ware_id=wxorder_ware.id and wxorder_ware.tenant_id=16"
+ " INNER JOIN wxorder_order_goods wxorder_order_goods ON wxorder_order.id=wxorder_order_goods.order_id and wxorder_order_goods.tenant_id=16";
String otherSql = " GROUP BY wxorder_order.id ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(selectSql+fromSql+whereSql+otherSql, 16L));
}
private static void testOrderPrintExcelData() {
String subQueryOrderSn = "select group_concat(wo.order_sn) "
+ " from wxorder_order wo inner join wxorder_order_print_list_map woplm on wo.id=woplm.order_id "
+ " where woplm.order_print_list_id=order_print_list.id and wo.tenant_id=16";
String selectSql = " select ("+subQueryOrderSn+") orderSnList, "
+ " order_print_list.consignee, order_print_list.mobile mobile, "
+ " order_print_list.province_name provinceName, order_print_list.city_name cityName, order_print_list.district_name districtName,"
+ " order_print_list.address, order_print_list.channel_remark channelRemark, "
+ " group_concat(wxorder_order_print_list_goods.goods_name, '(', wxorder_order_print_list_goods.sku_name, '*', wxorder_order_print_list_goods.goods_number, ')') groupConcatGoods, "
+ " sum(wxorder_order_print_list_goods.goods_number) sumGoodsNumber, "
+ " order_print_list.print_num printNum, order_print_list.print_task_id printTaskId, order_print_list.print_count printCount, "
+ " order_print_list.status, order_print_list.waybill_code waybillCode, "
+ " order_print_list.express_name expressName, order_print_list.create_time createTime, order_print_list.update_time updateTime, order_print_list.print_latest_time printLatestTime, "
+ " order_print_list.template_url templateUrl, order_print_list.print_area_url printAreaUrl, "
+ " ware.name wareName, channel.name channelName, channel.wx_group_nickname wxGroupNickname, channel.manager_nickname managerNickname ";
String fromSql = " from wxorder_order_print_list order_print_list"
+ " inner join wxorder_ware ware on order_print_list.ware_id=ware.id "
+ " inner join wxorder_channel channel on order_print_list.channel_id=channel.id"
+ " left join wxorder_order_print_list_goods on wxorder_order_print_list_goods.order_print_list_id = order_print_list.id";
String whereSql = " WHERE order_print_list.id in(467) ";
String otherSql = " GROUP BY order_print_list.id ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(selectSql+fromSql+whereSql+otherSql, 16L));
}
private static void testWeekOrderInfoExcelData() {
String sql = " SELECT wo.customer_network_name as customerNetworkName,wo.order_sn AS orderSn,wo.consignee AS consignee,wo.mobile AS mobile, wog.`goods_name` AS goodsName, wog.`sku_name` AS skuName, wog.`goods_number` AS saleNumber, "
+ " concat(wo.province_name,wo.city_name,wo.district_name,wo.address) AS receiveAddress,"
+ " ww.name as wareName, ww.manager_nickname as wareManager, "
+ " ifnull((select GROUP_CONCAT(wxorder_order_express.express_number separator ';') from wxorder_order_express AS wxorder_order_express where wxorder_order_express.order_id=wo.id and wxorder_order_express.tenant_id=16),0) AS expressNumber, "
+ " wc.name as channelName, "
+ " wog.goods_base_sku_price as costSinglePrice, "
+ " wc.manager_nickname as channelManager, "
+ " (wog.money_paid-wog.refund_money ) AS shouldReceiveMoney, "
+ " (wog.refund_money ) AS channelRefund, "
+ " (wog.ware_refund_money ) AS wareRefund, "
+ " ( wog.goods_base_sku_price*wog.goods_number+wog.ware_shipping_price ) AS cost, "
+ " wog.channel_goods_price as channelGoodsPrice, "
+ " wog.money_paid as moneyPaid, "
+ " wo.create_time as orderTime "
+ " FROM `wxorder_order` wo "
+ " INNER JOIN `wxorder_order_goods_origin` wog ON wo.id = wog.`order_id` and wo.tenant_id=16 and wog.tenant_id=16"
+ " INNER JOIN wxorder_channel as wc on wc.id = wo.channel_id "
+ " INNER JOIN wxorder_ware as ww on ww.id=wo.ware_id "
+ " INNER JOIN wxorder_channel_goods as wcg on wcg.id = wog.channel_goods_id "
+ " where wo.id=208925 ORDER BY saleNumber DESC ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testDayOrderInfoAPI() {
String sql = "SELECT wo.customer_network_name as customerNetworkName,wo.order_sn AS orderSn, wog.`goods_name` AS goodsName, wog.`sku_name` AS skuName, wog.`goods_number` AS saleNumber,"
// woe.order_goods_id woe.order_goods_origin_id
+ " ifnull((SELECT sum(woe.`goods_number`) from `wxorder_order_express` as woe WHERE woe.order_goods_id = wog.id and woe.tenant_id=16),0) as deliveryGoodsNumber, "
+ " ww.name as wareName, ww.manager_nickname as wareManager, "
+ " wc.name as channelName, "
+ " wog.goods_base_sku_price as costSinglePrice, "
+ " wc.manager_nickname as channelManager,"
+ " (wog.money_paid-wog.refund_money) AS shouldReceiveMoney, "
+ " wog.refund_money AS channelRefund, "
+ " wog.ware_refund_money AS wareRefund, "
+ " (wog.goods_base_sku_price*wog.goods_number+wog.ware_shipping_price) AS cost, "
+ " wog.channel_goods_price as channelGoodsPrice, "
+ " wog.money_paid as moneyPaid, "
+ " wo.create_time as orderTime "
+ " FROM `wxorder_order` wo "
+ " INNER JOIN `wxorder_order_goods_origin` wog ON wo.id = wog.`order_id` and wo.tenant_id=16 and wog.tenant_id=16"
+ " INNER JOIN wxorder_channel as wc on wc.id = wo.channel_id "
+ " INNER JOIN wxorder_ware as ww on ww.id=wo.ware_id "
+ " INNER JOIN wxorder_channel_goods as wcg on wcg.id = wog.channel_goods_id "
+ " where wo.id=208925 ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testDayOrderInfoExcelData() {
String sql = "SELECT wo.customer_network_name as customerNetworkName,wo.order_sn AS orderSn, wog.`goods_name` AS goodsName, wog.`sku_name` AS skuName, wog.`goods_number` AS saleNumber,"
+ " (SELECT sum(woe.`goods_number`) from `wxorder_order_express` as woe WHERE woe.order_goods_id = wog.id and woe.tenant_id=16)as deliveryGoodsNumber, "
+ " ww.name as wareName, ww.manager_nickname as wareManager, "
+ " wc.name as channelName, "
+ " wog.goods_base_sku_price as costSinglePrice, "
+ " wc.manager_nickname as channelManager,"
+ " (wog.money_paid-wog.refund_money) AS shouldReceiveMoney, "
+ " wog.refund_money AS channelRefund, "
+ " wog.ware_refund_money AS wareRefund, "
+ " (wog.goods_base_sku_price*wog.goods_number+wog.ware_shipping_price) AS cost, "
+ " wog.channel_goods_price as channelGoodsPrice, "
+ " wog.money_paid as moneyPaid, "
+ " wo.create_time as orderTime "
+ " FROM `wxorder_order` wo "
+ " INNER JOIN `wxorder_order_goods` wog ON wo.id = wog.`order_id` and wo.tenant_id=16 and wog.tenant_id=16 "
+ " INNER JOIN wxorder_ware as ww on ww.id = wo.ware_id "
+ " INNER JOIN wxorder_channel as wc on wc.id = wo.channel_id "
+ " INNER JOIN wxorder_channel_goods as wcg on wcg.id = wog.channel_goods_id "
+ " where wo.id=208925 ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testTenantWithRootUser() {
String sql = "select tenant.id, tenant.name 'tenantName', users.id 'userId', users.mobile 'userMobile', users.type 'userType', date(tenant.create_time) 'createTime', "
+ " (select group_concat(agent_nickname) from wxorder_agent_ssy agent_ssy where agent_ssy.tenant_id=tenant.id) 'agentSsyAgentNickname'"
+ ", wv.name as versionName "
+ " from wxorder_tenant tenant "
+ " inner join wxorder_version wv on tenant.version_id=wv.id "
+ " inner join wxorder_user users on tenant.id=users.tenant_id "
+ " where 1=1 ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testExportPaymentDetailData() {
String sql = "SELECT wc.manager_nickname,cp.id as paymentId, wo.order_sn,wo.`upload_sn`,wo.consignee,wo.mobile,"
+ " ifnull((SELECT wc.`refund_to_channel` FROM `wxorder_compensate` AS wc WHERE wc.`order_id` = cp.`order_id` LIMIT 1),0) AS refundToChannel, "
+ " ifnull((SELECT wc.`refund_instructions` FROM `wxorder_compensate` AS wc WHERE wc.`order_id` = cp.`order_id` LIMIT 1),'') AS refundRemark, "
+ " (SELECT wpb.`pay_result` from wxorder_ware_payment_batch wpb WHERE wpb.`batch_no`= cp.`pay_batch_no` ORDER BY wpb.`pay_result` asc LIMIT 1) as pay_result,"
+ "CONCAT(wo.province_name,wo.city_name,wo.district_name,wo.address) fullAddress,wo.`progress_delivery`,wo.`real_delivery_time`,"
+ "wo.`express_number`,wc.`name`,wc.wx_group_nickname,wog.`goods_name`,wog.`sku_name`,wog.`sku_code`,"
+ "wog.`goods_base_sku_price`,wog.`goods_number`, wog.`goods_base_sku_price`*wog.`goods_number` as goodsMoney,"
+ "wog.ware_shipping_price as shipping_price,wo.`customer_remark`,wo.`channel_remark`,wo.`control_status`,wog.`ware_refund_money` as refund_money, wog.ware_money_loss as moneyLoss, "
+ "wog.`ware_money_paid` as money_paid,wo.`pay_time`,wo.`create_time`, wo.`latest_distribute_time`, "
+ "cp.`deal_progress`, cp.`check_date`,cp.deal_check_date "
+ " FROM `wxorder_ware_payment` cp "
+ " INNER JOIN `wxorder_order` AS wo ON wo.`id`=cp.order_id "
+ " INNER JOIN `wxorder_order_goods` wog ON wog.`order_id`=wo.id "
+ " INNER JOIN `wxorder_ware` wc ON wc.`id`=wo.`ware_id` "
+ "WHERE cp.id in (30617) "
+ " and cp.tenant_id=16"
+ " and wo.tenant_id=16"
+ " and wog.tenant_id=16";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testWarePaymentSelectSql() {
String sql = " select wxorder_ware_payment.id as id,wxorder_ware_payment.order_id as orderId,wxorder_ware_payment.deal_progress as dealProgress, "
+ "wxorder_ware_payment.check_date as checkDate,wxorder_ware_payment.deal_check_date as dealCheckDate, "
+ "wxorder_ware_payment.status_sysnotice_check as statusSysnoticeCheck,wxorder_ware_payment.tenant_id as tenantId, "
+ "wxorder_ware_payment.pay_batch_no as payBatchNo,wxorder_order.consignee,wxorder_order.mobile,wxorder_order.province_name as provinceName,"
+ "wxorder_order.city_name as cityName,wxorder_order.district_name as districtName,wxorder_order.address,wxorder_order.create_time as createTime, "
+ "wxorder_ware_payment.update_time as updateTime,wxorder_order.order_sn as orderSn,wxorder_order.ware_money_paid as moneyPaid, "
+ "wxorder_order.ware_refund_money as refundMoney,wxorder_order.ware_shipping_price as shippingPrice, wxorder_order.ware_money_loss as moneyLoss, "
+ "wxorder_order.real_delivery_time as realDeliveryTime,wxorder_order.latest_distribute_time as latestDistributeTime,wxorder_order.progress_delivery as progressDelivery, "
+ "wxorder_order.pay_time as payTime,wxorder_order.control_status as controlStatus,wxorder_order.upload_sn as uploadSn, "
+ "(select name from wxorder_ware where id = wxorder_order.ware_id ) as wareName, "
+ "(SELECT settlement_type from wxorder_ware_payment_cycle WHERE `ware_id`= `wxorder_order`.`ware_id`) as settlementType, "
+ "IF(`wxorder_ware_payment`.`deal_progress`!= 2, 0, (select FLOOR(sum(pay_result)/count(*)) from `wxorder_ware_payment_batch` WHERE wxorder_ware_payment_batch.batch_no= wxorder_ware_payment.`pay_batch_no`)) as payResult ";
sql += " FROM wxorder_ware_payment"
+ " inner join wxorder_order on wxorder_ware_payment.order_id = wxorder_order.id and wxorder_ware_payment.tenant_id=16 and wxorder_order.tenant_id=16 "
+ " limit 5; ";
System.out.println(jdbcTemplateWrapperTenant.queryForList(sql, 16L));
}
private static void testSelectShardingSubQuery() {
String sql = " select wc.name,(select count(*) from wxorder_order where) as 'sumOrderNum' from wxorder_channel wc limit 3; ";
}
public static void testWhereSubquery() {
}
public static void testBroadCast() {
System.out.println(jdbcTemplateBroadcast.queryForObject("select id from wxorder_order order by id desc limit 5 ", String.class, new String[]{"wxorder_order"}));
System.out.println(jdbcTemplateWrapperTenant.queryForObject("select id from wxorder_order limit 1", Long.class, 1L));
System.out.println(jdbcTemplateWrapperTenant.queryForList("select * from wxorder_order limit 1", 1L));
System.out.println(jdbcTemplateWrapperTenant.queryForList("select * from wxorder_order limit 1", 2L));
System.out.println(jdbcTemplateWrapperTenant.queryForList("select * from wxorder_order_express limit 1", 1L));
}
public static void testSelectSubQuery() {
String sql = " SELECT "
+ " wog.`goods_number` AS saleNumber,"
+ " (SELECT sum(woe.`goods_number`) from `wxorder_order_express` as woe WHERE woe.order_goods_id = wog.id and woe.tenant_id=16) as deliveryGoodsNumber, "
+ " (SELECT sum(woe.`goods_number`) from `wxorder_order_express` as woe WHERE woe.order_goods_id = wog.id and woe.tenant_id=16) ee, "
+ " ww.name as wareName,"
+ " ww.manager_nickname as wareManager, "
+ " wc.name as channelName, "
+ " wog.goods_base_sku_price as costSinglePrice, "
+ " wc.manager_nickname as channelManager,"
+ " (wog.money_paid-wog.refund_money) AS shouldReceiveMoney, "
+ " wog.refund_money AS channelRefund, "
+ " wog.ware_refund_money AS wareRefund, "
+ " (wog.goods_base_sku_price*wog.goods_number+wog.ware_shipping_price) AS cost, "
+ " wog.channel_goods_price as channelGoodsPrice, "
+ " wog.money_paid as moneyPaid, "
+ " wo.create_time as orderTime "
//+ " 'aa' "
+ " FROM `wxorder_order` wo "
+ " INNER JOIN `wxorder_order_goods_origin` wog ON wo.id = wog.`order_id` and wo.tenant_id=16 and wog.tenant_id=16 "
+ " INNER JOIN wxorder_channel as wc on wc.id = wo.channel_id "
+ " INNER JOIN wxorder_ware as ww on ww.id=wo.ware_id "
+ " INNER JOIN wxorder_channel_goods as wcg on wcg.id = wog.channel_goods_id"
+ " limit 10 ";
List<Map<String, Object>> data = jdbcTemplateWrapperTenant.queryForList(sql, 16L);
System.out.println(data);
}
}