123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- package com.persagy.apm.diagnose.service;
- import java.util.*;
- import com.alibaba.excel.util.CollectionUtils;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.persagy.apm.diagnose.constant.EnumDataTimeType;
- import com.persagy.apm.diagnose.feign.client.CenterMiddlewareClient;
- import com.persagy.apm.diagnose.service.dto.ObjRelationDataDTO;
- import com.persagy.apm.diagnose.service.dto.TimeDataDTO;
- import com.persagy.apm.diagnose.utils.DataUtils;
- import com.persagy.apm.diagnose.utils.DateUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.util.StringUtils;
- @Service
- @Slf4j
- public class CenterDataService{
- @Value(value = "${energy.eq.run.system.code}")
- private String systemCode;
- private static String SUCCESS = "success";
- @Autowired
- private CenterMiddlewareClient centerMiddlewareClient;
- public JSONArray queryObjListByObjType(String projectId, List<String> classCodeList) throws Exception {
- JSONArray resultArray = new JSONArray();
- Map<String, Object> requestMap = new HashMap<>();
- try {
- requestMap.put("projectId", projectId);
- requestMap.put("groupCode", systemCode);
- Map<String, Object> criteria = new HashMap<>();
- criteria.put("classCode", classCodeList);
- criteria.put("valid", 1);
- requestMap.put("criteria", criteria);
- String result = centerMiddlewareClient.queryObject(requestMap);
- resultArray = handleDataResult(result);
- } catch (Exception e) {
- log.error("获取类型对象列表数据错误,错误原因:" + e);
- log.error("查询数据中台queryObject参数:" + requestMap);
- throw e;
- }
- return resultArray;
- }
- private JSONArray handleDataResult(String result) throws Exception {
- if (org.springframework.util.StringUtils.isEmpty(result)) {
- throw new Exception("查询数据中台报错,无返回值");
- }
- JSONObject parseJsonObject = JSONObject.parseObject(result);
- if (null != parseJsonObject && !parseJsonObject.isEmpty()
- && SUCCESS.equals(parseJsonObject.getString("result"))) {
- if (parseJsonObject.getJSONArray("data") != null) {
- return parseJsonObject.getJSONArray("data");
- } else {
- return new JSONArray();
- }
- } else {
- throw new Exception("查询数据中台报错:");
- }
- }
- public List<JSONObject> queryObjListByObjId(String projectId, List<String> objIdList) throws Exception {
- List<JSONObject> list = new ArrayList<>();
- Map<String, Object> requestMap = new HashMap<>();
- try {
- requestMap.put("projectId", projectId);
- Map<String, Object> criteria = new HashMap<>();
- criteria.put("id", objIdList);
- criteria.put("valid", 1);
- requestMap.put("criteria", criteria);
- requestMap.put("groupCode", systemCode);
- String result = centerMiddlewareClient.queryObject(requestMap);
- JSONArray jsonArray = handleDataResult(result);
- List<JSONObject> jsonToList = JSON.parseArray(jsonArray.toJSONString(), JSONObject.class);
- if (!CollectionUtils.isEmpty(jsonToList)) {
- list.addAll(jsonToList);
- }
- } catch (Exception e) {
- log.error("获取对象列表数据错误,错误原因:" + e);
- log.error("查询数据中台queryObject参数:" + requestMap);
- throw e;
- }
- return list;
- }
- public List<TimeDataDTO> queryObjTimeDataList(String projectId, String objId, String infoCode, Date startTime,
- Date endTime, EnumDataTimeType dataTimeType) throws Exception {
- List<TimeDataDTO> list = new ArrayList<>();
- Map<String, Object> requestMap = new HashMap<>();
- try {
- requestMap.put("projectId", projectId);
- requestMap.put("groupCode", systemCode);
- Map<String, Object> criteria = new HashMap<>();
- criteria.put("period", dataTimeType.getCode());
- criteria.put("interpolation", false);
- criteria.put("code", infoCode);
- criteria.put("id", objId);
- Map<String, Object> receivetimeMap = new HashMap<>();
- receivetimeMap.put("$gte", DateUtils.date2Str(startTime, DateUtils.SDFSECOND));
- receivetimeMap.put("$lt", DateUtils.date2Str(endTime, DateUtils.SDFSECOND));
- criteria.put("receivetime", receivetimeMap);
- requestMap.put("criteria", criteria);
- String result = centerMiddlewareClient.queryPeriodData(requestMap);
- if (null != result) {
- JSONObject responseMap = JSONObject.parseObject(result);
- if (null != responseMap && !responseMap.isEmpty() && SUCCESS.equals(responseMap.get("Result"))) {
- List<Map> contentList = (List<Map>) responseMap.get("Content");
- if (CollectionUtils.isEmpty(contentList)) {
- return list;
- }
- for (Map map : contentList) {
- String data_time = (String) map.get("data_time");
- if (null == data_time || "".equals(data_time)) {
- continue;
- }
- TimeDataDTO dto = new TimeDataDTO();
- dto.setTime(data_time);
- dto.setData(DataUtils.parseDouble(map.get("data_value")));
- list.add(dto);
- }
- }
- }
- } catch (Exception e) {
- log.error("获取分精度数据错误,错误原因:" + e);
- log.error("查询数据中台queryObject参数:" + requestMap);
- throw e;
- }
- return list;
- }
- public List<JSONObject> queryObjRelationList(ObjRelationDataDTO dto) throws Exception {
- List<JSONObject> list = new ArrayList<>();
- if (null == dto || StringUtils.isEmpty(dto.getGraphCode()) || StringUtils.isEmpty(dto.getRelCode())
- || (StringUtils.isEmpty(dto.getObjFrom()) && StringUtils.isEmpty(dto.getObjTo()))) {
- return list;
- }
- Map<String, Object> requestMap = new HashMap<>();
- try {
- requestMap.put("projectId", dto.getProjectId());
- requestMap.put("groupCode", systemCode);
- Map<String, Object> criteria = new HashMap<>();
- Map<String, Object> relation = new HashMap<>();
- relation.put("graphCode", dto.getGraphCode());
- relation.put("relCode", dto.getRelCode());
- if (!StringUtils.isEmpty(dto.getObjFrom())) {
- relation.put("objFrom", dto.getObjFrom());
- criteria.put("relationTo", relation);
- } else {
- relation.put("objTo", dto.getObjTo());
- criteria.put("relationFrom", relation);
- }
- if (!StringUtils.isEmpty(dto.getClassCode())) {
- criteria.put("classCode", dto.getClassCode());
- }
- requestMap.put("criteria", criteria);
- String result = centerMiddlewareClient.queryObject(requestMap);
- JSONArray jsonArray = handleDataResult(result);
- List<JSONObject> jsonToList = JSON.parseArray(jsonArray.toJSONString(), JSONObject.class);
- if (!CollectionUtils.isEmpty(jsonToList)) {
- list.addAll(jsonToList);
- }
- } catch (Exception e) {
- log.error("获取关系对象数据错误,错误原因:" + e);
- log.error("查询数据中台queryObject参数:" + requestMap);
- throw e;
- }
- return list;
- }
- public JSONArray queryObjListByObjTypeAndName(String projectId, List<String> classCodeList, String keyWords)
- throws Exception {
- JSONArray resultArray = new JSONArray();
- Map<String, Object> requestMap = new HashMap<>();
- try {
- requestMap.put("projectId", projectId);
- requestMap.put("groupCode", systemCode);
- Map<String, Object> criteria = new HashMap<>();
- criteria.put("classCode", classCodeList);
- Map<String, Object> like = new HashMap<>();
- like.put("$like", "%" + keyWords + "%");
- criteria.put("localName", like);
- criteria.put("valid", 1);
- requestMap.put("criteria", criteria);
- String result = centerMiddlewareClient.queryObject(requestMap);
- resultArray = handleDataResult(result);
- } catch (Exception e) {
- log.error("获取类型对象列表数据错误,错误原因:" + e);
- log.error("查询数据中台queryObject参数:" + requestMap);
- throw e;
- }
- return resultArray;
- }
- }
|