Merge remote-tracking branch 'origin/main'

This commit is contained in:
达富斌
2025-08-24 00:10:20 +08:00
10 changed files with 272 additions and 22 deletions

View File

@@ -287,17 +287,32 @@ public class DictController {
return success(BeanUtils.toBean(res, FarmingTypeRespVO.class));
}
@Operation(summary = "字典数据维护-下拉框列表-物种类别")
@GetMapping("/list/species-classify-library")
public CommonResult<List<SpeciesClassifyLibraryRespVO>> getSpeciesClassifyLibraryList() {
@Operation(summary = "字典数据维护-下拉框列表-三级物种类别")
@GetMapping("/list/three-library")
public CommonResult<List<SpeciesClassifyLibraryRespVO>> getTreeLibraryList() {
try {
// 获取物种类别字典数据
List<SysDictDO> dictList = sysDictService.getByTypeCode(CommonConstants.DICT_TYPE_CODE_3);
// 使用工具类构建树结构
List<SpeciesClassifyLibraryRespVO> treeList = TreeStructureUtil.buildSpeciesClassifyTree(dictList);
return success(treeList);
List<SpeciesClassifyLibraryRespVO> threeList = TreeStructureUtil.buildSpeciesClassifyTree(dictList);
return success(threeList);
} catch (Exception e) {
log.error("获取物种类别列表失败", e);
log.error("获取三级物种类别列表失败", e);
return success(new ArrayList<>());
}
}
@Operation(summary = "字典数据维护-下拉框列表-二级物种类别")
@GetMapping("/list/two-library")
public CommonResult<List<SpeciesClassifyLibraryRespVO>> getTwoLibraryList() {
try {
// 获取物种类别字典数据
List<SysDictDO> dictList = sysDictService.getByTypeCode(CommonConstants.DICT_TYPE_CODE_3);
// 使用工具类构建二级树结构
List<SpeciesClassifyLibraryRespVO> twoList = TreeStructureUtil.buildTwoLevelTree(dictList);
return success(twoList);
} catch (Exception e) {
log.error("获取二级物种类别列表失败", e);
return success(new ArrayList<>());
}
}

View File

@@ -41,6 +41,12 @@ public class ModelManagementController {
return success(modelManagementService.createModelManagement(createReqVO));
}
@PostMapping("/copy-model")
@Operation(summary = "复制模型管理")
public CommonResult<String> copyModelManagement(@Valid @RequestBody ModelManagementSaveReqVO createReqVO) {
return success(modelManagementService.copyModelManagement(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新模型管理")
public CommonResult<Boolean> updateModelManagement(@Valid @RequestBody ModelManagementSaveReqVO updateReqVO) {
@@ -48,6 +54,13 @@ public class ModelManagementController {
return success(true);
}
@PutMapping("/is-release")
@Operation(summary = "更新模型管理")
public CommonResult<Boolean> isRelease(@Valid @RequestBody ModelManagementSaveReqVO updateReqVO) {
modelManagementService.isRelease(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除模型管理")
@Parameter(name = "id", description = "编号", required = true)
@@ -72,6 +85,13 @@ public class ModelManagementController {
return success(modelManagement);
}
@GetMapping("/page-release")
@Operation(summary = "获得发布模型分页")
public CommonResult<PageResult<ModelManagementRespVO>> getModelManagementPageRelease(@Valid ModelManagementPageReqVO pageReqVO) {
PageResult<ModelManagementDO> pageResult = modelManagementService.getModelManagementPageRelease(pageReqVO);
return success(BeanUtils.toBean(pageResult, ModelManagementRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得模型管理分页")
public CommonResult<PageResult<ModelManagementRespVO>> getModelManagementPage(@Valid ModelManagementPageReqVO pageReqVO) {

View File

@@ -52,5 +52,6 @@ public class ModelManagementPageReqVO extends PageParam {
@Schema(description = "租户id", example = "20468")
private String tenantId;
private int isRelease;
private int quoteCount;
}

View File

@@ -71,7 +71,8 @@ public class ModelManagementRespVO {
@Schema(description = "租户id", example = "20468")
@ExcelProperty("租户id")
private String tenantId;
private int isRelease;
private int quoteCount;
private List<ModelCycleRespVO> modelCycles;
}

View File

@@ -47,5 +47,6 @@ public class ModelManagementSaveReqVO {
@Schema(description = "租户id", example = "20468")
private String tenantId;
private int isRelease;
private int quoteCount;
}

View File

@@ -1,12 +1,12 @@
package cn.iocoder.yudao.module.farm.dal.dataobject.modelmanagement;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.modelcycle.ModelCycleDO;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.util.List;
/**
* 模型管理 DO
*
@@ -81,5 +81,6 @@ public class ModelManagementDO extends BaseDO {
* 任务ID
*/
private String taskId;
private int isRelease;
private int quoteCount;
}

View File

@@ -3,12 +3,12 @@ package cn.iocoder.yudao.module.farm.dal.mysql.modelmanagement;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.farm.dal.dataobject.modelmanagement.ModelManagementDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.specieslibrary.SpeciesLibraryDO;
import cn.iocoder.yudao.module.farm.controller.admin.modelmanagement.vo.ModelManagementPageReqVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.modelmanagement.ModelManagementDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.specieslibrary.SpeciesLibraryDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.farm.controller.admin.modelmanagement.vo.*;
/**
* 模型管理 Mapper
@@ -48,4 +48,25 @@ public interface ModelManagementMapper extends BaseMapperX<ModelManagementDO> {
return selectJoinPage(reqVO, ModelManagementDO.class, query);
}
default PageResult<ModelManagementDO> selectPageRelease(ModelManagementPageReqVO reqVO) {
MPJLambdaWrapperX<ModelManagementDO> query = new MPJLambdaWrapperX<ModelManagementDO>()
.selectAll(ModelManagementDO.class)
.likeIfPresent(ModelManagementDO::getModelName, reqVO.getModelName())
.eqIfPresent(ModelManagementDO::getSpeciesId, reqVO.getSpeciesId())
.likeIfPresent(ModelManagementDO::getSpeciesName, reqVO.getSpeciesName())
.eqIfPresent(ModelManagementDO::getCycle, reqVO.getCycle())
.eqIfPresent(ModelManagementDO::getHarvest, reqVO.getHarvest())
.eqIfPresent(ModelManagementDO::getSuitablePlantingAreas, reqVO.getSuitablePlantingAreas())
.eqIfPresent(ModelManagementDO::getDescription, reqVO.getDescription())
.betweenIfPresent(ModelManagementDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(ModelManagementDO::getBaseId, reqVO.getBaseId())
.likeIfPresent(ModelManagementDO::getBaseName, reqVO.getBaseName())
.eqIfPresent(ModelManagementDO::getPlotId, reqVO.getPlotId())
.likeIfPresent(ModelManagementDO::getPlotName, reqVO.getPlotName())
.eqIfPresent(ModelManagementDO::getTenantId, reqVO.getTenantId())
.eqIfPresent(ModelManagementDO::getIsRelease, 1)
.orderByDesc(ModelManagementDO::getCreateTime);
return selectJoinPage(reqVO, ModelManagementDO.class, query);
}
}

View File

@@ -62,4 +62,9 @@ public interface ModelManagementService {
*/
PageResult<ModelManagementDO> getModelManagementPage(ModelManagementPageReqVO pageReqVO);
String copyModelManagement(@Valid ModelManagementSaveReqVO createReqVO);
void isRelease(@Valid ModelManagementSaveReqVO updateReqVO);
PageResult<ModelManagementDO> getModelManagementPageRelease(@Valid ModelManagementPageReqVO pageReqVO);
}

View File

@@ -66,6 +66,7 @@ public class ModelManagementServiceImpl implements ModelManagementService {
ModelManagementDO modelManagement = BeanUtils.toBean(createReqVO, ModelManagementDO.class);
modelManagement.setId(IdUtil.fastUUID());
modelManagement.setTenantId(String.valueOf(user.getTenantId()));
modelManagement.setIsRelease(0);
modelManagementMapper.insert(modelManagement);
// 返回
@@ -83,7 +84,8 @@ public class ModelManagementServiceImpl implements ModelManagementService {
if (modelManagementDO == null) {
return "";
}
modelManagementDO.setQuoteCount(modelManagementDO.getQuoteCount() + 1);
modelManagementMapper.updateById(modelManagementDO);
// 2. 创建新的模型引用案例
ModelManagementDO newModelCase = BeanUtils.toBean(modelManagementDO, ModelManagementDO.class);
String newModelId = IdUtil.fastUUID();
@@ -99,11 +101,10 @@ public class ModelManagementServiceImpl implements ModelManagementService {
List<ModelCycleDO> originalCycles = modelCycleMapper.selectListByModelId(id);
for (ModelCycleDO originalCycle : originalCycles) {
// 复制周期
ModelCycleDO newCycle = BeanUtils.toBean(originalCycle, ModelCycleDO.class);
String newCycleId = IdUtil.fastUUID();
newCycle.setId(newCycleId);
newCycle.setModelId(newModelId);
modelCycleMapper.insert(newCycle);
originalCycle.setId(newCycleId);
originalCycle.setModelId(newModelId);
modelCycleMapper.insert(originalCycle);
// 复制环境指标
List<ModelEnvironmentIndexDO> environmentIndexes = modelEnvironmentIndexMapper.selectByCycleId(originalCycle.getId());
@@ -218,4 +219,97 @@ public class ModelManagementServiceImpl implements ModelManagementService {
return modelManagementMapper.selectPage(pageReqVO);
}
@Override
public String copyModelManagement(ModelManagementSaveReqVO createReqVO) {
// 1. 查询原模型(类型为模型模板)
ModelManagementDO modelManagementDO = modelManagementMapper.selectOne(
ModelManagementDO::getId, createReqVO.getId(),
ModelManagementDO::getType, CommonConstants.MODEL_TYPE_1
);
if (modelManagementDO == null) {
return "";
}
// 2. 创建新的模型引用案例
ModelManagementDO newModelCase = BeanUtils.toBean(modelManagementDO, ModelManagementDO.class);
String newModelId = IdUtil.fastUUID();
newModelCase.setId(newModelId);
newModelCase.setType(CommonConstants.MODEL_TYPE_1);
newModelCase.setModelName(modelManagementDO.getModelName() + "-复制模型");
// 3. 保存新的模型引用案例
modelManagementMapper.insert(newModelCase);
// 4. 复制模型周期及其子集
List<ModelCycleDO> originalCycles = modelCycleMapper.selectListByModelId(createReqVO.getId());
for (ModelCycleDO originalCycle : originalCycles) {
// 复制周期
String newCycleId = IdUtil.fastUUID();
originalCycle.setId(newCycleId);
originalCycle.setModelId(newModelId);
modelCycleMapper.insert(originalCycle);
// 复制环境指标
List<ModelEnvironmentIndexDO> environmentIndexes = modelEnvironmentIndexMapper.selectByCycleId(originalCycle.getId());
for (ModelEnvironmentIndexDO envIndex : environmentIndexes) {
envIndex.setId(IdUtil.fastUUID());
envIndex.setCycleId(newCycleId);
modelEnvironmentIndexMapper.insert(envIndex);
}
// 复制气象灾害
List<ModelWeatherDisasterDO> weatherDisasters = modelWeatherDisasterMapper.selectByCycleId(originalCycle.getId());
for (ModelWeatherDisasterDO weatherDisaster : weatherDisasters) {
weatherDisaster.setId(IdUtil.fastUUID());
weatherDisaster.setCycleId(newCycleId);
modelWeatherDisasterMapper.insert(weatherDisaster);
}
// 复制病虫草灾害
List<ModelPestDiseaseWeedDO> pestDiseaseWeeds = modelPestDiseaseWeedMapper.selectByCycleId(originalCycle.getId());
for (ModelPestDiseaseWeedDO pestDiseaseWeed : pestDiseaseWeeds) {
pestDiseaseWeed.setId(IdUtil.fastUUID());
pestDiseaseWeed.setCycleId(newCycleId);
modelPestDiseaseWeedMapper.insert(pestDiseaseWeed);
}
// 复制农事操作
List<ModelFarmingOperationDO> farmingOperations = modelFarmingOperationMapper.selectByCycleId(originalCycle.getId());
for (ModelFarmingOperationDO farmingOperation : farmingOperations) {
String newFarmingId = IdUtil.fastUUID();
farmingOperation.setId(newFarmingId);
farmingOperation.setCycleId(newCycleId);
modelFarmingOperationMapper.insert(farmingOperation);
// 复制农事操作投入品
List<ModelFarmingOperationInputDO> farmingOperationInputs = modelFarmingOperationInputMapper.selectByFarmingId(farmingOperation.getId());
for (ModelFarmingOperationInputDO farmingOperationInput : farmingOperationInputs) {
farmingOperationInput.setId(IdUtil.fastUUID());
farmingOperationInput.setFarmingId(newFarmingId);
modelFarmingOperationInputMapper.insert(farmingOperationInput);
}
}
}
// 返回新建的模型引用案例ID
return newModelId;
}
@Override
public void isRelease(ModelManagementSaveReqVO updateReqVO) {
ModelManagementDO modelManagementDO = modelManagementMapper.selectById(updateReqVO.getId());
if (modelManagementDO.getIsRelease() == 0) {
modelManagementDO.setIsRelease(1);
} else {
modelManagementDO.setIsRelease(0);
}
modelManagementMapper.updateById(modelManagementDO);
}
@Override
public PageResult<ModelManagementDO> getModelManagementPageRelease(ModelManagementPageReqVO pageReqVO) {
return modelManagementMapper.selectPageRelease(pageReqVO);
}
}

View File

@@ -49,6 +49,39 @@ public class TreeStructureUtil {
}
}
/**
* 构建物种类别二级树结构
*
* @param dictList 字典数据列表
* @return 二级树形结构列表
*/
public static List<SpeciesClassifyLibraryRespVO> buildTwoLevelTree(List<SysDictDO> dictList) {
if (dictList == null || dictList.isEmpty()) {
return new ArrayList<>();
}
try {
// 按一级分类分组
Map<String, List<SysDictDO>> groupedByLevel1 = dictList.stream()
.filter(dict -> isValidLevel1Node(dict))
.collect(Collectors.groupingBy(
SysDictDO::getField1Code,
Collectors.toList()
));
// 构建二级树形结构
return groupedByLevel1.entrySet().stream()
.map(entry -> buildTwoLevelNode(entry.getKey(), entry.getValue()))
.filter(Objects::nonNull)
.sorted(Comparator.comparing(SpeciesClassifyLibraryRespVO::getSpeciesClassName))
.collect(Collectors.toList());
} catch (Exception e) {
// 记录错误日志,返回空列表
return new ArrayList<>();
}
}
/**
* 构建通用树结构
*
@@ -209,4 +242,62 @@ public class TreeStructureUtil {
level2Node.setChildren(level3Nodes);
return level2Node;
}
/**
* 构建二级树节点(只包含一级和二级,不包含三级)
*/
private static SpeciesClassifyLibraryRespVO buildTwoLevelNode(String level1Code, List<SysDictDO> level1Children) {
if (level1Children == null || level1Children.isEmpty()) {
return null;
}
// 获取一级分类名称
String level1Name = level1Children.stream()
.filter(TreeStructureUtil::isValidLevel1Node)
.map(SysDictDO::getField1Name)
.findFirst()
.orElse("");
if (level1Name.isEmpty()) {
return null;
}
// 创建一级节点
SpeciesClassifyLibraryRespVO level1Node = new SpeciesClassifyLibraryRespVO(level1Code, level1Name);
// 按二级分类分组
Map<String, List<SysDictDO>> groupedByLevel2 = level1Children.stream()
.filter(dict -> isValidLevel2Node(dict))
.collect(Collectors.groupingBy(
SysDictDO::getField2Code,
Collectors.toList()
));
// 构建二级节点列表(不包含三级)
List<SpeciesClassifyLibraryRespVO> level2Nodes = groupedByLevel2.entrySet().stream()
.map(entry -> {
String level2Code = entry.getKey();
List<SysDictDO> level2Children = entry.getValue();
// 获取二级分类名称
String level2Name = level2Children.stream()
.filter(TreeStructureUtil::isValidLevel2Node)
.map(SysDictDO::getField2Name)
.findFirst()
.orElse("");
if (level2Name.isEmpty()) {
return null;
}
// 创建二级节点(不设置children,即不包含三级分类)
return new SpeciesClassifyLibraryRespVO(level2Code, level2Name);
})
.filter(Objects::nonNull)
.sorted(Comparator.comparing(SpeciesClassifyLibraryRespVO::getSpeciesClassName))
.collect(Collectors.toList());
level1Node.setChildren(level2Nodes);
return level1Node;
}
}