Commit f889c2c7339f537ed595b0162be6ebcfd87ce9c9

Authored by 房远帅
1 parent 4b9555ca

采购计划:涉及过磅码单变更校验

... ... @@ -34,6 +34,8 @@ import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
34 34 import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanChange;
35 35 import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanChangeLine;
36 36 import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanLine;
  37 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicket;
  38 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketPlan;
37 39 import com.lframework.xingyun.sc.procurement.mappers.change.ProcurementPlanChangeLineMapper;
38 40 import com.lframework.xingyun.sc.procurement.mappers.change.ProcurementPlanChangeMapper;
39 41 import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyService;
... ... @@ -42,6 +44,8 @@ import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChang
42 44 import com.lframework.xingyun.sc.procurement.service.contract.ProcurementContractService;
43 45 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService;
44 46 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  47 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketPlanService;
  48 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketService;
45 49 import com.lframework.xingyun.sc.procurement.vo.buyout.CreateProcurementBuyoutApplyVo;
46 50 import com.lframework.xingyun.sc.procurement.vo.change.CreateProcurementPlanChangeLineVo;
47 51 import com.lframework.xingyun.sc.procurement.vo.change.CreateProcurementPlanChangeVo;
... ... @@ -90,12 +94,99 @@ public class ProcurementPlanChangeServiceImpl extends
90 94 private FlowTaskWrapperMapper flowTaskWrapperMapper;
91 95 @Resource
92 96 private ProcurementContractService procurementContractService;
  97 + @Resource
  98 + private ProcurementWeighingTicketPlanService weighingTicketPlanService;
  99 + @Resource
  100 + private ProcurementWeighingTicketService weighingTicketService;
93 101
94 102
95 103 private static final List<String> PROCESS_STATUSES = Arrays.asList(
96 104 "COMPLETED", "ABORTED"
97 105 );
98 106
  107 + /**
  108 + * 计划是否已关联有效过磅码单(码单未作废、未取消)
  109 + */
  110 + private boolean existsValidWeighingTicket(String planId) {
  111 + List<ProcurementWeighingTicketPlan> planLines = weighingTicketPlanService.list(
  112 + Wrappers.lambdaQuery(ProcurementWeighingTicketPlan.class)
  113 + .eq(ProcurementWeighingTicketPlan::getProcurementPlanId, planId));
  114 + if (CollectionUtil.isEmpty(planLines)) {
  115 + return false;
  116 + }
  117 + List<String> ticketIds = planLines.stream()
  118 + .map(ProcurementWeighingTicketPlan::getWeighingTicketId)
  119 + .filter(StringUtil::isNotBlank)
  120 + .distinct()
  121 + .collect(Collectors.toList());
  122 + if (CollectionUtil.isEmpty(ticketIds)) {
  123 + return false;
  124 + }
  125 + // 有效码单:未作废(deleted=0)且未取消(approval_status != CANCEL)
  126 + return weighingTicketService.count(Wrappers.lambdaQuery(ProcurementWeighingTicket.class)
  127 + .in(ProcurementWeighingTicket::getId, ticketIds)
  128 + .eq(ProcurementWeighingTicket::getDeleted, false)
  129 + .ne(ProcurementWeighingTicket::getApprovalStatus, "CANCEL")) > 0;
  130 + }
  131 +
  132 + /**
  133 + * 已关联有效过磅码单的计划快速变更:只允许变更开票品名、公司名称,其余字段必须与原值一致;
  134 + * 原有变更能力不受影响(子计划快速变更原本仅支持改分厂,分厂不允许变更后即无法快速变更)
  135 + */
  136 + private void assertFastChangeLimitedWhenWeighed(CreateProcurementPlanChangeVo vo, ProcurementPlan plan) {
  137 + // 子计划快速变更仅分厂可改,已过磅后分厂不允许变更
  138 + if (StringUtil.isNotEmpty(plan.getParentId())) {
  139 + throw new DefaultClientException("该计划已关联过磅码单,不允许快速变更!");
  140 + }
  141 +
  142 + // 另付运费必须与原值一致
  143 + if (diff(vo.getShippingCost(), plan.getShippingCost())) {
  144 + throw new DefaultClientException("该计划已关联过磅码单,快速变更仅允许变更开票品名和公司名称,不允许修改另付运费!");
  145 + }
  146 +
  147 + // 明细行除开票品名外必须与原值一致
  148 + List<CreateProcurementPlanChangeLineVo> lines = vo.getLines();
  149 + if (CollectionUtil.isEmpty(lines)) {
  150 + return;
  151 + }
  152 + Map<String, ProcurementPlanLine> lineMap = procurementPlanLineService.list(
  153 + Wrappers.lambdaQuery(ProcurementPlanLine.class)
  154 + .eq(ProcurementPlanLine::getProcurementPlanId, vo.getProcurementPlanId()))
  155 + .stream()
  156 + .collect(Collectors.toMap(ProcurementPlanLine::getId, l -> l, (v1, v2) -> v1));
  157 +
  158 + for (CreateProcurementPlanChangeLineVo lineVo : lines) {
  159 + ProcurementPlanLine origin = lineVo.getProcurementPlanLineId() == null ? null
  160 + : lineMap.get(lineVo.getProcurementPlanLineId());
  161 + if (origin == null) {
  162 + continue;
  163 + }
  164 + if (!Objects.equals(lineVo.getWorkshopId(), origin.getWorkshopId())
  165 + || diff(lineVo.getQuantity(), origin.getQuantity())
  166 + || diff(lineVo.getActualPurchasePrice(), origin.getActualPurchasePrice())
  167 + || diff(lineVo.getPriceListPrices(), origin.getPriceListPrices())
  168 + || diff(lineVo.getCoordinationRange(), origin.getCoordinationRange())
  169 + || diff(lineVo.getEstimatedLoss(), origin.getEstimatedLoss())
  170 + || diff(lineVo.getApplicationAttrition(), origin.getApplicationAttrition())
  171 + || diff(lineVo.getPaintDamageRatio(), origin.getPaintDamageRatio())) {
  172 + throw new DefaultClientException("该计划已关联过磅码单,快速变更仅允许变更开票品名和公司名称,其他字段不允许修改!");
  173 + }
  174 + }
  175 + }
  176 +
  177 + /**
  178 + * 金额/数量是否不一致(任一为 null 视为不等,两者为 null 视为相等)
  179 + */
  180 + private boolean diff(BigDecimal a, BigDecimal b) {
  181 + if (a == null && b == null) {
  182 + return false;
  183 + }
  184 + if (a == null || b == null) {
  185 + return true;
  186 + }
  187 + return a.compareTo(b) != 0;
  188 + }
  189 +
99 190 @Override
100 191 @Transactional(rollbackFor = Exception.class)
101 192 @OpLog(type = OtherOpLogType.class, name = "创建采购计划变更单,原计划ID:{},变更单ID:{}", params = {"#vo.procurementPlanId", "#result"})
... ... @@ -116,7 +207,16 @@ public class ProcurementPlanChangeServiceImpl extends
116 207 || !PROCESS_STATUSES.contains(plan.getProcessStatus())) {
117 208 throw new DefaultClientException("原采购计划状态不允许变更,请确认计划已中止/完成");
118 209 }
  210 + // 计划已关联有效过磅码单(未作废、未取消)时不允许常规变更,只允许快速变更
  211 + if (!"FAST".equals(vo.getChangeType()) && existsValidWeighingTicket(vo.getProcurementPlanId())) {
  212 + throw new DefaultClientException("该计划已关联过磅码单,不允许常规变更,请使用快速变更!");
  213 + }
119 214 if ("FAST".equals(vo.getChangeType())) {
  215 + // 已关联有效过磅码单的计划:只允许变更开票品名、公司名称,其余字段必须与原值一致;
  216 + // 原有逻辑不变(子计划快速变更原本仅支持改分厂,分厂不允许变更后即无法快速变更)
  217 + if (existsValidWeighingTicket(vo.getProcurementPlanId())) {
  218 + assertFastChangeLimitedWhenWeighed(vo, plan);
  219 + }
120 220 ProcurementPlanChange planChange = new ProcurementPlanChange();
121 221 BeanUtil.copyProperties(vo, planChange);
122 222 planChange.setId(IdUtil.getId());
... ...