From 918032ec4d745924bbed1d405e93a219b6a6f6f0 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 23 Aug 2022 17:37:55 +0800
Subject: [PATCH] 后台销售、出库、损耗记录添加删除功能并能回滚
---
src/main/java/org/springblade/modules/InventoryLoss/controller/InventoryController.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/springblade/modules/InventoryLoss/controller/InventoryController.java b/src/main/java/org/springblade/modules/InventoryLoss/controller/InventoryController.java
index 558f81d..eec1f07 100644
--- a/src/main/java/org/springblade/modules/InventoryLoss/controller/InventoryController.java
+++ b/src/main/java/org/springblade/modules/InventoryLoss/controller/InventoryController.java
@@ -28,13 +28,20 @@
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.entity.FarmProductStock;
import org.springblade.modules.farmplant.service.FarmProductStockService;
import org.springblade.modules.InventoryLoss.entity.Inventory;
import org.springblade.modules.InventoryLoss.service.InventoryService;
import org.springblade.modules.InventoryLoss.vo.InventoryVO;
+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.sale.entity.Sale;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
+import java.util.Date;
/**
* 库存损耗记录表 控制器
@@ -50,7 +57,8 @@
private final InventoryService inventoryService;
private final FarmProductStockService farmProductStockService;
-
+// private final IProcessService processService;
+ private final IProcessInvService processInvService;
/**
* 详情
*/
@@ -110,17 +118,49 @@
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@ApiOperation(value = "新增或修改", notes = "传入sale")
- public R submit(@Valid @RequestBody Inventory inventory) {
- boolean res = farmProductStockService.stockCompare(inventory.getSaleNum(),inventory.getStrainId());
+ public R submit(@Valid @RequestBody InventoryVO inventory) {
+ boolean res = farmProductStockService.stockCompare(inventory.getSaleNum(),inventory.getProid());
if (!res){
throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
}else {
//库存充足,减去相应库存
- farmProductStockService.stockReduce(inventory.getSaleNum(),inventory.getStrainId());
+ farmProductStockService.stockReduce(inventory.getSaleNum(),inventory.getProid());
}
return R.status(inventoryService.saveOrUpdate(inventory));
}
+ /**
+ * 新增或修改 库存损耗记录表(加工产品)
+ */
+ @PostMapping("/submitProcess")
+ @ApiOperationSupport(order = 8)
+ @ApiOperation(value = "新增或修改", notes = "传入sale")
+ public R submitProcess(@Valid @RequestBody InventoryVO inventory) {
+// boolean res = processService.stockCompare(inventory.getSaleNum(),inventory.getProid());
+// if (!res){
+// throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
+// }else {
+// //库存充足,减去相应库存
+// processService.stockReduce(inventory.getSaleNum(),inventory.getProid());
+// }
+// return R.status(inventoryService.saveOrUpdate(inventory));
+ boolean res = processInvService.stockCompare(inventory.getSaleNum(),inventory.getProid());
+ if (!res){
+ throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
+ }else {
+ //库存充足,减去相应库存
+ processInvService.stockReduce(inventory.getSaleNum(),inventory.getProid());
+ //更新updateTIme 和 updateUser
+ ProcessInv processInv = new ProcessInv();
+ processInv.setUpdateUser(inventory.getCreateUser());
+ processInv.setUpdateTime(new Date());
+ processInv.setId(Long.parseLong(inventory.getProid()));
+ ProcessInvVO processInvVO = processInvService.getLand(processInv);
+ inventory.setLandId(processInvVO.getLandId());
+ processInvService.updateById(processInv);
+ }
+ return R.status(inventoryService.saveOrUpdate(inventory));
+ }
/**
* 删除 库存损耗记录表
@@ -129,6 +169,11 @@
@ApiOperationSupport(order = 7)
@ApiOperation(value = "逻辑删除", notes = "传入ids")
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+ Inventory inventory = inventoryService.getById(Long.parseLong(ids));
+ FarmProductStock farmProductStock = farmProductStockService.selectBy2Id(inventory.getStrainId(), inventory.getLandId());
+ Double weight = Double.parseDouble(farmProductStock.getWeight())+inventory.getSaleNum();
+ farmProductStock.setWeight(weight.toString());
+ farmProductStockService.updateById(farmProductStock);
return R.status(inventoryService.deleteLogic(Func.toLongList(ids)));
}
--
Gitblit v1.9.3