|
@@ -1,11 +1,17 @@
|
|
|
package com.sd.business.service.inventory.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+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.StringUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.ruoyi.system.utils.UserUtil;
|
|
|
import com.sd.business.entity.bom.po.Bom;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
+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.Inventory;
|
|
@@ -16,8 +22,11 @@ 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.inventory.InventoryService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
@@ -41,6 +50,9 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
@Autowired
|
|
|
private BomSpecService bomSpecService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InventoryMapper inventoryMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<InventoryVo> getPage(InventorySelectDto dto, String tableName) {
|
|
|
IWrapper<Inventory> wrapper = getWrapper();
|
|
@@ -85,7 +97,26 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
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;
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算最新的结存数量和结存金额
|
|
|
+ balanceNum = balanceNum.add(quantity);
|
|
|
+ BigDecimal balancep = quantity.multiply(unitPrice);
|
|
|
+ balancePrice = balancePrice.add(balancep);
|
|
|
+ BigDecimal balanceUnitPrice = balancePrice.divide(balanceNum,2,BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
if (inventory != null) {
|
|
|
inventory.setQuantity(inventory.getQuantity().add(quantity));
|
|
|
} else {
|
|
@@ -94,6 +125,8 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
inventory.setDepartmentId(departmentId);
|
|
|
inventory.setBomSpecId(bomSpecId);
|
|
|
inventory.setQuantity(quantity);
|
|
|
+ inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
+
|
|
|
inventoryList.add(inventory);
|
|
|
map.put(bomSpecId, inventory);
|
|
|
}
|
|
@@ -124,7 +157,30 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
}
|
|
|
|
|
|
for (Inventory inventory : inventoryList) {
|
|
|
- inventory.setQuantity(inventory.getQuantity().subtract(map.get(inventory.getBomSpecId())));
|
|
|
+
|
|
|
+ //获取出入详情表中的信息
|
|
|
+ List<InOutStorageDetails> detailsList = inventoryMapper.getInOutDetails(inventory.getWarehouseId(),inventory.getDepartmentId(),inventory.getBomSpecId());
|
|
|
+ if (CollUtil.isEmpty(detailsList)){
|
|
|
+ throw new ServiceException("库存为空");
|
|
|
+ }
|
|
|
+ //按照时间进行排序后获取最早入库的数据
|
|
|
+ //TODO 该地方可能用循环
|
|
|
+ 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())));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
updateBatchById(inventoryList);
|
|
|
}
|