基础设施统计接口
This commit is contained in:
parent
1b320e74e4
commit
a7de7fa61a
|
@ -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<List<Map<String, Object>>> infrastructureInfo() {
|
||||
List<Map<String, Object>> result = new CopyOnWriteArrayList<>();
|
||||
CompletableFuture<Void> 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<String, Object>() {
|
||||
{
|
||||
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<String, Object>() {
|
||||
{
|
||||
put("amount", sum);
|
||||
put("type", "视频资源数量");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
break;
|
||||
case TSINGTAO_XHA: { // 青岛西海岸
|
||||
allAmount = CompletableFuture.supplyAsync(() -> { // 获取平台总基础设施数目
|
||||
List<Long> 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<String, Object>() {
|
||||
{
|
||||
put("amount", sum);
|
||||
put("type", "视频资源数量");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
CompletableFuture<Void> all = CompletableFuture.allOf(allAmount);
|
||||
all.join();
|
||||
return new Result().ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue