| | |
| | | |
| | | private final PendingInventoryMapper pendingInventoryMapper; |
| | | |
| | | private final ProductionSchedulingMapper productionSchedulingMapper; |
| | | |
| | | @Override |
| | | public IPage<ProductionMasterDto> selectPMList(Page page, ProductionMasterDto productionMasterDto) { |
| | | // 1. 构建主表查询条件 |
| | |
| | | batchInsertInventories(masterId, dto.getProductionInventoryList()); |
| | | |
| | | // 插入待入库数据 |
| | | insertPendingInventory(dto.getProductionList()); |
| | | // insertPendingInventory(dto.getProductionList()); |
| | | |
| | | return 1; |
| | | } |
| | |
| | | BeanUtils.copyProperties(p, copy); |
| | | copy.setId(null); |
| | | copy.setProductionMasterId(masterId); |
| | | copy.setStatus(1); |
| | | productionMapper.insert(copy); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 将加工产生的产品记录到待入库表 |
| | | */ |
| | | private void insertPendingInventory(List<Production> list) { |
| | | public void insertPendingInventory(List<Production> list) { |
| | | LocalDate currentDate = LocalDate.now(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDate = currentDate.format(formatter); |
| | |
| | | .collect(Collectors.toList()); |
| | | productionInventoryMapper.deleteBatchIds(inventoryIds); |
| | | } |
| | | List<Production> productions = productionMapper.selectList(new LambdaQueryWrapper<Production>() |
| | | .in(Production::getProductionMasterId, idList)); |
| | | |
| | | // 删除生产报工记录 |
| | | productionSchedulingMapper.delete( |
| | | new LambdaQueryWrapper<ProductionScheduling>() |
| | | .in(ProductionScheduling::getProductionId, productions.stream().map(Production::getId).collect(Collectors.toList())) |
| | | ); |
| | | |
| | | // 删除生产明细 |
| | | productionMapper.delete( |
| | | new LambdaQueryWrapper<Production>() |
| | | .in(Production::getProductionMasterId, idList) |
| | | ); |
| | | |
| | | |
| | | // 5. 删除主记录 |
| | | return productionMasterMapper.deleteBatchIds(idList); |
| | |
| | | } |
| | | |
| | | // 批量更新官方库存 |
| | | for (Map.Entry<Long, BigDecimal> entry : inventoryAdjustMap.entrySet()) { |
| | | OfficialInventory official = officialInventoryMapper.selectById(entry.getKey()); |
| | | if (official == null) { |
| | | throw new BaseException("官方库存不存在,ID: " + entry.getKey()); |
| | | } |
| | | |
| | | // 使用线程安全的BigDecimal操作 |
| | | official.setInventoryQuantity( |
| | | Optional.ofNullable(official.getInventoryQuantity()) |
| | | .orElse(BigDecimal.ZERO) |
| | | .add(entry.getValue()) |
| | | ); |
| | | officialInventoryMapper.updateById(official); |
| | | } |
| | | // for (Map.Entry<Long, BigDecimal> entry : inventoryAdjustMap.entrySet()) { |
| | | // OfficialInventory official = officialInventoryMapper.selectById(entry.getKey()); |
| | | // if (official == null) { |
| | | // throw new BaseException("官方库存不存在,ID: " + entry.getKey()); |
| | | // } |
| | | // |
| | | // // 使用线程安全的BigDecimal操作 |
| | | // official.setInventoryQuantity( |
| | | // Optional.ofNullable(official.getInventoryQuantity()) |
| | | // .orElse(BigDecimal.ZERO) |
| | | // .add(entry.getValue()) |
| | | // ); |
| | | // officialInventoryMapper.updateById(official); |
| | | // } |
| | | |
| | | // 批量删除生产库存 |
| | | if (!productionIdsToDelete.isEmpty()) { |