From 7b742c17016031e66b51a95da3aa56c9a7dfe61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=B9=85=E5=93=A5?= <787952492@qq.com> Date: Wed, 25 May 2022 18:04:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E7=89=A9=E5=87=BA=E5=85=A5=E5=85=B3?= =?UTF-8?q?=E8=81=94=E4=BD=9C=E7=89=A9=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/GlobalErrorCodeConstants.java | 3 ++ .../cropRecord/CropRecordController.java | 5 +-- .../service/cropRecord/CropRecordService.java | 5 ++- .../cropRecord/CropRecordServiceImpl.java | 35 +++++++++++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/GlobalErrorCodeConstants.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/GlobalErrorCodeConstants.java index 69b97e5a..d7fa042a 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/GlobalErrorCodeConstants.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/GlobalErrorCodeConstants.java @@ -36,6 +36,9 @@ public interface GlobalErrorCodeConstants { ErrorCode UNKNOWN = new ErrorCode(999, "未知错误"); + //农作物出入管理 + ErrorCode CROP_RECORD_CANT_NEGATIVE = new ErrorCode(10001, "出库失败,农作物库存小于出库数量"); + static boolean isMatch(Integer code) { return code != null && code >= SUCCESS.getCode() && code <= UNKNOWN.getCode(); diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/cropRecord/CropRecordController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/cropRecord/CropRecordController.java index b7159cc4..fd3cc4cc 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/cropRecord/CropRecordController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/cropRecord/CropRecordController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.farm.controller.admin.cropRecord; +import org.apache.poi.ss.formula.functions.T; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -38,8 +39,8 @@ public class CropRecordController { @PostMapping("/create") @ApiOperation("创建") @PreAuthorize("@ss.hasPermission('farm:crop-record:create')") - public CommonResult createCropRecord(@Valid @RequestBody CropRecordCreateReqVO createReqVO) { - return success(cropRecordService.createCropRecord(createReqVO)); + public CommonResult createCropRecord(@Valid @RequestBody CropRecordCreateReqVO createReqVO) { + return cropRecordService.createCropRecord(createReqVO); } @PutMapping("/update") diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordService.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordService.java index 2bc0bb1c..d853c949 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordService.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordService.java @@ -2,9 +2,12 @@ package cn.iocoder.yudao.module.farm.service.cropRecord; import java.util.*; import javax.validation.*; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.farm.controller.admin.cropRecord.vo.*; import cn.iocoder.yudao.module.farm.dal.dataobject.cropRecord.CropRecordDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import org.apache.poi.ss.formula.functions.T; /** * Service 接口 @@ -19,7 +22,7 @@ public interface CropRecordService { * @param createReqVO 创建信息 * @return 编号 */ - Long createCropRecord(@Valid CropRecordCreateReqVO createReqVO); + CommonResult createCropRecord(@Valid CropRecordCreateReqVO createReqVO); /** * 更新 diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordServiceImpl.java index 20d0731e..b256fd8b 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordServiceImpl.java @@ -1,5 +1,9 @@ package cn.iocoder.yudao.module.farm.service.cropRecord; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.farm.dal.dataobject.crop.CropDO; +import cn.iocoder.yudao.module.farm.dal.mysql.crop.CropMapper; +import org.apache.poi.ss.formula.functions.T; import org.springframework.stereotype.Service; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -12,6 +16,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.farm.convert.cropRecord.CropRecordConvert; import cn.iocoder.yudao.module.farm.dal.mysql.cropRecord.CropRecordMapper; +import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.*; @@ -26,14 +31,30 @@ public class CropRecordServiceImpl implements CropRecordService { @Resource private CropRecordMapper cropRecordMapper; + @Resource + private CropMapper cropMapper; @Override - public Long createCropRecord(CropRecordCreateReqVO createReqVO) { + public CommonResult createCropRecord(CropRecordCreateReqVO createReqVO) { // 插入 CropRecordDO cropRecord = CropRecordConvert.INSTANCE.convert(createReqVO); + //修改作物 + CropDO crop = cropMapper.selectById(createReqVO.getCropId()); + if (createReqVO.getType()){ + //入 + crop.setStock(crop.getStock() + createReqVO.getStock()); + }else{ + //出 + if (crop.getStock() < createReqVO.getStock()){ + return CommonResult.error(CROP_RECORD_CANT_NEGATIVE); + } + crop.setStock(crop.getStock() - createReqVO.getStock()); + } cropRecordMapper.insert(cropRecord); + cropMapper.updateById(crop); + // 返回 - return cropRecord.getId(); + return CommonResult.success("成功"); } @Override @@ -42,6 +63,16 @@ public class CropRecordServiceImpl implements CropRecordService { this.validateCropRecordExists(updateReqVO.getId()); // 更新 CropRecordDO updateObj = CropRecordConvert.INSTANCE.convert(updateReqVO); + //修改作物 + CropDO crop = cropMapper.selectById(updateReqVO.getCropId()); + if (updateReqVO.getType()){ + //入 + crop.setStock(crop.getStock() + updateReqVO.getStock()); + }else{ + //出 + crop.setStock(crop.getStock() - updateReqVO.getStock()); + } + cropMapper.updateById(crop); cropRecordMapper.updateById(updateObj); }