QuerySql.java
51.4 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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
package com.glsk.compute;
import com.glsk.util.DateUtils;
/**
* @author fangfang
* @create 2024-04-26 16:16
*/
public class QuerySql {
public static void main(String[] args) {
queryMerchantSupervision01( );
// getqueryMerchantDatasql01("1970-01-01", DateUtils.getToday());
}
public static String getqueryMerchantDatasql00(String startdate,String enddate){
String sql00="\n" +
"select distinct merchant_id from dj_smartcarlife.dj_car_life_goods_order dclgo\n" +
"where dclgo.deleted_flag='N'\n" +
"and merchant_name not like '%测试%'\n" +
"and dclgo.status in (2, 4, 6)\n" +
"and dclgo.upgrade_flag in ('Y','N')\n" +
"and dclgo.scene_type=0 \n" +
"and dclgo.business_type in (1,2)\n";
System.out.println("sql00="+sql00);
return sql00;
}
public static String getqueryMerchantDatasql01(String startdate,String enddate){
//20240417之前
String sql01="\n" +
"select\n" +
"ifnull(主服务商id,\"\")主服务商id,ifnull(主服务商名称,\"\")主服务商名称,ifnull(园区店商户号,\"\")园区店商户号,ifnull(园区店商户名称,\"\")园区店商户名称,statdate,\n" +
"ifnull(4s店商户号,\"\")4s店商户号,ifnull(t1.服务门店,\"\")服务门店,\n" +
"ifnull(t1.零售技能,\"\")零售技能,ifnull(t4.业务类型,\"\")业务类型,ifnull(新车交付数,0)新车交付数,ifnull(新车到店流量,'')新车到店流量,ifnull(售后到店流量,'')售后到店流量,\n" +
"ifnull(引流率,'')引流率,round(ifnull(个人产值,0),2)个人产值,ifnull(升级订单数,0)升级订单数,ifnull(升级战败订单总数,0)升级战败订单总数,ifnull(升级客单价,0)升级客单价,\n" +
"round(ifnull(t4.转化率,0),2)转化率,ifnull(t4.渗透率,'')渗透率,业务负责人姓名,服务商负责人姓名,\n" +
"now() created_date\n" +
" from (\n" +
"\t\tselect 主服务商id,主服务商名称,sub_merchant_id 园区店商户号 ,sub_merchant_name 园区店商户名称,\n" +
"\t\t\t\t\tmain_merchant_id 4s店商户号,main_merchant_name 服务门店,\n" +
"\t\t\t\t零售技能\n" +
"\t\t from (\n" +
"\t\tselect main_merchant_id, -- 4s店商户号\n" +
"\t\t\t\t\t main_merchant_name, -- 4s店商户名称\n" +
"\t\t\t\t\t sub_merchant_id, -- 园区店商户号\n" +
"\t\t\t\t\t sub_merchant_name, -- 园区店商户名称\n" +
"\t\t\t\t\t(case when scene=1 then '轻改' when scene=0 then '保险' end)零售技能\n" +
"\t\tfrom dj_car_life_scene_merchant_ref\n" +
"\t\twhere deleted_flag = 'N'\n" +
"\t\tand scene in(0) -- 只看2.1会员权益的\n" +
"\t\tand sub_merchant_type in (6,8)\n" +
"\t\torder by sub_merchant_id\n" +
"\t\t)a inner join\n" +
"\t\t(select merchant_id,partner_merchant_id 主服务商id,partner_merchant_name 主服务商名称 from dj_car_life_yqmerchant_config where deleted_flag = 'N' ) b\n" +
"\t\ton a.sub_merchant_id=b.merchant_id\n" +
"\t\tinner join (\n" +
"\t\t\tselect staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号,merchant_id 所属商户号,merchant_name 所属商户名称\n" +
"\t\t\tfrom dj_business_school.dj_car_life_staff_performance_info where deleted_flag = 'N'\n" +
"\t\t)c on a.sub_merchant_id=c.所属商户号\n" +
"\t\tgroup by 主服务商id,零售技能,4s店商户号\n" +
" \t\t-- having 主服务商id is not null\n" +
")t1\n" +
"inner join (\n" +
"\t\t\tselect merchant_id,merchant_name,statdate,\n" +
"\t\t\tifnull(新车交付数,0)新车交付数,\n" +
"\t\t\tifnull(新车到店流量,'')新车到店流量,\n" +
"\t\t\tifnull(售后到店流量,'')售后到店流量,\n" +
"\t\t\tifnull(round((新车到店流量/新车交付数)*100,2),'') as 引流率,\n" +
"\t\t\tifnull(个人产值,0)个人产值,\n" +
"\t\t\tifnull(升级订单数,0) as 升级订单数,\n" +
"\t\t\tifnull(个人产值/升级订单数,0) as 升级客单价,\n" +
"\t\t\tifnull(升级战败订单总数,0) as 升级战败订单总数,\n" +
"\t\t\tifnull(升级订单数/(ifnull(新车到店流量,0)+ifnull(售后到店流量,0)),ifnull(升级订单数/ifnull(升级战败订单总数,0),0))*100 转化率,\n" +
"\t\t\tifnull(round((升级订单数/ifnull(新车交付数,0))*100,2),'') as 渗透率,\n" +
"\t\t\t零售技能,\n" +
"\t\t\t (case when business_type=1 then '权益' when business_type=2 then '延保' end) 业务类型,\n" +
"会员权益业务负责人姓名 业务负责人姓名,\n" +
"会员权益业务服务商负责人姓名 服务商负责人姓名\n" +
"\t\t\t from\n" +
"\t\t\t(\n" +
"\t\t\t\t\t select\n" +
"\t\t\t\t\t\tmerchant_id \t,\n" +
"\t\t\t\t\t\tmerchant_name\t ,\n" +
"\t\t\t\t\t\tbusiness_type,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')statdate,\n" +
// "\t\t\t\t\t\tsum(total_price) 个人产值,\n" +
"\t\t\t\t\t\tsum((case when dclgo.upgrade_flag='Y' then total_price else null end)) 个人产值,\n" +
"\t\t\t\t\t\tcount(distinct (case when dclgo.upgrade_flag='Y' then dclgo.order_code else null end))升级订单数,\n" +
"\t\t\t\t\t\tcount(distinct dclgo.order_code)升级战败订单总数 ,\n" +
"\t\t\t\t\t\tifnull((t7.新车交付数),0)新车交付数,\n" +
"\t\t\t\t\t\t(case when dclgo.scene_type=1 then t8.到店流量_太阳膜 when dclgo.scene_type=0 then t8.到店流量_会员权益 end ) 新车到店流量,\n" +
"\t\t\t\t\t\t售后到店流量,\n" +
"\t\t\t\t\t\t(case when scene_type=1 then '轻改' when scene_type=0 then '保险' end)零售技能\n" +
"\t\t\t\t\t\tfrom\n" +
"\t\t\t\t\t\t(\n" +
" select ifnull(b.success_date,a.order_time) order_time ,\n" +
" a.id,a.order_code,a.channel_type,a.user_id,a.merchant_id,a.merchant_name,a.sub_shop_merchant_id,a.sub_shop_merchant_name,\n" +
" a.merchant_car_brand_logo,a.employee_name,a.status,a.oper_status,a.upgrade_flag,a.install_upgrade_time,a.total_price,\n" +
" a.seller_user_id,a.seller_merchant_id,a.seller_merchant_name,a.seller_name,a.source,a.remark,a.advance_user_id,a.advance_user_name,\n" +
" a.customer_coupon_id,a.select_pay_type,\ta.order_type,a.construction_flag,a.confirm_construction_date,a.outbound_status,\n" +
" a.outbound_msg,\ta.created_by,a.created_date,a.updated_by,a.updated_date,a.deleted_flag,a.refund_remark,a.associated_order_code,\n" +
" a.failure_flag,a.scene_type,a.business_type,a.deposit_price,a.deposit_payee_type,a.install_merchant_name,a.marketing_merchant_name,\n" +
" a.profit_allocation_status,\ta.wait_profit_allocation_date,\ta.specify_account_rule_id,a.specify_division_rule_id,a.technician_name,\n" +
" a.technician_uuid,\ta.technician_id,\ta.division_operator,\ta.division_operation_date,\ta.film_order\n" +
" from dj_smartcarlife.dj_car_life_goods_order a\n" +
" left join\n" +
" (select * from dj_smartcarlife.dj_car_life_pay_order where deleted_flag = 'N' and order_code is not null) b\n" +
" on a.order_code=b.order_code\n" +
" )dclgo\n" +
"\t\t\t\t\t\tleft join(\n" +
" select merchant_id 4s店商户号, DATE_FORMAT(report_date,'%Y-%m-%d')report_date,sum(delivery_count) 新车交付数 from (\n" +
" SELECT t1.*\n" +
" FROM (\n" +
" select * from dj_car_life_staff_daily_report where deleted_flag = 'N'and\n" +
" DATE_FORMAT(report_date,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(report_date,'%Y-%m-%d')<='"+enddate+"'\n" +
" ) t1\n" +
" INNER JOIN (\n" +
" SELECT merchant_id,report_date, MAX(created_date) AS max_date\n" +
" FROM (\n" +
" select * from dj_car_life_staff_daily_report where deleted_flag = 'N'and\n" +
" DATE_FORMAT(report_date,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(report_date,'%Y-%m-%d')<='"+enddate+"'\n" +
" )t\n" +
" GROUP BY merchant_id,report_date\n" +
" ) t2 ON t1.merchant_id = t2.merchant_id and t1.report_date = t2.report_date AND t1.created_date = t2.max_date\n" +
" )t\n" +
" group by merchant_id, DATE_FORMAT(report_date,'%Y-%m-%d')\n" +
"\t\t\t\t )t7 on dclgo.merchant_id=t7.4s店商户号 and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')=t7.report_date\n" +
"\t\t\t\t\t\tleft join(\n" +
"\t\t\t\t\t\t\t\tselect merchant_id 4s店店商户号,merchant_name 4s店商户名称,DATE_FORMAT(report_date,'%Y-%m-%d')report_date,yq_merchant_id 园区店店商户id,yq_merchant_name 园区店店商户号,\n" +
"\t\t\t\t\t\t\t\tsum(ifnull(film_to_shop_count,0)) 到店流量_太阳膜,sum(ifnull(equity_to_shop_count,0)) 到店流量_会员权益,\n" +
"\t\t\t\t\t\t\t\tsum(ifnull(after_sale_equity_to_shop_count,0))售后到店流量,report_date 日报日期\n" +
"\t\t\t\t\t\t\t\tfrom dj_car_life_staff_daily_report where deleted_flag = 'N'\n" +
"\t\t\t\t\t\t\t\tand DATE_FORMAT(report_date,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(report_date,'%Y-%m-%d')<='"+enddate+"'\n" +
"\t\t\t\t\t\t\t\tgroup by merchant_id,DATE_FORMAT(report_date,'%Y-%m-%d')\n" +
"\t\t\t\t\t\t)t8 on dclgo.merchant_id=t8.4s店店商户号 and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')=t8.report_date\n" +
"\t\t\t\t\t\twhere dclgo.deleted_flag='N'\n" +
"\t\t\t\t\t\tand merchant_name not like '%测试%'\n" +
"\t\t\t\t\t\tand dclgo.status in (2, 4, 6)\n" +
"\t\t\t\t\t\tand dclgo.upgrade_flag in ('Y','N')\n" +
"\t\t\t\t\t\t-- and seller_user_id is not null\n" +
"\t\t\t\t\t\tand dclgo.scene_type=0 -- 2.1会员权益场景\n" +
"\t\t\t\t\t\tand dclgo.business_type in (1,2)\n" +
"\t\t\t\t\t\tand DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')<='"+enddate+"'\n" +
"\t\t\t\t\t\tGROUP BY merchant_id,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d'),business_type\n" +
"\t\t\t)t \n" +
" left join(\n" +
" select merchant_id 门店id,\n" +
" boutique_director_user_id 精品升级业务负责人id,boutique_director_name 精品升级业务负责人姓名,\n" +
" quotation_director_user_id 会员权益业务负责人id,quotation_director_name 会员权益业务负责人姓名\n" +
" from dj_car_life_shop_merchant_config where deleted_flag='N'\n" +
" group by merchant_id\n" +
" )tt on t.merchant_id=tt.门店id\n" +
" left join (\n" +
" select merchant_id 门店id,\n" +
" boutique_service_director_user_id 精品升级业务服务商负责人id,boutique_service_director_name 精品升级业务服务商负责人姓名,\n" +
" quotation_service_director_user_id 会员权益业务服务商负责人id,quotation_service_director_name 会员权益业务服务商负责人姓名\n" +
" from dj_car_life_shop_merchant_config where deleted_flag='N'\n" +
" group by merchant_id\n" +
" )t0 on t.merchant_id=t0.门店id\n" +
"order by merchant_id,statdate\n" +
")t4 on t1.4s店商户号=t4.merchant_id \n"+
"having 4s店商户号!='44205761' \n";
System.out.println("sql01="+sql01);
return sql01;
}
public static String getqueryMerchantDatasql02(String startdate,String enddate,String merchantNo){
String wheremerchantNo=" ";
if(merchantNo!=null){
wheremerchantNo="and merchantNo in "+merchantNo+"\n";
}
//账户中心获取商户的行政区划信息
String sql01="\n" +
"select\n" +
"distinct pm.merchantNo,pm.province_code,pm.province_name,pm.city_code,pm.city_name \n" +
"from platform_merchant pm where del_flag = 0 and province_code is not null and province_code !=\"\"\n" +
""+wheremerchantNo+"" +
"order by province_code,city_code\n\n";
System.out.println("sql01="+sql01);
return sql01;
}
public static String queryMerchantSupervision01(){
String sql01="select distinct data_month,merchant_id, area_supervision as '区域督导',area_supervision_phone as '区域督导电话',now() created_date from \n" +
"\t\t\t (select merchant_id ,data_month,id from dj_car_life_service_merchant_output_value_target where deleted_flag = 'N' )a \n" +
"\t\tLEFT JOIN\n" +
"(\n" +
"\t\t\t\tselect a.* from (\n" +
"\t\t\t\t\tselect output_value_id,user_id area_supervision_id,user_name area_supervision ,user_num area_supervision_phone, created_date from dj_car_life_service_merchant_staff_allocation where latest_flag='Y' and deleted_flag = 'N' and user_type=1 \n" +
"\t\t\t\t)a\n" +
"\t\t\t\tINNER JOIN (\n" +
"\t\t\t\t\tselect output_value_id,max(created_date)max_time from dj_car_life_service_merchant_staff_allocation where latest_flag='Y' and deleted_flag = 'N' and user_type=1 \n" +
"\t\t\t\t\t group by output_value_id\n" +
"\t\t\t\t)b on a.output_value_id=b.output_value_id and a.created_date=b.max_time\n" +
")b\n" +
"\t\ton a.id=b.output_value_id\n" +
"\t\twhere area_supervision is not null\n" +
"\t\tgroup by data_month,merchant_id,area_supervision\n" +
"order by data_month desc \n";
System.out.println("sql01="+sql01);
return sql01;
}
public static String queryMerchantServiceBoss01(){
String sql01="select \n" +
"role_code,role_name,merchantNo,staff_uuid,staff_name,staff_phone ,now() created_date\n" +
"from (\n" +
"SELECT \n" +
"\t\tpm.merchantNo,pm.id,\n" +
"\t\tpm.merchant_name,\n" +
"\t\tpm.merchant_abbreviation,\n" +
"\t\tpm.province_code,pm.province_name,\n" +
"\t\tpm.city_code,pm.city_name,\n" +
"\t\tpm.district_code,pm.district_name,\n" +
"\t\tpms.staff_uuid,pms.staff_name,pms.staff_phone,\n" +
"\t\tpms.visible_inferior_mer 可见下级商户id,pms.visible_merchant_no 园区店可见下级4s店商户,\n" +
"\t\tpmr.role_name,pmr.role_code\n" +
" FROM \n" +
"(\n" +
"\t\tSELECT * FROM platform_merchant_role WHERE role_name = '服务商老板' AND del_flag = 0\n" +
") pmr\n" +
"INNER JOIN platform_merchant_role_staff_relation pmrsr ON pmr.id = pmrsr.role_id\n" +
"AND pmrsr.del_flag = 0\n" +
"INNER JOIN platform_merchant_staff pms ON pmrsr.staff_id = pms.id\n" +
"AND pms.del_flag = 0\n" +
"left join platform_merchant pm\n" +
"on pmr.merchant_id=pm.id and pm.del_flag = 0\n" +
")t \n" +
"group by role_code,role_name,merchantNo,staff_uuid,staff_name\n";
System.out.println("sql01="+sql01);
return sql01;
}
public static String getqueryMerchantStaffFlowDatasql01(String startdate,String enddate){
String sql01="\n" +
"\t\t\t\t\t select\n" +
"\t\t\t\t\t\tmerchant_id \t,\n" +
"\t\t\t\t\t\tmerchant_name\t ,\n" +
"\t\t\t\t\t\tuser_id,employee_name,\n" +
"\t\t\t\t\t\t(case when business_type=1 then '权益' when business_type=2 then '延保' end) 业务类型,\n" +
"\t\t\t\t\t\tDATE_FORMAT(dclgo.order_time,'%Y-%m-%d')statdate,\n" +
"\t\t\t\t\t\tsum(total_price) 个人产值,\n" +
"\t\t\t\t\t\tcount(distinct (case when dclgo.upgrade_flag='Y' then dclgo.order_code else null end))升级订单数,\n" +
"\t\t\t\t\t\tcount(distinct dclgo.order_code)升级战败订单总数,now() created_date\n" +
"\t\t\t\t\t\tfrom\n" +
"\t\t\t\t\t\t(\n" +
"\n" +
" select ifnull(b.success_date,a.order_time) order_time ,\n" +
" a.id,a.order_code,a.channel_type,a.user_id,a.merchant_id,a.merchant_name,a.sub_shop_merchant_id,a.sub_shop_merchant_name,\n" +
" a.merchant_car_brand_logo,a.employee_name,a.status,a.oper_status,a.upgrade_flag,a.install_upgrade_time,a.total_price,\n" +
" a.seller_user_id,a.seller_merchant_id,a.seller_merchant_name,a.seller_name,a.source,a.remark,a.advance_user_id,a.advance_user_name,\n" +
" a.customer_coupon_id,a.select_pay_type,\ta.order_type,a.construction_flag,a.confirm_construction_date,a.outbound_status,\n" +
" a.outbound_msg,\ta.created_by,a.created_date,a.updated_by,a.updated_date,a.deleted_flag,a.refund_remark,a.associated_order_code,\n" +
" a.failure_flag,a.scene_type,a.business_type,a.deposit_price,a.deposit_payee_type,a.install_merchant_name,a.marketing_merchant_name,\n" +
" a.profit_allocation_status,\ta.wait_profit_allocation_date,\ta.specify_account_rule_id,a.specify_division_rule_id,a.technician_name,\n" +
" a.technician_uuid,\ta.technician_id,\ta.division_operator,\ta.division_operation_date,\ta.film_order\n" +
" from dj_smartcarlife.dj_car_life_goods_order a\n" +
" left join\n" +
" (select * from dj_smartcarlife.dj_car_life_pay_order where deleted_flag = 'N' and order_code is not null) b\n" +
" on a.order_code=b.order_code\n" +
" )dclgo\n" +
"\t\t\t\t\t\twhere dclgo.deleted_flag='N'\n" +
"\t\t\t\t\t\tand merchant_name not like '%测试%'\n" +
"\t\t\t\t\t\tand dclgo.status in (2, 4, 6)\n" +
"\t\t\t\t\t\tand dclgo.upgrade_flag in ('Y','N')\n" +
"\t\t\t\t\t\tand user_id is not null\n" +
"\t\t\t\t\t\tand dclgo.scene_type=0 -- 2.1会员权益场景\n" +
"\t\t\t\t\t\tand dclgo.business_type in (1,2)\n" +
"\t\t\t\t\t\tand DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')<='"+enddate+"'\n" +
"\t\t\t\t\t\tGROUP BY merchant_id,user_id,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d'),business_type \n" +
"having merchant_id!='44205761'";
System.out.println("sql01="+sql01);
return sql01;
}
public static String getqueryMerchantStaffFlowDatasql02(String startdate,String enddate){
String sql02="\n" +
"select distinct staff_uuid,staff_name,ifnull(staff_phone,'')staff_phone from platform_merchant_staff where del_flag=0\n";
System.out.println("sql02="+sql02);
return sql02;
}
public static String getqueryStaffDatasql01(String startdate,String enddate){
//订单员工信息
String sql01="\n" +
"select\n" +
"ifnull(主服务商id,\"\")主服务商id,ifnull(主服务商名称,\"\")主服务商名称,ifnull(园区店商户号,\"\")园区店商户号,ifnull(园区店商户名称,\"\")园区店商户名称,statdate,\n" +
"ifnull(4s店商户号,\"\")4s店商户号,ifnull(t1.服务门店,\"\")服务门店,ifnull(t1.员工uuid,\"\")员工uuid,ifnull(员工姓名,\"\")员工姓名,ifnull(员工手机号,\"\")员工手机号,\n" +
"ifnull(t1.零售技能,\"\")零售技能,ifnull(t4.业务类型,\"\")业务类型,ifnull(新车交付数,0)新车交付数,ifnull(新车到店流量,'')新车到店流量,ifnull(售后到店流量,'')售后到店流量,\n" +
"ifnull(引流率,'')引流率,round(ifnull(个人产值,0),2)个人产值,ifnull(升级订单数,0)升级订单数,ifnull(升级战败订单总数,0)升级战败订单总数,ifnull(升级客单价,0)升级客单价,\n" +
"round(ifnull(t4.转化率,0),2)转化率,ifnull(t4.渗透率,'')渗透率,ifnull(填报标记,0)填报标记,\n" +
"now() created_date\n" +
" from (\n" +
"\t\tselect 主服务商id,主服务商名称,sub_merchant_id 园区店商户号 ,sub_merchant_name 园区店商户名称,\n" +
"\t\t\t\t\tmain_merchant_id 4s店商户号,main_merchant_name 服务门店,\n" +
"\t\t\t\t员工uuid,员工姓名,员工手机号,零售技能\n" +
"\t\t from (\n" +
"\t\tselect main_merchant_id, -- 4s店商户号\n" +
"\t\t\t\t\t main_merchant_name, -- 4s店商户名称\n" +
"\t\t\t\t\t sub_merchant_id, -- 园区店商户号\n" +
"\t\t\t\t\t sub_merchant_name, -- 园区店商户名称\n" +
"\t\t\t\t\t(case when scene=1 then '轻改' when scene=0 then '保险' end)零售技能\n" +
"\t\tfrom dj_car_life_scene_merchant_ref\n" +
"\t\twhere deleted_flag = 'N'\n" +
"\t\tand scene in(0) -- 只看2.1会员权益的\n" +
"\t\tand sub_merchant_type in (6,8)\n" +
"\t\torder by sub_merchant_id\n" +
"\t\t)a inner join\n" +
"\t\t(select merchant_id,partner_merchant_id 主服务商id,partner_merchant_name 主服务商名称 from dj_car_life_yqmerchant_config where deleted_flag = 'N' ) b\n" +
"\t\ton a.sub_merchant_id=b.merchant_id\n" +
"\t\tinner join (\n" +
"\t\t\tselect staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号,merchant_id 所属商户号,merchant_name 所属商户名称\n" +
"\t\t\tfrom dj_business_school.dj_car_life_staff_performance_info where deleted_flag = 'N'\n" +
"\t\t)c on a.sub_merchant_id=c.所属商户号\n" +
"\t\tgroup by 主服务商id,零售技能,员工uuid,4s店商户号\n" +
"\t\t-- having 主服务商id is not null\n" +
" \t\torder by 主服务商id, 园区店商户号 ,零售技能,员工uuid\n" +
")t1\n" +
"left join (\n" +
"\t\t\tselect merchant_id,merchant_name,seller_user_id,statdate,\n" +
"\t\t\tifnull(新车交付数,0)新车交付数,\n" +
"\t\t\tifnull(新车到店流量,'')新车到店流量,\n" +
"\t\t\tifnull(售后到店流量,'')售后到店流量,\n" +
"\t\t\tifnull(round((新车到店流量/新车交付数)*100,2),'') as 引流率,\n" +
"\t\t\tifnull(个人产值,0)个人产值,\n" +
"\t\t\tifnull(升级订单数,0) as 升级订单数,\n" +
"\t\t\tifnull(个人产值/升级订单数,0) as 升级客单价,\n" +
"\t\t\tifnull(升级战败订单总数,0) as 升级战败订单总数,\n" +
"\t\t\tifnull(升级订单数/(ifnull(新车到店流量,0)+ifnull(售后到店流量,0)),ifnull(升级订单数/ifnull(升级战败订单总数,0),0))*100 转化率,\n" +
"\t\t\tifnull(round((升级订单数/ifnull(新车交付数,0))*100,2),'') as 渗透率,\n" +
"\t\t\t零售技能,填报标记,\n" +
"\t\t\t (case when business_type=1 then '权益' when business_type=2 then '延保' end) 业务类型\n" +
"\t\t\t from\n" +
"\t\t\t(\n" +
"\t\t\t\t\t select\n" +
"\t\t\t\t\t\tmerchant_id \t,\n" +
"\t\t\t\t\t\tmerchant_name\t ,\n" +
"\t\t\t\t\t\tseller_user_id,business_type,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')statdate,\n" +
// "\t\t\t\t\t\tsum(total_price) 个人产值,\n" +
"\t\t\t\t\t\tsum((case when dclgo.upgrade_flag='Y' then total_price else null end)) 个人产值,\n" +
"\t\t\t\t\t\tcount(distinct (case when dclgo.upgrade_flag='Y' then dclgo.order_code else null end))升级订单数,\n" +
"\t\t\t\t\t\tcount(distinct dclgo.order_code)升级战败订单总数 ,\n" +
"\t\t\t\t\t\tifnull((t7.新车交付数),0)新车交付数,\n" +
"\t\t\t\t\t\t(case when dclgo.scene_type=1 then t8.到店流量_太阳膜 when dclgo.scene_type=0 then t8.到店流量_会员权益 end ) 新车到店流量,\n" +
"\t\t\t\t\t\t售后到店流量,\n" +
"\t\t\t\t\t\t(case when scene_type=1 then '轻改' when scene_type=0 then '保险' end)零售技能,\n" +
"\t\t\t\t\t\tcount(distinct t8.日报日期) 填报标记\n" +
"\t\t\t\t\t\tfrom\n" +
"\t\t\t\t\t\t(\n" +
" select ifnull(b.success_date,a.order_time) order_time ,\n" +
" a.id,a.order_code,a.channel_type,a.user_id,a.merchant_id,a.merchant_name,a.sub_shop_merchant_id,a.sub_shop_merchant_name,\n" +
" a.merchant_car_brand_logo,a.employee_name,a.status,a.oper_status,a.upgrade_flag,a.install_upgrade_time,a.total_price,\n" +
" a.seller_user_id,a.seller_merchant_id,a.seller_merchant_name,a.seller_name,a.source,a.remark,a.advance_user_id,a.advance_user_name,\n" +
" a.customer_coupon_id,a.select_pay_type,\ta.order_type,a.construction_flag,a.confirm_construction_date,a.outbound_status,\n" +
" a.outbound_msg,\ta.created_by,a.created_date,a.updated_by,a.updated_date,a.deleted_flag,a.refund_remark,a.associated_order_code,\n" +
" a.failure_flag,a.scene_type,a.business_type,a.deposit_price,a.deposit_payee_type,a.install_merchant_name,a.marketing_merchant_name,\n" +
" a.profit_allocation_status,\ta.wait_profit_allocation_date,\ta.specify_account_rule_id,a.specify_division_rule_id,a.technician_name,\n" +
" a.technician_uuid,\ta.technician_id,\ta.division_operator,\ta.division_operation_date,\ta.film_order\n" +
" from dj_smartcarlife.dj_car_life_goods_order a\n" +
" left join\n" +
" (select * from dj_smartcarlife.dj_car_life_pay_order where deleted_flag = 'N' and order_code is not null) b\n" +
" on a.order_code=b.order_code\n" +
" )dclgo\n" +
"\t\t\t\t\t\tleft join(\n" +
" select merchant_id 4s店商户号,staff_uuid, DATE_FORMAT(report_date,'%Y-%m-%d')report_date,sum(delivery_count) 新车交付数 from (\n" +
" SELECT t1.*\n" +
" FROM (\n" +
" select * from dj_car_life_staff_daily_report where deleted_flag = 'N'and\n" +
" DATE_FORMAT(report_date,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(report_date,'%Y-%m-%d')<='"+enddate+"'\n" +
" ) t1\n" +
" INNER JOIN (\n" +
" SELECT merchant_id,staff_uuid,report_date, MAX(created_date) AS max_date\n" +
" FROM (\n" +
" select * from dj_car_life_staff_daily_report where deleted_flag = 'N'and\n" +
" DATE_FORMAT(report_date,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(report_date,'%Y-%m-%d')<='"+enddate+"'\n" +
" )t\n" +
" GROUP BY merchant_id,staff_uuid,report_date\n" +
" ) t2 ON t1.merchant_id = t2.merchant_id and t1.report_date = t2.report_date and t1.staff_uuid = t2.staff_uuid AND t1.created_date = t2.max_date\n" +
" )t\n" +
" group by merchant_id,staff_uuid, DATE_FORMAT(report_date,'%Y-%m-%d')\n" +
"\t\t\t\t )t7 on dclgo.merchant_id=t7.4s店商户号 and dclgo.seller_user_id=t7.staff_uuid and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')=t7.report_date\n" +
"\t\t\t\t\t\tleft join(\n" +
"\t\t\t\t\t\t\t\tselect merchant_id 4s店店商户号,merchant_name 4s店商户名称,DATE_FORMAT(report_date,'%Y-%m-%d')report_date,yq_merchant_id 园区店店商户id,yq_merchant_name 园区店店商户号,\n" +
"\t\t\t\t\t\t\t\tsum(ifnull(film_to_shop_count,0)) 到店流量_太阳膜,sum(ifnull(equity_to_shop_count,0)) 到店流量_会员权益,\n" +
"\t\t\t\t\t\t\t\tsum(ifnull(after_sale_equity_to_shop_count,0))售后到店流量,report_date 日报日期,staff_uuid 员工uuid,staff_name 员工姓名\n" +
"\t\t\t\t\t\t\t\tfrom dj_car_life_staff_daily_report where deleted_flag = 'N'\n" +
"\t\t\t\t\t\t\t\tand DATE_FORMAT(report_date,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(report_date,'%Y-%m-%d')<='"+enddate+"'\n" +
"\t\t\t\t\t\t\t\tgroup by merchant_id,staff_uuid,DATE_FORMAT(report_date,'%Y-%m-%d')\n" +
"\t\t\t\t\t\t)t8 on dclgo.merchant_id=t8.4s店店商户号 and dclgo.seller_user_id=t8.员工uuid and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')=t8.report_date\n" +
"\t\t\t\t\t\twhere dclgo.deleted_flag='N'\n" +
"\t\t\t\t\t\tand merchant_name not like '%测试%'-- and dclgo.order_type in (1,2)\n" +
"\t\t\t\t\t\tand dclgo.status in (2, 4, 6)\n" +
"\t\t\t\t\t\tand dclgo.upgrade_flag in ('Y','N')\n" +
"\t\t\t\t\t\tand seller_user_id is not null\n" +
"\t\t\t\t\t\tand dclgo.scene_type=0 -- 2.1会员权益场景\n" +
"\t\t\t\t\t\tand dclgo.business_type in (1,2)\n" +
"\t\t\t\t\t\tand DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')<='"+enddate+"'\n" +
"\t\t\t\t\t\tGROUP BY merchant_id,seller_user_id,零售技能,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d'),business_type\n" +
"\t\t\t)t order by merchant_id,seller_user_id,零售技能,statdate\n" +
")t4 on t1.员工uuid=t4.seller_user_id and t1.4s店商户号=t4.merchant_id and t1.零售技能=t4.零售技能\n" +
"having 4s店商户号!='44205761' \n" +
"order by 员工uuid";
System.out.println("sql01="+sql01);
return sql01;
}
public static String getqueryStaffDatasql01add(String startdate,String enddate){
//补充 dj_car_life_goods_order在dj_business_school.dj_car_life_staff_performance_info中没有的员工的数据
String sql01add="\t\t\tselect merchant_id,merchant_name,seller_user_id,seller_name,statdate,\n" +
"\t\t\tifnull(个人产值,0)个人产值,\n" +
"\t\t\tifnull(升级订单数,0) as 升级订单数,\n" +
"\t\t\tifnull(个人产值/升级订单数,0) as 升级客单价,\n" +
"\t\t\tifnull(升级战败订单总数,0) as 升级战败订单总数,\n" +
"\t\t\t零售技能, \n" +
"\t\t\t (case when business_type=1 then '权益' when business_type=2 then '延保' end) 业务类型\n" +
"\t\t\t from\n" +
"\t\t\t(\n" +
"\t\t\t\t\t select\n" +
"\t\t\t\t\t\tmerchant_id \t,\n" +
"\t\t\t\t\t\tmerchant_name\t ,\n" +
"\t\t\t\t\t\tseller_user_id,seller_name,business_type,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')statdate,\n" +
"\t\t\t\t\t\tsum((case when dclgo.upgrade_flag='Y' then total_price else null end)) 个人产值,\n" +
"\t\t\t\t\t\tcount(distinct (case when dclgo.upgrade_flag='Y' then dclgo.order_code else null end))升级订单数,\n" +
"\t\t\t\t\t\tcount(distinct dclgo.order_code)升级战败订单总数 ,\n" +
"\t\t\t\t\t\t(case when scene_type=1 then '轻改' when scene_type=0 then '保险' end)零售技能\n" +
"\t\t\t\t\t\tfrom\n" +
"\t\t\t\t\t\t(\n" +
" select ifnull(b.success_date,a.order_time) order_time ,\n" +
" a.id,a.order_code,a.channel_type,a.user_id,a.merchant_id,a.merchant_name,a.sub_shop_merchant_id,a.sub_shop_merchant_name,\n" +
" a.merchant_car_brand_logo,a.employee_name,a.status,a.oper_status,a.upgrade_flag,a.install_upgrade_time,a.total_price,\n" +
" a.seller_user_id,a.seller_merchant_id,a.seller_merchant_name,a.seller_name,a.source,a.remark,a.advance_user_id,a.advance_user_name,\n" +
" a.customer_coupon_id,a.select_pay_type,\ta.order_type,a.construction_flag,a.confirm_construction_date,a.outbound_status,\n" +
" a.outbound_msg,\ta.created_by,a.created_date,a.updated_by,a.updated_date,a.deleted_flag,a.refund_remark,a.associated_order_code,\n" +
" a.failure_flag,a.scene_type,a.business_type,a.deposit_price,a.deposit_payee_type,a.install_merchant_name,a.marketing_merchant_name,\n" +
" a.profit_allocation_status,\ta.wait_profit_allocation_date,\ta.specify_account_rule_id,a.specify_division_rule_id,a.technician_name,\n" +
" a.technician_uuid,\ta.technician_id,\ta.division_operator,\ta.division_operation_date,\ta.film_order\n" +
" from dj_smartcarlife.dj_car_life_goods_order a\n" +
" left join\n" +
" (select * from dj_smartcarlife.dj_car_life_pay_order where deleted_flag = 'N' and order_code is not null) b\n" +
" on a.order_code=b.order_code\n" +
" )dclgo\n" +
"\t\t\t\t\t\twhere dclgo.deleted_flag='N'\n" +
"\t\t\t\t\t\tand merchant_name not like '%测试%'-- and dclgo.order_type in (1,2)\n" +
"\t\t\t\t\t\tand dclgo.status in (2, 4, 6)\n" +
"\t\t\t\t\t\tand dclgo.upgrade_flag in ('Y','N')\n" +
"\t\t\t\t\t\tand seller_user_id is not null\n" +
"\t\t\t\t\t\tand dclgo.scene_type=0 -- 2.1会员权益场景\n" +
"\t\t\t\t\t\tand dclgo.business_type in (1,2)\n" +
"\t\t\t\t\t\tand seller_user_id not in (\n" +
"\t\t\t\t\t\t\t\tselect distinct staff_uuid from dj_business_school.dj_car_life_staff_performance_info where deleted_flag = 'N'\n" +
"\t\t\t\t\t\t)\n" +
"\t\t\t\t\t\tand DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')<='"+enddate+"'\n" +
"\t\t\t\t\t\tGROUP BY merchant_id,seller_user_id,零售技能,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d'),business_type\n" +
"\t\t\t)t having merchant_id!='44205761'\n" +
" order by merchant_id,seller_user_id,零售技能,statdate";
System.out.println("sql01add="+sql01add);
return sql01add;
}
public static String getqueryStaffDatasql02(String startdate,String enddate){
//补充驻店员工(seller_user_id,seller_name)为空 但有产值的数据
String sql02="\t\t\tselect merchant_id,merchant_name,seller_user_id,statdate,\n" +
"\t\t\tifnull(个人产值,0)个人产值,\n" +
"\t\t\tifnull(升级订单数,0) as 升级订单数,\n" +
"\t\t\tifnull(个人产值/升级订单数,0) as 升级客单价,\n" +
"\t\t\tifnull(升级战败订单总数,0) as 升级战败订单总数,\n" +
"\t\t\tifnull(升级订单数/ifnull(升级战败订单总数,0),0)*100 转化率,\n" +
"\t\t\t (case when business_type=1 then '权益' when business_type=2 then '延保' end) 业务类型\n" +
"\t\t\t from\n" +
"\t\t\t(\n" +
"\t\t\t\t\t select\n" +
"\t\t\t\t\t\tmerchant_id \t,\n" +
"\t\t\t\t\t\tmerchant_name\t ,\n" +
"\t\t\t\t\t\tseller_user_id,business_type,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')statdate,\n" +
"\t\t\t\t\t\tsum((case when dclgo.upgrade_flag='Y' then total_price else null end)) 个人产值,\n" +
"\t\t\t\t\t\tcount(distinct (case when dclgo.upgrade_flag='Y' then dclgo.order_code else null end))升级订单数,\n" +
"\t\t\t\t\t\tcount(distinct dclgo.order_code)升级战败订单总数 ,\n" +
"\t\t\t\t\t\t(case when scene_type=1 then '轻改' when scene_type=0 then '保险' end)零售技能\n" +
"\t\t\t\t\t\tfrom\n" +
"\t\t\t\t\t\t(\n" +
" select ifnull(b.success_date,a.order_time) order_time ,\n" +
" a.id,a.order_code,a.channel_type,a.user_id,a.merchant_id,a.merchant_name,a.sub_shop_merchant_id,a.sub_shop_merchant_name,\n" +
" a.merchant_car_brand_logo,a.employee_name,a.status,a.oper_status,a.upgrade_flag,a.install_upgrade_time,a.total_price,\n" +
" a.seller_user_id,a.seller_merchant_id,a.seller_merchant_name,a.seller_name,a.source,a.remark,a.advance_user_id,a.advance_user_name,\n" +
" a.customer_coupon_id,a.select_pay_type,\ta.order_type,a.construction_flag,a.confirm_construction_date,a.outbound_status,\n" +
" a.outbound_msg,\ta.created_by,a.created_date,a.updated_by,a.updated_date,a.deleted_flag,a.refund_remark,a.associated_order_code,\n" +
" a.failure_flag,a.scene_type,a.business_type,a.deposit_price,a.deposit_payee_type,a.install_merchant_name,a.marketing_merchant_name,\n" +
" a.profit_allocation_status,\ta.wait_profit_allocation_date,\ta.specify_account_rule_id,a.specify_division_rule_id,a.technician_name,\n" +
" a.technician_uuid,\ta.technician_id,\ta.division_operator,\ta.division_operation_date,\ta.film_order\n" +
" from dj_smartcarlife.dj_car_life_goods_order a\n" +
" left join\n" +
" (select * from dj_smartcarlife.dj_car_life_pay_order where deleted_flag = 'N' and order_code is not null) b\n" +
" on a.order_code=b.order_code\n" +
" )dclgo\n" +
"\t\t\t\t\t\twhere dclgo.deleted_flag='N'\n" +
"\t\t\t\t\t\tand merchant_name not like '%测试%'-- and dclgo.order_type in (1,2)\n" +
"\t\t\t\t\t\tand dclgo.status in (2, 4, 6)\n" +
"\t\t\t\t\t\tand dclgo.upgrade_flag in ('Y','N')\n" +
"\t\t\t\t\t\tand seller_user_id is null\n" +
"\t\t\t\t\t\tand dclgo.scene_type=0 -- 2.1会员权益场景\n" +
"\t\t\t\t\t\tand dclgo.business_type in (1,2)\n" +
"\t\t\t\t\t\tand DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')>='"+startdate+"'and DATE_FORMAT(dclgo.order_time,'%Y-%m-%d')<='"+enddate+"'\n" +
"\t\t\t\t\t\tGROUP BY merchant_id,seller_user_id,零售技能,DATE_FORMAT(dclgo.order_time,'%Y-%m-%d'),business_type\n" +
"\t\t\t)t having merchant_id!='44205761'";
System.out.println("sql02="+sql02);
return sql02;
}
public static String getqueryStaffDatasql03(String startdate,String enddate){
String sql03="select t1.*,\n" +
" datediff(t1.考核结束时间,t1.考核开始时间)+1 总天数,\n" +
" count(distinct (case when t2.report_date >= date_format(t1.考核开始时间, '%Y-%m-%d') and t2.report_date <= date_format(t1.考核结束时间, '%Y-%m-%d') then report_date else null end)) 报表完成天数\n" +
"from (\n" +
" select\n" +
" mtc.merchant_id,stc.staff_uuid,stc.check_status,\n" +
" (case when stc.check_month=1 then '首月' when stc.check_month=2 then '次月'when stc.check_month=3 then '第3月' end) 考核月度,\n" +
" (case when stc.check_period=1 then '上半月' when stc.check_period=2 then '下半月'end) 考核周期\n" +
" ,stc.check_start_time as 考核开始时间,stc.check_end_time as 考核结束时间,\n" +
" max(IFNULL(mttcp.conversion_rate,mttc.conversion_rate))conversion_rate,\n" +
" max(IFNULL(mttcp.customer_unit_price,mttc.customer_unit_price))customer_unit_price\n" +
" from dj_car_life_staff_target_check stc\n" +
" left join dj_car_life_merchant_target_config mtc on mtc.id=stc.target_id\n" +
" left join dj_car_life_merchant_target_period_config mtpc on mtpc.target_id=stc.target_id\n" +
" and mtpc.check_month=stc.check_month and mtpc.check_period=stc.check_period\n" +
" left join dj_car_life_merchant_target_task_config mttc on mttc.target_period_id=mtpc.id\n" +
" left join dj_car_life_merchant_target_task_config_package mttcp on mttcp.target_task_id=mttc.id and mttcp.deleted_flag='N'\n" +
" where stc.deleted_flag='N' and stc.check_status=1\n" +
" and mtc.deleted_flag='N' and mtc.scene_type = 0 and mtc.config_status='Y' -- and mtc.merchant_id=\n" +
" and mtpc.deleted_flag='N'\n" +
" and mttc.deleted_flag='N'\n" +
" GROUP BY mtc.merchant_id,stc.staff_uuid\n" +
" ORDER BY mtc.merchant_id,stc.staff_uuid\n" +
" )t1\n" +
"left join (\n" +
" select distinct merchant_id, staff_uuid,report_date\n" +
" from dj_car_life_staff_daily_report\n" +
")t2 on t1.merchant_id=t2.merchant_id and t1.staff_uuid=t2.staff_uuid\n" +
"group by t1.merchant_id,t1.staff_uuid\n" +
" having merchant_id!='44205761'\n" +
"order by t1.merchant_id,t1.staff_uuid";
System.out.println("sql03="+sql03);
return sql03;
}
public static String getqueryToStoreDatasql01(String startdate,String enddate){
//待上线
String sql01="\n" +
"select t1.merchant_id,t1.staff_uuid,t1.report_date,ifnull(t2.新车交付数,0)新车交付数,\n" +
"到店流量_会员权益 新车到店流量,\n" +
"售后到店流量,now() created_date\n" +
"from (select distinct merchant_id ,staff_uuid,scene_type,report_date from dj_car_life_staff_daily_report where scene_type=0 )t1\n" +
"left join (\n" +
"\n" +
" select merchant_id 4s店商户号,staff_uuid,scene_type, DATE_FORMAT(report_date,'%Y-%m-%d')report_date,sum(delivery_count) 新车交付数 from (\n" +
" SELECT t1.*\n" +
" FROM (\n" +
" select * from dj_car_life_staff_daily_report where deleted_flag = 'N'\n" +
" ) t1\n" +
" INNER JOIN (\n" +
" SELECT merchant_id,staff_uuid,scene_type,report_date, MAX(created_date) AS max_date\n" +
" FROM (\n" +
" select * from dj_car_life_staff_daily_report where deleted_flag = 'N'\n" +
" )t\n" +
" GROUP BY merchant_id,staff_uuid,scene_type,report_date\n" +
" ) t2 ON t1.merchant_id = t2.merchant_id and t1.report_date = t2.report_date and t1.staff_uuid = t2.staff_uuid and t1.scene_type = t2.scene_type AND t1.created_date = t2.max_date\n" +
" )t\n" +
" group by merchant_id,staff_uuid,scene_type, DATE_FORMAT(report_date,'%Y-%m-%d')\n" +
")t2 on t1.report_date=t2.report_date and t1.merchant_id=t2.4s店商户号 and t1.staff_uuid=t2.staff_uuid and t1.scene_type=t2.scene_type \n" +
"left join (\n" +
"\t\t\t\t\t\t\t\tselect merchant_id 4s店商户号,scene_type,merchant_name 4s店商户名称,DATE_FORMAT(report_date,'%Y-%m-%d')report_date,yq_merchant_id 园区店店商户id,yq_merchant_name 园区店店商户号,\n" +
"\t\t\t\t\t\t\t\tsum(ifnull(film_to_shop_count,0)) 到店流量_太阳膜,sum(ifnull(equity_to_shop_count,0)) 到店流量_会员权益,\n" +
"\t\t\t\t\t\t\t\tsum(ifnull(after_sale_equity_to_shop_count,0))售后到店流量,report_date 日报日期,staff_uuid 员工uuid,staff_name 员工姓名\n" +
"\t\t\t\t\t\t\t\tfrom dj_car_life_staff_daily_report where deleted_flag = 'N'\n" +
"\t\t\t\t\t\t\t\tgroup by merchant_id,staff_uuid,scene_type,DATE_FORMAT(report_date,'%Y-%m-%d')\n" +
")t3 on t1.report_date=t3.report_date and t1.merchant_id=t3.4s店商户号 and t1.staff_uuid=t3.员工uuid and t1.scene_type=t3.scene_type \n"+
"having merchant_id!='44205761' \n";
System.out.println("sql01="+sql01);
return sql01;
}
public static String getqueryToStoreDatasql02(String startdate,String enddate){
String sql02="select \n" +
"\tt1.merchant_id,t1.report_date,ifnull(t2.新车交付数,0)新车交付数,now() created_date,t1.scene_type\n" +
"from (select distinct merchant_id,scene_type ,report_date from dj_car_life_staff_daily_report where scene_type=0 \n" +
")t1\n" +
"left join (\n" +
"\n" +
" select merchant_id 4s店商户号,scene_type, DATE_FORMAT(report_date,'%Y-%m-%d')report_date,sum(delivery_count) 新车交付数 from (\n" +
" SELECT t1.*\n" +
" FROM (\n" +
" select t.* from dj_car_life_staff_daily_report t where deleted_flag = 'N'\n" +
" ) t1\n" +
" INNER JOIN (\n" +
" SELECT merchant_id,scene_type,report_date, MAX(created_date) AS max_date\n" +
" FROM (\n" +
" select * from dj_car_life_staff_daily_report where deleted_flag = 'N'\n" +
" )t\n" +
" GROUP BY merchant_id,scene_type,report_date\n" +
" ) t2 ON t1.merchant_id = t2.merchant_id and t1.report_date = t2.report_date and t1.scene_type = t2.scene_type AND t1.created_date = t2.max_date\n" +
" )t\n" +
" group by merchant_id,scene_type, DATE_FORMAT(report_date,'%Y-%m-%d')\n" +
")t2 on t1.report_date=t2.report_date and t1.merchant_id=t2.4s店商户号 and t1.scene_type=t2.scene_type \n" +
"having merchant_id!='44205761' ";
System.out.println("sql02="+sql02);
return sql02;
}
}