|
@@ -13,7 +13,6 @@ 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.common.constant.SourceConstant;
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
import com.fjhx.common.entity.InOutBo;
|
|
import com.fjhx.common.entity.InOutBo;
|
|
-import com.fjhx.common.enums.InOutType;
|
|
|
|
import com.fjhx.common.service.file.FtpFileService;
|
|
import com.fjhx.common.service.file.FtpFileService;
|
|
import com.fjhx.common.service.file.impl.FtpFileServiceImpl;
|
|
import com.fjhx.common.service.file.impl.FtpFileServiceImpl;
|
|
import com.fjhx.file.entity.FileInfoVo;
|
|
import com.fjhx.file.entity.FileInfoVo;
|
|
@@ -22,7 +21,6 @@ import com.fjhx.item.entity.product.bo.ProductAnalysisBo;
|
|
import com.fjhx.item.entity.product.bo.ProductExcelExportBo;
|
|
import com.fjhx.item.entity.product.bo.ProductExcelExportBo;
|
|
import com.fjhx.item.entity.product.dto.ProductInfoDto;
|
|
import com.fjhx.item.entity.product.dto.ProductInfoDto;
|
|
import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
|
|
import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
|
|
-import com.fjhx.item.entity.product.po.ProductAvailableRecord;
|
|
|
|
import com.fjhx.item.entity.product.po.ProductClassify;
|
|
import com.fjhx.item.entity.product.po.ProductClassify;
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
import com.fjhx.item.entity.product.po.ProductStockInfo;
|
|
import com.fjhx.item.entity.product.po.ProductStockInfo;
|
|
@@ -342,20 +340,23 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
* 修改可用库存
|
|
* 修改可用库存
|
|
*
|
|
*
|
|
* @param inOutList 产品列表
|
|
* @param inOutList 产品列表
|
|
- * @param inOutType 1添加 2减少
|
|
|
|
*/
|
|
*/
|
|
@DSTransactional
|
|
@DSTransactional
|
|
@Override
|
|
@Override
|
|
- public synchronized void editAvailableQuantity(List<InOutBo> inOutList, InOutType inOutType, Long businessId, ProductAvailableRecordType businessType, Long companyId) {
|
|
|
|
|
|
+ public synchronized void editAvailableQuantity(List<InOutBo> inOutList, Long businessId, ProductAvailableRecordType businessType, Long companyId) {
|
|
|
|
|
|
- List<Long> pIds = inOutList.stream().map(InOutBo::getProductId).collect(Collectors.toList());
|
|
|
|
- if (ObjectUtil.isEmpty(pIds)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ List<Long> materialIds = inOutList.stream().map(InOutBo::getProductId).collect(Collectors.toList());
|
|
|
|
+ Map<Long, ProductInfo> materialMap = this.mapKEntity(ProductInfo::getId, q -> q.in(ProductInfo::getId, materialIds));
|
|
|
|
|
|
- List<ProductAvailableRecord> availableRecordList = new ArrayList<>();
|
|
|
|
for (InOutBo inOutBo : inOutList) {
|
|
for (InOutBo inOutBo : inOutList) {
|
|
- //查询可用库存
|
|
|
|
|
|
+ Long materialId = inOutBo.getProductId();
|
|
|
|
+ BigDecimal quantity = inOutBo.getQuantity();
|
|
|
|
+
|
|
|
|
+ //获取产品安全库存
|
|
|
|
+ ProductInfo materialInfo = materialMap.get(materialId);
|
|
|
|
+ BigDecimal stockThreshold = materialInfo.getStockThreshold();
|
|
|
|
+
|
|
|
|
+ //获取可用库存
|
|
ProductStockInfo productStockInfo = productStockInfoService.getOne(q -> q
|
|
ProductStockInfo productStockInfo = productStockInfoService.getOne(q -> q
|
|
.eq(ProductStockInfo::getProductId, inOutBo.getProductId())
|
|
.eq(ProductStockInfo::getProductId, inOutBo.getProductId())
|
|
.eq(ProductStockInfo::getCompanyId, companyId)
|
|
.eq(ProductStockInfo::getCompanyId, companyId)
|
|
@@ -367,45 +368,102 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
productStockInfo.setProductId(inOutBo.getProductId());
|
|
productStockInfo.setProductId(inOutBo.getProductId());
|
|
productStockInfoService.save(productStockInfo);
|
|
productStockInfoService.save(productStockInfo);
|
|
}
|
|
}
|
|
-
|
|
|
|
- BigDecimal availableQuantityNew;
|
|
|
|
- BigDecimal edQuantity = inOutBo.getQuantity();
|
|
|
|
-
|
|
|
|
|
|
+ Long productStockInfoId = productStockInfo.getId();
|
|
BigDecimal availableQuantity = productStockInfo.getAvailableQuantity();
|
|
BigDecimal availableQuantity = productStockInfo.getAvailableQuantity();
|
|
|
|
|
|
- if (inOutType.equals(InOutType.IN)) {
|
|
|
|
- availableQuantityNew = availableQuantity.add(inOutBo.getQuantity());
|
|
|
|
- } else if (inOutType.equals(InOutType.OUT)) {
|
|
|
|
- availableQuantityNew = availableQuantity.subtract(inOutBo.getQuantity());
|
|
|
|
- } else if (inOutType.equals(InOutType.EQ)) {
|
|
|
|
- availableQuantityNew = inOutBo.getQuantity();
|
|
|
|
|
|
|
|
- edQuantity = availableQuantityNew.subtract(availableQuantity);
|
|
|
|
- } else {
|
|
|
|
- throw new ServiceException("未知类型");
|
|
|
|
|
|
+ //下发订单 创建待采购
|
|
|
|
+ if (ProductAvailableRecordType.SALE_PASS.equals(businessType)) {
|
|
|
|
+ //计数需要采购的数量(需采购量 = 安全库存 - (可用库存 - 合同量)若 需采购量<0,则按0算不采购)
|
|
|
|
+ BigDecimal subtract = availableQuantity.subtract(quantity);
|
|
|
|
+ BigDecimal requiredQuantity = stockThreshold.subtract(subtract);
|
|
|
|
+
|
|
|
|
+ //返回需采购量
|
|
|
|
+ inOutBo.setQuantity(requiredQuantity);
|
|
|
|
+
|
|
|
|
+ //计算可用库存
|
|
|
|
+ if (requiredQuantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
+ //需要采购的数量<0 可用库存 = 可用库存 - 合同量
|
|
|
|
+ productStockInfoService.update(q -> q
|
|
|
|
+ .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
|
+ .setSql("available_quantity = available_quantity - " + quantity)
|
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ //需要采购的数量>=0 可用库存 = 安全库存
|
|
|
|
+ productStockInfoService.update(q -> q
|
|
|
|
+ .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
|
+ .setSql("available_quantity = " + stockThreshold)
|
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //销售合同作废 可用库存=可用库存-((待采购量-已采购量)-合同量)
|
|
|
|
+ //申购的-采购合同作废 可用库存 = 当前可用库存 - 采购明细数量
|
|
|
|
+ //手动出库 可用库存 = 当前可用库存 - 出库数量
|
|
|
|
+ else if (ProductAvailableRecordType.SALE_CANCEL.equals(businessType) || ProductAvailableRecordType.PURCHASE_CANCEL.equals(businessType) || ProductAvailableRecordType.HAND_OUT.equals(businessType)) {
|
|
|
|
+ productStockInfoService.update(q -> q
|
|
|
|
+ .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
|
+ .setSql("available_quantity = available_quantity - " + quantity)
|
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ //申购的-采购合同通过 可用库存 = 当前可用库存 + 采购明细数量
|
|
|
|
+ //手动入库 可用库存 = 当前可用库存 + 入库数量
|
|
|
|
+ else if (ProductAvailableRecordType.PURCHASE_PASS.equals(businessType) || ProductAvailableRecordType.HAND_IN.equals(businessType)) {
|
|
|
|
+ productStockInfoService.update(q -> q
|
|
|
|
+ .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
|
+ .setSql("available_quantity = available_quantity + " + quantity)
|
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
- Long productStockInfoId = productStockInfo.getId();
|
|
|
|
- productStockInfoService.update(q -> q
|
|
|
|
- .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
|
- .set(ProductStockInfo::getAvailableQuantity, availableQuantityNew)
|
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
|
- );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- //保存操作记录
|
|
|
|
- ProductAvailableRecord productAvailableRecord = new ProductAvailableRecord();
|
|
|
|
- productAvailableRecord.setBeforeQuantity(productStockInfo.getAvailableQuantity());
|
|
|
|
- productAvailableRecord.setAfterQuantity(availableQuantityNew);
|
|
|
|
- productAvailableRecord.setEditQuantity(edQuantity);
|
|
|
|
- productAvailableRecord.setBusinessId(businessId);
|
|
|
|
- productAvailableRecord.setBusinessType(businessType.getType());
|
|
|
|
- productAvailableRecord.setProductId(inOutBo.getProductId());
|
|
|
|
- productAvailableRecord.setCompanyId(companyId);
|
|
|
|
|
|
|
|
- availableRecordList.add(productAvailableRecord);
|
|
|
|
- }
|
|
|
|
- productAvailableRecordService.saveBatch(availableRecordList);
|
|
|
|
|
|
+ //-------------------------------------
|
|
|
|
+
|
|
|
|
+// List<ProductAvailableRecord> availableRecordList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+// BigDecimal availableQuantityNew;
|
|
|
|
+// BigDecimal edQuantity = inOutBo.getQuantity();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// if (inOutType.equals(InOutType.IN)) {
|
|
|
|
+// availableQuantityNew = availableQuantity.add(inOutBo.getQuantity());
|
|
|
|
+// } else if (inOutType.equals(InOutType.OUT)) {
|
|
|
|
+// availableQuantityNew = availableQuantity.subtract(inOutBo.getQuantity());
|
|
|
|
+// } else if (inOutType.equals(InOutType.EQ)) {
|
|
|
|
+// availableQuantityNew = inOutBo.getQuantity();
|
|
|
|
+//
|
|
|
|
+// edQuantity = availableQuantityNew.subtract(availableQuantity);
|
|
|
|
+// } else {
|
|
|
|
+// throw new ServiceException("未知类型");
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// productStockInfoService.update(q -> q
|
|
|
|
+// .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
|
+// .set(ProductStockInfo::getAvailableQuantity, availableQuantityNew)
|
|
|
|
+// .set(BasePo::getUpdateTime, new Date())
|
|
|
|
+// .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
|
+// );
|
|
|
|
+
|
|
|
|
+// //保存操作记录
|
|
|
|
+// ProductAvailableRecord productAvailableRecord = new ProductAvailableRecord();
|
|
|
|
+// productAvailableRecord.setBeforeQuantity(productStockInfo.getAvailableQuantity());
|
|
|
|
+// productAvailableRecord.setAfterQuantity(availableQuantityNew);
|
|
|
|
+// productAvailableRecord.setEditQuantity(edQuantity);
|
|
|
|
+// productAvailableRecord.setBusinessId(businessId);
|
|
|
|
+// productAvailableRecord.setBusinessType(businessType.getType());
|
|
|
|
+// productAvailableRecord.setProductId(inOutBo.getProductId());
|
|
|
|
+// productAvailableRecord.setCompanyId(companyId);
|
|
|
|
+//
|
|
|
|
+// availableRecordList.add(productAvailableRecord);
|
|
|
|
+// productAvailableRecordService.saveBatch(availableRecordList);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|