|
@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.system.utils.UserUtil;
|
|
@@ -14,6 +15,7 @@ import com.sd.business.entity.bom.vo.BomSpecVo;
|
|
|
import com.sd.business.entity.in.po.InOutStorageDetails;
|
|
|
import com.sd.business.entity.inventory.bo.InOutFun;
|
|
|
import com.sd.business.entity.inventory.dto.InventorySelectDto;
|
|
|
+import com.sd.business.entity.inventory.po.BalancePriceNum;
|
|
|
import com.sd.business.entity.inventory.po.Inventory;
|
|
|
import com.sd.business.entity.inventory.po.InventoryBackup;
|
|
|
import com.sd.business.entity.inventory.vo.InventoryVo;
|
|
@@ -21,6 +23,8 @@ import com.sd.business.entity.inventory.vo.QuantityByDepartmentVo;
|
|
|
import com.sd.business.entity.inventory.vo.QuantityByWarehouseVo;
|
|
|
import com.sd.business.mapper.inventory.InventoryMapper;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
|
+import com.sd.business.service.in.InOutStorageDetailsService;
|
|
|
+import com.sd.business.service.in.InOutStorageService;
|
|
|
import com.sd.business.service.inventory.InventoryService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -30,6 +34,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
@@ -51,7 +56,8 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
private BomSpecService bomSpecService;
|
|
|
|
|
|
@Autowired
|
|
|
- private InventoryMapper inventoryMapper;
|
|
|
+ private InOutStorageDetailsService detailsService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Page<InventoryVo> getPage(InventorySelectDto dto, String tableName) {
|
|
@@ -94,22 +100,18 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
synchronized (this) {
|
|
|
List<Inventory> inventoryList = getInventoryList(departmentId, warehouseId, bomSpecIdList);
|
|
|
Map<Long, Inventory> map = inventoryList.stream().collect(Collectors.toMap(Inventory::getBomSpecId, Function.identity()));
|
|
|
+
|
|
|
+
|
|
|
for (InOutFun inOutFun : list) {
|
|
|
Long bomSpecId = inOutFun.getBomSpecId();
|
|
|
BigDecimal quantity = inOutFun.getQuantity();
|
|
|
BigDecimal unitPrice = inOutFun.getUnitPrice();
|
|
|
Inventory inventory = map.get(bomSpecId);
|
|
|
|
|
|
-
|
|
|
- BigDecimal balanceNum = inventoryMapper.getNum(bomSpecId,warehouseId);
|
|
|
- if (balanceNum == null){
|
|
|
- balanceNum = BigDecimal.ZERO;
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal balancePrice = inventoryMapper.getprice(bomSpecId,warehouseId);
|
|
|
- if (balancePrice == null){
|
|
|
- balancePrice = BigDecimal.ZERO;
|
|
|
- }
|
|
|
+
|
|
|
+ BalancePriceNum priceAndNum = baseMapper.getPriceAndNum(bomSpecId, warehouseId);
|
|
|
+ BigDecimal balanceNum = priceAndNum.getBalanceNum();
|
|
|
+ BigDecimal balancePrice = priceAndNum.getBalancePrice();
|
|
|
|
|
|
|
|
|
balanceNum = balanceNum.add(quantity);
|
|
@@ -156,31 +158,64 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for (Inventory inventory : inventoryList) {
|
|
|
+
|
|
|
+ List<InOutStorageDetails> detailsList = getDetailsList(warehouseId, bomSpecIdList);
|
|
|
+ List<InOutStorageDetails> updateList = new ArrayList<>();
|
|
|
+ List<InOutStorageDetails> outDetailsList = new ArrayList<>();
|
|
|
+ Map<Long,BigDecimal> outPriceMap = new HashMap<>();
|
|
|
|
|
|
-
|
|
|
- List<InOutStorageDetails> detailsList = inventoryMapper.getInOutDetails(inventory.getWarehouseId(),inventory.getDepartmentId(),inventory.getBomSpecId());
|
|
|
- if (CollUtil.isEmpty(detailsList)){
|
|
|
- throw new ServiceException("库存为空");
|
|
|
+ for (int i = 0; i < detailsList.size(); i++) {
|
|
|
+ InOutStorageDetails details = detailsList.get(i);
|
|
|
+ }
|
|
|
+ for (InOutStorageDetails details : detailsList) {
|
|
|
+
|
|
|
+ BigDecimal outNum = map.get(details.getBomSpecId());
|
|
|
+ if (details.getQuantity().compareTo(outNum) >= 0){
|
|
|
+
|
|
|
+ details.setQuantity(details.getQuantity().subtract(outNum));
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal outPrice = details.getInUnitPrice().multiply(outNum);
|
|
|
+ outPriceMap.put(details.getBomSpecId(),outPrice);
|
|
|
+
|
|
|
+
|
|
|
+ updateList.add(details);
|
|
|
+
|
|
|
+ InOutStorageDetails outStorageDetails = new InOutStorageDetails();
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(details,outStorageDetails);
|
|
|
+
|
|
|
+ outStorageDetails.setQuantity(outNum);
|
|
|
+ outStorageDetails.setId(null);
|
|
|
+ outStorageDetails.setType(0L);
|
|
|
+
|
|
|
+ outDetailsList.add(outStorageDetails);
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- InOutStorageDetails inOutDetails = detailsList.get(0);
|
|
|
- BigDecimal quantity = inOutDetails.getQuantity();
|
|
|
-
|
|
|
- int i = inventory.getQuantity().compareTo(quantity);
|
|
|
- if (i >= 0){
|
|
|
-
|
|
|
- inventory.setQuantity(inventory.getQuantity().subtract(map.get(inventory.getBomSpecId())));
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal remainderNum = outNum.subtract(details.getQuantity());
|
|
|
+ if (remainderNum.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ details.setQuantity(BigDecimal.ZERO);
|
|
|
+ updateList.add(details);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ detailsService.updateBatchById(updateList);
|
|
|
+ detailsService.saveBatch(outDetailsList);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ for (Inventory inventory : inventoryList) {
|
|
|
+
|
|
|
+ BigDecimal balancePrice = inventory.getQuantity().multiply(inventory.getBalanceUnitPrice());
|
|
|
+
|
|
|
+ BigDecimal newBalancePrice = balancePrice.subtract(outPriceMap.get(inventory.getBomSpecId()));
|
|
|
+
|
|
|
+ inventory.setQuantity(inventory.getQuantity().subtract(map.get(inventory.getBomSpecId())));
|
|
|
+
|
|
|
+ BigDecimal balanceUnitPrice = newBalancePrice.divide(inventory.getQuantity(),2,BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
}
|
|
|
updateBatchById(inventoryList);
|
|
|
}
|
|
@@ -195,5 +230,12 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ private List<InOutStorageDetails> getDetailsList(Long warehouseId, List<Long> bomSpecIdList) {
|
|
|
+ return detailsService.list(q -> q
|
|
|
+ .eq(InOutStorageDetails::getWarehouseId, warehouseId)
|
|
|
+ .in(InOutStorageDetails::getBomSpecId, bomSpecIdList)
|
|
|
+ .isNotNull(InOutStorageDetails::getQuantity)
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
}
|