From 8f03a0b54d4972a26c9b6c16f84aef0c78b68b5f Mon Sep 17 00:00:00 2001 From: wangliwen Date: Wed, 4 Jan 2023 17:42:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E3=80=81=E5=B8=82=20=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E4=B8=8A=E6=9E=B6=E3=80=81=E7=94=B3=E8=AF=B7=20?= =?UTF-8?q?=E7=8E=AF=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/CensusController.java | 178 +++++++++++++++++- .../impl/SysDateSnapshotServiceImpl.java | 2 +- .../service/impl/ResourceServiceImpl.java | 6 +- .../src/main/resources/application-dev.yml | 11 +- .../date_snapshot/SysDateSnapshotDao.xml | 2 +- 5 files changed, 191 insertions(+), 8 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/common/controller/CensusController.java b/renren-admin/src/main/java/io/renren/common/controller/CensusController.java index af6a57d4..41514fee 100644 --- a/renren-admin/src/main/java/io/renren/common/controller/CensusController.java +++ b/renren-admin/src/main/java/io/renren/common/controller/CensusController.java @@ -8,6 +8,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.renren.common.annotation.LogOperation; import io.renren.common.constant.Constant; import io.renren.common.utils.Result; +import io.renren.modules.date_snapshot.dto.SysDateSnapshotDTO; +import io.renren.modules.date_snapshot.entity.SnapshotType; import io.renren.modules.date_snapshot.service.SysDateSnapshotService; import io.renren.modules.processForm.service.TAbilityApplicationService; import io.renren.modules.resource.dao.ResourceDao; @@ -647,7 +649,66 @@ public class CensusController { @LogOperation("资源数量环比") @ApiImplicitParams({}) public Result similitude() { - return new Result(); + long countApply = tAbilityApplicationService.countApplyAll(); // 资源申请量 + HashMap resultMap = (HashMap) resourceService.selectTotal(); + List> snapshot_now = new ArrayList>() {{ + add(new LinkedHashMap() {{ + put("count", countApply); + put("type", "资源申请量"); + }}); + try { + if (resultMap.containsKey("total")) { + addAll((Collection>) resultMap.get("total")); + } + } catch (Exception exception) { + logger.error("获取资源数量失败", exception); + } + }}; // 当前数据信息 + final List needType = new ArrayList() {{ + add("组件服务"); + add("应用资源"); + add("数据资源"); + add("基础设施"); + }}; + SysDateSnapshotDTO data_weekly = sysDateSnapshotService.selectForFlag(SnapshotType.DATA_WEEKLY.getFlag()); // 最近的周快照 + SysDateSnapshotDTO data_month = sysDateSnapshotService.selectForFlag(SnapshotType.DATA_MONTH.getFlag()); // 最近的周快照 + List> result = snapshot_now.stream().filter(index -> needType.contains(index.get("type").toString())).map(index -> { + String typeTemp = index.get("type").toString(); + Map temp = new LinkedHashMap<>(); + temp.put("type", typeTemp); + temp.put("count", Integer.valueOf(index.get("count").toString())); + if (data_weekly != null) { + Optional> t_weekly = data_weekly.getSnapshot().stream().filter(t -> typeTemp.equals(t.get("type"))).findFirst();// 周环比 + if (t_weekly.isPresent()) { + temp.put("weekly_change", Integer.valueOf(index.get("count").toString()) - Integer.valueOf(t_weekly.get().get("count").toString())); + } else { + temp.put("weekly_change", Integer.valueOf(index.get("count").toString())); + } + } else { + temp.put("weekly_change", Integer.valueOf(index.get("count").toString())); + } + if (data_month != null) { + Optional> t_month = data_month.getSnapshot().stream().filter(t -> typeTemp.equals(t.get("type"))).findFirst(); // 月环比 + if (t_month.isPresent()) { + temp.put("month_change", Integer.valueOf(index.get("count").toString()) - Integer.valueOf(t_month.get().get("count").toString())); + } else { + temp.put("month_change", Integer.valueOf(index.get("count").toString())); + } + } else { + temp.put("month_change", Integer.valueOf(index.get("count").toString())); + } + return temp; + }).collect(Collectors.toList()); + Integer sum = result.stream().mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); + Integer weekly_change = result.stream().mapToInt(index -> Integer.valueOf(index.get("weekly_change").toString())).sum(); + Integer month_change = result.stream().mapToInt(index -> Integer.valueOf(index.get("month_change").toString())).sum(); + result.add(new LinkedHashMap() {{ + put("type", "四大类资源"); + put("count", sum); + put("weekly_change", weekly_change); + put("month_change", month_change); + }}); + return new Result().ok(result); } @GetMapping("/similitude_dept") @@ -655,7 +716,120 @@ public class CensusController { @LogOperation("部门资源数量环比") @ApiImplicitParams({}) public Result similitudeDept() { - return new Result(); + List> resultList1 = (List>) resourceService.selectApplyDeptDetailTypeCountList(new HashMap() {{ + put("snapshot", true); + }}); // 能力申请统计原始数据 + + List> resultList2 = (List>) resourceService.selectDeptDetailTypeCountList(new HashMap() {{ + put("snapshot", true); + }}); // 能力上架统计原始数据 + + Integer county_apply_sum = resultList1.stream().filter(index -> index.containsKey("level") && "county".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 区申请总量 + Integer county_resource_sum = resultList2.stream().filter(index -> index.containsKey("level") && "county".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 区上架总量 + + Integer municipal_apply_sum = resultList1.stream().filter(index -> index.containsKey("level") && "municipal".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 市申请总量 + Integer municipal_resource_sum = resultList2.stream().filter(index -> index.containsKey("level") && "municipal".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 市上架总量 + + Integer county_resource_weekly_change = 0; + Integer county_resource_month_change = 0; + + Integer municipal_resource_weekly_change = 0; + Integer municipal_resource_month_change = 0; + + SysDateSnapshotDTO resource_weekly = sysDateSnapshotService.selectForFlag(SnapshotType.RESOURCE_WEEKLY.getFlag()); // 最近的上架周快照 + SysDateSnapshotDTO resource_month = sysDateSnapshotService.selectForFlag(SnapshotType.RESOURCE_MONTH.getFlag()); // 最近的上架月快照 + if (resource_weekly != null) { + int temp = resource_weekly.getSnapshot().stream().filter(index -> index.containsKey("level") && "county".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 区上架总量 + county_resource_weekly_change = county_resource_sum - temp; + temp = resource_weekly.getSnapshot().stream().filter(index -> index.containsKey("level") && "municipal".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 市上架总量 + municipal_resource_weekly_change = municipal_resource_sum - temp; + } else { + county_resource_weekly_change = county_resource_sum; + municipal_resource_weekly_change = municipal_resource_sum; + } + if (resource_month != null) { + int temp = resource_month.getSnapshot().stream().filter(index -> index.containsKey("level") && "county".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 区上架总量 + county_resource_month_change = county_resource_sum - temp; + + temp = resource_month.getSnapshot().stream().filter(index -> index.containsKey("level") && "municipal".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 市上架总量 + municipal_resource_month_change = municipal_resource_sum - temp; + } else { + county_resource_month_change = county_resource_sum; + municipal_resource_month_change = municipal_resource_sum; + } + + SysDateSnapshotDTO apply_weekly = sysDateSnapshotService.selectForFlag(SnapshotType.APPLY_WEEKLY.getFlag()); // 最近的申请周快照 + SysDateSnapshotDTO apply_month = sysDateSnapshotService.selectForFlag(SnapshotType.APPLY_MONTH.getFlag()); // 最近的申请月快照 + + Integer county_apply_weekly_change = 0; + Integer county_apply_month_change = 0; + + Integer municipal_apply_weekly_change = 0; + Integer municipal_apply_month_change = 0; + + if (apply_weekly != null) { + int temp = apply_weekly.getSnapshot().stream().filter(index -> index.containsKey("level") && "county".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 区申请总量 + county_apply_weekly_change = county_apply_sum - temp; + + temp = apply_weekly.getSnapshot().stream().filter(index -> index.containsKey("level") && "municipal".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 市申请总量 + municipal_apply_weekly_change = municipal_apply_sum - temp; + } else { + county_apply_weekly_change = county_apply_sum; + municipal_apply_weekly_change = municipal_apply_sum; + } + + if (apply_month != null) { + int temp = apply_month.getSnapshot().stream().filter(index -> index.containsKey("level") && "county".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 区申请总量 + county_apply_month_change = county_apply_sum - temp; + + temp = apply_month.getSnapshot().stream().filter(index -> index.containsKey("level") && "municipal".equals(index.get("level").toString())) + .mapToInt(index -> Integer.valueOf(index.get("count").toString())).sum(); // 市申请总量 + municipal_apply_month_change = municipal_apply_sum - temp; + } else { + county_apply_month_change = county_apply_sum; + municipal_apply_month_change = municipal_apply_sum; + } + + Integer finalCounty_resource_weekly_change = county_resource_weekly_change; + Integer finalCounty_resource_month_change = county_resource_month_change; + Integer finalMunicipal_resource_weekly_change = municipal_resource_weekly_change; + Integer finalMunicipal_resource_month_change = municipal_resource_month_change; + Integer finalCounty_apply_weekly_change = county_apply_weekly_change; + Integer finalMunicipal_apply_weekly_change = municipal_apply_weekly_change; + Integer finalMunicipal_apply_month_change = municipal_apply_month_change; + Integer finalCounty_apply_month_change = county_apply_month_change; + List> result = new ArrayList>() {{ + add(new LinkedHashMap() {{ + put("level", "county"); + put("apply_sum", county_apply_sum); + put("resource_sum", county_resource_sum); + put("resource_weekly_change", finalCounty_resource_weekly_change); + put("resource_month_change", finalCounty_resource_month_change); + put("apply_weekly_change", finalCounty_apply_weekly_change); + put("apply_month_change", finalCounty_apply_month_change); + }}); + add(new LinkedHashMap() {{ + put("level", "municipal"); + put("apply_sum", municipal_apply_sum); + put("resource_sum", municipal_resource_sum); + put("resource_weekly_change", finalMunicipal_resource_weekly_change); + put("resource_month_change", finalMunicipal_resource_month_change); + put("apply_weekly_change", finalMunicipal_apply_weekly_change); + put("apply_month_change", finalMunicipal_apply_month_change); + }}); + }}; + return new Result().ok(result); } } diff --git a/renren-admin/src/main/java/io/renren/modules/date_snapshot/service/impl/SysDateSnapshotServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/date_snapshot/service/impl/SysDateSnapshotServiceImpl.java index 9b395b81..4fcd921d 100644 --- a/renren-admin/src/main/java/io/renren/modules/date_snapshot/service/impl/SysDateSnapshotServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/date_snapshot/service/impl/SysDateSnapshotServiceImpl.java @@ -77,7 +77,7 @@ public class SysDateSnapshotServiceImpl extends CrudServiceImpl> resultList = (List>) resourceService.selectApplyDeptDetailTypeCountList(new HashMap() {{ put("snapshot", true); - }}); // 能力上架统计原始数据 + }}); // 能力申请统计原始数据 List> snapshot = new ArrayList>() {{ addAll(resultList); }}; diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index b3f4a83d..2c8a4303 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -2745,8 +2745,8 @@ public class ResourceServiceImpl extends CrudServiceImpl countMap = new HashMap<>(); resultList = resultList.stream().map(index -> { - index.put("level", "municipal"); // 市级别 if (typeCountListMap.keySet().contains(index.get("dept_id").toString())) { // 该部门存在上架信息 + index.put("level", "municipal"); // 市级别 index.put("count", typeCountListMap.get(index.get("dept_id").toString()).stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); typeCountListMap.get(index.get("dept_id").toString()).stream().forEach(count -> { index.put(count.get("type").toString(), count.get("count")); @@ -2763,8 +2763,8 @@ public class ResourceServiceImpl extends CrudServiceImpl index.get("deptType").toString().equals("3")) .collect(Collectors.groupingBy(m -> m.get("district").toString())); resultList = resultList.stream().map(index -> { - index.put("level", "county"); // 区县级别 if (typeCountListMap1.keySet().contains(index.get("dept_id").toString())) { // 该部门存在上架信息 + index.put("level", "county"); // 区县级别 index.put("count", typeCountListMap1.get(index.get("dept_id").toString()).stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); typeCountListMap1.get(index.get("dept_id").toString()).stream().forEach(count -> { index.put(count.get("type").toString(), Integer.parseInt(count.get("count").toString()) + Integer.parseInt(index.getOrDefault(count.get("type").toString(), "0").toString())); @@ -2781,8 +2781,8 @@ public class ResourceServiceImpl extends CrudServiceImpl index.get("deptType").toString().equals("4")) .collect(Collectors.groupingBy(m -> m.get("dept_id").toString())); resultList = resultList.stream().map(index -> { - index.put("level", "other"); // 企业级别 if (typeCountListMap2.keySet().contains(index.get("dept_id").toString())) { // 该部门存在上架信息 + index.put("level", "other"); // 企业级别 index.put("count", typeCountListMap2.get(index.get("dept_id").toString()).stream().mapToInt(it -> Integer.parseInt(it.get("count").toString())).sum()); typeCountListMap2.get(index.get("dept_id").toString()).stream().forEach(count -> { index.put(count.get("type").toString(), Integer.parseInt(count.get("count").toString()) + Integer.parseInt(index.getOrDefault(count.get("type").toString(), "0").toString())); diff --git a/renren-admin/src/main/resources/application-dev.yml b/renren-admin/src/main/resources/application-dev.yml index c1fe0803..93c1b934 100644 --- a/renren-admin/src/main/resources/application-dev.yml +++ b/renren-admin/src/main/resources/application-dev.yml @@ -111,4 +111,13 @@ synchro: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://15.2.21.238:3310/share_platform?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&useSSL=false username: root - password: Hisense2019 \ No newline at end of file + password: Hisense2019 + +# 是否统计云资源 +cloud: + enable: false + +# 全局RestTemplate配置 +rest_template: + read_timeout: 150 + connect_timeout: 30 \ No newline at end of file diff --git a/renren-admin/src/main/resources/mapper/date_snapshot/SysDateSnapshotDao.xml b/renren-admin/src/main/resources/mapper/date_snapshot/SysDateSnapshotDao.xml index ae9ebdff..182d6adf 100644 --- a/renren-admin/src/main/resources/mapper/date_snapshot/SysDateSnapshotDao.xml +++ b/renren-admin/src/main/resources/mapper/date_snapshot/SysDateSnapshotDao.xml @@ -21,7 +21,7 @@ typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/> - SELECT * FROM