郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
package com.gk.hotwork.Service.ServiceImpl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Enum.TaskType;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.Utils.*;
import com.gk.hotwork.Domain.Vo.TaskVo;
import com.gk.hotwork.Domain.Vo.TaskWorkerVo;
import com.gk.hotwork.Domain.Vo.WorkShowTaskVo;
import com.gk.hotwork.Domain.Vo.specTask.ActiveTaskInfo;
import com.gk.hotwork.Domain.Vo.specTask.ActiveTaskLocationDto;
import com.gk.hotwork.Domain.Vo.specTask.TaskLocation;
import com.gk.hotwork.Mapper.TaskInfoMapper;
import com.gk.hotwork.Mapper.TaskReviewMapper;
import com.gk.hotwork.Service.*;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.xmlbeans.XmlException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author : jingjy
 * @date : 2021/8/19 17:08
 */
@Service("TaskService")
public class TaskServiceImpl extends ServiceImpl<TaskInfoMapper, TaskInfo> implements TaskService {
    @Autowired
    private TaskInfoMapper taskInfoMapper;
    @Autowired
    private TaskReviewMapper taskReviewMapper;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private TaskLogService taskLogService;
    @Autowired
    private TaskAnalysisService taskAnalysisService;
    @Autowired
    private TaskSecurityService taskSecurityService;
    @Autowired
    private TaskWorkerService taskWorkerService;
    @Autowired
    private TaskEnclosureService taskEnclosureService;
    @Autowired
    private TaskEquipmentService taskEquipmentService;
    @Autowired
    private TaskRiskService taskRiskService;
    @Autowired
    private UserService userService;
    @Autowired
    private WordService wordService;
    @Autowired
    private TaskInvolveDepService taskInvolveDepService;
    @Autowired
    private InvolveDepService involveDepService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private EquipmentService equipmentService;
    @Autowired
    private WarningService warningService;
    @Autowired
    private SubTaskService subTaskService;
    @Autowired
    private TaskLocationService taskLocationService;
    @Autowired
    private TaskReviewService taskReviewService;
    @Value("${workCode}")
    private String workCode;
    @Value("${taskPath}")
    private String taskPath;
    @Value("${task}")
    private String task;
 
    @Override
    public void selectDataGrid(PageInfo pageInfo) {
        Page<TaskInfo> page = PageUtil.getPage(pageInfo,"createdat");
        if (StringUtils.isBlank(pageInfo.getSort())){
            pageInfo.setSort("createdat");
        }
        if (StringUtils.isBlank(pageInfo.getOrder())){
            pageInfo.setOrder("desc");
        }
        List<TaskInfo> taskInfos = taskInfoMapper.selectTaskDataGrid(pageInfo.getCondition(),page);
        pageInfo.setResult(taskInfos);
        pageInfo.setTotalCount(page.getTotal());
    }
 
 
    @Override
    public void selectStatisticsData(PageInfo pageInfo) {
        Page<TaskInfo> page = PageUtil.getPage(pageInfo,"createdat");
        if (StringUtils.isBlank(pageInfo.getSort())){
            pageInfo.setSort("createdat");
        }
        if (StringUtils.isBlank(pageInfo.getOrder())){
            pageInfo.setOrder("desc");
        }
        List<TaskInfo> taskInfos = taskInfoMapper.selectStatisticsData(pageInfo.getCondition(),page);
        pageInfo.setResult(taskInfos);
        pageInfo.setTotalCount(page.getTotal());
    }
 
    @Override
    public List<TaskVo> getWorkShowTaskList(UserInfo user) {
        //主表
        List<TaskVo> doingTask = taskInfoMapper.getDoingTask();
        //加上作业类型
        if (doingTask.size() > 0) {
            for (TaskVo taskVo : doingTask) {
                String taskCode = taskVo.getCode();
                List<SubTaskInfo> subTasks = subTaskService.getSubTasksByCode(taskCode);
                taskVo.setSubTaskInfos(subTasks);
            }
        }
        return doingTask;
    }
 
    @Override
    public List<TaskVo> getWorkShowPersonList(UserInfo user) {
        //主表
        List<TaskVo> doingTask = taskInfoMapper.getDoingTask();
        //加上人员列表
        if (doingTask.size() > 0) {
            for (TaskVo taskVo : doingTask) {
                String taskCode = taskVo.getCode();
                List<TaskWorkerVo> workers = taskWorkerService.getVoByTaskCode(taskCode);
                List<EquipmentInfo>equipmentInfos = equipmentService.selectByTaskAndWorker(taskVo.getCode(),taskVo.getApproversupervisor());
                taskVo.setTaskWorkers(workers);
                taskVo.setSupervisorEquipments(equipmentInfos);
            }
        }
        return doingTask;
    }
 
    @Override
    public void selectDataGridTesting(PageInfo pageInfo) {
        Page<TaskInfo> page = PageUtil.getPage(pageInfo,"createdat");
        if (StringUtils.isBlank(pageInfo.getSort())){
            pageInfo.setSort("createdat");
        }
        if (StringUtils.isBlank(pageInfo.getOrder())){
            pageInfo.setOrder("desc");
        }
        List<TaskInfo> taskInfos = taskInfoMapper.selectDataGridTesting(pageInfo.getCondition(),page);
        List<TaskVo>taskVos = new ArrayList<>();
        for (TaskInfo taskInfo : taskInfos){
            TaskVo taskVo = BeanUtils.copy(taskInfo,TaskVo.class);
            List<TaskWorkerVo> workers = taskWorkerService.getVoByTaskCode(taskVo.getCode());
            List<TaskSecurity>securities = taskSecurityService.getListByTaskCode(taskVo.getCode());
            List<TaskAnalysis>analyses = taskAnalysisService.getListByTaskCode(taskVo.getCode());
            List<TaskEnclosure> enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode());
            List<TaskEquipment>equipments = taskEquipmentService.getListByTaskCode(taskVo.getCode());
            List<TaskInvolveDepartment> departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode());
            List<EquipmentInfo>equipmentInfos = equipmentService.selectByTaskAndWorker(taskInfo.getCode(),taskInfo.getApproversupervisor());
            TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode());
            List<TaskReview> reviews = taskReviewService.getListByTaskCode(taskVo.getCode());
            taskVo.setTaskReviews(reviews);
            taskVo.setTaskWorkers(workers);
            taskVo.setTaskSecurities(securities);
            taskVo.setTaskAnalyses(analyses);
            taskVo.setTaskEquipments(equipments);
            taskVo.setTaskRisk(taskRisk);
            taskVo.setResources(enclosures);
            taskVo.setDepartments(departments);
            taskVo.setSupervisorEquipments(equipmentInfos);
            List<SubTaskInfo> subTaskInfos = subTaskService.getSubTasksByCode(taskVo.getCode());
            taskVo.setSubTaskInfos(subTaskInfos);
            taskVos.add(taskVo);
        }
        pageInfo.setResult(taskVos);
        pageInfo.setTotalCount(page.getTotal());
    }
 
    /**
     * 获取进行中的作业
     * @return
     */
    @Override
    public List<ActiveTaskLocationDto> selectActiveTaskLocation(Date time,Byte type) {
        List<ActiveTaskLocationDto> activeTaskDtoList = null;
        if(time == null)
            time = new Date();
        List<ActiveTaskInfo> activeTaskList = taskInfoMapper.selectActiveTaskList(time,type);
        if(activeTaskList != null && activeTaskList.size() > 0){
            activeTaskDtoList = new ArrayList<>();
            //1、包装作业代码作为查询条件
            List<Long> codeIdList = new ArrayList<>();
            for(ActiveTaskInfo info : activeTaskList){
                //包装位置查询参数
                codeIdList.add(info.getId());
            }
            //2、查询全部坐标信息
            List<TaskLocation> taskLocationList = taskReviewMapper.getTaskLocationListByTaskCodes(codeIdList);
            //3、数据匹配
            if(taskLocationList!=null && taskLocationList.size()>0){
                for (TaskLocation l:taskLocationList){
                    for(ActiveTaskInfo info : activeTaskList){
                        if(l.getTaskId() != null && info.getId() != null && info.getId().longValue() == l.getTaskId().longValue()){
                            ActiveTaskLocationDto activeTaskLocationDto = new ActiveTaskLocationDto();
                            activeTaskLocationDto.setId(info.getId());
                            activeTaskLocationDto.setCode(info.getCode());
                            activeTaskLocationDto.setLon(l.getLon());
                            activeTaskLocationDto.setLat(l.getLat());
                            activeTaskDtoList.add(activeTaskLocationDto);
                        }
                    }
                }
            }
            //4、获取子作业
            for(ActiveTaskLocationDto activeTaskLocationDto:activeTaskDtoList){
                List<SubTaskInfo> subTaskInfoList = subTaskService.getSubTasksByCode(activeTaskLocationDto.getCode());
                if(subTaskInfoList != null && subTaskInfoList.size() > 0){
                    List<String> taskTypeList = new ArrayList<>();
                    for(SubTaskInfo subTaskInfo:subTaskInfoList){
                        if(subTaskInfo.getType() != null && !subTaskInfo.getType().isEmpty()){
                            taskTypeList.add(subTaskInfo.getType());
                        }
                    }
                    activeTaskLocationDto.setTaskTypeList(taskTypeList);
                }
                //打包子作业类型数据
            }
        }
        return activeTaskDtoList;
    }
 
    @Override
    @Transactional
    public void saveTaskForAnalysis(TaskVo taskVo, UserInfo userInfo) {
        Date now = new Date();
        String realName = userInfo.getRealname();
        String taskCode = this.generateCode(userInfo,workCode);
        taskVo.setStatus(TaskInfo.TEST_COMMITTED);
        taskVo.setCode(taskCode);
        taskVo.setCreatedat(now);
        taskVo.setCreatedby(realName);
        if (StringUtils.isBlank(taskVo.getAnalysisarea()) || StringUtils.isBlank(taskVo.getAnalysismedium())){
            throw new BusinessException("需要气体检测分析时必须填写分析点名称和分析介质");
        }
 
        {
            List<SubTaskInfo> subTaskInfos = taskVo.getSubTaskInfos();
            if (subTaskInfos == null || subTaskInfos.size() == 0) {throw new BusinessException("请选择涉及的作业信息");}
            subTaskInfos.forEach(item-> item.setTaskcode(taskVo.getCode()));
            subTaskService.saveBatch(subTaskInfos);
        }
        this.save(taskVo);
        TaskLog taskLog = new TaskLog(taskVo.getCode(), "创建任务信息,提交检测中心", realName, new Date(), userInfo.getCompany());
        taskLogService.save(taskLog);
    }
 
    @Override
    public void updateTaskByApp(TaskVo taskVo, UserInfo userInfo) {
        Date now = new Date();
        TaskInfo taskInfo = BeanUtils.copy(taskVo,TaskInfo.class);
        taskSecurityService.removeByTaskCode(taskVo.getCode());
        taskEquipmentService.removeByTaskCode(taskVo.getCode());
        taskRiskService.removeByCode(taskVo.getCode());
        taskEnclosureService.removeByTaskCode(taskVo.getCode());
        List<TaskSecurity> taskSecurities = taskVo.getTaskSecurities();
 
        Byte level = taskVo.getLevel();
        List<InvolveDepInfo> depInfos = involveDepService.list();
        List<TaskInvolveDepartment>departments = new ArrayList<>();
        List<TaskInvolveDepartment>departmentsExist = taskInvolveDepService.getListByTaskCode(taskVo.getCode());
        if (departmentsExist == null || departmentsExist.size() == 0){
            if (taskVo.getIsholiday().equals((byte)1)){
                level++;
            }
            if (!level.equals(TaskInfo.LEVEL_SECOND)){
                for (InvolveDepInfo depInfo : depInfos){
                    TaskInvolveDepartment department = new TaskInvolveDepartment();
                    department.setDepartment(depInfo.getDepartment());
                    department.setTaskcode(taskVo.getCode());
                    department.setCreatedat(new Date());
                    department.setCreatedby(userInfo.getRealname());
                    departments.add(department);
                }
                taskInvolveDepService.saveBatch(departments);
            }
        }
 
        DepartmentInfo departmentInfo = departmentService.selectSafetyDepartment();
        if (departmentInfo == null && !level.equals(TaskInfo.LEVEL_SECOND)){
            throw new BusinessException("安全部门信息不能为空");
        }
        if (departmentInfo != null && !level.equals(TaskInfo.LEVEL_SECOND) && StringUtils.isBlank(taskInfo.getSecuritydep())){
            taskInfo.setSecuritydep(departmentInfo.getDepartment());
        }
 
        TaskReview taskReview = taskVo.getTaskReviews().get(0);
        taskReview.setCreatedat(new Date());
        taskReview.setCreatedby(userInfo.getRealname());
        taskReviewService.saveReview(taskReview);
 
        taskSecurities.forEach(item->{
            item.setTaskcode(taskVo.getCode());
            item.setCreatedat(now);
            item.setCreatedby(userInfo.getRealname());
        });
        taskSecurityService.saveBatch(taskSecurities);
 
        List<TaskEnclosure> resources = taskVo.getResources();
        if (resources != null && resources.size() > 0){
            resources.forEach(item->{
                item.setTaskcode(taskVo.getCode());
                item.setCreatedat(now);
                item.setCreatedby(userInfo.getRealname());
            });
            taskEnclosureService.saveBatch(resources);
        }
 
        List<TaskEquipment> taskEquipments = taskVo.getTaskEquipments();
 
        taskEquipments.forEach(item->{
            item.setTaskcode(taskVo.getCode());
            item.setCreatedat(now);
            item.setCreatedby(userInfo.getRealname());
        });
        taskEquipmentService.saveBatch(taskEquipments);
 
        TaskRisk risk = taskVo.getTaskRisk();
 
        risk.setTaskcode(taskVo.getCode());
        risk.setCreatedat(now);
        risk.setCreatedby(userInfo.getRealname());
        taskRiskService.save(risk);
 
        taskInfo.setStatus(TaskInfo.COMMITTED);
        taskInfo.setModifiedat(new Date());
        taskInfo.setModifiedby(userInfo.getRealname());
        updateById(taskInfo);
        String content = "任务提交";
        TaskLog taskLog = new TaskLog(taskInfo.getCode(),content,userInfo.getRealname(),new Date(),userInfo.getCompany());
        taskLogService.save(taskLog);
    }
 
    @Override
    public void updateTaskByAppForAnalysis(TaskVo taskVo, UserInfo userInfo) {
        if (StringUtils.isBlank(taskVo.getAnalysisarea()) || StringUtils.isBlank(taskVo.getAnalysismedium())){
            throw new BusinessException("需要气体检测分析时必须填写分析点名称和分析介质");
        }
        taskVo.setStatus(TaskInfo.TEST_COMMITTED);
        taskVo.setModifiedby(userInfo.getRealname());
        taskVo.setModifiedat(new Date());
        TaskInfo taskInfo = BeanUtils.copy(taskVo,TaskInfo.class);
        updateById(taskInfo);
    }
 
    @Override
    public String generateCode(UserInfo userInfo, String workCode) {
        UserInfo user = userService.getById(userInfo);
        CompanyInfo companyInfo = companyService.selectByName(user.getCompany());
        Calendar calendar = Calendar.getInstance();
        Integer year = calendar.get(Calendar.YEAR);
        Integer total = taskInfoMapper.getTotalByYear(year);
        total++;
        String sn;
        int maxSn = 999;
        if (total > maxSn){
            sn = total.toString();
        }else {
            sn = String.format("%03d",total);
        }
        String code =  companyInfo.getCode()+"-"+workCode+"-"+year+"-"+sn;
        TaskInfo taskInfo = getTaskByCode(code);
        while (taskInfo != null){
            total ++;
            if (total > maxSn){
                sn = total.toString();
            }else {
                sn = String.format("%03d",total);
            }
            code =  companyInfo.getCode()+"-"+workCode+"-"+year+"-"+sn;
            taskInfo = getTaskByCode(code);
        }
        return code;
    }
 
 
    /**
    * @Description: 创建任务-app端  注意:app端 新建就等于提交
    * @date 2021/8/23 14:13
    */
    @Override
    @Transactional
    public void saveTaskByApp(TaskVo taskVo, UserInfo user) {
        //时间
        Date now = new Date();
        String realName = user.getRealname();
        //任务 task
        {
            //任务编号
            String taskCode = this.generateCode(user,workCode);
            taskVo.setStatus(TaskInfo.COMMITTED);
            taskVo.setCode(taskCode);
            taskVo.setCreatedat(now);
            taskVo.setCreatedby(realName);
 
            if (taskVo.getIsanalysis() .equals((byte)1)){
                if (StringUtils.isBlank(taskVo.getAnalysisarea()) || StringUtils.isBlank(taskVo.getAnalysismedium())){
                    throw new BusinessException("需要气体检测分析时必须填写分析点名称和分析介质");
                }
            }
 
            //任务为一级特级时,要添加相关部门审核流程
            List<InvolveDepInfo> depInfos = involveDepService.list();
            List<TaskInvolveDepartment>departments = new ArrayList<>();
            Byte level = taskVo.getLevel();
            if (taskVo.getIsholiday().equals((byte)1)){
                level++;
            }
            if (!level.equals(TaskInfo.LEVEL_SECOND)){
                for (InvolveDepInfo depInfo : depInfos){
                    TaskInvolveDepartment department = new TaskInvolveDepartment();
                    department.setDepartment(depInfo.getDepartment());
                    department.setTaskcode(taskCode);
                    department.setCreatedat(new Date());
                    department.setCreatedby(user.getRealname());
                    departments.add(department);
                }
                taskInvolveDepService.saveBatch(departments);
            }
            DepartmentInfo departmentInfo = departmentService.selectSafetyDepartment();
            if (departmentInfo == null && !level.equals(TaskInfo.LEVEL_SECOND)){
                throw new BusinessException("安全部门信息不能为空");
            }
            if (departmentInfo != null && !level.equals(TaskInfo.LEVEL_SECOND)){
                taskVo.setSecuritydep(departmentInfo.getDepartment());
            }
 
            this.save(taskVo);
        }
        //审核信息
        {
            if (taskVo.getIsanalysis() .equals((byte)0)){
                if (taskVo.getTaskReviews() == null || taskVo.getTaskReviews().size() < 1 || taskVo.getTaskReviews().get(0) ==null){
                    throw new BusinessException("审核信息不能为空");
                }
                TaskReview taskReview = taskVo.getTaskReviews().get(0);
                taskReview.setTaskId(taskVo.getId());
                taskReview.setTaskcode(taskVo.getCode());
                taskReview.setCreatedat(new Date());
                taskReview.setCreatedby(user.getRealname());
                taskReviewService.saveReview(taskReview);
            }
        }
        //安全措施
        {
            List<TaskSecurity> taskSecurities = taskVo.getTaskSecurities();
            if (taskSecurities == null || taskSecurities.size() == 0)
                throw new BusinessException("请填写安全措施");
 
            taskSecurities.forEach(item->{
                item.setTaskcode(taskVo.getCode());
                item.setCreatedat(now);
                item.setCreatedby(realName);
                item.setConfirmedby(realName);
            });
            taskSecurityService.saveBatch(taskSecurities);
        }
 
        //pdf或图片
        {
            List<TaskEnclosure> resources = taskVo.getResources();
            if (resources != null && resources.size() > 0){
                resources.forEach(item->{
                    item.setTaskcode(taskVo.getCode());
                    item.setCreatedat(now);
                    item.setCreatedby(realName);
                });
                taskEnclosureService.saveBatch(resources);
            }
 
        }
        //安全设备
        {
            List<TaskEquipment> taskEquipments = taskVo.getTaskEquipments();
            if (taskEquipments == null || taskEquipments.size() == 0)
                throw new BusinessException("请选择安全设备");
                taskEquipments.forEach(item->{
                    item.setTaskcode(taskVo.getCode());
                    item.setCreatedat(now);
                    item.setCreatedby(realName);
                });
 
            taskEquipmentService.saveBatch(taskEquipments);
 
        }
 
        //安全风险
        {
            TaskRisk risk = taskVo.getTaskRisk();
            if (risk == null) throw new BusinessException("请填写安全风险");
            risk.setTaskcode(taskVo.getCode());
            risk.setCreatedat(now);
            risk.setCreatedby(realName);
            taskRiskService.save(risk);
        }
 
        {
            List<SubTaskInfo> subTaskInfos = taskVo.getSubTaskInfos();
            if (subTaskInfos == null || subTaskInfos.size() == 0) {throw new BusinessException("请选择涉及的作业信息");}
            subTaskInfos.forEach(item-> item.setTaskcode(taskVo.getCode()));
            subTaskService.saveBatch(subTaskInfos);
        }
 
 
        TaskLog taskLog = new TaskLog(taskVo.getCode(), "", realName, new Date(), user.getCompany());
        taskLogService.save(taskLog);
    }
 
    @Override
    public void selectDataGridByDep(PageInfo pageInfo) {
        Page<TaskInfo> page = PageUtil.getPage(pageInfo,"createdat");
        if (StringUtils.isBlank(pageInfo.getSort())){
            pageInfo.setSort("createdat");
        }
        if (StringUtils.isBlank(pageInfo.getOrder())){
            pageInfo.setOrder("desc");
        }
        List<TaskInfo> taskInfos = taskInfoMapper.selectTaskDataGridByDep(pageInfo.getCondition(),page);
        pageInfo.setResult(taskInfos);
        pageInfo.setTotalCount(page.getTotal());
 
    }
 
    @Override
    public void selectDataGridViewable(PageInfo pageInfo) {
        Page<TaskInfo> page = PageUtil.getPage(pageInfo,"createdat");
        if (StringUtils.isBlank(pageInfo.getSort())){
            pageInfo.setSort("createdat");
        }
        if (StringUtils.isBlank(pageInfo.getOrder())){
            pageInfo.setOrder("desc");
        }
        List<TaskInfo> taskInfos = taskInfoMapper.selectDataGridViewable(pageInfo.getCondition(),page);
        List<TaskVo>taskVos = new ArrayList<>();
        for (TaskInfo taskInfo : taskInfos){
            TaskVo taskVo = BeanUtils.copy(taskInfo,TaskVo.class);
            List<TaskWorkerVo> workers = taskWorkerService.getVoByTaskCode(taskVo.getCode());
            List<TaskSecurity>securities = taskSecurityService.getListByTaskCode(taskVo.getCode());
            List<TaskAnalysis>analyses = taskAnalysisService.getListByTaskCode(taskVo.getCode());
            List<TaskEnclosure> enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode());
            List<TaskEquipment>equipments = taskEquipmentService.getListByTaskCode(taskVo.getCode());
            List<TaskInvolveDepartment> departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode());
            List<EquipmentInfo>equipmentInfos = equipmentService.selectByTaskAndWorker(taskInfo.getCode(),taskInfo.getApproversupervisor());
            TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode());
            List<TaskReview> reviews = taskReviewService.getListByTaskCode(taskVo.getCode());
            taskVo.setTaskReviews(reviews);
            taskVo.setTaskWorkers(workers);
            taskVo.setTaskSecurities(securities);
            taskVo.setTaskAnalyses(analyses);
            taskVo.setTaskEquipments(equipments);
            taskVo.setTaskRisk(taskRisk);
            taskVo.setResources(enclosures);
            taskVo.setDepartments(departments);
            taskVo.setSupervisorEquipments(equipmentInfos);
            List<SubTaskInfo> subTaskInfos = subTaskService.getSubTasksByCode(taskVo.getCode());
            taskVo.setSubTaskInfos(subTaskInfos);
            taskVos.add(taskVo);
        }
        pageInfo.setResult(taskVos);
        pageInfo.setTotalCount(page.getTotal());
    }
 
    @Override
    public void getWaitReviewDataGrid(PageInfo pageInfo) {
        Page<TaskInfo> page = PageUtil.getPage(pageInfo,"createdat");
        if (StringUtils.isBlank(pageInfo.getSort())){
            pageInfo.setSort("createdat");
        }
        if (StringUtils.isBlank(pageInfo.getOrder())){
            pageInfo.setOrder("desc");
        }
        List<TaskInfo> taskInfos = taskInfoMapper.getWaitReviewDataGrid(pageInfo.getCondition(),page);
        List<TaskVo>taskVos = new ArrayList<>();
        for (TaskInfo taskInfo : taskInfos){
            TaskVo taskVo = BeanUtils.copy(taskInfo,TaskVo.class);
            List<TaskWorkerVo> workers = taskWorkerService.getVoByTaskCode(taskVo.getCode());
            List<TaskSecurity>securities = taskSecurityService.getListByTaskCode(taskVo.getCode());
            List<TaskAnalysis>analyses = taskAnalysisService.getListByTaskCode(taskVo.getCode());
            List<TaskEnclosure> enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode());
            List<TaskEquipment>equipments = taskEquipmentService.getListByTaskCode(taskVo.getCode());
            List<TaskInvolveDepartment> departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode());
            TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode());
            List<TaskReview> reviews = taskReviewService.getListByTaskCode(taskVo.getCode());
            taskVo.setTaskReviews(reviews);
            taskVo.setTaskWorkers(workers);
            taskVo.setTaskSecurities(securities);
            taskVo.setTaskAnalyses(analyses);
            taskVo.setTaskEquipments(equipments);
            taskVo.setTaskRisk(taskRisk);
            taskVo.setResources(enclosures);
            taskVo.setDepartments(departments);
            List<SubTaskInfo> subTaskInfos = subTaskService.getSubTasksByCode(taskVo.getCode());
            taskVo.setSubTaskInfos(subTaskInfos);
            taskVos.add(taskVo);
        }
        pageInfo.setResult(taskVos);
        pageInfo.setTotalCount(page.getTotal());
    }
 
    @Override
    public TaskInfo getTaskByCode(String code) {
        LambdaQueryWrapper<TaskInfo>wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TaskInfo::getCode,code);
        return baseMapper.selectOne(wrapper);
    }
 
    @Override
    public List<TaskVo> getPendingTask(String type, String name) {
        List<TaskVo> taskVos = taskInfoMapper.getPendingTask(type,name);
        for (TaskVo taskVo : taskVos){
            List<TaskWorkerVo> workers = taskWorkerService.getVoByTaskCode(taskVo.getCode());
            List<TaskSecurity>securities = taskSecurityService.getListByTaskCode(taskVo.getCode());
            List<TaskAnalysis>analyses = taskAnalysisService.getListByTaskCode(taskVo.getCode());
            List<TaskEnclosure> enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode());
            List<TaskEquipment>equipments = taskEquipmentService.getListByTaskCode(taskVo.getCode());
            List<TaskInvolveDepartment> departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode());
            List<EquipmentInfo>equipmentInfos = equipmentService.selectByTaskAndWorker(taskVo.getCode(),taskVo.getApproversupervisor());
            TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode());
            List<TaskReview> reviews = taskReviewService.getListByTaskCode(taskVo.getCode());
            taskVo.setTaskReviews(reviews);
            taskVo.setTaskWorkers(workers);
            taskVo.setTaskSecurities(securities);
            taskVo.setTaskAnalyses(analyses);
            taskVo.setTaskEquipments(equipments);
            taskVo.setTaskRisk(taskRisk);
            taskVo.setResources(enclosures);
            taskVo.setDepartments(departments);
            taskVo.setSupervisorEquipments(equipmentInfos);
            List<SubTaskInfo> subTaskInfos = subTaskService.getSubTasksByCode(taskVo.getCode());
            taskVo.setSubTaskInfos(subTaskInfos);
        }
        return taskVos;
    }
 
 
    /**
    * @Description: 生成pdf文件
    * @date 2021/8/26 12:23
    */
    @Override
    public List<TaskInfo> selectAllWorkCertUndone() {
        LambdaQueryWrapper<TaskInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(TaskInfo::getId, TaskInfo::getCode)
                .eq(TaskInfo::getStatus, TaskInfo.APPROVED)
                .isNull(TaskInfo::getPath);
        return taskInfoMapper.selectList(queryWrapper);
    }
 
    @Override
    public List<TaskVo> getDoingTask() {
        List<TaskVo> taskVos = taskInfoMapper.getDoingTask();
        for (TaskVo taskVo : taskVos){
            List<TaskWorkerVo> workers = taskWorkerService.getVoByTaskCode(taskVo.getCode());
            List<TaskSecurity>securities = taskSecurityService.getListByTaskCode(taskVo.getCode());
            List<TaskAnalysis>analyses = taskAnalysisService.getListByTaskCode(taskVo.getCode());
            List<TaskEnclosure> enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode());
            List<TaskEquipment>equipments = taskEquipmentService.getListByTaskCode(taskVo.getCode());
            List<TaskInvolveDepartment> departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode());
            List<EquipmentInfo>equipmentInfos = equipmentService.selectByTaskAndWorker(taskVo.getCode(),taskVo.getApproversupervisor());
            TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode());
            List<TaskReview> reviews = taskReviewService.getListByTaskCode(taskVo.getCode());
            taskVo.setTaskReviews(reviews);
            taskVo.setTaskWorkers(workers);
            taskVo.setTaskSecurities(securities);
            taskVo.setTaskAnalyses(analyses);
            taskVo.setTaskEquipments(equipments);
            taskVo.setTaskRisk(taskRisk);
            taskVo.setResources(enclosures);
            taskVo.setDepartments(departments);
            taskVo.setSupervisorEquipments(equipmentInfos);
        }
        return taskVos;
    }
 
    @Override
    public List<Map>  getWorkToday() {
 
 
        List<Map> data = new ArrayList<>(8);
 
        //动火
        Map<String, Object> map1 = new HashMap<>();
        map1.put("num", taskInfoMapper.selectCountWorkToday(TaskInfo.DOING));
        map1.put("name", "动火作业");
        data.add(map1);
 
        //吊装作业
        Map<String, Object> map2 = new HashMap<>();
        map2.put("num", 0);
        map2.put("name", "吊装作业");
        data.add(map2);
 
        //动土作业
        Map<String, Object> map3 = new HashMap<>();
        map3.put("num", 0);
        map3.put("name", "动土作业");
        data.add(map3);
 
        //断路作业
        Map<String, Object> map4 = new HashMap<>();
        map4.put("num", 0);
        map4.put("name", "断路作业");
        data.add(map4);
 
        //高处作业
        Map<String, Object> map5 = new HashMap<>();
        map5.put("num", 0);
        map5.put("name", "高处作业");
        data.add(map5);
 
        //临时用电作业
        Map<String, Object> map6 = new HashMap<>();
        map6.put("num", 0);
        map6.put("name", "临时用电作业");
        data.add(map6);
 
            //盲板抽堵作业
        Map<String, Object> map7 = new HashMap<>();
        map7.put("num", 0);
        map7.put("name", "盲板抽堵作业");
        data.add(map7);
        Map<String, Object> map = new HashMap<>();
 
 
            //受限空间作业
        Map<String, Object> map8 = new HashMap<>();
        map8.put("num", 0);
        map8.put("name", "受限空间作业");
        data.add(map8);
 
        return data;
    }
 
 
 
    @Override
    public IPage getWorkTodayDetail(Page<WorkShowTaskVo> page, Map filter) {
        Map<String, Object> params = new HashMap<>();
        params.put("flag", TaskInfo.DOING);
        List<WorkShowTaskVo> data = taskInfoMapper.selectPageWorkTodayDetail(page,params);
        return page.setRecords(data);
    }
 
    @Override
    public List<Map> getSpecialCompareInPeriod(String period) {
 
        Calendar instance = Calendar.getInstance();
 
        if ("year".equals(period)) {
            instance.clear(Calendar.MONTH);
            instance.set(Calendar.DAY_OF_MONTH,1);
            instance.set(Calendar.HOUR_OF_DAY,0);
        }
        if ("month".equals(period)) {
            instance.add(Calendar.MONTH, -1);
        }
 
        Date startTime = instance.getTime();
 
        List<Map> data = new ArrayList<>(8);
 
        //动火
        Map<String, Object> map1 = new HashMap<>();
        map1.put("num", taskInfoMapper.selectCountDoneInPeriod(startTime,TaskInfo.APPROVED));
        map1.put("name", "动火作业");
        data.add(map1);
 
        //吊装作业
        Map<String, Object> map2 = new HashMap<>();
        map2.put("num", 0);
        map2.put("name", "吊装作业");
        data.add(map2);
 
        //动土作业
        Map<String, Object> map3 = new HashMap<>();
        map3.put("num", 0);
        map3.put("name", "动土作业");
        data.add(map3);
 
        //断路作业
        Map<String, Object> map4 = new HashMap<>();
        map4.put("num", 0);
        map4.put("name", "断路作业");
        data.add(map4);
 
        //高处作业
        Map<String, Object> map5 = new HashMap<>();
        map5.put("num", 0);
        map5.put("name", "高处作业");
        data.add(map5);
 
        //临时用电作业
        Map<String, Object> map6 = new HashMap<>();
        map6.put("num", 0);
        map6.put("name", "临时用电作业");
        data.add(map6);
 
        //盲板抽堵作业
        Map<String, Object> map7 = new HashMap<>();
        map7.put("num", 0);
        map7.put("name", "盲板抽堵作业");
        data.add(map7);
 
        //受限空间作业
        Map<String, Object> map8 = new HashMap<>();
        map8.put("num", 0);
        map8.put("name", "受限空间作业");
        data.add(map8);
 
        return data;
    }
 
    @Override
    public Map getWorkEverydayInMonth() {
 
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        //当前日期往前推days天
        calendar.add(Calendar.DATE, -30);
        Date startTime = calendar.getTime();
 
        int[] index = new int[30];
        for (int i = 0; i < 30; i++) {
            index[i] = i + 1;
        }
 
        //所有
        Map<String, Object> map = new HashMap<>();
        map.put("everyday", taskInfoMapper.selectCountWorkEverydayInMonth(index,startTime,TaskInfo.APPROVED));
 
        return map;
    }
 
    @Override
    public  Map getFourTotal() {
 
        Map<String, Object> map = new HashMap<>();
 
        List<Map> workToday = this.getWorkToday();
        //今日作业总数
        Integer sum = workToday.stream().map(item -> (int) item.get("num")).reduce(0, Integer::sum);
        map.put("num0", sum);
        //今日预警总数
        map.put("num1", warningService.getCount(WarningInfo.EARLY_WARNING));
        //今日报警总数
        map.put("num2", warningService.getCount(WarningInfo.WARNING));
        //今日设备故障总数
        map.put("num3", warningService.getCount(WarningInfo.FAULT));
 
        return map;
    }
 
    @Override
    public IPage selectTaskInPeriod(Page<TaskInfo> page, Map filter, UserInfo user) {
        LambdaQueryWrapper<TaskInfo> queryWrapper = new LambdaQueryWrapper<>();
        //flag = 4 作业中
        queryWrapper.select(TaskInfo::getId,TaskInfo::getCode,TaskInfo::getArea,TaskInfo::getStarttime,TaskInfo::getEndtime,TaskInfo::getDirector)
                 .eq(TaskInfo::getFlag,4)
                .like(TaskInfo::getCode,filter.get("taskcode"))
                .orderByDesc(TaskInfo::getCreatedat);
        return taskInfoMapper.selectPage(page,queryWrapper);
    }
 
    @Override
    public TaskVo getTaskVoByCode(String code) {
        TaskInfo taskInfo = getTaskByCode(code);
        TaskVo taskVo = BeanUtils.copy(taskInfo,TaskVo.class);
        List<TaskWorkerVo> workers = taskWorkerService.getVoByTaskCode(taskVo.getCode());
        List<TaskSecurity>securities = taskSecurityService.getListByTaskCode(taskVo.getCode());
        List<TaskAnalysis>analyses = taskAnalysisService.getListByTaskCode(taskVo.getCode());
        List<TaskEnclosure> enclosures = taskEnclosureService.getListByTaskCode(taskVo.getCode());
        List<TaskEquipment>equipments = taskEquipmentService.getListByTaskCode(taskVo.getCode());
        List<TaskInvolveDepartment> departments = taskInvolveDepService.getListByTaskCode(taskVo.getCode());
        List<EquipmentInfo>equipmentInfos = equipmentService.selectByTaskAndWorker(taskVo.getCode(),taskVo.getApproversupervisor());
        TaskRisk taskRisk = taskRiskService.getTaskRiskByCode(taskVo.getCode());
        List<TaskReview> reviews = taskReviewService.getListByTaskCode(taskVo.getCode());
        taskVo.setTaskReviews(reviews);
        taskVo.setTaskWorkers(workers);
        taskVo.setTaskSecurities(securities);
        taskVo.setTaskAnalyses(analyses);
        taskVo.setTaskEquipments(equipments);
        taskVo.setTaskRisk(taskRisk);
        taskVo.setResources(enclosures);
        taskVo.setDepartments(departments);
        taskVo.setSupervisorEquipments(equipmentInfos);
 
        List<SubTaskInfo>subTaskInfos = subTaskService.getSubTasksByCode(code);
        taskVo.setSubTaskInfos(subTaskInfos);
        return taskVo;
    }
 
    @Override
    public String generateAllWorkCert(String code) {
 
        String fileDocxUrl = taskPath + code + "-apply.doc";
        String fileReturn = task + code + "-apply.doc";
 
        TaskVo taskInfo = this.getTaskVoByCode(code);
        //1.word文档替换
        try {
            ClassPathResource classPathResource = new ClassPathResource("printTemplate/allworkcert.doc");
            InputStream inputStream = classPathResource.getInputStream();
            WordTemplate template = new WordTemplate();
            template.loadTemplate(null, inputStream);
            //数据准备
            Map<String, String> simpleData = new HashMap<>();
            Map<String,WordTemplate.Table> tables = new HashMap<>();
            Map<String,WordTemplate.MergeTable> mergeTables = new HashMap<>();
            Map<String,List<String>> tasktypesMergeMap = new HashMap<>();
            Map<String,List<WordTemplate.Attribute>> ownAttr =new HashMap<>();
            Map<String,String> nameMapGraph = new HashMap<>();
 
            {
                //基础信息
                {simpleData.put("unit", taskInfo.getUnit());
                simpleData.put("applicant", taskInfo.getApplicant());
                simpleData.put("code", taskInfo.getCode());
                simpleData.put("area", taskInfo.getArea());
                simpleData.put("description", taskInfo.getDescription());
                simpleData.put("analysisarea", taskInfo.getAnalysisarea());
                simpleData.put("analysismedium", taskInfo.getAnalysismedium());
                simpleData.put("mode", taskInfo.getMode());
                simpleData.put("director", taskInfo.getDirector());
                simpleData.put("starttime",  WordTemplate.formatTime(taskInfo.getStarttime(),WordTemplate.sdf));
                simpleData.put("endtime", WordTemplate.formatTime(taskInfo.getEndtime(), WordTemplate.sdf));
                simpleData.put("othertask", taskInfo.getOthertask());
                simpleData.put("hazard", taskInfo.getHazard());
                simpleData.put("supervisor", taskInfo.getSupervisor());
                simpleData.put("profession", taskInfo.getProfession());
                simpleData.put("partdirector", taskInfo.getPartdirector());
                simpleData.put("approversupervisor", taskInfo.getApproversupervisor());
                simpleData.put("approverprofession", taskInfo.getApproverprofession());
 
                simpleData.put("applyunittime", WordTemplate.formatTime(taskInfo.getApplyunittime(),WordTemplate.sdf));
 
                simpleData.put("constructionunit", taskInfo.getConstructionunit());
                simpleData.put("constructiontime", WordTemplate.formatTime(taskInfo.getConstructiontime(), WordTemplate.sdf));
 
                simpleData.put("securitytime", WordTemplate.formatTime(taskInfo.getSecuritytime(), WordTemplate.sdf));
 
 
                simpleData.put("enterprisetime", WordTemplate.formatTime(taskInfo.getEnterprisetime(), WordTemplate.sdf));}
                //基础信息签名照
                {
                    List<TaskReview> taskReviews = taskInfo.getTaskReviews();
                    String blank = "";
                    nameMapGraph.put("applyunitname", blank);
                    simpleData.put("applyunitopinion", blank);
                    nameMapGraph.put("constructionname", blank);
                    simpleData.put("constructionopinion", blank);
                    nameMapGraph.put("securityname", blank);
                    simpleData.put("securityopinion",blank);
                    nameMapGraph.put("enterprisename", blank);
                    simpleData.put("enterpriseopinion", blank);
                    taskReviews.forEach(taskReview -> {
                        String autograph = taskReview.getAutograph();
                        String level = taskReview.getLevel();
                        String opinion = taskReview.getOpinion();
                        if (("申请部门审批").equals(level)) {
                            nameMapGraph.put("applyunitname", autograph);
                            simpleData.put("applyunitopinion", opinion);
                        }
 
                        if (("施工单位补充确认").equals(level)) {
                            nameMapGraph.put("constructionname", autograph);
                            simpleData.put("constructionopinion", opinion);
                        }
 
                        if (("安全部门审批").equals(level)) {
                            nameMapGraph.put("securityname", autograph);
                            simpleData.put("securityopinion",opinion);
                        }
 
                        if (("单位负责人审批").equals(level)) {
                            nameMapGraph.put("enterprisename", autograph);
                            simpleData.put("enterpriseopinion", opinion);
                        }
 
 
                    });
 
 
 
 
 
                    //enterprisename 单位负责人审批
 
                }
                //动火等级判断
                switch (taskInfo.getLevel()) {
                    case (byte)0:
                        simpleData.put("level", "二级");break;
                    case (byte)1:
                        simpleData.put("level", "一级");break;
                    case (byte)2:
                        simpleData.put("level", "特级");break;
                    default:
                        simpleData.put("level", null);
                }
                //安全部门
                simpleData.put("securitydep", taskInfo.getSecuritydep());
                //作业人
                {
                    List<TaskWorkerVo> taskWorkersList = taskInfo.getTaskWorkers();
                    //作业人员
                    String workersname = taskWorkersList.stream().map(TaskWorker::getWorker).distinct().collect(Collectors.joining(","));
                    simpleData.put("workersname", workersname);
 
                    String[] workerFields = {"worker", "branch", "number"};
                    List<String[]> workers= new ArrayList<String[]>(){{
                        taskWorkersList.forEach(item->{
                            add(new String[]{item.getWorker(), item.getBranch(), item.getNumber()});
                        });
                    }};
                    WordTemplate.Table workerTable = new WordTemplate.Table(workerFields, workers);
                    tables.put("workerTable", workerTable);
                }
                //分析介质
                {
                    List<TaskAnalysis> taskAnalyses = taskInfo.getTaskAnalyses();
                    String[] analysisFields = {"mediumname", "mediumvalue", "analysisat","analyst"};
                    List<String[]> taskAnalysis = new ArrayList<String[]>(){{
                        taskAnalyses.forEach(item-> add(new String[]{item.getMediumname(), item.getMediumvalue(), WordTemplate.formatTime(item.getAnalysisat(),WordTemplate.sdf_dhms), item.getAnalyst()}));
                    }};
                    WordTemplate.Table analysisTable = new WordTemplate.Table(analysisFields, taskAnalysis);
                    tables.put("mediumTable", analysisTable);
                }
                //安全措施
                {
                    List<TaskSecurity> taskSecurityList = taskInfo.getTaskSecurities();
                    Map<String, List<TaskSecurity>> parentGroupData = new HashMap<>();
                    taskSecurityList.forEach(item->{
                        String tasktype = item.getTasktype();
                        if (parentGroupData.containsKey(tasktype)) {
                            parentGroupData.get(tasktype).add(item);
                        }else{
                            parentGroupData.put(tasktype, new ArrayList<>(Collections.singletonList(item)));
                        }
                    });
 
 
                    //遍历分组后内容
 
                    for (Map.Entry<String, List<TaskSecurity>> parent : parentGroupData.entrySet()) {
 
                        Map<String, List<TaskSecurity>> groupByDataMap = new HashMap<>();
 
                        String[] taskSecurityFields = {"order", "content", "checked", "createby"};
                        String[] taskSecurityMergeFields = {"createby"};
                        //根据创建人分组
                        parent.getValue().forEach(item -> {
                            String confirmedby = "";
                            if(item.getConfirmedby() != null)
                                confirmedby = item.getConfirmedby();
                            if (!groupByDataMap.containsKey(confirmedby)) {
                                groupByDataMap.put(confirmedby, new ArrayList<>(Collections.singletonList(item)));
                            } else {
                                groupByDataMap.get(confirmedby).add(item);
                            }
                        });
 
 
                        int lastOrder = 0;          //记录上一个合并表格的最大序号
                        int mergeTableSeq = 1;   //word合并表后缀序号
                        for (Map.Entry<String, List<TaskSecurity>> entry : groupByDataMap.entrySet())   {
                            String confirmedby = entry.getKey();
                            List<TaskSecurity> mappingList = entry.getValue();
                            List<String[]> taskSecurities = new ArrayList<>();
                            for (int i = mappingList.size() - 1; i >= 0; i--) {
                                TaskSecurity taskSecurity = mappingList.get(i);
                                taskSecurities.add(new String[]{
                                        lastOrder + i + 1 + "",
                                        taskSecurity.getContent().replace("_",taskSecurity.getNum()+""),
                                        taskSecurity.getChecked() == (byte) 1 ? "√" : "/",
                                        confirmedby});
                                if (i == 0) {
                                    lastOrder =  mappingList.size();
                                }
 
                            }
                            WordTemplate.MergeTable mergeTable = new WordTemplate.MergeTable(taskSecurityFields, taskSecurityMergeFields, taskSecurities);
                            String mergeTableFlag = parent.getKey() + "mergeTable" + mergeTableSeq;
                            mergeTables.put(mergeTableFlag, mergeTable);
                            if (tasktypesMergeMap.get(parent.getKey()) == null) {
                                tasktypesMergeMap.put(parent.getKey(), new ArrayList<>(Collections.singletonList(mergeTableFlag)));
                            }else{
                                tasktypesMergeMap.get(parent.getKey()).add(mergeTableFlag);
                            }
                            mergeTableSeq++;
                        }
                    }
 
 
                }
                //相关部门
                {
                    //时间降序吗,最新为第一条
                    List<TaskInvolveDepartment> departments = taskInfo.getDepartments();
 
                    if (departments.size() > 0) {
                        simpleData.put("involvedep",departments.stream().map(TaskInvolveDepartment::getDepartment).collect(Collectors.joining("、")));
                        simpleData.put("departmentconent", departments.get(0).getContent());
                        simpleData.put("reviewedbys",departments.stream().map(TaskInvolveDepartment::getReviewedby).collect(Collectors.joining("、")));
                        simpleData.put("reviewedtime", WordTemplate.formatTime(departments.get(0).getCreatedat(), WordTemplate.sdf));
                    }else{
                        simpleData.put("involvedep",null);
                        simpleData.put("departmentconent", null);
                        simpleData.put("reviewedbys",null);
                        simpleData.put("reviewedtime",null);
                    }
 
                }
                //作业类型
                {
                    List<SubTaskInfo> subTaskInfos = taskInfo.getSubTaskInfos();
                    String collectType = subTaskInfos.stream().map(subTaskInfo -> "☑ " + subTaskInfo.getType()).collect(Collectors.joining("   "));
                    simpleData.put("type", collectType);
                    //8个作业
 
                    List<WordTemplate.Attribute> attrList;
                    for (SubTaskInfo subTask : subTaskInfos) {
                        if (TaskType.HOT.msg.equals(subTask.getType())) {
                            attrList = new ArrayList<>();
                            String level = "";
                            switch (subTask.getLevel()){
                                case (byte)0:
                                    level =  "二级";
                                case (byte)1:
                                    level =  "一级";
                                case (byte)2:
                                    level =  "特级";
                            }
 
 
                            attrList.add(new WordTemplate.Attribute("动火作业级别", level));
                            attrList.add(new WordTemplate.Attribute("动火作业方式", subTask.getFiretype() +""));
                            ownAttr.put(subTask.getType(), attrList);
                        }
 
                        if (TaskType.SPACE.msg.equals(subTask.getType())) {
                            attrList = new ArrayList<>();
                            attrList.add(new WordTemplate.Attribute("受限空间分类", subTask.getSpacecategory() +""));
                            attrList.add(new WordTemplate.Attribute("受限空间名称", subTask.getSpacename() +""));
                            attrList.add(new WordTemplate.Attribute("受限空间介质名称", subTask.getSpacemedium() +""));
                            attrList.add(new WordTemplate.Attribute("是否酸碱腐蚀",subTask.getAcibase()));
 
                            ownAttr.put(subTask.getType(), attrList);
                        }
 
                        if (TaskType.HIGH.msg.equals(subTask.getType())) {
                            attrList = new ArrayList<>();
                            attrList.add(new WordTemplate.Attribute("高度作业等级", subTask.getHeightlevel() +""));
                            attrList.add(new WordTemplate.Attribute("高处作业作业高度", subTask.getWorkheight() +""));
                            ownAttr.put(subTask.getType(), attrList);
                        }
 
                        if (TaskType.HOISTING.msg.equals(subTask.getType())) {
                            attrList = new ArrayList<>();
                            attrList.add(new WordTemplate.Attribute("吊装作业等级", subTask.getHoistinglevel() + ""));
                            attrList.add(new WordTemplate.Attribute("吊装作业重量", subTask.getHoistingweight() + ""));
                            ownAttr.put(subTask.getType(), attrList);
                        }
 
                        if (TaskType.BLIND.msg.equals(subTask.getType())) {
                            attrList = new ArrayList<>();
                            attrList.add(new WordTemplate.Attribute("盲板材质", subTask.getBlindboardmaterial() +""));
                            attrList.add(new WordTemplate.Attribute("盲板规格", subTask.getBlindboardspecification()+""));
                            attrList.add(new WordTemplate.Attribute("盲板编号", subTask.getBlindboardnumber() + ""));
                            attrList.add(new WordTemplate.Attribute("生产单位作业指挥", subTask.getCommander() + ""));
                            attrList.add(new WordTemplate.Attribute("设备管道名称", subTask.getPipename() + ""));
                            attrList.add(new WordTemplate.Attribute("设备管道介质", subTask.getPipemedium() + ""));
                            attrList.add(new WordTemplate.Attribute("设备管道温度", subTask.getPipetemperature() + ""));
                            attrList.add(new WordTemplate.Attribute("设备管道压力", subTask.getPipepressure() + ""));
                            //位置图没有
                            ownAttr.put(subTask.getType(), attrList);
                        }
 
                        if (TaskType.BREAK.msg.equals(subTask.getType())) {
                            attrList = new ArrayList<>();
                            attrList.add(new WordTemplate.Attribute("断路原因", subTask.getBreakreason() +""));
                            //断路地段示意图无
                            ownAttr.put(subTask.getType(), attrList);
                        }
 
                        if (TaskType.ELECTRIC.msg.equals(subTask.getType())) {
                            attrList = new ArrayList<>();
                            attrList.add(new WordTemplate.Attribute("电源接入点", subTask.getElectricityarea() +""));
                            attrList.add(new WordTemplate.Attribute("工作电压", subTask.getVoltage() +""));
                            attrList.add(new WordTemplate.Attribute("功率", subTask.getPower() +""));
                            //断路地段示意图无
                            ownAttr.put(subTask.getType(), attrList);
                        }
 
                        if (TaskType.SOILD.msg.equals(subTask.getType())) {
                            attrList = new ArrayList<>();
                            attrList.add(new WordTemplate.Attribute("动土作业深度(单位:m)", subTask.getSoildepth() +""));
                            attrList.add(new WordTemplate.Attribute("动土作业面积(单位:㎡)", subTask.getSoilarea() +""));
                            //动土文件地址无
                            ownAttr.put(subTask.getType(), attrList);
                        }
 
 
                    }
 
                }
 
                //安全交底和风险
                {
 
                    TaskRisk taskRisk = taskInfo.getTaskRisk();
                    simpleData.put("environment", taskRisk.getEnvironment());
                    simpleData.put("preventive", taskRisk.getPreventive());
                    simpleData.put("emergency", taskRisk.getEmergency());
                    simpleData.put("other", taskRisk.getOther());
                    simpleData.put("taskrisk-director", taskRisk.getDirector());
                    simpleData.put("taskrisk-taskdirector", taskRisk.getTaskdirector());
                    simpleData.put("confirmat", WordTemplate.formatTime(taskRisk.getConfirmat(),WordTemplate.sdf));
                    simpleData.put("contents", taskRisk.getContent());
                }
 
 
 
            }
            wordService.generateAllTaskCert(
                    new HashMap<String,Map<String,List<String>>>(){{put("tasktype",tasktypesMergeMap);}},
                    new HashMap<String,Map<String,List<WordTemplate.Attribute>>>(){{put("typeAndOwnAttr",ownAttr);}},
                    tables,
                    mergeTables,
                    simpleData,
                    nameMapGraph,
                    template);
            template.saveFile(fileDocxUrl);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new BusinessException("找不到模板文件路径");
        } catch (IOException | XmlException | InvalidFormatException | InterruptedException e) {
            e.printStackTrace();
        }
        return fileReturn;
    }
 
 
 
 
 
 
 
 
}