whycxzp
2022-12-05 bac7755aa3aea1705caf870c4318803186484e9c
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.config.EnumWorksheetType;
import com.whyc.dto.MailDTO;
import com.whyc.dto.Response;
import com.whyc.dto.WorksheetMainDTO;
import com.whyc.dto.WorksheetMainDTO2;
import com.whyc.mapper.DocUserMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.mapper.WorksheetMainMapper;
import com.whyc.pojo.*;
import com.whyc.util.CommonUtil;
import com.whyc.util.Zip4jUtil;
import org.aspectj.util.FileUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
public class WorksheetMainService {
 
    @Resource
    private WorksheetMainMapper mainMapper;
 
    @Resource
    private WorksheetLinkMapper linkMapper;
 
    @Autowired
    @Lazy
    private WorksheetLinkService linkService;
 
    @Resource
    private DocUserMapper userMapper;
 
    @Autowired
    @Lazy
    private ProductBomApprovingService approvingService;
 
    @Autowired
    private ProductApprovingService paService;
 
    @Autowired
    private MaterialProductApprovingService cpApprovingService;
 
    @Autowired
    private MaterialApprovingService mApprovingService;
 
    @Autowired
    private MaterialService mService;
 
    @Autowired
    private ProductBomService pbService;
 
    @Autowired
    private MaterialProductHistoryService cphService;
 
    @Autowired
    private ProductSoftwareApprovingService psaService;
 
    @Autowired
    private ProductSoftwareService productSoftwareService;
 
    @Autowired
    private ProductService productService;
 
    @Autowired
    private ProductHistoryService productHistoryService;
 
    @Autowired
    private MailService mailService;
 
    @Autowired
    private ProcedureDocApprovingService procedureDocApprovingService;
 
    @Transactional
    public boolean submit(WorksheetMain main, DocUser user) throws IOException {
        main.setType(1);
        ProductApproving productApproving = main.getProductApproving();
        List<ProductBomApproving> bomList = productApproving.getBomApprovingList();
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
        if(user.getRoleId().equals("1001")){
            if(main.getId()==null) {
                main.setLevel(2);
                main.setStatus(1);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(1);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(0);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1002")){
            if(main.getId()==null) {
                main.setLevel(1);
                main.setStatus(2);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(2);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(1);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1003")){
            main.setLevel(0);
            main.setStatus(5);
            mainMapper.insert(main);
        }else{
            return false;
        }
        //产品bom/图纸图片提交
        if(productApproving.getCustomCode()!=null && bomList.get(0).getId()!=null) { //与前端约定 定制表单号关联产品,则关联的产品id写入id
            Product product = productService.getById(bomList.get(0).getId());
            List<ProductBom> productBomList = pbService.getBomByProductId(bomList.get(0).getId());
            //product下的图纸复制到新的审批路径
            String rootFile = CommonUtil.getRootFile();
            String dateFormat = new SimpleDateFormat("YYYY-MM").format(new Date());
            long timeStamp = System.currentTimeMillis();
            String filePath = rootFile + "product_approving" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp;
            String inFilePath = rootFile + "product" + File.separator + product.getParentModel() + File.separator + "standard"+ File.separator + product.getVersion();
            File parentFile = new File(filePath);
            //FileCopyUtils.copy(new File(inFilePath),parentFile);
            FileUtil.copyDir(new File(inFilePath),parentFile);
            productApproving.setFileUrl(filePath);
            bomList.clear();
            productBomList.forEach(bom->{
                ProductBomApproving approving = new ProductBomApproving();
                approving.setCategory(bom.getCategory());
                approving.setSubCode(bom.getSubCode());
                approving.setSubName(bom.getSubName());
                approving.setSubModel(bom.getSubModel());
                approving.setUnit(bom.getUnit());
                approving.setQuantity(bom.getQuantity());
                approving.setProducer(bom.getProducer());
                approving.setMaterial(bom.getMaterial());
                approving.setThickness(bom.getThickness());
                approving.setSurfaceDetail(bom.getSurfaceDetail());
                approving.setNotes(bom.getNotes());
 
                bomList.add(approving);
            });
        }
        //冻结(不启用)已存在的产品编码+定制保单号
        productService.deleteByParentCodeAndCustomCode(productApproving.getParentCode(),productApproving.getCustomCode());
        productHistoryService.updateEnabledStatus(productApproving.getParentCode(),productApproving.getCustomCode(),0);
 
        productApproving.setMainId(main.getId());
        productApproving.setCreateTime(new Date());
        paService.insert(productApproving);
 
        bomList.forEach(bom->{
            //bom.setMainId(main.getId());
            bom.setProductApprovingId(productApproving.getId());
            bom.setUpUserId(user.getId());
            bom.setCreateDate(new Date());
            if(bom.getDwgUrl()==null){
                bom.setDwgUrl("");
            }else {
                bom.setDwgUrl(bom.getDwgUrl());
            }
            if(bom.getFileUrl()==null){
                bom.setFileUrl("");
            }else {
                bom.setFileUrl(bom.getFileUrl());
            }
            if(bom.getPictureUrl()==null){
                bom.setPictureUrl("");
            }else{
                bom.setPictureUrl(bom.getPictureUrl());
            }
        });
        approvingService.insert(bomList);
        return true;
    }
 
    public boolean MaterialProductSubmit(WorksheetMainDTO mainDTO, DocUser user) {
        List<MaterialProductApproving> approvingList = new LinkedList<>();
        WorksheetMain main = mainDTO.getMain();
        List<MaterialProductApproving> addedList = mainDTO.getAddedList();
        //List<MaterialProductApproving> replacedList = mainDTO.getReplacedList();
        List<MaterialProductApproving> removedList = mainDTO.getRemovedList();
 
        main.setType(EnumWorksheetType.MaterialProduct.getType());
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
        if(user.getRoleId().equals("1001")){
            if(main.getId()==null) {
                main.setLevel(2);
                main.setStatus(1);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(1);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(0);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1002")){
            if(main.getId()==null) {
                main.setLevel(1);
                main.setStatus(2);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(2);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(1);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1003")){
            main.setLevel(0);
            main.setStatus(5);
            mainMapper.insert(main);
        }else{
            return false;
        }
        //物料-产品审批提交
        if(addedList!=null && addedList.size()!=0){
            addedList.forEach(item->{
                item.setMainId(main.getId());
                item.setLinkType(1);
            });
            approvingList.addAll(addedList);
        }
        /*if(replacedList!=null && replacedList.size()!=0){
            replacedList.forEach(item->{
                item.setMainId(main.getId());
                item.setLinkType(2);
            });
            approvingList.addAll(replacedList);
        }*/
        if(removedList!=null && removedList.size()!=0){
            removedList.forEach(item->{
                item.setMainId(main.getId());
                item.setLinkType(-1);
            });
            approvingList.addAll(removedList);
        }
        cpApprovingService.insert(approvingList);
        return true;
    }
 
    public Response materialSubmit(WorksheetMain main, DocUser user) {
        Response<Object> response = new Response<>();
        List<MaterialApproving> mApprovingList = main.getMApprovingList();
        //判断是新增还是删除
        boolean isAdded = mApprovingList.get(0).getSubName()!=null;
        if(isAdded) { //新增
            //查询是否有 已生效或者已提交审批的 相同的物料
            List<Material> existMaterialList = new LinkedList<>();
            List<MaterialApproving> existCAList = new LinkedList<>();
 
            List<Material> materialList = mService.getList();
            List<MaterialApproving> cAList = mApprovingService.getListByStatus(1);
            for (int i = 0; i < mApprovingList.size(); i++) {
                MaterialApproving materialApproving = mApprovingList.get(i);
                for (int j = 0; j < materialList.size(); j++) {
                    if (materialApproving.getSubCode().equals(materialList.get(j).getSubCode())
                            && materialApproving.getSubName().equals(materialList.get(j).getSubName())
                            && materialApproving.getSubModel().equals(materialList.get(j).getSubModel())
                    ) {
                        existMaterialList.add(materialList.get(j));
                    }
                }
 
                for (int j = 0; j < cAList.size(); j++) {
                    if (materialApproving.getSubCode().equals(cAList.get(j).getSubCode())
                            && materialApproving.getSubName().equals(cAList.get(j).getSubName())
                            && materialApproving.getSubModel().equals(cAList.get(j).getSubModel())
                    ) {
                        existCAList.add(cAList.get(j));
                    }
                }
            }
 
            int existCASize = existCAList.size();
            int existMaterialSize = existMaterialList.size();
            if (existCASize != 0) {
                if (existMaterialSize != 0) {
                    response.setII(21, existCAList, existMaterialList, "重复提交:现有物料及正在进行审批的物料中,存在当前提交上传的物料");
                } else {
                    response.set(22, existCAList, "重复提交:正在进行审批的物料中,存在当前提交上传的物料");
                }
                return response;
            } else {
                if (existMaterialSize != 0) {
                    return response.setII(23, null, existMaterialList, "重复提交:现有物料中,存在当前提交上传的物料");
                }
            }
        }else{ //删除
            //判断是否在物料审批删除中,是否存在产品关联及关联审批
            MaterialApproving deleteApproving = new MaterialApproving();
            List<MaterialProductHistory> existMaterialProducts = new LinkedList<>();
            List<MaterialProductApproving> existMaterialProductApprovingList = new LinkedList<>();
            deleteApproving = mApprovingService.getListByMaterialId(mApprovingList.get(0).getMaterialId());
 
            //查看产品关联
            List<MaterialProductHistory> cphLatestExistList =  cphService.getLatestExistListByMaterialId(mApprovingList.get(0).getMaterialId());
            //查看产品关联审批
            List<MaterialProductApproving> cpaLatestExistList = cpApprovingService.getLatestExistListByMaterialId(mApprovingList.get(0).getMaterialId());
            if(deleteApproving!=null){
                return response.set(31,deleteApproving,"拒绝本次删除申请,当前物料正在进行删除审批");
            }
            if(cphLatestExistList!=null && cphLatestExistList.size()!=0){
                if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){
                    return response.setII(32,cpaLatestExistList,cphLatestExistList,"拒绝本次删除申请,当前散装已经关联产品及在产品关联审批");
                }else{
                    return response.setII(33,null,cphLatestExistList,"拒绝本次删除申请,当前物料在产品关联审批");
                }
            }else{
                if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){
                    return response.set(34,cpaLatestExistList,"拒绝本次删除申请,当前物料已经关联产品");
                }
            }
 
        }
        main.setType(EnumWorksheetType.Material.getType());
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
        if(user.getRoleId().equals("1001")){
            if(main.getId()==null) {
                main.setLevel(2);
                main.setStatus(1);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(1);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(0);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1002")){
            if(main.getId()==null) {
                main.setLevel(1);
                main.setStatus(2);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(2);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(1);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1003")){
            main.setLevel(0);
            main.setStatus(5);
            mainMapper.insert(main);
        }else{
            return response.set(3);
        }
        //物料-审批提交
        mApprovingList.forEach(cApproving->{
            cApproving.setCreateDate(new Date());
            cApproving.setMainId(main.getId());
            cApproving.setStatus(1);
        });
 
        mApprovingService.insert(mApprovingList);
        return response.set(1);
    }
 
    public Response productSoftwareSubmit(MultipartFile file, WorksheetMainDTO2 mainDTO, DocUser user) throws IOException {
        Response response = new Response();
        WorksheetMain main = mainDTO.getMain();
        ProductSoftwareApproving approving = mainDTO.getApproving();
        //首先校验文件名是否已存在
        String filename = file.getOriginalFilename();
        List<ProductSoftwareApproving> softwareApprovingList = psaService.getAll();
        List<ProductSoftware> softwareList = productSoftwareService.getAll();
        List<String> existApprovingList = softwareApprovingList.stream().map(ProductSoftwareApproving::getSoftwareName).collect(Collectors.toList());
        List<String> existList = softwareList.stream().map(ProductSoftware::getSoftwareName).collect(Collectors.toList());
 
        for (String existFilename:existList){
            if(filename.equals(existFilename)){
                return response.set(1,false,"软件文件名已存在");
            }
        }
        for (String existFilename:existApprovingList){
            if(filename.equals(existFilename)){
                return response.set(1,false,"软件文件名在审批列表中已存在");
            }
        }
 
        main.setType(1);
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
        if(user.getRoleId().equals("1001")){
            if(main.getId()==null) {
                main.setLevel(2);
                main.setStatus(1);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(1);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(0);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1002")){
            if(main.getId()==null) {
                main.setLevel(1);
                main.setStatus(2);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(2);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(1);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1003")){
            main.setLevel(0);
            main.setStatus(5);
            mainMapper.insert(main);
        }else{
            return response.set(1,false,"角色无法提交审批");
        }
        //转化为审批路径
        //检查是否为zip
        boolean isZip = Zip4jUtil.checkZipFileParam(file);
        if(!isZip){
            return response.set(1,false,"上传的文件格式不是zip");
        }
        //zip存储路径:doc_file/product_approving/${username}/{dateFormat}/${timeStamp}
        String rootFile = CommonUtil.getRootFile();
        String dateFormat = new SimpleDateFormat("YYYY-MM").format(new Date());
        long timeStamp = System.currentTimeMillis();
        String productSoftwarePath =  File.separator + "product_software" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp;
        String filePath = rootFile + productSoftwarePath;
        String originalFilename = file.getOriginalFilename();
        File zipFile = new File(filePath+File.separator+ originalFilename);
        if(!zipFile.exists()){
            zipFile.mkdirs();
        }
        file.transferTo(zipFile);
        approving.setSoftwareUrl("doc_file"+productSoftwarePath+File.separator+ originalFilename);
        approving.setSoftwareName(originalFilename);
        approving.setCreateTime(new Date());
        approving.setMainId(main.getId());
        //产品软件提交
        psaService.insert(approving);
        return response.set(1,true, "提交完成");
    }
 
    public WorksheetMain getInfoById(Integer id) {
        return mainMapper.selectById(id);
    }
 
    public void updateStatusById(Integer id,Integer status) {
        WorksheetMain main = new WorksheetMain();
        main.setId(id);
        main.setStatus(status);
        mainMapper.updateById(main);
    }
 
    public void updateEndStatusById(Integer id,String endReason,Integer status) {
        WorksheetMain main = new WorksheetMain();
        main.setId(id);
        main.setStatus(status);
        main.setEndReason(endReason);
        main.setEndTime(new Date());
        mainMapper.updateById(main);
    }
 
    /**
     * 用户对应的工作台数据分类
     * @param user
     * @return*/
    public Map<String, Integer> getStatusStatistic(DocUser user) {
        Map<String,Integer> map = new HashMap<>();
        switch (user.getRoleId()){
            //普通员工
            case "1001":
                {
                    //未处理(审批中)/已驳回/已审批
                    map.put("rejected",0);
                    map.put("approving",0);
                    map.put("approved",0);
                    QueryWrapper<WorksheetMain> query = Wrappers.query();
                    query.eq("create_user_id",user.getId());
                    List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
                    Map<Integer, List<WorksheetMain>> groupingList = worksheetMainList.stream().collect(Collectors.groupingBy(WorksheetMain::getStatus));
                    groupingList.forEach((status,mainList)->{
                        switch (status){
                            case 0:{
                                map.put("rejected",mainList.size());
                            }break;
                            case 1:
                            case 2:{
                                Integer addedMainCount= map.get("approving");
                                if(addedMainCount ==0){
                                    map.put("approving",mainList.size());
                                }else{
                                    map.put("approving",addedMainCount+mainList.size());
                                }
                            }break;
                            case 5:{
                                map.put("approved",mainList.size());
                            }break;
                        }
                    });
                }
                break;
            //项目经理
            case "1002":
                {
                    //待处理/已处理/属于自己-审批中/已驳回/已审批
                    //属于自己-审批中/已驳回/已审批
                    map.put("rejected",0);
                    map.put("approving",0);
                    map.put("approved",0);
                    map.put("handling",0);
                    map.put("handled",0);
 
                    QueryWrapper<WorksheetMain> query = Wrappers.query();
                    query.eq("create_user_id",user.getId());
                    List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
                    Map<Integer, List<WorksheetMain>> groupingList = worksheetMainList.stream().collect(Collectors.groupingBy(WorksheetMain::getStatus));
                    groupingList.forEach((status,mainList)->{
                        switch (status){
                            case 0:{
                                map.put("rejected",mainList.size());
                            }break;
                            case 2:{
                                map.put("approving",mainList.size());
                            }break;
                            case 5:{
                                map.put("approved",mainList.size());
                            }break;
                        }
                    });
                    //待处理/已处理
                    List<WorksheetLink> WorksheetLinkList = linkService.getInfoList(user.getId());
                    Map<Integer, List<WorksheetLink>> groupingLinkList = WorksheetLinkList.stream().collect(Collectors.groupingBy(WorksheetLink::getLinkStatus));
                    groupingLinkList.forEach((linkStatus,linkList)->{
                        List<WorksheetMain> mainList = new LinkedList<>();
                        linkList.forEach(link -> {mainList.add(link.getMain());});
                        switch (linkStatus){
                            case 0:{
                                map.put("handling",mainList.size());
                            }break;
                            case 1:
                            case 2:{
                                Integer addedMainCount= map.get("handled");
                                if(addedMainCount ==0){
                                    map.put("handled",mainList.size());
                                }else{
                                    map.put("handled",addedMainCount+mainList.size());
                                }
                            }break;
                        }
                    });
                }
                break;
            //总经理
            case "1003":
                {
                    //待处理/已审批
                    map.put("handling",0);
                    map.put("approved",0);
                    List<WorksheetLink> WorksheetLinkList = linkService.getInfoList(user.getId());
                    Map<Integer, List<WorksheetLink>> groupingLinkList = WorksheetLinkList.stream().collect(Collectors.groupingBy(WorksheetLink::getLinkStatus));
                    groupingLinkList.forEach((linkStatus,linkList)->{
                        List<WorksheetMain> mainList = new LinkedList<>();
                        linkList.forEach(link -> {mainList.add(link.getMain());});
                        switch (linkStatus){
                            case 0:{
                                map.put("handling",mainList.size());
                            }break;
                            case 1:
                            case 2:{
                                Integer addedMainCount= map.get("approved");
                                if(addedMainCount ==0){
                                    map.put("approved",mainList.size());
                                }else{
                                    map.put("approved",addedMainCount+mainList.size());
                                }
                            }break;
                        }
                    });
                }
                break;
        }
        //查询我的工单数量
        QueryWrapper<WorksheetMain> query = Wrappers.query();
        query.eq("create_user_id",user.getId());
        Integer count = mainMapper.selectCount(query);
        map.put("my",count);
 
        return map;
    }
 
    public WorksheetMain getLinkList(int id) {
         //判断是哪种类型的审批,返回不同的类型 具体数据
        Integer type = getInfoById(id).getType();
        if(type.intValue() == EnumWorksheetType.ProductBom.getType()) {
            WorksheetMain main = mainMapper.getLinkList(id);
            List<ProductBomApproving> pbaList = approvingService.getList(main.getProductApproving().getId());
            main.getProductApproving().setBomApprovingList(pbaList);
            return main;
        }else if(type.intValue() == EnumWorksheetType.Material.getType()){
            return mainMapper.getLinkListWithMaterials(id);
        }else{ //物料-产品
            return mainMapper.getLinkListWithMaterialProducts(id);
        }
    }
 
    public Response<PageInfo<WorksheetMain>> getApprovingListPage(DocUser user, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<WorksheetMain> query = Wrappers.query();
        query.eq("create_user_id",user.getId()).in("status",1,2).orderByDesc("id");
        List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
        //查询主表状态对应的子表
        worksheetMainList.forEach(main -> {
            main.setApprovingUser(linkService.getApprovingUser(main.getId()));
        });
        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
    }
 
    public Response<PageInfo<WorksheetMain>> getRejectedListPage(DocUser user, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<WorksheetMain> query = Wrappers.query();
        query.eq("create_user_id",user.getId()).in("status",0).orderByDesc("id");
        List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
    }
 
    public Response<PageInfo<WorksheetMain>> getApprovedListPage(DocUser user, int pageNum, int pageSize) {
        Response<PageInfo<WorksheetMain>> response = new Response<>();
        PageHelper.startPage(pageNum,pageSize);
        List<WorksheetMain> worksheetMainList = null;
        //自己的工单
        if(!user.getRoleId().equals("1003")){
            QueryWrapper<WorksheetMain> query = Wrappers.query();
            query.eq("create_user_id",user.getId()).in("status",5).orderByDesc("id");
            worksheetMainList = mainMapper.selectList(query);
 
        }else{
            //总经理,节点审批人为自己
            worksheetMainList = linkService.getInfoList2(user.getId(),1);
        }
        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
        return response.set(1,pageInfo);
    }
 
    public Response<PageInfo<WorksheetMain>> getHandlingListPage(DocUser user, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<WorksheetMain> worksheetMainList = linkService.getInfoList3(user.getId(),0);
        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
    }
 
    public Response<PageInfo<WorksheetMain>> getHandledListPage(DocUser user, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<WorksheetMain> worksheetMainList = linkService.getInfoList3(user.getId(),1);
        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
    }
 
    public WorksheetMain getInfo(int id) {
         return mainMapper.selectById(id);
    }
 
    public Response<PageInfo<WorksheetMain>> getMyList(int pageNum, int pageSize, DocUser user) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<WorksheetMain> query = Wrappers.query();
        query.eq("create_user_id",user.getId()).orderByDesc("id");
        List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
 
    }
 
    public Response addProductProcedureAndSOP(ProcedureDocApproving approving, DocUser user) throws IOException, MessagingException {
        WorksheetMain main = new WorksheetMain();
         //存储上传信息到主表,节点表
        //文件保存在/doc_file/procedure_approving/xxx.doc
        MultipartFile multipartFile = approving.getMultipartFile();
        String originalFilename = multipartFile.getOriginalFilename();
        String rootFile = CommonUtil.getRootFile();
        Date date = new Date();
        String suffixFilePath = "procedure_approving" + File.separator + date.getTime() + "_" + originalFilename;
        String outFilePath = rootFile + suffixFilePath;
        File outFile = new File(outFilePath);
        multipartFile.transferTo(outFile);
 
        main.setTitle(approving.getName());
        main.setDescription(approving.getDescription());
        main.setCreateUserId(user.getId());
        main.setBeginTime(date);
        main.setStatus(1);
        if(approving.getType()==1){
            main.setType(EnumWorksheetType.ProductProcedure.getType());
        }else{
            main.setType(EnumWorksheetType.SOP.getType());
        }
        mainMapper.insert(main);
 
        List<WorksheetLink> links = new LinkedList<>();
        WorksheetLink baseLink = new WorksheetLink();
        WorksheetLink linkFzr = new WorksheetLink();
        WorksheetLink linkBz = new WorksheetLink();
        WorksheetLink linkZz = new WorksheetLink();
        WorksheetLink linkPb = new WorksheetLink();
 
        baseLink.setMainId(main.getId());
        baseLink.setLinkStatus(0);
        baseLink.setCreateTime(date);
 
        BeanUtils.copyProperties(baseLink,linkFzr);
        BeanUtils.copyProperties(baseLink,linkBz);
        BeanUtils.copyProperties(baseLink,linkZz);
        BeanUtils.copyProperties(baseLink,linkPb);
 
        linkFzr.setDealUserId(approving.getFzr());
        linkBz.setDealUserId(approving.getBz());
        linkZz.setDealUserId(approving.getZz());
        linkPb.setDealUserId(approving.getPb());
        links.add(linkFzr);
        links.add(linkBz);
        links.add(linkZz);
        links.add(linkPb);
        linkMapper.insertBatchSomeColumn(links);
 
        //流程文档审批子表存入
        approving.setFile("doc_file"+ File.separator + suffixFilePath);
        approving.setMainId(main.getId());
        procedureDocApprovingService.insert(approving);
        //发送邮件给四个确认人
        QueryWrapper<DocUser> query = Wrappers.query();
        query.select("mail").in("id",approving.getFzr(),approving.getBz(),approving.getZz(),approving.getPb());
        List<DocUser> docUsers = userMapper.selectList(query);
        List<String> userMailList = docUsers.stream().map(DocUser::getMail).collect(Collectors.toList());
 
        MailDTO mailDTO = new MailDTO();
        mailDTO.setMailList(userMailList);
        if(approving.getType()==1){
            mailDTO.setTitle("【流程卡确认】"+main.getTitle());
            mailDTO.setContent(user.getName()+"在文档管理平台上传了产品流程卡,请及时确认");
        }else{
            mailDTO.setTitle("【SOP确认】"+main.getTitle());
            mailDTO.setContent(user.getName()+"在文档管理平台上传了SOP,请及时确认");
        }
        mailService.sendMail(mailDTO);
 
        return new Response().setII(1,"上传完成");
    }
}