wangjiawen 4 vuotta sitten
vanhempi
commit
285869b3f9

+ 54 - 0
src/main/java/com/gyee/frame/controller/app/TargetdetailController.java

@@ -0,0 +1,54 @@
+package com.gyee.frame.controller.app;
+
+import com.gyee.frame.netty.websocket.util.SocketToolController;
+import com.gyee.frame.service.app.targetdetail.TargetdetailService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+/**
+ * @author Wang Jiawen
+ * @purpose
+ * @date 2020-05-14 21:52
+ */
+@Controller
+@RequestMapping("/targetdetail")
+public class TargetdetailController extends SocketToolController {
+    @Autowired
+    private TargetdetailService targetdetailService;
+
+    @ResponseBody
+    @RequestMapping("/targetdetail_target")
+    public String targetdetail(HttpServletRequest httpServletRequest,String pointKey) throws Exception {
+        String remoteAddr = httpServletRequest.getRemoteAddr();
+        Map<String, String> pointMap = TargetdetailService.targetdetail_target_pointMap;
+        pointMap.put(remoteAddr,pointKey);
+        TargetdetailService.targetdetail_target_pointMap = pointMap;
+        return remoteAddr;
+    }
+
+    @ResponseBody
+    @RequestMapping("/targetdetail_curve")
+    public String targetdetail_curve(HttpServletRequest httpServletRequest,String pointKey) throws Exception {
+        String remoteAddr = httpServletRequest.getRemoteAddr();
+        Map<String, String> pointMap = TargetdetailService.targetdetail_curve_pointMap;
+        pointMap.put(remoteAddr,pointKey);
+        TargetdetailService.targetdetail_curve_pointMap = pointMap;
+        return remoteAddr;
+    }
+
+    @ResponseBody
+    @RequestMapping("/targetdetail_histogram")
+    public String targetdetail_histogram(HttpServletRequest httpServletRequest,String pointKey) throws Exception {
+        String remoteAddr = httpServletRequest.getRemoteAddr();
+        Map<String, String> pointMap = TargetdetailService.targetdetail_histogram_pointMap;
+        pointMap.put(remoteAddr,pointKey);
+        TargetdetailService.targetdetail_histogram_pointMap = pointMap;
+        return remoteAddr;
+    }
+}

+ 56 - 32
src/main/java/com/gyee/frame/service/app/targetdetail/TargetdetailService.java

@@ -12,8 +12,7 @@ import org.springframework.stereotype.Service;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author Wang Jiawen
@@ -24,58 +23,83 @@ import java.util.List;
 @Service
 public class TargetdetailService extends SocketToolService {
 
-    static String point = "";
+    public static Map<String,String> targetdetail_target_pointMap = new HashMap<>();
+    public static Map<String,String> targetdetail_curve_pointMap = new HashMap<>();
+    public static Map<String,String> targetdetail_histogram_pointMap = new HashMap<>();
 
     public void targetdetail_target() throws Exception {
+        Set set = targetdetail_target_pointMap.keySet();
+        Iterator<String>  it =  set.iterator();
         IMongodbUtil mongodb = new MongodbUtilImpl();
-//查看实时数据
-        PointData real=mongodb.getRealData("HB_GD_KBF_JS_P4_L19_220_CI0136");
-        double pointValueInDouble = real.getPointValueInDouble();
-        this.pushToWeb("pageNumber_8","functionNumber_1",pointValueInDouble, Messagetype.MESSAGE);
+        Map<String,Double> pointDataMap = new HashMap();
+        while(it.hasNext()){
+            String ip = it.next();
+            PointData real=mongodb.getRealData(targetdetail_target_pointMap.get(ip));
+            double pointValueInDouble = real.getPointValueInDouble();
+            pointDataMap.put(ip,pointValueInDouble);
+        }
+
+        this.pushToWeb("pageNumber_8","functionNumber_1",pointDataMap, Messagetype.MESSAGE);
     }
 
     public void targetdetail_curve() throws Exception {
+        Set set = targetdetail_curve_pointMap.keySet();
+        Iterator<String>  it =  set.iterator();
         IMongodbUtil mongodb = new MongodbUtilImpl();
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
-        Date nowTime = DateUtils.getNowDate();
-        Date endTime = sdf.parse(sdf.format(nowTime));
-        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
-        Date beginTime = sdf1.parse(sdf1.format(nowTime));
-        Long count = (endTime.getTime()-beginTime.getTime())/1000L/3600L;
-        List<PointData> ls = mongodb.getHistoryDatasSnap("HB_GD_KBF_JS_P4_L19_220_CI0136",
-                beginTime.getTime() / 1000, endTime.getTime() / 1000,
-                (long) count, 3600L);
-        for(int i=0;i<ls.size();i++){
-            ls.get(i).setPointTime(ls.get(i).getPointTime()-3600);
+        Map<String,List<PointData>> pointDataMap = new HashMap();
+        while(it.hasNext()) {
+            String ip = it.next();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
+            Date nowTime = DateUtils.getNowDate();
+            Date endTime = sdf.parse(sdf.format(nowTime));
+            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
+            Date beginTime = sdf1.parse(sdf1.format(nowTime));
+            Long count = (endTime.getTime() - beginTime.getTime()) / 1000L / 3600L;
+            List<PointData> ls = mongodb.getHistoryDatasSnap(targetdetail_curve_pointMap.get(ip),
+                    beginTime.getTime() / 1000, endTime.getTime() / 1000,
+                    (long) count, 3600L);
+            for (int i = 0; i < ls.size(); i++) {
+                ls.get(i).setPointTime(ls.get(i).getPointTime() - 3600);
+            }
+            if(ls.size()>0) {
+                ls.remove(0);
+            }
+            pointDataMap.put(ip,ls);
         }
-        ls.remove(0);
-
 /*        if (!ls.isEmpty()) {
             ls.forEach(obj -> System.out.println(obj.getEdnaId() + "___" +obj.getPointTime() + "___" + obj.getPointValueInDouble()));
         }
         for(PointData obj:ls){
             System.out.println(obj.getEdnaId() + "___" +obj.getPointTime() + "___" + obj.getPointValueInDouble());
         }*/
-        this.pushToWeb("pageNumber_8","functionNumber_2",ls, Messagetype.MESSAGE);
+        this.pushToWeb("pageNumber_8","functionNumber_2",pointDataMap, Messagetype.MESSAGE);
     }
 
     public void targetdetail_histogram() throws Exception {
+        Set set = targetdetail_histogram_pointMap.keySet();
+        Iterator<String>  it =  set.iterator();
         IMongodbUtil mongodb = new MongodbUtilImpl();
-        Date nowTime = DateUtils.getNowDate();
-        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
-        Date endTime = sdf1.parse(sdf1.format(nowTime));
-        Date beginTime = DateUtils.addDays(endTime, -7);
+        Map<String,List<PointData>> pointDataMap = new HashMap();
+        while(it.hasNext()) {
+            String ip = it.next();
+            Date nowTime = DateUtils.getNowDate();
+            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
+            Date endTime = sdf1.parse(sdf1.format(nowTime));
+            Date beginTime = DateUtils.addDays(endTime, -7);
 //查看历史快照数据
-        List<PointData> ls = mongodb.getHistoryDatasSnap("HB_GD_KBF_JS_P4_L19_220_CI0136",
-                beginTime.getTime() / 1000, endTime.getTime() / 1000,
-                7L, 3600*24L);
-        for (int i=0;i<ls.size();i++){
-            ls.get(i).setPointTime(ls.get(i).getPointTime()-24*3600);
+            List<PointData> ls = mongodb.getHistoryDatasSnap(targetdetail_histogram_pointMap.get(ip),
+                    beginTime.getTime() / 1000, endTime.getTime() / 1000,
+                    7L, 3600 * 24L);
+            for (int i = 0; i < ls.size(); i++) {
+                ls.get(i).setPointTime(ls.get(i).getPointTime() - 24 * 3600);
+            }
+            ls.remove(0);
+            pointDataMap.put(ip,ls);
         }
-        ls.remove(0);
+
         /*if (!ls.isEmpty()) {
             ls.forEach(obj -> System.out.println(obj.getEdnaId() + "___" +obj.getPointTime() + "___" + obj.getPointValueInDouble()));
         }*/
-        this.pushToWeb("pageNumber_8","functionNumber_3",ls, Messagetype.MESSAGE);
+        this.pushToWeb("pageNumber_8","functionNumber_3",pointDataMap, Messagetype.MESSAGE);
     }
 }