|
@@ -1,20 +1,15 @@
|
|
|
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.SecurityUtils;
|
|
|
-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.dto.QuantityByWarehouseDto;
|
|
|
import com.sd.business.entity.inventory.po.BalancePriceNum;
|
|
|
import com.sd.business.entity.inventory.po.Inventory;
|
|
|
import com.sd.business.entity.inventory.po.InventoryBackup;
|
|
@@ -24,13 +19,10 @@ 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;
|
|
|
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;
|
|
@@ -56,8 +48,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
private BomSpecService bomSpecService;
|
|
|
|
|
|
@Autowired
|
|
|
- private InOutStorageDetailsService detailsService;
|
|
|
-
|
|
|
+ private InOutStorageDetailsService inOutStorageDetailsService;
|
|
|
|
|
|
@Override
|
|
|
public Page<InventoryVo> getPage(InventorySelectDto dto, String tableName) {
|
|
@@ -83,9 +74,10 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public List<QuantityByWarehouseVo> getQuantityByWarehouse() {
|
|
|
- return baseMapper.getQuantityByWarehouse();
|
|
|
+ public List<QuantityByWarehouseVo> getQuantityByWarehouse(QuantityByWarehouseDto dto) {
|
|
|
+ return baseMapper.getQuantityByWarehouse(dto);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -101,24 +93,12 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
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);
|
|
|
|
|
|
- //根据bom规格id和仓库id获取结存金额和结存数量
|
|
|
- BalancePriceNum priceAndNum = baseMapper.getPriceAndNum(bomSpecId, warehouseId);
|
|
|
- BigDecimal balanceNum = priceAndNum.getBalanceNum();
|
|
|
- BigDecimal balancePrice = priceAndNum.getBalancePrice();
|
|
|
-
|
|
|
- //计算最新的结存数量和结存金额
|
|
|
- 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 {
|
|
@@ -127,12 +107,23 @@ 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);
|
|
|
}
|
|
|
+
|
|
|
+ // 根据bom规格id和仓库id获取结存金额和结存数量
|
|
|
+ BalancePriceNum priceAndNum = baseMapper.getPriceAndNum(bomSpecId, warehouseId);
|
|
|
+ BigDecimal balanceNum = priceAndNum.getBalanceNum();
|
|
|
+ BigDecimal balancePrice = priceAndNum.getBalancePrice();
|
|
|
+
|
|
|
+ // 计算最新的结存数量和结存金额
|
|
|
+ balanceNum = balanceNum.add(quantity);
|
|
|
+ BigDecimal balancep = quantity.multiply(unitPrice);
|
|
|
+ balancePrice = balancePrice.add(balancep);
|
|
|
+ BigDecimal balanceUnitPrice = balancePrice.divide(balanceNum, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
}
|
|
|
+
|
|
|
saveOrUpdateBatch(inventoryList);
|
|
|
}
|
|
|
|
|
@@ -167,6 +158,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
for (int i = 0; i < detailsList.size(); i++) {
|
|
|
InOutStorageDetails details = detailsList.get(i);
|
|
|
}
|
|
|
+
|
|
|
for (InOutStorageDetails details : detailsList) {
|
|
|
//如果数量足够减扣
|
|
|
BigDecimal outNum = map.get(details.getBomSpecId());
|
|
@@ -192,28 +184,28 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
outDetailsList.add(outStorageDetails);
|
|
|
break;
|
|
|
}
|
|
|
- //数量不够减扣
|
|
|
- //获取剩余的数量
|
|
|
+ // 数量不够减扣
|
|
|
+ // 获取剩余的数量
|
|
|
BigDecimal remainderNum = outNum.subtract(details.getQuantity());
|
|
|
- if (remainderNum.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ if (remainderNum.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
details.setQuantity(BigDecimal.ZERO);
|
|
|
updateList.add(details);
|
|
|
}
|
|
|
- //TODO 这时候需要顺延到下一条记录,暂时没想好怎么顺
|
|
|
- //上面也许可以不用增强for,普通for试试
|
|
|
+ // TODO 这时候需要顺延到下一条记录,暂时没想好怎么顺
|
|
|
+ // 上面也许可以不用增强for,普通for试试
|
|
|
}
|
|
|
- detailsService.updateBatchById(updateList);
|
|
|
- detailsService.saveBatch(outDetailsList);
|
|
|
+ inOutStorageDetailsService.updateBatchById(updateList);
|
|
|
+ inOutStorageDetailsService.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);
|
|
|
+ // 获取最后的结存单价
|
|
|
+ BigDecimal balanceUnitPrice = newBalancePrice.divide(inventory.getQuantity(), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
//将数据存入对象
|
|
|
inventory.setBalanceUnitPrice(balanceUnitPrice);
|
|
|
}
|
|
@@ -231,7 +223,7 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
|
|
|
}
|
|
|
|
|
|
private List<InOutStorageDetails> getDetailsList(Long warehouseId, List<Long> bomSpecIdList) {
|
|
|
- return detailsService.list(q -> q
|
|
|
+ return inOutStorageDetailsService.list(q -> q
|
|
|
.eq(InOutStorageDetails::getWarehouseId, warehouseId)
|
|
|
.in(InOutStorageDetails::getBomSpecId, bomSpecIdList)
|
|
|
.isNotNull(InOutStorageDetails::getQuantity)
|