dhz
2022-06-22 935b4b66b99b1f022f82cdaef8e3ef6599afbc72
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
package cn.ksource.web.facade.tj;
 
import cn.ksource.beans.GG_USER;
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.dao.SqlParameter;
import cn.ksource.core.util.*;
import cn.ksource.web.Constants;
import cn.ksource.web.entity.LoginEntity;
import cn.ksource.web.service.DataDictionaryService;
import cn.ksource.web.util.ChartUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat;
import java.util.*;
 
@Service("incidentStatisFacade")
public class IncidentStatisFacadeImpl implements IncidentStatisFacade {
 
    @Autowired
    private BaseDao baseDao;
    
    @Autowired
    private DataDictionaryService dataDictionaryService;
 
    //获取查询Map
    private Map getQueryMap(HttpServletRequest request){
        String queryType = request.getParameter("queryType");
        Map queryMap = new HashMap();
        if(queryType.equals("1")){//按事件类型查询
            queryMap.put("col","TYPE_ID");
            queryMap.put("queryType",queryType);
            queryMap.put("dicCategoryKey",Constants.INCIDENT_TYPE);
        }else if(queryType.equals("2")){//按事件来源
            queryMap.put("col","SOURCE_ID");
            queryMap.put("queryType",queryType);
            queryMap.put("dicCategoryKey",Constants.INCIDENT_SOURCE);
        }else if(queryType.equals("3")){//关闭原因
            queryMap.put("col","RESOLVE_TYPE_ID");
            queryMap.put("queryType",queryType);
            queryMap.put("dicCategoryKey",Constants.CLOSE_REASON);
        }else if(queryType.equals("4")){//优先级
            queryMap.put("col","PRIORITY_ID");
            queryMap.put("queryType",queryType);
            queryMap.put("dicCategoryKey",Constants.INCIDENT_EVENT_PRI);
        }else if(queryType.equals("5")){//影响度
            queryMap.put("col","INFLUENCE_ID");
            queryMap.put("queryType",queryType);
            queryMap.put("dicCategoryKey",Constants.EVENT_EFFECT_DG);
        }else if(queryType.equals("6")){//服务级别
            queryMap.put("col","SLA_ID");
            queryMap.put("queryType",queryType);
        }else if(queryType.equals("7")){//响应超时
            queryMap.put("col","ANSWER_TIMEOUT");
            queryMap.put("queryType",queryType);
        }else if(queryType.equals("8")){//处理超时
            queryMap.put("col","DEAL_TIMEOUT");
            queryMap.put("queryType",queryType);
        }
        
        return queryMap;
    }
    
    //获取初始化list
    private List getQueryTypeList(Map queryMap){
        String queryType = queryMap.get("queryType").toString();
        List queryTypeList = new ArrayList<Map>();
        if(queryType.equals("1")||queryType.equals("2")||queryType.equals("3")||queryType.equals("4")
                ||queryType.equals("5")){
            queryTypeList = dataDictionaryService.getDataDictionaryByCategoryKey(queryMap.get("dicCategoryKey").toString());
        }else if(queryType.equals("6")){
            String sql = " select id DATAKEY,level_name DATAVALUE from SC_SLA where STATE=1 order by serial asc ";
            queryTypeList = baseDao.queryForList(sql,queryMap);
        }else if(queryType.equals("7")){
            String sql = " select 1 DATAKEY,'响应超时' DATAVALUE union select 2 DATAKEY,'响应及时' DATAVALUE ";
            queryTypeList = baseDao.queryForList(sql);
        }else if(queryType.equals("8")){
            String sql = " select 1 DATAKEY,'处理超时' DATAVALUE union select 2 DATAKEY,'处理及时' DATAVALUE ";
            queryTypeList = baseDao.queryForList(sql);
        }
        return queryTypeList;
    }
    
    
    
    
    @Override
    public List incidentTypePie(HttpServletRequest request) {
        String cusId = request.getParameter("cusId");
        String type = request.getParameter("type");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        if(!StringUtil.notEmptyNum(type)) {
            type = "2";
        }
        if(type.equals("1")) {
            beginTime = beginTime.replace("-", "")+"01";
            endTime = endTime.replace("-", "")+"31";
        } else {
            beginTime = beginTime.replace("-", "");
            endTime = endTime.replace("-", "");
        }
        //获取初始化LIST
        Map queryMap = getQueryMap(request);
        List<Map> list = getQueryTypeList(queryMap);
        List<Map> dataList = getQueryList_Pie(request,queryMap);
        
        List listResult = new ArrayList();
        if(list!=null&&list.size() > 0){
            for(Map resMap:list){
                List pieDate = new ArrayList();
                resMap.put("num", 0);
                if(dataList!=null&&dataList.size()>0){
                    for(Map tempMap:dataList){
                        if(tempMap.get("COLKEY").toString().equals(resMap.get("DATAKEY").toString())){
                            resMap.put("num", tempMap.get("NUM"));
                            break;
                        }
                    }
                }
                pieDate.add(resMap.get("DATAVALUE"));
                pieDate.add(resMap.get("num"));
                listResult.add(pieDate);
            }
        }
        System.out.println("事件类型---------------------->"+JsonUtil.list2Json(listResult));
        return listResult;
    }
 
    @Override
    public Map incidentTypeLine(HttpServletRequest request) {
        
        String type = request.getParameter("type");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        
        if(!StringUtil.notEmptyNum(type)) {
            type = "2";
        }
        List<String> categories = new ArrayList<String>();//获取X轴数据
        if(type.equals("1")) {
            categories = DateUtil.getBetweenTwoDateList(beginTime, endTime, 1, "yyyyMM");
        } else {
            categories = DateUtil.getBetweenTwoDateList(beginTime, endTime, 2, "yyyyMMdd");
        }
        
        
        Map queryMap = getQueryMap(request);
        List<Map> types = getQueryTypeList(queryMap);
        List<Map> typeMsg = getQueryList_Line(request,queryMap);
        
        Map cacheMap = new HashMap();
        if(null!=typeMsg && typeMsg.size()>0) {
            for(Map  msg : typeMsg) {
                String typeId = ConvertUtil.obj2StrBlank(msg.get("COLKEY"));
                int num = ConvertUtil.obj2Int(msg.get("NUM"));
                String time = ConvertUtil.obj2StrBlank(msg.get("DC_TIME"));
                String key = time + "-" + typeId;
                cacheMap.put(key, num);
            }
        }
        
        
        List resultList = new ArrayList();
        
        if(null!=types && types.size()>0) {
            for(Map t : types) {
                Map newMap = new HashMap();
                String key = ConvertUtil.obj2StrBlank(t.get("DATAKEY"));
                String name = ConvertUtil.obj2StrBlank(t.get("DATAVALUE"));
                
                newMap.put("name", name);
                List list = new ArrayList();
                for(String cate : categories) {
                    String unitKey = cate + "-" + key;
                    if(cacheMap.containsKey(unitKey)) {
                        list.add(cacheMap.get(unitKey));
                    } else {
                        list.add(0);
                    }
                }
                newMap.put("data", list);
                resultList.add(newMap);
            }
        }
        
        //System.out.println(JsonUtil.list2Json(resultList));
        Map resultMap = new HashMap();
        resultMap.put("cate", categories);
        resultMap.put("data", resultList);
        resultMap.put("step", Math.round(categories.size()/8));
        
        System.out.println("line-------------->"+JsonUtil.map2Json(resultMap));
        return resultMap;
    }
    
    //获取饼状图查询结果
    private List getQueryList_Pie(HttpServletRequest request,Map queryMap){
        String cusId = request.getParameter("cusId");
        String type = request.getParameter("type");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        List<Map> queryList = new ArrayList<Map>();
        Map paramMap = new HashMap();
        StringBuilder buffer = new StringBuilder("SELECT $KEY as COLKEY,COUNT(C.ID) AS NUM FROM SC_WORKFLOW_INCIDENT C WHERE 1=1 ");
        if(StringUtil.notEmpty(cusId) ) {
            buffer.append(" AND CUSTOMER_ID = :cusId AND CUSTOMER_ID = :cusId ");
            paramMap.put("cusId", cusId);
            paramMap.put("cusId", cusId);
        } 
        if(StringUtil.notEmpty(type)) {
            buffer.append(" AND C.CREATE_TIME >= :beginTime AND C.CREATE_TIME <= :endTime ");
            
            if(type.equals("1")) {
                paramMap.put("beginTime", beginTime+"01000000");
                paramMap.put("endTime", endTime+"31240000");
            } else {
                paramMap.put("beginTime", beginTime+"000000");
                paramMap.put("endTime", endTime+"240000");
            }
            
        }
        buffer.append(" and $KEY is not null ");
        buffer.append(" GROUP BY $KEY ");
        
        String sql = buffer.toString().replace("$KEY", queryMap.get("col").toString());
        List<Map> dataList = baseDao.queryForList(sql, paramMap);
        return dataList;
    }
    
    //获取线形图查询结果
    private List getQueryList_Line(HttpServletRequest request,Map queryMap){
        String cusId = request.getParameter("cusId");
        String type = request.getParameter("type");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        
        Map paramMap = new HashMap();
        StringBuilder builder = new StringBuilder("");
        if(type.equals("2")) {
            builder = builder.append("SELECT $KEY COLKEY,COUNT(C.TYPE_ID) AS NUM,DATE_FORMAT(C.CREATE_TIME,'%Y-%m-%d') AS DC_TIME  FROM SC_WORKFLOW_INCIDENT C WHERE 1=1 ");
        } else {
            builder = builder.append("SELECT $KEY COLKEY,COUNT(C.TYPE_ID) AS NUM,DATE_FORMAT(C.CREATE_TIME,'%Y-%m') AS DC_TIME FROM SC_WORKFLOW_INCIDENT C WHERE 1=1 ");
        }
        
        if(StringUtil.notEmpty(cusId) ) {
            builder.append(" AND C.CUSTOMER_ID = :cusId AND C.CUSTOMER_ID = :cusId ");
            paramMap.put("cusId", cusId);
        } 
        if(StringUtil.notEmpty(beginTime) && StringUtil.notEmpty(endTime)) {
            beginTime = beginTime.replaceAll("-", "");
            endTime = endTime.replaceAll("-", "");
            builder.append(" AND C.CREATE_TIME>=:beginTime AND C.CREATE_TIME <=:endTime ");
            if(type.equals("1")) {
                paramMap.put("beginTime", beginTime+"01000000");
                paramMap.put("endTime", endTime+"31240000");
            } else {
                paramMap.put("beginTime", beginTime+"000000");
                paramMap.put("endTime", endTime+"240000");
            }
        }
        builder.append(" and $KEY is not null ");
        builder.append(" GROUP BY $KEY,DC_TIME ");
        String sql = builder.toString().replace("$KEY", queryMap.get("col").toString());
        return baseDao.queryForList(sql,paramMap);
    }
    
    @Override
    public Map incidentTimeLine(HttpServletRequest request){
        String selDay = request.getParameter("selDay");
        String cusId = request.getParameter("cusId");
        
        StringBuilder sql = new StringBuilder();
        Map paramMap = new HashMap();
        sql.append(" SELECT HOUR(HAPPEN_TIME)  MHOUR,count(ID) NUM FROM SC_WORKFLOW_INCIDENT C");
        sql.append(" where DATE_FORMAT(HAPPEN_TIME,'%Y%m%d')=:selDay and HOUR(HAPPEN_TIME)>=7  and HOUR(HAPPEN_TIME)<=18   ");
        if(StringUtil.notEmpty(cusId) ) {
            sql.append(" AND CUSTOMER_ID = :cusId  ");
            paramMap.put("cusId", cusId);
            paramMap.put("cusId", cusId);
        } 
        sql.append(" GROUP BY MHOUR ");
        
        paramMap.put("selDay", selDay);
        List<Map> list = baseDao.queryForList(sql.toString(),paramMap);
        Map categoriesMap = new HashMap();
        categoriesMap.put("7:00-9:00", 0);
        categoriesMap.put("9:00-11:00", 0);
        categoriesMap.put("11:00-13:00", 0);
        categoriesMap.put("13:00-15:00", 0);
        categoriesMap.put("15:00-17:00", 0);
        categoriesMap.put("17:00-18:00", 0);
        //x轴
        List<String> categoriesList = new ArrayList<String>();
        categoriesList.add("7:00-9:00");
        categoriesList.add("9:00-11:00");
        categoriesList.add("11:00-13:00");
        categoriesList.add("13:00-15:00");
        categoriesList.add("15:00-17:00");
        categoriesList.add("17:00-18:00");
        
        
        if(list!=null&&list.size()>0){
            for(Map map:list){
                String hour = map.get("MHOUR").toString();
                if(hour.equals("7")||hour.equals("8")){
                    Integer sum = Integer.valueOf(categoriesMap.get("7:00-9:00").toString())+Integer.valueOf(map.get("NUM").toString());
                    categoriesMap.put("7:00-9:00", sum);
                }else if(hour.equals("9")||hour.equals("10")){
                    Integer sum = Integer.valueOf(categoriesMap.get("9:00-11:00").toString())+Integer.valueOf(map.get("NUM").toString());
                    categoriesMap.put("9:00-11:00", sum);
                }else if(hour.equals("11")||hour.equals("12")){
                    Integer sum = Integer.valueOf(categoriesMap.get("11:00-13:00").toString())+Integer.valueOf(map.get("NUM").toString());
                    categoriesMap.put("11:00-13:00", sum);
                }else if(hour.equals("13")||hour.equals("14")){
                    Integer sum = Integer.valueOf(categoriesMap.get("13:00-15:00").toString())+Integer.valueOf(map.get("NUM").toString());
                    categoriesMap.put("13:00-15:00", sum);
                }else if(hour.equals("15")||hour.equals("16")){
                    Integer sum = Integer.valueOf(categoriesMap.get("15:00-17:00").toString())+Integer.valueOf(map.get("NUM").toString());
                    categoriesMap.put("15:00-17:00", sum);
                }else if(hour.equals("17")||hour.equals("18")){
                    Integer sum = Integer.valueOf(categoriesMap.get("17:00-18:00").toString())+Integer.valueOf(map.get("NUM").toString());
                    categoriesMap.put("17:00-18:00", sum);
                }
            }
        }
        List dataList = new ArrayList();
        dataList.add(categoriesMap.get("7:00-9:00"));
        dataList.add(categoriesMap.get("9:00-11:00"));
        dataList.add(categoriesMap.get("11:00-13:00"));
        dataList.add(categoriesMap.get("13:00-15:00"));
        dataList.add(categoriesMap.get("15:00-17:00"));
        dataList.add(categoriesMap.get("17:00-18:00"));
        List seriesList = new ArrayList();
        Map seriesMap = new HashMap();
        seriesMap.put("name","数量");
        seriesMap.put("data",dataList);
        seriesList.add(seriesMap);
        Map resMap = new HashMap();
        resMap.put("categories", categoriesList);
        resMap.put("series", seriesList);
        
        System.out.println("发生时间统计-------------->"+JsonUtil.map2Json(resMap));
        return resMap;
    }
    
    
    @Override
    public Map incidentDealRateColumn(HttpServletRequest request){
        String selDay = request.getParameter("selDay");
        String cusId = request.getParameter("cusId");
        String queryType = request.getParameter("queryType");
 
        StringBuilder sql = new StringBuilder();
        Map paramMap = new HashMap();
        sql.append(" select CUSTOMER_ID,floor((count(ID)/(select count(ID) from workflow_base c where businesstype = 8 ))*100) RATE ");
        sql.append(" from workflow_base C where businesstype = 8  and wfstate=2 and CUSTOMER_ID is not null  ");
        sql.append(" and CURRENT_NODE_ID = :nodeId  ");
        if(queryType.equals("frontLine")){
            paramMap.put("nodeId", Constants.KFRY);
        }else{
            paramMap.put("nodeId", Constants.YXCL);
        }
        if(StringUtil.notEmpty(cusId)) {
            sql.append(" AND CUSTOMER_ID = :cusId AND CUSTOMER_ID = :cusId ");
            paramMap.put("cusId", cusId);
            
        }
        sql.append(" GROUP BY CUSTOMER_ID "); 
        List<Map> queryList = baseDao.queryForList(sql.toString(), paramMap);
        List<String> categories = new ArrayList<String>();//X轴类别
        List series = new ArrayList();
        Map seriesMap = new HashMap();
        List dataList = new ArrayList();
        seriesMap.put("name", "解决率");
        seriesMap.put("data", dataList);
        series.add(seriesMap);
        Map resMap = new HashMap();
        resMap.put("categories", categories);
        resMap.put("series", series);
        return resMap;
    }
 
    @Override
    public Map incidentDealRateLine(HttpServletRequest request) {
        String selDay = request.getParameter("selDay");
        String cusId = request.getParameter("cusId");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        
        List<String> categories = new ArrayList<String>();//获取X轴数据
        categories = DateUtil.getBetweenTwoDateList(beginTime, endTime, 2, "yyyyMMdd");
        
        StringBuilder sql = new StringBuilder();
        Map paramMap = new HashMap();
        sql.append(" select DATE_FORMAT(CREATETIME,'%Y%m%d') MDAY,CURRENT_NODE_ID,floor((count(ID)/(select count(ID) from workflow_base c where businesstype = 8 ))*100) RATE ");
        sql.append(" from workflow_base C where businesstype = 8  and wfstate=2 and CUSTOMER_ID is not null  ");
        sql.append(" and CURRENT_NODE_ID in ('"+Constants.KFRY+"','"+Constants.YXCL+"')  ");
        if(StringUtil.notEmpty(cusId) ) {
            sql.append(" AND CUSTOMER_ID = :cusId ");
            paramMap.put("cusId", cusId);
        } 
        sql.append(" GROUP BY CURRENT_NODE_ID,MDAY "); 
        System.out.println("sql is ---------------"+sql.toString());
        List<Map> queryList = baseDao.queryForList(sql.toString(), paramMap);
        
        List series = new ArrayList();//最终数据集合
        
        Map tempMap = new HashMap();
        tempMap.put(Constants.KFRY, "服务台解决率");
        tempMap.put(Constants.YXCL, "一线解决率");
        Iterator it=tempMap.keySet().iterator(); 
        while(it.hasNext()){
            String key = it.next().toString() ;    
            String value = tempMap.get(key).toString(); 
            Map seriesMap = new HashMap();
            List dataList = new ArrayList();
            seriesMap.put("name", value);
            for(String categorie:categories){
                Integer rate = 0;
                for(Map queryMap:queryList){
                    if(queryMap.get("CURRENT_NODE_ID").toString().equals(key)&&categorie.equals(queryMap.get("MDAY").toString())){
                        rate = Integer.valueOf(queryMap.get("RATE").toString());
                        break;
                    }
                }
                dataList.add(rate);
            }
            seriesMap.put("data", dataList);
            series.add(seriesMap);
        }
        
        Map resMap = new HashMap();
        resMap.put("categories", categories);
        resMap.put("series", series);
        resMap.put("step", Math.round(categories.size()/8));
        return resMap;
    }
 
    @Override
    public Map incidentTotalChart(String cusId,String cusName,String beginTime,String endTime) {
        //获取参数
        beginTime = beginTime + "000000";
        endTime = endTime + "666666";
        
        List<Map> typeList = getDicList(Constants.INCIDENT_TYPE);
        List<Map> sourceList = getDicList(Constants.INCIDENT_SOURCE);
        List<Map> closeList = getDicList(Constants.CLOSE_REASON);
        List<Map> priList = getDicList(Constants.INCIDENT_EVENT_PRI);
        List<Map> effectList = getDicList(Constants.EVENT_EFFECT_DG);
        List<Map> levelList = baseDao.queryForList(" select LEVEL_NAME labelName from SC_SLA where state=1 order by SERIAL asc  ");
        List<Map> timeoutList = baseDao.queryForList(" select '超时' labelName union select '正常' labelName ");
        List<Map> resolveList = getDicList(Constants.RESOLVE_WAY);
        List<Map> stateList = baseDao.queryForList(" select '待响应' labelName union select '处理中' labelName union select '已完成' labelName ");
        String blankKey = "";
        String blankSql = "";
        String tempSql = "";
        StringBuilder sql = new StringBuilder();
        sql.append(" select mtotal.total_num,mtotal.mdate,mtype.type_num,msource.source_num,mclose.close_num,mpri.pri_num,meffect.effect_num, ");
        sql.append(" mlevel.level_num,manswer.answer_num,mdeal.deal_num,mresolve.resolve_num,mstate.state_num ");
        sql.append(" from "); 
        sql.append(" ( "); 
        sql.append("    select count(ID) total_num,substr(HAPPEN_TIME||'',1,8)  mdate from SC_WORKFLOW_INCIDENT  ");
        sql.append("    where  HAPPEN_TIME>=:beginTime and HAPPEN_TIME<=:endTime  "); 
        if(StringUtil.isNotBlank(cusId)){
            sql.append("and CUSTOMER_ID=:cusId  "); 
        }
        sql.append("    group by substr(HAPPEN_TIME||'',1,8)  ");
        
        sql.append(" ) mtotal "); 
        //事件类型
        sql = getPartSql(sql,"type_num",Constants.INCIDENT_TYPE,blankSql,"TYPE_ID","mtype","1",cusId);
        //事件来源
        sql = getPartSql(sql,"source_num",Constants.INCIDENT_SOURCE,blankSql,"SOURCE_ID","msource","1",cusId);
        //关闭原因
        sql = getPartSql(sql,"close_num",Constants.CLOSE_REASON,blankSql,"RESOLVE_TYPE_ID","mclose","1",cusId);
        //优先级
        sql = getPartSql(sql,"pri_num",Constants.INCIDENT_EVENT_PRI,blankSql,"PRIORITY_ID","mpri","1",cusId);
        //影响度
        sql = getPartSql(sql,"effect_num",Constants.EVENT_EFFECT_DG,blankSql,"INFLUENCE_ID","meffect","1",cusId);
        //服务级别
        tempSql = " select id DATAKEY,SERIAL ordernum from SC_SLA where STATE=1  ";
        sql = getPartSql(sql,"level_num",blankKey,tempSql,"SLA_ID","mlevel","1",cusId);
        //响应时间
        tempSql = " select 1 DATAKEY,1 ordernum union select 2 DATAKEY,2 ordernum  ";
        sql = getPartSql(sql,"answer_num",blankKey,tempSql,"ANSWER_TIMEOUT","manswer","1",cusId);
        //解决时间
        sql = getPartSql(sql,"deal_num",blankKey,tempSql,"DEAL_TIMEOUT","mdeal","1",cusId);
        //解决途径
        sql = getPartSql(sql,"resolve_num",Constants.RESOLVE_WAY,blankSql,"RESOLVE_TYPE_ID","mresolve","1",cusId);
        //事件状态
        tempSql = " select 1 DATAKEY,1 ordernum union select 2 DATAKEY,2 ordernum  union select 3 DATAKEY,3 ordernum ";
        sql = getPartSql(sql,"state_num",blankKey,tempSql,"FLOWSTATE","mstate","2",cusId);
        
        Map param = new HashMap();
        param.put("cusId", cusId);
        param.put("beginTime", beginTime);
        param.put("endTime", endTime);
        List<Map> resList = baseDao.queryForList(sql.toString(),param); 
        Map resMap = new HashMap();
        resMap.put("typeList", typeList);
        resMap.put("sourceList", sourceList);
        resMap.put("closeList", closeList);
        resMap.put("priList", priList);
        resMap.put("effectList", effectList);
        resMap.put("levelList", levelList);
        resMap.put("timeoutList", timeoutList);
        resMap.put("resolveList", resolveList);
        resMap.put("stateList", stateList);
        resMap.put("resList", resList);
        resMap.put("cusName", cusName);
        
        return resMap;
    }
    
    /**
     * 获取组装sql
     * @param sql
     * @param categoryKey 数据字典分类key
     * @param tempSql 临时sql
     * @param column 列名称
     * @param tempTableName 临时表名称
     * @param flag 标示
     * @return 组装后sql
     */
    private StringBuilder getPartSql(StringBuilder sql,String numName,String categoryKey,String tempSql,
            String column,String tempTableName,String flag,String cusId){
        sql.append(" left join  ");
        sql.append(" (  ");
        sql.append("  select mdate,WM_CONCAT(num) "+numName+" from ");
        sql.append("  (    ");
        sql.append("      select count(i.ID)  num,mdate,datakey,ordernum from ");
        sql.append("      ( ");
        sql.append("          select DATAKEY,mdate,ordernum from ");
        sql.append("          (select substr(HAPPEN_TIME||'',1,8) mdate  from SC_WORKFLOW_INCIDENT group by substr(HAPPEN_TIME||'',1,8) ) d,");
        sql.append("          ( ");
        if(StringUtil.isNotBlank(categoryKey)){
            sql = getDicSql(sql,categoryKey);
        }else{
            sql.append(tempSql);
        }
        sql.append("          ) c ");
        sql.append("      ) b ");
        sql.append("      left join  ");
        if(flag.equals("1")){
            sql.append("( select * from SC_WORKFLOW_INCIDENT   ");
            if(StringUtil.isNotBlank(cusId)){
                sql.append(" where CUSTOMER_ID = :cusId  ");
            }
            sql.append(" ) ");
        }else{
            sql = getStateSql(sql,cusId);
        }
        sql.append(" i on i."+column+" = b.DATAKEY and substr(HAPPEN_TIME||'',1,8)=b.mdate ");
        sql.append("     group by b.mdate,b.datakey,b.ordernum order by b.ordernum");
        sql.append(" ) t group by t.mdate ");
        sql.append(" ) "+tempTableName);
        sql.append(" on "+tempTableName+".mdate = mtotal.mdate ");
        return sql;
    }
    
    /**
     * 获取数据字典查询sql
     * @param sql
     * @param categoryKey
     * @return
     */
    private StringBuilder getDicSql(StringBuilder sql,String categoryKey){
        sql.append(" select d.DATAKEY,d.ordernum from CONFIG_DATA_DICTIONARY d ");
        sql.append(" inner join CONFIG_DATA_DICTIONARY_CATEGORY cate  ");
        sql.append(" on d.CATEGORYID = cate.ID  ");
        sql.append(" where cate.CATEGORYKEY='"+categoryKey+"' order by ordernum");
        return sql;
    }
    
    /**
     * 获取事件状态sql
     * @param sql
     * @return
     */
    private StringBuilder getStateSql(StringBuilder sql,String cusId){
        sql.append(" (");
        sql.append("  select c.CUSTOMER_ID,c.id,n.FLOWSTATE,c.HAPPEN_TIME,b.WFSTATE from SC_WORKFLOW_INCIDENT c  ");
        sql.append("  inner join workflow_base b on c.flow_id = b.id and b.wfstate<>3  ");
        sql.append("  inner JOIN workflow_node n on b.CURRENT_NODE_ID = n.id  ");
        if(StringUtil.isNotBlank(cusId)){
            sql.append("  where c.CUSTOMER_ID = :cusId and c.STATE !=10");
        }
        sql.append(" )");
        return sql;
    }
    
    
    private List<Map> getDicList(String categoryKey){
        String sql = " select d.DATAVALUE labelName from CONFIG_DATA_DICTIONARY d  " +
                    " inner join CONFIG_DATA_DICTIONARY_CATEGORY c on " +
                    " d.CATEGORYID = c.ID where c.CATEGORYKEY=:categoryKey order by d.ordernum ASC";
        Map param = new HashMap();
        param.put("categoryKey",categoryKey);
        return baseDao.queryForList(sql,param);
    }
 
    @Override
    public List queryIncidentStatis(String cusId,String subCustomerId,String beginTime,String endTime,String jjState,String csState,String jjrId) {
        beginTime = beginTime + "000000";
        endTime = endTime + "240000";
        Map param= new HashMap();
        param.put("cusId", cusId);
        param.put("cusId", cusId);
        param.put("beginTime", beginTime);
        param.put("endTime", endTime);
        param.put("subCustomerId", subCustomerId);
        param.put("jjrId", jjrId);
        StringBuilder sql=new StringBuilder();
        sql.append("SELECT A.*,B.WFSTATE,B.CURRENT_DEALER_NAME FROM SC_WORKFLOW_INCIDENT A,WORKFLOW_BASE B WHERE 1=1 AND A.ID=B.BUSINESS_ID");
        if(StringUtil.notEmpty(cusId) ){
            sql.append(" AND A.CUSTOMER_ID=:cusId ");
        }
        if(StringUtil.notEmpty(beginTime) && StringUtil.notEmpty(endTime)){
            sql.append(" AND A.CREATE_TIME>:beginTime AND A.CREATE_TIME<:endTime");
        }
        if(StringUtil.notEmpty(subCustomerId)){
            sql.append(" AND A.SUB_CUSTOMER_ID=:subCustomerId");
        }
        if(StringUtil.notEmpty(jjrId)){
            sql.append(" AND A.RESOLVE_USER_ID=:jjrId");
        }
        if(StringUtil.notEmpty(csState)){
            if(csState.equals("1")){
                sql.append(" AND (A.ANSWER_TIMEOUT=1 or A.DEAL_TIMEOUT=1) ");
            }else if(csState.equals("2")){
                sql.append(" AND A.ANSWER_TIMEOUT=2 AND A.DEAL_TIMEOUT=2 ");
            }
        }
        if(StringUtil.notEmpty(jjState)){
            if(jjState.equals("1")){
                sql.append(" AND B.WFSTATE in(2,4) ");
            }else if(jjState.equals("2")){
                sql.append(" AND B.WFSTATE=1 ");
            }
        }
        List incidentList=baseDao.queryForList(sql.toString(), param);
        return incidentList;
    }
    @Override
    public List queryIncidentStatisTwo(String cusId,String subCustomerId,String beginTime,String endTime,String jjState,String csState,String jjrId,String type_id) {
        beginTime = beginTime + "000000";
        endTime = endTime + "240000";
        Map param= new HashMap();
        param.put("cusId", cusId);
        param.put("cusId", cusId);
        param.put("beginTime", beginTime);
        param.put("endTime", endTime);
        param.put("subCustomerId", subCustomerId);
        param.put("jjrId", jjrId);
        param.put("type_id", type_id);
        StringBuilder sql=new StringBuilder();
        sql.append("SELECT A.*,B.WFSTATE,B.CURRENT_DEALER_NAME FROM SC_WORKFLOW_INCIDENT A,WORKFLOW_BASE B WHERE 1=1 AND A.ID=B.BUSINESS_ID");
        if(StringUtil.notEmpty(cusId) ){
            sql.append(" AND A.CUSTOMER_ID=:cusId ");
        }
        if(StringUtil.notEmpty(beginTime) && StringUtil.notEmpty(endTime)){
            sql.append(" AND A.CREATE_TIME>:beginTime AND A.CREATE_TIME<:endTime");
        }
        if(StringUtil.notEmpty(subCustomerId)){
            sql.append(" AND A.SUB_CUSTOMER_ID=:subCustomerId");
        }
        if(StringUtil.notEmpty(jjrId)){
            sql.append(" AND A.RESOLVE_USER_ID=:jjrId");
        }
        if(StringUtil.notEmpty(type_id)){
            sql.append(" AND A.TYPE_ID=:type_id");
        }
        if(StringUtil.notEmpty(csState)){
            if(csState.equals("1")){
                sql.append(" AND (A.ANSWER_TIMEOUT=1 or A.DEAL_TIMEOUT=1) ");
            }else if(csState.equals("2")){
                sql.append(" AND A.ANSWER_TIMEOUT=2 AND A.DEAL_TIMEOUT=2 ");
            }
        }
        if(StringUtil.notEmpty(jjState)){
            if(jjState.equals("1")){
                sql.append(" AND B.WFSTATE in(2,4) ");
            }else if(jjState.equals("2")){
                sql.append(" AND B.WFSTATE=1 ");
            }
        }
        List incidentList=baseDao.queryForList(sql.toString(), param);
        return incidentList;
    }
 
    /**
     * 事件达成率统计
     */
    @Override
    public List<Map> queryIncidentDclStatis(String cusId,String subCustomerId,String beginTime,String endTime) {
        
        Map paramMap = new HashMap();
        
        //通过项目编号,查询该项目的所有的服务目录
        String sql = "SELECT COUNT(ID) AS NUM,THIRD_CATEGORY_ID,THIRD_CATEGORY_NAME,SECOND_CATEGORY_NAME,FIRST_CATEGORY_NAME FROM SC_WORKFLOW_INCIDENT WHERE state!=10 and CUSTOMER_ID = :cusId AND CUSTOMER_ID = :cusId AND CREATE_TIME > :beginTime AND CREATE_TIME <= :endTime ";
        if(StringUtil.notEmpty(subCustomerId)) {
            sql+= " AND SUB_CUSTOMER_ID = :subCustomerId ";
            paramMap.put("subCustomerId", subCustomerId);
        }
        
        StringBuilder builder1 = new StringBuilder(sql);
        StringBuilder builder2 = new StringBuilder(sql);
        StringBuilder builder3 = new StringBuilder(sql);
        StringBuilder builder4 = new StringBuilder(sql);
        
        
        String endSql = " GROUP BY THIRD_CATEGORY_ID,THIRD_CATEGORY_NAME,SECOND_CATEGORY_NAME,FIRST_CATEGORY_NAME ";
        
        builder1.append(endSql);
        
        builder2.append(" AND ANSWER_TIMEOUT = 1 ").append(endSql);
        
        builder3.append(" AND DEAL_TIMEOUT = 1 ").append(endSql);
        
        builder4.append(" AND ANSWER_TIMEOUT = 2 AND DEAL_TIMEOUT = 2 ").append(endSql);
        
        
        
        paramMap.put("cusId", cusId);
        paramMap.put("cusId", cusId);
        paramMap.put("beginTime", beginTime+"000000");
        paramMap.put("endTime", endTime+"240000");
        
        
        List<Map> list1 = baseDao.queryForList(builder1.toString(),paramMap);
        
        List<Map> list2 = baseDao.queryForList(builder2.toString(),paramMap);
        
        List<Map> list3 = baseDao.queryForList(builder3.toString(),paramMap);
        
        List<Map> list4 = baseDao.queryForList(builder4.toString(),paramMap);
        
        
        if(null!=list1 && list1.size()>0) {
            Map map2 = new HashMap();
            for(Map map : list2) {
                map2.put(map.get("THIRD_CATEGORY_ID"), map);
            }
            
            Map map3 = new HashMap();
            for(Map map : list3) {
                map3.put(map.get("THIRD_CATEGORY_ID"), map);
            }
            
            Map map4 = new HashMap();
            for(Map map : list4) {
                map4.put(map.get("THIRD_CATEGORY_ID"), map);
            }
            
            for(Map map : list1) {
                String thirdCategoryId = ConvertUtil.obj2StrBlank(map.get("THIRD_CATEGORY_ID"));
                if(map2.containsKey(thirdCategoryId)) {
                    Map m = (Map)map2.get(thirdCategoryId);
                    int num = ConvertUtil.obj2Int(m.get("NUM"));
                    map.put("xy", num);
                } else {
                    map.put("xy", 0);
                }
                
                if(map3.containsKey(thirdCategoryId)) {
                    Map m = (Map)map3.get(thirdCategoryId);
                    int num = ConvertUtil.obj2Int(m.get("NUM"));
                    System.out.println("num:"+num);
                    map.put("cl", num);
                } else {
                    map.put("cl", 0);
                }
                
                double jj = 0;
                
                if(map4.containsKey(thirdCategoryId)) {
                    Map m = (Map)map4.get(thirdCategoryId);
                    int num = ConvertUtil.obj2Int(m.get("NUM"));
                    
                    jj = ConvertUtil.obj2Double(m.get("NUM"));
                    
                    map.put("jj", num);
                } else {
                    map.put("jj", 0);
                }
                
                
                double total = ConvertUtil.obj2Double(map.get("NUM"));
                
                
                double jjl = NumberUtil.div(jj, total, 3);
                
                //jjl = NumberUtil.mul(jjl, ConvertUtil.obj2Double(100));
                
                map.put("jjl", jjl);
                
            }
            
        }
        
        System.out.println(JsonUtil.list2Json(list1));
        return list1;
    }
 
    @Override
    public Map queryOrderClStatis(HttpServletRequest request,int type) {
        Map resultMap = new HashMap();
        String cusId = request.getParameter("cusId");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String subCustomerId = request.getParameter("sub_customer_id");
        StringBuilder builder1 = new StringBuilder("SELECT COUNT(A.ID) AS NUM,B.THIRD_CATEGORY_ID,B.THIRD_CATEGORY_NAME FROM WORKFLOW_BASE A,SC_WORKFLOW_INCIDENT B WHERE A.BUSINESS_ID = B.ID AND A.WFSTATE != 5 AND A.BUSINESSTYPE = :businessType AND A.CUSTOMER_ID = :cusId AND A.CUSTOMER_ID = :cusId AND B.CREATE_TIME > :beginTime AND B.CREATE_TIME <= :endTime ");
        StringBuilder builder2 = new StringBuilder("SELECT COUNT(A.ID) AS NUM,B.THIRD_CATEGORY_ID,A.WFSTATE FROM WORKFLOW_BASE A,SC_WORKFLOW_INCIDENT B WHERE A.BUSINESS_ID = B.ID AND A.WFSTATE != 5 AND A.BUSINESSTYPE = :businessType AND A.CUSTOMER_ID = :cusId AND A.CUSTOMER_ID = :cusId AND B.CREATE_TIME > :beginTime AND B.CREATE_TIME <= :endTime ");
        
        Map paramMap = new HashMap();
        
        if(StringUtil.notEmpty(subCustomerId)) {
            builder1.append(" AND A.SUB_CUSTOMER_ID = :subCustomerId ");
            builder2.append(" AND A.SUB_CUSTOMER_ID = :subCustomerId ");
            paramMap.put("subCustomerId", subCustomerId);
        }
        
        builder1.append(" GROUP BY B.THIRD_CATEGORY_ID ");
        builder2.append(" GROUP BY B.THIRD_CATEGORY_ID,A.WFSTATE ");
        
        paramMap.put("cusId", cusId);
        paramMap.put("cusId", cusId);
        paramMap.put("beginTime", beginTime+"000000");
        paramMap.put("endTime", endTime+"240000");
        paramMap.put("businessType", type);
        
        
        List<Map> list1 = baseDao.queryForList(builder1.toString(),paramMap);
        
        List<Map> list2 = baseDao.queryForList(builder2.toString(),paramMap);
        
        int total = 0;
        int totaljxz = 0;
        int totalywc = 0;
        int totalygb = 0;
        int totalypj = 0;
        int totalygq = 0;
        
        if(null!=list1 && list1.size()>0) {
            Map map2 = new HashMap();
            for(Map map : list2) {
                String third_category_id = ConvertUtil.obj2StrBlank(map.get("THIRD_CATEGORY_ID"));
                String wfstate = ConvertUtil.obj2StrBlank(map.get("WFSTATE"));
                String unitKey = third_category_id+"-"+wfstate;
                String num = ConvertUtil.obj2StrBlank(map.get("NUM"));
                map2.put(unitKey, num);
            }
            
            
            for(Map map : list1) {
                int num = ConvertUtil.obj2Int(map.get("NUM"));
                total += num;
                
                
                String third_category_id = ConvertUtil.obj2StrBlank(map.get("THIRD_CATEGORY_ID"));
                String unitKey1 = third_category_id+"-1";
                
                int jxz = 0;
                if(map2.containsKey(unitKey1)) {
                    jxz = ConvertUtil.obj2Int(map2.get(unitKey1));
                }
                map.put("jxz", jxz);
                
                totaljxz+=jxz;
                
                int ywc = 0;
                String unitKey2 = third_category_id+"-2";
                if(map2.containsKey(unitKey2)) {
                    ywc = ConvertUtil.obj2Int(map2.get(unitKey2));
                }
                map.put("ywc", ywc);
                
                totalywc += ywc;
                
                
                int ygb = 0;
                String unitKey3 = third_category_id+"-3";
                if(map2.containsKey(unitKey3)) {
                    ygb = ConvertUtil.obj2Int(map2.get(unitKey3));
                }
                map.put("ygb", ygb);
                
                totalygb += ygb;
                
                int ypj = 0;
                String unitKey4 = third_category_id+"-4";
                if(map2.containsKey(unitKey4)) {
                    ypj = ConvertUtil.obj2Int(map2.get(unitKey4));
                }
                map.put("ypj", ypj);
                
                totalypj += ypj;
                
                int ygq = 0;
                String unitKey6 = third_category_id+"-6";
                if(map2.containsKey(unitKey6)) {
                    ygq = ConvertUtil.obj2Int(map2.get(unitKey6));
                }
                map.put("ygq", ygq);
                
                totalygq += ygq;
                
            }
        }
        
        resultMap.put("reports", list1);
        resultMap.put("totaljxz", totaljxz);
        resultMap.put("totalywc", totalywc);
        resultMap.put("totalygb", totalygb);
        resultMap.put("totalypj", totalypj);
        resultMap.put("totalygq", totalygq);
        resultMap.put("total", total);
        System.out.println(JsonUtil.map2Json(resultMap));
        return resultMap;
    }
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    @Override
    public Map queryCloseReport(String cusId,String beginDay,String endDay) {
        
        Map paramMap = new HashMap();
        paramMap.put("cusId", cusId);
        paramMap.put("beginDay", beginDay+"000000");
        paramMap.put("endDay", endDay+"666666");
        
        List<String> lebalList = new ArrayList<String>();  
        List<List<String>> dataList = new ArrayList<List<String>>();  
        Map extendMap = new HashMap();
        
        StringBuilder builder = new StringBuilder();
        builder.append(" select mtotal.THIRD_CATEGORY_ID,mtotal.THIRD_CATEGORY_NAME,mtotal.FIRST_CATEGORY_NAME,mtotal.SECOND_CATEGORY_NAME,total_num,IFNULL(close_num,0) close_num from  ");
        builder.append(" (select THIRD_CATEGORY_NAME,SECOND_CATEGORY_NAME,FIRST_CATEGORY_NAME,count(id) total_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT where CUSTOMER_ID=:cusId and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay  group by THIRD_CATEGORY_ID,THIRD_CATEGORY_NAME,\n" +
                "        SECOND_CATEGORY_NAME,\n" +
                "        FIRST_CATEGORY_NAME) mtotal left join  ");
        builder.append(" (select count(i.id) close_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT i,workflow_base b where i.FLOW_ID=b.ID and b.WFSTATE=3 and i.CUSTOMER_ID=:cusId and i.CREATE_TIME>=:beginDay and i.CREATE_TIME<=:endDay group by i.THIRD_CATEGORY_ID) mclose  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mclose.THIRD_CATEGORY_ID ");
        List<Map> baseList = baseDao.queryForList(builder.toString(),paramMap);
        
        //long startTime = System.currentTimeMillis();
        //查询数据字典
        List<Map> resolveList = dataDictionaryService.getDataDictionaryByCategoryKey("RESOLVE_WAY");
        List<Map> closeList = dataDictionaryService.getDataDictionaryByCategoryKey("CLOSE_REASON");
        //long endTime = System.currentTimeMillis();
        //System.out.println("程序运行时间:"+(endTime-startTime)+"ms");
        //查询解决方式,关闭原因
        builder.setLength(0);
        builder.append(" select count(id) m_num,CONCAT(THIRD_CATEGORY_ID,'_',RESOLVE_TYPE_ID) m_key from SC_WORKFLOW_INCIDENT   ");
        builder.append(" where CUSTOMER_ID=:cusId and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay group by RESOLVE_TYPE_ID,THIRD_CATEGORY_ID   ");
        List<Map> extendList = baseDao.queryForList(builder.toString(),paramMap);
        if(extendList!=null&&extendList.size()>0){
            for(Map extend : extendList){
                extendMap.put(extend.get("m_key"), extend.get("m_num"));
            }
        }
        
        //组织表头
        lebalList.add("服务目录");
        lebalList.add("事件数");
        lebalList.add("已取消事件");
        for(Map map:resolveList){
            lebalList.add(map.get("DATAVALUE").toString());
        }
        for(Map map:closeList){
            lebalList.add(map.get("DATAVALUE").toString());
        }
        //组织数据
        if(baseList!=null&&baseList.size()>0){
            for(Map base:baseList){
                List<String> tempList = new ArrayList<String>();
                tempList.add(ConvertUtil.obj2StrBlank(base.get("FIRST_CATEGORY_NAME"))+"->"+ConvertUtil.obj2StrBlank(base.get("SECOND_CATEGORY_NAME"))+"->"+ConvertUtil.obj2StrBlank(base.get("THIRD_CATEGORY_NAME")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("total_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("close_num")));
                //组织解决方式数据
                for(Map map:resolveList){
                    String key = base.get("THIRD_CATEGORY_ID")+"_"+map.get("DATAKEY").toString();
                    if(extendMap.get(key)!=null){
                        tempList.add(ConvertUtil.obj2StrBlank(extendMap.get(key)));
                    }else{
                        tempList.add("0");
                    }
                }
                //组织关闭原因数据
                for(Map map:closeList){
                    String key = base.get("THIRD_CATEGORY_ID")+"_"+map.get("DATAKEY").toString();
                    if(extendMap.get(key)!=null){
                        tempList.add(ConvertUtil.obj2StrBlank(extendMap.get(key)));
                    }else{
                        tempList.add("0");
                    }
                }
                dataList.add(tempList);
            }
        }
        Map res = new HashMap();
        res.put("lebalList",lebalList);
        res.put("dataList",dataList);
        return res;
    }
 
    @Override
    public Map queryTypeReport(String cusId,String beginDay,String endDay) {
        
        Map paramMap = new HashMap();
        paramMap.put("cusId", cusId);
        paramMap.put("beginDay", beginDay+"000000");
        paramMap.put("endDay", endDay+"666666");
        
        List<String> lebalList = new ArrayList<String>();  
        List<List<String>> dataList = new ArrayList<List<String>>();  
        Map extendMap = new HashMap();
        
        StringBuilder builder = new StringBuilder();
        builder.append(" select mtotal.THIRD_CATEGORY_ID,mtotal.THIRD_CATEGORY_NAME,mtotal.FIRST_CATEGORY_NAME,mtotal.SECOND_CATEGORY_NAME,total_num from  ");
        builder.append(" (select THIRD_CATEGORY_NAME,SECOND_CATEGORY_NAME,FIRST_CATEGORY_NAME,count(id) total_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT where state!=10 and  CUSTOMER_ID=:cusId and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay  group by THIRD_CATEGORY_ID,THIRD_CATEGORY_NAME,SECOND_CATEGORY_NAME,FIRST_CATEGORY_NAME) mtotal   ");
        List<Map> baseList = baseDao.queryForList(builder.toString(),paramMap);
        
        //查询数据字典
        List<Map> typeList = dataDictionaryService.getDataDictionaryByCategoryKey("INCIDENT_TYPE");
        //查询解决方式,关闭原因
        builder.setLength(0);
        builder.append(" select count(id) m_num,CONCAT(THIRD_CATEGORY_ID,'_',TYPE_ID) m_key,THIRD_CATEGORY_NAME,THIRD_CATEGORY_ID,TYPE_ID from SC_WORKFLOW_INCIDENT   ");
        builder.append(" where CUSTOMER_ID=:cusId and state!=10 and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay  group by TYPE_ID,THIRD_CATEGORY_ID,CONCAT(THIRD_CATEGORY_ID,'_',TYPE_ID),THIRD_CATEGORY_NAME   ");
        List<Map> extendList = baseDao.queryForList(builder.toString(),paramMap);
        if(extendList!=null&&extendList.size()>0){
            for(Map extend : extendList){
                extendMap.put(extend.get("m_key"), extend.get("m_num"));
            }
        }
        
        //组织表头
        lebalList.add("服务目录");
        for(Map map:typeList){
            lebalList.add(map.get("DATAVALUE").toString());
        }
        lebalList.add("合计");
        //组织数据
        if(baseList!=null&&baseList.size()>0){
            for(Map base:baseList){
                List<String> tempList = new ArrayList<String>();
                tempList.add(ConvertUtil.obj2StrBlank(base.get("FIRST_CATEGORY_NAME"))+"->"+ConvertUtil.obj2StrBlank(base.get("SECOND_CATEGORY_NAME"))+"->"+ConvertUtil.obj2StrBlank(base.get("THIRD_CATEGORY_NAME")));
                for(Map map:typeList){
                    String key = base.get("THIRD_CATEGORY_ID")+"_"+map.get("DATAKEY").toString();
                    if(extendMap.get(key)!=null){
                        tempList.add(ConvertUtil.obj2StrBlank(extendMap.get(key)));
                    }else{
                        tempList.add("0");
                    }
                }
                dataList.add(tempList);
            }
        }
        Map res = new HashMap();
        res.put("lebalList",lebalList);
        res.put("dataList",dataList);
        return res;
    }
 
    @Override
    public Map queryDealTimeReport(String cusId,String beginDay,String endDay) {
        
        Map paramMap = new HashMap();
        paramMap.put("cusId", cusId);
        paramMap.put("beginDay", beginDay+"000000");
        paramMap.put("endDay", endDay+"666666");
        
        List<String> lebalList = new ArrayList<String>();  
        List<List<String>> dataList = new ArrayList<List<String>>();  
        Map extendMap = new HashMap();
        
        StringBuilder builder = new StringBuilder();
        builder.append(" select mtotal.THIRD_CATEGORY_NAME,mtotal.FIRST_CATEGORY_NAME,mtotal.SECOND_CATEGORY_NAME,total_num,IFNULL(finish_num,0) finish_num,truncate(ifnull(avg_time,0)*3600*1000,0) avg_time,truncate(ifnull(sum_time,0)*3600*1000,0) sum_time from  ");
        builder.append(" (select AVG(a.DEAL_USE_TIME) avg_time,sum(a.DEAL_USE_TIME) sum_time,b.CATEGORY_NAME THIRD_CATEGORY_NAME,a.SECOND_CATEGORY_NAME,a.FIRST_CATEGORY_NAME,count(a.id) total_num,a.THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT a,SC_SERVCE_CATEGORY b where a.state!=10 and  a.CUSTOMER_ID=:cusId and a.CREATE_TIME>=:beginDay and a.CREATE_TIME<=:endDay and a.THIRD_CATEGORY_ID=b.id  group by a.THIRD_CATEGORY_ID,b.CATEGORY_NAME ,a.SECOND_CATEGORY_NAME,a.FIRST_CATEGORY_NAME) mtotal left join  ");
        builder.append(" (select THIRD_CATEGORY_NAME,count(i.id) finish_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT i,workflow_base b where i.FLOW_ID=b.ID and (b.WFSTATE=2 or b.WFSTATE=4)  and i.CUSTOMER_ID=:cusId and i.CREATE_TIME>=:beginDay and i.CREATE_TIME<=:endDay group by i.THIRD_CATEGORY_ID,i.THIRD_CATEGORY_NAME) mfinish  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mfinish.THIRD_CATEGORY_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){
                DecimalFormat    df   = new DecimalFormat("######0.00");   
                List<String> tempList = new ArrayList<String>();
                tempList.add(ConvertUtil.obj2StrBlank(base.get("FIRST_CATEGORY_NAME"))+"->"+ConvertUtil.obj2StrBlank(base.get("SECOND_CATEGORY_NAME"))+"->"+ConvertUtil.obj2StrBlank(base.get("THIRD_CATEGORY_NAME")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("total_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("finish_num")));
                tempList.add(ConvertUtil.obj2StrBlank(DateUtil.secToTime(Math.round((Double)base.get("sum_time")))));
                tempList.add(ConvertUtil.obj2StrBlank(DateUtil.secToTime(Math.round((Double)base.get("avg_time")))));
                dataList.add(tempList);
            }
        }
        Map res = new HashMap();
        res.put("lebalList",lebalList);
        res.put("dataList",dataList);
        return res;
    }
 
    @Override
    public Map queryDealSituationReport(String cusId,String beginDay,String endDay) {
        
        Map paramMap = new HashMap();
        paramMap.put("cusId", cusId);
        paramMap.put("beginDay", beginDay+"000000");
        paramMap.put("endDay", endDay+"666666");
        paramMap.put("nodeTemplateId", Constants.YXCL);
        
        List<String> lebalList = new ArrayList<String>();  
        List<List<String>> dataList = new ArrayList<List<String>>();  
        Map extendMap = new HashMap();
        
        StringBuilder builder = new StringBuilder();
        builder.append(" select mtotal.THIRD_CATEGORY_NAME,mtotal.FIRST_CATEGORY_NAME,mtotal.SECOND_CATEGORY_NAME,total_num,IFNULL(answer_num,0) answer_num,IFNULL(activi_num,0) activi_num,IFNULL(finish_num,0) finish_num,IFNULL(timeout_num,0) timeout_num,  ");
        builder.append(" IFNULL(pri_num,0) pri_num,IFNULL(ques_num,0) ques_num,IFNULL(avg_time,0) avg_time,truncate(IFNULL(first_num, 0)*100/total_num,2) first_rate,truncate((IFNULL(total_num,0)-IFNULL(timeout_num,0))*100/IFNULL(total_num,0),2) ontime_rate  from  ");
        builder.append(" (select THIRD_CATEGORY_NAME,SECOND_CATEGORY_NAME,FIRST_CATEGORY_NAME,count(id) total_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT where state!=10 and CUSTOMER_ID=:cusId and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay  group by THIRD_CATEGORY_ID,THIRD_CATEGORY_NAME,SECOND_CATEGORY_NAME,FIRST_CATEGORY_NAME) mtotal   ");
        builder.append(" left join (select count(i.id) answer_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT i,workflow_base b,workflow_node n where i.FLOW_ID=b.ID and b.CURRENT_NODE_ID=n.ID and n.FLOWSTATE=1 and i.CUSTOMER_ID=:cusId and i.CREATE_TIME>=:beginDay and i.CREATE_TIME<=:endDay group by i.THIRD_CATEGORY_ID) manswer  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = manswer.THIRD_CATEGORY_ID ");
        builder.append(" left join (select count(i.id) activi_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT i,workflow_base b where i.FLOW_ID=b.ID and b.WFSTATE=1 and i.CUSTOMER_ID=:cusId and i.CREATE_TIME>=:beginDay and i.CREATE_TIME<=:endDay group by i.THIRD_CATEGORY_ID) mactivi  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mactivi.THIRD_CATEGORY_ID ");
        builder.append(" left join (select count(i.id) finish_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT i,workflow_base b where i.FLOW_ID=b.ID and b.WFSTATE in (2,4) and i.CUSTOMER_ID=:cusId and i.CREATE_TIME>=:beginDay and i.CREATE_TIME<=:endDay group by i.THIRD_CATEGORY_ID) mfinish  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mfinish.THIRD_CATEGORY_ID ");
        builder.append(" left join (select count(id) timeout_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT where (ANSWER_TIMEOUT=1 or DEAL_TIMEOUT=1) and CUSTOMER_ID=:cusId and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay group by THIRD_CATEGORY_ID) mtimeout  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mtimeout.THIRD_CATEGORY_ID ");
        builder.append(" left join (select count(id) pri_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT where SLA_NAME='LEVEL1' and CUSTOMER_ID=:cusId and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay group by THIRD_CATEGORY_ID) mpri  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mpri.THIRD_CATEGORY_ID ");
        builder.append(" left join (select count(id) ques_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT where QUESTIONID is not null and CUSTOMER_ID=:cusId and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay group by THIRD_CATEGORY_ID) mques  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mques.THIRD_CATEGORY_ID ");
        builder.append(" left join (select truncate(avg(DEAL_USE_TIME)*3600*1000,0) avg_time,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT where CUSTOMER_ID=:cusId and state!=10 and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay group by THIRD_CATEGORY_ID) mdeal  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mdeal.THIRD_CATEGORY_ID ");
        builder.append(" left join (select count(i.id) first_num,THIRD_CATEGORY_ID from SC_WORKFLOW_INCIDENT i,workflow_base b,workflow_node n where i.FLOW_ID=b.ID and b.CURRENT_NODE_ID=n.ID and (b.WFSTATE=2 or b.WFSTATE=4) and n.NODE_TEMPLATE_ID = :nodeTemplateId and i.CUSTOMER_ID=:cusId and i.CREATE_TIME>=:beginDay and i.CREATE_TIME<=:endDay group by i.THIRD_CATEGORY_ID) mfirst  ");
        builder.append(" on  mtotal.THIRD_CATEGORY_ID = mfirst.THIRD_CATEGORY_ID ");
        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("平均处理时长");
        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("FIRST_CATEGORY_NAME"))+"->"+ConvertUtil.obj2StrBlank(base.get("SECOND_CATEGORY_NAME"))+"->"+ConvertUtil.obj2StrBlank(base.get("THIRD_CATEGORY_NAME")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("total_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("answer_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("activi_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("finish_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("timeout_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("pri_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("ques_num")));
                
                tempList.add(DateUtil.secToTime(Math.round((Double)base.get("avg_time"))));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("first_rate"))+"%");
                tempList.add(ConvertUtil.obj2StrBlank(base.get("ontime_rate"))+"%");
                dataList.add(tempList);
            }
        }
        Map res = new HashMap();
        res.put("lebalList",lebalList);
        res.put("dataList",dataList);
        return res;
    }
 
    @Override
    public Map queryEngineerDealReport(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+"000000");
        paramMap.put("endDay", endDay+"666666");
        paramMap.put("nodeTemplateId", Constants.YXCL);
        
        List<String> lebalList = new ArrayList<String>();  
        List<List<String>> dataList = new ArrayList<List<String>>();  
        Map extendMap = new HashMap();
        
        StringBuilder builder = new StringBuilder();
        
        builder.append(" select mtotal.user_name,IFNULL(mactivi.num ,0)activi_num,IFNULL(mfinish.num ,0) finish_num,IFNULL(msend.num ,0) send_num, ");
        builder.append(" IFNULL(truncate(mfinish.num*100/mtotal.num,2),0) deal_rate,IFNULL(mtime.deal_time,0) deal_time,IFNULL(mscore.score ,0) score from  ");
        builder.append(" ( ");
        builder.append("     select count(b.ID) num,user_name,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        builder.append("         SELECT FLOWID,current_dealer_id user_id,current_dealer_name user_name ");
        builder.append("         FROM workflow_node,( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 group by u.USER_ID ");
        builder.append("         ) u WHERE current_dealer_id  = u.USER_ID GROUP BY USER_ID,FLOWID ");
        builder.append("     ) t where b.ID = t.FLOWID  and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mtotal left join  ");
        builder.append(" ( ");
        builder.append("     select count(b.ID) num,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 group by u.USER_ID ");
        builder.append("     ) t where b.CURRENT_DEALER_ID = t.USER_ID and b.WFSTATE=1 and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mactivi on mtotal.user_id = mactivi.user_id left join  ");
        builder.append(" ( ");
        builder.append("     select count(b.ID) num,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 group by u.USER_ID ");
        builder.append("     ) t where b.CURRENT_DEALER_ID = t.USER_ID and (b.WFSTATE=2 or b.WFSTATE=4) and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mfinish on mtotal.user_id = mfinish.user_id left join  ");
        builder.append(" ( ");
        builder.append("     select truncate(avg(TIMESTAMPDIFF(SECOND,b.CREATETIME,b.ENDTIME)*1000),0) deal_time,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 group by u.USER_ID ");
        builder.append("     ) t where b.CURRENT_DEALER_ID = t.USER_ID and (b.WFSTATE=2 or b.WFSTATE=4) and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mtime on mtotal.user_id = mtime.user_id left join  ");
        builder.append(" ( ");
        builder.append("     select truncate(avg(SCORE),2) score,i.user_id from AUDITING_SATIS_INFO i,(  ");
        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 CUSTOMER_ID = :cusId  and g.state=1 and u.state=1 group by u.USER_ID ");
        builder.append("     ) u where i.USER_ID=u.USER_ID ");
        builder.append("     and BUS_TYPE=8 and CREATE_TIME>=:beginDay and CREATE_TIME<=:endDay and CUSTOMER_ID=:cusId ");
        builder.append(" ) mscore on mtotal.user_id = mscore.user_id left join  ");
        builder.append(" ( ");
        builder.append("     select count(b.ID) num,user_name,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        builder.append("         SELECT FLOWID,current_dealer_id user_id,current_dealer_name user_name ");
        builder.append("         FROM workflow_node,( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 group by u.USER_ID ");
        builder.append("         ) u WHERE current_dealer_id  = u.USER_ID GROUP BY USER_ID,FLOWID ");
        builder.append("     ) t where b.ID = t.FLOWID and b.CURRENT_DEALER_ID<>t.user_id and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) msend on mtotal.user_id = msend.user_id ");
        List<Map> baseList = baseDao.queryForList(builder.toString(),paramMap);
        
        //组织表头
        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>();
                tempList.add(ConvertUtil.obj2StrBlank(base.get("user_name")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("activi_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("finish_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("send_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("deal_rate"))+"%");
                tempList.add(DateUtil.secToTime(ConvertUtil.obj2Long(base.get("deal_time"))));
                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 queryServiceDealReport(HttpServletRequest request) {
        
        String cusId = request.getParameter("cusId");
        String beginDay = request.getParameter("beginDay");
        String endDay = request.getParameter("endDay");
        
        //String deskId = Constants.getDeskTop(Constants.ZFWT_DESK);
        String deskId = "";
        Map paramMap = new HashMap();
        paramMap.put("cusId", cusId);
        paramMap.put("cusId", cusId);
        paramMap.put("deskId", deskId);
        paramMap.put("beginDay", beginDay+"000000");
        paramMap.put("endDay", endDay+"666666");
        
        List<String> lebalList = new ArrayList<String>();  
        List<List<String>> dataList = new ArrayList<List<String>>();  
        Map extendMap = new HashMap();
        
        StringBuilder builder = new StringBuilder();
        
        builder.append(" select mtotal.user_name,IFNULL(create_num ,0) create_num,IFNULL(finish_num ,0) finish_num,truncate(IFNULL(finish_num ,0)*100/total_num,2) deal_rate, ");
        builder.append(" IFNULL(forward_num ,0) forward_num,IFNULL(repeat_num,0) repeat_num,IFNULL(error_num,0) error_num,IFNULL(invest_num ,0) invest_num from  ");
        builder.append(" ( ");
        builder.append("     select count(b.ID) total_num,user_name,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        builder.append("         SELECT FLOWID,current_dealer_id user_id,current_dealer_name user_name ");
        builder.append("         FROM workflow_node,( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 and g.GROUP_TYPE=1 group by u.USER_ID ");
        builder.append("             union select id user_id from gg_user where DESKID = :deskId and ZT=1  ");
        builder.append("             union select USER_ID from SC_PARTNER_CUSTOMER_SERVICE where DEL_FLAG = 1 and CUSTOMER_ID = :cusId  ");
        builder.append("         ) u WHERE current_dealer_id  = u.USER_ID GROUP BY USER_ID,FLOWID ");
        builder.append("     ) t where b.ID = t.FLOWID and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mtotal left join  ");
        //创建事件数
        builder.append(" ( ");
        builder.append("     select count(b.ID) create_num,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 and g.GROUP_TYPE=1 group by u.USER_ID ");
        builder.append("         union select id user_id from gg_user where DESKID = :deskId and ZT=1  ");
        builder.append("         union select USER_ID from SC_PARTNER_CUSTOMER_SERVICE where DEL_FLAG = 1 and CUSTOMER_ID = :cusId  ");
        builder.append("     ) t where b.CREATERID = t.USER_ID and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mcreate on mtotal.user_id = mcreate.user_id left join  ");
        //完成事件数
        builder.append(" ( ");
        builder.append("     select count(b.ID) finish_num,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 and g.GROUP_TYPE=1  group by u.USER_ID ");
        builder.append("         union select id user_id from gg_user where DESKID = :deskId and ZT=1  ");
        builder.append("         union select USER_ID from SC_PARTNER_CUSTOMER_SERVICE where DEL_FLAG = 1 and CUSTOMER_ID = :cusId  ");
        builder.append("     ) t where b.CURRENT_DEALER_ID = t.USER_ID and (b.WFSTATE=2 or b.WFSTATE=4)   and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mfinish on mtotal.user_id = mfinish.user_id left join  ");
        //转发数
        builder.append(" ( ");
        builder.append("     select count(b.ID) forward_num,user_id from workflow_base b ,  ");
        builder.append("     ( ");
        builder.append("         SELECT FLOWID,current_dealer_id user_id,current_dealer_name user_name ");
        builder.append("         FROM workflow_node,( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 and g.GROUP_TYPE=1  group by u.USER_ID ");
        builder.append("             union select id user_id from gg_user where DESKID = :deskId and ZT=1  ");
        builder.append("             union select USER_ID from SC_PARTNER_CUSTOMER_SERVICE where DEL_FLAG = 1 and CUSTOMER_ID = :cusId  ");
        builder.append("         ) u WHERE current_dealer_id  = u.USER_ID GROUP BY USER_ID,FLOWID ");
        builder.append("     ) t where b.ID = t.FLOWID and b.CURRENT_DEALER_ID<>t.user_id and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mforward on mtotal.user_id = mforward.user_id left join  ");
        //重复事件数
        builder.append(" ( ");
        builder.append("     select count(b.ID) repeat_num,user_id from workflow_base b , SC_WORKFLOW_INCIDENT i, ");
        builder.append("     ( ");
        builder.append("         SELECT FLOWID,current_dealer_id user_id,current_dealer_name user_name ");
        builder.append("         FROM workflow_node,( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 and g.GROUP_TYPE=1  group by u.USER_ID ");
        builder.append("             union select id user_id from gg_user where DESKID = :deskId and ZT=1  ");
        builder.append("             union select USER_ID from SC_PARTNER_CUSTOMER_SERVICE where DEL_FLAG = 1 and CUSTOMER_ID = :cusId  ");
        builder.append("         ) u WHERE current_dealer_id  = u.USER_ID GROUP BY USER_ID,FLOWID ");
        builder.append("     ) t where b.ID = t.FLOWID and b.id=i.FLOW_ID and i.RESOLVE_TYPE_ID ='SJCF' and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) mrepeat on mtotal.user_id = mrepeat.user_id left join  ");    
        //消失,误报
        builder.append(" ( ");
        builder.append("     select count(b.ID) error_num,user_id from workflow_base b , SC_WORKFLOW_INCIDENT i, ");
        builder.append("     ( ");
        builder.append("         SELECT FLOWID,current_dealer_id user_id,current_dealer_name user_name ");
        builder.append("         FROM workflow_node,( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 and g.GROUP_TYPE=1  group by u.USER_ID ");
        builder.append("             union select id user_id from gg_user where DESKID = :deskId and ZT=1  ");
        builder.append("             union select USER_ID from SC_PARTNER_CUSTOMER_SERVICE where DEL_FLAG = 1 and CUSTOMER_ID = :cusId  ");
        builder.append("         ) u WHERE current_dealer_id  = u.USER_ID GROUP BY USER_ID,FLOWID ");
        builder.append("     ) t where b.ID = t.FLOWID and b.id=i.FLOW_ID and (i.RESOLVE_TYPE_ID ='XS' or i.RESOLVE_TYPE_ID ='WB') and b.BUSINESSTYPE=8 and b.CUSTOMER_ID=:cusId and b.CREATETIME>=:beginDay and b.CREATETIME<=:endDay GROUP BY t.user_id ");
        builder.append(" ) merror on mtotal.user_id = merror.user_id left join  ");    
        //调查
        builder.append(" ( ");
        builder.append("     select count(s.id) invest_num,u.user_id from AUDITING_SATIS_INFO s,( ");
        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 CUSTOMER_ID = :cusId and g.state=1 and u.state=1 and g.GROUP_TYPE=1  group by u.USER_ID ");
        builder.append("             union select id user_id from gg_user where DESKID = :deskId and ZT=1  ");
        builder.append("             union select USER_ID from SC_PARTNER_CUSTOMER_SERVICE where DEL_FLAG = 1 and CUSTOMER_ID = :cusId  ");
        builder.append("     ) u where s.INVEST_USER_ID =u.USER_ID and CREATE_TIME>:beginDay and CREATE_TIME<:endDay and BUS_TYPE=8 and CUSTOMER_ID=:cusId ");
        builder.append(" ) minvest on mtotal.user_id = minvest.user_id  ");
        
        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>();
                tempList.add(ConvertUtil.obj2StrBlank(base.get("user_name")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("create_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("finish_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("deal_rate"))+"%");
                tempList.add(ConvertUtil.obj2StrBlank(base.get("forward_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("repeat_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("error_num")));
                tempList.add(ConvertUtil.obj2StrBlank(base.get("invest_num")));
                dataList.add(tempList);
            }
        }
        Map res = new HashMap();
        res.put("lebalList",lebalList);
        res.put("dataList",dataList);
        return res;
    }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /**
     * 将数据字典转化成DataKeyMap
     * @author chenlong
     * @param dicList
     * @return
     */
    private Map dicListToDataKeyMap(List<Map> dicList){
        Map dataKeyMap = new HashMap();
        for(Map dic:dicList){
            dataKeyMap.put(ConvertUtil.obj2StrBlank(dic.get("DATAKEY")),ConvertUtil.obj2StrBlank(dic.get("DATAVALUE")));
        }
        return dataKeyMap;
    }
    
    /**
     * 格式化数据字典
     * @author chenlong
     * @param dicList
     */
    private void formatDicList(List<Map> dicList){
        for(Map dic:dicList){
            dic.put("key", ConvertUtil.obj2StrBlank(dic.get("DATAKEY")));
            dic.put("val", ConvertUtil.obj2StrBlank(dic.get("DATAVALUE")));
        }
    }
    
    
    
    /**
     * 组织时间查询条件
     * @author chenlong
     * @param frequency
     * @param sql
     * @param colName
     */
    private void getDateWhereSql(String frequency,StringBuilder sql,String colName){
        if(frequency.equals("day")||frequency==null){
            sql.append(" and substr("+colName+"||'',1,8)>=:startDate and substr("+colName+"||'',1,8)<=:endDate  ");
        }else if(frequency.equals("month")){
            sql.append(" and substr("+colName+"||'',1,6)>=:startDate and substr("+colName+"||'',1,6)<=:endDate  ");
        }
    }
 
    @Override
    public Map incidentTypePie(String frequency,String cusId,String startDate,String endDate) {
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        List categoryList = dataDictionaryService.getDataDictionaryByCategoryKey(Constants.INCIDENT_TYPE);
        formatDicList(categoryList);
        
        StringBuilder sql = new StringBuilder();
        sql.append(" select count(id) val,type_id category  from sc_workflow_incident where 1=1 AND STATE!=10");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by type_id ");
        List datas = baseDao.queryForList(sql.toString(),param);
        return ChartUtil.createHchartPieMap(datas,categoryList,"数量");
    }
    
    @Override
    public Map incidentSourcePie(String frequency, String cusId,String startDate, String endDate) {
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        List categoryList = dataDictionaryService.getDataDictionaryByCategoryKey(Constants.INCIDENT_SOURCE);
        formatDicList(categoryList);
        
        StringBuilder sql = new StringBuilder();
        sql.append(" select count(id) val,source_id category  from sc_workflow_incident where state!=10 ");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by source_id ");
        List datas = baseDao.queryForList(sql.toString(),param);
        return ChartUtil.createHchartPieMap(datas,categoryList,"数量");
    }
 
    @Override
    public Map incidentCloseCol(String frequency, String cusId,String startDate, String endDate) {
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        List dicList = dataDictionaryService.getDataDictionaryByCategoryKey(Constants.CLOSE_REASON);
        Map dataKeyMap = dicListToDataKeyMap(dicList);
        
        StringBuilder sql = new StringBuilder();
        sql.append(" select count(id) val,resolve_type_id datakey,1 as category  from sc_workflow_incident where resolve_type_id is not null ");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by resolve_type_id ");
        List datas = baseDao.queryForList(sql.toString(),param);
        
        Map categoryMap = new HashMap();
        categoryMap.put("key", "1");
        categoryMap.put("val", "数量");
        List<Map> categoryList = new ArrayList<Map>();
        categoryList.add(categoryMap);
        return ChartUtil.createHchartLineMap(datas,categoryList,dataKeyMap,0.0);
    }
 
    @Override
    public Map incidentPriPie(String frequency, String cusId, String startDate,String endDate) {
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        List categoryList = dataDictionaryService.getDataDictionaryByCategoryKey(Constants.INCIDENT_EVENT_PRI);
        formatDicList(categoryList);
        
        StringBuilder sql = new StringBuilder();
        sql.append(" select count(id) val,priority_id category  from sc_workflow_incident where state!=10 ");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by priority_id ");
        List datas = baseDao.queryForList(sql.toString(),param);
        return ChartUtil.createHchartPieMap(datas,categoryList,"数量");
    }
 
    @Override
    public Map incidentInfluenceCol(String frequency, String cusId,String startDate, String endDate) {
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        List dicList = dataDictionaryService.getDataDictionaryByCategoryKey(Constants.EVENT_EFFECT_DG);
        Map dataKeyMap = dicListToDataKeyMap(dicList);
        
        StringBuilder sql = new StringBuilder();
        sql.append(" select count(id) val,influence_id datakey,1 as category  from sc_workflow_incident where state!=10");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by influence_id ");
        List datas = baseDao.queryForList(sql.toString(),param);
        
        Map categoryMap = new HashMap();
        categoryMap.put("key", "1");
        categoryMap.put("val", "数量");
        List<Map> categoryList = new ArrayList<Map>();
        categoryList.add(categoryMap);
        return ChartUtil.createHchartLineMap(datas,categoryList,dataKeyMap,0.0);
    }
    
    
    @Override
    public Map incidentLvPie(String frequency, String cusId, String startDate,String endDate) {
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        StringBuilder sql = new StringBuilder();
        sql.append(" select id as key,level_name as val from sc_sla where state=1 order by serial asc");
        List<Map> categoryList = baseDao.queryForList(sql.toString(),param); 
        
        sql.setLength(0);
        sql.append(" select count(id) val,sla_id category  from sc_workflow_incident where state!=10 ");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by sla_id ");
        List datas = baseDao.queryForList(sql.toString(),param);
        return ChartUtil.createHchartPieMap(datas,categoryList,"数量");
    }
 
    @Override
    public Map incidentResponsePie(String frequency, String cusId,String startDate, String endDate) {
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        List<Map> categoryList = new ArrayList<Map>();
        for(int i=1;i<=2;i++){
            Map category = new HashMap();
            category.put("key", String.valueOf(i));
            if(i==1){
                category.put("val", "响应超时");
            }else{
                category.put("val", "响应及时");
            }
            categoryList.add(category);
        }
        
        StringBuilder sql = new StringBuilder();
        sql.append(" select count(id) val,answer_timeout category  from sc_workflow_incident where state!=10 and answer_timeout is not null ");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by answer_timeout ");
        List datas = baseDao.queryForList(sql.toString(),param);
        return ChartUtil.createHchartPieMap(datas,categoryList,"数量");
    }
 
    @Override
    public Map incidentDealPie(String frequency, String cusId,String startDate, String endDate) {
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        
        List<Map> categoryList = new ArrayList<Map>();
        for(int i=1;i<=2;i++){
            Map category = new HashMap();
            category.put("key", String.valueOf(i));
            if(i==1){
                category.put("val", "处理超时");
            }else{
                category.put("val", "处理及时");
            }
            categoryList.add(category);
        }
        
        StringBuilder sql = new StringBuilder();
        sql.append(" select count(id) val,deal_timeout category  from sc_workflow_incident where state!=10 and deal_timeout is not null ");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by deal_timeout ");
        List datas = baseDao.queryForList(sql.toString(),param);
        return ChartUtil.createHchartPieMap(datas,categoryList,"数量");
    }
    
    @Override
    public Map incidentHappendTimeLine(String frequency, String cusId,String startDate, String endDate) {
        Map chartMap = new HashMap();
        SqlParameter param = new SqlParameter();
        param.addValue("cusId", cusId)
            .addValue("startDate", startDate)
            .addValue("endDate", endDate);
        StringBuilder sql = new StringBuilder();
        sql.append(" select to_number(substr(happen_time||'',9,2)) mhour,count(id) num from sc_workflow_incident c");
        sql.append(" where c.state!=10 and to_number(substr(happen_time||'',9,2))>=7  and to_number(substr(happen_time||'',9,2))<=18   ");
        if(StringUtil.isNotBlank(cusId)){
            sql.append(" and customer_id = :cusId ");
        }
        getDateWhereSql(frequency,sql,"create_time");
        sql.append(" group by to_number(substr(happen_time||'',9,2)) ");
        
        List<Map> list = baseDao.queryForList(sql.toString(),param);
        Map categoriesMap = new HashMap();
        categoriesMap.put("7:00-9:00", 0);
        categoriesMap.put("9:00-11:00", 0);
        categoriesMap.put("11:00-13:00", 0);
        categoriesMap.put("13:00-15:00", 0);
        categoriesMap.put("15:00-17:00", 0);
        categoriesMap.put("17:00-18:00", 0);
        //x轴
        List<String> categoriesList = new ArrayList<String>();
        categoriesList.add("7:00-9:00");
        categoriesList.add("9:00-11:00");
        categoriesList.add("11:00-13:00");
        categoriesList.add("13:00-15:00");
        categoriesList.add("15:00-17:00");
        categoriesList.add("17:00-18:00");
        
        if(list!=null&&list.size()>0){
            for(Map map:list){
                String hour = map.get("mhour").toString();
                if(hour.equals("7")||hour.equals("8")){
                    Integer sum = Integer.valueOf(categoriesMap.get("7:00-9:00").toString())+Integer.valueOf(map.get("num").toString());
                    categoriesMap.put("7:00-9:00", sum);
                }else if(hour.equals("9")||hour.equals("10")){
                    Integer sum = Integer.valueOf(categoriesMap.get("9:00-11:00").toString())+Integer.valueOf(map.get("num").toString());
                    categoriesMap.put("9:00-11:00", sum);
                }else if(hour.equals("11")||hour.equals("12")){
                    Integer sum = Integer.valueOf(categoriesMap.get("11:00-13:00").toString())+Integer.valueOf(map.get("num").toString());
                    categoriesMap.put("11:00-13:00", sum);
                }else if(hour.equals("13")||hour.equals("14")){
                    Integer sum = Integer.valueOf(categoriesMap.get("13:00-15:00").toString())+Integer.valueOf(map.get("num").toString());
                    categoriesMap.put("13:00-15:00", sum);
                }else if(hour.equals("15")||hour.equals("16")){
                    Integer sum = Integer.valueOf(categoriesMap.get("15:00-17:00").toString())+Integer.valueOf(map.get("num").toString());
                    categoriesMap.put("15:00-17:00", sum);
                }else if(hour.equals("17")||hour.equals("18")){
                    Integer sum = Integer.valueOf(categoriesMap.get("17:00-18:00").toString())+Integer.valueOf(map.get("num").toString());
                    categoriesMap.put("17:00-18:00", sum);
                }
            }
            List dataList = new ArrayList();
            dataList.add(categoriesMap.get("7:00-9:00"));
            dataList.add(categoriesMap.get("9:00-11:00"));
            dataList.add(categoriesMap.get("11:00-13:00"));
            dataList.add(categoriesMap.get("13:00-15:00"));
            dataList.add(categoriesMap.get("15:00-17:00"));
            dataList.add(categoriesMap.get("17:00-18:00"));
            List seriesList = new ArrayList();
            Map seriesMap = new HashMap();
            seriesMap.put("name","数量");
            seriesMap.put("data",dataList);
            seriesList.add(seriesMap);
            chartMap.put("categories", categoriesList);
            chartMap.put("series", seriesList);
            chartMap.put("nodata", false);
        }else{
            chartMap.put("nodata", true);
        }
        return chartMap;
    }
 
    @Override
    public Map queryDealEngineerReportData(Map param) {
        String sql="SELECT id,ZSXM,IFNULL(b.score,0) score,IFNULL(b.num,0) mydnum,IFNULL(c.num,0) cynum,IFNULL(d.num,0) wcnum FROM" +
                " gg_user a " +
                "LEFT JOIN " +
                "( SELECT sum(SCORE) score,count(b.id) num,RESOLVE_USER_ID FROM order_satis_info a," +
                "workflow_base b,sc_workflow_incident c WHERE a.BUSINESS_ID = b.id ";
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("beginDay")))){
            sql+=" and to_number(substr(c.create_time||'',1,8))>=:beginDay ";
        }
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("endDay")))){
            sql+=" and to_number(substr(c.create_time||'',1,8))<=:endDay ";
        }
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("cusId")))){
            sql+=" and c.CUSTOMER_ID=:cusId ";
        }
        sql+=" AND c.id = b.BUSINESS_ID GROUP BY RESOLVE_USER_ID) b on a.id=b.RESOLVE_USER_ID " +
                "LEFT JOIN " +
                "(SELECT sum(d.num) num,d.CURRENT_DEALER_ID" +
                " from (SELECT count(*) num," +
                "c.CURRENT_DEALER_ID from sc_workflow_incident a,workflow_base b,workflow_node c" +
                " where a.id=b.BUSINESS_ID and b.id=c.FLOWID ";
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("beginDay")))){
            sql+=" and to_number(substr(a.create_time||'',1,8))>=:beginDay ";
        }
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("endDay")))){
            sql+=" and to_number(substr(a.create_time||'',1,8))<=:endDay ";
        }
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("cusId")))){
            sql+=" and a.CUSTOMER_ID=:cusId ";
        }
        sql+=" group by c.CURRENT_DEALER_ID,a.id) d" +
                " GROUP BY CURRENT_DEALER_ID) c" +
                " on c.CURRENT_DEALER_ID=a.id " +
                " LEFT JOIN " ;
        sql+=" (SELECT count(*) num,RESOLVE_USER_ID from sc_workflow_incident WHERE 1=1 ";
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("beginDay")))){
 
            sql+=" and to_number(substr(create_time||'',1,8))>=:beginDay ";
        }
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("endDay")))){
            sql+=" and to_number(substr(create_time||'',1,8))<=:endDay ";
        }
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("cusId")))){
            sql+=" and CUSTOMER_ID=:cusId ";
        }
        sql+=" GROUP BY RESOLVE_USER_ID) d " +
                "on a.id=d.RESOLVE_USER_ID" +
                " WHERE a.zt = 1 ";
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("userName")))){
            param.put("userName", "%"+ConvertUtil.obj2Str(param.get("userName"))+"%");
            sql+=" and a.zsxm like :userName ";
        }
        List<Map> userList=baseDao.queryForList(sql, param);
        sql="SELECT *,0 num from sc_sla where state=1 ORDER BY SERIAL";
        List<Map> slaList=baseDao.queryForList(sql);
        if(userList.size()>0){
            for(Map ma:userList){
                ma.put("slaList", slaList);
            }
        }
        if(userList.size()>0){
            sql="SELECT RESOLVE_USER_ID,SLA_ID,COUNT(a.id) num from sc_workflow_incident a," +
                    "workflow_base b where a.id=b.BUSINESS_ID and b.WFSTATE in(2,4) ";
            if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("beginDay")))){
                sql+=" and to_number(substr(a.create_time||'',1,8))>=:beginDay ";
            }
            if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("endDay")))){
                sql+=" and to_number(substr(a.create_time||'',1,8))<=:endDay ";
            }
            if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("cusId")))){
                sql+=" and a.CUSTOMER_ID=:cusId ";
            }
            sql+=" GROUP BY RESOLVE_USER_ID,SLA_ID,SLA_NAME order by SLA_NAME";
            List<Map> lvList=baseDao.queryForList(sql, param);
            if(lvList.size()>0){
                for(Map mapa:userList){
                    String userId=ConvertUtil.obj2Str(mapa.get("id"));
                    List<Map> list2=new LinkedList<Map>();
                    for(Map mm:slaList){
                        Map mn=new HashMap();
                        mn.putAll(mm);
                        list2.add(mn);
                    }
                    if(list2.size()>0){
                        for(Map mapb:list2){
                            String slaId=ConvertUtil.obj2Str(mapb.get("ID"));
                            for(Map mapc:lvList){
                                String RESOLVE_USER_ID=ConvertUtil.obj2Str(mapc.get("RESOLVE_USER_ID"));
                                String SLA_ID=ConvertUtil.obj2Str(mapc.get("SLA_ID"));
                                if(RESOLVE_USER_ID.equals(userId) && SLA_ID.equals(slaId)){
                                    mapb.put("num", mapc.get("num"));
                                }
                            }
                        }
                        mapa.put("slaList", list2);
                    }
                }
            }
            for(Map mape:userList){
                String score=ConvertUtil.obj2Str(mape.get("score"));
                String mydnum=ConvertUtil.obj2Str(mape.get("mydnum"));
                String cynum=ConvertUtil.obj2Str(mape.get("cynum"));
                String wcnum=ConvertUtil.obj2Str(mape.get("wcnum"));
                if(StringUtil.isEmpty(mydnum) || mydnum.equals("0") || StringUtil.isEmpty(score) || score.equals("0")){
                    mape.put("myf", "0.00");
                }else{
                    double myf=NumberUtil.div(ConvertUtil.obj2Double(score), ConvertUtil.obj2Double(mydnum),2);
                    mape.put("myf", myf);
                }
                if(StringUtil.isEmpty(cynum) || cynum.equals("0") || StringUtil.isEmpty(wcnum) || wcnum.equals("0")){
                    mape.put("jjl", "0");
                }else{
                    double jjl=NumberUtil.div(ConvertUtil.obj2Double(wcnum), ConvertUtil.obj2Double(cynum),4);
                    jjl=jjl*100;
                    mape.put("jjl", jjl);
                }
                List<Map> list2=(List<Map>) mape.get("slaList");
                int sum=0;
                for(Map mapd:list2){
                    if(StringUtil.isEmpty(ConvertUtil.obj2Str(mapd.get("num")))){
                        sum+=0;
                    }else{
                        sum+=ConvertUtil.obj2Int(mapd.get("num"));
                    }
                }
                mape.put("sum", sum);
            }
        }
        Map result=new HashMap();
        result.put("userList", userList);
        result.put("slaList", slaList);
        return result;
    }
 
    /* (non-Javadoc)
     * @see cn.ksource.web.facade.tj.IncidentStatisFacade#getGcsList(java.util.Map)
     */
    @Override
    public List<Map> getGcsList(Map param) {
        String sql="select ID,ZSXM from gg_user where zt=1";
        if(StringUtil.notEmpty(ConvertUtil.obj2Str(param.get("type")))){
            sql=" select a.ID,a.ZSXM from gg_user a,ac_user_ref_role b,ac_role c where a.ID=B.YHBH and C.ID=B.JSBH and C.IDENTIFY='LOCATION'";
            
        }
        return baseDao.queryForList(sql, param);
    }
    
}