|
@@ -1,15 +1,34 @@
|
|
|
package com.ebei.screen.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ebei.screen.common.constants.EbaMessageCode;
|
|
|
+import com.ebei.screen.common.constants.EbaSystemConstants;
|
|
|
+import com.ebei.screen.common.response.ResponseBean;
|
|
|
+import com.ebei.screen.common.response.ResponseBuilder;
|
|
|
import com.ebei.screen.common.util.EbaUtils;
|
|
|
+import com.ebei.screen.common.util.Levi;
|
|
|
+import com.ebei.screen.common.util.LeviUtils;
|
|
|
import com.ebei.screen.service.EbaSystemService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
+import org.springframework.data.mongodb.core.query.Update;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* EBA系统大屏
|
|
@@ -25,102 +44,372 @@ public class EbaSystemServiceImpl implements EbaSystemService {
|
|
|
@Autowired
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化数据
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getMobjectList(Long projectId) {
|
|
|
-// List<Map> mobjectList = EbaUtils.getMobjectList(projectId);
|
|
|
- mongoTemplate.dropCollection("mobjectList");
|
|
|
- mongoTemplate.insert("mobjectList", "mobjectList");
|
|
|
+ public void initData() {
|
|
|
+ initToken();
|
|
|
+ initProjectList();
|
|
|
+ initDeviceSystemList();
|
|
|
+ initDeviceTypeList();
|
|
|
+ initDeviceParamList();
|
|
|
+ initDeviceAlarmTypeList();
|
|
|
+ initFireDeviceTypeList();
|
|
|
+ initRealDataDeviceList();
|
|
|
+ initMobjectList();
|
|
|
+ initIotList();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化当前用户名token到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getIotList(Long projectId) {
|
|
|
- List<Map> iotList = EbaUtils.getIotList(projectId);
|
|
|
- mongoTemplate.dropCollection("iotList");
|
|
|
- mongoTemplate.insert(iotList, "iotList");
|
|
|
+ public void initToken() {
|
|
|
+ String str = JSON.toJSONString(Levi.by("clientId", EbaSystemConstants.cliendId).set("clientSecret", EbaSystemConstants.clientSecret));
|
|
|
+ String result = HttpRequest.post(EbaSystemConstants.getTokenInfo)
|
|
|
+ .header("content-type", "application/json")
|
|
|
+ .body(str)
|
|
|
+ .execute().body();
|
|
|
+ String token = LeviUtils.getJsonFieldOne(result, "data.token", String.class);
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("token"));
|
|
|
+ Update update = new Update();
|
|
|
+ update.set("data", token);
|
|
|
+ update.set("expire", LocalDateTime.now());
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ EbaUtils.token = token;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化当前用户名下项目列表到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getDeviceSystemList() {
|
|
|
- List<Map> deviceSystemList = EbaUtils.getDeviceSystemList();
|
|
|
- mongoTemplate.dropCollection("deviceSystemList");
|
|
|
- mongoTemplate.insert(deviceSystemList, "deviceSystemList");
|
|
|
+ public void initProjectList() {
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getProjectList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("projectList"));
|
|
|
+ Update update = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.projectList", Map.class);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ map.forEach(x -> data.put(x.get("projectId").toString(), x));
|
|
|
+ update.set("data", data);
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ EbaUtils.project = data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化设备信息(deviceSys)到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getDeviceTypeList() {
|
|
|
- List<Map> deviceTypeList = EbaUtils.getDeviceTypeList();
|
|
|
- mongoTemplate.dropCollection("deviceTypeList");
|
|
|
- mongoTemplate.insert(deviceTypeList, "deviceTypeList");
|
|
|
+ public void initDeviceSystemList() {
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getDeviceSystemList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("deviceSystemList"));
|
|
|
+ Update update = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.datas", Map.class);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ map.forEach(x -> data.put(x.get("deviceSysId").toString(), x));
|
|
|
+ update.set("data", data);
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ EbaUtils.deviceSystem = data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化设备类型信息(deviceType)到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getDeviceParamList() {
|
|
|
- List<Map> deviceParamList = EbaUtils.getDeviceParamList();
|
|
|
- mongoTemplate.dropCollection("deviceParamList");
|
|
|
- mongoTemplate.insert(deviceParamList, "deviceParamList");
|
|
|
+ public void initDeviceTypeList() {
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getDeviceTypeList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("deviceTypeList"));
|
|
|
+ Update update = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.datas", Map.class);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ map.forEach(x -> data.put(x.get("deviceTypeId").toString(), x));
|
|
|
+ update.set("data", data);
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ EbaUtils.deviceType = data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化设备参数信息(deviceParam)到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getDeviceAlarmTypeList() {
|
|
|
- List<Map> deviceAlarmTypeList = EbaUtils.getDeviceAlarmTypeList();
|
|
|
- mongoTemplate.dropCollection("deviceAlarmTypeList");
|
|
|
- mongoTemplate.insert(deviceAlarmTypeList, "deviceAlarmTypeList");
|
|
|
+ public void initDeviceParamList() {
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getDeviceParamList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("deviceParamList"));
|
|
|
+ Update update = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.datas", Map.class);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ map.forEach(x -> data.put(x.get("deviceParamId").toString(), x));
|
|
|
+ update.set("data", data);
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ EbaUtils.deviceParam = data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化设备告警类型信息(alarmType)到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getFireDeviceTypeList() {
|
|
|
- List<Map> fireDeviceTypeList = EbaUtils.getFireDeviceTypeList();
|
|
|
- mongoTemplate.dropCollection("fireDeviceTypeList");
|
|
|
- mongoTemplate.insert(fireDeviceTypeList, "fireDeviceTypeList");
|
|
|
+ public void initDeviceAlarmTypeList() {
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getDeviceAlarmTypeList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("deviceAlarmTypeList"));
|
|
|
+ Update update = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.datas", Map.class);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ map.forEach(x -> data.put(x.get("alarmTypeId").toString(), x));
|
|
|
+ update.set("data", data);
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ EbaUtils.deviceAlarmType = data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化消防设备类型信息(fireDeviceType)到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getMobjectRealDataList(List<Map<String, Integer>> deviceParams) {
|
|
|
- List<Map> mobjectRealDataList = EbaUtils.getMobjectRealDataList(deviceParams);
|
|
|
- mongoTemplate.dropCollection("mobjectRealDataList");
|
|
|
- mongoTemplate.insert(mobjectRealDataList, "mobjectRealDataList");
|
|
|
+ public void initFireDeviceTypeList() {
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getFireDeviceTypeList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("fireDeviceTypeList"));
|
|
|
+ Update update = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.datas", Map.class);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ map.forEach(x -> data.put(x.get("fireDeviceTypeId").toString(), x));
|
|
|
+ update.set("data", data);
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ EbaUtils.fireDeviceType = data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化所有项目实时device信息到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getMobjectRealDataByProjectIdList(Long projectId) {
|
|
|
- List<Map> dataByProjectIdList = EbaUtils.getMobjectRealDataByProjectIdList(projectId);
|
|
|
- mongoTemplate.dropCollection("dataByProjectIdList");
|
|
|
- mongoTemplate.insert(dataByProjectIdList, "dataByProjectIdList");
|
|
|
+ public void initRealDataDeviceList() {
|
|
|
+ Set<String> keys = EbaUtils.project.keySet();
|
|
|
+ keys.forEach(key -> {
|
|
|
+ String param = JSON.toJSONString(Levi.by("projectId", Integer.parseInt(key)));
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getMobjectRealDataByProjectIdList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .body(param)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ // 存入原始数据用于统计
|
|
|
+ Query query1 = new Query();
|
|
|
+ query1.addCriteria(Criteria.where("_id").is(key + "_" + LocalDateTime.now().getYear() + "_" + LocalDateTime.now().getMonthValue()));
|
|
|
+ Update update1 = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.realtimeDataList", Map.class);
|
|
|
+ update1.set("data", EbaUtils.setDataField(map, key, "realDataDeviceList", false));
|
|
|
+ mongoTemplate.upsert(query1, update1, "realDataDeviceList");
|
|
|
+ // 存入当前最新数据方便查询
|
|
|
+ Query query2 = new Query();
|
|
|
+ query2.addCriteria(Criteria.where("_id").is("realDataDeviceList"));
|
|
|
+ JSONObject data1 = new JSONObject();
|
|
|
+ JSONObject data2 = new JSONObject();
|
|
|
+ map.forEach(x -> data1.put(x.get("deviceId").toString() + "_" + x.get("paramId").toString(), x.get("paramValue").toString()));
|
|
|
+ Update update2 = new Update();
|
|
|
+ data2.put(key, data1);
|
|
|
+ update2.set("data", data2);
|
|
|
+ mongoTemplate.upsert(query2, update2, "ebaAuth");
|
|
|
+ EbaUtils.realDataDevice = data2;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化所有项目device信息到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getMobjectEnergyList(Long deviceId, Long deviceParameterId, Long beginTime, Long endTime) {
|
|
|
- List<Map> mobjectEnergyList = EbaUtils.getMobjectEnergyList(deviceId, deviceParameterId, beginTime, endTime);
|
|
|
- mongoTemplate.dropCollection("mobjectEnergyList");
|
|
|
- mongoTemplate.insert(mobjectEnergyList, "mobjectEnergyList");
|
|
|
+ public void initMobjectList() {
|
|
|
+ Set<String> keys = EbaUtils.project.keySet();
|
|
|
+ keys.forEach(key -> {
|
|
|
+ String param = JSON.toJSONString(Levi.by("projectId", Integer.parseInt(key)));
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getMobjectList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .body(param)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("mobjectList"));
|
|
|
+ Update update = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.mObjectList", Map.class);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ map.forEach(x -> {
|
|
|
+ List<Map> list = (List<Map>) x.get("params");
|
|
|
+ Integer deviceId = (Integer) x.get("deviceId");
|
|
|
+ list.forEach(y -> y.put("paramValue", EbaUtils.realDataDevice.getJSONObject(key).getString(deviceId.toString() + "_" + y.get("paramId").toString())));
|
|
|
+ });
|
|
|
+ data.put(key, map);
|
|
|
+ update.set("data", data);
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化所有项目iot信息到mongo
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getMobjectRealTimeAlarmList(Long projectId) {
|
|
|
- List<Map> mobjectRealTimeAlarmList = EbaUtils.getMobjectRealTimeAlarmList(projectId);
|
|
|
- mongoTemplate.dropCollection("mobjectRealTimeAlarmList");
|
|
|
- mongoTemplate.insert(mobjectRealTimeAlarmList, "mobjectRealTimeAlarmList");
|
|
|
+ public void initIotList() {
|
|
|
+ Set<String> keys = EbaUtils.project.keySet();
|
|
|
+ keys.forEach(key -> {
|
|
|
+ String param = JSON.toJSONString(Levi.by("projectId", Integer.parseInt(key)));
|
|
|
+ String str = HttpRequest.post(EbaSystemConstants.getIotList)
|
|
|
+ .header("token", EbaUtils.token)
|
|
|
+ .body(param)
|
|
|
+ .execute().body();
|
|
|
+ if (EbaUtils.isSuccess(str)) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is("iotList"));
|
|
|
+ Update update = new Update();
|
|
|
+ List<Map> map = LeviUtils.getJsonFieldMany(str, "data.datas", Map.class);
|
|
|
+ update.set("data", Levi.by(key, map));
|
|
|
+ mongoTemplate.upsert(query, update, "ebaAuth");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 实时数据接收
|
|
|
+ *
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getMobjectHisAlarmPageList(Long projectId, Long beginTime, Long endTime, Integer pageIndex, Integer pageSize) {
|
|
|
- List<Map> mobjectHisAlarmPageList = EbaUtils.getMobjectHisAlarmPageList(projectId, beginTime, endTime, pageIndex, pageSize);
|
|
|
- mongoTemplate.dropCollection("mobjectHisAlarmPageList");
|
|
|
- mongoTemplate.insert(mobjectHisAlarmPageList, "mobjectHisAlarmPageList");
|
|
|
+ public Integer realTimeCallback(Map<String, String> params) {
|
|
|
+ // 判断类型
|
|
|
+ String messageCode = params.get("messageCode");
|
|
|
+ String content = params.get("content");
|
|
|
+ List<Map> contentList = LeviUtils.getJsonFieldMany(content, null, Map.class);
|
|
|
+ List<Map> huojing = contentList.stream().filter(x -> ((Integer) x.get("AlarmType")) == 1).collect(Collectors.toList());
|
|
|
+ List<Map> guzhang = contentList.stream().filter(x -> ((Integer) x.get("AlarmType")) == 2).collect(Collectors.toList());
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").is(messageCode + "_" + LocalDateTime.now().getYear() + "_" + LocalDateTime.now().getMonthValue()));
|
|
|
+ Update update = new Update();
|
|
|
+ Map hjMap = EbaUtils.setDataFieldCount("hjCount", huojing, messageCode, "realTimeList", false);
|
|
|
+ update.set("data", hjMap.get("data"));
|
|
|
+ update.set("hjCount", hjMap.get("hjCount"));
|
|
|
+ mongoTemplate.upsert(query, update, "realTimeList");
|
|
|
+ Map gzMap = EbaUtils.setDataFieldCount("gzCount", guzhang, messageCode, "realTimeList", false);
|
|
|
+ update.set("data", gzMap.get("data"));
|
|
|
+ update.set("gzCount", gzMap.get("gzCount"));
|
|
|
+ mongoTemplate.upsert(query, update, "realTimeList");
|
|
|
+ log.info("实时数据接收:{}", JSON.toJSONString(params));
|
|
|
+ return 200;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取项目列表
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getIotVideoUrl(Long IotId) {
|
|
|
- List<Map> iotVideoUrl = EbaUtils.getIotVideoUrl(IotId);
|
|
|
- mongoTemplate.dropCollection("iotVideoUrl");
|
|
|
- mongoTemplate.insert(iotVideoUrl, "iotVideoUrl");
|
|
|
+ public ResponseBean getProjectList() {
|
|
|
+ List<Map> results = new ArrayList<>();
|
|
|
+ JSONObject map = mongoTemplate.findById("projectList", JSONObject.class, "ebaAuth");
|
|
|
+ if (MapUtil.isNotEmpty(map)) {
|
|
|
+ Map data = (Map) map.get("data");
|
|
|
+ data.keySet().forEach(x -> results.add((Map) data.get(x)));
|
|
|
+ }
|
|
|
+ return ResponseBuilder.ok(results);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取实时设备列表
|
|
|
+ *
|
|
|
+ * @param projectId 项目id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void getIotAlarmRealTimeList(Long projectId) {
|
|
|
- List<Map> iotAlarmRealTimeList = EbaUtils.getIotAlarmRealTimeList(projectId);
|
|
|
- mongoTemplate.dropCollection("iotAlarmRealTimeList");
|
|
|
- mongoTemplate.insert(iotAlarmRealTimeList, "iotAlarmRealTimeList");
|
|
|
+ public ResponseBean getDeviceList(String projectId) {
|
|
|
+ JSONObject obj = mongoTemplate.findById("mobjectList", JSONObject.class, "ebaAuth");
|
|
|
+ JSONArray array = obj.getJSONObject("data").getJSONArray(projectId);
|
|
|
+ return ResponseBuilder.ok(array == null ? new JSONArray() : array);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取实时火警和预警
|
|
|
+ *
|
|
|
+ * @param projectId 项目id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseBean getRealTimeList(String projectId) {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ int year = now.getYear();
|
|
|
+ int month = now.getMonthValue();
|
|
|
+ int day = now.getDayOfMonth();
|
|
|
+ Map monthMap = mongoTemplate.findById(EbaMessageCode.D.getCode() + "_" + year + "_" + month, Map.class, "realTimeList");
|
|
|
+ if (MapUtil.isEmpty(monthMap)) {
|
|
|
+ return ResponseBuilder.ok("暂无实时火警和预警信息");
|
|
|
+ }
|
|
|
+ List<Map> dayList = (List<Map>) monthMap.get("data");
|
|
|
+ Map dayMap = dayList.get(day - 1);
|
|
|
+ List<Map> hourList = (List<Map>) dayMap.get("data");
|
|
|
+ List<Map> filterList = hourList.stream().filter(x -> {
|
|
|
+ List<Map> dataList = (List<Map>) x.get("data");
|
|
|
+ return dataList.size() > 0;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ // 抽取AlarmType:1火警、2故障
|
|
|
+ List<Map> huojing = new ArrayList<>();
|
|
|
+ List<Map> guzhang = new ArrayList<>();
|
|
|
+ filterList.forEach(x -> {
|
|
|
+ List<Map> dataList = (List<Map>) x.get("data");
|
|
|
+ dataList.forEach(y -> {
|
|
|
+ Integer alarmType = (Integer) y.get("AlarmType");
|
|
|
+ Integer pid = (Integer) y.get("ProjectId");
|
|
|
+ if ((pid.toString()).equals(projectId)) {
|
|
|
+ if (alarmType == 1) {
|
|
|
+ huojing.add(y);
|
|
|
+ } else if (alarmType == 2) {
|
|
|
+ guzhang.add(y);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ Integer hjDayCount = (Integer) dayMap.get("hjCount");
|
|
|
+ Integer hjMonthCount = (Integer) monthMap.get("hjCount");
|
|
|
+ Integer gzDayCount = (Integer) dayMap.get("gzCount");
|
|
|
+ Integer gzMonthCount = (Integer) monthMap.get("gzCount");
|
|
|
+ // 获取去年同时间数据
|
|
|
+ LocalDateTime previousYear = now.minus(1, ChronoUnit.YEARS);
|
|
|
+ Map oldMonthMap = mongoTemplate.findById(EbaMessageCode.D.getCode() + "_" + previousYear.getYear() + "_" + previousYear.getMonthValue(), Map.class, "realTimeList");
|
|
|
+ if (MapUtil.isEmpty(oldMonthMap)) {
|
|
|
+ return ResponseBuilder.ok(Levi.by("huojing", huojing).set("guzhang", guzhang).set("hjDayCount", hjDayCount).set("hjMonthCount", hjMonthCount).set("gzDayCount", gzDayCount).set("gzMonthCount", gzMonthCount).set("hjDayTb", "100%").set("hjMonthTb", "100%").set("gzDayTb", "100%").set("gzMonthTb", "100%"));
|
|
|
+ }
|
|
|
+ List<Map> oldDayList = (List<Map>) oldMonthMap.get("data");
|
|
|
+ Map oldDayMap = oldDayList.get(day - 1);
|
|
|
+ Integer hjDayCountOld = (Integer) oldDayMap.get("hjCount");
|
|
|
+ Integer hjMonthCountOld = (Integer) oldMonthMap.get("hjCount");
|
|
|
+ Integer gzDayCountOld = (Integer) oldDayMap.get("gzCount");
|
|
|
+ Integer gzMonthCountOld = (Integer) oldMonthMap.get("gzCount");
|
|
|
+ return ResponseBuilder.ok(Levi.by("huojing", huojing).set("guzhang", guzhang).set("hjDayCount", hjDayCount).set("hjMonthCount", hjMonthCount).set("gzDayCount", gzDayCount).set("gzMonthCount", gzMonthCount).set("hjDayTb", EbaUtils.getTongBi(hjDayCountOld, hjDayCount)).set("hjMonthTb", EbaUtils.getTongBi(hjMonthCountOld, hjMonthCount)).set("gzDayTb", EbaUtils.getTongBi(gzDayCountOld, gzDayCount)).set("gzMonthTb", EbaUtils.getTongBi(gzMonthCountOld, gzMonthCount)));
|
|
|
}
|
|
|
|
|
|
}
|