郑永安
2023-08-23 0a9ed7b7488de66a50799f79369d7806910ae00a
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
package com.gk.hotwork.Controller;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.hotwork.Config.attachment.FilePathConfig;
import com.gk.hotwork.Controller.Base.BaseController;
import com.gk.hotwork.Domain.CompanyInfo;
import com.gk.hotwork.Domain.SafetyFacilityInspection;
import com.gk.hotwork.Domain.SafetyFacilityProcessflow;
import com.gk.hotwork.Domain.Enum.ResultCodes;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.Utils.FilterObject;
import com.gk.hotwork.Domain.Utils.Msg;
import com.gk.hotwork.Domain.Utils.PageInfo;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Domain.query.CompanyQuery;
import com.gk.hotwork.Service.CompanyService;
import com.gk.hotwork.Service.SafetyFacilityInspectionService;
import com.gk.hotwork.Service.SafetyFacilityProcessflowService;
import com.gk.hotwork.Service.UserService;
import freemarker.template.Template;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
@Api(tags = "②安全设施审查流程")
@RestController
@RequestMapping("/safetyFacilityInspection")
public class SafetyFacilityInspectionController extends BaseController {
 
    @Autowired
    private SafetyFacilityInspectionService safetyFacilityInspectionService;
 
    @Autowired
    private SafetyFacilityProcessflowService safetyFacilityProcessflowService;
 
    @Autowired
    private UserService userService;
 
    @Resource
    private FilePathConfig filePathConfig;
 
    @Autowired
    private CompanyService companyService;
    
    @Autowired
    private FreeMarkerConfigurer freeMarkerConfigurer;
 
    @ApiOperation("审查项目分页列表")
    @PostMapping("/page")
    @ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "每页行数"),
            @ApiImplicitParam(name = "progress", value = "进度进度(0:待受理,1:已受理,10:待评审,11:评审中,12:评审否决,19:待企业反馈,20:待审查,21:审查中,29:待企业补正,22:审查否决,30:完成)"),
            @ApiImplicitParam(name = "expert", value = "审查专家"),
            @ApiImplicitParam(name = "createBy", value = "企业用户姓名"),
            @ApiImplicitParam(name = "type", value = "类别(1:安全设施设计审查,2:安全条件审查)"),
            @ApiImplicitParam(name = "submitDateStartTime", value = "开始时间"),
            @ApiImplicitParam(name = "submitDateEndTime", value = "结束时间") })
    public Msg selectPage(@RequestBody FilterObject filterObject) {
        Integer pageIndex = filterObject.getPageIndex() == null ? 1 : filterObject.getPageIndex();
        Integer pageSize = filterObject.getPageSize() == null ? 10 : filterObject.getPageSize();
        Map<String, Object> map = filterObject.getFilter();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
 
        try {
            if (map.get("submitDateStartTime") != null && StringUtils.isNotBlank(map.get("submitDateStartTime").toString()))
                map.put("submitDateStartTime", simpleDateFormat.format(simpleDateFormat.parse(map.get("submitDateStartTime").toString())));
 
            if (map.get("submitDateEndTime") != null  && StringUtils.isNotBlank(map.get("submitDateEndTime").toString()))
                map.put("submitDateEndTime", simpleDateFormat.format(simpleDateFormat.parse(map.get("submitDateEndTime").toString())));
            
            if (map.get("progress") != null  && StringUtils.isNotBlank(map.get("progress").toString()))
                map.put("progress", Integer.valueOf(map.get("progress").toString()));
            else
                map.put("progress", null);
            
            IPage<SafetyFacilityInspection> page = safetyFacilityInspectionService.selectPage(new Page<>(pageIndex, pageSize), filterObject.getFilter(), getUser());
            return success(page);
        } catch (ParseException e) {
            return failed(e.getMessage());
        }
 
    }
 
    @ApiOperation("业务处理历史详情")
    @PostMapping("/dealFlow")
    @ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "每页行数"),
            @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public Msg dealFlow(@RequestBody FilterObject filterObject) {
        Integer pageIndex = filterObject.getPageIndex() == null ? 1 : filterObject.getPageIndex();
        Integer pageSize = filterObject.getPageSize() == null ? 100 : filterObject.getPageSize();
 
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
        int progress = inspection.getProgress();
 
        IPage<SafetyFacilityProcessflow> page = safetyFacilityProcessflowService.processflowPages(new Page<>(pageIndex, pageSize), filterObject.getFilter(), getUser());
        List<SafetyFacilityProcessflow> list = new ArrayList<SafetyFacilityProcessflow>();
        List<SafetyFacilityProcessflow> review = new ArrayList<SafetyFacilityProcessflow>();
        List<SafetyFacilityProcessflow> examine = new ArrayList<SafetyFacilityProcessflow>();
 
        String reviewFinalResolution = "";
        String examineFinalResolution = "";
 
        for (SafetyFacilityProcessflow flow : page.getRecords()) {
            if ("资料提交".equals(flow.getProgressName()) || "待评审".equals(flow.getProgressName()) || "已受理".equals(flow.getProgressName()) || "待受理".equals(flow.getProgressName()))
                list.add(flow);
        }
 
        if (progress > 20) { // 构建审查全流程
            SafetyFacilityProcessflow inner = new SafetyFacilityProcessflow();
            inner.setProgressName("审查开始");
            inner.setCheckTime(inspection.getExamineTime());
            examine.add(inner);
 
            for (SafetyFacilityProcessflow flow : page.getRecords()) {
                if ("通知补正".equals(flow.getProgressName()) || "企业补正".equals(flow.getProgressName()) || "审查通过".equals(flow.getProgressName()) || "审查否决".equals(flow.getProgressName())) {
                    examine.add(flow);
                }
                if ("审查否决".equals(flow.getProgressName()) || "审查通过".equals(flow.getProgressName())) {
                    examineFinalResolution = flow.getResolution();
                }
            }
        }
 
        if (progress > 10) { // 构建评审全流程
            SafetyFacilityProcessflow inner = new SafetyFacilityProcessflow();
            inner.setProgressName("评审开始");
            inner.setCheckTime(inspection.getReviewTime());
            review.add(inner);
 
            for (SafetyFacilityProcessflow flow : page.getRecords()) {
                if ("评审反馈".equals(flow.getProgressName()) || "企业反馈".equals(flow.getProgressName()) || "评审通过".equals(flow.getProgressName()) || "评审否决".equals(flow.getProgressName())) {
                    review.add(flow);
                }
                if ("评审通过".equals(flow.getProgressName()) || "评审否决".equals(flow.getProgressName())) {
                    reviewFinalResolution = flow.getResolution();
                }
            }
        }
 
        if (progress == 30) {
            if (inspection.getType() == 1) {
                SafetyFacilityProcessflow f1 = new SafetyFacilityProcessflow();
                f1.setProgressName("评审通过");
                f1.setResult("评审通过");
                f1.setResolution(reviewFinalResolution);
                f1.setChildFlow(review);
                f1.setLinkInspectionId(inspectionId);
                list.add(f1);
            }
 
            SafetyFacilityProcessflow f = new SafetyFacilityProcessflow();
            f.setProgressName("审查通过");
            f.setResult("耗时:" + inspection.getExamineTaketime());
            f.setResolution("详情查看审查意见书");
            f.setChildFlow(examine);
            f.setLinkInspectionId(inspectionId);
            list.add(f);
 
            SafetyFacilityProcessflow ff = new SafetyFacilityProcessflow();
            ff.setProgressName("已完成");
            ff.setLinkInspectionId(inspectionId);
            list.add(ff);
        }
        if (progress >= 20 && progress < 30) {
            if (inspection.getType() == 1) {
                SafetyFacilityProcessflow f1 = new SafetyFacilityProcessflow();
                f1.setProgressName("评审通过");
                f1.setResult("评审通过");
                f1.setLinkInspectionId(inspectionId);
                f1.setResolution(reviewFinalResolution);
                f1.setChildFlow(review);
                list.add(f1);
            }
 
            SafetyFacilityProcessflow f = new SafetyFacilityProcessflow();
            if (progress == 20)
                f.setProgressName("待审查");
            if (progress == 21)
                f.setProgressName("审查中");
            if (progress == 29)
                f.setProgressName("待企业补正");
            if (progress == 22){
                f.setProgressName("审查否决");
                f.setResolution(examineFinalResolution);
            }
            f.setChildFlow(examine);
            list.add(f);
        }
 
        if (progress > 10 && progress < 20) {
            SafetyFacilityProcessflow f = new SafetyFacilityProcessflow();
 
            if (progress == 11)
                f.setProgressName("评审中");
            if (progress == 19)
                f.setProgressName("待企业反馈");
            if (progress == 12){
                f.setProgressName("评审否决");
                f.setResolution(reviewFinalResolution);
            }
            f.setChildFlow(review);
            list.add(f);
        }
 
        page.setRecords(list);
        return success(page);
    }
 
    @ApiOperation("企业新增审查")
    @PostMapping("/add")
    @ApiImplicitParams({ @ApiImplicitParam(name = "submitDate", value = "提交日期(可为空默认当前时间)", required = false),
            @ApiImplicitParam(name = "type", value = "类别(1:安全设施设计审查,2:安全条件审查)"),
            @ApiImplicitParam(name = "projectName", value = "项目名称"),
            @ApiImplicitParam(name = "progress", required = false, value = "进度(0:待受理,1:已受理,10:待评审,11:评审中,12:评审否决,19:待企业反馈,20:待审查,21:审查中,29:待企业补正,22:审查否决,30:完成)"),
            @ApiImplicitParam(name = "expert", value = "审查专家", required = false),
            @ApiImplicitParam(name = "contact", value = "联系人", required = false),
            @ApiImplicitParam(name = "telephone", value = "联系电话", required = false),
            @ApiImplicitParam(name = "company", value = "企业名称", required = false) })
    public Msg add(@RequestBody SafetyFacilityInspection param) {
        String genId = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli() + "" + (int) (Math.random() * 900 + 100);
        param.setId(Long.valueOf(genId));
        Date date = new Date();
        safetyFacilityInspectionService.addOne(param, this.getUser());
 
        SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
        flow.setCheckTime(date);
        flow.setProgressName("资料提交");
        flow.setResult("资料提交");
        flow.setResolution("开始");
        flow.setLinkInspectionId(Long.valueOf(genId));
        flow.setProcessBy(this.getUser().getRealname());
        safetyFacilityProcessflowService.addOne(flow, this.getUser());
 
        SafetyFacilityProcessflow flowd = new SafetyFacilityProcessflow();
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.SECOND, 1);
 
        flowd.setCheckTime(c.getTime());
        flowd.setProgressName("待受理");
        flowd.setLinkInspectionId(Long.valueOf(genId));
        safetyFacilityProcessflowService.addOne(flowd, this.getUser());
 
        return success();
    }
    
    
    @ApiOperation("删除审查项目")
    @PostMapping("/delete")
    @ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public Msg delete(@RequestBody FilterObject filterObject) {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return failed("安全审查项目ID不能为空");
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());        
        safetyFacilityInspectionService.delOne(inspectionId, this.getUser());
        safetyFacilityProcessflowService.deleteBylinkInspectionId(inspectionId, this.getUser());
        return success();
    }
 
    @ApiOperation("获取审查专家列表")
    @PostMapping("/expert")
    @ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "每页行数") })
    public Msg getExpert(@RequestParam(defaultValue = "0") Integer pageIndex,@RequestParam(defaultValue = "10") Integer pageSize, String realname) {
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize);
        HashMap<String, Object> condition = new HashMap<String, Object>();
        condition.put("job", "审查");
        condition.put("company", "危化处");
        if (StringUtils.isNotBlank(realname)) {
            condition.put("realname", realname.trim());
        }
 
        pageInfo.setCondition(condition);
        userService.selectExpertUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @ApiOperation("危化处业务处理")
    @PostMapping("/dealCheck")
    @ApiImplicitParams({ @ApiImplicitParam(name = "acceptTime", value = "选择受理时间(默认当前时间)", required = false),
            @ApiImplicitParam(name = "reviewTime", value = "自定义评审开始时间", required = false),
            @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public Msg dealCheck(@RequestBody FilterObject filterObject) throws ParseException {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return failed("安全审查项目ID不能为空");
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
        String acceptTimeString = null;
        if (inspection.getProgress() == 0) {
            if (inspection.getType() == 1) {
                if (filterObject.getFilter().get("acceptTime") != null && StringUtils.isNotBlank(filterObject.getFilter().get("acceptTime").toString())) {
                    acceptTimeString = filterObject.getFilter().get("acceptTime").toString();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    inspection.setAcceptTime(simpleDateFormat.parse(acceptTimeString));
                } else
                    inspection.setAcceptTime(new Date());
                inspection.setProgress(1);
 
                SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
                flow.setCheckTime(new Date());
                flow.setProgressName("已受理");
                flow.setResult("选择受理时间");
                flow.setLinkInspectionId(inspectionId);
                flow.setProcessBy(this.getUser().getRealname());
                safetyFacilityProcessflowService.addOne(flow, this.getUser());
                safetyFacilityInspectionService.modOne(inspection, getUser());
                safetyFacilityProcessflowService.modPending(inspectionId, this.getUser()); // 删除待处理流程记录
            }
            if (inspection.getType() == 2) {
                Date date = new Date();
                if (filterObject.getFilter().get("acceptTime") != null && StringUtils.isNotBlank(filterObject.getFilter().get("acceptTime").toString())) {
                    acceptTimeString = filterObject.getFilter().get("acceptTime").toString();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    inspection.setAcceptTime(simpleDateFormat.parse(acceptTimeString));
                } else
                    inspection.setAcceptTime(date);
                inspection.setProgress(20);
 
                SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
                flow.setCheckTime(date);
                flow.setProgressName("已受理");
                flow.setResult("选择受理时间");
                flow.setLinkInspectionId(inspectionId);
                flow.setProcessBy(this.getUser().getRealname());
                safetyFacilityProcessflowService.addOne(flow, this.getUser());
                safetyFacilityProcessflowService.modPending(inspectionId, this.getUser()); // 删除待处理流程记录
 
                SafetyFacilityProcessflow flow1 = new SafetyFacilityProcessflow();
                Calendar c = Calendar.getInstance();
                c.setTime(date);
                c.add(Calendar.SECOND, 1);
                flow1.setProgressName("待审查");
                flow1.setCheckTime(c.getTime());
                flow1.setLinkInspectionId(inspectionId);
                flow1.setProcessBy(this.getUser().getRealname());
                safetyFacilityProcessflowService.addOne(flow1, this.getUser());            
                safetyFacilityInspectionService.modOne(inspection, getUser());
            }
            return success();
        }
        if (inspection.getProgress() == 1) {
            if (filterObject.getFilter().get("reviewTime") != null && StringUtils.isNotBlank(filterObject.getFilter().get("reviewTime").toString())) {
                acceptTimeString = filterObject.getFilter().get("reviewTime").toString();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                inspection.setReviewTime(simpleDateFormat.parse(acceptTimeString));
            } else
                inspection.setReviewTime(new Date());
            inspection.setProgress(10);
 
            SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
            flow.setCheckTime(new Date());
            flow.setProgressName("待评审");
            flow.setResult("业务流转");
            flow.setLinkInspectionId(inspectionId);
            flow.setProcessBy(this.getUser().getRealname());
            safetyFacilityProcessflowService.addOne(flow, this.getUser());
 
            safetyFacilityInspectionService.modOne(inspection, getUser());
 
            return success();
 
        }
        return failed("处理失败!");
    }
 
    @ApiOperation("业务处分配审查专家")
    @PostMapping("/dealExamine")
    @ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true),
            @ApiImplicitParam(name = "expert", value = "审查专家ID(多个ID中间逗号分隔)"),
            @ApiImplicitParam(name = "examineTime", value = "审查开始时间") })
    public Msg dealExamine(@RequestBody FilterObject filterObject) throws ParseException {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return failed("安全审查项目ID不能为空");
 
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
 
        int currentprocess = inspection.getProgress();
        if (currentprocess == 20) {
 
            inspection.setProgress(21);
            inspection.setExpert(filterObject.getFilter().get("expert") == null ? "" : filterObject.getFilter().get("expert").toString());
 
            if (filterObject.getFilter().get("examineTime") != null && StringUtils.isNotBlank(filterObject.getFilter().get("examineTime").toString())) {
                String examineTimeString = filterObject.getFilter().get("examineTime").toString();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                inspection.setExamineTime(simpleDateFormat.parse(examineTimeString));
            } else
                inspection.setExamineTime(new Date());
 
            safetyFacilityInspectionService.modOne(inspection, this.getUser());
            return success();
        } else {
            return failed("当前项目不在待审查状态,无法进行专家分配!");
        }
 
    }
 
    @ApiOperation("专家审查")
    @PostMapping("/expertExamine")
    @ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true),
            @ApiImplicitParam(name = "result", required = true, value = "评审反馈结果(9:否决驳回,2:需补正,1:审查通过)"),
            @ApiImplicitParam(name = "correctNo", required = false, value = "补正告知书编号"),
            @ApiImplicitParam(name = "correctPDFPath", required = false, value = "补正告知书路径"),
            @ApiImplicitParam(name = "emergency", value = "应急局通知人(多个ID中间逗号分隔)"),
            @ApiImplicitParam(name = "resolution", value = "反馈意见") })
    public Msg expertExamine(@RequestBody FilterObject filterObject) {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return failed("安全审查项目ID不能为空");
 
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId, this.getUser());
        int res = Integer.valueOf(filterObject.getFilter().get("result").toString());
        int currentprocess = inspection.getProgress();
        if (currentprocess == 20 || currentprocess == 21) {
 
            SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
            flow.setCheckTime(new Date());
            flow.setLinkInspectionId(inspectionId);
            flow.setProcessBy(this.getUser().getRealname());
            flow.setResolution(filterObject.getFilter().get("resolution") == null ? "" : filterObject.getFilter().get("resolution").toString());
            if (res == 9) {
                flow.setProgressName("审查否决");
                flow.setResult("否决驳回");
                inspection.setProgress(22);
            }
            if (res == 2) {
                flow.setProgressName("通知补正");
                inspection.setProgress(29);
                String correctNo = filterObject.getFilter().get("correctNo") == null ? "" : filterObject.getFilter().get("correctNo").toString();
                String newFilePath = filterObject.getFilter().get("correctPDFPath") == null ? "" : filterObject.getFilter().get("correctPDFPath").toString();
                flow.setResolution(newFilePath);
                flow.setResult(correctNo);
                inspection.setCorrectpdf(newFilePath);
            }
            if (res == 1) {
                flow.setProgressName("审查通过");
                flow.setResult("审查通过完成");
                inspection.setProgress(30);
 
                Date begin = inspection.getExamineTime();
 
                Calendar cal1 = Calendar.getInstance();
                cal1.setTime(begin);
                Calendar cal2 = Calendar.getInstance();
                cal2.setTime(new Date());
 
                Long diff = (cal2.getTimeInMillis() - cal1.getTimeInMillis()) / 60000;
                int day = diff.intValue() / 1440;
                int hour = (diff.intValue() % 1440) / 60;
                int min = (diff.intValue() % 1440) % 60;
                inspection.setExamineTaketime(day + "天" + hour + "小时" + min + "分钟");
 
                SimpleDateFormat pageno = new SimpleDateFormat("MMdd");
                int dateno = Integer.valueOf(pageno.format(new Date())) / 2;
                if (dateno < 100)
                    inspection.setExaminePageno("0" + dateno);
                else
                    inspection.setExaminePageno("" + dateno);
            }
 
            safetyFacilityProcessflowService.addOne(flow, this.getUser());
            safetyFacilityInspectionService.modOne(inspection, this.getUser());
 
            return success();
        } else {
            return failed("当前项目状态异常无法进行审查!");
        }
 
    }
 
    @ApiOperation("专家审查上传补正告知书")
    @PostMapping("/uploadCorrectPDF")
    @ApiImplicitParams({ @ApiImplicitParam(name = "file", value = "上传补正告知书(PDF)文件") })
    public Msg uploadCorrectPDF(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
        if (file.getSize() > 1024 * 1024 * 2) {
            return failed("文件超过2M无法上传");
        }
 
        String path = filePathConfig.getModule().get("correctPDF");
        String dcPath = filePathConfig.getDcPath();
        String originalFilename = file.getOriginalFilename();
        LocalDateTime now = LocalDateTime.now();
        File newFile = null;
 
        try {
            String key = UUID.randomUUID().toString().replace("-", "");
            String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
            path = path.replace("/", File.separator);
            String modulePath = now.getYear() + path + now.format(DateTimeFormatter.ofPattern("MMdd"));
            String newFilePath = modulePath + File.separator + key + suffix;
            String localPath = dcPath + newFilePath;
            newFile = new File(localPath);
            if (!newFile.exists() && !newFile.mkdirs()) {
                return failed("文件上传路径不存在!");
            }
            file.transferTo(newFile);
            return success(newFilePath);
        } catch (IOException e) {
            if (newFile != null && newFile.exists()) {
                newFile.delete();
            }
            return failed("文件上传异常!");
        }
    }
 
    @ApiOperation("补正告知书下载")
    @PostMapping("/downCorrectPDF")
    @ApiImplicitParams({ @ApiImplicitParam(name = "filename", value = "补正告知书文件名", required = true),
            @ApiImplicitParam(name = "correctNo", value = "补正告知书编号") })
    public void downCorrectPDF(@RequestBody FilterObject filterObject, HttpServletResponse response) throws Exception {
        if (filterObject.getFilter().get("filename") == null)
            return;
        String filepath = filterObject.getFilter().get("filename").toString();
        String correctNo = filterObject.getFilter().get("correctNo") == null ? "" : filterObject.getFilter().get("correctNo").toString();
        response.reset();
        response.addHeader("Access-Control-Allow-Origin", "*");
        response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        response.setContentType("application/octet-stream; charset=UTF-8");
        response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("补正告知书" + correctNo + ".pdf", StandardCharsets.UTF_8.name()));
        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        String dcPath = filePathConfig.getDcPath();
        File file = new File(dcPath + filepath);
        if (!file.exists()) {
            throw new BusinessException(ResultCodes.FILE_NOT_EXISIST);
        }
        response.addHeader("Content-Length", "" + file.length());
        FileInputStream inputStream = new FileInputStream(file);
        byte[] b = new byte[inputStream.available()];
        inputStream.read(b);
        ServletOutputStream outputStream = response.getOutputStream();
        outputStream.write(b);
        outputStream.flush();
        inputStream.close();
    }
 
    @ApiOperation("审查意见书预览")
    @PostMapping("/viewExamineFile")
    @ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public void viewExamineFile(@RequestBody FilterObject filterObject, HttpServletResponse response) throws Exception {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return;
        Template template = freeMarkerConfigurer.getConfiguration().getTemplate("ReviewHtml.ftl", "UTF-8");
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("year", String.valueOf(LocalDate.now().getYear()));
        map.put("pageno", "0001");
        map.put("company", inspection.getCompany());
        map.put("projectName", inspection.getProjectName());
        map.put("contact", inspection.getContact());
        map.put("telephone", inspection.getTelephone());
 
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        map.put("submitDate", simpleDateFormat.format(new Date()));
 
        String duplicate = "";
        if (inspection.getCompany() != null) {
            duplicate = companyService.selectByName(inspection.getCompany()).getCity();
        }
        map.put("duplicate", duplicate + "应急管理局");
        response.setContentType("text/html;charset=utf-8");
        template.process(map, response.getWriter());
    }
 
    @ApiOperation("审查意见书下载")
    @PostMapping("/downExamineFile")
    @ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public void downExamineFile(@RequestBody FilterObject filterObject, HttpServletResponse response) throws Exception {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return;
        Template template = freeMarkerConfigurer.getConfiguration().getTemplate("ReviewHtml.ftl", "UTF-8");
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId, this.getUser());
 
        Map<String, Object> map = new HashMap<String, Object>();
        SimpleDateFormat year = new SimpleDateFormat("yyyy");
        map.put("year", year.format(inspection.getCreateTime()));
        map.put("pageno", inspection.getExaminePageno());
        map.put("company", inspection.getCompany());
        map.put("projectName", inspection.getProjectName());
        map.put("contact", inspection.getContact());
        map.put("telephone", inspection.getTelephone());
 
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        map.put("submitDate", simpleDateFormat.format(new Date()));
 
        String duplicate = "";
        if (inspection.getCompany() != null) {
            duplicate = companyService.selectByName(inspection.getCompany()).getCity();
        }
        map.put("duplicate", duplicate + "应急管理局");
        response.setHeader("content-Type", "application/msword");
        String fileName = URLEncoder.encode("审查意见书", "UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".doc");
        template.process(map, response.getWriter());
    }
 
    @ApiOperation("安科院评审反馈")
    @PostMapping("/reviewFeedback")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "result", required = true, value = "评审反馈结果(9:否决驳回,2:需问题反馈,1:通过并流转到业务处室)"),
            @ApiImplicitParam(name = "resolution", value = "反馈意见"),
            @ApiImplicitParam(name = "reviewTime", value = "评审开始时间", required = true),
            @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public Msg reviewFeedback(@RequestBody FilterObject filterObject) throws ParseException {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return failed("安全审查项目ID不能为空");
        if (filterObject.getFilter().get("result") == null)
            return failed("评审反馈结果不能为空");
        if (filterObject.getFilter().get("reviewTime") == null)
            return failed("请选择评审开始时间");
 
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        int res = Integer.valueOf(filterObject.getFilter().get("result").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
 
        int currentprocess = inspection.getProgress();
        String timeString = filterObject.getFilter().get("reviewTime").toString();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        inspection.setReviewTime(simpleDateFormat.parse(timeString));
 
        if (currentprocess == 10 || currentprocess == 11) {
            SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
            Date date = new Date();
            flow.setCheckTime(date);
            flow.setLinkInspectionId(inspectionId);
            flow.setProcessBy(this.getUser().getRealname());
            flow.setResolution(filterObject.getFilter().get("resolution") == null ? "" : filterObject.getFilter().get("resolution").toString());
            if (res == 9) {
                flow.setProgressName("评审否决");
                flow.setResult("否决驳回");
                inspection.setProgress(12);
            }
            if (res == 2) {
                flow.setProgressName("评审反馈");
                flow.setResult("需问题反馈");
                inspection.setProgress(19);
            }
            if (res == 1) {
                flow.setProgressName("评审通过");
                flow.setResult("通过并流转到业务处室");
                inspection.setProgress(20);
            }
 
            safetyFacilityProcessflowService.addOne(flow, this.getUser());
            safetyFacilityInspectionService.modOne(inspection, this.getUser());
            safetyFacilityProcessflowService.modPending(inspectionId, this.getUser()); // 删除待处理流程记录
 
            if (res == 1) {
                SafetyFacilityProcessflow flow1 = new SafetyFacilityProcessflow();
                Calendar c = Calendar.getInstance();
                c.setTime(date);
                c.add(Calendar.SECOND, 1);
                flow1.setProgressName("待审查");
                flow1.setCheckTime(c.getTime());
                flow1.setLinkInspectionId(inspectionId);
                flow1.setProcessBy(this.getUser().getRealname());
                safetyFacilityProcessflowService.addOne(flow1, this.getUser());
            }
 
            return success();
        } else {
            return failed("当前项目不在评审环节,不能进行评审!");
        }
 
    }
 
    @ApiOperation("企业提交反馈")
    @PostMapping("/companySubmission")
    @ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public Msg companySubmission(@RequestBody FilterObject filterObject) {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return failed("安全审查项目ID不能为空");
 
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
 
        int currentprocess = inspection.getProgress();
        if (currentprocess == 19) {
            SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
            flow.setCheckTime(new Date());
            flow.setLinkInspectionId(inspectionId);
            flow.setProcessBy(this.getUser().getRealname());
            flow.setProgressName("企业反馈");
            flow.setResult("已线下提交反馈资料");
            safetyFacilityProcessflowService.addOne(flow, this.getUser());
 
            inspection.setProgress(11);
            safetyFacilityInspectionService.modOne(inspection, this.getUser());
            return success();
        } else {
            return failed("当前项目不在待提交反馈状态,企业无法提交反馈!");
        }
    }
 
    @ApiOperation("获取审查项目对应的当地(市、州)级应急局所有人")
    @PostMapping("/getEmergencyInfo")
    @ApiImplicitParams({ @ApiImplicitParam(name = "pageIndex", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "每页行数"),
            @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public Msg getEmergencyInfo(@RequestBody FilterObject filterObject) {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return failed("安全审查项目ID不能为空");
 
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
 
        String duplicate = null;
        if (inspection.getCompany() != null) {
            duplicate = companyService.selectByName(inspection.getCompany()).getCity();
        } else {
            return failed("当前安全审查项目没有归属地!");
        }
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        Integer pageIndex = filterObject.getPageIndex() == null ? 1 : filterObject.getPageIndex();
        Integer pageSize = filterObject.getPageSize() == null ? 10 : filterObject.getPageSize();
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize);
        HashMap<String, Object> condition = new HashMap<String, Object>();
        condition.put("company", duplicate);
        pageInfo.setCondition(condition);
        userService.selectSuperviseUserDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @ApiOperation("企业提交补正")
    @PostMapping("/companySubcorrect")
    @ApiImplicitParams({ @ApiImplicitParam(name = "linkInspectionId", value = "安全审查项目ID", required = true) })
    public Msg companySubcorrect(@RequestBody FilterObject filterObject) {
        if (filterObject.getFilter().get("linkInspectionId") == null)
            return failed("安全审查项目ID不能为空");
 
        Long inspectionId = Long.valueOf(filterObject.getFilter().get("linkInspectionId").toString());
        SafetyFacilityInspection inspection = safetyFacilityInspectionService.selectByPrimaryKey(inspectionId,this.getUser());
 
        int currentprocess = inspection.getProgress();
        if (currentprocess == 29) {
            SafetyFacilityProcessflow flow = new SafetyFacilityProcessflow();
            flow.setCheckTime(new Date());
            flow.setLinkInspectionId(inspectionId);
            flow.setProcessBy(this.getUser().getRealname());
            flow.setProgressName("企业补正");
            flow.setResult("已线下提交补正材料");
            safetyFacilityProcessflowService.addOne(flow, this.getUser());
 
            inspection.setProgress(21);
            safetyFacilityInspectionService.modOne(inspection, this.getUser());
            return success();
        } else {
            return failed("当前项目不在待提交补正状态,企业无法提交补正!");
        }
    }
 
}