Parcourir la source

增加报警信息

dongjh il y a 1 an
Parent
commit
287c33dd2b

+ 3 - 3
module-guan/src/main/java/org/jeecg/modules/webaccess/controller/WebAccessController.java

@@ -82,9 +82,9 @@ public class WebAccessController {
     @ApiOperation(value = "获取点位实时值(webaccess)", notes = "获取点位实时值(webaccess)")
     @RequestMapping(value = "/getWATagValue", method = RequestMethod.GET)
     public Result getWATagValue() {
-        JSONObject result = webAccessService.getDashboardTagNameValues();
-        JSONArray jsonArray = result.getJSONArray("Values");
+        JSONArray result = webAccessService.getDashboardTagNameValues();
+//        JSONArray jsonArray = result.getJSONArray("Values");
 
-        return Result.OK("获取成功", jsonArray);
+        return Result.OK("获取成功", result);
     }
 }

+ 14 - 8
module-guan/src/main/java/org/jeecg/modules/webaccess/job/WAMsgJob.java

@@ -25,18 +25,24 @@ public class WAMsgJob implements Job {
 
         log.info(String.format(" 获取设备实时值! 时间:" + DateUtils.getTimestamp()));
 
-        JSONArray list = new JSONArray();
+        JSONObject jsonObject = new JSONObject();
 
         // 设备实时值
-        JSONObject tagObject = webAccessService.getDashboardTagNameValues();
-        tagObject.put("Name", "设备实时值");
-        list.add(tagObject);
+        JSONArray tagArray = webAccessService.getDashboardTagNameValues();
+        jsonObject.put("设备实时值", tagArray);
 
         // 设备历史值
-        JSONObject logObject = webAccessService.getDashboardDataLog();
-        logObject.put("Name", "设备历史值");
-        list.add(logObject);
+        JSONArray logArray = webAccessService.getDashboardDataLog();
+        jsonObject.put("设备历史值", logArray);
 
-        webSocket.pushMessageByObject(list);
+        // 最新一条报警信息
+        JSONArray lastAlarmArray = webAccessService.getDashboardDataLog();
+        jsonObject.put("最新一条报警信息", lastAlarmArray);
+
+        // 报警信息列表
+        JSONArray alarmArray = webAccessService.getDashboardDataLog();
+        jsonObject.put("报警信息列表", alarmArray);
+
+        webSocket.pushMessageByObject(jsonObject);
     }
 }

+ 224 - 28
module-guan/src/main/java/org/jeecg/modules/webaccess/service/WebAccessService.java

@@ -1,6 +1,5 @@
 package org.jeecg.modules.webaccess.service;
 
-import com.alipay.api.domain.DashboardParam;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import org.apache.commons.codec.binary.Base64;
@@ -19,10 +18,9 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
-import javax.swing.plaf.synth.Region;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.jar.JarEntry;
 
 /**
  * 调用webaccess的接口
@@ -82,8 +80,8 @@ public class WebAccessService {
      * @return
      */
     public JSONObject tagList() {
-        String getTagValueUrl = getDictItemDesc("取得所有测点列表", "group");
-        JSONObject result = httpRequest(getTagValueUrl, null);
+        String url = getDictItemDesc("取得所有测点列表", "group");
+        JSONObject result = httpRequest(url, null);
 
         return result;
     }
@@ -96,8 +94,8 @@ public class WebAccessService {
      */
     public String getTagNameValues(JSONObject jsonObject) {
         String paramValues = "";
-        String getTagValueUrl = getDictItemDesc("取得测点的量测值", "group");
-        JSONObject result = httpRequest(getTagValueUrl, jsonObject);
+        String url = getDictItemDesc("取得测点的量测值", "group");
+        JSONObject result = httpRequest(url, jsonObject);
         JSONArray jsonArray = result.getJSONArray("Values");
 
         for (int i = 0; i < jsonArray.size(); i++) {
@@ -117,9 +115,8 @@ public class WebAccessService {
      * @return
      */
     public JSONObject getTagNameValuesNoAnalysis(JSONObject jsonObject) {
-        String paramValues = "";
-        String getTagValueUrl = getDictItemDesc("取得测点的量测值", "group");
-        JSONObject result = httpRequest(getTagValueUrl, jsonObject);
+        String url = getDictItemDesc("取得测点的量测值", "group");
+        JSONObject result = httpRequest(url, jsonObject);
 
         return result;
     }
@@ -131,8 +128,8 @@ public class WebAccessService {
      * @return
      */
     public JSONObject GetDataLog(JSONObject jsonObject) {
-        String getTagValueUrl = getDictItemDesc("取得历史资料", "group");
-        JSONObject result = httpRequest(getTagValueUrl, jsonObject);
+        String url = getDictItemDesc("取得历史资料", "group");
+        JSONObject result = httpRequest(url, jsonObject);
 
         return result;
     }
@@ -157,14 +154,14 @@ public class WebAccessService {
             JSONObject itemInfor = JSONObject.fromObject(item);
             map.put(itemInfor.getString("Name"), itemInfor.getDouble("Value"));
         }
-        String getTagValueUrl = getDictItemDesc("取得测点的量测值", "group");
-        String setTagValueUrl = getDictItemDesc("更改测点的量测值", "group");
+        String getUrl = getDictItemDesc("取得测点的量测值", "group");
+        String setUrl = getDictItemDesc("更改测点的量测值", "group");
 
-        JSONObject result = httpRequest(setTagValueUrl, jsonObject);
+        JSONObject result = httpRequest(setUrl, jsonObject);
         Thread.sleep(500);
 
         if (result.getInt("Ret") >= 0) {
-            result = httpRequest(getTagValueUrl, jsonObject);
+            result = httpRequest(getUrl, jsonObject);
             JSONArray resJsonArray = result.getJSONArray("Values");
             JSONArray paramJsonArry = new JSONArray();
             System.out.println("rrr" + resJsonArray);
@@ -212,13 +209,13 @@ public class WebAccessService {
             JSONObject itemInfor = JSONObject.fromObject(item);
             map.put(itemInfor.getString("Name"), itemInfor.getString("Value"));
         }
-        String getTagValueTextUrl = getDictItemDesc("取得文字测点的量测值", "group");
-        String setTagValueTextUrl = getDictItemDesc("更改文字测点的量测值", "group");
+        String getUrl = getDictItemDesc("取得文字测点的量测值", "group");
+        String setUrl = getDictItemDesc("更改文字测点的量测值", "group");
 
-        JSONObject result = httpRequest(setTagValueTextUrl, jsonObject);
+        JSONObject result = httpRequest(setUrl, jsonObject);
 
         if (result.getInt("Ret") >= 0) {
-            result = httpRequest(getTagValueTextUrl, jsonObject);
+            result = httpRequest(getUrl, jsonObject);
             JSONArray resJsonArray = result.getJSONArray("Values");
             JSONArray paramJsonArry = new JSONArray();
             System.out.println(resJsonArray);
@@ -247,6 +244,29 @@ public class WebAccessService {
     }
 
     /**
+     * 取得实时警报资料数量
+     * @return
+     */
+    public JSONObject getAlarmSummaryCount() {
+        String url = getDictItemDesc("取得实时警报资料数量", "group");
+        JSONObject result = httpRequest(url, null);
+
+        return result;
+    }
+
+    /**
+     * 取得实时警报资料
+     * @return
+     */
+    public JSONObject getAlarmSummary(Integer start, Integer count) {
+        String url = getDictItemDesc("取得实时警报资料数量", "group");
+        url += "/" + start + "/" + count;
+        JSONObject result = httpRequest(url, null);
+
+        return result;
+    }
+
+    /**
      * 调用webaccess接口
      *
      * @param url
@@ -376,7 +396,7 @@ public class WebAccessService {
      *
      * @return
      */
-    public JSONObject getDashboardTagNameValues() {
+    public JSONArray getDashboardTagNameValues() {
         // 获取大屏参数设置
         GuanDashboardParam paramat = new GuanDashboardParam();
         paramat.setStatus("1"); // 状态为启用
@@ -398,7 +418,145 @@ public class WebAccessService {
         }
         JSONObject waparams = generateGetObject(tags);
         JSONObject jsonObject = getTagNameValuesNoAnalysis(waparams);
-        return jsonObject;
+        JSONArray resJsonArray = jsonObject.getJSONArray("Values");
+
+        return addDashboardTagNameValues(resJsonArray);
+    }
+
+    /**
+     * 增加需要计算的值
+     * @param resJsonArray
+     * @return
+     */
+    private JSONArray addDashboardTagNameValues(JSONArray resJsonArray) {
+
+        // 需要计算的信息
+        JSONObject addObject = new JSONObject();
+        JSONArray calArray = getCalElement(resJsonArray);
+        Integer syyxsj = 0;
+        Integer yjjssj = 0;
+        Integer cxdsdsj = 0;
+        Integer cxdyxsj = 0;
+        Float wdscl = 0F;
+        Float sdscl = 0F;
+        if (calArray != null && calArray.size() > 0) {
+            for(Object obj : calArray) {
+                JSONObject calObj = (JSONObject) obj;
+                switch (calObj.get("Name").toString()) {
+                    case "试验运行时间":
+                        syyxsj = (Integer) calObj.get("Value");
+                        break;
+                    case "预计结束时间":
+                        yjjssj = (Integer) calObj.get("Value");
+                        break;
+                    case "程序段设定时间":
+                        cxdsdsj = (Integer) calObj.get("Value");
+                        break;
+                    case "程序段运行时间":
+                        cxdyxsj = (Integer) calObj.get("Value");
+                        break;
+                    case "温度输出率":
+                        wdscl = ((Integer) calObj.get("Value")).floatValue();
+                        break;
+                    case "湿度输出率":
+                        sdscl = ((Integer) calObj.get("Value")).floatValue();
+                        break;
+                    case "":
+                        break;
+                    default:
+                        break;
+                }
+            }
+        }
+
+        // 试验进度:试验运行时间/(试验运行时间+预计结束时间)
+        Float syjd = (syyxsj + yjjssj) == 0 ? 0 : syyxsj.floatValue() / (syyxsj.floatValue() + yjjssj.floatValue());
+        addObject.put("Name", "试验进度");
+        addObject.put("Value",String.format("%.2f", syjd));
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+        // 预计结束时间-试验信息:“预计结束时间”给到的是时间段(s):预计结束时间+本地时间=预计时间(显示月日时分)。
+        Date yjjssj_syxx = new Date();
+        if (yjjssj != null) {
+            Calendar calendar = Calendar.getInstance();
+            // 设置当前的时间戳
+            calendar.setTime(new Date());
+            calendar.add(Calendar.SECOND, yjjssj);
+            yjjssj_syxx = calendar.getTime();
+        }
+
+        addObject.put("Name", "预计结束时间-试验信息");
+        addObject.put("Value",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yjjssj_syxx));
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+        // 段余时间:程序段设定时间-程序段运行时间
+        addObject.put("Name", "段余时间");
+        addObject.put("Value", cxdsdsj - cxdyxsj);
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+
+        // 段进度:(程序段设定时间(设定时间-秒) - 程序段运行时间(运行时间-秒) )/程序段设定时间(设定时间-秒)
+        String djd = cxdyxsj == 0 ? "0" : String.format("%.2f", (cxdsdsj.floatValue() - cxdyxsj.floatValue()) / cxdsdsj.floatValue());
+
+        addObject.put("Name", "段进度");
+        addObject.put("Value",djd);
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+        // 斜率设定
+        addObject.put("Name", "斜率设定");
+        addObject.put("Value",0);
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+        // 升温/降温:温度输出率为0%-100%则是加热状态,-100%--0%则是降温状态
+        addObject.put("Name", "升温");
+        addObject.put("Value",wdscl > 0 ? 1 : 0);
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+        addObject.put("Name", "降温");
+        addObject.put("Value",wdscl < 0 ? 1 : 0);
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+        // 加湿/除湿:湿度输出率为0%-100%则是加湿状态,-100%--0%则是除湿状态
+        addObject.put("Name", "加湿");
+        addObject.put("Value", sdscl > 0 ? 1 : 0);
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+        addObject.put("Name", "除湿");
+        addObject.put("Value", sdscl < 0 ? 1 : 0);
+        addObject.put("Quality", 0);
+        resJsonArray.add(addObject);
+
+        return resJsonArray;
+    }
+
+    /**
+     * 获取需要计算的信息依赖的点位值
+     * @param jsonArray
+     * @return
+     */
+    private JSONArray getCalElement(JSONArray jsonArray) {
+        JSONArray rtnArray = new JSONArray();
+
+        if (jsonArray != null && jsonArray.size() > 0) {
+            for (Object jsonObject : jsonArray) {
+                JSONObject obj = (JSONObject) jsonObject;
+                String name = obj.get("Name").toString();
+                if ("试验运行时间".equals(name) || "预计结束时间".equals(name) || "程序段设定时间".equals(name) ||
+                        "程序段运行时间".equals(name) || "温度输出率".equals(name) || "湿度输出率".equals(name)) {
+                    rtnArray.add(obj);
+                }
+            }
+        }
+
+        return rtnArray;
     }
 
     /**
@@ -406,7 +564,7 @@ public class WebAccessService {
      *
      * @return
      */
-    public JSONObject getDashboardDataLog() {
+    public JSONArray getDashboardDataLog() {
         // 获取大屏参数设置
         GuanDashboardParam paramat = new GuanDashboardParam();
         paramat.setStatus("1"); // 状态为启用
@@ -437,9 +595,47 @@ public class WebAccessService {
         else {
             return null;
         }
-        JSONObject rtn = new JSONObject();
-        rtn.put("历史记录", list);
-        return rtn;
+        return list;
+    }
+
+    /**
+     * 获取最新一条报警信息
+     * @return
+     */
+    public JSONArray getDashboardLastAlarm() {
+        JSONArray jsonArray = new JSONArray();
+        // 先获取报警信息数量
+        JSONObject jsonObject = getAlarmSummaryCount();
+        // 再获取最后一条记录
+        if (jsonObject != null) {
+            Integer total = (Integer) jsonObject.get("Total");
+            if (total != null && total > 0) {
+                JSONObject alarms = getAlarmSummary(total, 1);
+                jsonArray = alarms.getJSONArray("AlarmTagList");
+            }
+        }
+
+        return jsonArray;
+    }
+
+    /**
+     * 翻页获取多条报警信息
+     * @return
+     */
+    public JSONArray getDashboardPageAlarm() {
+        JSONArray jsonArray = new JSONArray();
+        // 先获取报警信息数量
+        JSONObject jsonObject = getAlarmSummaryCount();
+        // 再获取最后一条记录
+        if (jsonObject != null) {
+            Integer total = (Integer) jsonObject.get("Total");
+            if (total != null && total > 0) {
+                JSONObject alarms = getAlarmSummary(total, 10);
+                jsonArray = alarms.getJSONArray("AlarmTagList");
+            }
+        }
+
+        return jsonArray;
     }
     //endregion
 }