|
@@ -0,0 +1,134 @@
|
|
|
+package com.persagy.apm.energy.report.iotdataanalysis.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.persagy.apm.energy.report.common.dto.QueryAreaPlatformParamDTO;
|
|
|
+import com.persagy.apm.energy.report.common.dto.QueryPjPlatformParamDTO;
|
|
|
+import com.persagy.apm.energy.report.common.service.CommonService;
|
|
|
+import com.persagy.apm.energy.report.common.utils.DataUtils;
|
|
|
+import com.persagy.apm.energy.report.common.utils.DateUtils;
|
|
|
+import com.persagy.apm.energy.report.common.utils.HttpUtils;
|
|
|
+import com.persagy.apm.energy.report.iotdataanalysis.service.IDataAnalysisWebService;
|
|
|
+import com.persagy.apm.energy.report.monthly.detail.business.model.Platform;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+@Service
|
|
|
+public class IDataAnalysisWebServiceImpl implements IDataAnalysisWebService {
|
|
|
+
|
|
|
+ @Value("${iot.data.analysis.url}")
|
|
|
+ private String iotDataAnalysisUrl;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CommonService commonService;
|
|
|
+
|
|
|
+ public final static String SUCCESS = "success";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getPjbianSunAndzongZhiRate(QueryPjPlatformParamDTO queryPjPlatformParamDTO, Platform bianSunPlatform, Platform zongZhiPlatform) {
|
|
|
+ TreeMap<Date, Double> biansun_date_rateMap = new TreeMap<>();
|
|
|
+ TreeMap<Date, Double> zongzhi_date_rateMap = new TreeMap<>();
|
|
|
+ Date reportDate = queryPjPlatformParamDTO.getReportDate();
|
|
|
+ Date startDate = DateUtils.getFirstDayOfYear(reportDate);
|
|
|
+ while (startDate.before(DateUtils.getMonthOff(reportDate, 1))) {
|
|
|
+ Double bianSunRate = null;
|
|
|
+ Double zongZhiRate = null;
|
|
|
+ getBianSunAndZongZhiRate(queryPjPlatformParamDTO.getUserId(), queryPjPlatformParamDTO.getGroupCode(), queryPjPlatformParamDTO.getProjectId(), bianSunRate, zongZhiRate, reportDate);
|
|
|
+ biansun_date_rateMap.put(startDate, bianSunRate);
|
|
|
+ zongzhi_date_rateMap.put(startDate, zongZhiRate);
|
|
|
+ startDate = DateUtils.getMonthOff(startDate, 1);
|
|
|
+ }
|
|
|
+ List<Double> bianSunMonthlySummaries = biansun_date_rateMap.values().stream().collect(Collectors.toList());
|
|
|
+ List<Double> zongZhiMonthlySummaries = zongzhi_date_rateMap.values().stream().collect(Collectors.toList());
|
|
|
+ bianSunPlatform.setMonthlySummaries(bianSunMonthlySummaries);
|
|
|
+ zongZhiPlatform.setMonthlySummaries(zongZhiMonthlySummaries);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getBianSunAndZongZhiRate(String userId, String groupCode, String projectId, Double bianSunRate, Double zongZhiRate, Date reportDate) {
|
|
|
+ try {
|
|
|
+ JSONObject paramObject = new JSONObject();
|
|
|
+ paramObject.put("userId", userId);
|
|
|
+ paramObject.put("groupCode", groupCode);
|
|
|
+ List<String> pjIdList = new ArrayList<>();
|
|
|
+ pjIdList.add(projectId);
|
|
|
+ paramObject.put("projectIdList", pjIdList.toString());
|
|
|
+ Date startTime = DateUtils.getStartTimeOfDay(reportDate);
|
|
|
+ Date endTime = DateUtils.getMonthOff(startTime, 1);
|
|
|
+ paramObject.put("alarmStartTime", startTime);
|
|
|
+ paramObject.put("alarmEndTime", endTime);
|
|
|
+ String url = iotDataAnalysisUrl + "/alarm/show/view/queryList";
|
|
|
+ String response = HttpUtils.postJson(url, paramObject.toString());
|
|
|
+ JSONObject responseObject = JSONObject.parseObject(response);
|
|
|
+ if (SUCCESS.equals(responseObject.getString("respMsg"))) {
|
|
|
+ List<Map> content = (List<Map>) responseObject.get("content");
|
|
|
+ if (CollectionUtils.isNotEmpty(content)) {
|
|
|
+ Map data = content.get(0);
|
|
|
+ bianSunRate = DataUtils.parseDouble(data.get("bianSunRate"));
|
|
|
+ zongZhiRate = DataUtils.parseDouble(data.get("zongZhiRate"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getAreabianSunAndzongZhiRate(QueryAreaPlatformParamDTO queryAreaPlatformParamDTO, Platform bianSunPlatform, Platform zongZhiPlatform) {
|
|
|
+ // 变损合格标准
|
|
|
+ Double bianSunStandardValue = bianSunPlatform.getStandardValue();
|
|
|
+ // 变损校验规则
|
|
|
+ String bianSunQualifyFormula = bianSunPlatform.getQualifyFormula();
|
|
|
+ // 变损达标数量
|
|
|
+ Integer bianSunSatisfiedCount = 0;
|
|
|
+ // 变损未达标数量
|
|
|
+ Integer bianSunUnsatisfiedCount = 0;
|
|
|
+ // 变损未达标项目id列表
|
|
|
+ List<String> bianSunUnsatisfiedPjIdList = new ArrayList<>();
|
|
|
+ // 总支不平衡合格标准
|
|
|
+ Double zongZhiStandardValue = bianSunPlatform.getStandardValue();
|
|
|
+ // 总支不平衡校验规则
|
|
|
+ String zongZhiQualifyFormula = bianSunPlatform.getQualifyFormula();
|
|
|
+ // 总支不平衡达标数量
|
|
|
+ Integer zongZhiSatisfiedCount = 0;
|
|
|
+ // 总支不平衡未达标数量
|
|
|
+ Integer zongZhiUnsatisfiedCount = 0;
|
|
|
+ // 总支不平衡未达标项目id列表
|
|
|
+ List<String> zongZhiUnsatisfiedPjIdList = new ArrayList<>();
|
|
|
+ for (String pjId : queryAreaPlatformParamDTO.getProjectIdList()) {
|
|
|
+ Double bianSunRate = null;
|
|
|
+ Double zongZhiRate = null;
|
|
|
+ getBianSunAndZongZhiRate(queryAreaPlatformParamDTO.getUserId(), queryAreaPlatformParamDTO.getGroupCode(), pjId, bianSunRate, zongZhiRate, queryAreaPlatformParamDTO.getReportDate());
|
|
|
+ if (null != bianSunRate && null != bianSunStandardValue) {
|
|
|
+ if (DataUtils.getQualifyResult(bianSunStandardValue, bianSunQualifyFormula, bianSunRate) == 0.0) {
|
|
|
+ bianSunUnsatisfiedCount++;
|
|
|
+ bianSunUnsatisfiedPjIdList.add(pjId);
|
|
|
+ } else {
|
|
|
+ bianSunSatisfiedCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != zongZhiRate && null != zongZhiStandardValue) {
|
|
|
+ if (DataUtils.getQualifyResult(zongZhiStandardValue, zongZhiQualifyFormula, zongZhiRate) == 0.0) {
|
|
|
+ zongZhiUnsatisfiedCount++;
|
|
|
+ zongZhiUnsatisfiedPjIdList.add(pjId);
|
|
|
+ } else {
|
|
|
+ zongZhiSatisfiedCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 根据未达标项目id列表获取不达标项目名称
|
|
|
+ List<String> bianSunPjNameList = commonService.getPjNameByPjId(bianSunUnsatisfiedPjIdList);
|
|
|
+ bianSunPlatform.setSatisfiedCount(bianSunSatisfiedCount);
|
|
|
+ bianSunPlatform.setUnsatisfiedCount(bianSunUnsatisfiedCount);
|
|
|
+ bianSunPlatform.setUnsatisfiedProjects(bianSunPjNameList);
|
|
|
+ // 根据未达标项目id列表获取不达标项目名称
|
|
|
+ List<String> zongZhiPjNameList = commonService.getPjNameByPjId(zongZhiUnsatisfiedPjIdList);
|
|
|
+ zongZhiPlatform.setSatisfiedCount(zongZhiSatisfiedCount);
|
|
|
+ zongZhiPlatform.setUnsatisfiedCount(zongZhiUnsatisfiedCount);
|
|
|
+ zongZhiPlatform.setUnsatisfiedProjects(zongZhiPjNameList);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|