|
@@ -389,42 +389,22 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
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())
|
|
|
- );
|
|
|
+ availableQuantity = availableQuantity.subtract(quantity);
|
|
|
} else {
|
|
|
|
|
|
- productStockInfoService.update(q -> q
|
|
|
- .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
- .setSql("available_quantity = " + stockThreshold)
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
+ availableQuantity = stockThreshold;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
- );
|
|
|
+ availableQuantity = availableQuantity.subtract(quantity);
|
|
|
}
|
|
|
|
|
|
|
|
|
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())
|
|
|
- );
|
|
|
+ availableQuantity = availableQuantity.add(quantity);
|
|
|
}
|
|
|
|
|
|
else if (ProductAvailableRecordType.PURCHASE_UPDATE.equals(businessType)) {
|
|
@@ -432,44 +412,25 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
if (ObjectUtils.isEmpty(quantity)) {
|
|
|
|
|
|
- productStockInfoService.update(q -> q
|
|
|
- .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
- .setSql("available_quantity = available_quantity + " + newQuantity)
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
+ availableQuantity = availableQuantity.add(newQuantity);
|
|
|
} else if (ObjectUtils.isEmpty(newQuantity)) {
|
|
|
|
|
|
if (inOutBo.getInStockQuantity().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
throw new ServiceException("该采购存在已入库数据禁止变更!");
|
|
|
}
|
|
|
|
|
|
- productStockInfoService.update(q -> q
|
|
|
- .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
- .setSql("available_quantity = available_quantity - " + quantity)
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
+ availableQuantity = availableQuantity.subtract(quantity);
|
|
|
} else if (quantity.compareTo(newQuantity) < 0) {
|
|
|
|
|
|
BigDecimal subtract = newQuantity.subtract(quantity);
|
|
|
- productStockInfoService.update(q -> q
|
|
|
- .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
- .setSql("available_quantity = available_quantity + " + subtract)
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
+
|
|
|
+ availableQuantity = availableQuantity.add(subtract);
|
|
|
} else if (quantity.compareTo(newQuantity) > 0) {
|
|
|
|
|
|
if (newQuantity.compareTo(inOutBo.getInStockQuantity()) >= 0) {
|
|
|
BigDecimal subtract = quantity.subtract(newQuantity);
|
|
|
|
|
|
- productStockInfoService.update(q -> q
|
|
|
- .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
- .setSql("available_quantity = available_quantity - " + subtract)
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
+ availableQuantity = availableQuantity.subtract(subtract);
|
|
|
} else {
|
|
|
|
|
|
throw new ServiceException("新采购量小于已入库数据,禁止变更!");
|
|
@@ -483,18 +444,17 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
if (newQuantity.compareTo(inOutBo.getQuantity()) > 0) {
|
|
|
BigDecimal subtract = newQuantity.subtract(inOutBo.getQuantity());
|
|
|
- productStockInfoService.update(q -> q
|
|
|
- .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
- .setSql("available_quantity = available_quantity + " + subtract)
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
+ availableQuantity = availableQuantity.add(subtract);
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal subtract1 = availableQuantity.subtract(subtract);
|
|
|
+ BigDecimal requiredQuantity = stockThreshold.subtract(subtract1);
|
|
|
+ inOutBo.setNewQuantity(requiredQuantity);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
else if (newQuantity.compareTo(inOutBo.getQuantity()) < 0) {
|
|
|
|
|
|
- BigDecimal count = BigDecimal.ZERO;
|
|
|
-
|
|
|
|
|
|
if (newQuantity.compareTo(inOutBo.getInStockQuantity()) > 0) {
|
|
|
BigDecimal subtract = newQuantity.subtract(inOutBo.getInStockQuantity());
|
|
@@ -503,7 +463,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
availableQuantity = availableQuantity.subtract(subtract);
|
|
|
}
|
|
|
|
|
|
- if (newQuantity.compareTo(inOutBo.getInStockQuantity()) < 0) {
|
|
|
+ else if (newQuantity.compareTo(inOutBo.getInStockQuantity()) < 0) {
|
|
|
BigDecimal subtract = inOutBo.getQuantity().subtract(inOutBo.getInStockQuantity());
|
|
|
|
|
|
|
|
@@ -514,18 +474,23 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
availableQuantity = BigDecimal.ZERO;
|
|
|
}
|
|
|
|
|
|
- BigDecimal finalAvailableQuantity = availableQuantity;
|
|
|
- productStockInfoService.update(q -> q
|
|
|
- .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
- .set(ProductStockInfo::getAvailableQuantity, finalAvailableQuantity)
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
+
|
|
|
+ inOutBo.setNewQuantity(BigDecimal.ZERO);
|
|
|
+
|
|
|
}
|
|
|
} else {
|
|
|
throw new ServiceException("未知操作类型,请联系管理员!");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ BigDecimal finalAvailableQuantity = availableQuantity;
|
|
|
+ productStockInfoService.update(q -> q
|
|
|
+ .eq(ProductStockInfo::getId, productStockInfoId)
|
|
|
+ .set(ProductStockInfo::getAvailableQuantity, finalAvailableQuantity)
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|