From 72b971c98c46531064d74b68fc8fe8864ed0b544 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 08 Nov 2022 09:04:56 +0800
Subject: [PATCH] 大屏溯源统计次数sql修改

---
 src/main/java/org/springblade/modules/sale/controller/SaleController.java |   78 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 68 insertions(+), 10 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 5582a92..ea9f837 100644
--- a/src/main/java/org/springblade/modules/sale/controller/SaleController.java
+++ b/src/main/java/org/springblade/modules/sale/controller/SaleController.java
@@ -29,7 +29,14 @@
 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.InventoryLoss.entity.Inventory;
+import org.springblade.modules.farmplant.entity.FarmProductStock;
 import org.springblade.modules.farmplant.service.FarmProductStockService;
+import org.springblade.modules.process.service.IProcessService;
+import org.springblade.modules.processInv.entity.ProcessInv;
+import org.springblade.modules.processInv.service.IProcessInvService;
+import org.springblade.modules.processInv.vo.ProcessInvVO;
+import org.springblade.modules.retrieval.entity.Retrieval;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.RequestParam;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -37,6 +44,8 @@
 import org.springblade.modules.sale.vo.SaleVO;
 import org.springblade.modules.sale.service.ISaleService;
 import org.springblade.core.boot.ctrl.BladeController;
+
+import java.util.Date;
 
 /**
  * 销售记录表 控制器
@@ -52,7 +61,8 @@
 
 	private final ISaleService saleService;
 	private final FarmProductStockService farmProductStockService;
-
+//	private final IProcessService processService;
+	private final IProcessInvService processInvService;
 	/**
 	 * 详情
 	 */
@@ -112,17 +122,53 @@
 	@PostMapping("/submit")
 	@ApiOperationSupport(order = 6)
 	@ApiOperation(value = "新增或修改", notes = "传入sale")
-	public R submit(@Valid @RequestBody Sale sale) {
-		boolean res = farmProductStockService.stockCompare(sale.getSaleNum(),sale.getStrainId());
+	public R submit(@Valid @RequestBody SaleVO sale) {
+		boolean res = farmProductStockService.stockCompare(sale.getSaleNum(),sale.getProid());
 		if (!res){
 			throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
 		}else {
 			//库存充足,减去相应库存
-			farmProductStockService.stockReduce(sale.getSaleNum(),sale.getStrainId());
+			farmProductStockService.stockReduce(sale.getSaleNum(),sale.getProid());
 		}
+		sale.setProdId(sale.getProid());
 		return R.status(saleService.saveOrUpdate(sale));
 	}
 
+	/**
+	 * 新增或修改 销售记录表(加工产品)
+	 */
+	@PostMapping("/submitProcess")
+	@ApiOperationSupport(order = 8)
+	@ApiOperation(value = "新增或修改", notes = "传入sale")
+	public R submitProcess(@Valid @RequestBody SaleVO sale) {
+//		//对比加工表库存量
+//		boolean res = processService.stockCompare(sale.getSaleNum(),sale.getProid());
+//		if (!res){
+//			throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
+//		}else {
+//			//库存充足,减去相应库存
+//			processService.stockReduce(sale.getSaleNum(),sale.getProid());
+//		}
+//		return R.status(saleService.saveOrUpdate(sale));
+		//对比加工表库存量
+		boolean res = processInvService.stockCompare(sale.getSaleNum(),sale.getProid());
+		if (!res){
+			throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
+		}else {
+			//库存充足,减去相应库存
+			processInvService.stockReduce(sale.getSaleNum(),sale.getProid());
+			//更新updateTIme 和 updateUser
+			ProcessInv processInv = new ProcessInv();
+			processInv.setUpdateUser(sale.getCreateUser());
+			processInv.setUpdateTime(new Date());
+			processInv.setId(Long.parseLong(sale.getProid()));
+			ProcessInvVO processInvVO = processInvService.getLand(processInv);
+			sale.setLandId(processInvVO.getLandId());
+			processInvService.updateById(processInv);
+		}
+		sale.setProdId(sale.getProid());
+		return R.status(saleService.saveOrUpdate(sale));
+	}
 
 	/**
 	 * 删除 销售记录表
@@ -131,6 +177,18 @@
 	@ApiOperationSupport(order = 7)
 	@ApiOperation(value = "逻辑删除", notes = "传入ids")
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+		Sale sale = saleService.getById(Long.parseLong(ids));
+		if (sale.getType() == 0){
+			FarmProductStock farmProductStock = farmProductStockService.getById(sale.getProdId());
+			Double weight = Double.parseDouble(farmProductStock.getWeight())+sale.getSaleNum();
+			farmProductStock.setWeight(weight.toString());
+			farmProductStockService.updateById(farmProductStock);
+		}else {
+			ProcessInv inv = processInvService.findById(sale.getProdId());
+			Double weight = inv.getProductInventoryNum()+sale.getSaleNum();
+			inv.setProductInventoryNum(weight);
+			processInvService.updateById(inv);
+		}
 		return R.status(saleService.deleteLogic(Func.toLongList(ids)));
 	}
 
@@ -138,16 +196,16 @@
 	 * 大屏销售统计
 	 */
 	@GetMapping("/selctSaletCount")
-	public R selctSaletCount() {
-		return R.data(saleService.selctSaletCount());
+	public R selctSaletCount(String farmId) {
+		return R.data(saleService.selctSaletCount(farmId));
 	}
 
 	/**
 	 * 统计今年和去年的销售总额
 	 */
 	@GetMapping("/selctSaletZ")
-	public R selctSaletZ() {
-		return R.data(saleService.selctSaletZ());
+	public R selctSaletZ(SaleVO sale) {
+		return R.data(saleService.selctSaletZ(sale));
 	}
 
 	/**
@@ -164,8 +222,8 @@
 	 * 按行政区统计市场流通
 	 */
 	@GetMapping("/selectMarketDistrict")
-	public R selectMarketDistrict() {
-		return R.data(saleService.selectMarketDistrict());
+	public R selectMarketDistrict(String farmId,String startTime,String endTime) {
+		return R.data(saleService.selectMarketDistrict(farmId,startTime,endTime));
 	}
 
 }

--
Gitblit v1.9.3