feat (farm):
1. 分类下有物种 不能删除分类 2. 物种下有模型 不能删除物种
This commit is contained in:
@@ -38,256 +38,21 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class DictController {
|
public class DictController {
|
||||||
|
|
||||||
private final SysDictService sysDictService;
|
|
||||||
private final ProductionPlanService productionPlanService;
|
private final ProductionPlanService productionPlanService;
|
||||||
private final BaseInfoService baseInfoService;
|
private final BaseInfoService baseInfoService;
|
||||||
|
|
||||||
public DictController(SysDictService sysDictService, ProductionPlanService productionPlanService, BaseInfoService baseInfoService) {
|
public DictController(ProductionPlanService productionPlanService, BaseInfoService baseInfoService) {
|
||||||
this.sysDictService = sysDictService;
|
|
||||||
this.productionPlanService = productionPlanService;
|
this.productionPlanService = productionPlanService;
|
||||||
this.baseInfoService = baseInfoService;
|
this.baseInfoService = baseInfoService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 农事类型
|
|
||||||
// @Operation(summary = "字典数据维护-农事类型-分页")
|
|
||||||
// @GetMapping("/farming-type/page")
|
|
||||||
// public CommonResult<PageResult<FarmingTypeMaintenanceRespVO>> getFarmingTypePage(FarmingTypeMaintenancePageReqVO reqVO) {
|
|
||||||
// PageResult<FarmingTypeMaintenanceDO> result = sysDictService.getFarmingTypeMaintenancePage(reqVO);
|
|
||||||
// return success(BeanUtils.toBean(result, FarmingTypeMaintenanceRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-农事类型-查看")
|
|
||||||
// @GetMapping("/farming-type/get/{id}")
|
|
||||||
// public CommonResult<FarmingTypeMaintenanceRespVO> getFarmingTypeMaintenance(@PathVariable("id") String id) {
|
|
||||||
// FarmingTypeMaintenanceDO aDo = sysDictService.getFarmingTypeMaintenance(id);
|
|
||||||
// return success(BeanUtils.toBean(aDo, FarmingTypeMaintenanceRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-农事类型-新增")
|
|
||||||
// @PostMapping("/farming-type/create")
|
|
||||||
// public CommonResult<Boolean> createFarmingType(@RequestBody FarmingTypeMaintenanceSaveReqVO saveVO) {
|
|
||||||
// sysDictService.createFarmingTypeMaintenance(saveVO);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-农事类型-编辑")
|
|
||||||
// @PutMapping("/farming-type/update")
|
|
||||||
// public CommonResult<Boolean> updateFarmingType(@RequestBody FarmingTypeMaintenanceSaveReqVO updateVO) {
|
|
||||||
// sysDictService.updateFarmingTypeMaintenance(updateVO);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-农事类型-删除")
|
|
||||||
// @DeleteMapping("/farming-type/delete/{id}")
|
|
||||||
// public CommonResult<Boolean> delFarmingType(@PathVariable("id") String id) {
|
|
||||||
// sysDictService.deleteFarmingTypeMaintenance(id);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 农事名称
|
|
||||||
// @Operation(summary = "字典数据维护-农事名称-分页")
|
|
||||||
// @GetMapping("/farming-name/page")
|
|
||||||
// public CommonResult<PageResult<FarmingNameMaintenanceRespVO>> getFarmingNameMaintenancePage(@Valid FarmingNameMaintenancePageReqVO pageReqVO) {
|
|
||||||
// PageResult<FarmingNameMaintenanceDO> pageResult = sysDictService.getFarmingNameMaintenancePage(pageReqVO);
|
|
||||||
// return success(BeanUtils.toBean(pageResult, FarmingNameMaintenanceRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-农事名称-查看")
|
|
||||||
// @GetMapping("/farming-name/get/{id}")
|
|
||||||
// public CommonResult<FarmingNameMaintenanceRespVO> getFarmingNameMaintenance(@PathVariable("id") String id) {
|
|
||||||
// FarmingNameMaintenanceDO farmingNameMaintenance = sysDictService.getFarmingNameMaintenance(id);
|
|
||||||
// return success(BeanUtils.toBean(farmingNameMaintenance, FarmingNameMaintenanceRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-农事名称-新增")
|
|
||||||
// @PostMapping("/farming-name/create")
|
|
||||||
// public CommonResult<Boolean> createFarmingNameMaintenance(@Valid @RequestBody FarmingNameMaintenanceSaveReqVO createReqVO) {
|
|
||||||
// sysDictService.createFarmingNameMaintenance(createReqVO);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-农事名称-编辑")
|
|
||||||
// @PutMapping("/farming-name/update")
|
|
||||||
// public CommonResult<Boolean> updateFarmingNameMaintenance(@Valid @RequestBody FarmingNameMaintenanceSaveReqVO updateReqVO) {
|
|
||||||
// sysDictService.updateFarmingNameMaintenance(updateReqVO);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-农事名称-删除")
|
|
||||||
// @DeleteMapping("/farming-name/delete/{id}")
|
|
||||||
// public CommonResult<Boolean> deleteFarmingNameMaintenance(@PathVariable("id") String id) {
|
|
||||||
// sysDictService.deleteFarmingNameMaintenance(id);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 物种库维护
|
|
||||||
// @Operation(summary = "字典数据维护-物种库-分页")
|
|
||||||
// @GetMapping("/species/page")
|
|
||||||
// public CommonResult<PageResult<SpeciesLibraryRespVO>> getSpeciesLibraryPage(@Valid SpeciesLibraryPageReqVO pageReqVO) {
|
|
||||||
// PageResult<SpeciesLibraryDO> pageResult = speciesLibraryService.getSpeciesLibraryPage(pageReqVO);
|
|
||||||
// return success(BeanUtils.toBean(pageResult, SpeciesLibraryRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-物种库-查看")
|
|
||||||
// @GetMapping("/species/get/{id}")
|
|
||||||
// public CommonResult<SpeciesLibraryRespVO> getSpeciesLibrary(@PathVariable("id") String id) {
|
|
||||||
// SpeciesLibraryDO speciesLibrary = speciesLibraryService.getSpeciesLibrary(id);
|
|
||||||
// return success(BeanUtils.toBean(speciesLibrary, SpeciesLibraryRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-物种库-新增")
|
|
||||||
// @PostMapping("/species/create")
|
|
||||||
// public CommonResult<String> createSpeciesLibrary(@Valid @RequestBody SpeciesLibrarySaveReqVO createReqVO) {
|
|
||||||
// String msg = speciesLibraryService.createSpeciesLibrary(createReqVO);
|
|
||||||
//
|
|
||||||
// CommonResult<String> result = new CommonResult<>();
|
|
||||||
// result.setCode(GlobalErrorCodeConstants.SUCCESS.getCode());
|
|
||||||
// result.setData("");
|
|
||||||
// result.setMsg(msg);
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-物种库-编辑")
|
|
||||||
// @PutMapping("/species/update")
|
|
||||||
// public CommonResult<Boolean> updateSpeciesLibrary(@Valid @RequestBody SpeciesLibrarySaveReqVO updateReqVO) {
|
|
||||||
// speciesLibraryService.updateSpeciesLibrary(updateReqVO);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-物种库-删除")
|
|
||||||
// @DeleteMapping("/species/delete/{id}")
|
|
||||||
// public CommonResult<Boolean> deleteSpeciesLibrary(@PathVariable("id") String id) {
|
|
||||||
// speciesLibraryService.deleteSpeciesLibrary(id);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 投入品维护
|
|
||||||
// @Operation(summary = "字典数据维护-投入品-分页")
|
|
||||||
// @GetMapping("/invest-goods/page")
|
|
||||||
// public CommonResult<PageResult<InputLibraryRespVO>> getInputLibraryPage(@Valid InputLibraryPageReqVO pageReqVO) {
|
|
||||||
// PageResult<InputLibraryDO> pageResult = inputLibraryService.getInputLibraryPage(pageReqVO);
|
|
||||||
// return success(BeanUtils.toBean(pageResult, InputLibraryRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-投入品-查看")
|
|
||||||
// @GetMapping("/invest-goods/get/{id}")
|
|
||||||
// public CommonResult<InputLibraryRespVO> getInputLibrary(@PathVariable("id") String id) {
|
|
||||||
// InputLibraryDO inputLibrary = inputLibraryService.getInputLibrary(id);
|
|
||||||
// return success(BeanUtils.toBean(inputLibrary, InputLibraryRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-投入品-新增")
|
|
||||||
// @PostMapping("/invest-goods/create")
|
|
||||||
// public CommonResult<String> createInputLibrary(@Valid @RequestBody InputLibrarySaveReqVO createReqVO) {
|
|
||||||
// return success(inputLibraryService.createInputLibrary(createReqVO));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @PutMapping("/invest-goods/update")
|
|
||||||
// @Operation(summary = "字典数据维护-投入品-编辑")
|
|
||||||
// public CommonResult<Boolean> updateInputLibrary(@Valid @RequestBody InputLibrarySaveReqVO updateReqVO) {
|
|
||||||
// inputLibraryService.updateInputLibrary(updateReqVO);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-投入品-删除")
|
|
||||||
// @DeleteMapping("/invest-goods/delete/{id}")
|
|
||||||
// public CommonResult<Boolean> deleteInputLibrary(@PathVariable("id") String id) {
|
|
||||||
// inputLibraryService.deleteInputLibrary(id);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 灾害/气象灾害库维护
|
|
||||||
// @Operation(summary = "字典数据维护-灾害库-分页")
|
|
||||||
// @GetMapping("/disaster/page")
|
|
||||||
// public CommonResult<PageResult<DisasterDataRespVO>> getDisasterDataPage(@Valid DisasterDataPageReqVO pageReqVO) {
|
|
||||||
// PageResult<DisasterDataDO> pageResult = disasterDataService.getDisasterDataPage(pageReqVO);
|
|
||||||
// return success(BeanUtils.toBean(pageResult, DisasterDataRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-灾害库-查看")
|
|
||||||
// @GetMapping("/disaster/get/{id}")
|
|
||||||
// public CommonResult<DisasterDataRespVO> getDisasterData(@PathVariable("id") String id) {
|
|
||||||
// DisasterDataDO disasterData = disasterDataService.getDisasterData(id);
|
|
||||||
// return success(BeanUtils.toBean(disasterData, DisasterDataRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-灾害库-新增")
|
|
||||||
// @PostMapping("/disaster/create")
|
|
||||||
// public CommonResult<String> createDisasterData(@Valid @RequestBody DisasterDataSaveReqVO createReqVO) {
|
|
||||||
// return success(disasterDataService.createDisasterData(createReqVO));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-灾害库-编辑")
|
|
||||||
// @PutMapping("/disaster/update")
|
|
||||||
// public CommonResult<Boolean> updateDisasterData(@Valid @RequestBody DisasterDataSaveReqVO updateReqVO) {
|
|
||||||
// disasterDataService.updateDisasterData(updateReqVO);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-灾害库-删除")
|
|
||||||
// @DeleteMapping("/disaster/delete/{id}")
|
|
||||||
// public CommonResult<Boolean> deleteDisasterData(@PathVariable("id") String id) {
|
|
||||||
// disasterDataService.deleteDisasterData(id);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// // 下拉框列表
|
|
||||||
// @Operation(summary = "字典数据维护-下拉框列表-农事类型")
|
|
||||||
// @GetMapping("/list/farming-type")
|
|
||||||
// public CommonResult<List<FarmingTypeRespVO>> getFarmingTypeList() {
|
|
||||||
// List<FarmingTypeMaintenanceDO> res = farmingTypeMaintenanceService.getFarmingTypeList();
|
|
||||||
// return success(BeanUtils.toBean(res, FarmingTypeRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-下拉框列表-三级物种类别")
|
|
||||||
// @GetMapping("/list/three-library")
|
|
||||||
// public CommonResult<List<SpeciesThreeLevelTreeRespVO>> getTreeLibraryList() {
|
|
||||||
// try {
|
|
||||||
// List<SpeciesThreeLevelTreeRespVO> threeList = speciesLibraryService.getSpeciesThreeLevelTree();
|
|
||||||
// return success(threeList);
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error("获取三级物种类别列表失败", e);
|
|
||||||
// return success(new ArrayList<>());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-下拉框列表-二级物种类别")
|
|
||||||
// @GetMapping("/list/two-library")
|
|
||||||
// public CommonResult<List<SpeciesThreeLevelTreeRespVO>> getTwoLibraryList() {
|
|
||||||
// try {
|
|
||||||
// List<SpeciesThreeLevelTreeRespVO> twoList = speciesLibraryService.getSpeciesTwoLevelTree();
|
|
||||||
// return success(twoList);
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error("获取二级物种类别列表失败", e);
|
|
||||||
// return success(new ArrayList<>());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-下拉框列表-物种类别与模型")
|
|
||||||
// @GetMapping("/list/species-classify-model")
|
|
||||||
// public CommonResult<List<SpeciesClassifyLibraryRespVO>> getSpeciesClassifyAndModelList() {
|
|
||||||
// return success(sysDictService.getSpeciesClassifyAndModelList());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
@GetMapping("/list/base-name")
|
@GetMapping("/list/base-name")
|
||||||
@Operation(summary = "字典数据维护-下拉框列表-基地,地块二级联动")
|
@Operation(summary = "字典数据维护-下拉框列表-基地,地块二级联动")
|
||||||
public CommonResult<List<BaseNameRespVO>> getBaseNameList() {
|
public CommonResult<List<BaseNameRespVO>> getBaseNameList() {
|
||||||
List<BaseNameRespVO> res = baseInfoService.getBaseNameList();
|
List<BaseNameRespVO> res = baseInfoService.getBaseNameList();
|
||||||
return success(res);
|
return success(res);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
@GetMapping("/list/base-name-plan")
|
@GetMapping("/list/base-name-plan")
|
||||||
@Operation(summary = "字典数据维护-下拉框列表-基地,地块,计划三级联动")
|
@Operation(summary = "字典数据维护-下拉框列表-基地,地块,计划三级联动")
|
||||||
public CommonResult<List<BaseNamePlanRespVO>> getBaseNameAndPlanList() {
|
public CommonResult<List<BaseNamePlanRespVO>> getBaseNameAndPlanList() {
|
||||||
@@ -295,18 +60,4 @@ public class DictController {
|
|||||||
return success(res);
|
return success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Operation(summary = "字典数据维护-下拉框列表-通用字典分类查询")
|
|
||||||
// @GetMapping("/list/{dictTypeCode}")
|
|
||||||
// public CommonResult<List<SysDictRespVO>> getSysDictList(@PathVariable("dictTypeCode") String dictTypeCode) {
|
|
||||||
// List<SysDictDO> res = sysDictService.getByTypeCode(dictTypeCode);
|
|
||||||
// return success(BeanUtils.toBean(res, SysDictRespVO.class));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Operation(summary = "字典数据维护-下拉框列表-字典分类名称")
|
|
||||||
// @GetMapping("/list")
|
|
||||||
// public CommonResult<List<SysDictTypeCodeRespVO>> getSysDictList() {
|
|
||||||
// List<SysDictDO> res = sysDictService.groupByTypeCode();
|
|
||||||
// return success(BeanUtils.toBean(res, SysDictTypeCodeRespVO.class));
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,8 +74,7 @@ public class SpeciesLibraryController {
|
|||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "获得物种库维护分页")
|
@Operation(summary = "获得物种库维护分页")
|
||||||
public CommonResult<PageResult<SpeciesLibraryRespVO>> getSpeciesLibraryPage(@Valid SpeciesLibraryPageReqVO pageReqVO) {
|
public CommonResult<PageResult<SpeciesLibraryRespVO>> getSpeciesLibraryPage(@Valid SpeciesLibraryPageReqVO pageReqVO) {
|
||||||
PageResult<SpeciesLibraryDO> pageResult = speciesLibraryService.getSpeciesLibraryPage(pageReqVO);
|
PageResult<SpeciesLibraryRespVO> resp = speciesLibraryService.getSpeciesLibraryPage2(pageReqVO);
|
||||||
PageResult<SpeciesLibraryRespVO> resp = BeanUtils.toBean(pageResult, SpeciesLibraryRespVO.class);
|
|
||||||
return success(resp);
|
return success(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +92,7 @@ public class SpeciesLibraryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/two/tree")
|
@GetMapping("/two/tree")
|
||||||
@Operation(summary = "物种库二级树")
|
@Operation(summary = "物种库二级树-列表")
|
||||||
public CommonResult<List<SpeciesTwoLevelTreeRespVO>> getSpeciesTwoLevelTree(SpeciesTwoLevelTreeReqVO req) {
|
public CommonResult<List<SpeciesTwoLevelTreeRespVO>> getSpeciesTwoLevelTree(SpeciesTwoLevelTreeReqVO req) {
|
||||||
return success(speciesLibraryService.getSpeciesTwoTree(req));
|
return success(speciesLibraryService.getSpeciesTwoTree(req));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,82 +33,82 @@ import cn.iocoder.yudao.module.farm.service.twodict.TwoDictService;
|
|||||||
|
|
||||||
@Tag(name = "管理心中 - 基础数据管理 - 物种类型维护")
|
@Tag(name = "管理心中 - 基础数据管理 - 物种类型维护")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/farm/two-dict")
|
//@RequestMapping("/farm/two-dict")
|
||||||
@Validated
|
@Validated
|
||||||
public class TwoDictController {
|
public class TwoDictController {
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
private TwoDictService twoDictService;
|
// private TwoDictService twoDictService;
|
||||||
|
//
|
||||||
@PostMapping("/create")
|
// @PostMapping("/create")
|
||||||
@Operation(summary = "创建二级字典")
|
// @Operation(summary = "创建二级字典")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:create')")
|
// @PreAuthorize("@ss.hasPermission('farm:two-dict:create')")
|
||||||
public CommonResult<Long> createTwoDict(@Valid @RequestBody TwoDictSaveReqVO createReqVO) {
|
// public CommonResult<Long> createTwoDict(@Valid @RequestBody TwoDictSaveReqVO createReqVO) {
|
||||||
return success(twoDictService.createTwoDict(createReqVO));
|
// return success(twoDictService.createTwoDict(createReqVO));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@PutMapping("/update")
|
// @PutMapping("/update")
|
||||||
@Operation(summary = "更新二级字典")
|
// @Operation(summary = "更新二级字典")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:update')")
|
// @PreAuthorize("@ss.hasPermission('farm:two-dict:update')")
|
||||||
public CommonResult<Boolean> updateTwoDict(@Valid @RequestBody TwoDictSaveReqVO updateReqVO) {
|
// public CommonResult<Boolean> updateTwoDict(@Valid @RequestBody TwoDictSaveReqVO updateReqVO) {
|
||||||
twoDictService.updateTwoDict(updateReqVO);
|
// twoDictService.updateTwoDict(updateReqVO);
|
||||||
return success(true);
|
// return success(true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@DeleteMapping("/delete")
|
// @DeleteMapping("/delete")
|
||||||
@Operation(summary = "删除二级字典")
|
// @Operation(summary = "删除二级字典")
|
||||||
@Parameter(name = "id", description = "编号", required = true)
|
// @Parameter(name = "id", description = "编号", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:delete')")
|
// @PreAuthorize("@ss.hasPermission('farm:two-dict:delete')")
|
||||||
public CommonResult<Boolean> deleteTwoDict(@RequestParam("id") Long id) {
|
// public CommonResult<Boolean> deleteTwoDict(@RequestParam("id") Long id) {
|
||||||
twoDictService.deleteTwoDict(id);
|
// twoDictService.deleteTwoDict(id);
|
||||||
return success(true);
|
// return success(true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@DeleteMapping("/delete-list")
|
// @DeleteMapping("/delete-list")
|
||||||
@Parameter(name = "ids", description = "编号", required = true)
|
// @Parameter(name = "ids", description = "编号", required = true)
|
||||||
@Operation(summary = "批量删除二级字典")
|
// @Operation(summary = "批量删除二级字典")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:delete')")
|
// @PreAuthorize("@ss.hasPermission('farm:two-dict:delete')")
|
||||||
public CommonResult<Boolean> deleteTwoDictList(@RequestParam("ids") List<Long> ids) {
|
// public CommonResult<Boolean> deleteTwoDictList(@RequestParam("ids") List<Long> ids) {
|
||||||
twoDictService.deleteTwoDictListByIds(ids);
|
// twoDictService.deleteTwoDictListByIds(ids);
|
||||||
return success(true);
|
// return success(true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GetMapping("/get")
|
// @GetMapping("/get")
|
||||||
@Operation(summary = "获得二级字典")
|
// @Operation(summary = "获得二级字典")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
// @Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
// @PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
||||||
public CommonResult<TwoDictRespVO> getTwoDict(@RequestParam("id") Long id) {
|
// public CommonResult<TwoDictRespVO> getTwoDict(@RequestParam("id") Long id) {
|
||||||
TwoDictDO twoDict = twoDictService.getTwoDict(id);
|
// TwoDictDO twoDict = twoDictService.getTwoDict(id);
|
||||||
return success(BeanUtils.toBean(twoDict, TwoDictRespVO.class));
|
// return success(BeanUtils.toBean(twoDict, TwoDictRespVO.class));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GetMapping("/page")
|
// @GetMapping("/page")
|
||||||
@Operation(summary = "获得二级字典分页")
|
// @Operation(summary = "获得二级字典分页")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
// @PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
||||||
public CommonResult<PageResult<TwoDictRespVO>> getTwoDictPage(@Valid TwoDictPageReqVO pageReqVO) {
|
// public CommonResult<PageResult<TwoDictRespVO>> getTwoDictPage(@Valid TwoDictPageReqVO pageReqVO) {
|
||||||
PageResult<TwoDictDO> pageResult = twoDictService.getTwoDictPage(pageReqVO);
|
// PageResult<TwoDictDO> pageResult = twoDictService.getTwoDictPage(pageReqVO);
|
||||||
return success(BeanUtils.toBean(pageResult, TwoDictRespVO.class));
|
// return success(BeanUtils.toBean(pageResult, TwoDictRespVO.class));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GetMapping("/export-excel")
|
// @GetMapping("/export-excel")
|
||||||
@Operation(summary = "导出二级字典 Excel")
|
// @Operation(summary = "导出二级字典 Excel")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:export')")
|
// @PreAuthorize("@ss.hasPermission('farm:two-dict:export')")
|
||||||
@ApiAccessLog(operateType = EXPORT)
|
// @ApiAccessLog(operateType = EXPORT)
|
||||||
public void exportTwoDictExcel(@Valid TwoDictPageReqVO pageReqVO,
|
// public void exportTwoDictExcel(@Valid TwoDictPageReqVO pageReqVO,
|
||||||
HttpServletResponse response) throws IOException {
|
// HttpServletResponse response) throws IOException {
|
||||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
// pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
List<TwoDictDO> list = twoDictService.getTwoDictPage(pageReqVO).getList();
|
// List<TwoDictDO> list = twoDictService.getTwoDictPage(pageReqVO).getList();
|
||||||
// 导出 Excel
|
// // 导出 Excel
|
||||||
ExcelUtils.write(response, "二级字典.xls", "数据", TwoDictRespVO.class,
|
// ExcelUtils.write(response, "二级字典.xls", "数据", TwoDictRespVO.class,
|
||||||
BeanUtils.toBean(list, TwoDictRespVO.class));
|
// BeanUtils.toBean(list, TwoDictRespVO.class));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GetMapping("/tree")
|
// @GetMapping("/tree")
|
||||||
@Operation(summary = "获得二级字典树形结构")
|
// @Operation(summary = "获得二级字典树形结构")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
// @PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
||||||
public CommonResult<List<TwoDictTreeRespVO>> getTwoDictTree() {
|
// public CommonResult<List<TwoDictTreeRespVO>> getTwoDictTree() {
|
||||||
List<TwoDictTreeRespVO> tree = twoDictService.getTwoDictTree();
|
// List<TwoDictTreeRespVO> tree = twoDictService.getTwoDictTree();
|
||||||
return success(tree);
|
// return success(tree);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -72,4 +72,16 @@ public class SpeciesLibraryRespVO {
|
|||||||
@Schema(description = "租户id")
|
@Schema(description = "租户id")
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
|
||||||
|
@Schema(description = "使用状态 (1: 可删除; 0:不可删除)")
|
||||||
|
private Integer delStateForCode;
|
||||||
|
@Schema(description = "不可删除列表")
|
||||||
|
private List<SpeciesLibraryRespVO.Species> notDelList;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class Species {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,21 @@ public class SpeciesTwoLevelTreeRespVO {
|
|||||||
private String name;
|
private String name;
|
||||||
@Schema(description = "使用状态 (1: 启用; 0:停用)")
|
@Schema(description = "使用状态 (1: 启用; 0:停用)")
|
||||||
private Integer useStatus;
|
private Integer useStatus;
|
||||||
|
|
||||||
|
@Schema(description = "使用状态 (1: 可删除; 0:不可删除)")
|
||||||
|
private Integer delStateForCode;
|
||||||
|
@Schema(description = "不可删除列表")
|
||||||
|
private List<Species> notDelList;
|
||||||
|
|
||||||
@Schema(description = "子节点")
|
@Schema(description = "子节点")
|
||||||
private List<SpeciesTwoLevelTreeRespVO> children;
|
private List<SpeciesTwoLevelTreeRespVO> children;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class Species {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -604,25 +604,6 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
|
|||||||
FarmingRecordDO farmingRecord = farmingRecordService.getFarmingRecord(id);
|
FarmingRecordDO farmingRecord = farmingRecordService.getFarmingRecord(id);
|
||||||
FarmingRecordRespVO res = BeanUtils.toBean(farmingRecord, FarmingRecordRespVO.class);
|
FarmingRecordRespVO res = BeanUtils.toBean(farmingRecord, FarmingRecordRespVO.class);
|
||||||
res.setTaskStatusName(FARMING_RECORD_TASK_STATUS_MAP.get(res.getTaskStatus()));
|
res.setTaskStatusName(FARMING_RECORD_TASK_STATUS_MAP.get(res.getTaskStatus()));
|
||||||
|
|
||||||
// List<FarmingRecordRespVO.FarmingRecordInputVO> list = new ArrayList<>();
|
|
||||||
// for (FarmingRecordInputDO fr : farmingRecord.getInvestGoodsList()) {
|
|
||||||
// FarmingRecordRespVO.FarmingRecordInputVO target = new FarmingRecordRespVO.FarmingRecordInputVO();
|
|
||||||
// target.setId(fr.getId());
|
|
||||||
// target.setInputsId(fr.getInputChildCategory());
|
|
||||||
// target.setAssetType(fr.getInputParentCategory());
|
|
||||||
// target.setDose(fr.getDosage());
|
|
||||||
// target.setUsage(fr.getUsage());
|
|
||||||
//
|
|
||||||
// int diluted = fr.getDilutionRatio() != null ? Integer.parseInt(fr.getDilutionRatio()) : 0;
|
|
||||||
// target.setDiluted(diluted);
|
|
||||||
// int packageUnit = fr.getSingleUseUnit() != null ? Integer.parseInt(fr.getSingleUseUnit()) : 0;
|
|
||||||
// target.setPackageUnit(packageUnit);
|
|
||||||
// int unit = fr.getSingleUseOption() != null ? Integer.parseInt(fr.getSingleUseOption()) : 0;
|
|
||||||
// target.setUnit(unit);
|
|
||||||
// list.add(target);
|
|
||||||
// }
|
|
||||||
// res.setInvestGoodsList(list);
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public interface SpeciesLibraryService {
|
|||||||
* @param pageReqVO 分页查询
|
* @param pageReqVO 分页查询
|
||||||
* @return 物种库维护分页
|
* @return 物种库维护分页
|
||||||
*/
|
*/
|
||||||
|
PageResult<SpeciesLibraryRespVO> getSpeciesLibraryPage2(SpeciesLibraryPageReqVO pageReqVO);
|
||||||
PageResult<SpeciesLibraryDO> getSpeciesLibraryPage(SpeciesLibraryPageReqVO pageReqVO);
|
PageResult<SpeciesLibraryDO> getSpeciesLibraryPage(SpeciesLibraryPageReqVO pageReqVO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
@Resource
|
@Resource
|
||||||
private SpeciesLibraryMapper speciesLibraryMapper;
|
private SpeciesLibraryMapper speciesLibraryMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private SysDictService sysDictService;
|
|
||||||
@Resource
|
|
||||||
private ModelManagementMapper modelManagementMapper;
|
private ModelManagementMapper modelManagementMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TwoDictService twoDictService;
|
private TwoDictService twoDictService;
|
||||||
@@ -66,12 +64,6 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
speciesLibrary.setId(id);
|
speciesLibrary.setId(id);
|
||||||
speciesLibrary.setTenantId(String.valueOf(user.getTenantId()));
|
speciesLibrary.setTenantId(String.valueOf(user.getTenantId()));
|
||||||
speciesLibrary.setCreateTime(LocalDateTime.now());
|
speciesLibrary.setCreateTime(LocalDateTime.now());
|
||||||
// TwoDictDO dictDO3 = twoDictService.getTwoDict(Long.valueOf(speciesLibrary.getCategory()));
|
|
||||||
// TwoDictDO dictDO2 = twoDictService.getTwoDict(dictDO3.getParentId());
|
|
||||||
// if (dictDO2.getParentId() != null) {
|
|
||||||
// TwoDictDO dictDO1 = twoDictService.getTwoDict(dictDO2.getParentId());
|
|
||||||
// speciesLibrary.setSpeciesName(dictDO1.getName() + "/" + dictDO2.getName() + "/" + dictDO3.getName());
|
|
||||||
// }
|
|
||||||
String speciesName = twoDictService.appendToSpeciesName(String.valueOf(speciesLibrary.getCategory()));
|
String speciesName = twoDictService.appendToSpeciesName(String.valueOf(speciesLibrary.getCategory()));
|
||||||
speciesLibrary.setSpeciesName(speciesName);
|
speciesLibrary.setSpeciesName(speciesName);
|
||||||
for (String image : createReqVO.getImageList()) {
|
for (String image : createReqVO.getImageList()) {
|
||||||
@@ -101,12 +93,6 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
|
|
||||||
// 更新
|
// 更新
|
||||||
SpeciesLibraryDO updateObj = BeanUtils.toBean(updateReqVO, SpeciesLibraryDO.class);
|
SpeciesLibraryDO updateObj = BeanUtils.toBean(updateReqVO, SpeciesLibraryDO.class);
|
||||||
// TwoDictDO dictDO3 = twoDictService.getTwoDict(Long.valueOf(updateObj.getCategory()));
|
|
||||||
// TwoDictDO dictDO2 = twoDictService.getTwoDict(dictDO3.getParentId());
|
|
||||||
// if (dictDO2.getParentId() != null) {
|
|
||||||
// TwoDictDO dictDO1 = twoDictService.getTwoDict(dictDO2.getParentId());
|
|
||||||
// updateObj.setSpeciesName(dictDO1.getName() + "/" + dictDO2.getName() + "/" + dictDO3.getName());
|
|
||||||
// }
|
|
||||||
String speciesName = twoDictService.appendToSpeciesName(String.valueOf(updateObj.getCategory()));
|
String speciesName = twoDictService.appendToSpeciesName(String.valueOf(updateObj.getCategory()));
|
||||||
updateObj.setSpeciesName(speciesName);
|
updateObj.setSpeciesName(speciesName);
|
||||||
for (String image : updateObj.getImageList()) {
|
for (String image : updateObj.getImageList()) {
|
||||||
@@ -148,17 +134,53 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
return speciesLibrary;
|
return speciesLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PageResult<SpeciesLibraryRespVO> getSpeciesLibraryPage2(SpeciesLibraryPageReqVO pageReqVO) {
|
||||||
|
PageResult<SpeciesLibraryDO> pageResult = this.getSpeciesLibraryPage(pageReqVO);
|
||||||
|
PageResult<SpeciesLibraryRespVO> resp = BeanUtils.toBean(pageResult, SpeciesLibraryRespVO.class);
|
||||||
|
|
||||||
|
Map<String, List<SpeciesLibraryRespVO.Species>> containForModel = isContainForModel();
|
||||||
|
|
||||||
|
for (SpeciesLibraryRespVO s : resp.getList()) {
|
||||||
|
String id = s.getId(); // 物种表id
|
||||||
|
if (containForModel.containsKey(id)) {
|
||||||
|
s.setDelStateForCode(CommonConstants.NO_CODE);
|
||||||
|
s.setNotDelList(containForModel.get(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String,List<SpeciesLibraryRespVO.Species>> isContainForModel() {
|
||||||
|
List<ModelManagementDO> mList = modelManagementMapper.selectList();
|
||||||
|
|
||||||
|
return mList.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
ModelManagementDO::getSpeciesId,
|
||||||
|
Collectors.mapping(
|
||||||
|
model -> new SpeciesLibraryRespVO.Species(
|
||||||
|
String.valueOf(model.getId()),
|
||||||
|
model.getModelName()
|
||||||
|
),
|
||||||
|
Collectors.toList()
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<SpeciesLibraryDO> getSpeciesLibraryPage(SpeciesLibraryPageReqVO pageReqVO) {
|
public PageResult<SpeciesLibraryDO> getSpeciesLibraryPage(SpeciesLibraryPageReqVO pageReqVO) {
|
||||||
PageResult<SpeciesLibraryDO> pageResult = speciesLibraryMapper.selectPage(pageReqVO);
|
PageResult<SpeciesLibraryDO> pageResult = speciesLibraryMapper.selectPage(pageReqVO);
|
||||||
if (pageResult.getList() != null) {
|
if (pageResult.getList() == null) {
|
||||||
// 触发图片集合转换,确保分页结果中的每个DO对象都包含转换后的图片集合
|
throw exception(SPECIES_LIBRARY_NOT_EXISTS);
|
||||||
pageResult.getList().forEach(speciesLibrary -> {
|
|
||||||
if (speciesLibrary != null) {
|
|
||||||
speciesLibrary.getImageList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 触发图片集合转换,确保分页结果中的每个DO对象都包含转换后的图片集合
|
||||||
|
pageResult.getList().forEach(speciesLibrary -> {
|
||||||
|
if (speciesLibrary != null) {
|
||||||
|
speciesLibrary.getImageList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return pageResult;
|
return pageResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,16 +314,7 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String splitSpeciesName(String speciesName, int index) {
|
|
||||||
if (speciesName == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String[] parts = speciesName.split("/");
|
|
||||||
if (index < parts.length) {
|
|
||||||
return parts[index];
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SpeciesTwoLevelTreeRespVO> getSpeciesTwoTree(SpeciesTwoLevelTreeReqVO req) {
|
public List<SpeciesTwoLevelTreeRespVO> getSpeciesTwoTree(SpeciesTwoLevelTreeReqVO req) {
|
||||||
@@ -319,24 +332,6 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
return buildInfiniteTree(allDicts, null, 0);
|
return buildInfiniteTree(allDicts, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID在树中查找节点
|
|
||||||
*/
|
|
||||||
private SpeciesTwoLevelTreeRespVO findNodeById(List<SpeciesTwoLevelTreeRespVO> tree, Long id) {
|
|
||||||
for (SpeciesTwoLevelTreeRespVO node : tree) {
|
|
||||||
if (node.getId().equals(id)) {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
|
||||||
SpeciesTwoLevelTreeRespVO found = findNodeById(node.getChildren(), id);
|
|
||||||
if (found != null) {
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建无限极树形结构
|
* 构建无限极树形结构
|
||||||
*
|
*
|
||||||
@@ -347,17 +342,40 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
*/
|
*/
|
||||||
private List<SpeciesTwoLevelTreeRespVO> buildInfiniteTree(List<TwoDictDO> allDicts, Long parentId, int level) {
|
private List<SpeciesTwoLevelTreeRespVO> buildInfiniteTree(List<TwoDictDO> allDicts, Long parentId, int level) {
|
||||||
List<SpeciesTwoLevelTreeRespVO> treeList = new ArrayList<>();
|
List<SpeciesTwoLevelTreeRespVO> treeList = new ArrayList<>();
|
||||||
|
Map<Long, List<SpeciesTwoLevelTreeRespVO.Species>> speciesMap = this.isContain();
|
||||||
|
|
||||||
for (TwoDictDO dict : allDicts) {
|
for (TwoDictDO dict : allDicts) {
|
||||||
// 匹配父级ID,构建当前层级的节点
|
// 匹配父级ID,构建当前层级的节点
|
||||||
if (Objects.equals(dict.getParentId(), parentId)) {
|
if (Objects.equals(dict.getParentId(), parentId)) {
|
||||||
SpeciesTwoLevelTreeRespVO treeNode = convertToSpeciesTreeVO(dict);
|
SpeciesTwoLevelTreeRespVO treeNode = convertToSpeciesTreeVO(dict,level);
|
||||||
treeNode.setSort(level);
|
|
||||||
|
|
||||||
// 递归构建子节点
|
// 递归构建子节点
|
||||||
List<SpeciesTwoLevelTreeRespVO> children = buildInfiniteTree(allDicts, dict.getId(), level + 1);
|
List<SpeciesTwoLevelTreeRespVO> children = buildInfiniteTree(allDicts, dict.getId(), level + 1);
|
||||||
treeNode.setChildren(children);
|
treeNode.setChildren(children);
|
||||||
|
|
||||||
|
// 设置删除状态
|
||||||
|
if (children.isEmpty()) {
|
||||||
|
// 叶子节点:根据关联关系判断
|
||||||
|
treeNode.setDelStateForCode(speciesMap.containsKey(treeNode.getId()) ? 0 : 1);
|
||||||
|
List<SpeciesTwoLevelTreeRespVO.Species> species = speciesMap.get(treeNode.getId());
|
||||||
|
treeNode.setNotDelList(species);
|
||||||
|
} else {
|
||||||
|
// 非叶子节点:如果任何子节点不可删除,当前节点也不可
|
||||||
|
boolean anyChildCannotDelete = children.stream().anyMatch(child -> child.getDelStateForCode() == 0);
|
||||||
|
treeNode.setDelStateForCode(anyChildCannotDelete ? 0 : 1);
|
||||||
|
|
||||||
|
if (anyChildCannotDelete) {
|
||||||
|
List<SpeciesTwoLevelTreeRespVO.Species> list = children.stream()
|
||||||
|
.map(SpeciesTwoLevelTreeRespVO::getNotDelList)
|
||||||
|
.filter(Objects::nonNull) // 过滤掉null的List
|
||||||
|
.flatMap(List::stream) // 将每个List展开
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
treeNode.setNotDelList(list);
|
||||||
|
} else {
|
||||||
|
treeNode.setNotDelList(Collections.EMPTY_LIST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
treeList.add(treeNode);
|
treeList.add(treeNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,258 +383,42 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
return treeList;
|
return treeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<Long,List<SpeciesTwoLevelTreeRespVO.Species>> isContain() {
|
||||||
|
List<SpeciesLibraryDO> list = speciesLibraryMapper.selectList();
|
||||||
|
|
||||||
|
return list.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(speciesLib -> speciesLib.getCategory() != null)
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
SpeciesLibraryDO::getCategory,
|
||||||
|
Collectors.mapping(
|
||||||
|
speciesLib -> {
|
||||||
|
// 处理speciesName和cultivarName可能为null的情况
|
||||||
|
String speciesName = speciesLib.getSpeciesName() != null ? speciesLib.getSpeciesName() : "";
|
||||||
|
String cultivarName = speciesLib.getCultivarName() != null ? speciesLib.getCultivarName() : "";
|
||||||
|
String name = speciesName + "/" + cultivarName;
|
||||||
|
|
||||||
|
return new SpeciesTwoLevelTreeRespVO.Species(speciesLib.getId(),name);
|
||||||
|
},
|
||||||
|
Collectors.toList()
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将TwoDictDO转换为SpeciesTwoLevelTreeRespVO
|
* 将TwoDictDO转换为SpeciesTwoLevelTreeRespVO
|
||||||
*/
|
*/
|
||||||
private SpeciesTwoLevelTreeRespVO convertToSpeciesTreeVO(TwoDictDO dict) {
|
private SpeciesTwoLevelTreeRespVO convertToSpeciesTreeVO(TwoDictDO dict,int level) {
|
||||||
SpeciesTwoLevelTreeRespVO vo = new SpeciesTwoLevelTreeRespVO();
|
SpeciesTwoLevelTreeRespVO vo = new SpeciesTwoLevelTreeRespVO();
|
||||||
vo.setId(dict.getId());
|
vo.setId(dict.getId());
|
||||||
vo.setParentId(dict.getParentId() != null ? dict.getParentId() : 0L);
|
vo.setParentId(dict.getParentId() != null ? dict.getParentId() : 0L);
|
||||||
vo.setName(dict.getName());
|
vo.setName(dict.getName());
|
||||||
vo.setUseStatus(Boolean.TRUE.equals(dict.getStatus()) ? 1 : 0);
|
vo.setUseStatus(Boolean.TRUE.equals(dict.getStatus()) ? 1 : 0);
|
||||||
|
vo.setSort(level);
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建从指定节点到根节点的完整路径,并过滤掉不相关的分支
|
|
||||||
*/
|
|
||||||
private List<SpeciesTwoLevelTreeRespVO> buildPathToRoot(List<SpeciesTwoLevelTreeRespVO> tree, Long targetNodeId) {
|
|
||||||
// 首先找到目标节点
|
|
||||||
SpeciesTwoLevelTreeRespVO targetNode = findNodeById(tree, targetNodeId);
|
|
||||||
if (targetNode == null) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建从目标节点到根节点的路径
|
|
||||||
List<SpeciesTwoLevelTreeRespVO> path = new ArrayList<>();
|
|
||||||
buildPathRecursively(tree, targetNodeId, path);
|
|
||||||
|
|
||||||
// 反转路径,使其从根节点开始
|
|
||||||
Collections.reverse(path);
|
|
||||||
|
|
||||||
// 构建过滤后的树结构
|
|
||||||
if (!path.isEmpty()) {
|
|
||||||
return buildFilteredTreeFromPath(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归构建从目标节点到根节点的路径
|
|
||||||
*/
|
|
||||||
private boolean buildPathRecursively(List<SpeciesTwoLevelTreeRespVO> tree, Long targetNodeId, List<SpeciesTwoLevelTreeRespVO> path) {
|
|
||||||
for (SpeciesTwoLevelTreeRespVO node : tree) {
|
|
||||||
if (node.getId().equals(targetNodeId)) {
|
|
||||||
path.add(node);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
|
||||||
if (buildPathRecursively(node.getChildren(), targetNodeId, path)) {
|
|
||||||
path.add(node);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据路径构建过滤后的树结构
|
|
||||||
*/
|
|
||||||
private List<SpeciesTwoLevelTreeRespVO> buildFilteredTreeFromPath(List<SpeciesTwoLevelTreeRespVO> path) {
|
|
||||||
if (path.isEmpty()) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从根节点开始构建过滤后的树
|
|
||||||
SpeciesTwoLevelTreeRespVO rootNode = createFilteredNodeFromPath(path, 0);
|
|
||||||
return Collections.singletonList(rootNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归创建过滤后的节点,只包含路径上的节点
|
|
||||||
*/
|
|
||||||
private SpeciesTwoLevelTreeRespVO createFilteredNodeFromPath(List<SpeciesTwoLevelTreeRespVO> path, int currentIndex) {
|
|
||||||
if (currentIndex >= path.size()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpeciesTwoLevelTreeRespVO originalNode = path.get(currentIndex);
|
|
||||||
SpeciesTwoLevelTreeRespVO filteredNode = new SpeciesTwoLevelTreeRespVO();
|
|
||||||
filteredNode.setId(originalNode.getId());
|
|
||||||
filteredNode.setParentId(originalNode.getParentId());
|
|
||||||
filteredNode.setName(originalNode.getName());
|
|
||||||
filteredNode.setUseStatus(originalNode.getUseStatus());
|
|
||||||
filteredNode.setSort(originalNode.getSort());
|
|
||||||
|
|
||||||
// 如果有下一个节点,说明当前节点有子节点
|
|
||||||
if (currentIndex + 1 < path.size()) {
|
|
||||||
SpeciesTwoLevelTreeRespVO childNode = createFilteredNodeFromPath(path, currentIndex + 1);
|
|
||||||
if (childNode != null) {
|
|
||||||
filteredNode.setChildren(Collections.singletonList(childNode));
|
|
||||||
} else {
|
|
||||||
filteredNode.setChildren(new ArrayList<>());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 这是路径的最后一个节点,没有子节点
|
|
||||||
filteredNode.setChildren(new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
return filteredNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 找到指定节点的根节点ID
|
|
||||||
*/
|
|
||||||
private Long findRootNodeId(List<SpeciesTwoLevelTreeRespVO> tree, Long targetNodeId) {
|
|
||||||
// 首先找到目标节点
|
|
||||||
SpeciesTwoLevelTreeRespVO targetNode = findNodeById(tree, targetNodeId);
|
|
||||||
if (targetNode == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果目标节点就是根节点
|
|
||||||
if (targetNode.getParentId() == null || targetNode.getParentId() == 0L) {
|
|
||||||
return targetNode.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 递归向上查找根节点
|
|
||||||
return findRootNodeIdRecursively(tree, targetNode.getParentId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归查找根节点ID
|
|
||||||
*/
|
|
||||||
private Long findRootNodeIdRecursively(List<SpeciesTwoLevelTreeRespVO> tree, Long nodeId) {
|
|
||||||
for (SpeciesTwoLevelTreeRespVO node : tree) {
|
|
||||||
if (node.getId().equals(nodeId)) {
|
|
||||||
if (node.getParentId() == null || node.getParentId() == 0L) {
|
|
||||||
return node.getId();
|
|
||||||
} else {
|
|
||||||
return findRootNodeIdRecursively(tree, node.getParentId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
|
||||||
Long result = findRootNodeIdRecursively(node.getChildren(), nodeId);
|
|
||||||
if (result != null) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建过滤后的根节点,只包含匹配的子节点路径
|
|
||||||
*/
|
|
||||||
private SpeciesTwoLevelTreeRespVO createFilteredRootNode(SpeciesTwoLevelTreeRespVO rootNode, List<Long> matchedChildIds) {
|
|
||||||
SpeciesTwoLevelTreeRespVO filteredRootNode = new SpeciesTwoLevelTreeRespVO();
|
|
||||||
filteredRootNode.setId(rootNode.getId());
|
|
||||||
filteredRootNode.setParentId(rootNode.getParentId());
|
|
||||||
filteredRootNode.setName(rootNode.getName());
|
|
||||||
filteredRootNode.setUseStatus(rootNode.getUseStatus());
|
|
||||||
filteredRootNode.setSort(rootNode.getSort());
|
|
||||||
|
|
||||||
// 递归过滤子节点
|
|
||||||
List<SpeciesTwoLevelTreeRespVO> filteredChildren = filterChildrenRecursively(rootNode.getChildren(), matchedChildIds);
|
|
||||||
filteredRootNode.setChildren(filteredChildren);
|
|
||||||
|
|
||||||
return filteredRootNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归过滤子节点,只保留包含匹配节点的路径
|
|
||||||
*/
|
|
||||||
private List<SpeciesTwoLevelTreeRespVO> filterChildrenRecursively(List<SpeciesTwoLevelTreeRespVO> children, List<Long> matchedChildIds) {
|
|
||||||
if (children == null || children.isEmpty()) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<SpeciesTwoLevelTreeRespVO> filteredChildren = new ArrayList<>();
|
|
||||||
|
|
||||||
for (SpeciesTwoLevelTreeRespVO child : children) {
|
|
||||||
// 检查当前节点是否在匹配列表中
|
|
||||||
boolean isMatched = matchedChildIds.contains(child.getId());
|
|
||||||
|
|
||||||
// 递归检查子节点
|
|
||||||
List<SpeciesTwoLevelTreeRespVO> filteredGrandChildren = filterChildrenRecursively(child.getChildren(), matchedChildIds);
|
|
||||||
|
|
||||||
// 如果当前节点匹配或有匹配的子节点,则包含此节点
|
|
||||||
if (isMatched || !filteredGrandChildren.isEmpty()) {
|
|
||||||
SpeciesTwoLevelTreeRespVO filteredChild = new SpeciesTwoLevelTreeRespVO();
|
|
||||||
filteredChild.setId(child.getId());
|
|
||||||
filteredChild.setParentId(child.getParentId());
|
|
||||||
filteredChild.setName(child.getName());
|
|
||||||
filteredChild.setUseStatus(child.getUseStatus());
|
|
||||||
filteredChild.setSort(child.getSort());
|
|
||||||
filteredChild.setChildren(filteredGrandChildren);
|
|
||||||
filteredChildren.add(filteredChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return filteredChildren;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 收集指定节点的所有后代节点ID
|
|
||||||
*/
|
|
||||||
private void collectAllDescendants(List<SpeciesTwoLevelTreeRespVO> tree, Long nodeId, Set<Long> allDescendants) {
|
|
||||||
SpeciesTwoLevelTreeRespVO node = findNodeById(tree, nodeId);
|
|
||||||
if (node != null && node.getChildren() != null) {
|
|
||||||
for (SpeciesTwoLevelTreeRespVO child : node.getChildren()) {
|
|
||||||
allDescendants.add(child.getId());
|
|
||||||
// 递归收集子节点的后代
|
|
||||||
collectAllDescendants(tree, child.getId(), allDescendants);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建完整的树形结构(之前的实现)
|
|
||||||
*/
|
|
||||||
private List<SpeciesTwoLevelTreeRespVO> buildTree(List<TwoDictDO> allDicts) {
|
|
||||||
Map<Long, List<TwoDictDO>> childrenMap = allDicts.stream()
|
|
||||||
.filter(dict -> dict.getParentId() != null)
|
|
||||||
.collect(Collectors.groupingBy(TwoDictDO::getParentId));
|
|
||||||
|
|
||||||
return allDicts.stream()
|
|
||||||
.filter(dict -> dict.getParentId() == null)
|
|
||||||
.sorted(Comparator.comparing(TwoDictDO::getId))
|
|
||||||
.map(parent -> buildNode(parent, childrenMap, 1))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private SpeciesTwoLevelTreeRespVO buildNode(TwoDictDO dict, Map<Long, List<TwoDictDO>> childrenMap, int sort) {
|
|
||||||
SpeciesTwoLevelTreeRespVO vo = convertToVO(dict);
|
|
||||||
vo.setSort(sort);
|
|
||||||
|
|
||||||
List<TwoDictDO> children = childrenMap.get(dict.getId());
|
|
||||||
if (children != null) {
|
|
||||||
List<TwoDictDO> sortedChildren = children.stream()
|
|
||||||
.sorted(Comparator.comparing(TwoDictDO::getId))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<SpeciesTwoLevelTreeRespVO> childNodes = new ArrayList<>();
|
|
||||||
for (int i = 0; i < sortedChildren.size(); i++) {
|
|
||||||
childNodes.add(buildNode(sortedChildren.get(i), childrenMap, i + 1));
|
|
||||||
}
|
|
||||||
vo.setChildren(childNodes);
|
|
||||||
} else {
|
|
||||||
vo.setChildren(new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
return vo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SpeciesTwoLevelTreeRespVO convertToVO(TwoDictDO dict) {
|
|
||||||
SpeciesTwoLevelTreeRespVO vo = new SpeciesTwoLevelTreeRespVO();
|
|
||||||
vo.setId(dict.getId());
|
|
||||||
vo.setParentId(dict.getParentId() != null ? dict.getParentId() : 0L);
|
|
||||||
vo.setName(dict.getName());
|
|
||||||
vo.setUseStatus(dict.getStatus() ? 1 : 0);
|
|
||||||
return vo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SpeciesAndModelTreeRespVO> getSpeciesAndModelTree() {
|
public List<SpeciesAndModelTreeRespVO> getSpeciesAndModelTree() {
|
||||||
@@ -700,7 +502,7 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
|
|
||||||
if (hasChildren) {
|
if (hasChildren) {
|
||||||
// 3. 如果是父节点,更新自身及其所有子节点
|
// 3. 如果是父节点,更新自身及其所有子节点
|
||||||
updateSelfAndChildren(id, req.getUseStatus() == 1);
|
updateSelfAndChildren(id, req.getName(),req.getUseStatus() == 1);
|
||||||
} else {
|
} else {
|
||||||
// 4. 如果是子节点,只更新自身
|
// 4. 如果是子节点,只更新自身
|
||||||
this.updateSelf(id, req.getName(), req.getUseStatus() == 1);
|
this.updateSelf(id, req.getName(), req.getUseStatus() == 1);
|
||||||
@@ -732,9 +534,9 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
|
|||||||
/**
|
/**
|
||||||
* 更新自身及其所有子节点(递归更新)
|
* 更新自身及其所有子节点(递归更新)
|
||||||
*/
|
*/
|
||||||
private void updateSelfAndChildren(Long id, boolean status) {
|
private void updateSelfAndChildren(Long id, String name,boolean status) {
|
||||||
// 先更新自身
|
// 先更新自身
|
||||||
updateSelf(id, null, status);
|
updateSelf(id, name, status);
|
||||||
// 递归更新所有子节点
|
// 递归更新所有子节点
|
||||||
updateChildrenRecursively(id, status);
|
updateChildrenRecursively(id, status);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user