cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
package cn.ksource.web.facade.tj;
 
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.dao.SqlParameter;
import cn.ksource.core.util.*;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class SatisfactionStatisFacadeImpl implements SatisfactionStatisFacade{
    @Resource
    private BaseDao baseDao;
    
    @Override
    public Map satisfactionDetailChart(HttpServletRequest request) {
        //获取查询参数
        Map param = new HashMap();
        String cusId = request.getParameter("cusId");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String busType = request.getParameter("busType");
        
        
        //查询参数初始化
        param.put("cusId", cusId);
        param.put("cusId", cusId);
        param.put("beginTime", beginTime);
        param.put("endTime", endTime);
        param.put("busType", busType);
        
        //查询最新模板id
        StringBuilder sql = new StringBuilder();
        sql.append(" select id from CUSTOMER_SATIS_TEMPLATE where state=1 and template_type = :busType  ");
        String templateId = baseDao.queryForString(sql.toString(),param);
        param.put("templateId", templateId);
 
        //组织表头
        sql.setLength(0);
        sql.append(" select id,item_name text,FATHER_ID parentId,ORDERNUM sortId from CUSTOMER_SATIS_TEMPLATE_ITEM  ");
        sql.append(" where TEMPLATE_ID = :templateId  ");
        sql.append(" union ");
        sql.append(" select id,text,parentId,sortId from (   ");
        sql.append(" select i1.id,i1.ITEM_ID parentId,i1.ORDERNUM sortId,i1.EVA_NAME text from satis_eva_item i1   ");
        sql.append(" inner join CUSTOMER_SATIS_TEMPLATE_ITEM i2  on i1.ITEM_ID = i2.ID ");
        sql.append(" where i2.TEMPLATE_ID = :templateId ) t ");
        //将查询结果配装为树
        TreeUtil treeUtil = new TreeUtil();
        Map root = treeUtil.createTree(baseDao.queryForList(sql.toString(),param));
        
        //查询每个日期下对应的各三级满意度调查项的满意度数量
        sql.setLength(0);
        //三级满意度调查项与时间外连接
        sql.append("    select t.$COLUMN,GROUP_CONCAT(IFNULL(i.num,'-') order by ordernum1,ordernum2,ordernum3) total_num from ( ");
        sql.append("        select t2.$COLUMN,t1.resultid,ordernum1,ordernum2,ordernum3 from ");
        sql.append("        ( ");
        sql.append("            select v3.id resultid,v1.ORDERNUM ordernum1,v2.ORDERNUM ordernum2,v3.ordernum ordernum3 from ");
        sql.append("            ( ");
        sql.append("                select ID,ITEM_NAME,FATHER_ID,ORDERNUM from CUSTOMER_SATIS_TEMPLATE_ITEM  ");
        sql.append("                where state=1 and item_level =1 and TEMPLATE_ID = :templateId ");
        sql.append("            ) v1 ");
        sql.append("            inner join ");
        sql.append("            (  ");
        sql.append("                select ID,ITEM_NAME,FATHER_ID,ORDERNUM from CUSTOMER_SATIS_TEMPLATE_ITEM  ");
        sql.append("                where state=1 and item_level =2 and TEMPLATE_ID = :templateId ");
        sql.append("            ) v2 ");
        sql.append("            on v1.ID = v2.FATHER_ID ");
        sql.append("            inner join  ");
        sql.append("            ( ");
        sql.append("                select id,item_id,eva_name,ordernum from  satis_eva_item "); 
        sql.append("            ) v3  ");
        sql.append("            on v2.id = v3.item_id  ");
        sql.append("        ) t1 , ");
        sql.append("        ( ");
        sql.append("            select $COLUMN from SATIS_INFO_DETAIL d inner join $TABLE i  ");
        sql.append("            on d.BUSINESS_ID = i.ID ");
        sql.append("             where i.$COLUMN >=:beginTime and i.$COLUMN <=:endTime  ");
        sql.append("               and i.TEMPLATE_ID =:templateId ");
        if(StringUtil.notEmpty(cusId)){
            sql.append(" and i.customer_id = :cusId ");
        }
        if(StringUtil.notEmpty(cusId) ) {
            sql.append(" AND i.CUSTOMER_ID = :cusId ");
        }
        sql.append("            group by $COLUMN ");
        sql.append("        ) t2 ");
        sql.append("    ) t  ");
        //将满意度调查项根据调查时间,三级调查项目分组
        sql.append("    left join ");
        sql.append("    ( ");
        sql.append("        select count(i.id) num,d.RESULTID,i.$COLUMN from SATIS_INFO_DETAIL d inner join $TABLE i "); 
        sql.append("        on d.BUSINESS_ID = i.ID  ");
        sql.append("         where i.$COLUMN >=:beginTime and i.$COLUMN <=:endTime  ");
        sql.append("         and i.customer_id = :cusId  and i.TEMPLATE_ID =:templateId ");
        if(StringUtil.notEmpty(cusId) ) {
            sql.append(" AND i.CUSTOMER_ID = :cusId  ");
        }
        sql.append("        group by i.$COLUMN,d.RESULTID ");
        sql.append("    ) i on t.resultid = i.RESULTID and t.$COLUMN = i.$COLUMN ");
        sql.append("    group by $COLUMN ");
        
        Map resMap = new HashMap();
        String finalSql = sql.toString();
        if(busType.equals("1")||busType.equals("2")){
            finalSql = finalSql.replace("$COLUMN","INVEST_TIME");
            finalSql = finalSql.replace("$TABLE","ORDER_SATIS_INFO");
        }else if(busType.equals("3")||busType.equals("4")){
            finalSql = finalSql.replace("$COLUMN","CARD_MONTH");
            finalSql = finalSql.replace("$TABLE","AUDITING_SATIS_INFO");
        }
        List<Map> resList = baseDao.queryForList(finalSql,param);
        resMap.put("resList", resList);
        resMap.put("root", root);
        return resMap;
    }
 
    @Override
    public Map satisfactionBigItemChart(HttpServletRequest request) {
        //获取查询参数
        Map param = new HashMap();
        String cusId = request.getParameter("cusId");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String showType = request.getParameter("showType");
        String busType = request.getParameter("busType");
        //查询参数初始化
        param.put("cusId", cusId);
        param.put("beginTime", beginTime);
        param.put("endTime", endTime);
        param.put("busType", busType);
        //查询最新模板id
        StringBuilder sql = new StringBuilder();
        sql.append(" select id from CUSTOMER_SATIS_TEMPLATE where state=1 and template_type = :busType  ");
        String templateId = baseDao.queryForString(sql.toString(),param);
        param.put("templateId", templateId);
 
        //获取LegendList
        sql.setLength(0);
        sql.append(" select id,item_name name from CUSTOMER_SATIS_TEMPLATE_ITEM ");
        sql.append(" where item_level = 1 and TEMPLATE_ID = :templateId ");
        sql.append(" order by ORDERNUM ");
        List<Map> legendList = baseDao.queryForList(sql.toString(),param);
        //获取xAxis
        List<String> categories = new ArrayList<String>();
        //查询数据
        sql.setLength(0);
        sql.append(" select CONCAT(id1,'_',$COLUMN) mname,SUM(score) score from ");
        sql.append(" ( ");
        sql.append("     select i.$COLUMN,t.id1,t.id2,truncate((t.weight*AVG(d.RESULTSCORE))/1000,1) score from  ");
        sql.append("     SATIS_INFO_DETAIL d  ");
        sql.append("     inner join $TABLE i  ");
        sql.append("     on d.BUSINESS_ID = i.ID ");
        sql.append("     inner join  ");
        sql.append("     ( ");
        sql.append("         select lv1.id id1,lv1.ITEM_NAME name1,lv2.id id2,lv2.ITEM_NAME name2,weight from  ");
        sql.append("         ( ");
        sql.append("         select id,ITEM_NAME,FATHER_ID,TEMPLATE_WEIGHT weight from CUSTOMER_SATIS_TEMPLATE_ITEM where item_level = 2 ");
        sql.append("         ) lv2 ");
        sql.append("         inner join  ");
        sql.append("         ( ");
        sql.append("         select id,ITEM_NAME from CUSTOMER_SATIS_TEMPLATE_ITEM where item_level = 1 ");
        sql.append("        ) lv1  ");
        sql.append("         on lv2.FATHER_ID = lv1.id ");
        sql.append("     ) t  ");
        sql.append("     on t.id2 = d.CONFIGID ");
        sql.append("     where i.$COLUMN >=:beginTime and i.$COLUMN <=:endTime  ");
        sql.append("      and i.TEMPLATE_ID =:templateId  ");
        if(StringUtil.notEmpty(cusId)){
            sql.append(" and i.customer_id = :cusId  ");
        }
        if(StringUtil.notEmpty(cusId) ) {
            sql.append(" AND i.CUSTOMER_ID = :cusId  ");
        }
        sql.append("     group by i.$COLUMN,t.id1,t.id2 ");
        sql.append(" )t group by id1,$COLUMN ");
        
        String finalSql = sql.toString();
        if(busType.equals("1")||busType.equals("2")){
            categories = DateUtil.getBetweenTwoDateList(beginTime, endTime, 2, "yyyyMMdd");
            finalSql = finalSql.replace("$COLUMN","INVEST_TIME");
            finalSql = finalSql.replace("$TABLE","ORDER_SATIS_INFO");
        }else if(busType.equals("3")||busType.equals("4")){
            categories = DateUtil.getBetweenTwoDateList(beginTime, endTime, 1, "yyyyMM");
            finalSql = finalSql.replace("$COLUMN","CARD_MONTH");
            finalSql = finalSql.replace("$TABLE","AUDITING_SATIS_INFO");
        }
        List<Map> queryList = baseDao.queryForList(finalSql,param);
        //hightchart series
        List<Map> series = new ArrayList<Map>();
        List<List> tableData = new ArrayList<List>();
        
        Map queryMap = new HashMap();
        if(queryList!=null&&queryList.size()>0){
            for(Map map:queryList){
                queryMap.put(map.get("mname").toString(), map.get("score"));
            }
        }
        
        if(showType.equals("chart")){
            //组装 hightchart series
            for(Map legendMap:legendList){
                Map tempMap = new HashMap();
                tempMap.put("name", legendMap.get("name").toString());
                List tempList = new ArrayList();
                for(String category:categories){
                    String name = legendMap.get("id").toString()+"_"+category.replace("-", "");
                    if(queryMap.get(name)!=null){
                        double score=ConvertUtil.obj2Double(queryMap.get(name))*10;
                        tempList.add(score);
                    }else{
                        tempList.add(0);
                    }
                }
                tempMap.put("data", tempList);
                series.add(tempMap);
            }
        }
        //table数据组装
        if(showType.equals("table")){
            for(String category:categories ){
                Map tempMap = new HashMap();
                List tempList = new ArrayList<String>();
                tempList.add(category);
                for(Map legendMap:legendList){
                    String name = legendMap.get("id").toString()+"_"+category.replace("-", "");
                    if(queryMap.get(name)!=null){
                        double score=ConvertUtil.obj2Double(queryMap.get(name))*10;
                        tempList.add(score);
                    }else{
                        tempList.add("-");
                    }
                }
                tableData.add(tempList);
            }
        }
        //System.out.println("table------------------"+JsonUtil.list2Json(tableData));
        //返回结果
        Map resMap = new HashMap();
        resMap.put("categories", categories);
        resMap.put("series", series);
        resMap.put("step", Math.round(categories.size()/9));
        
        resMap.put("tableData", tableData);
        resMap.put("tableLabel", legendList);
        
        return resMap;
    }
    
    
    @Override
    public Map satisfactionSmallItemChart(HttpServletRequest request) {
        //获取查询参数
        Map param = new HashMap();
        String cusId = request.getParameter("cusId");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String showType = request.getParameter("showType");
        String busType = request.getParameter("busType");
        //查询参数初始化
        param.put("cusId", cusId);
        param.put("beginTime", beginTime);
        param.put("endTime", endTime);
        param.put("busType", busType);
        //查询最新模板id
        StringBuilder sql = new StringBuilder();
        sql.append(" select id from CUSTOMER_SATIS_TEMPLATE where state=1 and template_type = :busType  ");
        String templateId = baseDao.queryForString(sql.toString(),param);
        param.put("templateId", templateId);
                
        //获取LegendList
        sql.setLength(0);
        sql.append(" select v2.id id,v2.name name from  ");
        sql.append(" ( ");
        sql.append(" select id,ORDERNUM from CUSTOMER_SATIS_TEMPLATE_ITEM   ");
        sql.append(" where item_level = 1 and TEMPLATE_ID = :templateId    ");
        sql.append(" ) v1   ");
        sql.append(" inner join   ");
        sql.append(" (   ");
        sql.append(" select id,item_name name,FATHER_ID pid,ORDERNUM from CUSTOMER_SATIS_TEMPLATE_ITEM    ");
        sql.append(" where item_level = 2 and TEMPLATE_ID = :templateId     ");
        sql.append(" ) v2     ");
        sql.append(" on v1.id = v2.pid    ");
        sql.append(" order by  v1.ORDERNUM,v2.ORDERNUM    ");
        List<Map> legendList = baseDao.queryForList(sql.toString(),param);
        //获取xAxis
        List<String> categories = new ArrayList<String>();
        
        //查询数据
        sql.setLength(0);
        sql.append(" select CONCAT(t.id2,'_',i.$COLUMN) mname, truncate(AVG(d.RESULTSCORE)/10,1) score from   ");
        sql.append(" SATIS_INFO_DETAIL d   ");
        sql.append(" inner join $TABLE i  ");
        sql.append(" on d.BUSINESS_ID = i.ID ");
        sql.append(" inner join  ");
        sql.append(" ( ");
        sql.append("     select lv1.id id1,lv1.ITEM_NAME name1,lv2.id id2,lv2.ITEM_NAME name2,weight from  ");
        sql.append("     ( ");
        sql.append("     select id,ITEM_NAME,FATHER_ID,TEMPLATE_WEIGHT weight from CUSTOMER_SATIS_TEMPLATE_ITEM where item_level = 2 and TEMPLATE_ID = :templateId ");
        sql.append("     ) lv2 ");
        sql.append("     inner join  ");
        sql.append("     ( ");
        sql.append("     select id,ITEM_NAME from CUSTOMER_SATIS_TEMPLATE_ITEM where item_level = 1 and TEMPLATE_ID = :templateId ");
        sql.append("    ) lv1  ");
        sql.append("     on lv2.FATHER_ID = lv1.id ");
        sql.append(" ) t  ");
        sql.append(" on t.id2 = d.CONFIGID ");
        sql.append("     where i.$COLUMN >=:beginTime and i.$COLUMN <=:endTime  ");
        sql.append("       and i.TEMPLATE_ID =:templateId  ");
        if(StringUtil.notEmpty(cusId)){
            sql.append(" and i.customer_id = :cusId ");
        }
        if(StringUtil.notEmpty(cusId)) {
            sql.append(" AND i.CUSTOMER_ID = :cusId  ");
        }
        sql.append(" group by i.$COLUMN,t.id1,t.id2 ");
        
        
        String finalSql = sql.toString();
        if(busType.equals("1")||busType.equals("2")){
            categories = DateUtil.getBetweenTwoDateList(beginTime, endTime, 2, "yyyyMMdd");
            finalSql = finalSql.replace("$COLUMN","INVEST_TIME");
            finalSql = finalSql.replace("$TABLE","ORDER_SATIS_INFO");
        }else if(busType.equals("3")||busType.equals("4")){
            categories = DateUtil.getBetweenTwoDateList(beginTime, endTime, 1, "yyyyMM");
            finalSql = finalSql.replace("$COLUMN","CARD_MONTH");
            finalSql = finalSql.replace("$TABLE","AUDITING_SATIS_INFO");
        }
        List<Map> queryList = baseDao.queryForList(finalSql,param);
        //hightchart series
        List<Map> series = new ArrayList<Map>();
        List<List> tableData = new ArrayList<List>();
        Map queryMap = new HashMap();
        if(queryList!=null&&queryList.size()>0){
            for(Map map:queryList){
                queryMap.put(map.get("mname").toString(), map.get("score"));
            }
        }
        //组装 hightchart series
        if(showType.equals("chart")){
            
            for(Map legendMap:legendList){
                Map tempMap = new HashMap();
                tempMap.put("name", legendMap.get("name").toString());
                List tempList = new ArrayList();
                for(String category:categories){
                    String name = legendMap.get("id").toString()+"_"+category.replace("-", "");
                    if(queryMap.get(name)!=null){
                        double score=ConvertUtil.obj2Double(queryMap.get(name))*10;
                        tempList.add(score);
                    }else{
                        tempList.add(0);
                    }
                }
                tempMap.put("data", tempList);
                series.add(tempMap);
            }
        }
        //组装talbe数据
        if(showType.equals("table")){
            for(String category:categories ){
                Map tempMap = new HashMap();
                List tempList = new ArrayList<String>();
                tempList.add(category);
                for(Map legendMap:legendList){
                    String name = legendMap.get("id").toString()+"_"+category.replace("-", "");
                    if(queryMap.get(name)!=null){
                        double score=ConvertUtil.obj2Double(queryMap.get(name))*10;
                        tempList.add(score);
                    }else{
                        tempList.add("-");
                    }
                }
                tableData.add(tempList);
            }
        }
        System.out.println("tableData--------------------"+JsonUtil.list2Json(tableData));
        sql.setLength(0);
        sql.append(" select id,item_name text,FATHER_ID parentId,ORDERNUM sortId from CUSTOMER_SATIS_TEMPLATE_ITEM  ");
        sql.append(" where TEMPLATE_ID = :templateId  and (ITEM_LEVEL =1 or ITEM_LEVEL =2) ");
        TreeUtil treeUtil = new TreeUtil();
        Map root = treeUtil.createTree(baseDao.queryForList(sql.toString(),param));
        
        //返回结果
        Map resMap = new HashMap();
        
        resMap.put("categories", categories);
        resMap.put("series", series);
        resMap.put("step", Math.round(categories.size()/9));
        resMap.put("tableData", tableData);
        resMap.put("tableLabel", root);
        return resMap;
    }
 
 
    @Override
    public Map satisfactionMonthChart(HttpServletRequest request) {
        String cusId = request.getParameter("cusId");
        String showType = request.getParameter("showType");
        
        String selMonth = request.getParameter("selMonth");
        
        StringBuilder sql = new StringBuilder();
        Map param = new HashMap();
        param.put("selMonth", selMonth);
        param.put("cusId", cusId);
        List<String> categories = new ArrayList<String>();
        categories.add("事件响应类得分");
        categories.add("驻场服务得分");
        categories.add("驻场响应类得分");
        categories.add("总得分");
        
        sql.setLength(0);
        sql.append(" select i.month,i.all_score,d.satis_score from totle_satis_info i, totle_satis_detail d ");
        sql.append(" where i.id = d.bus_id and i.month = :selMonth and i.customer_id = :cusId  order by d.satis_type asc ");
        List<Map> queryList = baseDao.queryForList(sql.toString(),param);
        Map resMap = new HashMap();
        Map queryMap = new HashMap();
        if(queryList!=null&&queryList.size()>0){
            for(int i=0;i<queryList.size();i++){
                if(i==0){
                    queryMap.put("XYL_SCORE",queryList.get(i).get("satis_score"));
                }else if(i==1){
                    queryMap.put("ZC_SCORE",queryList.get(i).get("satis_score"));
                    queryMap.put("ALL_SCORE",queryList.get(i).get("all_score"));
                }else if(i==2){
                    queryMap.put("ZCXYL_SCORE",queryList.get(i).get("satis_score"));
                }
            }
        }
        
        if(showType.equals("chart")){
            Map tempMap = new HashMap();
            List<Map> series = new ArrayList<Map>();
            List tempList = new ArrayList();
            tempMap.put("name", DateUtil.format("yyyy-MM", selMonth));
            tempList.add(ConvertUtil.obj2Double(queryMap.get("XYL_SCORE")));
            tempList.add(ConvertUtil.obj2Double(queryMap.get("ZC_SCORE")));
            tempList.add(ConvertUtil.obj2Double(queryMap.get("ALL_SCORE")));
            tempMap.put("data", tempList);
            series.add(tempMap);
            resMap.put("series", series);
            resMap.put("categories", categories);
        }else{
            queryMap.put("MONTH", DateUtil.format("yyyy-MM", selMonth));
            resMap.put("tableLabel", categories);
            resMap.put("tableData",queryMap);
        }
        return resMap;
    }
    
    @Override
    public Map querySatisReport(String cusId,String beginDay,String endDay) {
        
        Map paramMap = new HashMap();
        paramMap.put("cusId", cusId);
        paramMap.put("beginDay", beginDay);
        paramMap.put("endDay", endDay);
        //定义报表变量
        List<String> lebalList = new ArrayList<String>();  
        List<List<String>> dataList = new ArrayList<List<String>>();  
        //查询数据
        StringBuilder builder = new StringBuilder();
        builder.append(" select d.SATIS_TYPE,d.REQUEST_FG_RATE,d.SATIS_QZ,d.REQUEST_SATIS_SCORE,sum(d.ALL_COUNT) total_num,SUM(d.SATIS_COUNT) do_num,sum(d.ALL_COUNT-SATIS_COUNT) undo_num, ");
        builder.append(" truncate(avg(d.FG_RATE),2) cover_rate,truncate(avg(d.SATIS_SCORE),2) score  ");
        builder.append(" from TOTLE_SATIS_INFO i ,TOTLE_SATIS_DETAIL d ");
        builder.append(" where i.ID = d.BUS_ID and i.MONTH >= DATE_FORMAT(:beginDay,'%Y%m') and i.MONTH<=DATE_FORMAT(:endDay,'%Y%m')  ");
        if(StringUtil.notEmpty(cusId)){
            builder.append(" and i.CUSTOMER_ID = :cusId ");
        }
        builder.append(" group by d.SATIS_TYPE order by d.SATIS_TYPE ");
        List<Map> baseList = baseDao.queryForList(builder.toString(),paramMap);
        //组织表头
        lebalList.add("调查类型");
        lebalList.add("计划数");
        lebalList.add("已调查数");
        lebalList.add("未完成数");
        lebalList.add("要求覆盖率");
        lebalList.add("实际覆盖率");
        lebalList.add("得分权重");
        lebalList.add("要求得分");
        lebalList.add("满意度得分");
        
        //组织数据
        if(baseList!=null&&baseList.size()>0){
            for(Map base:baseList){
                List<String> tempList = new ArrayList<String>();
                if(ConvertUtil.obj2StrBlank(base.get("SATIS_TYPE")).equals("1")){
                    tempList.add("事件响应支持类");
                }else if(ConvertUtil.obj2StrBlank(base.get("SATIS_TYPE")).equals("3")){
                    tempList.add("驻场服务类");
                }else if(ConvertUtil.obj2StrBlank(base.get("SATIS_TYPE")).equals("6")){
                    tempList.add("驻场响应支持类");
                }
                tempList.add(ConvertUtil.obj2StrBlank(base.get("total_num")));
                
                
                
                tempList.add(ConvertUtil.obj2StrBlank(base.get("do_num")));
                if(ConvertUtil.obj2StrBlank(base.get("undo_num")).indexOf("-")>=0){
                    tempList.add("0");
                }else{
                    tempList.add(ConvertUtil.obj2StrBlank(base.get("undo_num")));
                }
                tempList.add(ConvertUtil.obj2StrBlank(base.get("REQUEST_FG_RATE"))+"%");
                tempList.add(ConvertUtil.obj2StrBlank(base.get("cover_rate"))+"%");
                tempList.add(ConvertUtil.obj2StrBlank(base.get("SATIS_QZ")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("REQUEST_SATIS_SCORE")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("score")));
                dataList.add(tempList);
            }
        }
        Map res = new HashMap();
        res.put("lebalList",lebalList);
        res.put("dataList",dataList);
        return res;
    }
 
 
    @Override
    public Map queryEngineerSatisReport(HttpServletRequest request) {
        String cusId = request.getParameter("cusId");
        String beginDay = request.getParameter("beginDay");
        String endDay = request.getParameter("endDay");
        
        Map paramMap = new HashMap();
        paramMap.put("cusId", cusId);
        paramMap.put("beginDay", beginDay);
        paramMap.put("endDay", endDay);
        paramMap.put("beginTime", beginDay+"666666");
        paramMap.put("endTime", endDay+"666666");
        
        String sql = " select  c.SATIS_BUSTYPE from KPI_SATIS_TEMPLATE t,KPI_CONFIG c  "  
                + " where t.ID = c.TEMPLATE_ID and t.STATE=1 and c.SATIS_TYPE = 2  "; 
        String businessTypes = baseDao.queryForString(sql,paramMap);
        if(StringUtil.isNotBlank(businessTypes)){
            businessTypes = businessTypes + ",'8'";
        }else{
            businessTypes = "'8'";
        }
        
        //定义报表变量
        List<String> lebalList = new ArrayList<String>();  
        List<List<String>> dataList = new ArrayList<List<String>>();  
        //查询数据
        StringBuilder builder = new StringBuilder();
        builder.append(" select user_name,total_num,IFNULL(invest_num,0) invest_num, ");
        builder.append(" truncate(IFNULL(invest_num,0)*100/total_num,2) cover_rate,truncate(score,2) score from (  ");
        builder.append("     select count(b.ID) total_num,user_name,user_id from workflow_base b,( ");
        builder.append("         SELECT FLOWID,current_dealer_id user_id,current_dealer_name user_name  ");
        builder.append("         FROM workflow_node n,( ");
        builder.append("             SELECT u.USER_ID FROM SC_SERVICER_GROUP g,SC_SERVICER_GROUP_USER u ");
        builder.append("             WHERE g.ID = u.GROUP_ID AND PROJECT_ID = :cusId AND GROUP_TYPE in (3,4,5) group by u.USER_ID ");
        builder.append("         ) u WHERE n.current_dealer_id  = u.USER_ID GROUP BY USER_ID,FLOWID ");
        builder.append("     ) t where b.ID = t.FLOWID and b.PROJECT_ID=:cusId and b.BUSINESSTYPE in ("+businessTypes+") ");
        builder.append("     and b.CREATETIME>:beginTime and b.CREATETIME<:endTime GROUP BY t.user_id ");
        builder.append(" ) mtotal left join ( ");
        builder.append("     select count(id) invest_num,INVEST_USER_ID,avg(SCORE) score from ORDER_SATIS_INFO  ");
        builder.append("     where INVEST_TIME >:beginDay and INVEST_TIME<:endDay and PROJECT_ID = :cusId group by INVEST_USER_ID ");
        builder.append(" ) minvest on mtotal.user_id=minvest.INVEST_USER_ID ");
        List<Map> baseList = baseDao.queryForList(builder.toString(),paramMap);
        //组织表头
        lebalList.add("人员");
        lebalList.add("处理工单数");
        lebalList.add("调查数");
        lebalList.add("覆盖率");
        lebalList.add("平均满意度得分");
        
        //组织数据
        if(baseList!=null&&baseList.size()>0){
            for(Map base:baseList){
                List<String> tempList = new ArrayList<String>();
                tempList.add(ConvertUtil.obj2StrBlank(base.get("user_name")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("total_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("invest_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("cover_rate"))+"%");
                tempList.add(ConvertUtil.obj2StrBlank(base.get("score")));
                dataList.add(tempList);
            }
        }
        Map res = new HashMap();
        res.put("lebalList",lebalList);
        res.put("dataList",dataList);
        return res;
    }
 
////////////////////////////////////////////////////////////////////////////////////////////////
    
    @Override
    public Map satisTrendLine(String cusId,String startDate, String endDate) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
        Calendar cal = Calendar.getInstance();
        try {
            cal.setTime(df.parse(startDate));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cal.add(Calendar.MONTH, -1);
        startDate = df.format(cal.getTime());
        
        Map chartMap = new HashMap();
        StringBuilder builder = new StringBuilder();
        builder.append(" SELECT I.ALL_SCORE,D.SATIS_SCORE,D.SATIS_TYPE,I.MONTH FROM TOTLE_SATIS_DETAIL D ,TOTLE_SATIS_INFO I ");
        builder.append(" WHERE D.BUS_ID = I.ID AND I.MONTH>=:startDate AND I.MONTH<=:endDate  ");
        if(StringUtil.isNotBlank(cusId)){
            builder.append(" and I.CUSTOMER_ID=:cusId ");
        }
        builder.append(" GROUP BY D.SATIS_TYPE,I.MONTH  ORDER BY SATIS_TYPE,MONTH ");
        
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        List<Map> queryList = baseDao.queryForList(builder.toString(), param);
        builder.setLength(0);    
        Map<String,Object> queryMap = new HashMap<String,Object>();
        
        if(queryList!=null&&queryList.size()>0){
            for(Map map:queryList){
                String key = map.get("SATIS_TYPE").toString()+"_"+map.get("MONTH").toString();
                queryMap.put(key, map);
            }
            List<Map> series = new ArrayList<Map>();
            List<String> categories = DateUtil.getIntervalMonths(Long.valueOf(startDate),Long.valueOf(endDate));
            List<String> categories_format = new  ArrayList<String>();
            List<String> typeList = new ArrayList();
            typeList.add("1");
            typeList.add("2");
            typeList.add("3");
            typeList.add("4");
            
            Map tempWholeMap = new HashMap();
            List tempWholeList = new ArrayList();
            tempWholeMap.put("name", "整体得分");
            tempWholeMap.put("type", "spline");
            //组装数据
            for(String type:typeList){
                Map tempMap = new HashMap();
                List tempList = new ArrayList();
                if(type.equals("1")){
                    tempMap.put("name", "响应支持类");
                }else if(type.equals("2")){
                    tempMap.put("name", "预防性维护类");
                }else if(type.equals("3")){
                    tempMap.put("name", "驻场服务类");
                }else if(type.equals("4")){
                    tempMap.put("name", "综合类满意度");
                }
                for(String cate:categories){
                    if(type.equals("1")){
                        categories_format.add(DateUtil.format("yyyy-MM", cate));
                    }
                    
                    String key = type + "_" + cate;
                    if(queryMap.get(key)!=null){
                        tempList.add(((Map)queryMap.get(key)).get("SATIS_SCORE"));
                        //整体得分
                        if(type.equals("1")){
                            tempWholeList.add(((Map)queryMap.get(key)).get("ALL_SCORE"));
                        }
                    }else{
                        tempList.add(0);
                        //整体得分
                        if(type.equals("1")){
                            tempWholeList.add(0);
                        }
                    }
                }
                
                tempMap.put("data", tempList);
                tempMap.put("type", "column");
                series.add(tempMap);
                if(type.equals("4")){
                    tempWholeMap.put("data", tempWholeList);
                    series.add(tempWholeMap);
                }
                chartMap.put("series", series);
                chartMap.put("categories", categories_format);
            }
            chartMap.put("nodata", false);
        }else{
            chartMap.put("nodata", true);
        }
        return chartMap;
    }
 
 
    @Override
    public Map satisCoverLine(String cusId,String startDate, String endDate) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
        Calendar cal = Calendar.getInstance();
        try {
            cal.setTime(df.parse(startDate));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cal.add(Calendar.MONTH, -1);
        startDate = df.format(cal.getTime());
        
        Map chartMap = new HashMap();
        StringBuilder builder = new StringBuilder();
        builder.append(" SELECT D.FG_RATE,D.SATIS_TYPE,I.MONTH FROM TOTLE_SATIS_DETAIL D ,TOTLE_SATIS_INFO I ");
        builder.append(" WHERE D.BUS_ID = I.ID AND I.MONTH>=:startDate AND I.MONTH<=:endDate  ");
        if(StringUtil.isNotBlank(cusId)){
            builder.append(" and I.CUSTOMER_ID=:cusId ");
        }
        builder.append(" GROUP BY D.SATIS_TYPE,I.MONTH  ORDER BY SATIS_TYPE,MONTH");
        
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        List<Map> queryList = baseDao.queryForList(builder.toString(), param);
        builder.setLength(0);    
        Map<String,Object> queryMap = new HashMap<String,Object>();
        
        if(queryList!=null&&queryList.size()>0){
            for(Map map:queryList){
                String key = map.get("SATIS_TYPE").toString()+"_"+map.get("MONTH").toString();
                queryMap.put(key, map);
            }
            List<Map> series = new ArrayList<Map>();
            List<String> categories = DateUtil.getIntervalMonths(Long.valueOf(startDate), Long.valueOf(endDate));
            List<String> categories_format = new  ArrayList<String>();
            List<String> typeList = new ArrayList();
            typeList.add("1");
            typeList.add("2");
            typeList.add("3");
            typeList.add("4");
            
            //组装数据
            for(String type:typeList){
                Map tempMap = new HashMap();
                List tempList = new ArrayList();
                if(type.equals("1")){
                    tempMap.put("name", "响应支持类");
                }else if(type.equals("2")){
                    tempMap.put("name", "预防性维护类");
                }else if(type.equals("3")){
                    tempMap.put("name", "驻场服务类");
                }else if(type.equals("4")){
                    tempMap.put("name", "综合类满意度");
                }
                for(String cate:categories){
                    if(type.equals("1")){
                        categories_format.add(DateUtil.format("yyyy-MM", cate));
                    }
                    String key = type + "_" + cate;
                    if(queryMap.get(key)!=null){
                        tempList.add(((Map)queryMap.get(key)).get("FG_RATE"));
                    }else{
                        tempList.add(0);
                    }
                }
                
                tempMap.put("data", tempList);
                series.add(tempMap);
                chartMap.put("series", series);
                chartMap.put("categories", categories_format);
            }
        }
        return chartMap;
    }
    
}