feat (farm): 生产计划
- 物种与模型三级联动接口
This commit is contained in:
@@ -275,35 +275,15 @@ public class DictController {
|
||||
@Operation(summary = "字典数据维护-下拉框列表-物种类别")
|
||||
@GetMapping("/list/species-classify-library")
|
||||
public CommonResult<List<SpeciesClassifyLibraryRespVO>> getSpeciesClassifyLibraryList() {
|
||||
|
||||
List<SysDictDO> list = sysDictService.getByTypeCode(CommonConstants.DICT_TYPE_CODE_3);
|
||||
Map<String, String> parentMap = list.stream()
|
||||
.collect(Collectors.toMap(
|
||||
SysDictDO::getField1Code, // key: field1Code
|
||||
SysDictDO::getField1Name, // value: field1Name
|
||||
(existing, replacement) -> existing // 处理重复key,保留现有值
|
||||
));
|
||||
|
||||
List<SpeciesClassifyLibraryRespVO> parentList = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : parentMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
SpeciesClassifyLibraryRespVO pVO = new SpeciesClassifyLibraryRespVO(key, entry.getValue());
|
||||
|
||||
List<SpeciesClassifyLibraryRespVO> childList = new ArrayList<>();
|
||||
for (SysDictDO e : list) {
|
||||
if (e.getField1Code().equals(key)) {
|
||||
childList.add(new SpeciesClassifyLibraryRespVO(e.getField2Code(),e.getField2Name()));
|
||||
}
|
||||
}
|
||||
pVO.setChildren(childList);
|
||||
parentList.add(pVO);
|
||||
return success(sysDictService.getSpeciesClassifyLibraryList());
|
||||
}
|
||||
|
||||
return success(parentList);
|
||||
@Operation(summary = "字典数据维护-下拉框列表-物种类别与模型")
|
||||
@GetMapping("/list/species-classify-model")
|
||||
public CommonResult<List<SpeciesClassifyLibraryRespVO>> getSpeciesClassifyAndModelList(){
|
||||
return success(sysDictService.getSpeciesClassifyAndModelList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "字典数据维护-下拉框列表-通用字典分类查询")
|
||||
@GetMapping("/list/{dictTypeCode}")
|
||||
public CommonResult<List<SysDictRespVO>> getSysDictList(@PathVariable("dictTypeCode") String dictTypeCode) {
|
||||
@@ -318,131 +298,4 @@ public class DictController {
|
||||
return success(BeanUtils.toBean(res, SysDictTypeCodeRespVO.class));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "字典数据维护-下拉框列表-投入品类型")
|
||||
@GetMapping("/list/invest-goods")
|
||||
public CommonResult<List<CommonDictRespVO>> getInvestGoodsList() {
|
||||
// todo 后续维护到字典表
|
||||
List<CommonDictRespVO> list = Arrays.asList(
|
||||
new CommonDictRespVO("1", "肥料", 1),
|
||||
new CommonDictRespVO("2", "药物", 1),
|
||||
new CommonDictRespVO("3", "种子", 1),
|
||||
new CommonDictRespVO("4", "膜", 1),
|
||||
new CommonDictRespVO("99", "其他", 1)
|
||||
);
|
||||
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "字典数据维护-下拉框列表-投入品规格-单位1")
|
||||
@GetMapping("/list/units/1")
|
||||
public CommonResult<List<CommonDictRespVO>> getUnits1List() {
|
||||
// todo 后续维护到字典表
|
||||
List<CommonDictRespVO> list = Arrays.asList(
|
||||
new CommonDictRespVO("1", "吨", 1),
|
||||
new CommonDictRespVO("2", "千克", 1),
|
||||
new CommonDictRespVO("3", "斤", 1),
|
||||
new CommonDictRespVO("4", "立方米", 1),
|
||||
new CommonDictRespVO("5", "米", 1),
|
||||
new CommonDictRespVO("6", "克", 1)
|
||||
);
|
||||
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "字典数据维护-下拉框列表-投入品规格-单位2")
|
||||
@GetMapping("/list/units/2")
|
||||
public CommonResult<List<CommonDictRespVO>> getUnits2List() {
|
||||
// todo 后续维护到字典表
|
||||
List<CommonDictRespVO> list = Arrays.asList(
|
||||
new CommonDictRespVO("1", "包", 1),
|
||||
new CommonDictRespVO("2", "袋", 1),
|
||||
new CommonDictRespVO("3", "桶", 1),
|
||||
new CommonDictRespVO("4", "车", 1),
|
||||
new CommonDictRespVO("5", "捆", 1),
|
||||
new CommonDictRespVO("6", "立方米", 1),
|
||||
new CommonDictRespVO("7", "箱", 1)
|
||||
);
|
||||
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "字典数据维护-下拉框列表-灾害类型")
|
||||
@GetMapping("/list/disaster")
|
||||
public CommonResult<List<CommonDictRespVO>> getDisasterDataList() {
|
||||
// todo 后续维护到字典表
|
||||
List<CommonDictRespVO> list = Arrays.asList(
|
||||
new CommonDictRespVO("1", "虫害", 1),
|
||||
new CommonDictRespVO("2", "病害", 1),
|
||||
new CommonDictRespVO("3", "草害", 1)
|
||||
);
|
||||
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "字典数据维护-下拉框列表-气象灾害名称")
|
||||
@GetMapping("/list/weather/disaster")
|
||||
public CommonResult<List<CommonDictRespVO>> getWeatherDisasterDataList() {
|
||||
// todo 后续维护到字典表
|
||||
List<CommonDictRespVO> list = Arrays.asList(
|
||||
new CommonDictRespVO("1","洪水",1),
|
||||
new CommonDictRespVO("2","内涝",1),
|
||||
new CommonDictRespVO("3","渍涝",1),
|
||||
new CommonDictRespVO("4","洪涝",1),
|
||||
new CommonDictRespVO("5","农业干旱",1),
|
||||
new CommonDictRespVO("6","台风",1),
|
||||
new CommonDictRespVO("7","暴雨",1),
|
||||
new CommonDictRespVO("8","暴雪",1),
|
||||
new CommonDictRespVO("9","寒潮",1),
|
||||
new CommonDictRespVO("10","大风",1),
|
||||
new CommonDictRespVO("11","沙尘暴",1),
|
||||
new CommonDictRespVO("12","高温",1),
|
||||
new CommonDictRespVO("13","干热风",1),
|
||||
new CommonDictRespVO("14","下击暴流",1),
|
||||
new CommonDictRespVO("15","冰雹",1),
|
||||
new CommonDictRespVO("16","霜冻",1),
|
||||
new CommonDictRespVO("17","貍",1),
|
||||
new CommonDictRespVO("18","雷雨大风",1),
|
||||
new CommonDictRespVO("19","道路结冰",1),
|
||||
new CommonDictRespVO("20","干旱",1),
|
||||
new CommonDictRespVO("21","高温中暑",1),
|
||||
new CommonDictRespVO("22","森林火险",1),
|
||||
new CommonDictRespVO("23","草原火险",1),
|
||||
new CommonDictRespVO("24","冰冻",1),
|
||||
new CommonDictRespVO("25","低温雨雪冰冻",1),
|
||||
new CommonDictRespVO("26","大雪",1),
|
||||
new CommonDictRespVO("27","寒冷",1),
|
||||
new CommonDictRespVO("28","连阴雨",1),
|
||||
new CommonDictRespVO("29","渍涝风险",1),
|
||||
new CommonDictRespVO("30","强降雨",1),
|
||||
new CommonDictRespVO("31","强降温",1),
|
||||
new CommonDictRespVO("32","雪灾",1),
|
||||
new CommonDictRespVO("33","雷暴",1),
|
||||
new CommonDictRespVO("34","降温",1),
|
||||
new CommonDictRespVO("35","台风暴雨",1),
|
||||
new CommonDictRespVO("36","严寒",1),
|
||||
new CommonDictRespVO("37","沙尘",1),
|
||||
new CommonDictRespVO("38","低温",1),
|
||||
new CommonDictRespVO("39","雷暴大风",1),
|
||||
new CommonDictRespVO("40","持续低温",1),
|
||||
new CommonDictRespVO("41","台风海浪",1),
|
||||
new CommonDictRespVO("42","森林(草原)火险",1)
|
||||
);
|
||||
|
||||
return success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,19 +16,16 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SpeciesClassifyLibraryRespVO {
|
||||
@Schema(description = "ID")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "一级分类-编码")
|
||||
private String SpeciesClassCode;
|
||||
private String speciesClassCode;
|
||||
@Schema(description = "一级分类-名称")
|
||||
private String SpeciesClassName;
|
||||
@Schema(description = "使用状态")
|
||||
private String useStatus;
|
||||
private String speciesClassName;
|
||||
|
||||
private List<SpeciesClassifyLibraryRespVO> children;
|
||||
|
||||
public SpeciesClassifyLibraryRespVO(String speciesClassCode, String speciesClassName) {
|
||||
SpeciesClassCode = speciesClassCode;
|
||||
SpeciesClassName = speciesClassName;
|
||||
this.speciesClassCode = speciesClassCode;
|
||||
this.speciesClassName = speciesClassName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.farm.service.sysDict;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.dict.vo.SpeciesClassifyLibraryRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.dict.vo.sys.SysDictPageReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenancePageReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenanceSaveReqVO;
|
||||
@@ -26,6 +27,9 @@ public interface SysDictService {
|
||||
|
||||
PageResult<SysDictDO> selectDictByPage(SysDictPageReqVO reqVO);
|
||||
|
||||
List<SpeciesClassifyLibraryRespVO> getSpeciesClassifyLibraryList();
|
||||
|
||||
List<SpeciesClassifyLibraryRespVO> getSpeciesClassifyAndModelList();
|
||||
|
||||
/**
|
||||
* 农事类型
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cn.iocoder.yudao.module.farm.service.sysDict;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.dict.vo.SpeciesClassifyLibraryRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.dict.vo.sys.SysDictPageReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.dict.vo.sys.SysDictReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenancePageReqVO;
|
||||
@@ -9,15 +11,21 @@ import cn.iocoder.yudao.module.farm.controller.admin.farmingtypemaintenance.vo.F
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.farmingtypemaintenance.vo.FarmingTypeMaintenanceSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.farmingnamemaintenance.FarmingNameMaintenanceDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.farmingtypemaintenance.FarmingTypeMaintenanceDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.modelmanagement.ModelManagementDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.modelmanagement.ModelManagementMapper;
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.sysDict.SysDictDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.sysDict.SysDictMapper;
|
||||
import cn.iocoder.yudao.module.farm.enums.CommonConstants;
|
||||
import cn.iocoder.yudao.module.farm.utils.StrHelperUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||
import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.FARMING_TYPE_MAINTENANCE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -33,9 +41,11 @@ public class SysDictServiceImpl implements SysDictService{
|
||||
|
||||
|
||||
private final SysDictMapper sysDictMapper;
|
||||
private final ModelManagementMapper modelManagementMapper;
|
||||
|
||||
public SysDictServiceImpl(SysDictMapper sysDictMapper) {
|
||||
public SysDictServiceImpl(SysDictMapper sysDictMapper, ModelManagementMapper modelManagementMapper) {
|
||||
this.sysDictMapper = sysDictMapper;
|
||||
this.modelManagementMapper = modelManagementMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,6 +85,117 @@ public class SysDictServiceImpl implements SysDictService{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpeciesClassifyLibraryRespVO> getSpeciesClassifyLibraryList() {
|
||||
return getSpeciesClassifyLibraryList(1);
|
||||
}
|
||||
|
||||
private List<SpeciesClassifyLibraryRespVO> getSpeciesClassifyLibraryList2() {
|
||||
return getSpeciesClassifyLibraryList(2);
|
||||
}
|
||||
|
||||
private List<SpeciesClassifyLibraryRespVO> getSpeciesClassifyLibraryList(int level) {
|
||||
List<SysDictDO> list = this.getByTypeCode(CommonConstants.DICT_TYPE_CODE_3);
|
||||
|
||||
if (level == 1) {
|
||||
// 一,二级联动
|
||||
return this.build(list, SysDictDO::getField1Code, SysDictDO::getField1Name, SysDictDO::getField2Code, SysDictDO::getField2Name, SysDictDO::getField1Code
|
||||
);
|
||||
} else if (level == 2) {
|
||||
// 二,三级联动
|
||||
return this.build(list, SysDictDO::getField2Code, SysDictDO::getField2Name, SysDictDO::getField3Code, SysDictDO::getField3Name, SysDictDO::getField2Code
|
||||
);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported level: " + level);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<SpeciesClassifyLibraryRespVO> build(
|
||||
List<SysDictDO> list,
|
||||
Function<SysDictDO, String> parentKeyExtractor,
|
||||
Function<SysDictDO, String> parentValueExtractor,
|
||||
Function<SysDictDO, String> childKeyExtractor,
|
||||
Function<SysDictDO, String> childValueExtractor,
|
||||
Function<SysDictDO, String> parentFilterExtractor) {
|
||||
|
||||
// 获取父级映射(去重)
|
||||
Map<String, String> parentMap = list.stream()
|
||||
.collect(Collectors.toMap(
|
||||
parentKeyExtractor,
|
||||
parentValueExtractor,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
|
||||
List<SpeciesClassifyLibraryRespVO> result = new ArrayList<>();
|
||||
|
||||
// 按父级代码分组,提前组织子级数据
|
||||
Map<String, List<SysDictDO>> groupedByParent = list.stream().collect(Collectors.groupingBy(parentFilterExtractor));
|
||||
|
||||
for (Map.Entry<String, String> entry : parentMap.entrySet()) {
|
||||
String parentKey = entry.getKey();
|
||||
SpeciesClassifyLibraryRespVO parentVO = new SpeciesClassifyLibraryRespVO(parentKey, entry.getValue());
|
||||
|
||||
// 获取该父级下的所有子项
|
||||
List<SysDictDO> childrenItems = groupedByParent.getOrDefault(parentKey, Collections.emptyList());
|
||||
|
||||
// 去重处理子项
|
||||
Map<String, String> childMap = childrenItems.stream()
|
||||
.filter(e -> childKeyExtractor.apply(e) != null && !childKeyExtractor.apply(e).isEmpty())
|
||||
.collect(Collectors.toMap(
|
||||
childKeyExtractor,
|
||||
childValueExtractor,
|
||||
(existing, replacement) -> existing
|
||||
));
|
||||
|
||||
// 构建子级VO列表
|
||||
List<SpeciesClassifyLibraryRespVO> childList = childMap.entrySet().stream()
|
||||
.map(childEntry -> new SpeciesClassifyLibraryRespVO(childEntry.getKey(), childEntry.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
parentVO.setChildren(childList);
|
||||
result.add(parentVO);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpeciesClassifyLibraryRespVO> getSpeciesClassifyAndModelList() {
|
||||
LoginUser user = getLoginUser();
|
||||
if (user == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
QueryWrapper<ModelManagementDO> qw = new QueryWrapper<>();
|
||||
qw.eq("tenant_id", user.getTenantId());
|
||||
qw.eq("type", CommonConstants.MODEL_TYPE_1);
|
||||
List<ModelManagementDO> modelList = modelManagementMapper.selectList(qw);
|
||||
|
||||
Map<String, Map<String, String>> modelMap = modelList.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
ModelManagementDO::getSpeciesId,
|
||||
Collectors.toMap(ModelManagementDO::getId, ModelManagementDO::getModelName)
|
||||
));
|
||||
|
||||
List<SpeciesClassifyLibraryRespVO> rootList = this.getSpeciesClassifyLibraryList2();
|
||||
for (SpeciesClassifyLibraryRespVO vo : rootList) {
|
||||
for (SpeciesClassifyLibraryRespVO child : vo.getChildren()) {
|
||||
|
||||
if (!modelMap.containsKey(child.getSpeciesClassCode())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<String, String> stringStringMap = modelMap.get(child.getSpeciesClassCode());
|
||||
List<SpeciesClassifyLibraryRespVO> collect = stringStringMap.entrySet().stream().map(e -> new SpeciesClassifyLibraryRespVO(e.getKey(), e.getValue())).collect(Collectors.toList());
|
||||
child.setChildren(collect);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return rootList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<FarmingTypeMaintenanceDO> getFarmingTypeMaintenancePage(FarmingTypeMaintenancePageReqVO reqVO) {
|
||||
|
||||
@@ -268,9 +389,4 @@ public class SysDictServiceImpl implements SysDictService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user