| | |
| | | import com.ruoyi.framework.security.LoginUser; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SpareParts; |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | |
| | | private final StockInRecordService stockInRecordService; |
| | | private final StockUtils stockUtils; |
| | | private final ApprovalTemplateMapper approvalTemplateMapper; |
| | | private final SparePartsMapper sparePartsMapper; |
| | | |
| | | @Override |
| | | public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) { |
| | |
| | | purchaseLedger.setRecorderId(purchaseLedgerDto.getRecorderId()); |
| | | |
| | | purchaseLedger.setApprovalStatus(1); |
| | | if (purchaseLedger.getId() == null) { |
| | | purchaseLedger.setStatus(1); |
| | | } |
| | | // 3. 新增或更新主表 |
| | | if (purchaseLedger.getId() == null) { |
| | | purchaseLedgerMapper.insert(purchaseLedger); |
| | |
| | | for (SalesLedgerProduct product : products) { |
| | | try { |
| | | boolean processed; |
| | | if (Boolean.TRUE.equals(product.getIsChecked())) { |
| | | if (product.getProductType() != null && product.getProductType() == 2) { |
| | | processed = processPurchaseSparePart(purchaseLedger, product); |
| | | } else if (Boolean.TRUE.equals(product.getIsChecked())) { |
| | | processed = processPurchaseQualityProduct(purchaseLedger, product); |
| | | } else { |
| | | processed = processPurchaseDirectProduct(purchaseLedger, product); |
| | |
| | | detail.put("message", ex.getMessage()); |
| | | details.add(detail); |
| | | log.error("批量推进采购台账失败, purchaseLedgerId={}", id, ex); |
| | | } |
| | | } |
| | | |
| | | // 更新收货状态 |
| | | List<Long> processedIds = details.stream() |
| | | .filter(d -> "SUCCESS".equals(d.get("status")) || "PARTIAL".equals(d.get("status"))) |
| | | .map(d -> (Long) d.get("purchaseLedgerId")) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | if (!processedIds.isEmpty()) { |
| | | PurchaseLedgerDto statusQuery = new PurchaseLedgerDto(); |
| | | statusQuery.setIds(processedIds); |
| | | IPage<PurchaseLedgerDto> statusPage = this.selectPurchaseLedgerListPage( |
| | | new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(1, processedIds.size()), |
| | | statusQuery |
| | | ); |
| | | if (statusPage != null && CollectionUtils.isNotEmpty(statusPage.getRecords())) { |
| | | for (PurchaseLedgerDto dto : statusPage.getRecords()) { |
| | | PurchaseLedger update = new PurchaseLedger(); |
| | | update.setId(dto.getId()); |
| | | if ("完全入库".equals(dto.getStockInStatus())) { |
| | | update.setStatus(3); |
| | | } else if ("入库中".equals(dto.getStockInStatus())) { |
| | | update.setStatus(2); |
| | | } else { |
| | | update.setStatus(1); |
| | | } |
| | | purchaseLedgerMapper.updateById(update); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | return hasApprovedStockRecord(stockRecords); |
| | | } |
| | | |
| | | private boolean processPurchaseSparePart(PurchaseLedger purchaseLedger, SalesLedgerProduct product) { |
| | | if (purchaseLedger == null || product == null || product.getProductModelId() == null) { |
| | | return false; |
| | | } |
| | | SpareParts spareParts = sparePartsMapper.selectById(product.getProductModelId()); |
| | | if (spareParts == null) { |
| | | return false; |
| | | } |
| | | BigDecimal newQty = spareParts.getQuantity() != null |
| | | ? spareParts.getQuantity().add(product.getQuantity()) |
| | | : product.getQuantity(); |
| | | spareParts.setQuantity(newQty); |
| | | sparePartsMapper.updateById(spareParts); |
| | | return true; |
| | | } |
| | | |
| | | private LocalDateTime toStartOfDayPlusDays(Date date, int days) { |
| | | if (date == null) { |
| | | return null; |
| | |
| | | if (productModelId != null && modelMap.containsKey(productModelId)) { |
| | | product.setSpecificationModel(modelMap.get(productModelId)); |
| | | } |
| | | |
| | | if (product.getProductType() != null && product.getProductType() == 2) { |
| | | SpareParts spareParts = sparePartsMapper.selectById(productModelId); |
| | | if (spareParts != null) { |
| | | product.setProductCategory(spareParts.getName()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 分组处理 |