智慧农业后台管理
guoshilong
2022-11-08 72b971c98c46531064d74b68fc8fe8864ed0b544
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,23 +196,34 @@
    * 大屏销售统计
    */
   @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));
   }
   /**
    * 统计市场流通/去年流通量/本月流通量
    * @param sale
    * @return
    */
   @GetMapping("/selectMarketCirculate")
   public R selectMarketCirculate() {
      return R.data(saleService.selectMarketCirculate());
   public R selectMarketCirculate(SaleVO sale) {
      return R.data(saleService.selectMarketCirculate(sale));
   }
   /**
    * 按行政区统计市场流通
    */
   @GetMapping("/selectMarketDistrict")
   public R selectMarketDistrict(String farmId,String startTime,String endTime) {
      return R.data(saleService.selectMarketDistrict(farmId,startTime,endTime));
   }
}