Browse Source

作物出入关联作物库存

zyh
小久哥 3 years ago
parent
commit
7b742c1701
  1. 3
      yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/GlobalErrorCodeConstants.java
  2. 5
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/cropRecord/CropRecordController.java
  3. 5
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordService.java
  4. 35
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/cropRecord/CropRecordServiceImpl.java

3
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();

5
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<Long> createCropRecord(@Valid @RequestBody CropRecordCreateReqVO createReqVO) {
return success(cropRecordService.createCropRecord(createReqVO));
public CommonResult<String> createCropRecord(@Valid @RequestBody CropRecordCreateReqVO createReqVO) {
return cropRecordService.createCropRecord(createReqVO);
}
@PutMapping("/update")

5
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<String> createCropRecord(@Valid CropRecordCreateReqVO createReqVO);
/**
* 更新

35
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<String> 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);
}

Loading…
Cancel
Save