farm模块-地块类型

This commit is contained in:
顾君禹
2025-08-28 09:28:36 +08:00
parent 9ff364fadf
commit fed3313e28
3 changed files with 58 additions and 44 deletions

View File

@@ -8,10 +8,11 @@ import cn.iocoder.yudao.module.farm.controller.admin.cropFarmingCenter.vo.*;
import cn.iocoder.yudao.module.farm.controller.admin.farmingrecord.vo.FarmingRecordSaveReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingrecordinput.vo.FarmingRecordInputSaveReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.modelcycle.vo.ModelCycleRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.modelmanagement.vo.ModelManagementRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.modelfarmingoperation.vo.ModelFarmingOperationRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.modelmanagement.vo.ModelManagementRespVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.modelfarmingoperationinput.ModelFarmingOperationInputDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.productionplan.ProductionPlanDO;
import cn.iocoder.yudao.module.farm.dal.mysql.baseinfo.BaseInfoMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.productionplan.ProductionPlanMapper;
@@ -19,8 +20,10 @@ import cn.iocoder.yudao.module.farm.enums.CommonConstants;
import cn.iocoder.yudao.module.farm.service.farmingrecord.FarmingRecordService;
import cn.iocoder.yudao.module.farm.service.farmingrecordinput.FarmingRecordInputService;
import cn.iocoder.yudao.module.farm.service.modelmanagement.ModelManagementService;
import cn.iocoder.yudao.module.farm.service.plotinfo.PlotInfoService;
import cn.iocoder.yudao.module.farm.utils.StrHelperUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -49,28 +52,24 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
private final ModelManagementService modelManagementService;
private final FarmingRecordService farmingRecordService;
private final FarmingRecordInputService farmingRecordInputService;
private final PlotInfoService plotInfoService;
public CropFarmingCenterServiceImpl(BaseInfoMapper baseInfoMapper, ProductionPlanMapper productionPlanMapper,
ModelManagementService modelManagementService,
FarmingRecordService farmingRecordService,
FarmingRecordInputService farmingRecordInputService) {
FarmingRecordInputService farmingRecordInputService, PlotInfoService plotInfoService) {
this.baseInfoMapper = baseInfoMapper;
this.productionPlanMapper = productionPlanMapper;
this.modelManagementService = modelManagementService;
this.farmingRecordService = farmingRecordService;
this.farmingRecordInputService = farmingRecordInputService;
this.plotInfoService = plotInfoService;
}
@Override
public void createProductionPlan(ProductionPlanSaveReqVO reqVO) {
String taskId = IdUtil.fastUUID();
String speciesModelId = reqVO.getSpeciesModelId();
// 创建模型案例
speciesModelId = modelManagementService.createModelManagementCase(speciesModelId, taskId);
if (speciesModelId.equals("")) {
return;
}
String speciesModelId = reqVO.getSpeciesModelId();
List<ProductionPlanSaveReqVO.CultivationArea> cultivationAreaList = reqVO.getCultivationAreaList();
@@ -94,38 +93,48 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
obj.setRemark(e.getRemark());
obj.setBaseId(e.getBaseId());
obj.setBaseName(e.getBaseName());
BaseInfoDO baseInfoDO = baseInfoMapper.selectById(e.getBaseId());
obj.setBaseName(baseInfoDO.getName());
obj.setPlotId(e.getPlotId());
obj.setPlotName(e.getPlotName());
obj.setTenantId(e.getTenantId());
PlotInfoDO plotInfo = plotInfoService.getPlotInfoByPlotId(e.getPlotId());
obj.setPlotName(plotInfo.getPlotName());
obj.setTenantId(getLoginUser().getTenantId().toString());
obj.setId(IdUtil.fastUUID());
// 随机字符串 + 地块名称
obj.setPlanNumber(StrHelperUtil.generate() + "-" + e.getPlotName());
String taskId = IdUtil.fastUUID();
obj.setId(taskId);
// 创建模型案例
speciesModelId = modelManagementService.createModelManagementCase(speciesModelId, taskId);
if (speciesModelId.equals("")) {
return;
}
list.add(obj);
}
productionPlanMapper.insertBatch(list);
// 根据模型生成农事记录
for (ProductionPlanSaveReqVO.CultivationArea e : cultivationAreaList) {
generateFarmingRecordsFromModel(speciesModelId, taskId, e.getPlantingDate(), e.getBaseId(), e.getBaseName(), e.getPlotId(), e.getPlotName(), e.getTenantId());
}
// for (ProductionPlanSaveReqVO.CultivationArea e : cultivationAreaList) {
// generateFarmingRecordsFromModel(speciesModelId, taskId, e.getPlantingDate(), e.getBaseId(), e.getBaseName(), e.getPlotId(), e.getPlotName(), e.getTenantId());
// }
}
/**
* 根据模型生成农事记录
*
* @param modelId 模型ID
*
* @param modelId 模型ID
* @param productionPlanId 生产计划ID
* @param plantingDate 种植日期
* @param baseId 基地ID
* @param baseName 基地名称
* @param plotId 地块ID
* @param plotName 地块名称
* @param tenantId 租户ID
* @param plantingDate 种植日期
* @param baseId 基地ID
* @param baseName 基地名称
* @param plotId 地块ID
* @param plotName 地块名称
* @param tenantId 租户ID
*/
private void generateFarmingRecordsFromModel(String modelId, String productionPlanId, LocalDate plantingDate,
String baseId, String baseName, String plotId, String plotName, String tenantId) {
private void generateFarmingRecordsFromModel(String modelId, String productionPlanId, LocalDate plantingDate,
String baseId, String baseName, String plotId, String plotName, String tenantId) {
// 获取模型信息
ModelManagementRespVO model = modelManagementService.getModelManagement(modelId);
if (model == null || model.getModelCycles() == null) {
@@ -137,7 +146,7 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
for (ModelCycleRespVO cycle : model.getModelCycles()) {
// 计算农事操作时间(基于种植日期和周期天数)
LocalDate operationDate = plantingDate.plusDays(cycle.getStage());
// 生成农事操作记录
if (cycle.getFarmingOperationDOS() != null) {
for (ModelFarmingOperationRespVO operation : cycle.getFarmingOperationDOS()) {
@@ -156,9 +165,9 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
farmingRecordReq.setBaseName(baseName);
farmingRecordReq.setPlotName(plotName);
farmingRecordReq.setTenantId(tenantId);
String farmingRecordId = farmingRecordService.createFarmingRecord(farmingRecordReq);
// 生成农事操作投入品记录
if (operation.getFarmingOperationInputDOS() != null) {
for (ModelFarmingOperationInputDO input : operation.getFarmingOperationInputDOS()) {
@@ -174,14 +183,14 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
inputReq.setPlotId(plotId);
inputReq.setPlotName(plotName);
inputReq.setTenantId(tenantId);
farmingRecordInputService.createFarmingRecordInput(inputReq);
}
}
}
}
}
log.info("成功为生产计划 {} 生成农事记录,基于模型 {}", productionPlanId, modelId);
}
@@ -243,7 +252,7 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
.collect(Collectors.toList());
long size = collect.size();
return new PageResult<>(collect,size);
return new PageResult<>(collect, size);
}

View File

@@ -60,4 +60,5 @@ public interface PlotInfoService {
*/
PageResult<PlotInfoDO> getPlotInfoPage(PlotInfoPageReqVO pageReqVO);
PlotInfoDO getPlotInfoByPlotId(String plotId);
}

View File

@@ -1,24 +1,21 @@
package cn.iocoder.yudao.module.farm.service.plotinfo;
import cn.hutool.core.util.IdUtil;
import cn.iocoder.yudao.module.farm.controller.admin.plotinfo.vo.PlotInfoPageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.plotinfo.vo.PlotInfoSaveReqVO;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.module.farm.controller.admin.plotinfo.vo.PlotInfoPageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.plotinfo.vo.PlotInfoSaveReqVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO;
import cn.iocoder.yudao.module.farm.dal.mysql.plotinfo.PlotInfoMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.PLOT_INFO_NOT_EXISTS;
@@ -65,12 +62,12 @@ public class PlotInfoServiceImpl implements PlotInfoService {
}
@Override
public void deletePlotInfoListByIds(List<String> ids) {
public void deletePlotInfoListByIds(List<String> ids) {
// 删除
plotInfoMapper.deleteByIds(ids);
}
}
private void validatePlotInfoExists(String id) {
private void validatePlotInfoExists(String id) {
if (plotInfoMapper.selectById(id) == null) {
throw exception(PLOT_INFO_NOT_EXISTS);
}
@@ -91,4 +88,11 @@ private void validatePlotInfoExists(String id) {
return plotInfoMapper.selectPage(pageReqVO);
}
@Override
public PlotInfoDO getPlotInfoByPlotId(String plotId) {
LambdaQueryWrapper<PlotInfoDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PlotInfoDO::getPlotId, plotId);
return plotInfoMapper.selectOne(queryWrapper);
}
}