|
@@ -36,10 +36,8 @@ public class BasicIndicatorBenchmarkingService {
|
|
|
@Autowired
|
|
|
private ImaConfig imaConfig;
|
|
|
|
|
|
-
|
|
|
private List<Data1015Result> list;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取对标数据错误
|
|
|
*
|
|
@@ -161,12 +159,177 @@ public class BasicIndicatorBenchmarkingService {
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取基础指标对标同期数据
|
|
|
+ *
|
|
|
+ * @param body
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map contemporaneousData(JSONObject body, HttpServletRequest request) {
|
|
|
+ Map count = new LinkedHashMap();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
+ headers.add("zb-token", "a1d48f2759e0f311375247eb1f7462cad8e64f8b21654c1a9f02f43b45976ff7");
|
|
|
+ //请求参数为body
|
|
|
+ HttpEntity<String> requestEntity = new HttpEntity<>(body.toString(), headers);
|
|
|
+ ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getZbdbUrl() + "/queryData", HttpMethod.POST, requestEntity, String.class);
|
|
|
+ log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
+ if (200 == responseEntity2.getStatusCodeValue()) {
|
|
|
+ BbkResult result = JSON.parseObject(responseEntity2.getBody()).toJavaObject(BbkResult.class);
|
|
|
+ if (200 == result.getCode()) {
|
|
|
+ List<Data1011Result> list = result.getData();
|
|
|
+ // 填充动态头部分组并保持顺序,然后对每个分组内的元素按 time 降序排序
|
|
|
+ Map<String, List<Data1011Result>> orgCodeSortedByTime = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ data -> data.getOrgCode() + "_" + data.getOrgName(), // 使用orgCode和orgName的组合作为键
|
|
|
+ Collectors.collectingAndThen(
|
|
|
+ Collectors.toList(),
|
|
|
+ l -> list.stream()
|
|
|
+ .sorted(Comparator.comparing(Data1011Result::getTime)) // 按time升序排序
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ )
|
|
|
+ ));
|
|
|
+ //填充标题
|
|
|
+ List<Map> titleArray = new ArrayList<>();
|
|
|
+ final Map[] titletime = {null};
|
|
|
+ orgCodeSortedByTime.forEach((key, results) -> {
|
|
|
+ String[] parts = key.split("_");
|
|
|
+ String orgCode = parts[0];
|
|
|
+ String orgName = parts[1];
|
|
|
+ if (null == titletime[0]) {
|
|
|
+ titletime[0] = new LinkedHashMap();
|
|
|
+ titletime[0].put("name", "频度");//名称
|
|
|
+ titletime[0].put("code", "time");//code
|
|
|
+ titleArray.add(titletime[0]);
|
|
|
+ }
|
|
|
+ Map titleorg = new LinkedHashMap();
|
|
|
+ titleorg.put("name", orgName);//名称
|
|
|
+ titleorg.put("code", orgCode);//code
|
|
|
+ titleArray.add(titleorg);
|
|
|
+ });
|
|
|
+ count.put("title", titleArray);
|
|
|
+ // 填充内容 根据time字段进行分组
|
|
|
+ List<Map> listmap = new ArrayList<>();
|
|
|
+ Map<String, List<Data1011Result>> groupedByTime = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ Data1011Result::getTime, // 分组键是Data1011Result对象的time字段
|
|
|
+ Collectors.toList() // 将每个组的元素收集到列表中
|
|
|
+ ))
|
|
|
+ .entrySet()
|
|
|
+ .stream()
|
|
|
+ .sorted(Map.Entry.comparingByKey()) // 按键(时间)升序排序分组后的Map.Entry
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey, // 新Map的键是原Map.Entry的键
|
|
|
+ Map.Entry::getValue, // 新Map的值是原Map.Entry的值
|
|
|
+ (oldValue, newValue) -> oldValue, // 如果键冲突,保留旧值(理论上不应该发生,因为Map.Entry是唯一的)
|
|
|
+ LinkedHashMap::new // 使用LinkedHashMap来保持插入顺序(这里实际上是排序后的顺序)
|
|
|
+ ));
|
|
|
+ // 组合行
|
|
|
+ groupedByTime.forEach((time, results) -> {
|
|
|
+ Map row = new LinkedHashMap();
|
|
|
+ for (Data1011Result r : results) {
|
|
|
+ if (null == row.get("time")) {
|
|
|
+ row.put("time", r.getTime());
|
|
|
+ count.put("itemName", r.getItemName());
|
|
|
+ }
|
|
|
+ row.put(r.getOrgCode(), r.getValue());
|
|
|
+ }
|
|
|
+ listmap.add(row);
|
|
|
+ });
|
|
|
+ count.put("list", listmap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取基础指标对标上期数据
|
|
|
+ *
|
|
|
+ * @param body
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map previousPeriodData(JSONObject body, HttpServletRequest request) {
|
|
|
+ Map count = new LinkedHashMap();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
+ headers.add("zb-token", "a1d48f2759e0f311375247eb1f7462cad8e64f8b21654c1a9f02f43b45976ff7");
|
|
|
+ //请求参数为body
|
|
|
+ HttpEntity<String> requestEntity = new HttpEntity<>(body.toString(), headers);
|
|
|
+ ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getZbdbUrl() + "/queryData", HttpMethod.POST, requestEntity, String.class);
|
|
|
+ log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
+ if (200 == responseEntity2.getStatusCodeValue()) {
|
|
|
+ BbkResult result = JSON.parseObject(responseEntity2.getBody()).toJavaObject(BbkResult.class);
|
|
|
+ if (200 == result.getCode()) {
|
|
|
+ List<Data1011Result> list = result.getData();
|
|
|
+ // 填充动态头部分组并保持顺序,然后对每个分组内的元素按 time 降序排序
|
|
|
+ Map<String, List<Data1011Result>> orgCodeSortedByTime = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ data -> data.getOrgCode() + "_" + data.getOrgName(), // 使用orgCode和orgName的组合作为键
|
|
|
+ Collectors.collectingAndThen(
|
|
|
+ Collectors.toList(),
|
|
|
+ l -> list.stream()
|
|
|
+ .sorted(Comparator.comparing(Data1011Result::getTime)) // 按time升序排序
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ )
|
|
|
+ ));
|
|
|
+ //填充标题
|
|
|
+ List<Map> titleArray = new ArrayList<>();
|
|
|
+ final Map[] titletime = {null};
|
|
|
+ orgCodeSortedByTime.forEach((key, results) -> {
|
|
|
+ String[] parts = key.split("_");
|
|
|
+ String orgCode = parts[0];
|
|
|
+ String orgName = parts[1];
|
|
|
+ if (null == titletime[0]) {
|
|
|
+ titletime[0] = new LinkedHashMap();
|
|
|
+ titletime[0].put("name", "频度");//名称
|
|
|
+ titletime[0].put("code", "time");//code
|
|
|
+ titleArray.add(titletime[0]);
|
|
|
+ }
|
|
|
+ Map titleorg = new LinkedHashMap();
|
|
|
+ titleorg.put("name", orgName);//名称
|
|
|
+ titleorg.put("code", orgCode);//code
|
|
|
+ titleArray.add(titleorg);
|
|
|
+ });
|
|
|
+ count.put("title", titleArray);
|
|
|
+ // 填充内容 根据time字段进行分组
|
|
|
+ List<Map> listmap = new ArrayList<>();
|
|
|
+ Map<String, List<Data1011Result>> groupedByTime = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ Data1011Result::getTime, // 分组键是Data1011Result对象的time字段
|
|
|
+ Collectors.toList() // 将每个组的元素收集到列表中
|
|
|
+ ))
|
|
|
+ .entrySet()
|
|
|
+ .stream()
|
|
|
+ .sorted(Map.Entry.comparingByKey()) // 按键(时间)升序排序分组后的Map.Entry
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey, // 新Map的键是原Map.Entry的键
|
|
|
+ Map.Entry::getValue, // 新Map的值是原Map.Entry的值
|
|
|
+ (oldValue, newValue) -> oldValue, // 如果键冲突,保留旧值(理论上不应该发生,因为Map.Entry是唯一的)
|
|
|
+ LinkedHashMap::new // 使用LinkedHashMap来保持插入顺序(这里实际上是排序后的顺序)
|
|
|
+ ));
|
|
|
+ // 组合行
|
|
|
+ groupedByTime.forEach((time, results) -> {
|
|
|
+ Map row = new LinkedHashMap();
|
|
|
+ for (Data1011Result r : results) {
|
|
|
+ if (null == row.get("time")) {
|
|
|
+ row.put("time", r.getTime());
|
|
|
+ count.put("itemName", r.getItemName());
|
|
|
+ }
|
|
|
+ row.put(r.getOrgCode(), r.getValue());
|
|
|
+ }
|
|
|
+ listmap.add(row);
|
|
|
+ });
|
|
|
+ count.put("list", listmap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
|
|
|
public List<Data1015Result> queryData1015(JSONObject body, HttpServletRequest request) {
|
|
|
|
|
|
|
|
|
- if(null != list && list.size()>0){
|
|
|
- return list;
|
|
|
+ if (null != list && list.size() > 0) {
|
|
|
+ return list;
|
|
|
}
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
@@ -184,7 +347,6 @@ public class BasicIndicatorBenchmarkingService {
|
|
|
Bbk1015Result result = JSON.parseObject(str).toJavaObject(Bbk1015Result.class);*/
|
|
|
|
|
|
|
|
|
-
|
|
|
if (200 == result.getCode()) {
|
|
|
list = result.getData();
|
|
|
|
|
@@ -210,7 +372,6 @@ public class BasicIndicatorBenchmarkingService {
|
|
|
Bbk1015Result resulttree = JSON.parseObject(str1).toJavaObject(Bbk1015Result.class);*/
|
|
|
|
|
|
|
|
|
-
|
|
|
if (200 == result.getCode()) {
|
|
|
List<Data1015Result> listTree = resulttree.getData();
|
|
|
listTree.remove(datalist);
|