| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | 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); |
| | | final int SCALE = 2; |
| | | final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP; |
| | | final BigDecimal TAX_RATE = new BigDecimal("1.13"); |
| | | |
| | | for (Production p : list) { |
| | | PendingInventory pending = new PendingInventory(); |
| | | pending.setCoalId(p.getCoalId()); |
| | | pending.setInventoryQuantity(p.getProductionQuantity()); |
| | | pending.setSupplierName("生产加工入库"); |
| | | pending.setTotalPriceIncludingTax(p.getTotalCost()); |
| | | pending.setPriceIncludingTax(p.getPurchasePrice()); |
| | | pending.setUnit("吨"); |
| | | pending.setSupplierName(formattedDate + " - " + "生产加工入库"); |
| | | |
| | | // 非空处理 |
| | | BigDecimal totalCost = p.getTotalCost() == null ? BigDecimal.ZERO : p.getTotalCost(); |
| | | BigDecimal productionQuantity = p.getProductionQuantity() == null ? BigDecimal.ZERO : p.getProductionQuantity(); |
| | | |
| | | // 含税总价 |
| | | BigDecimal totalPriceIncludingTax = totalCost.multiply(productionQuantity) |
| | | .setScale(SCALE, ROUNDING_MODE); |
| | | pending.setTotalPriceIncludingTax(totalPriceIncludingTax); |
| | | |
| | | // 含税单价 |
| | | pending.setPriceIncludingTax(totalCost.setScale(SCALE, ROUNDING_MODE)); |
| | | |
| | | // 不含税单价(直接保留2位小数) |
| | | BigDecimal priceExcludingTax = totalCost.divide(TAX_RATE, SCALE, ROUNDING_MODE); |
| | | pending.setPriceExcludingTax(priceExcludingTax); |
| | | |
| | | // 不含税总价 |
| | | BigDecimal totalPriceExcludingTax = priceExcludingTax.multiply(productionQuantity) |
| | | .setScale(SCALE, ROUNDING_MODE); |
| | | pending.setTotalPriceExcludingTax(totalPriceExcludingTax); |
| | | |
| | | pending.setRegistrantId(p.getProducerId()); |
| | | pending.setRegistrationDate(LocalDate.now()); |
| | | pendingInventoryMapper.insert(pending); |
| | |
| | | } |
| | | |
| | | // 批量更新官方库存 |
| | | 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()) { |