| | |
| | | import com.ruoyi.production.mapper.ProductionProductMainMapper; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | |
| | | if (productProcessRouteItem == null) { |
| | | throw new RuntimeException("工艺路线项不存在"); |
| | | } |
| | | // 获取订单的已完成工单 |
| | | // 获取订单的工单 |
| | | List<ProductWorkOrder> productWorkOrderList = productWorkOrderMapper.selectList(Wrappers.<ProductWorkOrder>lambdaQuery() |
| | | .eq(ProductWorkOrder::getProductOrderId, productProcessRouteItem.getProductOrderId()) |
| | | .eq(ProductWorkOrder::getStatus, 3)); |
| | | .eq(ProductWorkOrder::getProductOrderId, productProcessRouteItem.getProductOrderId())); |
| | | // 获取完成数量 |
| | | BigDecimal completeQuantity = productWorkOrderList |
| | | .stream() |
| | | .filter(item -> item.getStatus() == 3) |
| | | .map(ProductWorkOrder::getCompleteQuantity) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 获取所有数量 |
| | | BigDecimal totalQuantity = productWorkOrderList |
| | | .stream() |
| | | .map(ProductWorkOrder::getPlanQuantity) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 获取未完成数量 |
| | | BigDecimal unCompleteQuantity = totalQuantity.subtract(completeQuantity); |
| | | if (unCompleteQuantity.compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new ServiceException("该工单已全部完成"); |
| | | } |
| | | // 计算比例 |
| | | BigDecimal ratio = unCompleteQuantity.divide(totalQuantity, 2, RoundingMode.HALF_UP); |
| | | if(CollectionUtils.isEmpty(productWorkOrderList)){ |
| | | productWorkOrderList = new ArrayList<>(); |
| | | } |
| | |
| | | productOrder.setStartTime(LocalDateTime.now());//开始时间 |
| | | productOrder.setStatus("生产中"); |
| | | } |
| | | // 通过比例计算完成数量 |
| | | productOrder.setCompleteQuantity(productOrder.getQuantity().multiply(ratio)); |
| | | if (productWorkOrderList.size() == productProcessRouteItems.size() - 1) { |
| | | //如果是最后一道工序报工之后生产订单完成数量+ |
| | | productOrder.setCompleteQuantity(productOrder.getCompleteQuantity().add(productQty)); |
| | | productOrder.setCompleteQuantity(productOrder.getQuantity()); |
| | | if (productOrder.getCompleteQuantity().compareTo(productOrder.getQuantity()) == 0) { |
| | | productOrder.setEndTime(LocalDateTime.now());//结束时间 |
| | | productOrder.setStatus("已完成"); |
| | |
| | | salesLedgerProductionAccountingMapper.insert(salesLedgerProductionAccounting); |
| | | } |
| | | //如果报废数量>0,需要进入报废的库存 |
| | | if (ObjectUtils.isNotEmpty(dto.getScrapQty())) { |
| | | if (dto.getScrapQty().compareTo(BigDecimal.ZERO) > 0) { |
| | | stockUtils.addUnStock(productModel.getId(), dto.getScrapQty(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(), productionProductMain.getId()); |
| | | } |
| | | } |
| | | // if (ObjectUtils.isNotEmpty(dto.getScrapQty())) { |
| | | // if (dto.getScrapQty().compareTo(BigDecimal.ZERO) > 0) { |
| | | // stockUtils.addUnStock(productModel.getId(), dto.getScrapQty(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(), productionProductMain.getId()); |
| | | // } |
| | | // } |
| | | return true; |
| | | } |
| | | |
| | |
| | | BigDecimal completeQty = productWorkOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : productWorkOrder.getCompleteQuantity(); |
| | | |
| | | BigDecimal validQuantity = outputQty.subtract(scrapQty); |
| | | |
| | | productWorkOrder.setStatus(2); |
| | | productWorkOrder.setCompleteQuantity(completeQty.subtract(validQuantity)); |
| | | productWorkOrder.setActualEndTime(null); |
| | | productWorkOrderMapper.updateById(productWorkOrder); |
| | |
| | | productOrder.setCompleteQuantity(newCompleteQty.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : newCompleteQty); |
| | | |
| | | productOrder.setEndTime(null); |
| | | |
| | | productOrder.setStatus("生产中"); |
| | | productOrderMapper.updateById(productOrder); |
| | | } else { |
| | | throw new ServiceException("关联的生产订单不存在"); |