智慧农业后台管理
guoshilong
2022-08-19 4d60a2ee6bbfe76e2740307c832c8f309090a41e
src/main/java/org/springblade/modules/sale/controller/SaleController.java
@@ -30,6 +30,10 @@
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
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.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -37,6 +41,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 +58,8 @@
   private final ISaleService saleService;
   private final FarmProductStockService farmProductStockService;
//   private final IProcessService processService;
   private final IProcessInvService processInvService;
   /**
    * 详情
    */
@@ -112,17 +119,51 @@
   @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());
      }
      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);
      }
      return R.status(saleService.saveOrUpdate(sale));
   }
   /**
    * 删除 销售记录表
@@ -138,16 +179,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 +205,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));
   }
}