Levi.u il y a 4 ans
Parent
commit
67169ee301

+ 12 - 0
src/main/java/com/ebei/screen/common/util/EbaUtils.java

@@ -129,12 +129,24 @@ public class EbaUtils {
             dataList.addAll(objList);
             hourMap.put("data", dataList);
             int size = objList.size();
+            for (Map x : dataList) {
+                String projectId = x.get("ProjectId").toString();
+                hourMap.put(key + "_" + projectId, addCount(hourMap, size, key + "_" + projectId));
+                dayMap.put(key + "_" + projectId, addCount(dayMap, size, key + "_" + projectId));
+                monthMap.put(key + "_" + projectId, addCount(monthMap, size, key + "_" + projectId));
+            }
             hourMap.put(key, addCount(hourMap, size, key));
             dayMap.put(key, addCount(dayMap, size, key));
             monthMap.put(key, addCount(monthMap, size, key));
         } else {
             hourMap.put("data", obj);
             int size = objList.size();
+            for (Map x : objList) {
+                String projectId = x.get("ProjectId").toString();
+                hourMap.put(key + "_" + projectId, addCount(hourMap, size, key + "_" + projectId) - dataList.size());
+                dayMap.put(key + "_" + projectId, addCount(dayMap, size, key + "_" + projectId) - dataList.size());
+                monthMap.put(key + "_" + projectId, addCount(monthMap, size, key + "_" + projectId) - dataList.size());
+            }
             hourMap.put(key, addCount(hourMap, size, key) - dataList.size());
             dayMap.put(key, addCount(dayMap, size, key) - dataList.size());
             monthMap.put(key, addCount(monthMap, size, key) - dataList.size());

+ 8 - 0
src/main/java/com/ebei/screen/controller/eba/EbaSystemController.java

@@ -3,6 +3,7 @@ package com.ebei.screen.controller.eba;
 import com.ebei.screen.common.response.BasePageBean;
 import com.ebei.screen.common.response.ResponseBean;
 import com.ebei.screen.common.util.EbaUtils;
+import com.ebei.screen.modules.req.RealTimeReq;
 import com.ebei.screen.service.EbaSystemService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -78,4 +79,11 @@ public class EbaSystemController {
         return ebaSystemService.deleteRelevance(ebeiProjectId);
     }
 
+    @ApiOperation("分页查询火警和故障信息")
+    @PostMapping("/getRealTimeListByPage")
+    public ResponseBean getRealTimeListByPage(@RequestBody RealTimeReq params) {
+        params.setProjectId(EbaUtils.getProjectId(params.getProjectId()));
+        return ebaSystemService.getRealTimeListByPage(params);
+    }
+
 }

+ 9 - 0
src/main/java/com/ebei/screen/service/EbaSystemService.java

@@ -2,6 +2,7 @@ package com.ebei.screen.service;
 
 import com.ebei.screen.common.response.BasePageBean;
 import com.ebei.screen.common.response.ResponseBean;
+import com.ebei.screen.modules.req.RealTimeReq;
 
 import java.util.Map;
 
@@ -136,4 +137,12 @@ public interface EbaSystemService {
      * @return
      */
     ResponseBean deleteRelevance(String ebeiProjectId);
+
+    /**
+     * 分页查询火警和故障信息
+     *
+     * @param params
+     * @return
+     */
+    ResponseBean getRealTimeListByPage(RealTimeReq params);
 }

+ 74 - 1
src/main/java/com/ebei/screen/service/impl/EbaSystemServiceImpl.java

@@ -17,6 +17,7 @@ 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.common.util.ScheduledUtils;
+import com.ebei.screen.modules.req.RealTimeReq;
 import com.ebei.screen.service.EbaSystemService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -569,5 +570,77 @@ public class EbaSystemServiceImpl implements EbaSystemService {
         return ResponseBuilder.ok("删除成功");
     }
 
-
+    /**
+     * 分页查询火警和故障信息
+     *
+     * @param params
+     * @return
+     */
+    @Override
+    public ResponseBean getRealTimeListByPage(RealTimeReq params) {
+        String projectId = params.getProjectId();
+        boolean flag = StringUtils.isNotBlank(projectId);
+        Integer pageNum = params.getPageNum();
+        Integer pageSize = params.getPageSize();
+        Integer dateType = params.getDateType();
+        Integer type = params.getType();
+        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");
+        // 抽取AlarmType:1火警、2故障
+        List<Map> huojing = new ArrayList<>();
+        List<Map> guzhang = new ArrayList<>();
+        // 查询一天 则替换集合元素为当日
+        if (dateType == 0) {
+            dayList = Arrays.asList(dayList.get(day - 1));
+        }
+        dayList.forEach(dayMap -> {
+            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());
+            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");
+                    y.put("AlarmTimeStr", LeviUtils.convertTime(y.get("AlarmTime")));
+                    if (flag) {
+                        if ((pid.toString()).equals(projectId)) {
+                            if (alarmType == 1) {
+                                huojing.add(y);
+                            } else if (alarmType == 2) {
+                                guzhang.add(y);
+                            }
+                        }
+                    } else {
+                        if (alarmType == 1) {
+                            huojing.add(y);
+                        } else if (alarmType == 2) {
+                            guzhang.add(y);
+                        }
+                    }
+                });
+            });
+        });
+        // 过滤多余字段 返回结果集
+        if (type == 0) {
+            List<Levi> hjList = huojing.stream().map(x -> Levi.by("ProjectName", x.get("ProjectName").toString()).set("ProjectId", x.get("ProjectId").toString()).set("AlarmContent", x.get("AlarmContent").toString()).set("AlarmTimeStr", x.get("AlarmTimeStr").toString())).collect(Collectors.toList());
+            Supplier<Stream<Levi>> hjStream = () -> hjList.stream();
+            List<Map> hjResult = hjStream.get().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
+            return ResponseBuilder.ok(PageBean.<Map>builder().total(hjStream.get().count()).row(hjResult).build());
+        } else {
+            List<Levi> gzList = guzhang.stream().map(x -> Levi.by("ProjectName", x.get("ProjectName").toString()).set("ProjectId", x.get("ProjectId").toString()).set("AlarmContent", x.get("AlarmContent").toString()).set("AlarmTimeStr", x.get("AlarmTimeStr").toString())).collect(Collectors.toList());
+            Supplier<Stream<Levi>> gzStream = () -> gzList.stream();
+            List<Map> gzResult = gzStream.get().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
+            return ResponseBuilder.ok(PageBean.<Map>builder().total(gzStream.get().count()).row(gzResult).build());
+        }
+    }
 }

+ 1 - 1
src/main/resources/application-prod.yml

@@ -8,7 +8,7 @@ spring:
   data:
     mongodb:
       database: eaglescreen
-      host: 10.81.51.7
+      host: 118.178.133.35
       port: 27017
       username: eaglescreen
       password: yibeitech@2019

+ 1 - 1
src/main/resources/application.yml

@@ -6,7 +6,7 @@ spring:
     default-property-inclusion: non_null
     time-zone: Asia/Shanghai
   profiles:
-    active: dev
+    active: prod
 cn:
   auth:
     permit-url-list: