|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|