lxw
2022-07-20 eb41a3b603f81d5aaf6ba0820cca7edcdfb688b6
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.dto.WorksheetMainDTO;
import com.whyc.mapper.DocUserMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.mapper.WorksheetMainMapper;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.ProductBomApproving;
import com.whyc.pojo.WorksheetLink;
import com.whyc.pojo.WorksheetMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sun.print.PSPrinterJob;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class WorksheetMainService {
 
    @Resource
    private WorksheetMainMapper mainMapper;
 
    @Resource
    private WorksheetLinkMapper linkMapper;
 
    @Resource
    private DocUserMapper userMapper;
 
    @Autowired
    private ProductBomApprovingService approvingService;
 
    @Transactional
    public boolean submit(WorksheetMainDTO mainDTO, DocUser user) {
        WorksheetMain main = mainDTO.getMain();
        List<ProductBomApproving> bomList = mainDTO.getBomList();
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
        if(user.getRoleId().equals("1001")){
            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")){
            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/图纸图片提交
        bomList.forEach(bom->bom.setMainId(main.getId()));
        approvingService.insert(bomList);
        return 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);
        mainMapper.updateById(main);
    }
 
    /**用户对应的工作台数据分类
     * @param user TODO*/
    public Map<String, WorksheetMain> getList(DocUser user) {
        Map<String,WorksheetMain> map = new HashMap<>();
        switch (user.getRoleId()){
            //普通员工
            case "1001":
                {
                    //未处理/已驳回/已审批
                    QueryWrapper<WorksheetMain> query = Wrappers.query();
                    query.eq("create_user_id",user.getId());
                    List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
                }
                break;
            //项目经理
            case "1002":
                {
                    //待处理/未处理/已驳回/已审批
 
                }
                break;
            //总经理
            case "1003":
                {
                    //待处理/已审批
                }
                break;
        }
 
        return null;
    }
 
    public WorksheetMain getLinkList(int id) {
        return mainMapper.getLinkList(id);
    }
}