提交 264efd1d 作者: zgz

智库区域/国别/领域统计分析(yjzx)

上级 c6d3e6df
......@@ -19,6 +19,7 @@ import org.springframework.web.util.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
......@@ -111,6 +112,19 @@ public class ThinktankBasicInfoController {
return Result.OK(pageList);
}
/**
* 智库区域/国别/领域统计分析(yjzx)
* @param type(continent按洲 country按国家 tag按领域)
*/
@PostMapping("/queryStatisticalAnalysis")
public Result<?> queryStatisticalAnalysis(String type,HttpServletRequest req) throws Exception {
ThinktankBasicInfoListVo vo = new ThinktankBasicInfoListVo();
Page<ThinktankBasicInfo> page = new Page<ThinktankBasicInfo>(1, 999999);
List<Map<String,Object>> mapList = thinktankBasicInfoService.queryStatisticalAnalysis(type,page,vo,req);
return Result.OK(mapList);
}
/**
* 模板下载
* @param response
......
......@@ -78,4 +78,12 @@ public class ThinktankBasicInfo extends Model<ThinktankBasicInfo> {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
//所属洲名称
@TableField(exist = false)
private String continentName;
//所属洲id
@TableField(exist = false)
private String continentId;
}
......@@ -11,6 +11,8 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* @Version 1.0
......@@ -39,4 +41,6 @@ public interface ThinktankBasicInfoService extends IService<ThinktankBasicInfo>
Result<?> getListBaseData(String id, Integer pageNo, Integer pageSize, Integer office);
IPage<ThinktankBasicInfo> pageList(Page page, ThinktankBasicInfoListVo vo, HttpServletRequest req) throws Exception;
List<Map<String,Object>> queryStatisticalAnalysis(String type,Page page, ThinktankBasicInfoListVo vo, HttpServletRequest req);
}
......@@ -806,6 +806,68 @@ public class ThinktankBasicInfoServiceImpl extends ServiceImpl<ThinktankBasicInf
return this.getBaseMapper().selectPage(page,queryWrapper);
}
@Override
public List<Map<String,Object>> queryStatisticalAnalysis(String type,Page page, ThinktankBasicInfoListVo vo, HttpServletRequest req){
List<Map<String,Object>> mapList = new ArrayList<>();
QueryWrapper<ThinktankBasicInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.select("id","code_id","chinese_whole","belong_country_id","belong_country","tag_id","tag_name",
"(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");
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()
.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;
}
return mapList;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论