| | |
| | | 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.processInv.entity.ProcessInv; |
| | | import org.springblade.modules.processInv.service.IProcessInvService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import org.springblade.modules.process.vo.ProcessVO; |
| | | import org.springblade.modules.process.service.IProcessService; |
| | | import org.springblade.core.boot.ctrl.BladeController; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 加工记录表 控制器 |
| | |
| | | |
| | | private final IProcessService processService; |
| | | private final FarmProductStockService farmProductStockService; |
| | | private final IProcessInvService processInvService; |
| | | /** |
| | | * 详情 |
| | | */ |
| | |
| | | }else { |
| | | //库存充足,减去相应库存 |
| | | farmProductStockService.stockReduce(process.getSaleNum(),process.getProid()); |
| | | //向加工产品库存表中添加数据 |
| | | ProcessInv processInv = new ProcessInv(); |
| | | |
| | | processInv.setFpsId(process.getFarmId()); |
| | | processInv.setProductId(Long.parseLong(process.getProcessId())); |
| | | processInv.setProductInventoryNum(process.getProcessNum()); |
| | | // processInv.setStrainId(Long.parseLong(process.getStrainId())); |
| | | processInv.setUpdateUser(process.getCreateUser()); |
| | | processInvService.insertOrUpdate(processInv); |
| | | } |
| | | return R.status(processService.saveOrUpdate(process)); |
| | | } |
| | | |
| | | /** |
| | | * 新增或修改 加工记录表(加工产品) |
| | | */ |
| | | @PostMapping("/submitProcess") |
| | | @ApiOperation(value = "新增或修改", notes = "传入process") |
| | | public R submitProcess(@Valid @RequestBody ProcessVO process) { |
| | | boolean res = processInvService.stockCompare(process.getSaleNum(),process.getProid()); |
| | | if (!res){ |
| | | throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!")); |
| | | }else { |
| | | //库存充足,减去相应库存 |
| | | processInvService.stockReduce(process.getSaleNum(),process.getProid()); |
| | | //向加工产品库存表中添加数据 |
| | | ProcessInv processInv = new ProcessInv(); |
| | | |
| | | processInv.setFpsId(process.getFarmId()); |
| | | processInv.setProductId(Long.parseLong(process.getProcessId())); |
| | | processInv.setProductInventoryNum(process.getProcessNum()); |
| | | processInv.setUpdateUser(process.getCreateUser()); |
| | | processInvService.insertOrUpdate(processInv); |
| | | } |
| | | return R.status(processService.saveOrUpdate(process)); |
| | | } |
| | |
| | | @PostMapping("/remove") |
| | | @ApiOperationSupport(order = 7) |
| | | @ApiOperation(value = "逻辑删除", notes = "传入ids") |
| | | public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { |
| | | public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids,@RequestParam String farmId) { |
| | | Process process = processService.getById(Long.parseLong(ids)); |
| | | if (process.getStrainId() == null){ |
| | | //只对加工产品库存操作 |
| | | ProcessInv processInvCP = processInvService.selectByFarmIdProductId(farmId,process.getProcessId()); |
| | | ProcessInv processInvLY = processInvService.selectByFarmIdProductId(farmId,process.getParentId()); |
| | | if (processInvCP.getProductInventoryNum()<0){ |
| | | throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前加工产品库存不足,不能删除数据!")); |
| | | }else { |
| | | processInvService.stockReduce(process.getProcessNum(),processInvCP.getId().toString()); |
| | | processInvService.stockAdd(process.getSaleNum(),processInvLY.getId().toString()); |
| | | } |
| | | }else { |
| | | //对加工产品库存和农产品库存操作 |
| | | FarmProductStock farmProductStock = farmProductStockService.selectBy2Id(process.getStrainId(),process.getLandId()); |
| | | ProcessInv processInv = processInvService.selectByFarmIdProductId(farmId,process.getProcessId()); |
| | | Double invNum = processInv.getProductInventoryNum()-process.getProcessNum(); |
| | | if (invNum<0){ |
| | | throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前加工产品库存不足,不能删除数据!")); |
| | | }else { |
| | | //更新加工产品库存 |
| | | processInv.setProductInventoryNum(invNum); |
| | | processInvService.updateById(processInv); |
| | | //更新农产品库存 |
| | | Double weight = Double.parseDouble(farmProductStock.getWeight())+process.getSaleNum(); |
| | | farmProductStock.setWeight(weight.toString()); |
| | | farmProductStockService.updateById(farmProductStock); |
| | | } |
| | | } |
| | | return R.status(processService.deleteLogic(Func.toLongList(ids))); |
| | | } |
| | | |