diff --git a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/IndexServiceImpl.java b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/IndexServiceImpl.java index 49b78e6..3a43c42 100644 --- a/bocloud.sms.service/src/main/java/com/bocloud/sms/service/IndexServiceImpl.java +++ b/bocloud.sms.service/src/main/java/com/bocloud/sms/service/IndexServiceImpl.java @@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bocloud.sms.entity.User; +import com.bocloud.sms.enums.WarnInfo; import com.bocloud.sms.enums.YkInfo; import com.bocloud.sms.interfaces.IndexService; import com.bocloud.sms.repository.UserRepository; +import com.bocloud.sms.utils.WarnUtil; import com.bocloud.sms.utils.YkUtil; import com.megatron.common.model.GeneralResult; import com.megatron.common.model.Pager; @@ -28,6 +30,8 @@ public class IndexServiceImpl implements IndexService { private YkUtil ykUtil; @Autowired private UserRepository userRepository; + @Autowired + private WarnUtil warnUtil; @Override public GeneralResult doneWorkOrder(Pager pager, RequestContext requestContext) { @@ -91,29 +95,19 @@ public class IndexServiceImpl implements IndexService { @Override public GeneralResult userDataStatic(RequestContext requestContext) { try { - Map resultMap = new HashMap<>(); - //查询当前用户授权应用 - List userAppList = getUserAppList(requestContext); - resultMap.put("userAppCount", userAppList.size()); - - - //获取运维任务申请表 - JSONObject taskJson = getTaskList(requestContext); - Integer total = taskJson.getInteger("total"); - resultMap.put("taskCount", total); - - //获取用户数据权限申请数量 JSONObject userParam = new JSONObject(); userParam.put("userId", "1111"); - String userDataAuthStr = ykUtil.call(YkInfo.getUserDataAuth, userParam, JSONArray.class); + String userDataAuthStr = ykUtil.call(YkInfo.getCountTaskByUser, userParam, JSONArray.class); List userDataJAuthJson = JSONObject.parseObject(userDataAuthStr, List.class); List authResList = JSONObject.parseObject(userDataJAuthJson.get(0).getString("authRes"),List.class); - resultMap.put("userAuthList", authResList.size()); - log.info("resultMap:{}", JSON.toJSONString(resultMap)); + String result = warnUtil.call(WarnInfo.get1DayWarnCount.getUrl(), "GET"); + log.info("result:"+result); - return new GeneralResult(true, resultMap, "查询成功"); +// log.info("resultMap:{}", JSON.toJSONString(resultMap)); + + return new GeneralResult(true, "查询成功"); } catch (Exception e) { log.info("查询失败", e); return new GeneralResult(false, "查询失败"); diff --git a/bocloud.sms.storage/src/main/java/com/bocloud/sms/enums/WarnInfo.java b/bocloud.sms.storage/src/main/java/com/bocloud/sms/enums/WarnInfo.java new file mode 100644 index 0000000..2d3a7f8 --- /dev/null +++ b/bocloud.sms.storage/src/main/java/com/bocloud/sms/enums/WarnInfo.java @@ -0,0 +1,19 @@ +package com.bocloud.sms.enums; + +public enum WarnInfo { + + //单日告警统计 + get1DayWarnCount("/alistar/api/v1/alarm/current/statistics/7d"), + //近7日告警趋势统计 + get7DayWarnTrend("/alistar/api/v1/alarm/current/today/all"); + + private String url; + + WarnInfo(String url) { + this.url = url; + } + + public String getUrl() { + return url; + } +} diff --git a/bocloud.sms.storage/src/main/java/com/bocloud/sms/enums/YkInfo.java b/bocloud.sms.storage/src/main/java/com/bocloud/sms/enums/YkInfo.java index bf5936e..b21507a 100644 --- a/bocloud.sms.storage/src/main/java/com/bocloud/sms/enums/YkInfo.java +++ b/bocloud.sms.storage/src/main/java/com/bocloud/sms/enums/YkInfo.java @@ -13,6 +13,8 @@ public enum YkInfo { getAllAppList("/system/sysapp/getAppList"), //获取用户角色信息 getUserRoles("/system/user/queryUserRoles"), + //数据展示 + getCountTaskByUser("/system/task/countTaskByUser"), //用户数据权限信息查询接口 getUserDataAuth("/system/user/queryUserAuthres"), diff --git a/bocloud.sms.storage/src/main/java/com/bocloud/sms/utils/WarnUtil.java b/bocloud.sms.storage/src/main/java/com/bocloud/sms/utils/WarnUtil.java new file mode 100644 index 0000000..c0ecaca --- /dev/null +++ b/bocloud.sms.storage/src/main/java/com/bocloud/sms/utils/WarnUtil.java @@ -0,0 +1,58 @@ +package com.bocloud.sms.utils; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Base64; + +@Component +@Slf4j +public class WarnUtil { + + @Value("${warn.url:127.0.0.1:1234}") + private String url; + @Value("${warn.user:alistar}") + private String user; + @Value("${warn.password:alistarapi123}") + private String password; + + + public String call(String urlSuffix, String method) throws Exception { + URL obj = new URL(url + urlSuffix); + HttpURLConnection connection = (HttpURLConnection) obj.openConnection(); + + // 设置请求方法 + connection.setRequestMethod(method); + + // 添加Basic Auth鉴权头 + String auth = user + ":" + password; + String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes()); + String authHeaderValue = "Basic " + encodedAuth; + connection.setRequestProperty("Authorization", authHeaderValue); + + // 发起请求并获取响应码 + int responseCode = connection.getResponseCode(); + log.info("Response Code: " + responseCode); + + + // 读取响应数据 + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + StringBuilder response = new StringBuilder(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + // 输出响应 + log.info("Response: " + response.toString()); + return response.toString(); + + } +}