Commit d68b5ae26600ce9d0c6efeb161838f928ada7fe4

Authored by 房远帅
1 parent b2400a96

采购计划:问题修改

... ... @@ -2111,7 +2111,6 @@ CREATE TABLE `procurement_plan_change`
2111 2111 `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
2112 2112 `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
2113 2113 PRIMARY KEY (`id`),
2114   - UNIQUE KEY `uk_ppc_code` (`code`),
2115 2114 KEY `idx_ppc_procurement_plan_id` (`procurement_plan_id`),
2116 2115 KEY `idx_ppc_company_short_id` (`company_short_id`),
2117 2116 KEY `idx_ppc_supplier_id` (`supplier_id`),
... ... @@ -2210,7 +2209,6 @@ CREATE TABLE `procurement_plan_replenish`
2210 2209 `update_by` VARCHAR(64) DEFAULT NULL COMMENT '修改人(仅展示字段)',
2211 2210 `update_time` DATETIME DEFAULT NULL COMMENT '修改时间',
2212 2211 PRIMARY KEY (`id`),
2213   - UNIQUE KEY `uk_pp_replenish_code` (`code`),
2214 2212 KEY `idx_pp_replenish_plan_id` (`procurement_plan_id`),
2215 2213 KEY `idx_pp_replenish_status` (`approval_status`,`process_node`),
2216 2214 KEY `idx_pp_replenish_create_time` (`create_time`)
... ...
... ... @@ -336,7 +336,7 @@ public class GetProcurementPlanBo extends BaseBo<ProcurementPlan> {
336 336 /**
337 337 * 计划类型 正常 补单 变更 补单+变更
338 338 */
339   - @ApiModelProperty("计划类型 正常 补单 变更 补单+变更")
  339 + @ApiModelProperty("计划类型 补单 变更 补单+变更")
340 340 private String planType;
341 341
342 342 /**
... ... @@ -430,6 +430,18 @@ public class GetProcurementPlanBo extends BaseBo<ProcurementPlan> {
430 430 private String purchaseDeptName;
431 431
432 432 /**
  433 + * 是否展示审核按钮
  434 + */
  435 + @ApiModelProperty("是否展示审核按钮")
  436 + private Boolean showExamine;
  437 +
  438 + /**
  439 + * 是否展示审核详情按钮
  440 + */
  441 + @ApiModelProperty("是否展示审核详情按钮")
  442 + private Boolean showExamineDetail;
  443 +
  444 + /**
433 445 * 审核通过时间(精确到时分秒)
434 446 */
435 447 @ApiModelProperty("审核通过时间")
... ... @@ -599,18 +611,6 @@ public class GetProcurementPlanBo extends BaseBo<ProcurementPlan> {
599 611 private String workshopName;
600 612
601 613 /**
602   - * 是否展示审核按钮
603   - */
604   - @ApiModelProperty("是否展示审核按钮")
605   - private Boolean showExamine = false;
606   -
607   - /**
608   - * 是否展示审核详情按钮
609   - */
610   - @ApiModelProperty("是否展示审核详情按钮")
611   - private Boolean showExamineDetail;
612   -
613   - /**
614 614 * 创建人ID
615 615 */
616 616 @ApiModelProperty("创建人ID")
... ...
... ... @@ -342,7 +342,7 @@ public class GetProcurementPlanChangeBo extends BaseBo<ProcurementPlanChange> {
342 342 * 是否展示审核按钮(非持久化字段)
343 343 */
344 344 @ApiModelProperty("是否展示审核按钮")
345   - private Boolean showExamine = false;
  345 + private Boolean showExamine;
346 346
347 347 /**
348 348 * 是否展示审核详情按钮(非持久化字段)
... ...
... ... @@ -343,7 +343,7 @@ public class GetProcurementPlanReplenishBo extends BaseBo<ProcurementPlanRepleni
343 343 * 是否展示审核按钮(非持久化字段)
344 344 */
345 345 @ApiModelProperty("是否展示审核按钮")
346   - private Boolean showExamine = false;
  346 + private Boolean showExamine;
347 347
348 348 /**
349 349 * 是否展示审核详情按钮(非持久化字段)
... ...
... ... @@ -316,7 +316,7 @@ public class ProcurementPlanChange extends BaseEntity implements BaseDto {
316 316 * 是否展示审核按钮(非持久化字段)
317 317 */
318 318 @TableField(exist = false)
319   - private Boolean showExamine = false;
  319 + private Boolean showExamine;
320 320
321 321 /**
322 322 * 是否展示审核详情按钮(非持久化字段)
... ...
... ... @@ -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
... ...
... ... @@ -343,7 +343,7 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla
343 343
344 344 // 1. 校验明细:只要有任意一条明细未配置分厂ID,就不允许拆分
345 345 boolean hasEmptyWorkshopId = allLines.stream()
346   - .anyMatch(line -> line.getWorkshopId() == null); // 检查是否存在空的分厂ID
  346 + .anyMatch(line -> StringUtils.isEmpty(line.getWorkshopId()));// 检查是否存在空的分厂ID
347 347
348 348 if (hasEmptyWorkshopId) {
349 349 throw new DefaultClientException("部分采购计划明细未选择分厂,请先选择分厂!");
... ...
... ... @@ -321,8 +321,8 @@ public class CreateProcurementPlanVo implements BaseVo, Serializable {
321 321 /**
322 322 * 计划类型 正常 补单 变更 补单+变更
323 323 */
324   - @ApiModelProperty("计划类型 正常 补单 变更 补单+变更")
325   - private String planType = "正常";
  324 + @ApiModelProperty("计划类型 补单 变更 补单+变更")
  325 + private String planType;
326 326
327 327 /**
328 328 * 分厂ID
... ...