[测评系统]--测评系统核心代码库
林致杰
2022-03-15 6d29cd107cc2d75f9cc855174bd5bec3608de527
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
package com.ots.common.utils.poi;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ots.common.enums.ReportTypeEnum;
import com.ots.common.enums.ReportTypeNameEnum;
import com.ots.common.enums.TableEnum;
import com.ots.common.enums.TemplateTypeEnum;
import com.ots.common.utils.StringUtils;
import com.ots.framework.config.EssConfig;
import com.ots.framework.web.domain.AjaxResult;
import com.ots.project.exam.domain.TReportTemplate;
import com.ots.project.exam.dto.JAQTableStyle;
import com.ots.project.exam.dto.WordParam;
import com.ots.project.tool.PdfUtil;
import com.ots.project.tool.ShellTool;
import com.ots.project.tool.exam.ExamUtil;
import com.ots.project.tool.exam.ImageUtil;
import com.ots.project.tool.exam.ZipUtil;
import com.ots.project.tool.report.PAQ.chart.PAQChart;
import org.apache.commons.collections.map.HashedMap;
import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.dom4j.DocumentException;
import org.jetbrains.annotations.Nullable;
import org.openxmlformats.schemas.drawingml.x2006.chart.*;
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class WordUtil {
    private static final Logger log = LoggerFactory.getLogger(WordUtil.class);
    public static String tempFilePath = "/Users/shawnli/Downloads/";
    private static String noRunChange = "";
    private static Map<String, String> colorLabel = new HashMap<String, String>() {{
        put("<YellowText>", "</YellowText>");
    }};
    private static Map<String, String> fontSize = new HashMap<String, String>() {{
        put("<FontSize_11>", "</FontSize_11>");
    }};
    public static final int DEFAULT_FONT_SIZE = 10;
    
    public static boolean changWord(String inputUrl, String outputUrl,
                                    Map<String, Object> textMap, Map<String, Object> tableMap) {
        
        try {
            
            XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl));
            
            WordUtil.changeText(document, textMap);
            
            WordUtil.changeTable(document, textMap);
            
            File file = new File(outputUrl);
            FileOutputStream stream = new FileOutputStream(file);
            document.write(stream);
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
    public static OutputStream getReportWord(String inputUrl, String outputUrl,
                                             Map<String, Object> textMap, Map<String, Object> tableMap) {
        
        try {
            
            XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl));
            
            WordUtil.changeText(document, textMap);
            
            WordUtil.changeTable(document, textMap);
            
            File file = new File(outputUrl);
            return new FileOutputStream(file);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static boolean changWord(String inputUrl, String outputUrl,
                                    Map<String, Object> textMap, WordParam wordParam) {
        
        boolean changeFlag = true;
        try {
            
            XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(inputUrl));
            
            WordUtil.changeText(document, textMap);
            
            File file = new File(outputUrl);
            FileOutputStream stream = new FileOutputStream(file);
            document.write(stream);
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
            changeFlag = false;
        } catch (Exception e) {
        }
        return changeFlag;
    }
    
    public static void changeText(XWPFDocument document, Map<String, Object> textMap) throws IOException, InvalidFormatException {
        
        setHeader(document, textMap);
        
        
        List<IBodyElement> elements = document.getBodyElements();
        List<XWPFParagraph> paragraphs = new ArrayList<>();
        for (IBodyElement iBodyElement : elements) {
            if (iBodyElement instanceof XWPFParagraph) {
                paragraphs.add((XWPFParagraph) iBodyElement);
            }
        }
        for (XWPFParagraph paragraph : paragraphs) {
            
            String text = paragraph.getText();
            if (checkText(text)) {
                
                List<IRunElement> iRunElements = paragraph.getIRuns();
                List<XWPFRun> runs = new ArrayList<>();
                for (IRunElement iRunElement : iRunElements) {
                    runs.add((XWPFRun) iRunElement);
                }
                int runPosition = 0;
                for (XWPFRun run : runs) {
                    
                    String changeValueStr = changeValue(run.toString(), textMap, run, paragraph, document, runPosition);
                    if (!StringUtils.equals(changeValueStr, "NoChangValue")) {
                        run.setText(changeValueStr, 0);
                    }
                    runPosition++;
                }
                
                
            }
        }
    }
    
    private static void setHeader(XWPFDocument document, Map<String, Object> textMap) {
        try {
            List<XWPFHeader> headerList = document.getHeaderList();
            for (XWPFHeader header : headerList) {
                List<XWPFParagraph> paragraphs = header.getParagraphs();
                setHeadTable(document, textMap, header);
                setHeadParagraph(textMap, paragraphs);
            }
        } catch (Exception e) {
            log.info("正常的异常,没有表头数据{}", e.getMessage(), e);
        }
    }
    private static void setHeadParagraph(Map<String, Object> textMap, List<XWPFParagraph> paragraphs) {
        for (XWPFParagraph xwpfParagraph : paragraphs) {
            List<XWPFRun> runs = xwpfParagraph.getRuns();
            for (XWPFRun run : runs) {
                log.info(run.toString());
                if (run.toString().indexOf("%TName%") != -1) {
                    run.setText(textMap.get("questionnaireTaker").toString(), 0);
                }
                if (run.toString().indexOf("%TTime%") != -1) {
                    run.setText(textMap.get("reportGenerationDate").toString(), 0);
                }
                if (run.toString().indexOf("%LIBSAQGS0018%") != -1) {
                    run.setText(textMap.get("LIBSAQGS0018").toString(), 0);
                }
            }
        }
    }
    private static void setHeadTable(XWPFDocument document, Map<String, Object> textMap, XWPFHeader header) {
        if (Objects.nonNull(textMap.get("questionnaireTaker"))) {
            textMap.put("TName", textMap.get("questionnaireTaker").toString());
        }
        if (Objects.nonNull(textMap.get("reportGenerationDate"))) {
            textMap.put("TTime", textMap.get("reportGenerationDate").toString());
        }
        List<XWPFTable> tables = header.getTables();
        if (CollUtil.isEmpty(tables)) {
            return;
        }
        setTableValue(document, textMap, tables);
    }
    public static void changePage(XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
        
        List<XWPFParagraph> paragraphs = document.getParagraphs();
        for (XWPFParagraph paragraph : paragraphs) {
            
            String text = paragraph.getText();
            if (text.indexOf("%page-change%") != -1) {
                List<XWPFRun> runs = paragraph.getRuns();
                for (XWPFRun run : runs) {
                    
                    if (StringUtils.equals(run.toString(), "%page-change%")) {
                        run.setText("", 0);
                    }
                }
                paragraph.getCTP().getPPr().addNewSectPr();
            }
        }
    }
    public static void changeLine(XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
        
        List<XWPFParagraph> paragraphs = document.getParagraphs();
        for (XWPFParagraph paragraph : paragraphs) {
            
            String text = paragraph.getText();
            if (text.indexOf("%line-feed%") != -1) {
                List<XWPFRun> runs = paragraph.getRuns();
                for (XWPFRun run : runs) {
                    
                    if (StringUtils.equals(run.toString(), "%line-feed%")) {
                        run.setText("", 0);
                        run.addBreak();
                    }
                }
            }
        }
    }
    private static void setPicture(XWPFRun run, WordParam wordParam) throws org.apache.poi.openxml4j.exceptions.InvalidFormatException, IOException {
        InputStream in = new FileInputStream(wordParam.getContent());
        
        BufferedImage bufferedImage = ImageUtil.getImage(wordParam.getContent());
        int width = (int) Math.round(bufferedImage.getWidth());
        int height = (int) Math.round(bufferedImage.getHeight());
        int emuSelf = 3000;
        run.addPicture(in, Document.PICTURE_TYPE_PNG, "TEST", width * emuSelf, height * emuSelf);
        in.close();
        if (wordParam.isMove()) {
            
            CTDrawing drawing = run.getCTR().getDrawingArray(0);
            CTGraphicalObject graphicalobject = drawing.getInlineArray(0).getGraphic();
            
            CTAnchor anchor = getAnchorWithGraphic(graphicalobject, "TEST1",
                    Units.toEMU(wordParam.getPicWidth()), Units.toEMU(wordParam.getPicHeight()),
                    Units.toEMU(wordParam.getX()), Units.toEMU(wordParam.getY()), false, wordParam.getTopPosition());
            drawing.setAnchorArray(new CTAnchor[]{anchor});
            drawing.removeInline(0);
        }
    }
    
    public static CTAnchor getAnchorWithGraphic(CTGraphicalObject ctGraphicalObject,
                                                String deskFileName, int width, int height,
                                                int leftOffset, int topOffset, boolean behind, int topPosition) {
        long relativeHeight = 251649024L + topPosition;
        String anchorXML =
                "<wp:anchor xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" "
                        + "simplePos=\"0\" relativeHeight=\"" + relativeHeight + "\" behindDoc=\"" + ((behind) ? 1 : 0) + "\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"
                        + "<wp:simplePos x=\"0\" y=\"0\"/>"
                        + "<wp:positionH relativeFrom=\"column\">"
                        + "<wp:posOffset>" + leftOffset + "</wp:posOffset>"
                        + "</wp:positionH>"
                        + "<wp:positionV relativeFrom=\"paragraph\">"
                        + "<wp:posOffset>" + topOffset + "</wp:posOffset>" +
                        "</wp:positionV>"
                        + "<wp:extent cx=\"" + width + "\" cy=\"" + height + "\"/>"
                        + "<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>"
                        + "<wp:wrapNone/>"
                        + "<wp:docPr id=\"1\" name=\"Drawing 0\" descr=\"" + deskFileName + "\"/><wp:cNvGraphicFramePr/>"
                        + "</wp:anchor>";
        CTDrawing drawing = null;
        try {
            drawing = CTDrawing.Factory.parse(anchorXML);
        } catch (XmlException e) {
            e.printStackTrace();
        }
        CTAnchor anchor = drawing.getAnchorArray(0);
        anchor.setGraphic(ctGraphicalObject);
        return anchor;
    }
    
    public static void changeTable(XWPFDocument document, Map<String, Object> textMap) {
        
        List<XWPFTable> tables = document.getTables();
        setTableValue(document, textMap, tables);
    }
 
    /**
     * 设置表格值
     * @param document
     * @param textMap
     * @param tables
     */
    private static void setTableValue(XWPFDocument document, Map<String, Object> textMap, List<XWPFTable> tables) {
        for (int i = 0; i < tables.size(); i++) {
            
            log.info("第" + (i + 1) + "个表:");
            try {
                XWPFTable table = tables.get(i);
                if (table.getRows().size() > 0) {
                    log.info("表行数:{}",table.getRows().size());
                    log.info("表格数据:" + table.getText());
                    //增加表格或者減少表格
                    addOrDelTableRow(table,i,textMap);
                    if (checkText(table.getText())) {
                        List<XWPFTableRow> rows = table.getRows();
                        
                        eachTable(rows, textMap, document);
                    }
                }
            } catch (Exception e) {
                log.info("表格发生了多行!");
            }
        }
    }
 
    /**
     * 增加表格或者減少表格
     * @param table 表格
     * @param index 表索引
     * @param textMap 赋值对象
     */
    private static void addOrDelTableRow(XWPFTable table, int index, Map<String, Object> textMap) {
 
        try {
            TableEnum tableEnum = TableEnum.codeOf(index);
            Integer tableNum = Integer.valueOf(textMap.get(tableEnum.getName()).toString());
            Integer rows = table.getRows().size();
 
            //表1-表3 需剔除表头
            Integer contentRows = rows - 1;
            //表4 需剔除表头跟尾部预留行数
            if(tableEnum == TableEnum.table4){
                contentRows = rows - 6;
                rows -= 5;
            }
 
 
            //限制行数不为空 和 限制行数跟报告现有不一致需进行处理
            if(tableNum != null && !tableNum.equals(contentRows)){
 
                if(tableNum > contentRows){
                    //增加行数
                    Integer addRow = tableNum - contentRows;
                    log.info("{}增加{}行",tableEnum.getName(),addRow);
                    for (int i = rows; i < rows+addRow; i++) {
                        addJAQTable(table,tableEnum,i,textMap);
                    }
                }else{
                    //减少行数
                    Integer delRow = tableNum - rows;
                    log.info("{}减少{}行数",TableEnum.codeOf(index).getName(),delRow);
                }
 
            }
 
        }catch (Exception e){
            e.printStackTrace();
            log.info("表{}增加表格或者減少表格异常",index+1);
        }
    }
 
    /**
     * 添加JAQ表格
     * @param tableEnum
     * @param index
     */
    private static void addJAQTable(XWPFTable table,TableEnum tableEnum,Integer index,Map<String, Object> textMap){
 
        // 在表格中指定的位置新增一行
        insertRow(table,1,index);
 
        //XWPFTableRow row = table.createRow();
        XWPFTableRow row = table.getRows().get(index);
        List<XWPFTableCell> cells = row.getTableCells();
        XWPFTableCell cell;
       /* for (int i = 0; i < cells.size(); i++) {
            XWPFTableCell cell = cells.get(i);
            cell.setText("test");
            log.info(cell.getText());
        }*/
        switch (tableEnum){
            case table1:
                cell = cells.get(0);
                cells.get(0).setText(textMap.get("T1rank"+index)+"");
                cells.get(1).setText(textMap.get("T1com"+index)+"");
                cells.get(2).setText(textMap.get("T1com"+index+"IF_M")+"");
                cells.get(3).setText(textMap.get("T1com"+index+"IF_L")+"-"+textMap.get("T1com"+index+"IF_H"));
                break;
            case table2:
                cell = cells.get(0);
                cells.get(0).setText(textMap.get("T2rank"+index)+"");
                cells.get(1).setText(textMap.get("T2com"+index)+"");
                cells.get(2).setText(textMap.get("T2Com"+index+"I_M")+"");
                cells.get(3).setText(textMap.get("T2com"+index+"I_L")+"-"+textMap.get("T2com"+index+"I_H"));
                break;
            case table3:
                cell = cells.get(0);
                cells.get(0).setText(textMap.get("T3rank"+index)+"");
                cells.get(1).setText(textMap.get("T3item"+index)+"");
                cells.get(2).setText(textMap.get("T3item"+index+"IF_M")+"");
                cells.get(3).setText(textMap.get("T3com"+index)+"");
                break;
            case table4:
                cell = cells.get(0);
                cells.get(0).setText("#"+textMap.get("T4rank"+index)+".  "+textMap.get("T4com"+index));
 
                //子集合长度
                Integer table4ChildrenNum = Integer.valueOf(textMap.get(TableEnum.table4Children.getName()).toString());
                StringBuilder sb = new StringBuilder();
                List<String> str = new ArrayList<>();
                for (int j = 1; j <= table4ChildrenNum; j++) {
                    sb.append(textMap.get("T4com"+index+"item"+j)+"\t");
                    str.add(textMap.get("T4com"+index+"item"+j)+"");
                }
 
                //对某个单元格设置段落,spa
                XWPFParagraph para = cells.get(1).getParagraphs().get(0);
                //须要设置,不然中文换行会很生硬很难看
                para.setAlignment(ParagraphAlignment.LEFT);
 
                for(String text : str){
                    //对某个段落设置格式
                    XWPFRun run = para.createRun();
                    //run.addBreak(BreakType.TEXT_WRAPPING);//换行
                    run.setText(text.trim());
                    //换行
                    //run.addBreak();
                }
 
                cells.get(1).setText(sb.toString());
                break;
        }
    }
 
    /**
     * insertRow 在word表格中指定位置插入一行,并将某一行的样式复制到新增行
     * @param copyrowIndex 需要复制的行位置
     * @param newrowIndex 需要新增一行的位置
     * */
    public static void insertRow(XWPFTable table, int copyrowIndex, int newrowIndex) {
        // 在表格中指定的位置新增一行
        XWPFTableRow targetRow = table.insertNewTableRow(newrowIndex);
        // 获取需要复制行对象
        XWPFTableRow copyRow = table.getRow(copyrowIndex);
        //复制行对象
        targetRow.getCtRow().setTrPr(copyRow.getCtRow().getTrPr());
        //或许需要复制的行的列
        List<XWPFTableCell> copyCells = copyRow.getTableCells();
        //复制列对象
        XWPFTableCell targetCell = null;
        for (int i = 0; i < copyCells.size(); i++) {
            XWPFTableCell copyCell = copyCells.get(i);
            targetCell = targetRow.addNewTableCell();
            targetCell.getCTTc().setTcPr(copyCell.getCTTc().getTcPr());
            if (copyCell.getParagraphs() != null && copyCell.getParagraphs().size() > 0) {
                targetCell.getParagraphs().get(0).getCTP().setPPr(copyCell.getParagraphs().get(0).getCTP().getPPr());
                if (copyCell.getParagraphs().get(0).getRuns() != null
                        && copyCell.getParagraphs().get(0).getRuns().size() > 0) {
                    XWPFRun cellR = targetCell.getParagraphs().get(0).createRun();
                    cellR.setBold(copyCell.getParagraphs().get(0).getRuns().get(0).isBold());
                }
            }
        }
 
    }
 
    private static void addTableValue(XWPFDocument document, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) {
        if (Objects.isNull(autoTableMap)) {
            return;
        }
        List<XWPFTable> tables = document.getTables();
        for (int i = 0; i < tables.size(); i++) {
            
            log.info("第" + (i + 1) + "个表:");
            try {
                XWPFTable table = tables.get(i);
                if (table.getRows().size() > 0) {
                    
                    log.info("添加行表格数据:" + table.getText());
                    
                    Map<Integer, List<String[]>> mapRowsMap = autoTableMap.get(i);
                    log.info("插入" + table.getText());
                    insertTable(table, mapRowsMap.get(i), 1);
                }
            } catch (Exception e) {
                log.info("表格发生了多行!");
            }
        }
    }
   /* private static void setTableMap(Map<String, Object> tableMap, Map<Integer, List<String[]>> mapRowsMap) {
        if (Objects.isNull(tableMap) || tableMap.isEmpty()) {
            return;
        }
        
        List<Table1> table1 = (List<Table1>) tableMap.get("table1");
        List<String[]> table1List = new ArrayList<>();
        for (Table1 t : table1) {
            table1List.add(t.toRow());
        }
        mapRowsMap.put(0, table1List);
        
        List<Table2> table2 = (List<Table2>) tableMap.get("table2");
        List<String[]> table2List = new ArrayList<>();
        for (Table2 t : table2) {
            table2List.add(t.toRow());
        }
        mapRowsMap.put(1, table2List);
        
        List<Table3> table3 = (List<Table3>) tableMap.get("table3");
        List<String[]> table3List = new ArrayList<>();
        for (Table3 t : table3) {
            table3List.add(t.toRow());
        }
        mapRowsMap.put(2, table3List);
        
        List<Table4> table4 = (List<Table4>) tableMap.get("table4");
        List<String[]> table4List = new ArrayList<>();
        for (Table4 t : table4) {
            table4List.add(t.toRow());
        }
        mapRowsMap.put(3, table4List);
    }*/
    
    public static void eachTable(List<XWPFTableRow> rows, Map<String, Object> textMap, XWPFDocument document) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
        for (XWPFTableRow row : rows) {
            List<XWPFTableCell> cells = row.getTableCells();
            for (XWPFTableCell cell : cells) {
                
                //如果当前表格包含%就代表需要替换
                if (checkText(cell.getText())) {
                    List<XWPFParagraph> paragraphs = cell.getParagraphs();
                    for (XWPFParagraph paragraph : paragraphs) {
                        //获取所有行
                        List<IRunElement> iRunElements = paragraph.getIRuns();
                        List<XWPFRun> runs = new ArrayList<>();
                        //遍历所有行
                        for (IRunElement iRunElement : iRunElements) {
                            runs.add((XWPFRun) iRunElement);
                        }
                        int runPosition = 0;
                        //替换所有表格的文字
                        for (XWPFRun run : runs) {
                            setTextValue(textMap, document, paragraph, runPosition, run);
                        }
                    }
                }
            }
        }
    }
    private static void setTextValue(Map<String, Object> textMap, XWPFDocument document, XWPFParagraph paragraph, int runPosition, XWPFRun run) {
        log.info("表格的:{}", run.toString());
        try {
            run.setText(changeValue(run.toString(), textMap, run, paragraph, document, runPosition), 0);
        } catch (Exception e) {
            
            
        }
    }
    
    public static void insertTable(XWPFTable table, List<String[]> tableList, int inserRowNum) {
        
        for (int i = 0; i < tableList.size(); i++) {
            XWPFTableRow row = table.createRow();
        }
        
        XWPFTableRow headXwpfTableRow = table.getRows().get(0);
        for (int i = inserRowNum; i <= tableList.size(); i++) {
            XWPFTableRow newRow = table.getRow(i);
            List<XWPFTableCell> cells = newRow.getTableCells();
            for (int j = 0; j < cells.size(); j++) {
                try {
                    XWPFTableCell cell = cells.get(j);
                    cell.setText(tableList.get(i - 1)[j]);
                    
                    cell.getParagraphs().get(0).getCTP().setPPr(headXwpfTableRow.getCell(0).getParagraphs().get(0).getCTP().getPPr());
                } catch (Exception e) {
                }
            }
        }
    }
 
    //校验文本是否需要替换
    public static boolean checkText(String text) {
        //替换文本包含%
        if (text.indexOf("%") != -1 || StringUtils.equals(text, "N/A NONE")) {
            //只有%大于1 才通过
            if(getCount(text) > 1){
                return true;
            }
            return false;
        }
        return false;
    }
 
    //判断%出现的次数
    public static int getCount(String text){
        //旧长度
        int oldLength = text.length();
        text = text.replace("%", "");
        //新长度
        int newLength = text.length();
        //出现次数 = 旧长度 - 新长度
        int count = oldLength - newLength;
        return count;
    }
    
    public static String changeValue(String runValue, Map<String, Object> textMap, XWPFRun run, XWPFParagraph paragraph, XWPFDocument document, int runPosition) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
        log.debug("changeText:{}",runValue);
        Set<Map.Entry<String, Object>> textSets = textMap.entrySet();
        for (Map.Entry<String, Object> textSet : textSets) {
            
            String key = "%" + textSet.getKey() + "%";
            if (runValue.indexOf("%page-change%") != -1) {
                runValue = "";
                paragraph.getCTP().getPPr().addNewSectPr();
                break;
            } else if (runValue.indexOf("%line-feed%") != -1) {
                runValue = "";
                run.addBreak();
                break;
            } else if (runValue.indexOf(key) != -1) {
                runValue = changeWordAndPicValue(runValue, run, textSet, key, paragraph, document);
                if (runValue.indexOf("<BoldText>") != -1) {
                    return setOtherStyle(runValue, paragraph, runPosition, run);
                }
                //有些表格可能存在多个字典 需替换多次不能轻易break
                //没有可替换内容直接break
                if(getTextSize(runValue) == 0){
                    break;
                }
            }
        }
        
        if (checkText(runValue)) {
            runValue = runValue.replaceAll("%.*%", "");
            runValue = runValue.replaceAll("N/A NONE", "");
            
        }
        
        return runValue;
    }
    private static String setOtherStyle(String runValue, XWPFParagraph paragraph, int runPosition, XWPFRun oldRun) {
        
        
        
        
        int position = 0;
        int pointer = 0;
        int end = runValue.length();
        List<String> stringList = new ArrayList<>();
        while (pointer < end) {
            position = runValue.indexOf("<BoldText>", pointer);
            if (position != -1) {
                String originalRunStr = runValue.substring(pointer, position);
                if (StringUtils.isNotEmpty(originalRunStr)) {
                    stringList.add(originalRunStr);
                    XWPFRun insertRun = paragraph.insertNewRun(runPosition++);
                    insertRun.setText(originalRunStr);
                    insertRun.setBold(oldRun.isBold());
                    insertRun.setColor(oldRun.getColor());
                    insertRun.setFontFamily(oldRun.getFontFamily());
                    int fontSize = oldRun.getFontSize();
                    insertRun.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize);
                }
                pointer = position;
                position = runValue.indexOf("</BoldText>", pointer);
                position += 11;
                String newRunStr = runValue.substring(pointer, position);
                if (StringUtils.isNotEmpty(newRunStr)) {
                    newRunStr = newRunStr.replaceAll("<BoldText>", "");
                    newRunStr = newRunStr.replaceAll("</BoldText>", "");
                    
                    String rgbStr = getRGBStr(newRunStr, oldRun);
                    if (rgbStr == null) {
                        rgbStr = oldRun.getColor();
                    }
                    
                    int fontSize = getFontSize(newRunStr, oldRun);
                    if (fontSize == -1) {
                        fontSize = oldRun.getFontSize();
                    }
                    newRunStr = getfinalStr(newRunStr);
                    stringList.add(newRunStr);
                    XWPFRun insertRun = paragraph.insertNewRun(runPosition++);
                    insertRun.setText(newRunStr);
                    insertRun.setBold(true);
                    insertRun.setColor(rgbStr);
                    String fontFamily = oldRun.getFontFamily();
                    insertRun.setFontFamily(fontFamily);
                    insertRun.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize);
                }
                pointer = position;
            } else {
                stringList.add(runValue.substring(pointer, end));
                XWPFRun insertRun = paragraph.insertNewRun(runPosition++);
                insertRun.setText(runValue.substring(pointer, end));
                insertRun.setBold(oldRun.isBold());
                insertRun.setColor(oldRun.getColor());
                insertRun.setFontFamily(oldRun.getFontFamily());
                int fontSize = oldRun.getFontSize();
                insertRun.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize);
                pointer = end;
            }
        }
        
        paragraph.removeRun(runPosition);
        return "NoChangValue";
    }
    private static int getFontSize(String newRunStr, XWPFRun oldRun) {
        int font = -1;
        for (String lab : fontSize.keySet()) {
            if (newRunStr.contains(lab)) {
                int fontSize = getFontSize(lab);
                if (fontSize != -1) {
                    font = fontSize;
                    break;
                }
            }
        }
        return font;
    }
    private static int getFontSize(String lab) {
        int font = -1;
        int index = lab.indexOf("_");
        String size = lab.substring(index + 1, lab.length() - 1);
        try{
            font = Integer.parseInt(size);
        }catch (Exception e){}
        return font;
    }
    private static String getfinalStr(String newRunStr) {
        String result = newRunStr;
        for (String lab : colorLabel.keySet()) {
            if (newRunStr.contains(lab)) {
                newRunStr = newRunStr.replaceAll(lab, "");
                newRunStr = newRunStr.replaceAll(colorLabel.get(lab), "");
                result = newRunStr;
            }
        }
        for (String lab : fontSize.keySet()) {
            if (newRunStr.contains(lab)) {
                newRunStr = newRunStr.replaceAll(lab, "");
                newRunStr = newRunStr.replaceAll(fontSize.get(lab), "");
                result = newRunStr;
            }
        }
        return result;
    }
    private static String getRGBStr(String newRunStr, XWPFRun oldRun) {
        String rgbStr = null;
        for (String lab : colorLabel.keySet()) {
            if (newRunStr.contains(lab)) {
                String colorByLab = getColorByLab(lab);
                if (colorByLab != null) {
                    rgbStr = colorByLab;
                    break;
                }
            }
        }
        return rgbStr;
    }
    private static String getColorByLab(String lab) {
        String rgbStr = null;
        switch (lab) {
            case "<YellowText>":
                rgbStr = "ff9900";
                break;
            default:
                rgbStr = "000000";
                break;
        }
        return rgbStr;
    }
 
 
    private static void changOtherPicture(XWPFParagraph paragraph) {
        
        String paragraphText = paragraph.getText();
        if (paragraphText.indexOf("{start.png}") == -1) {
            return;
        }
        List<IRunElement> iRunElements = paragraph.getIRuns();
        XWPFRun oldRun = (XWPFRun) iRunElements.get(0);
        int position = 0;
        int poiter = 0;
        int end = paragraphText.length();
        int starLength = "{start.png}".length();
        int runPosition = 0;
        while (position < end) {
            position = paragraphText.indexOf("{start.png}", position);
            String value = "";
            if (position == -1) {
                
                runPosition = insertPicRun(paragraph, oldRun, runPosition, paragraphText.substring(poiter, end));
                break;
            }
            if (poiter == position) {
                position = position + starLength;
                
                runPosition = insertSmallRunPic(paragraph, runPosition);
                poiter = position;
                continue;
            } else {
                
                runPosition = insertPicRun(paragraph, oldRun, runPosition, paragraphText.substring(poiter, position));
                poiter = position;
                position = poiter + starLength;
                
                runPosition = insertSmallRunPic(paragraph, runPosition);
                poiter = position;
            }
        }
        for (int i = runPosition; i < iRunElements.size(); i++) {
            paragraph.removeRun(i);
        }
    }
    private static int insertSmallRunPic(XWPFParagraph paragraph, int runPosition) {
        XWPFRun insertRun = paragraph.insertNewRun(runPosition++);
        WordParam wordParam = new WordParam();
        wordParam.setPicHeight(1);
        wordParam.setPicWidth(1);
        wordParam.setMove(false);
        wordParam.setContent(EssConfig.getReportTemplates() + "start.png");
        try {
            setPicture(insertRun, wordParam);
        } catch (InvalidFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return runPosition;
    }
    private static int insertPicRun(XWPFParagraph paragraph, XWPFRun oldRun, int runPosition, String value) {
        XWPFRun insertRun = paragraph.insertNewRun(runPosition++);
        insertRun.setText(value);
        insertRun.setBold(oldRun.isBold());
        insertRun.setColor(oldRun.getColor());
        int fontSize = oldRun.getFontSize();
        insertRun.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize);
        return runPosition;
    }
    
    private static String changeWordAndPicValue(String runValue, XWPFRun run, Map.Entry<String, Object> textSet, String key, XWPFParagraph paragraph, XWPFDocument document) throws org.apache.poi.openxml4j.exceptions.InvalidFormatException, IOException {
        if (textSet.getValue() instanceof WordParam) {
            setPicture(run, (WordParam) textSet.getValue());
        } else {
            String keyTemp = textSet.getKey();
            String keyValue = Objects.isNull(textSet.getValue()) ? "" : textSet.getValue().toString();
            if (StringUtils.contains(keyValue, "%line-feed%")) {
                
                String[] keyValues = keyValue.split("%line-feed%");
                runValue = delDynList(keyTemp, Arrays.asList(keyValues), paragraph, document);
            }
            log.info("ChangeValue的key值:" + key + "  ChangeValue的value值:" + keyValue);
            runValue = runValue.replaceAll(key, keyValue);
        }
        return runValue;
    }
    
    public AjaxResult exportBaseOrDetailReport(String fileName, List<String> deleteFileStrList, List<String> fileNameList) {
        
        try {
            zipWord(fileName, fileNameList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        deleteFileByStr(deleteFileStrList);
        return AjaxResult.success(fileName + ".zip");
    }
    public AjaxResult exportZipKeepFiles(String fileName, List<String> deleteFileStrList, List<String> fileNameList) throws FileNotFoundException {
        
        zipKeepWord(fileName, fileNameList);
        
        deleteFileByStr(deleteFileStrList);
        return AjaxResult.success(fileName + ".zip");
    }
    
    
    public static String makeReportFile(String fileName, TReportTemplate tReportTemplate, Map<String, Object> textMap, Map<Integer, Map<Integer, List<String[]>>> autoTableMap, List<String> deleteFileStrList) {
        String returnMessage = "导出模板转移错误:";
        InputStream in = null;
        FileOutputStream out = null;
        String zipFilePath = "";
        String reportName = "";
        try {
            
            String reportType = tReportTemplate.getReportType();
            reportType = getTypeIfIsSAQ(tReportTemplate, reportType);
            reportType = getPositionIfJAQ(textMap, reportType);
            reportName = textMap.get("sendEmailFileName") + "_" + reportType + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getTemplateType()).getCode() + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getLangType()).getCode() + ".docx";
            
            reportName = reportName.replaceAll(" ", "_");
            out = getDownLoadFileOutputStream(reportName);
            
            log.info("reportTemplate:" + fileName);
            String templateType = tReportTemplate.getTemplateType();
            setChageWord(fileName, out, textMap, tReportTemplate.getReportType(), templateType, autoTableMap);
            out.flush();
            changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType());
            //PAQ采用新的doc转pdf
            if(!ReportTypeEnum.PAQ.getCode().equals(reportType)){
                ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
            }else{
                PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName);
            }
            zipFilePath = getPdfPath(reportName);
            
            deleteFileStrList.add(EssConfig.getProfile() + "/" + reportName);
        } catch (Exception ex) {
            returnMessage = returnMessage + ex.getMessage();
            deleteFileStrList.add(EssConfig.getProfile() + "/" + reportName);
            log.error("导出模板转移错误:{}\n检查文件:" + fileName, returnMessage, ex);
        } finally {
            closeChannel(out);
            closeChannel(in);
        }
        return zipFilePath;
    }
    @Nullable
    private static String getPositionIfJAQ(Map<String, Object> textMap, String reportType) {
        if (Objects.equals(reportType, "JAQ")) {
            reportType = Optional.ofNullable(textMap.get("position")).map(p -> p.toString()).orElse("JAQ");
        }
        return reportType;
    }
    private static void changColorIfJAQ(Map<String, Object> textMap, FileOutputStream out, String reportName, String reportType) throws IOException {
        if (Objects.equals(reportType, "JAQ")) {
            changTableColor(reportName, out, (List<JAQTableStyle>) textMap.get("JAQTableStyle"));
        }
    }
    private static String getTypeIfIsSAQ(TReportTemplate tReportTemplate, String reportType) {
        if (Objects.equals(tReportTemplate.getTemplateType(), TemplateTypeEnum.SAQ.getCode())) {
            reportType = TemplateTypeEnum.SAQ.getCode();
        }
        return reportType;
    }
    private static String getPdfPath(String reportName) {
        return reportName.substring(0, reportName.lastIndexOf(".")) + ".pdf";
    }
    public static void deleteFileByStr(List<String> deleteFileStrList) {
        
        for (String deleteStr : deleteFileStrList) {
            File file = new File(deleteStr);
            file.delete();
        }
    }
    private void zipWord(String fileName, List<String> zipFileNameList) throws FileNotFoundException {
        List<File> fileList = new ArrayList<>();
        File fileZip = getAbsoluteFileZipByName(fileName + ".zip");
        try {
            FileOutputStream zipOut = new FileOutputStream(fileZip);
            for (String zipFileName : zipFileNameList) {
                File file = new File(EssConfig.getProfile() + "/" + zipFileName);
                fileList.add(file);
            }
            ZipUtil.toZip(fileList, zipOut);
        } catch (Exception e) {
            e.printStackTrace();
        }
 
 
 
 
    }
    private void zipKeepWord(String fileName, List<String> zipFileNameList) throws FileNotFoundException {
        List<File> fileList = new ArrayList<>();
        File fileZip = getAbsoluteFileZipByName(fileName + ".zip");
        FileOutputStream zipOut = new FileOutputStream(fileZip);
        for (String zipFileName : zipFileNameList) {
            File file = new File(EssConfig.getProfile() + "/" + zipFileName);
            fileList.add(file);
        }
        ZipUtil.toZip(fileList, zipOut);
    }
    
    private static FileOutputStream getDownLoadFileOutputStream(String fileName) throws FileNotFoundException {
        File outFile = new File(EssConfig.getProfile() + "/" + fileName);
        if (!outFile.getParentFile().exists()) {
            outFile.getParentFile().mkdirs();
        }
        return new FileOutputStream(outFile);
    }
    private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType, String templateType, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException, DocumentException {
        String filePath = getTemplateDownLoadPathByUpLoad(fileName);
        
        XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(getTemplateDownLoadPathByUpLoad(fileName)));
 
        //设置文本
        changeText(document, textMap);
 
        //设置文本框
        changeTextBox(document, textMap);
 
        //设置图表
        if (Objects.equals(reportType, ReportTypeEnum.PAQ.getCode())) {
            PAQChart.changeChart(document, textMap);
        }
 
        //插入表格
        addTableValue(document, autoTableMap);
 
        //更改表格的值
        changeTable(document, textMap);
 
        //设置图表控件
        changChar(textMap, document, reportType, templateType);
        document.write(out);
    }
    private static void changeTextBox(XWPFDocument document, Map<String, Object> textMap) throws DocumentException {
        List<XWPFParagraph> paragraphs = document.getParagraphs();
        
        for (XWPFParagraph paragraph : paragraphs) {
            CTR[] rArray = paragraph.getCTP().getRArray();
            for (XmlObject ctr : rArray) {
                Node domNode = ctr.getDomNode();
                setTextVal(domNode, textMap);
            }
        }
    }
    private static void setTextVal(Node node, Map<String, Object> textMap) {
        if ("w:t".equalsIgnoreCase(node.getNodeName())) {
            Node wtItem = node.getChildNodes().item(0);
            if (wtItem != null) {
                wtItem.setNodeValue(getValByKey(wtItem.getNodeValue(), textMap));
            }
            return;
        }
        NodeList childNodes = node.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            setTextVal(childNodes.item(i), textMap);
        }
    }
    private static String getValByKey(String text, Map<String, Object> textMap) {
        log.debug("changeTextBox:{}",text);
        if (!checkText(text)) {
            return text;
        }
        String repText = "";
        Set<Map.Entry<String, Object>> textSets = textMap.entrySet();
        for (Map.Entry<String, Object> textSet : textSets) {
            
            String key = "%" + textSet.getKey() + "%";
            if (text.indexOf(key) != -1) {
                text = text.replaceAll(key, (String) textMap.get(textSet.getKey()));
                repText = text;
                if (checkText(text)) {
                    continue;
                } else {
                    break;
                }
            }
        }
        if (repText.indexOf("<BoldText>") != -1) {
            repText = repText.replaceAll("<BoldText>", "");
            repText = repText.replaceAll("</BoldText>", "");
        }
        if (repText.indexOf("N/A NONE") != -1) {
            repText = repText.replaceAll("N/A NONE", "");
        }
        return repText;
    }
    public static void changTableColor(String fileName, OutputStream out, List<JAQTableStyle> jaqTableStyleList) throws IOException {
        if (StringUtils.isEmpty(fileName) || CollUtil.isEmpty(jaqTableStyleList)) {
            return;
        }
        
        XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(EssConfig.getProfile() + "/" + fileName));
        if (Objects.isNull(document)) {
            return;
        }
        for (JAQTableStyle jaqTableStyle : jaqTableStyleList) {
            XWPFTable xwpfTable = document.getTables().get(jaqTableStyle.getTableNum());
            for (Map.Entry<Integer, String> jaqTableSet : jaqTableStyle.getRowColorMap().entrySet()) {
                XWPFTableRow row = xwpfTable.getRow(jaqTableSet.getKey());
                List<XWPFTableCell> cells = row.getTableCells();
                for (XWPFTableCell cell : cells) {
                    List<XWPFParagraph> paragraphs = cell.getParagraphs();
                    for (XWPFParagraph paragraph : paragraphs) {
                        List<XWPFRun> runs = paragraph.getRuns();
                        for (XWPFRun run : runs) {
                            run.setColor(jaqTableSet.getValue());
                        }
                    }
                }
            }
        }
        document.write(out);
        out.flush();
    }
 
    /**
     * 设置图标控件
     * @param textMap
     * @param document
     * @param reportType
     * @param templateType
     */
    private static void changChar(Map<String, Object> textMap, XWPFDocument document, String reportType, String templateType) {
        if (StringUtils.isEmpty(reportType) || StringUtils.isEmpty(templateType)) {
            return;
        }
        List<XWPFChart> charts = document.getCharts();
        if (ExamUtil.isListEmpty(charts)) {
            return;
        }
        if (StringUtils.equals(reportType, ReportTypeEnum.MAQ.getCode())) {
            setMAQCompleteChars(textMap, charts);
        } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQV2.getCode()) || StringUtils.equals(reportType, ReportTypeEnum.MAQIAR.getCode())) {
            setMAQ_V2CompleteChars(textMap, charts);
        } else if (StringUtils.equals(reportType, ReportTypeEnum.RuiLin.getCode())) {
            setRuiLinChar(textMap, charts);
        } else {
            return;
        }
    }
    private static void setMAQ_V2CompleteChars(Map<String, Object> textMap, List<XWPFChart> charts) {
        String p_Task31 = textMap.get("P_Task31").toString();
        String p_People32 = textMap.get("P_People32").toString();
        String P_INCON25 = textMap.get("P_INCON25").toString();
        String P_IM24 = textMap.get("P_IM24").toString();
        String P_SDE23 = textMap.get("P_SDE23").toString();
        
        for (XWPFChart xwpfChart : charts) {
            try {
                CTChart ctChart = xwpfChart.getCTChart();
                CTPlotArea ctPlotArea = ctChart.getPlotArea();
                List<CTScatterChart> scatterChartList = ctPlotArea.getScatterChartList();
                List<CTBarChart> barChartList = ctPlotArea.getBarChartList();
                if (scatterChartList.size() != 0 && barChartList.size() != 0) {
                    CTScatterChart ctScatterChart = scatterChartList.get(0);
                    CTScatterSer ctScatterSer = ctScatterChart.getSerList().get(0);
                    CTAxDataSource xVal = ctScatterSer.getXVal();
                    List<CTNumVal> ptList = xVal.getNumRef().getNumCache().getPtList();
                    ptList.get(0).setV(P_INCON25);
                    ptList.get(1).setV(P_IM24);
                    ptList.get(2).setV(P_SDE23);
                } else if (scatterChartList.size() != 0 && barChartList.size() == 0) {
                    CTScatterChart ctScatterChart = scatterChartList.get(0);
                    CTScatterSer ctScatterSer = ctScatterChart.getSerList().get(0);
                    CTAxDataSource xVal = ctScatterSer.getXVal();
                    CTNumDataSource yVal = ctScatterSer.getYVal();
                    xVal.getNumRef().getNumCache().getPtList().get(0).setV(p_Task31);
                    yVal.getNumRef().getNumCache().getPtList().get(0).setV(p_People32);
                } else if (barChartList.size() != 0) {
                    CTBarChart ctBarChart = barChartList.get(0);
                    List<CTBarSer> serList = ctBarChart.getSerList();
                    CTBarSer ctBarSer = serList.get(0);
                    CTNumDataSource val = ctBarSer.getVal();
                    val.getNumRef().getNumCache().getPtList().get(0).setV(p_People32);
                    val.getNumRef().getNumCache().getPtList().get(1).setV(p_Task31);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    private static void setRuiLinChar(Map<String, Object> textMap, List<XWPFChart> charts) {
        try {
            int char0Size = charts.get(0).getCTChart().getPlotArea().getBarChartList().get(0).getSerList().get(0).getVal().getNumRef().getNumCache().getPtList().size();
            System.out.println("睿邻第0个chart表个数:" + char0Size);
            int char1Size = charts.get(1).getCTChart().getPlotArea().getBarChartList().get(0).getSerList().get(0).getVal().getNumRef().getNumCache().getPtList().size();
            System.out.println("睿邻第1个chart表个数:" + char1Size);
 
 
            Map<Integer, RuiLinChar> setCharMap = new HashedMap();
            setCharMap.put(12, WordUtil::set12RuilinChartList);
            setCharMap.put(38, WordUtil::set38RuilinChartList);
            setCharMap.put(4, WordUtil::set4RuilinChartList);
            
            XWPFChart xwpfChart0 = charts.get(0);
            List<CTNumVal> ptList = xwpfChart0.getCTChart().getPlotArea().getBarChartList().get(0).getSerList().get(0).getVal().getNumRef().getNumCache().getPtList();
            setCharMap.get(char0Size).setsetRuilinChartList(textMap, ptList);
            
            XWPFChart xwpfChart1 = charts.get(1);
            ptList = xwpfChart1.getCTChart().getPlotArea().getBarChartList().get(0).getSerList().get(0).getVal().getNumRef().getNumCache().getPtList();
            setCharMap.get(char1Size).setsetRuilinChartList(textMap, ptList);
            
 
 
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private static void set38RuilinChartList(Map<String, Object> textMap, List<CTNumVal> ptList) {
        ptList.get(37).setV(textMap.get(("P_Com1")).toString());
        ptList.get(36).setV(textMap.get(("P_Com3")).toString());
        ptList.get(35).setV(textMap.get(("P_Com4")).toString());
        ptList.get(34).setV(textMap.get(("P_Com5")).toString());
        ptList.get(33).setV(textMap.get(("P_Com7")).toString());
        ptList.get(32).setV(textMap.get(("P_Com8")).toString());
        ptList.get(31).setV(textMap.get(("P_Com9")).toString());
        ptList.get(30).setV(textMap.get(("P_Com10")).toString());
        ptList.get(29).setV(textMap.get(("P_Com11")).toString());
        ptList.get(28).setV(textMap.get(("P_Com12")).toString());
        ptList.get(27).setV(textMap.get(("P_Com13")).toString());
        ptList.get(26).setV(textMap.get(("P_Com14")).toString());
        ptList.get(25).setV(textMap.get(("P_Com15")).toString());
        ptList.get(24).setV(textMap.get(("P_Com16")).toString());
        ptList.get(23).setV(textMap.get(("P_Com17")).toString());
        ptList.get(22).setV(textMap.get(("P_Com6")).toString());
        ptList.get(21).setV(textMap.get(("P_Com19")).toString());
        ptList.get(20).setV(textMap.get(("P_Com20")).toString());
        ptList.get(19).setV(textMap.get(("P_Com21")).toString());
        ptList.get(18).setV(textMap.get(("P_Com22")).toString());
        ptList.get(17).setV(textMap.get(("P_Com23")).toString());
        ptList.get(16).setV(textMap.get(("P_Com24")).toString());
        ptList.get(15).setV(textMap.get(("P_Com25")).toString());
        ptList.get(14).setV(textMap.get(("P_Com26")).toString());
        ptList.get(13).setV(textMap.get(("P_Com27")).toString());
        ptList.get(12).setV(textMap.get(("P_Com28")).toString());
        ptList.get(11).setV(textMap.get(("P_Com29")).toString());
        ptList.get(10).setV(textMap.get(("P_Com30")).toString());
        ptList.get(9).setV(textMap.get(("P_Com31")).toString());
        ptList.get(8).setV(textMap.get(("P_Com32")).toString());
        ptList.get(7).setV(textMap.get(("P_Com33")).toString());
        ptList.get(6).setV(textMap.get(("P_Com34")).toString());
        ptList.get(5).setV(textMap.get(("P_Com35")).toString());
        ptList.get(4).setV(textMap.get(("P_Com36")).toString());
        ptList.get(3).setV(textMap.get(("P_Com37")).toString());
        ptList.get(2).setV(textMap.get(("P_Com38")).toString());
        ptList.get(1).setV(textMap.get(("P_Com39")).toString());
        ptList.get(0).setV(textMap.get(("P_Com40")).toString());
    }
    private static void set4RuilinChartList(Map<String, Object> textMap, List<CTNumVal> ptList) {
        ptList.get(0).setV(textMap.get(("P_Com301")).toString());
        ptList.get(1).setV(textMap.get(("P_Com302")).toString());
        ptList.get(2).setV(textMap.get(("P_Com303")).toString());
        ptList.get(3).setV(textMap.get(("P_Com304")).toString());
    }
    private static void set12RuilinChartList(Map<String, Object> textMap, List<CTNumVal> ptList) {
        ptList.get(0).setV(textMap.get("P_Com201").toString());
        ptList.get(1).setV(textMap.get("P_Com202").toString());
        ptList.get(2).setV(textMap.get("P_Com203").toString());
        ptList.get(3).setV(textMap.get("P_Com204").toString());
        ptList.get(4).setV(textMap.get("P_Com205").toString());
        ptList.get(5).setV(textMap.get("P_Com206").toString());
        ptList.get(6).setV(textMap.get("P_Com207").toString());
        ptList.get(7).setV(textMap.get("P_Com208").toString());
        ptList.get(8).setV(textMap.get("P_Com209").toString());
        ptList.get(9).setV(textMap.get("P_Com210").toString());
        ptList.get(10).setV(textMap.get("P_Com211").toString());
        ptList.get(11).setV(textMap.get("P_Com212").toString());
    }
    private static void setMAQCompleteChars(Map<String, Object> textMap, List<XWPFChart> charts) {
        String p_Task31 = textMap.get("P_Task31").toString();
        String p_People32 = textMap.get("P_People32").toString();
        
        XWPFChart xwpfChart = charts.get(0);
        if (!setMAQbarGraph(p_Task31, p_People32, xwpfChart)) {
            log.info("第二个是条形");
            setMAQcanvasChart(p_Task31, p_People32, xwpfChart);
        }
        
        XWPFChart xwpfChartLeadershipFourSided = charts.get(1);
        if (!setMAQcanvasChart(p_Task31, p_People32, xwpfChartLeadershipFourSided)) {
            log.info("第一个是画布");
            setMAQbarGraph(p_Task31, p_People32, xwpfChartLeadershipFourSided);
        }
    }
    private static boolean setMAQcanvasChart(String p_Task31, String p_People32, XWPFChart xwpfChartLeadershipFourSided) {
        try {
            CTChart ctChartFourSided = xwpfChartLeadershipFourSided.getCTChart();
            CTPlotArea ctPlotAreaFourSided = ctChartFourSided.getPlotArea();
            List<CTScatterChart> scatterChartList = ctPlotAreaFourSided.getScatterChartList();
            CTScatterChart ctScatterChart = scatterChartList.get(0);
            CTScatterSer ctScatterSer = ctScatterChart.getSerList().get(0);
            CTAxDataSource xVal = ctScatterSer.getXVal();
            CTNumDataSource yVal = ctScatterSer.getYVal();
            xVal.getNumRef().getNumCache().getPtList().get(0).setV(p_Task31);
            yVal.getNumRef().getNumCache().getPtList().get(0).setV(p_People32);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    private static boolean setMAQbarGraph(String p_Task31, String p_People32, XWPFChart xwpfChart) {
        try {
            CTChart ctChart = xwpfChart.getCTChart();
            CTPlotArea ctPlotArea = ctChart.getPlotArea();
            List<CTBarChart> barChartList = ctPlotArea.getBarChartList();
            CTBarChart ctBarChart = barChartList.get(0);
            List<CTBarSer> serList = ctBarChart.getSerList();
            CTBarSer ctBarSer = serList.get(0);
            CTNumDataSource val = ctBarSer.getVal();
            val.getNumRef().getNumCache().getPtList().get(0).setV(p_Task31);
            val.getNumRef().getNumCache().getPtList().get(1).setV(p_People32);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    
    private String getTemplateDownLoadPath(String fileName) {
        
        return EssConfig.getReportTemplates() + fileName;
    }
    
    private static String getTemplateDownLoadPathByUpLoad(String fileName) {
        return EssConfig.getUploadPath() + fileName;
    }
    
    public static String getTemplatePicture(String pictureName) {
        
        return EssConfig.getReportTemplates() + pictureName;
    }
    private static void closeChannel(InputStream inputStream) {
        try {
            if (Objects.nonNull(inputStream)) {
                inputStream.close();
            }
        } catch (IOException ioe) {
            log.error("关闭通道失败:{}", ioe.getMessage(), ioe);
        }
    }
    private static void closeChannel(OutputStream outputStream) {
        try {
            if (Objects.nonNull(outputStream)) {
                outputStream.close();
            }
        } catch (IOException ioe) {
            log.error("关闭通道失败:{}", ioe.getMessage(), ioe);
        }
    }
    public File getAbsoluteFileZipByName(String filename) {
        String downloadPath = EssConfig.getDownloadPath() + filename;
        File desc = new File(downloadPath);
        if (!desc.getParentFile().exists()) {
            desc.getParentFile().mkdirs();
        }
        return desc;
    }
    
    public static void insertNextPageChar(XWPFDocument document) {
        XWPFParagraph paragraph = document.createParagraph();
        
        CTPPr ctpPr = paragraph.getCTP().addNewPPr();
        
        ctpPr.addNewSectPr();
    }
    private static String delDynList(String placeholder, List obj, XWPFParagraph oldParagraph, XWPFDocument templateDoc) {
        String placeholderValue = placeholder;
        List dataList = obj;
        Collections.reverse(dataList);
        XWPFRun oldRun = oldParagraph.getRuns().size() > 0 ? oldParagraph.getRuns().get(0) : null;
        Boolean isBold = Objects.nonNull(oldRun) ? oldRun.isBold() : false;
        for (int i = 0, size = dataList.size(); i < size; i++) {
            Object text = dataList.get(i);
            
            if (i == 0) {
                placeholderValue = String.valueOf(text);
            } else {
                XWPFParagraph paragraph = createParagraph(oldParagraph, templateDoc, oldRun, isBold, String.valueOf(text));
                if (paragraph != null) {
                    oldParagraph = paragraph;
                }
            }
        }
        return placeholderValue;
    }
    
    public static XWPFParagraph createParagraph(XWPFParagraph oldParagraph, XWPFDocument templateDoc, XWPFRun oldRun, boolean isBold, String... texts) {
        
        XmlCursor cursor = oldParagraph.getCTP().newCursor();
        XWPFParagraph newPar = templateDoc.insertNewParagraph(cursor);
        
        newPar.getCTP().setPPr(oldParagraph.getCTP().getPPr());
        copyParagraph(oldParagraph, newPar, oldRun, isBold, texts);
        return newPar;
    }
    
    ;
    private static void copyParagraph(XWPFParagraph sourcePar, XWPFParagraph targetPar, XWPFRun oldRun, boolean isBold, String... texts) {
        targetPar.setAlignment(sourcePar.getAlignment());
        targetPar.setVerticalAlignment(sourcePar.getVerticalAlignment());
        
        targetPar.setAlignment(sourcePar.getAlignment());
        targetPar.setVerticalAlignment(sourcePar.getVerticalAlignment());
        if (texts != null && texts.length > 0) {
            String[] arr = texts;
            
            for (int i = 0, len = texts.length; i < len; i++) {
                String text = arr[i];
                XWPFRun run = targetPar.createRun();
                run.setText(text);
                
                run.setFontFamily(oldRun.getFontFamily());
                int fontSize = oldRun.getFontSize();
                run.setFontSize((fontSize == -1) ? DEFAULT_FONT_SIZE : fontSize);
                run.setBold(isBold);
                run.setItalic(oldRun.isItalic());
                run.setColor(oldRun.getColor());
            }
        }
        String parText = targetPar.getText();
        if (parText.indexOf("<BoldText>") != -1) {
            oldRun.setBold(isBold);
            setOtherStyle(parText, targetPar, 0, oldRun);
        }
    }
    public static void changeJAQStyle(Map<String, Object> textMap, int tableNum, int inum, String line) {
        JAQTableStyle jaqTableStyle = new JAQTableStyle();
        jaqTableStyle.setTableNum(tableNum);
        Map<Integer, String> rowColorMap = new HashMap<>();
        jaqTableStyle.setRowColorMap(rowColorMap);
        
        for (Integer i = 1; i <= inum; i++) {
            if (Objects.equals(textMap.get(line + i.toString() + "C"), "1")) {
                rowColorMap.put(i, "C00000");
            }
            
 
        }
        if (CollUtil.isNotEmpty(rowColorMap)) {
            List<JAQTableStyle> jaqTableStyleList = null;
            if (CollUtil.isNotEmpty((List) textMap.get("JAQTableStyle"))) {
                jaqTableStyleList = (List) textMap.get("JAQTableStyle");
            } else {
                jaqTableStyleList = new ArrayList<>();
            }
            jaqTableStyleList.add(jaqTableStyle);
            textMap.put("JAQTableStyle", jaqTableStyleList);
        }
    }
 
    public static int getTextSize(String runValue){
        Pattern pattern = Pattern.compile("%\\w+%");
        Matcher matcher = pattern.matcher(runValue);
        List<String> result = new ArrayList<>();
        while(matcher.find()){
            result.add(matcher.group());
        }
        return result.size();
    }
 
 
    public static void main(String[] args) {
/*        if (!checkText("人才选拔的目的就是找到能够胜任工作、愿意承担工作,且与组织的需求、文化、价值观相匹配的人。PAQ报告是根据候选人对PAQ问卷中题目的作答信息而生成的,测量的是候选人在工作中偏好的行为风格。PAQ也包括了对作答真实性的测量,同时也装入了TAI专有的作假防范程序,可以有效降低候选人的伪装好倾向(全球30%的自评问卷中都出现了伪装好现象)。")) {
            System.out.println("11");
        }*/
 
        try {
            InputStream is = new FileInputStream("C:\\Users\\大头\\Desktop\\JAQ中文版.docx");
            XWPFDocument document = new XWPFDocument(is);
 
            String result = "{\"T3Line21C\":\"1\",\"T4com8item1\":\"JAQ0127\",\"T1com8IF_H\":\"12.92\",\"T4com8item3\":\"JAQ0046\",\"T4com8item2\":\"JAQ0108\",\"T1com8IF_L\":\"12.16\",\"T1com8IF_M\":\"12.54\",\"T3item2\":\"JAQ0092\",\"T2com1I_L\":\"3.80\",\"T3item3\":\"JAQ0019\",\"T3item4\":\"JAQ0027\",\"T3item5\":\"JAQ0021\",\"T3item6\":\"JAQ0044\",\"T3item7\":\"JAQ0045\",\"T2Com13I_M\":\"3.40\",\"T3item8\":\"JAQ0105\",\"T3item9\":\"JAQ0002\",\"T2com1I_H\":\"4.20\",\"T3item3IF_M\":\"18.00\",\"T3Line10C\":\"0\",\"T3Line22C\":\"0\",\"T1com15IF_H\":\"15.20\",\"T1com15IF_L\":\"7.28\",\"T3Line9C\":\"0\",\"T1com1IF_M\":\"15.62\",\"T1com15IF_M\":\"11.24\",\"T1com1IF_L\":\"14.44\",\"T2com6I_L\":\"3.60\",\"T1com1IF_H\":\"16.80\",\"T1com4IF_M\":\"14.78\",\"T1com4IF_L\":\"14.44\",\"T3Line11C\":\"0\",\"T2com6I_H\":\"4.00\",\"T1com4IF_H\":\"15.12\",\"T3item16IF_M\":\"16.00\",\"T3com18\":\"23. 激励他人\",\"T4com6item1\":\"JAQ0049\",\"T3com17\":\"11. 客户导向(内部和外部)\",\"T4com6item3\":\"JAQ0135\",\"T3com19\":\"14. 判断和决策\",\"T4com6item2\":\"JAQ0025\",\"T3Line8C\":\"0\",\"T3com10\":\"20. 授权\",\"T3item13IF_M\":\"16.00\",\"T3com12\":\"19. 人员配置与人才培养\",\"T3com11\":\"1. 适应性和变革管理\",\"T3com14\":\"15. 计划和组织\",\"T3Line23C\":\"0\",\"T3com13\":\"20. 授权\",\"T3com16\":\"23. 激励他人\",\"T3com15\":\"18. 管理他人\",\"T1com11IF_L\":\"10.88\",\"T1com11IF_M\":\"11.90\",\"T1com11IF_H\":\"12.92\",\"T2com14I_H\":\"3.40\",\"T2com1\":\"1. 适应性和变革管理\",\"T2com2\":\"20. 授权\",\"T3Line6C\":\"0\",\"T2com9\":\"6. 压力忍受-情绪韧性\",\"T2com7\":\"15. 计划和组织\",\"T2com8\":\"19. 人员配置与人才培养\",\"T2com5\":\"5. 缜密性\",\"T3item7IF_M\":\"18.00\",\"T3Line7C\":\"0\",\"T2com6\":\"9. 同理心\",\"T2Com14I_M\":\"3.40\",\"T3item24IF_M\":\"16.00\",\"T2com3\":\"23. 激励他人\",\"T2Com5I_M\":\"3.80\",\"T2com4\":\"11. 客户导向(内部和外部)\",\"T2com14I_L\":\"3.40\",\"T3Line12C\":\"0\",\"T3Line24C\":\"1\",\"T2com15I_H\":\"3.80\",\"T2com15I_L\":\"2.60\",\"T1com4\":\"1. 适应性和变革管理\",\"T4com2item2\":\"JAQ0089\",\"T1com5\":\"9. 同理心\",\"T4com2item3\":\"JAQ0129\",\"T1com6\":\"5. 缜密性\",\"T1com7\":\"8. 团队协作\",\"T4com2item1\":\"JAQ0105\",\"T1com8\":\"19. 人员配置与人才培养\",\"T1com9\":\"6. 压力忍受-情绪韧性\",\"T2Com6I_M\":\"3.80\",\"T1com1\":\"23. 激励他人\",\"T1com2\":\"20. 授权\",\"T1com3\":\"11. 客户导向(内部和外部)\",\"T2Line9C\":\"0\",\"T1com7IF_H\":\"17.60\",\"T2com5I_H\":\"4.00\",\"T1com7IF_M\":\"12.70\",\"T3Line13C\":\"0\",\"T1com7IF_L\":\"7.80\",\"T3Line25C\":\"0\",\"T2com5I_L\":\"3.60\",\"T1com2IF_M\":\"15.56\",\"T1com2IF_L\":\"14.40\",\"T1com2IF_H\":\"16.72\",\"表4子集合\":\"3\",\"T2rank1\":\"1\",\"T3item4IF_M\":\"18.00\",\"T3item27IF_M\":\"16.00\",\"T2rank3\":\"3\",\"T3com21\":\"12. 分析和批判性思维\",\"T2rank2\":\"2\",\"T3com20\":\"5. 缜密性\",\"T2rank5\":\"5\",\"T3com23\":\"6. 压力忍受-情绪韧性\",\"T2rank4\":\"4\",\"T3com22\":\"3. 主动性\",\"T2rank7\":\"7\",\"T3com25\":\"11. 客户导向(内部和外部)\",\"T2rank6\":\"6\",\"T3com24\":\"2. 学习敏锐度\",\"T2rank9\":\"9\",\"T3Line14C\":\"0\",\"T3com27\":\"20. 授权\",\"T2rank8\":\"8\",\"T3com26\":\"1. 适应性和变革管理\",\"T3Line26C\":\"0\",\"T3item23IF_M\":\"16.00\",\"T3item27\":\"JAQ0076\",\"T3item26\":\"JAQ0113\",\"T3item25\":\"JAQ0107\",\"T3item24\":\"JAQ0065\",\"T3item23\":\"JAQ0064\",\"T1rank9\":\"9\",\"T3item22\":\"JAQ0068\",\"T3item21\":\"JAQ0052\",\"T3item20\":\"JAQ0049\",\"T1rank6\":\"6\",\"T1com3IF_M\":\"14.88\",\"T1rank5\":\"5\",\"T1com3IF_L\":\"12.96\",\"T1rank8\":\"8\",\"T1rank7\":\"7\",\"T1rank2\":\"2\",\"T1rank1\":\"1\",\"T2Com15I_M\":\"3.20\",\"T1rank4\":\"4\",\"T1rank3\":\"3\",\"T3Line27C\":\"0\",\"表1\":\"15\",\"表2\":\"15\",\"表3\":\"27\",\"表4\":\"10\",\"T1com3IF_H\":\"16.80\",\"T3Line15C\":\"1\",\"T4com1item3\":\"JAQ0023\",\"T3item8IF_M\":\"18.00\",\"T3item17IF_M\":\"16.00\",\"T4com7item3\":\"JAQ0003\",\"T3item19\":\"JAQ0033\",\"T3item18\":\"JAQ0023\",\"T4com7item1\":\"JAQ0001\",\"T3item12IF_M\":\"16.00\",\"T3item17\":\"JAQ0020\",\"T4com7item2\":\"JAQ0042\",\"T3item16\":\"JAQ0133\",\"T3item15\":\"JAQ0012\",\"T1com12IF_M\":\"11.58\",\"T3item14\":\"JAQ0131\",\"T3item13\":\"JAQ0129\",\"T3item12\":\"JAQ0127\",\"T3item11\":\"JAQ0006\",\"T3item10\":\"JAQ0089\",\"T4com10\":\"24. 组织敏锐度\",\"T3item1\":\"JAQ0128\",\"T1com12IF_H\":\"12.96\",\"T1com12IF_L\":\"10.20\",\"T2Com10I_M\":\"3.50\",\"T2com10I_H\":\"4.40\",\"T3Line16C\":\"0\",\"T2Com1I_M\":\"4.00\",\"T2com4I_H\":\"4.20\",\"T2com10I_L\":\"2.60\",\"T4com1item2\":\"JAQ0133\",\"T2com4I_L\":\"3.60\",\"T4com1item1\":\"JAQ0019\",\"T1com13IF_H\":\"12.92\",\"T2Line4C\":\"0\",\"T3item5IF_M\":\"18.00\",\"T2com11I_H\":\"3.60\",\"T3Line1C\":\"0\",\"T4com9item3\":\"JAQ0114\",\"T4rank10\":\"10\",\"T1com13IF_L\":\"10.20\",\"T1com13IF_M\":\"11.56\",\"T3Line17C\":\"0\",\"T2Com2I_M\":\"4.00\",\"T2com11I_L\":\"3.40\",\"T2com9I_L\":\"3.00\",\"T4com9item1\":\"JAQ0064\",\"T4com9item2\":\"JAQ0050\",\"T2com9I_H\":\"4.00\",\"T2Line5C\":\"0\",\"T3item26IF_M\":\"16.00\",\"T4com10item3\":\"JAQ0079\",\"T2Com7I_M\":\"3.60\",\"T2Line6C\":\"0\",\"T3Line18C\":\"0\",\"T2com12\":\"24. 组织敏锐度\",\"T2com13\":\"16. 创造性\",\"T2com14\":\"25. 商业与战略敏锐度\",\"T2Line11C\":\"0\",\"T2com15\":\"3. 主动性\",\"T3rank27\":\"27\",\"T2com10\":\"8. 团队协作\",\"T2com11\":\"14. 判断和决策\",\"T4com5item3\":\"JAQ0097\",\"T4com5item1\":\"JAQ0044\",\"T4com5item2\":\"JAQ0004\",\"T4com3\":\"11. 客户导向(内部和外部)\",\"T4com4\":\"1. 适应性和变革管理\",\"T4com1\":\"23. 激励他人\",\"T3item9IF_M\":\"18.00\",\"T3item22IF_M\":\"16.00\",\"T4com2\":\"20. 授权\",\"T4com7\":\"8. 团队协作\",\"T3item2IF_M\":\"18.00\",\"T4com8\":\"19. 人员配置与人才培养\",\"T4com5\":\"9. 同理心\",\"T2Com8I_M\":\"3.60\",\"T2Com11I_M\":\"3.50\",\"T4com6\":\"5. 缜密性\",\"T2com3I_H\":\"4.20\",\"T3rank22\":\"22\",\"T3rank21\":\"21\",\"T3rank20\":\"20\",\"T4com9\":\"6. 压力忍受-情绪韧性\",\"T2Line7C\":\"0\",\"T3Line19C\":\"0\",\"T2com3I_L\":\"3.80\",\"T3rank26\":\"26\",\"T3rank25\":\"25\",\"T3rank24\":\"24\",\"T3rank23\":\"23\",\"T2Line10C\":\"0\",\"T1com6IF_M\":\"13.00\",\"T1com6IF_L\":\"10.80\",\"T3item18IF_M\":\"16.00\",\"T1com6IF_H\":\"15.20\",\"T3item11IF_M\":\"16.00\",\"T2Line8C\":\"0\",\"T2com8I_L\":\"3.40\",\"T1com9IF_M\":\"12.10\",\"T3rank1\":\"1\",\"T2com8I_H\":\"3.80\",\"T3rank2\":\"2\",\"T3item10IF_M\":\"18.00\",\"T1com14IF_M\":\"11.40\",\"T1com14IF_L\":\"8.40\",\"T3rank9\":\"9\",\"T3Line5C\":\"0\",\"T3rank7\":\"7\",\"T3rank8\":\"8\",\"T3rank5\":\"5\",\"T3rank6\":\"6\",\"T3rank3\":\"3\",\"T3rank4\":\"4\",\"T4rank7\":\"7\",\"T4rank6\":\"6\",\"T4rank5\":\"5\",\"T4rank4\":\"4\",\"T4com3item3\":\"JAQ0107\",\"T4com3item2\":\"JAQ0020\",\"T4rank9\":\"9\",\"T4com3item1\":\"JAQ0045\",\"T4rank8\":\"8\",\"T3item6IF_M\":\"18.00\",\"T1com14IF_H\":\"14.40\",\"T4rank3\":\"3\",\"T2Line13C\":\"0\",\"T4rank2\":\"2\",\"T4rank1\":\"1\",\"T3rank19\":\"19\",\"T2Line1C\":\"0\",\"T3rank18\":\"18\",\"T2Line12C\":\"0\",\"T3rank17\":\"17\",\"T3rank16\":\"16\",\"T2com12I_H\":\"4.00\",\"T3Line4C\":\"0\",\"T3item20IF_M\":\"16.00\",\"T2Com12I_M\":\"3.50\",\"T2Com3I_M\":\"4.00\",\"T3item14IF_M\":\"16.00\",\"T3rank11\":\"11\",\"T3rank10\":\"10\",\"T2com2I_H\":\"4.40\",\"T1com9IF_H\":\"15.20\",\"T2com12I_L\":\"3.00\",\"T3rank15\":\"15\",\"T3rank14\":\"14\",\"T2com2I_L\":\"3.60\",\"T3rank13\":\"13\",\"T1com9IF_L\":\"9.00\",\"T3rank12\":\"12\",\"T2rank14\":\"14\",\"T2rank13\":\"13\",\"T2rank15\":\"15\",\"T2rank10\":\"10\",\"T2com13I_H\":\"4.00\",\"T3item15IF_M\":\"16.00\",\"T2Line2C\":\"0\",\"T2rank12\":\"12\",\"T2rank11\":\"11\",\"T3Line3C\":\"0\",\"T1com10IF_M\":\"12.10\",\"T1com10IF_L\":\"9.00\",\"T2Com4I_M\":\"3.90\",\"T4com10item2\":\"JAQ0014\",\"T1com10IF_H\":\"15.20\",\"T4com10item1\":\"JAQ0027\",\"T2com13I_L\":\"2.80\",\"T3item25IF_M\":\"16.00\",\"T3item1IF_M\":\"18.00\",\"T3item21IF_M\":\"16.00\",\"T2com7I_L\":\"3.40\",\"T2Line15C\":\"1\",\"T3com6\":\"9. 同理心\",\"T3com7\":\"11. 客户导向(内部和外部)\",\"T3Line20C\":\"0\",\"T2com7I_H\":\"3.80\",\"T3com8\":\"20. 授权\",\"T3com9\":\"15. 计划和组织\",\"T3com2\":\"16. 创造性\",\"T3com3\":\"23. 激励他人\",\"T3com4\":\"24. 组织敏锐度\",\"T2Line3C\":\"0\",\"T3com5\":\"1. 适应性和变革管理\",\"T1rank15\":\"15\",\"T1rank14\":\"14\",\"T1rank13\":\"13\",\"T1rank12\":\"12\",\"T1rank11\":\"11\",\"T1rank10\":\"10\",\"T3Line2C\":\"0\",\"T1com5IF_H\":\"15.20\",\"T1com10\":\"24. 组织敏锐度\",\"T1com11\":\"25. 商业与战略敏锐度\",\"T2Com9I_M\":\"3.50\",\"T1com12\":\"14. 判断和决策\",\"T1com13\":\"15. 计划和组织\",\"T1com14\":\"16. 创造性\",\"T1com15\":\"26. 正直、信任和公信力\",\"T3item19IF_M\":\"16.00\",\"T1com5IF_M\":\"13.72\",\"T3com1\":\"1. 适应性和变革管理\",\"T4com4item1\":\"JAQ0128\",\"T1com5IF_L\":\"12.24\",\"T2Line14C\":\"0\",\"T4com4item2\":\"JAQ0021\",\"T4com4item3\":\"JAQ0006\"}";
 
            JSONObject jsonObject = JSONObject.parseObject(result);
            //json对象转Map
            Map<String,Object> textMap = jsonObject;
 
/*            Map<Integer,Map<Integer, List<String[]>>> autoTableMap = new HashMap<>();
            Map<Integer,List<String[]>> map = new HashMap<>();
            String[] arr = new String[]{"1","2","3","4"};
            String[] arr1 = new String[]{"1","2","3","4"};
            List<String[]> list = new ArrayList<>();
            list.add(arr);
            list.add(arr1);
            map.put(0,list);
 
            autoTableMap.put(0,map);
 
            //插入表格
            addTableValue(document, autoTableMap);*/
 
            //更改表格的值
            changeTable(document, textMap);
 
            //建立文件对象
            File file = new File("C:\\Users\\大头\\Desktop\\JAQ中文版1.docx");
            FileOutputStream out = new FileOutputStream(file);
            document.write(out);
            out.flush();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}