提交 7062b636 作者: zgz

智库语言统计图展示对应中文

上级 43b6db61
...@@ -90,6 +90,12 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf ...@@ -90,6 +90,12 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf
ISysBaseRegionService sysBaseRegionService; ISysBaseRegionService sysBaseRegionService;
@Autowired @Autowired
private ISysDictItemService sysDictItemService;
@Autowired
private ISysDictService sysDictService;
@Autowired
EsUtil esUtil; EsUtil esUtil;
@Resource @Resource
...@@ -790,59 +796,6 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf ...@@ -790,59 +796,6 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf
"(SELECT name_cn from brpa_base_region where id = (SELECT pid from brpa_base_region where id=belong_country_id) ) as continentName", "(SELECT name_cn from brpa_base_region where id = (SELECT pid from brpa_base_region where id=belong_country_id) ) as continentName",
"(SELECT pid from brpa_base_region where id=belong_country_id) as continentId"); "(SELECT pid from brpa_base_region where id=belong_country_id) as continentId");
List<ThinktankBasicInfo> list = this.getBaseMapper().selectPage(page,queryWrapper).getRecords(); List<ThinktankBasicInfo> list = this.getBaseMapper().selectPage(page,queryWrapper).getRecords();
// switch (type) {
// case "continent":
// mapList = list.stream()
// .collect(Collectors.groupingBy(
// ThinktankBasicInfo::getContinentName,
// Collectors.counting() // 计算每个组的数量
// ))
// .entrySet()
// .stream()
// .map(entry -> {
// Map<String, Object> map = new HashMap<>();
// map.put("data", entry.getKey()); // 使用entry.getKey()获取洲ID
// map.put("num", entry.getValue()); // 使用entry.getValue()获取数量
// return map;
// })
// .collect(Collectors.toList()); // 收集结果列表
// break;
// case "country":
// mapList = list.stream()
// .collect(Collectors.groupingBy(
// ThinktankBasicInfo::getBelongCountry,
// Collectors.counting() // 计算每个组的数量
// ))
// .entrySet()
// .stream()
// .map(entry -> {
// Map<String, Object> map = new HashMap<>();
// map.put("data", entry.getKey()); // 使用entry.getKey()获取洲ID
// map.put("num", entry.getValue()); // 使用entry.getValue()获取数量
// return map;
// })
// .collect(Collectors.toList()); // 收集结果列表
// break;
// case "tag":
// mapList = list.stream()
// .filter(info -> StringUtils.isNotBlank(info.getTagName())) // 确保info.getTagName()不为null
// .flatMap(info -> Arrays.stream(info.getTagName().split(","))) // 拆分每个tagName字段
// .map(String::trim) // 去除多余的空格
// .collect(Collectors.groupingBy(
// tag -> tag,
// Collectors.counting() // 计算每个组的数量
// ))
// .entrySet()
// .stream()
// .map(entry -> {
// Map<String, Object> map = new HashMap<>();
// map.put("data", entry.getKey()); // 使用entry.getKey()获取洲名称
// map.put("num", entry.getValue()); // 使用entry.getValue()获取数量
// return map;
// })
// .collect(Collectors.toList()); // 收集结果列表
// break;
// }
switch (type) { switch (type) {
case "continent": case "continent":
mapList = processGrouping(list, ThinktankBasicInfo::getContinentName,false,null);//洲 mapList = processGrouping(list, ThinktankBasicInfo::getContinentName,false,null);//洲
...@@ -854,7 +807,7 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf ...@@ -854,7 +807,7 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf
mapList = processGrouping(list, ThinktankBasicInfo::getTagName, true,",");//领域标签 mapList = processGrouping(list, ThinktankBasicInfo::getTagName, true,",");//领域标签
break; break;
case "lang": case "lang":
mapList = processGrouping(list, ThinktankBasicInfo::getLang, true,",");//语言 mapList = processGroupingByLang(list, ThinktankBasicInfo::getLang, true,",");//语言
break; break;
case "nature": case "nature":
mapList = processGrouping(list, ThinktankBasicInfo::getNature, false,null);//性质 mapList = processGrouping(list, ThinktankBasicInfo::getNature, false,null);//性质
...@@ -891,6 +844,49 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf ...@@ -891,6 +844,49 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
//语言聚合单独处理
private List<Map<String, Object>> processGroupingByLang(List<ThinktankBasicInfo> list, Function<ThinktankBasicInfo, String> classifier, boolean splitTags,String split) {
Stream<String> stream = list.stream().map(classifier)
.filter(item -> item != null && !item.isEmpty()); // 过滤掉null和空字符串
if (splitTags) {
stream = stream.flatMap(info -> Arrays.stream(info.split(split)))
.map(String::trim)
.filter(Objects::nonNull); // 过滤掉null元素;
}
List<Map<String, Object>> listMap = stream.collect(Collectors.groupingBy(
Function.identity(),
Collectors.counting()
)).entrySet().stream()
.map(entry -> createMap(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
QueryWrapper query = new QueryWrapper();
query.eq("dict_code","language");
SysDict sysDict = sysDictService.getOne(query);
if(sysDict!=null){
QueryWrapper queryItem = new QueryWrapper();
queryItem.eq("dict_id",sysDict.getId());
List<SysDictItem> sysDictItemList = sysDictItemService.list(queryItem);
// 创建映射关系
Map<String, String> dataToNameMap = new HashMap<>();
for (SysDictItem item : sysDictItemList) {
dataToNameMap.put(item.getItemValue(), item.getItemText());
}
// 替换list1中的data值为name值
for (Map<String, Object> map : listMap) {
String dataValue = (String) map.get("data");
String nameValue = dataToNameMap.get(dataValue);
if (nameValue != null) {
map.put("data", nameValue);
}
}
}
return listMap;
}
// 创建Map的方法 // 创建Map的方法
private Map<String, Object> createMap(String key, Long value) { private Map<String, Object> createMap(String key, Long value) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论