|
@@ -1,16 +1,20 @@
|
|
package com.fjhx.service.check.impl;
|
|
package com.fjhx.service.check.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fjhx.base.Condition;
|
|
import com.fjhx.base.Condition;
|
|
import com.fjhx.entity.check.CheckDetails;
|
|
import com.fjhx.entity.check.CheckDetails;
|
|
import com.fjhx.entity.check.CheckInfo;
|
|
import com.fjhx.entity.check.CheckInfo;
|
|
|
|
+import com.fjhx.entity.stock.Stock;
|
|
import com.fjhx.entity.warehouse.Warehouse;
|
|
import com.fjhx.entity.warehouse.Warehouse;
|
|
import com.fjhx.mapper.check.CheckInfoMapper;
|
|
import com.fjhx.mapper.check.CheckInfoMapper;
|
|
import com.fjhx.params.check.CheckInfoVo;
|
|
import com.fjhx.params.check.CheckInfoVo;
|
|
import com.fjhx.service.check.CheckDetailsService;
|
|
import com.fjhx.service.check.CheckDetailsService;
|
|
import com.fjhx.service.check.CheckInfoService;
|
|
import com.fjhx.service.check.CheckInfoService;
|
|
|
|
+import com.fjhx.service.form.FormOverflowLossService;
|
|
|
|
+import com.fjhx.service.stock.StockService;
|
|
import com.fjhx.uitl.code.CodeEnum;
|
|
import com.fjhx.uitl.code.CodeEnum;
|
|
import com.fjhx.utils.Assert;
|
|
import com.fjhx.utils.Assert;
|
|
import com.fjhx.utils.UserClientUtil;
|
|
import com.fjhx.utils.UserClientUtil;
|
|
@@ -22,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -37,6 +42,12 @@ public class CheckInfoServiceImpl extends ServiceImpl<CheckInfoMapper, CheckInfo
|
|
@Autowired
|
|
@Autowired
|
|
private CheckDetailsService checkDetailsService;
|
|
private CheckDetailsService checkDetailsService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private StockService stockService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FormOverflowLossService formOverflowLossService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Page<Map<String, Object>> getPage(Condition condition) {
|
|
public Page<Map<String, Object>> getPage(Condition condition) {
|
|
|
|
|
|
@@ -65,32 +76,55 @@ public class CheckInfoServiceImpl extends ServiceImpl<CheckInfoMapper, CheckInfo
|
|
Long warehouseId = checkInfoVo.getWarehouseId();
|
|
Long warehouseId = checkInfoVo.getWarehouseId();
|
|
Assert.notEmpty(warehouseId, "仓库id不能为空");
|
|
Assert.notEmpty(warehouseId, "仓库id不能为空");
|
|
|
|
|
|
|
|
+ // 最总盘点结论(0正常 1异常)类型
|
|
int checkResultType = 0;
|
|
int checkResultType = 0;
|
|
|
|
|
|
List<CheckDetails> checkDetailsList = checkInfoVo.getCheckDetailsList();
|
|
List<CheckDetails> checkDetailsList = checkInfoVo.getCheckDetailsList();
|
|
|
|
|
|
|
|
+ // 盘盈金额
|
|
|
|
+ BigDecimal overflowAmount = BigDecimal.ZERO;
|
|
|
|
+
|
|
|
|
+ // 盘亏金额
|
|
|
|
+ BigDecimal lossAmount = BigDecimal.ZERO;
|
|
|
|
+
|
|
|
|
+ // 获取商品加权平均价
|
|
|
|
+ List<Long> productIdList = checkDetailsList.stream().map(CheckDetails::getProductId).collect(Collectors.toList());
|
|
|
|
+ Map<Long, BigDecimal> kv = stockService.getKV(Stock::getGoodsId, Stock::getWeightingAveragePrice,
|
|
|
|
+ q -> q.eq(Stock::getWarehouseId, warehouseId).in(Stock::getGoodsId, productIdList));
|
|
|
|
+
|
|
for (CheckDetails checkDetails : checkDetailsList) {
|
|
for (CheckDetails checkDetails : checkDetailsList) {
|
|
|
|
+ Long productId = checkDetails.getProductId();
|
|
BigDecimal checkQuantity = checkDetails.getCheckQuantity();
|
|
BigDecimal checkQuantity = checkDetails.getCheckQuantity();
|
|
BigDecimal inventoryQuantity = checkDetails.getInventoryQuantity();
|
|
BigDecimal inventoryQuantity = checkDetails.getInventoryQuantity();
|
|
|
|
|
|
- Assert.notEmpty(checkDetails.getProductId(), "产品id不能为空");
|
|
|
|
|
|
+
|
|
|
|
+ Assert.notEmpty(productId, "产品id不能为空");
|
|
Assert.notEmpty(checkQuantity, "盘点数量不能为空");
|
|
Assert.notEmpty(checkQuantity, "盘点数量不能为空");
|
|
Assert.notEmpty(inventoryQuantity, "现有库存不能为空");
|
|
Assert.notEmpty(inventoryQuantity, "现有库存不能为空");
|
|
|
|
|
|
checkDetails.setCheckInfoId(id);
|
|
checkDetails.setCheckInfoId(id);
|
|
|
|
|
|
- int compareTo = inventoryQuantity.compareTo(checkQuantity);
|
|
|
|
- if (compareTo > 0) {
|
|
|
|
|
|
+ int flag = inventoryQuantity.compareTo(checkQuantity);
|
|
|
|
+ if (flag > 0) {
|
|
checkDetails.setResultType(2);
|
|
checkDetails.setResultType(2);
|
|
checkResultType = 1;
|
|
checkResultType = 1;
|
|
- } else if (compareTo < 0) {
|
|
|
|
|
|
+
|
|
|
|
+ // 添加盘亏金额
|
|
|
|
+ BigDecimal weightingAveragePrice = ObjectUtil.defaultIfNull(kv.get(productId), BigDecimal.ZERO);
|
|
|
|
+ lossAmount = lossAmount.add(inventoryQuantity.subtract(checkQuantity).multiply(weightingAveragePrice));
|
|
|
|
+ } else if (flag < 0) {
|
|
checkDetails.setResultType(1);
|
|
checkDetails.setResultType(1);
|
|
checkResultType = 1;
|
|
checkResultType = 1;
|
|
|
|
+
|
|
|
|
+ // 添加盘盈金额
|
|
|
|
+ BigDecimal weightingAveragePrice = ObjectUtil.defaultIfNull(kv.get(productId), BigDecimal.ZERO);
|
|
|
|
+ overflowAmount = overflowAmount.add(checkQuantity.subtract(inventoryQuantity).multiply(weightingAveragePrice));
|
|
} else {
|
|
} else {
|
|
checkDetails.setResultType(0);
|
|
checkDetails.setResultType(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 添加盘点记录
|
|
synchronized (this) {
|
|
synchronized (this) {
|
|
checkInfoVo.setId(id);
|
|
checkInfoVo.setId(id);
|
|
checkInfoVo.setResultType(checkResultType);
|
|
checkInfoVo.setResultType(checkResultType);
|
|
@@ -98,7 +132,17 @@ public class CheckInfoServiceImpl extends ServiceImpl<CheckInfoMapper, CheckInfo
|
|
save(checkInfoVo);
|
|
save(checkInfoVo);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 添加盘点明细
|
|
checkDetailsService.saveBatch(checkDetailsList);
|
|
checkDetailsService.saveBatch(checkDetailsList);
|
|
|
|
+
|
|
|
|
+ // 添加溢损单
|
|
|
|
+ if (overflowAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
+ formOverflowLossService.addOverflow(1, id, warehouseId, overflowAmount, "");
|
|
|
|
+ }
|
|
|
|
+ if (lossAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
+ formOverflowLossService.addLoss(1, id, warehouseId, lossAmount, "");
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|