|
...
|
...
|
@@ -2,9 +2,13 @@ package com.lframework.xingyun.sc.procurement.impl.change; |
|
2
|
2
|
|
|
3
|
3
|
import cn.hutool.core.bean.BeanUtil;
|
|
4
|
4
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
5
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
5
|
6
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
6
|
7
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
8
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
9
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
7
|
10
|
import com.github.pagehelper.PageInfo;
|
|
|
11
|
+import com.lframework.starter.bpm.service.FlowInstanceWrapperService;
|
|
8
|
12
|
import com.lframework.starter.common.exceptions.impl.DefaultClientException;
|
|
9
|
13
|
import com.lframework.starter.common.exceptions.impl.InputErrorException;
|
|
10
|
14
|
import com.lframework.starter.common.utils.Assert;
|
|
...
|
...
|
@@ -13,9 +17,7 @@ import com.lframework.starter.common.utils.StringUtil; |
|
13
|
17
|
import com.lframework.starter.web.core.annotations.oplog.OpLog;
|
|
14
|
18
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
|
15
|
19
|
import com.lframework.starter.web.core.components.security.SecurityUtil;
|
|
16
|
|
-import com.lframework.starter.web.core.utils.IdUtil;
|
|
17
|
|
-import com.lframework.starter.web.core.utils.PageHelperUtil;
|
|
18
|
|
-import com.lframework.starter.web.core.utils.PageResultUtil;
|
|
|
20
|
+import com.lframework.starter.web.core.utils.*;
|
|
19
|
21
|
import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
|
|
20
|
22
|
import com.lframework.starter.web.inner.entity.SysRole;
|
|
21
|
23
|
import com.lframework.starter.web.inner.service.system.SysRoleService;
|
|
...
|
...
|
@@ -45,6 +47,8 @@ public class ProcurementPlanChangeServiceImpl extends |
|
45
|
47
|
ServiceImpl<ProcurementPlanChangeMapper, ProcurementPlanChange> implements
|
|
46
|
48
|
ProcurementPlanChangeService {
|
|
47
|
49
|
|
|
|
50
|
+ private static final String BPM_FLAG = "PLAN_CHANGE";
|
|
|
51
|
+
|
|
48
|
52
|
@Resource
|
|
49
|
53
|
private ProcurementPlanService procurementPlanService;
|
|
50
|
54
|
@Resource
|
|
...
|
...
|
@@ -53,6 +57,8 @@ public class ProcurementPlanChangeServiceImpl extends |
|
53
|
57
|
private ProcurementPlanChangeLineMapper procurementPlanChangeLineMapper;
|
|
54
|
58
|
@Resource
|
|
55
|
59
|
private SysRoleService sysRoleService;
|
|
|
60
|
+ @Resource
|
|
|
61
|
+ private FlowInstanceWrapperService flowInstanceWrapperService;
|
|
56
|
62
|
|
|
57
|
63
|
|
|
58
|
64
|
private static final List<String> PROCESS_STATUSES = Arrays.asList(
|
|
...
|
...
|
@@ -90,7 +96,6 @@ public class ProcurementPlanChangeServiceImpl extends |
|
90
|
96
|
ProcurementPlanChange planChange = new ProcurementPlanChange();
|
|
91
|
97
|
BeanUtil.copyProperties(vo, planChange);
|
|
92
|
98
|
planChange.setId(IdUtil.getId());
|
|
93
|
|
- planChange.setProcessStatus("DRAFT");
|
|
94
|
99
|
if (roleCodes.contains("ltcgczg") || roleCodes.contains("ztcgczg")
|
|
95
|
100
|
|| roleCodes.contains("htcgeczg") || roleCodes.contains("htcgyczg")) {
|
|
96
|
101
|
planChange.setProcessNode("CGCZG");
|
|
...
|
...
|
@@ -140,7 +145,7 @@ public class ProcurementPlanChangeServiceImpl extends |
|
140
|
145
|
}
|
|
141
|
146
|
ProcurementPlanChange planChange = new ProcurementPlanChange();
|
|
142
|
147
|
BeanUtil.copyProperties(vo, planChange);
|
|
143
|
|
- this.updateById(entity);
|
|
|
148
|
+ this.updateById(planChange);
|
|
144
|
149
|
//保存或更新采购计划变更单明细
|
|
145
|
150
|
saveOrUpdateLines(vo.getProcurementPlanId(), vo.getLines());
|
|
146
|
151
|
}
|
|
...
|
...
|
@@ -168,7 +173,7 @@ public class ProcurementPlanChangeServiceImpl extends |
|
168
|
173
|
throw new InputErrorException("ID不能为空!");
|
|
169
|
174
|
}
|
|
170
|
175
|
|
|
171
|
|
- ProcurementPlanChange entity = this.getById(id);
|
|
|
176
|
+ ProcurementPlanChange entity = this.getBaseMapper().findById(id);
|
|
172
|
177
|
if (entity == null) {
|
|
173
|
178
|
throw new DefaultClientException("采购计划变更单不存在!");
|
|
174
|
179
|
}
|
|
...
|
...
|
@@ -186,6 +191,188 @@ public class ProcurementPlanChangeServiceImpl extends |
|
186
|
191
|
return bo;
|
|
187
|
192
|
}
|
|
188
|
193
|
|
|
|
194
|
+ @Override
|
|
|
195
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
196
|
+ @OpLog(type = OtherOpLogType.class, name = "采购计划变更单提交审核,ID:{}", params = {"#id"})
|
|
|
197
|
+ public void submit(String id) {
|
|
|
198
|
+ if (StringUtil.isBlank(id)) {
|
|
|
199
|
+ throw new InputErrorException("ID不能为空!");
|
|
|
200
|
+ }
|
|
|
201
|
+
|
|
|
202
|
+ ProcurementPlanChange entity = this.getById(id);
|
|
|
203
|
+ if (entity == null) {
|
|
|
204
|
+ throw new DefaultClientException("采购计划变更单不存在!");
|
|
|
205
|
+ }
|
|
|
206
|
+ String processNode = null;
|
|
|
207
|
+ String node = entity.getProcessNode();
|
|
|
208
|
+ if ("YWY".equals(node)) {
|
|
|
209
|
+ processNode = "QYJL";
|
|
|
210
|
+ } else if ("QYJL".equals(node)) {
|
|
|
211
|
+ processNode = "CGCZG";
|
|
|
212
|
+ } else if ("CGCZG".equals(node)) {
|
|
|
213
|
+ processNode = "GYGLKJHGLY";
|
|
|
214
|
+ }
|
|
|
215
|
+ LambdaUpdateWrapper<ProcurementPlanChange> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanChange.class)
|
|
|
216
|
+ .set(ProcurementPlanChange::getApprovalStatus, "AUDIT")
|
|
|
217
|
+ .set(ProcurementPlanChange::getProcessNode, processNode)
|
|
|
218
|
+ .eq(ProcurementPlanChange::getId, id);
|
|
|
219
|
+ getBaseMapper().update(updateWrapper);
|
|
|
220
|
+ ProcurementPlanChange procurementPlanChange = this.getBaseMapper().findById(id);
|
|
|
221
|
+ List<SysRole> sysRoleList = sysRoleService.getByUserId(SecurityUtil.getCurrentUser().getId());
|
|
|
222
|
+ String roleCode = null;
|
|
|
223
|
+ if (CollectionUtil.isNotEmpty(sysRoleList)) {
|
|
|
224
|
+ // 1. 提取角色列表中的所有 code,转换为 Set 集合,提升后续判断效率
|
|
|
225
|
+ Set<String> roleCodeSet = sysRoleList.stream()
|
|
|
226
|
+ .map(SysRole::getCode)
|
|
|
227
|
+ .collect(Collectors.toSet());
|
|
|
228
|
+
|
|
|
229
|
+ // 2. 判断是否包含采购主管相关的角色
|
|
|
230
|
+ if (roleCodeSet.contains("htcgeczg") || roleCodeSet.contains("htcgyczg")
|
|
|
231
|
+ || roleCodeSet.contains("ltcgczg") || roleCodeSet.contains("ztcgczg")) {
|
|
|
232
|
+ roleCode = "cgczg";
|
|
|
233
|
+ } else if (roleCodeSet.contains("qyjl")) {
|
|
|
234
|
+ // 3. 如果没有,继续判断是否包含区域经理
|
|
|
235
|
+ roleCode = "qyjl";
|
|
|
236
|
+ } else if (roleCodeSet.contains("nmcgkywy")) {
|
|
|
237
|
+ // 4. 如果还没有,继续判断是否包含内贸采购科业务员
|
|
|
238
|
+ roleCode = "nmcgkywy";
|
|
|
239
|
+ } else {
|
|
|
240
|
+ throw new DefaultClientException("当前角色无法发起审核!");
|
|
|
241
|
+ }
|
|
|
242
|
+ } else {
|
|
|
243
|
+ throw new DefaultClientException("当前角色无法发起审核!");
|
|
|
244
|
+ }
|
|
|
245
|
+ procurementPlanChange.setRoleCode(roleCode);
|
|
|
246
|
+ flowInstanceWrapperService.startInstance(BPM_FLAG, entity.getId(), BPM_FLAG, procurementPlanChange);
|
|
|
247
|
+ OpLogUtil.setVariable("id", id);
|
|
|
248
|
+ OpLogUtil.setExtra(entity);
|
|
|
249
|
+ }
|
|
|
250
|
+
|
|
|
251
|
+ @Override
|
|
|
252
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
253
|
+ @OpLog(type = OtherOpLogType.class, name = "取消采购计划变更单,ID:{}", params = {"#id"})
|
|
|
254
|
+ public void cancel(String id) {
|
|
|
255
|
+ if (StringUtil.isBlank(id)) {
|
|
|
256
|
+ throw new InputErrorException("ID不能为空!");
|
|
|
257
|
+ }
|
|
|
258
|
+
|
|
|
259
|
+ ProcurementPlanChange entity = this.getById(id);
|
|
|
260
|
+ if (entity == null) {
|
|
|
261
|
+ throw new DefaultClientException("采购计划变更单不存在!");
|
|
|
262
|
+ }
|
|
|
263
|
+ LambdaUpdateWrapper<ProcurementPlanChange> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanChange.class)
|
|
|
264
|
+ .set(ProcurementPlanChange::getApprovalStatus, "CANCEL")
|
|
|
265
|
+ .set(ProcurementPlanChange::getProcessNode, null)
|
|
|
266
|
+ .eq(ProcurementPlanChange::getId, id);
|
|
|
267
|
+ getBaseMapper().update(updateWrapper);
|
|
|
268
|
+
|
|
|
269
|
+ Wrapper<ProcurementPlan> parentWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
|
|
|
270
|
+ .set(ProcurementPlan::getChangeStatus, "CHANGED")
|
|
|
271
|
+ .eq(ProcurementPlan::getId, entity.getProcurementPlanId());
|
|
|
272
|
+ procurementPlanService.update(parentWrapper);
|
|
|
273
|
+
|
|
|
274
|
+ OpLogUtil.setVariable("id", id);
|
|
|
275
|
+ OpLogUtil.setExtra(entity);
|
|
|
276
|
+ }
|
|
|
277
|
+
|
|
|
278
|
+ @Override
|
|
|
279
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
280
|
+ @OpLog(type = OtherOpLogType.class, name = "更新采购计划变更单审核状态,ID:{}", params = {"#id"})
|
|
|
281
|
+ public void updateApprovalStatus(String id, String approvalStatus) {
|
|
|
282
|
+ if (StringUtil.isBlank(id) || StringUtil.isBlank(approvalStatus)) {
|
|
|
283
|
+ throw new InputErrorException("ID、审核状态不能为空!");
|
|
|
284
|
+ }
|
|
|
285
|
+
|
|
|
286
|
+ ProcurementPlanChange entity = this.getById(id);
|
|
|
287
|
+ if (entity == null) {
|
|
|
288
|
+ throw new DefaultClientException("采购计划变更单不存在!");
|
|
|
289
|
+ }
|
|
|
290
|
+
|
|
|
291
|
+ if ("PASS".equals(approvalStatus)) {
|
|
|
292
|
+ LambdaUpdateWrapper<ProcurementPlanChange> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanChange.class)
|
|
|
293
|
+ .set(ProcurementPlanChange::getApprovalStatus, approvalStatus)
|
|
|
294
|
+ .set(ProcurementPlanChange::getProcessNode, null)
|
|
|
295
|
+ .eq(ProcurementPlanChange::getId, id);
|
|
|
296
|
+ getBaseMapper().update(updateWrapper);
|
|
|
297
|
+
|
|
|
298
|
+ Wrapper<ProcurementPlan> parentWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
|
|
|
299
|
+ .set(ProcurementPlan::getChangeStatus, "CHANGED")
|
|
|
300
|
+ .eq(ProcurementPlan::getId, entity.getProcurementPlanId());
|
|
|
301
|
+ procurementPlanService.update(parentWrapper);
|
|
|
302
|
+ //todo 拆分分厂、生产买断操作申请单、生成合同,生成一份原始的计划数据(第一次变更)
|
|
|
303
|
+ } else if ("REFUSE".equals(approvalStatus)) {
|
|
|
304
|
+ List<SysRole> roles = sysRoleService.getByUserId(entity.getCreateById());
|
|
|
305
|
+ List<String> roleCodes = CollectionUtil.isEmpty(roles) ? new java.util.ArrayList<>()
|
|
|
306
|
+ : roles.stream().map(SysRole::getCode).collect(Collectors.toList());
|
|
|
307
|
+ String processNode = null;
|
|
|
308
|
+ if (roleCodes.contains("ltcgczg") || roleCodes.contains("ztcgczg")
|
|
|
309
|
+ || roleCodes.contains("htcgeczg") || roleCodes.contains("htcgyczg")) {
|
|
|
310
|
+ processNode = "CGCZG";
|
|
|
311
|
+ } else if (roleCodes.contains("qyjl")) {
|
|
|
312
|
+ processNode = "QYJL";
|
|
|
313
|
+ } else if (roleCodes.contains("nmcgkywy")) {
|
|
|
314
|
+ processNode = "YWY";
|
|
|
315
|
+ }
|
|
|
316
|
+
|
|
|
317
|
+ LambdaUpdateWrapper<ProcurementPlanChange> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanChange.class)
|
|
|
318
|
+ .set(ProcurementPlanChange::getApprovalStatus, approvalStatus)
|
|
|
319
|
+ .set(ProcurementPlanChange::getProcessNode, processNode)
|
|
|
320
|
+ .eq(ProcurementPlanChange::getId, id);
|
|
|
321
|
+ getBaseMapper().update(updateWrapper);
|
|
|
322
|
+ }
|
|
|
323
|
+
|
|
|
324
|
+ OpLogUtil.setVariable("id", id);
|
|
|
325
|
+ OpLogUtil.setExtra(entity);
|
|
|
326
|
+ }
|
|
|
327
|
+
|
|
|
328
|
+
|
|
|
329
|
+ @Override
|
|
|
330
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
331
|
+ @OpLog(type = OtherOpLogType.class, name = "采购计划变更单流程数据修改,ID:{}", params = {"#id"})
|
|
|
332
|
+ public void updateNoFlowInstance(Map<String, Object> map) {
|
|
|
333
|
+ try {
|
|
|
334
|
+ //流程编码
|
|
|
335
|
+ Object n = map.get("nodeCode");
|
|
|
336
|
+ String nodeCode = String.valueOf(n);
|
|
|
337
|
+
|
|
|
338
|
+ //审核状态
|
|
|
339
|
+ Object e = map.get("examStatus");
|
|
|
340
|
+ String examStatus = String.valueOf(e);
|
|
|
341
|
+ // 创建 ObjectMapper 实例
|
|
|
342
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
343
|
+ //先将 Map 序列化为 JSON 字符串,再反序列化为目标对象
|
|
|
344
|
+ String json = objectMapper.writeValueAsString(map);
|
|
|
345
|
+ UpdateProcurementPlanChangeVo vo = JsonUtil.parseObject(json, UpdateProcurementPlanChangeVo.class);
|
|
|
346
|
+ ProcurementPlanChange planChange = new ProcurementPlanChange();
|
|
|
347
|
+ BeanUtil.copyProperties(vo, planChange);
|
|
|
348
|
+ this.updateById(planChange);
|
|
|
349
|
+ //保存或更新采购计划变更单明细
|
|
|
350
|
+ saveOrUpdateLines(vo.getProcurementPlanId(), vo.getLines());
|
|
|
351
|
+ if ("PASS".equals(examStatus)) {
|
|
|
352
|
+ String processNode = null;
|
|
|
353
|
+ if ("plan_change_qyjl".equals(nodeCode)) {
|
|
|
354
|
+ processNode = "CGCZG";
|
|
|
355
|
+ } else if ("plan_change_ztcgczg".equals(nodeCode) || "plan_change_ltcgczg".equals(nodeCode)
|
|
|
356
|
+ || "plan_change_htcgyczg".equals(nodeCode) || "plan_change_htcgeczg".equals(nodeCode)) {
|
|
|
357
|
+ processNode = "GYGLKJHGLY";
|
|
|
358
|
+ } else if ("plan_change_gyglkjhgly".equals(nodeCode)) {
|
|
|
359
|
+ processNode = "GYGLKZLGLG";
|
|
|
360
|
+ } else if ("plan_change_gyglkzlglg".equals(nodeCode)) {
|
|
|
361
|
+ processNode = "GYGLKZG";
|
|
|
362
|
+ } else if ("plan_change_gyglkzg".equals(nodeCode)) {
|
|
|
363
|
+ processNode = "GYBZG";
|
|
|
364
|
+ } else if ("plan_change_gybzg".equals(nodeCode)) {
|
|
|
365
|
+ processNode = "YSFG";
|
|
|
366
|
+ }
|
|
|
367
|
+ LambdaUpdateWrapper<ProcurementPlanChange> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanChange.class)
|
|
|
368
|
+ .set(ProcurementPlanChange::getProcessNode, processNode)
|
|
|
369
|
+ .eq(ProcurementPlanChange::getId, vo.getId());
|
|
|
370
|
+ getBaseMapper().update(updateWrapper);
|
|
|
371
|
+ }
|
|
|
372
|
+ } catch (JsonProcessingException e) {
|
|
|
373
|
+ e.printStackTrace();
|
|
|
374
|
+ }
|
|
|
375
|
+ }
|
|
189
|
376
|
|
|
190
|
377
|
/**
|
|
191
|
378
|
* 保存或更新采购计划变更单明细
|
...
|
...
|
|