|
@@ -13,7 +13,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
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.impl.FtpFileServiceImpl;
|
|
|
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.dto.ProductInfoDto;
|
|
|
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.ProductInfo;
|
|
|
import com.fjhx.item.entity.product.po.ProductStockInfo;
|
|
@@ -342,20 +340,23 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
* 修改可用库存
|
|
|
*
|
|
|
* @param inOutList 产品列表
|
|
|
- * @param inOutType 1添加 2减少
|
|
|
*/
|
|
|
@DSTransactional
|
|
|
@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) {
|
|
|
-
|
|
|
+ Long materialId = inOutBo.getProductId();
|
|
|
+ BigDecimal quantity = inOutBo.getQuantity();
|
|
|
+
|
|
|
+
|
|
|
+ ProductInfo materialInfo = materialMap.get(materialId);
|
|
|
+ BigDecimal stockThreshold = materialInfo.getStockThreshold();
|
|
|
+
|
|
|
+
|
|
|
ProductStockInfo productStockInfo = productStockInfoService.getOne(q -> q
|
|
|
.eq(ProductStockInfo::getProductId, inOutBo.getProductId())
|
|
|
.eq(ProductStockInfo::getCompanyId, companyId)
|
|
@@ -367,45 +368,102 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
productStockInfo.setProductId(inOutBo.getProductId());
|
|
|
productStockInfoService.save(productStockInfo);
|
|
|
}
|
|
|
-
|
|
|
- BigDecimal availableQuantityNew;
|
|
|
- BigDecimal edQuantity = inOutBo.getQuantity();
|
|
|
-
|
|
|
+ Long productStockInfoId = productStockInfo.getId();
|
|
|
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)) {
|
|
|
+
|
|
|
+ BigDecimal subtract = availableQuantity.subtract(quantity);
|
|
|
+ BigDecimal requiredQuantity = stockThreshold.subtract(subtract);
|
|
|
+
|
|
|
+
|
|
|
+ inOutBo.setQuantity(requiredQuantity);
|
|
|
+
|
|
|
+
|
|
|
+ if (requiredQuantity.compareTo(BigDecimal.ZERO) < 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 {
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|