main-business/src/main/java/com/ruoyi/business/service/InventorySummaryService.java
@@ -1,9 +1,11 @@ package com.ruoyi.business.service; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.business.dto.OfficialInventoryDto; import com.ruoyi.business.dto.PendingInventoryDto; import com.ruoyi.business.entity.InventorySummary; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; /** * <p> @@ -21,4 +23,11 @@ * @param officialInventoryDto æ£å¼åºå */ int updateInventory(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto); /** * æ¹éæ´æ°åºå * @param ids åºåid * @return */ int updateInventorySummary(List<Long> ids); } main-business/src/main/java/com/ruoyi/business/service/impl/InputInventoryRecordServiceImpl.java
@@ -11,6 +11,7 @@ import com.ruoyi.business.mapper.InventorySummaryMapper; import com.ruoyi.business.service.InputInventoryRecordService; import com.ruoyi.business.service.InventorySummaryService; import com.ruoyi.business.utils.InventoryUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,6 +20,7 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; import static com.ruoyi.business.constant.InventoryRecordConstant.OFFICIAL_INVENTORY; import static com.ruoyi.business.constant.InventoryRecordConstant.PENDING_INVENTORY; @@ -37,6 +39,7 @@ private final InputInventoryRecordMapper inputInventoryRecordMapper; private final InventorySummaryService inventorySummaryService; private final InventorySummaryMapper inventorySummaryMapper; private final InventoryUtils inventoryUtils; @Override public int insertInputInventoryRecord(PendingInventoryDto pendingInventoryDto, OfficialInventoryDto officialInventoryDto, BigDecimal quantity) { @@ -62,7 +65,9 @@ @Override public int deleteInputInventoryRecord(List<Long> ids) { if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isEmpty(ids)) { throw new RuntimeException("è¯·ä¼ å ¥è¦å é¤çidè®°å½"); } List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectBatchIds(ids); // æ ¹æ®idè¿è¡éåºæåº List<InputInventoryRecord> inputInventoryRecordList = inputInventoryRecords.stream() @@ -70,14 +75,14 @@ .toList(); String InventoryType = inputInventoryRecords.get(0).getInventoryType(); List<Long> inventoryIds = inputInventoryRecords.stream().map(InputInventoryRecord::getInventoryId).toList(); List<Long> inventoryIds = inputInventoryRecords.stream().map(InputInventoryRecord::getInventoryId).toList().stream().distinct().collect(Collectors.toList()); List<InventorySummary> inventorySummaries = inventorySummaryMapper.selectList(new LambdaQueryWrapper<InventorySummary>() .eq(InventorySummary::getInventoryType, InventoryType) .in(InventorySummary::getInventoryId, inventoryIds)); if (CollectionUtils.isNotEmpty(inventorySummaries)) { List<InventorySummary> updates = new ArrayList<>(); for (InventorySummary inventorySummary : inventorySummaries) { for (InputInventoryRecord inputInventoryRecord : inputInventoryRecords) { for (InputInventoryRecord inputInventoryRecord : inputInventoryRecordList) { // 妿èç¹ä¸çå ¥åºè®°å½id大äºåæ´çidï¼è¯´ææ¤idåææå ¥åºè®°å½é½è¦éæ°è®¡ç® if (Objects.equals(inventorySummary.getInventoryId(), inputInventoryRecord.getInventoryId()) && inventorySummary.getInputEndRecordId() > inputInventoryRecord.getId()) { inventorySummary.setInputEndRecordId(inputInventoryRecord.getId()); @@ -86,12 +91,15 @@ } } // éç½®ä»ä»¬çèç¹æç»id // éç½®èç¹æç»id inventorySummaryMapper.updateById(updates); } } // todo éæ°è®¡ç®èç¹åºå // todo æ´æ°åºå宿½æ°æ® // éæ°è®¡ç®èç¹åºå inventorySummaryService.updateInventorySummary(ids); // æ´æ°åºå宿¶æ°æ® inventoryUtils.updateInventoryByIds(inventoryIds, inputInventoryRecords.get(0).getInventoryType()); // å é¤å ¥åºè®°å½ main-business/src/main/java/com/ruoyi/business/service/impl/InventorySummaryServiceImpl.java
@@ -87,4 +87,29 @@ return officialInventoryMapper.updateById(officialInventory); } } @Override public int updateInventorySummary(List<Long> ids) { List<InventorySummary> inventorySummaries = inventorySummaryMapper.selectBatchIds(ids); for (InventorySummary inventorySummary : inventorySummaries) { // æ¥è¯¢èç¹ä¹åææå ¥åºè®°å½ List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectList(new LambdaQueryWrapper<InputInventoryRecord>() .eq(InputInventoryRecord::getInventoryId, inventorySummary.getInventoryId()) .eq(InputInventoryRecord::getInventoryType, inventorySummary.getInventoryType()) .lt(InputInventoryRecord::getId, inventorySummary.getInputEndRecordId())); // æ¥è¯¢èç¹ä¹åææåºåºè®°å½ List<OutputInventoryRecord> outputInventoryRecords = outputInventoryRecordMapper.selectList(new LambdaQueryWrapper<OutputInventoryRecord>() .eq(OutputInventoryRecord::getInventoryId, inventorySummary.getInventoryId()) .eq(OutputInventoryRecord::getInventoryType, inventorySummary.getInventoryType()) .lt(OutputInventoryRecord::getId, inventorySummary.getOutputEndRecordId())); // 计ç®åºåæ°é BigDecimal inputQuantity = inputInventoryRecords.stream().map(InputInventoryRecord::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal outputQuantity = outputInventoryRecords.stream().map(OutputInventoryRecord::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add); inventorySummary.setInventoryQuantity(inputQuantity.subtract(outputQuantity)); } return inventorySummaryMapper.updateById(inventorySummaries).size(); } } main-business/src/main/java/com/ruoyi/business/utils/InventoryUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,73 @@ package com.ruoyi.business.utils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.business.constant.InventoryRecordConstant; import com.ruoyi.business.entity.*; import com.ruoyi.business.mapper.*; import com.ruoyi.common.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.util.List; @Component public class InventoryUtils { @Autowired private InventorySummaryMapper inventorySummaryMapper; @Autowired private InputInventoryRecordMapper inputInventoryRecordMapper; @Autowired private OutputInventoryRecordMapper outputInventoryRecordMapper; @Autowired private OfficialInventoryMapper officialInventoryMapper; @Autowired private PendingInventoryMapper pendingInventoryMapper; /** * æ´æ°åºå */ public void updateInventoryByIds(List<Long> ids, String type) { if (StringUtils.isEmpty(type)) { throw new RuntimeException("请æå®åºåç±»å"); } for (Long id : ids) { // è·ååºåèç¹ InventorySummary inventorySummary = inventorySummaryMapper.selectOne(new LambdaQueryWrapper<InventorySummary>() .eq(InventorySummary::getInventoryId, id) .eq(InventorySummary::getInventoryType, type)); Long inputEndRecordId = inventorySummary != null ? inventorySummary.getInputEndRecordId() : 0L; Long outputEndRecordId = inventorySummary != null ? inventorySummary.getOutputEndRecordId() : 0L; List<InputInventoryRecord> inputInventoryRecords = inputInventoryRecordMapper.selectList(new LambdaQueryWrapper<InputInventoryRecord>() .eq(InputInventoryRecord::getInventoryId, id) .eq(InputInventoryRecord::getInventoryType, type) .gt(InputInventoryRecord::getId, inputEndRecordId)); List<OutputInventoryRecord> outputInventoryRecords = outputInventoryRecordMapper.selectList(new LambdaQueryWrapper<OutputInventoryRecord>() .eq(OutputInventoryRecord::getInventoryId, id) .eq(OutputInventoryRecord::getInventoryType, type) .gt(OutputInventoryRecord::getId, outputEndRecordId)); // è·ååºåæ°æ® BigDecimal inputQuantity = inputInventoryRecords.stream().map(InputInventoryRecord::getQuantity).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); BigDecimal outputQuantity = outputInventoryRecords.stream().map(OutputInventoryRecord::getQuantity).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); // 计ç®è¿æ¬¡åºåæ°æ® BigDecimal quantity = inventorySummary != null ? inventorySummary.getInventoryQuantity().add(inputQuantity.subtract(outputQuantity)) : inputQuantity.subtract(outputQuantity); if (inventorySummary != null) { if (type.equals(InventoryRecordConstant.OFFICIAL_INVENTORY)) { OfficialInventory update = new OfficialInventory(); update.setInventoryQuantity(quantity); update.setId(id); officialInventoryMapper.updateById(update); } else { PendingInventory update = new PendingInventory(); update.setInventoryQuantity(quantity); update.setId(id); pendingInventoryMapper.updateById(update); } } } } }