From 14abea221d9284d2c04a726ca039defa60f205e2 Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Thu, 30 Jun 2022 20:56:06 +0800
Subject: [PATCH] 1、接口对接,增加库存判断,省市县对接,动态调整库存

---
 src/main/java/org/springblade/modules/sale/controller/SaleController.java |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/main/java/org/springblade/modules/sale/controller/SaleController.java b/src/main/java/org/springblade/modules/sale/controller/SaleController.java
index b2ee976..706737e 100644
--- a/src/main/java/org/springblade/modules/sale/controller/SaleController.java
+++ b/src/main/java/org/springblade/modules/sale/controller/SaleController.java
@@ -28,6 +28,8 @@
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.modules.farmplant.service.FarmProductStockService;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.RequestParam;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -49,6 +51,7 @@
 public class SaleController extends BladeController {
 
 	private final ISaleService saleService;
+	private final FarmProductStockService farmProductStockService;
 
 	/**
 	 * 详情
@@ -110,6 +113,13 @@
 	@ApiOperationSupport(order = 6)
 	@ApiOperation(value = "新增或修改", notes = "传入sale")
 	public R submit(@Valid @RequestBody Sale sale) {
+		boolean res = farmProductStockService.stockCompare(sale.getSaleNum(),sale.getStrainId());
+		if (!res){
+			throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
+		}else {
+			//库存充足,减去相应库存
+			farmProductStockService.stockReduce(sale.getSaleNum(),sale.getStrainId());
+		}
 		return R.status(saleService.saveOrUpdate(sale));
 	}
 

--
Gitblit v1.9.3