|
...
|
...
|
@@ -8,7 +8,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
8
|
8
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
9
|
9
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
10
|
10
|
import com.github.pagehelper.PageInfo;
|
|
|
11
|
+import com.lframework.starter.bpm.dto.FlowTaskDto;
|
|
|
12
|
+import com.lframework.starter.bpm.entity.FlowInstanceWrapper;
|
|
|
13
|
+import com.lframework.starter.bpm.mappers.FlowTaskWrapperMapper;
|
|
11
|
14
|
import com.lframework.starter.bpm.service.FlowInstanceWrapperService;
|
|
|
15
|
+import com.lframework.starter.bpm.vo.flow.task.QueryTodoTaskListVo;
|
|
12
|
16
|
import com.lframework.starter.common.exceptions.impl.DefaultClientException;
|
|
13
|
17
|
import com.lframework.starter.common.exceptions.impl.InputErrorException;
|
|
14
|
18
|
import com.lframework.starter.common.utils.Assert;
|
|
...
|
...
|
@@ -50,6 +54,7 @@ import java.time.LocalDateTime; |
|
50
|
54
|
import java.util.*;
|
|
51
|
55
|
import java.util.stream.Collectors;
|
|
52
|
56
|
import javax.annotation.Resource;
|
|
|
57
|
+import org.apache.commons.lang3.StringUtils;
|
|
53
|
58
|
import org.springframework.stereotype.Service;
|
|
54
|
59
|
import org.springframework.transaction.annotation.Transactional;
|
|
55
|
60
|
|
|
...
|
...
|
@@ -76,6 +81,8 @@ public class ProcurementPlanChangeServiceImpl extends |
|
76
|
81
|
private ProcurementBuyoutApplyService procurementBuyoutApplyService;
|
|
77
|
82
|
@Resource
|
|
78
|
83
|
private WorkshopService workshopService;
|
|
|
84
|
+ @Resource
|
|
|
85
|
+ private FlowTaskWrapperMapper flowTaskWrapperMapper;
|
|
79
|
86
|
|
|
80
|
87
|
|
|
81
|
88
|
private static final List<String> PROCESS_STATUSES = Arrays.asList(
|
|
...
|
...
|
@@ -275,7 +282,7 @@ public class ProcurementPlanChangeServiceImpl extends |
|
275
|
282
|
BeanUtil.copyProperties(vo, planChange);
|
|
276
|
283
|
this.updateById(planChange);
|
|
277
|
284
|
//保存或更新采购计划变更单明细
|
|
278
|
|
- saveOrUpdateLines(vo.getProcurementPlanId(), vo.getLines());
|
|
|
285
|
+ saveOrUpdateLines(vo.getId(), vo.getLines());
|
|
279
|
286
|
}
|
|
280
|
287
|
|
|
281
|
288
|
@Override
|
|
...
|
...
|
@@ -654,21 +661,66 @@ public class ProcurementPlanChangeServiceImpl extends |
|
654
|
661
|
try {
|
|
655
|
662
|
//流程编码
|
|
656
|
663
|
Object n = map.get("nodeCode");
|
|
657
|
|
- String nodeCode = String.valueOf(n);
|
|
|
664
|
+ String nodeCode = n == null ? null : String.valueOf(n);
|
|
658
|
665
|
|
|
659
|
666
|
//审核状态
|
|
660
|
667
|
Object e = map.get("examStatus");
|
|
661
|
|
- String examStatus = String.valueOf(e);
|
|
662
|
|
- // 创建 ObjectMapper 实例
|
|
663
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
664
|
|
- //先将 Map 序列化为 JSON 字符串,再反序列化为目标对象
|
|
665
|
|
- String json = objectMapper.writeValueAsString(map);
|
|
666
|
|
- UpdateProcurementPlanChangeVo vo = JsonUtil.parseObject(json, UpdateProcurementPlanChangeVo.class);
|
|
667
|
|
- ProcurementPlanChange planChange = new ProcurementPlanChange();
|
|
668
|
|
- BeanUtil.copyProperties(vo, planChange);
|
|
669
|
|
- this.updateById(planChange);
|
|
670
|
|
- //保存或更新采购计划变更单明细
|
|
671
|
|
- saveOrUpdateLines(vo.getProcurementPlanId(), vo.getLines());
|
|
|
668
|
+ String examStatus = e == null ? null : String.valueOf(e);
|
|
|
669
|
+
|
|
|
670
|
+ //业务ID(变更单ID)
|
|
|
671
|
+ Object bizIdObj = map.get("bizId");
|
|
|
672
|
+ String bizId = bizIdObj == null ? null : String.valueOf(bizIdObj);
|
|
|
673
|
+
|
|
|
674
|
+ // 优先解析 variables 子 map(前端流程回调 variables 包裹真实 VO 字段)
|
|
|
675
|
+ Map<String, Object> variablesMap = null;
|
|
|
676
|
+ Object varsObj = map.get("variables");
|
|
|
677
|
+ if (varsObj instanceof Map) {
|
|
|
678
|
+ variablesMap = (Map<String, Object>) varsObj;
|
|
|
679
|
+ }
|
|
|
680
|
+
|
|
|
681
|
+ if (StringUtil.isBlank(bizId) && variablesMap != null) {
|
|
|
682
|
+ Object bizIdInVar = variablesMap.get("bizId");
|
|
|
683
|
+ if (bizIdInVar != null) {
|
|
|
684
|
+ bizId = String.valueOf(bizIdInVar);
|
|
|
685
|
+ }
|
|
|
686
|
+ }
|
|
|
687
|
+
|
|
|
688
|
+ // 将 Map / variablesMap 转 VO
|
|
|
689
|
+ UpdateProcurementPlanChangeVo vo = null;
|
|
|
690
|
+ if (variablesMap != null) {
|
|
|
691
|
+ vo = JsonUtil.parseObject(JsonUtil.toJsonString(variablesMap), UpdateProcurementPlanChangeVo.class);
|
|
|
692
|
+ } else {
|
|
|
693
|
+ vo = JsonUtil.parseObject(JsonUtil.toJsonString(map), UpdateProcurementPlanChangeVo.class);
|
|
|
694
|
+ }
|
|
|
695
|
+
|
|
|
696
|
+ // 若 bizId 仍为空,用 vo.id 兜底;或从明细里的 procurementPlanChangeId 兜底
|
|
|
697
|
+ if (StringUtil.isBlank(bizId)) {
|
|
|
698
|
+ if (vo != null && StringUtil.isNotBlank(vo.getId())) {
|
|
|
699
|
+ bizId = vo.getId();
|
|
|
700
|
+ } else if (vo != null && !CollectionUtil.isEmpty(vo.getLines())) {
|
|
|
701
|
+ bizId = vo.getLines().stream()
|
|
|
702
|
+ .filter(l -> l != null && StringUtil.isNotBlank(l.getProcurementPlanChangeId()))
|
|
|
703
|
+ .map(UpdateProcurementPlanChangeLineVo::getProcurementPlanChangeId)
|
|
|
704
|
+ .findFirst().orElse(null);
|
|
|
705
|
+ }
|
|
|
706
|
+ }
|
|
|
707
|
+
|
|
|
708
|
+ // 有 VO + 有 bizId + VO有ID 才去更新主表和明细(和补单模块对齐)
|
|
|
709
|
+ if (vo != null && StringUtil.isNotBlank(bizId)) {
|
|
|
710
|
+ // 如果vo里没有id,手动补回bizId,保证后面 BeanUtil.copyProperties 时 id 有值,updateById 不会失效
|
|
|
711
|
+ if (StringUtil.isBlank(vo.getId())) {
|
|
|
712
|
+ vo.setId(bizId);
|
|
|
713
|
+ }
|
|
|
714
|
+
|
|
|
715
|
+ // 更新主表字段
|
|
|
716
|
+ ProcurementPlanChange planChange = new ProcurementPlanChange();
|
|
|
717
|
+ BeanUtil.copyProperties(vo, planChange);
|
|
|
718
|
+ this.updateById(planChange);
|
|
|
719
|
+
|
|
|
720
|
+ //保存或更新采购计划变更单明细
|
|
|
721
|
+ saveOrUpdateLines(bizId, vo.getLines());
|
|
|
722
|
+ }
|
|
|
723
|
+
|
|
672
|
724
|
if ("PASS".equals(examStatus)) {
|
|
673
|
725
|
String processNode = null;
|
|
674
|
726
|
if ("plan_change_qyjl".equals(nodeCode)) {
|
|
...
|
...
|
@@ -685,16 +737,23 @@ public class ProcurementPlanChangeServiceImpl extends |
|
685
|
737
|
} else if ("plan_change_gybzg".equals(nodeCode)) {
|
|
686
|
738
|
processNode = "YSFG";
|
|
687
|
739
|
}
|
|
688
|
|
- LambdaUpdateWrapper<ProcurementPlanChange> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanChange.class)
|
|
689
|
|
- .set(ProcurementPlanChange::getProcessNode, processNode)
|
|
690
|
|
- .set("plan_change_qyjl".equals(nodeCode), ProcurementPlanChange::getPurchaseDeptName, SecurityUtil.getCurrentUser().getName())
|
|
691
|
|
- .set("plan_change_gyglkzg".equals(nodeCode), ProcurementPlanChange::getManagementDeptName, SecurityUtil.getCurrentUser().getName())
|
|
692
|
|
- .set("plan_change_gybzg".equals(nodeCode), ProcurementPlanChange::getSupplyManagerName, SecurityUtil.getCurrentUser().getName())
|
|
693
|
|
- .eq(ProcurementPlanChange::getId, vo.getId());
|
|
694
|
|
- getBaseMapper().update(updateWrapper);
|
|
|
740
|
+ if (StringUtil.isNotBlank(bizId) && StringUtil.isNotBlank(processNode)) {
|
|
|
741
|
+ LambdaUpdateWrapper<ProcurementPlanChange> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanChange.class)
|
|
|
742
|
+ .set(ProcurementPlanChange::getProcessNode, processNode)
|
|
|
743
|
+ .set("plan_change_qyjl".equals(nodeCode), ProcurementPlanChange::getPurchaseDeptName, SecurityUtil.getCurrentUser().getName())
|
|
|
744
|
+ .set("plan_change_gyglkzg".equals(nodeCode), ProcurementPlanChange::getManagementDeptName, SecurityUtil.getCurrentUser().getName())
|
|
|
745
|
+ .set("plan_change_gybzg".equals(nodeCode), ProcurementPlanChange::getSupplyManagerName, SecurityUtil.getCurrentUser().getName())
|
|
|
746
|
+ .eq(ProcurementPlanChange::getId, bizId);
|
|
|
747
|
+ getBaseMapper().update(updateWrapper);
|
|
|
748
|
+ }
|
|
|
749
|
+ }
|
|
|
750
|
+
|
|
|
751
|
+ // 回填操作日志
|
|
|
752
|
+ if (StringUtil.isNotBlank(bizId)) {
|
|
|
753
|
+ OpLogUtil.setVariable("id", bizId);
|
|
695
|
754
|
}
|
|
696
|
|
- } catch (JsonProcessingException e) {
|
|
697
|
|
- e.printStackTrace();
|
|
|
755
|
+ } catch (Exception ex) {
|
|
|
756
|
+ ex.printStackTrace();
|
|
698
|
757
|
}
|
|
699
|
758
|
}
|
|
700
|
759
|
|
|
...
|
...
|
@@ -705,8 +764,20 @@ public class ProcurementPlanChangeServiceImpl extends |
|
705
|
764
|
* @param lineList 明细列表
|
|
706
|
765
|
*/
|
|
707
|
766
|
private void saveOrUpdateLines(String planChangeId, List<UpdateProcurementPlanChangeLineVo> lineList) {
|
|
|
767
|
+ // 统一计算真正要用的变更单ID:参数优先,其次取 lineVo 里的 procurementPlanChangeId(前端流程回调已带)
|
|
|
768
|
+ String finalChangeId = planChangeId;
|
|
|
769
|
+ if (StringUtil.isBlank(finalChangeId) && !CollectionUtil.isEmpty(lineList)) {
|
|
|
770
|
+ finalChangeId = lineList.stream()
|
|
|
771
|
+ .filter(l -> l != null && StringUtil.isNotBlank(l.getProcurementPlanChangeId()))
|
|
|
772
|
+ .map(UpdateProcurementPlanChangeLineVo::getProcurementPlanChangeId)
|
|
|
773
|
+ .findFirst().orElse(null);
|
|
|
774
|
+ }
|
|
|
775
|
+ if (StringUtil.isBlank(finalChangeId)) {
|
|
|
776
|
+ throw new DefaultClientException("采购计划变更单ID为空,无法保存明细!");
|
|
|
777
|
+ }
|
|
|
778
|
+
|
|
708
|
779
|
List<ProcurementPlanChangeLine> oldLineList = procurementPlanChangeLineService
|
|
709
|
|
- .getByChangeId(planChangeId);
|
|
|
780
|
+ .getByChangeId(finalChangeId);
|
|
710
|
781
|
Map<String, ProcurementPlanChangeLine> oldLineMap = CollectionUtil.isEmpty(oldLineList)
|
|
711
|
782
|
? Collections.emptyMap()
|
|
712
|
783
|
: oldLineList.stream().collect(Collectors.toMap(ProcurementPlanChangeLine::getId, v -> v));
|
|
...
|
...
|
@@ -720,17 +791,17 @@ public class ProcurementPlanChangeServiceImpl extends |
|
720
|
791
|
}
|
|
721
|
792
|
|
|
722
|
793
|
existIdList.add(lineVo.getId());
|
|
723
|
|
- lineVo.setProcurementPlanChangeId(planChangeId);
|
|
724
|
794
|
if (StringUtil.isBlank(lineVo.getItemId())) {
|
|
725
|
795
|
lineVo.setItemId(oldLine.getItemId());
|
|
726
|
796
|
}
|
|
727
|
797
|
ProcurementPlanChangeLine updateLine = BeanUtil.copyProperties(lineVo, ProcurementPlanChangeLine.class);
|
|
728
|
798
|
updateLine.setId(lineVo.getId());
|
|
|
799
|
+ updateLine.setProcurementPlanChangeId(finalChangeId);
|
|
729
|
800
|
procurementPlanChangeLineService.updateById(updateLine);
|
|
730
|
801
|
} else {
|
|
731
|
802
|
ProcurementPlanChangeLine createLine = BeanUtil.copyProperties(lineVo, ProcurementPlanChangeLine.class);
|
|
732
|
803
|
createLine.setId(IdUtil.getId());
|
|
733
|
|
- createLine.setProcurementPlanChangeId(planChangeId);
|
|
|
804
|
+ createLine.setProcurementPlanChangeId(finalChangeId);
|
|
734
|
805
|
procurementPlanChangeLineService.save(createLine);
|
|
735
|
806
|
existIdList.add(createLine.getId());
|
|
736
|
807
|
}
|
|
...
|
...
|
@@ -763,31 +834,24 @@ public class ProcurementPlanChangeServiceImpl extends |
|
763
|
834
|
return;
|
|
764
|
835
|
}
|
|
765
|
836
|
|
|
766
|
|
- List<String> businessIds = validDatas.stream()
|
|
767
|
|
- .map(ProcurementPlanChange::getId)
|
|
768
|
|
- .collect(Collectors.toList());
|
|
769
|
|
-
|
|
770
|
837
|
// 查询已发起的流程
|
|
771
|
|
- List<?> flowByConditionList =
|
|
772
|
|
- flowInstanceWrapperService.getFlowByBusinessIdList(businessIds);
|
|
773
|
|
- Set<String> flowBusinessIdSet = CollectionUtil.isNotEmpty(flowByConditionList)
|
|
774
|
|
- ? flowByConditionList.stream()
|
|
775
|
|
- .map(obj -> {
|
|
776
|
|
- try {
|
|
777
|
|
- return BeanUtil.getProperty(obj, "businessId");
|
|
778
|
|
- } catch (Exception e) {
|
|
779
|
|
- return null;
|
|
780
|
|
- }
|
|
781
|
|
- })
|
|
782
|
|
- .filter(Objects::nonNull)
|
|
783
|
|
- .map(String::valueOf)
|
|
784
|
|
- .collect(Collectors.toSet())
|
|
|
838
|
+ List<String> businessIds = validDatas.stream().map(ProcurementPlanChange::getId).collect(Collectors.toList());
|
|
|
839
|
+ List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(businessIds);
|
|
|
840
|
+ Set<String> flowBusinessIdSet = CollectionUtil.isNotEmpty(flowList)
|
|
|
841
|
+ ? flowList.stream().map(FlowInstanceWrapper::getBusinessId).collect(Collectors.toSet())
|
|
|
842
|
+ : new HashSet<>();
|
|
|
843
|
+
|
|
|
844
|
+ List<FlowTaskDto> todoFlowTaskList = flowTaskWrapperMapper.queryTodoList(
|
|
|
845
|
+ new QueryTodoTaskListVo(), SecurityUtil.getCurrentUser().getId());
|
|
|
846
|
+ Set<String> todoBusinessIdSet = CollectionUtil.isNotEmpty(todoFlowTaskList)
|
|
|
847
|
+ ? todoFlowTaskList.stream().map(FlowTaskDto::getBusinessId).collect(Collectors.toSet())
|
|
785
|
848
|
: new HashSet<>();
|
|
786
|
849
|
|
|
787
|
850
|
for (ProcurementPlanChange planChange : validDatas) {
|
|
788
|
851
|
boolean hasFlow = flowBusinessIdSet.contains(planChange.getId());
|
|
789
|
|
- planChange.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(planChange.getApprovalStatus()));
|
|
790
|
|
- planChange.setShowExamine(hasFlow && CustomerDevelopStatus.AUDIT.name().equals(planChange.getApprovalStatus()));
|
|
|
852
|
+ boolean hasTodo = todoBusinessIdSet.contains(planChange.getId());
|
|
|
853
|
+ planChange.setShowExamineDetail(hasFlow && StringUtils.isNotBlank(planChange.getApprovalStatus()));
|
|
|
854
|
+ planChange.setShowExamine(hasTodo && CustomerDevelopStatus.AUDIT.name().equals(planChange.getApprovalStatus()));
|
|
791
|
855
|
}
|
|
792
|
856
|
}
|
|
793
|
857
|
|
...
|
...
|
|