| | |
| | | import org.springblade.modules.recovery.entity.Recovery; |
| | | import org.springblade.modules.recovery.service.RecoveryService; |
| | | import org.springblade.modules.recovery.vo.RecoveryVO; |
| | | import org.springblade.modules.stock.vo.StocksVO; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 农事记录控制器 |
| | | * @since 2022-05-18 |
| | | * |
| | | * @author zhongrj |
| | | * @since 2022-05-18 |
| | | */ |
| | | @RestController |
| | | @AllArgsConstructor |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R save(@Valid @RequestBody Recovery recovery) { |
| | | recovery.setCreateTime(new Date()); |
| | | //新增 |
| | | boolean save = recoveryService.save(recovery); |
| | | if (save){ |
| | | if (save) { |
| | | //同时生成农事记录和库存记录 |
| | | FarmingRecord record = new FarmingRecord(); |
| | | record.setCreateTime(new Date()); |
| | |
| | | //采收 |
| | | record.setType("12"); |
| | | record.setLandId(recovery.getLandId()); |
| | | record.setDeptId(recovery.getDeptId()); |
| | | record.setTenantId(recovery.getTenantId()); |
| | | record.setStrainId(recovery.getStrainId()); |
| | | record.setOperator(recovery.getOperator()); |
| | | Strain strain = strainService.getById(recovery.getStrainId()); |
| | | record.setRemarks("品种: "+strain.getStrainName() +", 重量:"+recovery.getWeight()); |
| | | record.setContent("品种: " + strain.getStrainName() + ", 重量:" + recovery.getWeight()); |
| | | //新增 |
| | | farmingRecordService.save(record); |
| | | |
| | | //库存 |
| | | //先查询是否有该农产品的库存 |
| | | //先查询是否有该农产品的库存(根据地块,农产品) |
| | | FarmProductStock stock = new FarmProductStock(); |
| | | stock.setFarmPlantId(recovery.getFarmPlantId()); |
| | | stock.setStrainId(recovery.getStrainId()); |
| | | stock.setLandId(recovery.getLandId()); |
| | | FarmProductStock stock1 = farmProductStockService.getOne(new QueryWrapper<>(stock)); |
| | | if (null!=stock1) { |
| | | if (null != stock1) { |
| | | //更新库存 |
| | | //计算库存 |
| | | double old = Double.parseDouble(stock1.getWeight()); |
| | | double now = Double.parseDouble(recovery.getWeight()); |
| | | double addNum = add(old, now); |
| | | stock1.setWeight(String.valueOf(addNum)); |
| | | |
| | | //总采收 |
| | | double olds = Double.parseDouble(stock1.getRecovery()); |
| | | double addNums = add(olds, now); |
| | | stock1.setRecovery(String.valueOf(addNums)); |
| | | //更新 |
| | | farmProductStockService.updateById(stock1); |
| | | }else { |
| | | } else { |
| | | //新增库存 |
| | | FarmProductStock productStock = new FarmProductStock(); |
| | | productStock.setCreateTime(new Date()); |
| | |
| | | productStock.setTime(recovery.getTime()); |
| | | productStock.setStrainId(recovery.getStrainId()); |
| | | productStock.setWeight(recovery.getWeight()); |
| | | productStock.setRecovery(recovery.getWeight()); |
| | | productStock.setFarmPlantId(recovery.getFarmPlantId()); |
| | | productStock.setTenantId(recovery.getTenantId()); |
| | | productStock.setDeptId(recovery.getDeptId()); |
| | | productStock.setLandId(recovery.getLandId()); |
| | | //新增操作 |
| | | farmProductStockService.save(productStock); |
| | | } |
| | |
| | | return R.status(save); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * double 相加 |
| | | * |
| | | * @param d1 |
| | | * @param d2 |
| | | * @return |
| | | */ |
| | | private double add(double d1, double d2){ |
| | | private double add(double d1, double d2) { |
| | | // 进行加法运算 |
| | | BigDecimal b1 = new BigDecimal(d1); |
| | | BigDecimal b2 = new BigDecimal(d2); |
| | |
| | | return R.status(recoveryService.removeByIds(Func.toLongList(ids))); |
| | | } |
| | | |
| | | /** |
| | | * 数据统计采收详情 |
| | | */ |
| | | @PostMapping("/recoveryStatistics") |
| | | public R<IPage<RecoveryVO>> recoveryStatistics(RecoveryVO recoveryVO, Query query){ |
| | | IPage<RecoveryVO> pages = recoveryService.recoveryStatistics(Condition.getPage(query), recoveryVO); |
| | | return R.data(pages); |
| | | } |
| | | |
| | | /** |
| | | * 小程序采收详情列表自定义分页 |
| | | */ |
| | | @GetMapping("/pagec") |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "分页", notes = "传入recovery") |
| | | public R<IPage<RecoveryVO>> pagec(RecoveryVO recovery, Query query) { |
| | | IPage<RecoveryVO> pages = recoveryService.selectRecoveryPage(Condition.getPage(query), recovery); |
| | | for (int i = 0; i < pages.getRecords().size(); i++) { |
| | | String jobWay = pages.getRecords().get(i).getJobWay(); |
| | | if (jobWay.equals("0")) { |
| | | pages.getRecords().get(i).setLx("人工"); |
| | | } else { |
| | | pages.getRecords().get(i).setLx("机械"); |
| | | } |
| | | |
| | | } |
| | | return R.data(pages); |
| | | } |
| | | } |