| | |
| | | farmProductStockService.stockReduce(process.getSaleNum(),process.getProid()); |
| | | //向加工产品库存表中添加数据 |
| | | ProcessInv processInv = new ProcessInv(); |
| | | processInv.setFpsId(process.getProid()); |
| | | |
| | | processInv.setFpsId(process.getFarmId()); |
| | | processInv.setProductId(Long.parseLong(process.getProcessId())); |
| | | processInv.setProductInventoryNum(process.getProcessNum()); |
| | | processInv.setStrainId(Long.parseLong(process.getStrainId())); |
| | | // 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); |
| | | } |
| | |
| | | @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)); |
| | | //通过strainId和landId 确定是由哪一个品种库存加工而来 |
| | | FarmProductStock farmProductStock = farmProductStockService.selectBy2Id(process.getStrainId(),process.getLandId()); |
| | | //通过strainId和processId(processId为产品id)确定对应的加工库存 |
| | | ProcessInv processInv = processInvService.selectBySPId(process.getStrainId(),process.getProcessId(),farmProductStock.getId()); |
| | | //农产品增加相应库存 |
| | | Double weight = Double.parseDouble(farmProductStock.getWeight())+process.getSaleNum(); |
| | | farmProductStock.setWeight(weight.toString()); |
| | | farmProductStockService.updateById(farmProductStock); |
| | | //加工产品减少对应库存 |
| | | Double num = processInv.getProductInventoryNum()-process.getProcessNum(); |
| | | if (num<0){ |
| | | //删除对应库存 |
| | | // processInvService.del(processInv.getId()); |
| | | throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足,不能删除数据!")); |
| | | 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 { |
| | | //更新库存 |
| | | processInv.setProductInventoryNum(num); |
| | | processInvService.updateById(processInv); |
| | | //对加工产品库存和农产品库存操作 |
| | | 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))); |
| | | } |