From a7de7fa61ac14073db983f174555d3bc93de68d0 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Tue, 21 Jun 2022 14:44:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E8=AE=BE=E6=96=BD=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/CensusControllerV2.java | 98 +++++++++++++++++++ .../TsingtaoXHAVideoPreviewService.java | 8 +- 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java b/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java index 6ef03b50..dcbe6ea6 100644 --- a/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java +++ b/renren-admin/src/main/java/io/renren/common/controller/CensusControllerV2.java @@ -1,10 +1,13 @@ package io.renren.common.controller; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.renren.common.annotation.LogOperation; +import io.renren.common.constant.Constant; +import io.renren.common.domain.Tsingtao_xhaProperties; import io.renren.common.utils.Result; import io.renren.modules.processForm.service.TAbilityApplicationService; import io.renren.modules.resource.service.ResourceService; @@ -14,6 +17,9 @@ import io.renren.modules.sys.service.SysDeptService; import io.renren.modules.sys.service.SysUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,6 +40,8 @@ import java.util.stream.Collectors; @RestController @RequestMapping("/census/center/v2") public class CensusControllerV2 { + @Value("${project.place}") + private Integer projectPlace; private static final Logger logger = LoggerFactory.getLogger(CensusControllerV2.class); @Autowired @@ -49,6 +57,8 @@ public class CensusControllerV2 { @Autowired private JdbcTemplate jdbcTemplate; + @Autowired + private Tsingtao_xhaProperties tsingtao_xhaProperties; @Value("${census.type}") private String[] censusTypes; // 需要进行统计的资源类型 @@ -297,4 +307,92 @@ public class CensusControllerV2 { return new Result().ok(resourceService.componentServiceRank(type)); } + @GetMapping("/infrastructureInfo") + @ApiOperation("基础设施简况") + @LogOperation("基础设施简况") + public Result>> infrastructureInfo() { + List> result = new CopyOnWriteArrayList<>(); + CompletableFuture allAmount = null; + switch (Constant.ProjectPlace.getByFlag(projectPlace)) { + case BAOTOU: { // 包头 + allAmount = CompletableFuture.supplyAsync(() -> { // 获取平台总基础设施数目 + return jdbcTemplate.queryForObject("SELECT COUNT(id) FROM tb_data_resource WHERE type = '基础设施' AND del_flag = 0", Long.class); + }).thenAccept(sum -> { + result.add(new HashMap() { + { + put("amount", sum); + put("type", "视频资源数量"); + } + }); + }); + } + break; + case TSINGTAO: { // 青岛大数据局 + allAmount = CompletableFuture.supplyAsync(() -> { // 获取平台总基础设施数目 + return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM t_camera;", Long.class); + }).thenAccept(sum -> { + result.add(new HashMap() { + { + put("amount", sum); + put("type", "视频资源数量"); + } + }); + }); + } + break; + case TSINGTAO_XHA: { // 青岛西海岸 + allAmount = CompletableFuture.supplyAsync(() -> { // 获取平台总基础设施数目 + List result_ = new CopyOnWriteArrayList<>(); + CompletableFuture cloud = + CompletableFuture.runAsync(() -> { // 云脑专网 + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder().url(tsingtao_xhaProperties.getCloudcam()).build(); + try (Response response = client.newCall(request).execute()) { + if (response.isSuccessful()) { + JSONObject jsonObject = JSON.parseObject(response.body().string()); + if (jsonObject.containsKey("data")) { + result_.add(jsonObject.getJSONObject("data").getLongValue("total")); + } + } else { + logger.error("包头获取失败"); + } + } catch (Exception exception) { + logger.error("包头失败", exception); + } + }); + CompletableFuture local = + CompletableFuture.runAsync(() -> { // 金宏网 + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder().url(tsingtao_xhaProperties.getLocalcam()).build(); + try (Response response = client.newCall(request).execute()) { + if (response.isSuccessful()) { + JSONObject jsonObject = JSON.parseObject(response.body().string()); + if (jsonObject.containsKey("data")) { + result_.add(jsonObject.getJSONObject("data").getLongValue("total")); + } + } else { + logger.error("包头获取失败"); + } + } catch (Exception exception) { + logger.error("包头失败", exception); + } + }); + CompletableFuture.allOf(cloud, local); + return result_.stream().filter(index -> index != null).findAny().orElse(0l); + }).thenAccept(sum -> { + result.add(new HashMap() { + { + put("amount", sum); + put("type", "视频资源数量"); + } + }); + }); + } + break; + } + CompletableFuture all = CompletableFuture.allOf(allAmount); + all.join(); + return new Result().ok(result); + } + } diff --git a/renren-admin/src/main/java/io/renren/modules/resource/videoPreview/domain/TsingtaoXHAVideoPreviewService.java b/renren-admin/src/main/java/io/renren/modules/resource/videoPreview/domain/TsingtaoXHAVideoPreviewService.java index 41441d00..bb6b68fe 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/videoPreview/domain/TsingtaoXHAVideoPreviewService.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/videoPreview/domain/TsingtaoXHAVideoPreviewService.java @@ -47,10 +47,10 @@ public class TsingtaoXHAVideoPreviewService extends AbstractVideoPreviewService result.add(jsonObject.getString("data")); } } else { - logger.error("包头预览地址获取失败"); + logger.error("西海岸预览地址获取失败"); } } catch (Exception exception) { - logger.error("包头预览地址获取失败", exception); + logger.error("西海岸预览地址获取失败", exception); } }); CompletableFuture local = @@ -64,10 +64,10 @@ public class TsingtaoXHAVideoPreviewService extends AbstractVideoPreviewService result.add(jsonObject.getString("data")); } } else { - logger.error("包头预览地址获取失败"); + logger.error("西海岸预览地址获取失败"); } } catch (Exception exception) { - logger.error("包头预览地址获取失败", exception); + logger.error("西海案预览地址获取失败", exception); } }); CompletableFuture.allOf(cloud, local);