whycxzp
2022-07-27 d4d0c3614930df9a7877ba353cca97db6c99cdc4
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.mapper.ProductBomApprovingMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class WorksheetLinkService {
 
    @Resource
    private WorksheetMainService mainService;
 
    @Resource
    private WorksheetLinkMapper linkMapper;
 
    @Autowired
    private ProductBomApprovingMapper approvingMapper;
 
    @Autowired
    private ProductBomService bomService;
 
    @Autowired
    private ProductBomHistoryService historyService;
 
    @Transactional
    public void audit(WorksheetLink link) {
        link.setDealTime(new Date());
        //更新节点信息
        linkMapper.updateById(link);
        if(link.getLinkStatus() == 2){ //驳回
            //驳回到员工进行处理
            //查询工单的员工
            Long createUserId = mainService.getInfoById(link.getMainId()).getCreateUserId();
            WorksheetLink link2 = new WorksheetLink();
            link2.setMainId(link.getMainId());
            link2.setParentId(link.getId());
            link2.setDealUserId(createUserId);
            link2.setDealType(0);
            link2.setDealDesc("工单被经理驳回,驳回信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(0);
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),0);
        }else{
            //进入下一节点,总经理审批
            WorksheetLink link2 = new WorksheetLink();
            link2.setMainId(link.getMainId());
            link2.setParentId(link.getId());
            link2.setDealUserId(link.getNextUser());
            link2.setDealType(2);
            link2.setDealDesc("工单被经理审核通过,信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(1);
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),2);
        }
    }
 
    @Transactional
    public void approve(WorksheetLink link) {
        link.setDealTime(new Date());
        //更新节点信息
        linkMapper.updateById(link);
        if(link.getLinkStatus() == 2){ //驳回
            //驳回到员工进行处理
            //查询工单的员工
            Long createUserId = mainService.getInfoById(link.getMainId()).getCreateUserId();
            WorksheetLink link2 = new WorksheetLink();
            link2.setMainId(link.getMainId());
            link2.setParentId(link.getId());
            link2.setDealUserId(createUserId);
            link2.setDealType(0);
            link2.setDealDesc("工单被经理驳回,驳回信息:"+link.getDealReason());
            link2.setLinkStatus(0);
            link2.setEnableArchive(0);
            linkMapper.insert(link2);
            //更新主表状态
            mainService.updateStatusById(link.getMainId(),0);
        }else{
            //审批通过,更新主表状态
            mainService.updateEndStatusById(link.getMainId(),"完结",5);
            //将产品文件复制至正式路径
            QueryWrapper<ProductBomApproving> query = Wrappers.query();
            query.eq("main_id",link.getMainId());
            List<ProductBomApproving> approvingList = approvingMapper.selectList(query);
 
            //增加->增加部件(增加记录,同时所有eVersion+1)
            //修改->修改部件图纸,修改部件非图纸(增加记录,同时修改非原部件的所有eVersion+1)
            //删除? TODO 需要约定逻辑
 
            //查询部件最新的版本号
            Integer currentVersion = bomService.getProduct(approvingList.get(0).getParentModel()).getVersion();
            if(currentVersion==null){
                currentVersion = 0;
            }
            Integer nextVersion = currentVersion+1;
            //更新到product_bom_history,增加进去的需要sVersion和eVersion一致
            //增加所有部件,排查出相关的原部件,非也是更新
            List<ProductBomHistory> currentHistoryList = historyService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion);
            List<String> currentSubNameList = currentHistoryList.stream().map(ProductBomHistory::getSubName).collect(Collectors.toList());
 
            List<ProductBomHistory> newHistoryList = new LinkedList<>();
            approvingList.forEach(approvingBom->{
                if(currentSubNameList.contains(approvingBom.getSubName())){
                    approvingBom.setVersion(1);
                }else{
                    approvingBom.setVersion(0);
                }
                //转化为productBomHistory
                ProductBomHistory his = new ProductBomHistory();
                his.setCategory(approvingBom.getCategory());
                his.setCreateDate(approvingBom.getCreateDate());
                his.setDwgUrl(approvingBom.getDwgUrl());
                his.setEVersion(nextVersion);
                his.setFileUrl(approvingBom.getFileUrl());
                his.setMaterial(approvingBom.getMaterial());
                his.setNotes(approvingBom.getNotes());
                his.setParentCode(approvingBom.getParentCode());
                his.setParentModel(approvingBom.getParentModel());
                his.setParentName(approvingBom.getParentName());
                his.setParentVersion(approvingBom.getParentVersion());
                his.setPictureUrl(approvingBom.getPictureUrl());
                his.setProducer(approvingBom.getProducer());
                his.setQuantity(approvingBom.getQuantity());
                his.setSubCode(approvingBom.getSubCode());
                his.setSubModel(approvingBom.getSubModel());
                his.setSubName(approvingBom.getSubName());
                his.setSurfaceDetail(approvingBom.getSurfaceDetail());
                his.setSVersion(nextVersion);
                his.setThickness(approvingBom.getThickness());
                his.setType(approvingBom.getType());
                his.setUnit(approvingBom.getUnit());
                his.setUpdateDate(approvingBom.getUpdateDate());
                his.setUpUser(approvingBom.getUpUser());
 
                newHistoryList.add(his);
            });
            //本次审核中子件被修改的子件集合
            List<String> approvingUpdateSubNameList = approvingList.stream().filter(approvingBom -> approvingBom.getVersion() == 1).map(ProductBomApproving::getSubName).collect(Collectors.toList());
 
            historyService.addBatch(newHistoryList);
            /*更新产品的当前版本,更新到最新的版本*/
            //当前版本的所有bom的eVersion更新,排除被修改的子件
            List<ProductBomHistory> newVersionCurrentHistoryList = currentHistoryList.stream()
                    .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName()))
                    .collect(Collectors.toList());
            newVersionCurrentHistoryList.forEach(history->{history.setEVersion(nextVersion);});
            historyService.updateVersionBatch(newVersionCurrentHistoryList);
 
            /*更新到product_bom*/
            //查询新的版本
            List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion);
            bomService.updateNewBom(newBomList);
 
            /*String projectDir = CommonUtil.getProjectDir();
            FileUtil.copyDir()*/
 
 
            //将产品bom表的url修正,更新到正式表
        }
    }
 
    /**
     * 获取节点信息(包含main表)列表
     * @param id
     * @return
     */
    public List<WorksheetLink> getInfoList(Long id) {
        return linkMapper.getInfoList(id);
    }
 
    /**
     *
     * @param userId 总经理对应的userId
     * @param statusExp 0:未审批,1:已审批(包含状态值1,2)
     * @return
     */
    public List<WorksheetMain> getInfoList2(Long userId, int statusExp) {
        return linkMapper.getInfoList2(userId,statusExp);
    }
 
    /**
     *
     * @param userId 总经理对应的userId
     * @param statusExp 0:未审批,1:已审批(包含状态值1,2)
     * @return
     */
    public List<WorksheetMain> getInfoList3(Long userId, int statusExp) {
        return linkMapper.getInfoList3(userId,statusExp);
    }
 
    public DocUser getApprovingUser(Integer mainId) {
        return linkMapper.getApprovingUser(mainId);
    }
}