浏览代码

新建电子秤4个查询接口

zhuoning 3 年之前
父节点
当前提交
1efd7f4290
共有 47 个文件被更改,包括 391 次插入1849 次删除
  1. 9 1
      huimv-farm-v2/huimv-produce-warning/pom.xml
  2. 41 2
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/WeightController.java
  3. 5 1
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/repo/ProdDayWeightRepo.java
  4. 4 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IWeight.java
  5. 62 6
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/WeightImpl.java
  6. 0 161
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/FBoxSignalRConnection.java
  7. 0 45
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/Global.java
  8. 0 215
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/Main.java
  9. 0 24
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/Item.java
  10. 0 20
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/Monitory.java
  11. 0 27
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/MonitoryGetArgs.java
  12. 0 122
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/MonitoryValue.java
  13. 0 18
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/BoxServerResponseException.java
  14. 0 18
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ClientCredential.java
  15. 0 34
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ConsoleLogger.java
  16. 0 12
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ConsoleLoggerFactory.java
  17. 0 17
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/CredentialProvider.java
  18. 0 10
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/Logger.java
  19. 0 5
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/LoggerFactory.java
  20. 0 9
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/LoginFailedException.java
  21. 0 23
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/NullLogger.java
  22. 0 301
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ServerCaller.java
  23. 0 21
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/StaticCredentialProvider.java
  24. 0 132
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/TokenManager.java
  25. 0 5
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/TokenResponse.java
  26. 0 18
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/UserCredential.java
  27. 0 24
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/Box.java
  28. 0 8
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxGroup.java
  29. 0 18
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxReg.java
  30. 0 7
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxStateChanged.java
  31. 0 5
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/ByRowHdata.java
  32. 0 19
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/ByRowHdataRow.java
  33. 0 13
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/Cs.java
  34. 0 53
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DataSource.java
  35. 0 76
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DataType.java
  36. 0 14
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DmonWriteValueArgs.java
  37. 0 11
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetByChannelHdataArgs.java
  38. 0 9
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetByRowHdataArgs.java
  39. 0 9
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetDmonValuesById.java
  40. 0 9
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetDmonValuesByName.java
  41. 0 39
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetHdataArgs.java
  42. 0 33
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataChannelDef.java
  43. 0 5
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataControlOptions.java
  44. 0 33
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataDef.java
  45. 0 189
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/signalr/SignalRConnectionBase.java
  46. 0 28
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/signalr/SignalRLoggerWrapper.java
  47. 270 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/utils/DateUtil.java

+ 9 - 1
huimv-farm-v2/huimv-produce-warning/pom.xml

@@ -58,7 +58,15 @@
             <artifactId>zhenzisms</artifactId>
             <version>2.0.2</version>
         </dependency>
-
+        <dependency>
+            <groupId>org.springframework.data</groupId>
+            <artifactId>spring-data-jpa</artifactId>
+        </dependency>
+        <!-- JPA -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 41 - 2
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/WeightController.java

@@ -2,6 +2,7 @@ package com.huimv.produce.controller;
 
 import com.huimv.common.utils.Result;
 import com.huimv.produce.service.IWeight;
+import com.huimv.produce.utils.DateUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.CrossOrigin;
@@ -9,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.text.ParseException;
+
 /**
  * @Project : huimv.shiwan
  * @Package : com.huimv.biosafety.uface.controller
@@ -24,13 +27,49 @@ import org.springframework.web.bind.annotation.RestController;
 public class WeightController {
     @Autowired
     private IWeight weight;
+    @Autowired
+    private DateUtil dateUtil;
 
-    @RequestMapping(value = "/getDayWeight")
-    public Result getDayWeight(@RequestParam(value = "farmId",required = true) Integer farmId,@RequestParam(value = "startDate",required = false) String startDate,@RequestParam(value = "endDate",required = false) String endDate){
+    //指定查询日期期间
+    @RequestMapping(value = "/getWeight")
+    public Result getDayWeight(@RequestParam(value = "farmId",required = true) Integer farmId,@RequestParam(value = "startDate",required = true) String startDate,@RequestParam(value = "endDate",required = true) String endDate){
         log.info("farmId>>"+farmId);
         log.info("startDate>>"+startDate);
         log.info("endDate>>"+endDate);
         //
         return weight.getDayWeight(farmId,startDate,endDate);
     }
+
+    //近7次卖猪数据
+    @RequestMapping(value = "/getWeightLastNtimes")
+    public Result getDayWeightLastNtimes(@RequestParam(value = "farmId",required = true) Integer farmId,@RequestParam(value = "days",required = true) Integer days){
+        log.info("farmId>>"+farmId);
+        log.info("days>>"+days);
+        //
+        return weight.getDayWeightLastNtimes(farmId,days);
+    }
+
+    //本月统计
+    @RequestMapping(value = "/getWeightInOneMonth")
+    public Result getDayWeightInOneMonth(@RequestParam(value = "farmId",required = true) Integer farmId){
+        log.info("farmId>>"+farmId);
+        String startDateText = dateUtil.getMonthStart();
+        log.info("startDateText>>"+startDateText);
+        String endDateText = dateUtil.getMonthEnd();
+        log.info("endDateText>>"+endDateText);
+        //
+        return weight.getDayWeight(farmId,startDateText,endDateText);
+    }
+
+    //当天统计
+    @RequestMapping(value = "/getWeightOnToday")
+    public Result getDayWeightOnToday(@RequestParam(value = "farmId",required = true) Integer farmId) throws ParseException {
+        log.info("farmId>>"+farmId);
+        String todayDateText = dateUtil.getTodayDateText();
+        log.info("startDate>>"+todayDateText);
+        log.info("endDate>>"+todayDateText);
+        //
+        return weight.getDayWeight(farmId,todayDateText,todayDateText);
+    }
+
 }

+ 5 - 1
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/repo/ProdDayWeightRepo.java

@@ -7,7 +7,11 @@ import org.springframework.data.jpa.repository.Query;
 import java.util.List;
 
 public interface ProdDayWeightRepo extends JpaRepository<ProdDayWeightEntity, Integer>, JpaSpecificationExecutor<ProdDayWeightEntity> {
-
+    //
     @Query(nativeQuery = true,value = "SELECT * FROM prod_day_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d') >= DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d') <= DATE_FORMAT(?3,'%Y-%m-%d')")
     List<ProdDayWeightEntity> findByFarmIdAndStartAndEndDate(Integer farmId, String startDate, String endDate);
+
+    //
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_day_weight WHERE farm_id=?1 ORDER BY id DESC LIMIT ?2")
+    List<ProdDayWeightEntity> findByFarmIdAndDays(Integer farmId, Integer days);
 }

+ 4 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IWeight.java

@@ -3,5 +3,9 @@ package com.huimv.produce.service;
 import com.huimv.common.utils.Result;
 
 public interface IWeight {
+    //查询称重
     Result getDayWeight(Integer farmId, String startDate, String endDate);
+
+    //查询近几次卖猪记录
+    Result getDayWeightLastNtimes(Integer farmId, Integer days);
 }

+ 62 - 6
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/WeightImpl.java

@@ -1,5 +1,6 @@
 package com.huimv.produce.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.huimv.common.utils.Result;
 import com.huimv.common.utils.ResultCode;
 import com.huimv.produce.repo.ProdDayWeightEntity;
@@ -8,6 +9,8 @@ import com.huimv.produce.service.IWeight;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -23,14 +26,67 @@ public class WeightImpl implements IWeight {
     @Autowired
     private ProdDayWeightRepo dayWeightRepo;
 
+    /**
+     * @Method      : getDayWeight
+     * @Description : 
+     * @Params      : [farmId, startDate, endDate]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/7       
+     * @Time        : 13:58
+     */
     @Override
-    public Result getDayWeight(Integer farmId, String startDate, String endDate){
+    public Result getDayWeight(Integer farmId, String startDate, String endDate) {
         //
-        List<ProdDayWeightEntity> dayWeightEntityList = dayWeightRepo.findByFarmIdAndStartAndEndDate(farmId,startDate,endDate);
-        if(dayWeightEntityList.size()>0){
-            return new Result(ResultCode.SUCCESS,dayWeightEntityList);
-        }else{
-            return new Result(10001,"暂无数据.",false);
+        List<ProdDayWeightEntity> dayWeightEntityList = dayWeightRepo.findByFarmIdAndStartAndEndDate(farmId, startDate, endDate);
+        if (dayWeightEntityList.size() > 0) {
+            BigDecimal totalBd = new BigDecimal(0);
+            for (int a = 0; a < dayWeightEntityList.size(); a++) {
+                ProdDayWeightEntity dayWeightEntity = dayWeightEntityList.get(a);
+                totalBd = new BigDecimal(dayWeightEntity.getNetWeight()).add(totalBd);
+            }
+            JSONObject outJo = new JSONObject();
+            outJo.put("total", totalBd.toString());
+            outJo.put("weight", dayWeightEntityList);
+            return new Result(ResultCode.SUCCESS, outJo);
+        } else {
+            return new Result(10001, "暂无数据.", false);
+        }
+    }
+
+    /**
+     * @Method      : getDayWeightLastNtimes
+     * @Description : 
+     * @Params      : [farmId, days]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/7       
+     * @Time        : 13:58
+     */
+    @Override
+    public Result getDayWeightLastNtimes(Integer farmId, Integer days) {
+        //
+        List<ProdDayWeightEntity> dayWeightEntityList = dayWeightRepo.findByFarmIdAndDays(farmId, days);
+        if (dayWeightEntityList.size() > 0) {
+            //排序
+            List outList = new ArrayList();
+            for(int a=dayWeightEntityList.size()-1;a>=0;a--){
+                outList.add(dayWeightEntityList.get(a));
+            }
+            //计算总重
+            BigDecimal totalBd = new BigDecimal(0);
+            for (int a = 0; a < dayWeightEntityList.size(); a++) {
+                ProdDayWeightEntity dayWeightEntity = dayWeightEntityList.get(a);
+                totalBd = new BigDecimal(dayWeightEntity.getNetWeight()).add(totalBd);
+            }
+            JSONObject outJo = new JSONObject();
+            outJo.put("total", totalBd.toString());
+            outJo.put("weight", outList);
+            return new Result(ResultCode.SUCCESS, outJo);
+        } else {
+            return new Result(10001, "暂无数据.", false);
         }
     }
 }

+ 0 - 161
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/FBoxSignalRConnection.java

@@ -1,161 +0,0 @@
-package com.huimv.produce.sgd;
-
-import com.github.signalr4j.client.hubs.HubProxy;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import com.huimv.produce.sgd.fbox.Logger;
-import com.huimv.produce.sgd.fbox.LoggerFactory;
-import com.huimv.produce.sgd.fbox.TokenManager;
-import com.huimv.produce.sgd.fbox.signalr.SignalRConnectionBase;
-
-import java.net.Proxy;
-import java.text.SimpleDateFormat;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.LongAdder;
-
-public class FBoxSignalRConnection extends SignalRConnectionBase {
-    private final Gson gson;
-    private final Logger logger;
-    ConcurrentHashMap<Long, LongAdder> dmonIds = new ConcurrentHashMap<>();
-    private LongAdder dmonMsgCounter = new LongAdder();
-    private long lastDmonItemCount;
-    private long lastDmonMsgCount;
-    private long lastReportTime;
-    private Proxy proxy;
-    private LongAdder dmonItemCounter = new LongAdder();
-
-    public FBoxSignalRConnection(String hubUrl, String signalrClientId, TokenManager tokenManager, Proxy proxy, LoggerFactory loggerFactory) {
-        super(hubUrl, signalrClientId, tokenManager, proxy, loggerFactory);
-        this.logger = loggerFactory.createLogger("FBoxSignalRConnection");
-        this.proxy = proxy;
-        gson = new GsonBuilder().create();
-//        new Thread(() -> {
-//            //统计条目数线程,可以去掉此线程代码
-//            for (; ; ) {
-//                try {
-//                    Thread.sleep(5000);
-//                } catch (InterruptedException e) {
-//                    e.printStackTrace();
-//                }
-//                long currentTime = System.nanoTime();
-//                long currentMsgCount = this.dmonMsgCounter.longValue();
-//                long currentItemCount = this.dmonItemCounter.longValue();
-//                long msgRate = (currentMsgCount - this.lastDmonMsgCount) * 1000000000 / (currentTime - this.lastReportTime);
-//                long itemRate = (currentItemCount - this.lastDmonItemCount) * 1000000000 / (currentTime - this.lastReportTime);
-//                this.logger.logInformation(String.format("Dmon id count: %d, item rate: %d, message rate: %d", this.dmonIds.size(), itemRate, msgRate));
-//                this.lastReportTime = currentTime;
-//                this.lastDmonMsgCount = currentMsgCount;
-//                this.lastDmonItemCount = currentItemCount;
-//            }
-//        }).start();
-    }
-
-    @Override
-    public void connected() {
-        super.connected();
-        dmonIds.clear();
-    }
-
-
-    @Override
-    protected void onHubProxyDestroyed(HubProxy hubProxy){
-        hubProxy.removeSubscription("dMonUpdateValue");
-        hubProxy.removeSubscription("alarmTriggered");
-        hubProxy.removeSubscription("alarmRecovered");
-        hubProxy.removeSubscription("boxConnStateChanged");
-    }
-
-    SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-    @Override
-    protected void onHubProxyCreated(HubProxy hubProxy) {
-        //signalr实时数据推送事件,接收此事件数据前提条件,开启监控点数据推送控制接口(订阅)
-        hubProxy.subscribe("dMonUpdateValue").addReceivedHandler(jsonElements -> {
-            Global.threadPool.submit(() -> {
-                //try{
-                    this.dmonMsgCounter.increment();
-                    //System.out.println("Dmon data received: ");
-                    //收到的推送数据
-                    JsonArray items = jsonElements[1].getAsJsonArray();
-                    for (com.google.gson.JsonElement jsonElement : items) {
-                        JsonObject item = jsonElement.getAsJsonObject();
-                        this.dmonIds.computeIfAbsent(item.get("id").getAsLong(), aLong -> new LongAdder()).increment();
-                        this.dmonItemCounter.increment();
-                        //收到的推送数据
-                        String name = item.get("name").getAsString();
-                        String value = item.get("value").getAsString();
-                        long time = item.get("t").getAsLong();
-                        this.logger.logInformation(String.format(" %s, %s, %d\n",name,value,time));
-                        //监控点正常无status属性
-                        //long statu = item.get("status").getAsLong();
-                    };
-                    //打印监控点的值集合,集合详细信息请看接口文档http://docs.flexem.net/fbox/zh-cn/tutorials/RealtimeDataPush.html
-                    System.out.printf("%s",jsonElements[1].getAsJsonArray());
-                    //打印boxUid
-                    System.out.printf("%s",jsonElements[2].getAsLong());
-//                }
-//                catch (Exception e) {
-//                    System.out.printf("%s", e);
-//                }
-            });
-        });
-
-        // signalr报警触发事件
-//        hubProxy.subscribe("alarmTriggered").addReceivedHandler(jsonElements -> {
-//            Global.threadPool.submit(() -> {
-//                System.out.println("Alarm triggered: ");
-//                for (com.google.gson.JsonElement jsonElement : jsonElements) {
-//                    //报警推送消息全部打印。具体参数解释请看接口文档http://docs.flexem.net/fbox/zh-cn/tutorials/AlarmTiggerPush.html
-//                    System.out.println("\t" + jsonElement);
-//                };
-//                //打印报警条目的值集合
-//                System.out.printf("%s",jsonElements[1].getAsJsonArray());
-//                //打印boxUid
-//                System.out.printf("%s",jsonElements[2].getAsLong());
-//            });
-//        });
-
-        // signalr报警还原事件
-//        hubProxy.subscribe("alarmRecovered").addReceivedHandler(jsonElements -> {
-//            Global.threadPool.submit(() -> {
-//                System.out.println("Alarm recovered: ");
-//                for (com.google.gson.JsonElement jsonElement : jsonElements) {
-//                    //报警推送消息全部打印。具体参数解释请看接口文档http://docs.flexem.net/fbox/zh-cn/tutorials/AlarmReductionPush.html
-//                    System.out.println("\t" + jsonElement);
-//                };
-//                //打印报警条目的值集合
-//                System.out.printf("%s",jsonElements[1].getAsJsonArray());
-//                //打印boxUid
-//                System.out.printf("%s",jsonElements[2].getAsLong());
-//            });
-//        });
-
-        // signalr盒子状态变更事件
-//        hubProxy.subscribe("boxConnStateChanged").addReceivedHandler(jsonElements -> {
-//            Global.threadPool.submit(() -> {
-//                System.out.println("Box state changed.");
-//                if (jsonElements.length <= 0)
-//                    return;
-//                BoxStateChanged[] stateChanges = gson.fromJson(jsonElements[0], BoxStateChanged[].class);
-//                this.logger.logInformation(String.format("receive count: %d", stateChanges.length));
-//                for (BoxStateChanged stateChange : stateChanges) {
-//                    // stateChange.id 是盒子列表中BoxReg对象下的box.id,可以根据这个过滤要开的盒子。
-//                    // stateChange.state 为1、2是盒子上线事件。实时数据推送需要开点
-//                    if (stateChange.state == 1 || stateChange.state == 2) {
-//                            try {
-//                                // 盒子每次上线后,均需要开启FBox数据推送控制接口(订阅)
-//                                Global.commServer.executePost("box/" + stateChange.id + "/dmon/start", String.class);
-//                                // token有效期为两小时。若token过期,demo会自动刷新token。所以返回401后均需要重试接口
-//                                this.logger.logInformation(String.format("Start dmon points on box ok %s\n",stateChange.id));
-//                            } catch (IOException e) {
-//                                System.out.println(e);
-//                                e.printStackTrace();
-//                            }
-//                    }
-//                }
-//
-//            });
-//        });
-    }
-}

+ 0 - 45
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/Global.java

@@ -1,45 +0,0 @@
-package com.huimv.produce.sgd;
-
-
-import com.huimv.produce.sgd.fbox.ServerCaller;
-
-import java.net.Proxy;
-import java.util.UUID;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public class Global {
-    public static Proxy proxy = null;
-//    配置流量过Fiddler代理
-//    public static Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888));
-    public static ExecutorService threadPool = Executors.newCachedThreadPool();
-    public static ServerCaller commServer;
-    public static ServerCaller appServer;
-    public static ServerCaller hdataServer;
-    public static ServerCaller apiBaseServer;
-
-    // 以下服务器地址是繁易公有云,私有云请根据实际情况修改
-//    public static final String idServerUrl = "https://account.flexem.com/core/";
-//    public static String appServerApiUrl = "http://fbox360.com/api/client/";
-//    public static final String commServerApiUrl = "http://fbcs101.fbox360.com/api/";
-//    public static final String commServerSignalRUrl = "http://fbcs101.fbox360.com/push";
-//    public static String hdataServerApiUrl = "http://fbhs1.fbox360.com/api/";
-
-    public static final String idServerUrl = "http://account.highgerman.cn/core/";
-    public static String appServerApiUrl = "http://cloud.highgerman.cn/";
-    public static final String commServerApiUrl = "http://cs.highgerman.cn/api/";
-    public static final String commServerSignalRUrl = "http://cs.highgerman.cn/push";
-    public static String hdataServerApiUrl = "http://hs.highgerman.cn/api/";
-    public static String apiBaserUrl = "http://cs.highgerman.cn/api";
-    public static String signalrClientId = UUID.randomUUID().toString();
-
-
-    //FlexManager注册的账号
-    public static String username = "sgdsgd103";
-    public static String password = "sgdsgd123";
-    // 获取API账号请咨询对接的销售。
-    public static String clientId = "fboxsdkcc";
-    public static String clientSecret = "6f556f31d524498baa0fc8c8bcb99285";
-
-
-}

+ 0 - 215
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/Main.java

@@ -1,215 +0,0 @@
-package com.huimv.produce.sgd;
-
-import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.json.JSONUtil;
-import com.huimv.produce.sgd.entity.Item;
-import com.huimv.produce.sgd.entity.Monitory;
-import com.huimv.produce.sgd.entity.MonitoryGetArgs;
-import com.huimv.produce.sgd.entity.MonitoryValue;
-import com.huimv.produce.sgd.fbox.ConsoleLoggerFactory;
-import com.huimv.produce.sgd.fbox.ServerCaller;
-import com.huimv.produce.sgd.fbox.StaticCredentialProvider;
-import com.huimv.produce.sgd.fbox.TokenManager;
-import com.huimv.produce.sgd.fbox.models.BoxGroup;
-import com.huimv.produce.sgd.fbox.models.BoxReg;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class Main {
-    private static final long SLEEP_TIME = 1000;
-
-    public static void main(String[] args) throws IOException, InterruptedException {
-        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
-        // 指定连接服务器的凭据参数
-        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
-        ServerCaller appServer = new ServerCaller(tokenManager, Global.appServerApiUrl, Global.signalrClientId, loggerFactory);
-        ServerCaller apiBaseServer = new ServerCaller(tokenManager, Global.apiBaserUrl, Global.signalrClientId, loggerFactory);
-        Global.appServer = appServer;
-        Global.apiBaseServer = apiBaseServer;
-
-        BoxGroup[] boxGroups = appServer.executeGet("api/client/box/grouped", BoxGroup[].class);
-        // 返回的是 盒子分组-盒子注册项(BoxReg) 的二层结构
-        List<Map> list = new ArrayList();
-        for (BoxGroup group : boxGroups) {
-            //盒子
-            for (BoxReg boxReg : group.boxRegs) {
-                if (boxReg.alias.contains("环控")){
-                    Monitory[] monitories = apiBaseServer.executeGet("/v2/box/" + boxReg.boxUid + "/dmon/grouped", Monitory[].class);
-                    //每个监控点
-                    List<Map> groupnames = new ArrayList();
-                    for (Monitory monitory : monitories) {
-//                        System.out.println("监控点------------->" + monitory.toString());
-                       List names = new ArrayList();
-                        for (Item item : monitory.items) {
-                            String name = item.name;
-                            if ( monitory.name.contains("每个房间") && name != null ) {
-                                if (name.contains("平均温度") || name.contains("湿度") ||name.contains("日用水量") ||name.contains("月用水量")  ) {
-                                    names.add(name);
-                                }
-                            }
-
-                        }
-                                              Map map = new HashMap();
-
-                        if (ObjectUtil.isNotEmpty(names)) {
-                            MonitoryValue[] monitoryValues = apiBaseServer.executePost("/v2/box/" + boxReg.boxUid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
-                            StringBuilder str = new StringBuilder();
-                            for (MonitoryValue monitoryValue : monitoryValues) {
-                                if (ObjectUtil.isNotEmpty(monitory)) {
-                                    str.append(JSONUtil.toJsonStr(monitoryValue));
-                                }
-
-                            }
-                            map.put("monitoryValues", str);
-                            map.put("grpName", monitory.name);
-//                        map.put("names",names);
-                            groupnames.add(map);
-                        }
-                    }
-
-                    if (ObjectUtil.isNotEmpty(groupnames)){
-                        Map map = new HashMap();
-                        map.put("name",boxReg.alias);
-                        map.put("groupnames",groupnames);
-
-                        list.add(map);
-                    }
-                }
-            }
-        }
-
-        for (Map map : list) {
-            System.out.println(map.get("name")+"----->"+map.get("groupnames"));
-        }
-
-
-    }
-
-
-
-
-   /* private static final long SLEEP_TIME = 3000;
-    public static void main(String[] args) {
-
-        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
-
-        // 指定连接服务器的凭据参数
-        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
-
-        ServerCaller commServer = new ServerCaller(tokenManager, Global.commServerApiUrl, Global.signalrClientId, loggerFactory);
-        ServerCaller appServer = new ServerCaller(tokenManager, Global.appServerApiUrl, Global.signalrClientId, loggerFactory);
-        ServerCaller hdataServer = new ServerCaller(tokenManager, Global.hdataServerApiUrl, Global.signalrClientId, loggerFactory);
-
-        Global.commServer = commServer;
-        Global.appServer = appServer;
-        Global.hdataServer = hdataServer;
-
-        //建立signalr实例,signalr为单例模式
-        FBoxSignalRConnection fboxSignalR = new FBoxSignalRConnection(Global.commServerSignalRUrl, Global.signalrClientId, tokenManager, Global.proxy, loggerFactory);
-
-        // 连接SignalR推送通道
-        fboxSignalR.start();
-//        fboxSignalR.onHubProxyCreated();
-        // signalr连上后,请看src/main/java/FBoxSignalRConnection.java 接受推送数据的回调类。
-
-        System.out.println("Box list:");
-//        try {
-//以下为调接口示例,可忽略,若使用,参数请根据文档填写自己的账号下的参数
-
-        // 获取盒子列表接口示例,可忽略
-        try {
-            BoxGroup[] boxGroups = Global.appServer.executeGet("api/client/box/grouped", BoxGroup[].class);
-            // 返回的是 盒子分组-盒子注册项(BoxReg) 的二层结构
-//            for (BoxGroup group : boxGroups) {
-//                for (BoxReg boxReg : group.boxRegs) {
-//                    System.out.printf("\t%s\t%s\t%s\n", boxReg.alias, boxReg.box.boxNo, boxReg.box.boxType);
-//                }
-//            }
-//            commServer.executePost("box/300220120152/dmon/start", Object.class);
-            for (BoxGroup boxGroup : boxGroups) {
-                for (BoxReg boxReg : boxGroup.boxRegs) {
-                    commServer.executePost("box/" + boxReg.boxUid +"/dmon/start", Object.class);
-                    Thread.sleep(1000);
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-//        try {
-//            JsonObject jsonObject = commServer.executePost("dmon/222171502968050130/start", JsonObject.class);
-//        } catch (IOException e) {
-//            System.out.println("调用失败!");
-//            e.printStackTrace();
-//        }
-
-//        try {
-//            commServer.executePost("box/-6025651360718913057/dmon/start", Object.class);
-//        } catch (Exception e) {
-//            System.out.println("500");
-//            e.printStackTrace();
-//        }
-        System.out.println("测试");
-
-
-
-//
-//            // 获取按通道的数据接口示例 (数组第1维是固定两个元素时间和值,第2维是单个通道的所有数据,第3维是请求的每个通道)
-//            Object[][][] result =
-////                    String  result =
-//                    Global.hdataServer.executePost(String.format("v2/hdata/get"),
-//                            new GetByChannelHdataArgs(channelIds, new Date().getTime() - 7 * 86400000, new Date().getTime(), -100, 3),
-////                    String.class);
-//                            Object[][][].class);
-//
-//            System.out.println(result);
-//
-//            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
-//
-//            for (int i = 0; i < result.length; i++) {
-//                Object[][] channel = result[i];
-//                System.out.print("Channel " + channelNames.get(i));
-//                for (Object[] datum : channel) {
-//                    System.out.printf("(%s: %s)", dateFormatter.format(new Date(Math.round((double) datum[0]))), datum[1]);
-//                }
-//                System.out.println();
-//            }
-//
-//            //获取按行的数据接口示例(每行固定有通道个数个数据,如果这行的时间某些通道没有值,则为null)
-//            ByRowHdata result2 =
-////            String result2 =
-//                    Global.hdataServer.executePost(String.format("v2/hdata/get"),
-//                            new GetByRowHdataArgs(channelIds, new Date().getTime() - 7 * 86400000, new Date().getTime(), -100, 3),
-////                            String.class);
-//                            ByRowHdata.class);
-////            System.out.println(result2);
-//
-//            for (ByRowHdataRow row : result2.rows) {
-//                System.out.print(dateFormatter.format(row.getTime()) + ": ");
-//                Object[] c = row.c;
-//                for (int i = 0; i < c.length; i++) {
-//                    Object value = c[i];
-//                    if (i == 0) {
-//                        System.out.printf("%s", value);
-//                    } else {
-//                        System.out.printf(",%s", value);
-//                    }
-//                }
-//                System.out.println();
-//            }
-
-
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        }
-//
-//
-//        Scanner s = new Scanner(System.in);
-//        s.nextLine();
-    }*/
-
-
-}

+ 0 - 24
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/Item.java

@@ -1,24 +0,0 @@
-package com.huimv.produce.sgd.entity;
-
-
-public class Item {
-
-    public String id;
-
-    public String name;
-
-    public String devAlias;
-
-    public String dataType;
-    public String grpName;
-
-    @Override
-    public String toString() {
-        return "Items{" +
-                "id='" + id + '\'' +
-                ", name='" + name + '\'' +
-                ", devAlias='" + devAlias + '\'' +
-                ", dataType='" + dataType + '\'' +
-                '}';
-    }
-}

+ 0 - 20
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/Monitory.java

@@ -1,20 +0,0 @@
-package com.huimv.produce.sgd.entity;
-
-
-import java.util.Arrays;
-
-public class Monitory {
-    public String id;
-    public String name;
-    public Item[] items;
-
-
-    @Override
-    public String toString() {
-        return "Monitory{" +
-                "id='" + id + '\'' +
-                ", name='" + name + '\'' +
-                ", items=" + Arrays.toString(items) +
-                '}';
-    }
-}

+ 0 - 27
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/MonitoryGetArgs.java

@@ -1,27 +0,0 @@
-package com.huimv.produce.sgd.entity;
-
-
-import java.util.List;
-
-public class MonitoryGetArgs {
-    public List names;
-    public Long timeOut;
-    public List groupnames;
-    public MonitoryGetArgs() {
-    }
-    public MonitoryGetArgs(List names, Long timeOut, List groupnames) {
-        this.names = names;
-        this.timeOut = timeOut;
-        this.groupnames = groupnames;
-    }
-
-
-    @Override
-    public String toString() {
-        return "Test{" +
-                "names=" + names +
-                ", timeOut=" + timeOut +
-                ", groupnames=" + groupnames +
-                '}';
-    }
-}

+ 0 - 122
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/MonitoryValue.java

@@ -1,122 +0,0 @@
-package com.huimv.produce.sgd.entity;
-
-
-import java.util.Date;
-
-public class MonitoryValue {
-
-    //监控点id
-    private  String id;
-
-    //时间戳,由于从缓存里拉的数据,所以需要时间戳来判断是否已经过期,UTC 时间
-    private Date timestamp;
-
-    //数据类型,见附录二
-    private int dataType;
-
-    //值
-    private Object value;
-
-    //监控点名称
-    private String name;
-
-    //盒子id
-    private long boxId;
-
-    //监控点状态,0:正常,1:无数据,2:超时,3:错误,4:Socket 异常,5:FDS 错误,16:未完成
-    private int status;
-
-    //盒子连接状态, 0:未知 , 1:已连接 ,2:超时, 3:断开
-    private int connState;
-
-    //盒子的上线时间
-    private  Date connStateTimestamp ;
-
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public Date getTimestamp() {
-        return timestamp;
-    }
-
-    public void setTimestamp(Date timestamp) {
-        this.timestamp = timestamp;
-    }
-
-    public int getDataType() {
-        return dataType;
-    }
-
-    public void setDataType(int dataType) {
-        this.dataType = dataType;
-    }
-
-    public Object getValue() {
-        return value;
-    }
-
-    public void setValue(Object value) {
-        this.value = value;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public long getBoxId() {
-        return boxId;
-    }
-
-    public void setBoxId(long boxId) {
-        this.boxId = boxId;
-    }
-
-    public int getStatus() {
-        return status;
-    }
-
-    public void setStatus(int status) {
-        this.status = status;
-    }
-
-    public int getConnState() {
-        return connState;
-    }
-
-    public void setConnState(int connState) {
-        this.connState = connState;
-    }
-
-    public Date getConnStateTimestamp() {
-        return connStateTimestamp;
-    }
-
-    public void setConnStateTimestamp(Date connStateTimestamp) {
-        this.connStateTimestamp = connStateTimestamp;
-    }
-
-    @Override
-    public String toString() {
-        return "MonitoryValue{" +
-                "id='" + id + '\'' +
-                ", timestamp=" + timestamp +
-                ", dataType=" + dataType +
-                ", value=" + value +
-                ", name='" + name + '\'' +
-                ", boxId=" + boxId +
-                ", status=" + status +
-                ", connState=" + connState +
-                ", connStateTimestamp=" + connStateTimestamp +
-                '}';
-    }
-}

+ 0 - 18
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/BoxServerResponseException.java

@@ -1,18 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-import org.apache.http.client.HttpResponseException;
-
-public class BoxServerResponseException extends HttpResponseException {
-    public BoxServerResponseException(int statusCode, String s) {
-        super(statusCode, s);
-    }
-
-    public BoxServerResponseException(int statusCode, String s, int errCode) {
-        super(statusCode, s);
-        this.errCode = errCode;
-    }
-
-    public int errCode;
-
-
-}

+ 0 - 18
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ClientCredential.java

@@ -1,18 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public class ClientCredential {
-    public ClientCredential(String clientId, String clientSecret) {
-        this.clientId = clientId;
-        this.clientSecret = clientSecret;
-    }
-
-    /// <summary>
-    /// API账号
-    /// </summary>
-    public String clientId;
-
-    /// <summary>
-    /// API secret
-    /// </summary>
-    public String clientSecret;
-}

+ 0 - 34
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ConsoleLogger.java

@@ -1,34 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class ConsoleLogger implements Logger {
-    private final String name;
-    private final SimpleDateFormat formatter;
-
-    ConsoleLogger(String name) {
-        this.formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        this.name = name;
-    }
-
-    @Override
-    public void logInformation(String msg) {
-        System.out.println(formatter.format(new Date()) + " [Info ][" + name + "] " + msg);
-    }
-
-    @Override
-    public void logWarning(String msg) {
-        System.out.println(formatter.format(new Date()) + " [Warn ][" + name + "] " + msg);
-    }
-
-    @Override
-    public void logError(String msg) {
-        System.out.println(formatter.format(new Date()) + " [Error][" + name + "] " + msg);
-    }
-
-    @Override
-    public void logTrace(String msg) {
-        System.out.println(formatter.format(new Date()) + " [Trace][" + name + "] " + msg);
-    }
-}

+ 0 - 12
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ConsoleLoggerFactory.java

@@ -1,12 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public class ConsoleLoggerFactory implements LoggerFactory {
-    @Override
-    public Logger createLogger(String name) {
-        if (name == "FBoxSignalRConnection" || name == "SignalRConnectionBase" || name == "ServerCaller") {
-            return new ConsoleLogger(name);
-        }
-
-        return new NullLogger();
-    }
-}

+ 0 - 17
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/CredentialProvider.java

@@ -1,17 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public interface CredentialProvider {
-
-    /// <summary>
-    /// 获取用户密钥信息
-    /// </summary>
-    /// <returns></returns>
-    ClientCredential getClientCredential();
-
-    /// <summary>
-    /// 获取用户信息
-    /// </summary>
-    /// <returns></returns>
-    UserCredential getUserCredential();
-
-}

+ 0 - 10
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/Logger.java

@@ -1,10 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public interface Logger{
-    void logInformation(String msg);
-    void logWarning(String msg);
-    void logError(String msg);
-    void logTrace(String msg);
-}
-
-

+ 0 - 5
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/LoggerFactory.java

@@ -1,5 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public interface LoggerFactory {
-    Logger createLogger(String name);
-}

+ 0 - 9
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/LoginFailedException.java

@@ -1,9 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-import org.apache.http.client.HttpResponseException;
-
-public class LoginFailedException extends HttpResponseException {
-    public LoginFailedException(int statusCode, String s) {
-        super(statusCode, s);
-    }
-}

+ 0 - 23
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/NullLogger.java

@@ -1,23 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public class NullLogger implements Logger {
-    @Override
-    public void logInformation(String msg) {
-        
-    }
-
-    @Override
-    public void logWarning(String msg) {
-
-    }
-
-    @Override
-    public void logError(String msg) {
-
-    }
-
-    @Override
-    public void logTrace(String msg) {
-
-    }
-}

+ 0 - 301
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ServerCaller.java

@@ -1,301 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonSyntaxException;
-import org.apache.http.*;
-import org.apache.http.client.HttpResponseException;
-import org.apache.http.client.ServiceUnavailableRetryStrategy;
-import org.apache.http.client.methods.*;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.client.cache.CacheConfig;
-import org.apache.http.impl.client.cache.ExponentialBackOffSchedulingStrategy;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.util.EntityUtils;
-
-import javax.net.ssl.SSLException;
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.net.MalformedURLException;
-import java.net.SocketException;
-import java.net.URI;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-public class ServerCaller {
-    private static final long RETRY_SLEEP_TIME_MILLIS = 2000;
-    private static ArrayList<Class<?>> exceptionWhitelist = new ArrayList<>();
-    private static ArrayList<Class<?>> exceptionBlacklist = new ArrayList<>();
-
-    static {
-        // Retry if the server dropped connection on us
-        exceptionWhitelist.add(NoHttpResponseException.class);
-        // retry-this, since it may happens as part of a Wi-Fi to 3G failover
-        exceptionWhitelist.add(UnknownHostException.class);
-        // retry-this, since it may happens as part of a Wi-Fi to 3G failover
-        exceptionWhitelist.add(SocketException.class);
-
-        // never retry timeouts
-        exceptionBlacklist.add(InterruptedIOException.class);
-        // never retry SSL handshake failures
-        exceptionBlacklist.add(SSLException.class);
-    }
-
-    private final String baseUrl;
-    private final String signalrClientId;
-    private final Gson gson;
-    private final Logger logger;
-    private CloseableHttpClient http;
-    private TokenManager tokenManager;
-    private String accessToken;
-    private int maxRetries = 30;
-
-    public ServerCaller(TokenManager tokenManager, LoggerFactory loggerFactory) throws MalformedURLException {
-        this(tokenManager, null, null, loggerFactory);
-    }
-
-    public ServerCaller(TokenManager tokenManager, String signalrClientId, LoggerFactory loggerFactory) {
-        this(tokenManager, null, signalrClientId, null, null, loggerFactory);
-    }
-
-    public ServerCaller(TokenManager tokenManager, String baseUrl, String signalrClientId, LoggerFactory loggerFactory) {
-        this(tokenManager, baseUrl, signalrClientId, null, null, loggerFactory);
-    }
-
-    public ServerCaller(TokenManager tokenManager, String baseUrl, String signalrClientId, CloseableHttpClient http, HttpHost proxy, LoggerFactory loggerFactory) {
-        logger = loggerFactory.createLogger("ServerCaller");
-        this.baseUrl = baseUrl;
-        this.tokenManager = tokenManager;
-        this.signalrClientId = signalrClientId;
-        this.http = http;
-
-        this.gson = new GsonBuilder().create();
-
-        ArrayList<Header> headers = new ArrayList<>();
-        if (signalrClientId != null) {
-            headers.add(new BasicHeader("X-FBox-ClientId", signalrClientId));
-        }
-
-        if (http == null) {
-            CacheConfig cc = CacheConfig.DEFAULT;
-            ExponentialBackOffSchedulingStrategy ebo = new ExponentialBackOffSchedulingStrategy(cc);
-
-            HttpClientBuilder httpBuilder = HttpClients.custom()
-                    .setDefaultHeaders(headers).setServiceUnavailableRetryStrategy(new ServiceUnavailableRetryStrategy() {
-                        @Override
-                        public boolean retryRequest(HttpResponse response, int executionCount, HttpContext context) {
-                            if (executionCount > maxRetries)
-                                return false;
-                            if (response == null) {
-                                return false;
-                            }
-                            if (response.getStatusLine()== null) {
-                                return false;
-                            }
-                            switch (response.getStatusLine().getStatusCode()) {
-//                                case 401:
-//                                    Object otm = context.getAttribute("ServerCaller");
-//                                    if (otm == null)
-//                                        return false;
-//
-//                                    ServerCaller tm = (ServerCaller) otm;
-//                                    try {
-//                                        tm.accessToken = tm.tokenManager.getOrUpdateToken(tm.accessToken);
-//                                    } catch (IOException e) {
-//                                        System.err.printf("Error fetching token in service unavailable retry logic %s.\n", e.toString());
-//                                        return true;
-//                                    }
-//
-//                                    HttpClientContext clientContext = HttpClientContext.adapt(context);
-//                                    clientContext.getRequest().setHeader("Authorization", "Bearer " + tm.accessToken);
-//                                    return true;
-
-                                case HttpStatus.SC_BAD_GATEWAY:
-                                case HttpStatus.SC_SERVICE_UNAVAILABLE:
-                                    return true;
-                                default:
-                                    return false;
-                            }
-                        }
-
-                        @Override
-                        public long getRetryInterval() {
-                            return 1000;
-                        }
-                    })
-                    .setRetryHandler((exception, executionCount, context) -> {
-                        if (exception != null) {
-                            System.err.printf("Retrying due to %s.\n", exception.toString());
-                        }
-                        if (executionCount > maxRetries) {
-                            // Do not retry if over max retry count
-                            System.err.printf("Maxmimum retry count reached.\n");
-                            return false;
-                        } else if (isInList(exceptionBlacklist, exception)) {
-                            // immediately cancel retry if the error is blacklisted
-                            return false;
-                        } else if (isInList(exceptionWhitelist, exception)) {
-                            // immediately retry if error is whitelisted
-                        }
-
-                        HttpClientContext clientContext = HttpClientContext.adapt(context);
-                        if (clientContext == null) {
-                            return true;
-                        }
-
-                        HttpRequest request = clientContext.getRequest();
-                        if (request == null) {
-                            return true;
-                        }
-
-                        HttpResponse response = clientContext.getResponse();
-                        if (response == null) {
-                            return true;
-                        }
-                        StatusLine statusLine = response.getStatusLine();
-
-                        if (statusLine != null && statusLine.getStatusCode() == 401) {
-                            try {
-                                System.err.println("ServerCaller: try get another token for " + request.toString());
-                                this.accessToken = this.tokenManager.getOrUpdateToken(this.accessToken);
-                                request.setHeader("Authorization", "Bearer " + this.accessToken);
-                                return true;
-                            } catch (IOException e) {
-                                System.err.printf("Error fetching token in retry logic %s.\n", e.toString());
-                            }
-                        } else {
-
-                        }
-
-                        try {
-                            Thread.sleep(RETRY_SLEEP_TIME_MILLIS);
-                        } catch (InterruptedException e) {
-                        }
-                        return true;
-                    });
-            if (proxy != null)
-                httpBuilder = httpBuilder.setProxy(proxy);
-            this.http = httpBuilder.build();
-        }
-    }
-
-    protected boolean isInList(ArrayList<Class<?>> list, Throwable error) {
-        Iterator<Class<?>> itr = list.iterator();
-        while (itr.hasNext()) {
-            if (itr.next().isInstance(error)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public <T> T executeGet(String url, Class<T> responseType) throws IOException {
-        HttpGet request;
-        request = new HttpGet(baseUrl + url);
-        return executeCore(request, responseType);
-    }
-
-    public <T> T executePost(String url, Class<T> responseType) throws IOException {
-        return executePost(url, null, responseType);
-    }
-
-    public <T> T executePost(String url, Object entity, Class<T> responseType) throws IOException {
-        HttpPost request;
-        request = new HttpPost(baseUrl + url);
-        if (entity != null) {
-            String str = gson.toJson(entity);
-            request.setEntity(new StringEntity(str, ContentType.APPLICATION_JSON));
-        }
-        return executeCore(request, responseType);
-    }
-
-    public <T> T executePost(String url, HttpEntity body, Class<T> responseType) throws IOException {
-        HttpPost request;
-        request = new HttpPost(baseUrl + url);
-        if (body != null)
-            request.setEntity(body);
-        return executeCore(request, responseType);
-    }
-
-    public <T> T executePut(String url, HttpEntity body, Class<T> responseType) throws IOException {
-        HttpPut request;
-        request = new HttpPut(baseUrl + url);
-        request.setEntity(body);
-        return executeCore(request, responseType);
-    }
-
-    public <T> T executeDelete(String url, Class<T> responseType) throws IOException {
-        HttpDelete request;
-        request = new HttpDelete(baseUrl + url);
-        return executeCore(request, responseType);
-    }
-
-    private <T> T executeCore(HttpUriRequest request, Class<T> responseType) throws IOException {
-        if (this.accessToken == null) {
-            this.accessToken = this.tokenManager.getOrUpdateToken(this.accessToken);
-        }
-        request.setHeader("Authorization", "Bearer " + this.accessToken);
-        request.addHeader("Accept", "application/json; */*");
-        for (; ; ) {
-            String method = request.getMethod();
-            URI uri = request.getURI();
-         //   this.logger.logTrace(String.format("Executing request %s %s", method, uri));
-            CloseableHttpResponse response = null;
-            BasicHttpContext ctx = new BasicHttpContext();
-            ctx.setAttribute("ServerCaller", this);
-            try {
-                response = this.http.execute(request, ctx);
-            } catch (IOException e) {
-                System.err.printf("Request failed with error: %s.\n", e.toString());
-                throw e;
-            }
-            try {
-                StatusLine statusLine = response.getStatusLine();
-                if (statusLine == null)
-                    throw new HttpResponseException(0, "Null status line.");
-                int statusCode = statusLine.getStatusCode();
-              //  this.logger.logTrace(String.format("Executed request %s %s with code %d", method, uri, statusCode));
-                if (statusCode == 401) {
-//                    throw new HttpResponseException(401, "Unauthorized request");
-                    this.logger.logTrace("ServerCaller: 401 from " + request.getURI().toString());
-                    this.accessToken = this.tokenManager.getOrUpdateToken(this.accessToken);
-                    request.setHeader("Authorization", "Bearer " + this.accessToken);
-                    continue;
-                } else if (statusCode >= 300) {
-                    String exmsg = statusLine.getReasonPhrase();
-                    Header errCodeHeader = response.getFirstHeader("X-FBox-Code");
-                    int errCode = 0;
-                    if (errCodeHeader != null) {
-                        errCode = Integer.parseInt(errCodeHeader.getValue());
-                        exmsg += " code=" + errCode;
-                    }
-                    throw new BoxServerResponseException(statusCode, exmsg, errCode);
-                }
-                HttpEntity body = response.getEntity();
-                if (body != null && responseType != null) {
-                    String str = EntityUtils.toString(body);
-                    try {
-                        return gson.fromJson(str, responseType);
-                    } catch (JsonSyntaxException ex) {
-                        if (responseType.isAssignableFrom(String.class))
-                            return (T) str;
-                        else
-                            throw new IllegalArgumentException("Response cannot be parsed to " + responseType.toString() + " contentType is " + body.getContentType());
-                    }
-                }
-//                this.logger.logTrace(String.format("Request %s %s returned with empty body.", method, uri));
-                return null;
-            } finally {
-                response.close();
-            }
-        }
-    }
-}

+ 0 - 21
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/StaticCredentialProvider.java

@@ -1,21 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public class StaticCredentialProvider implements CredentialProvider {
-    private final ClientCredential clientCred;
-    private final UserCredential userCred;
-
-    public StaticCredentialProvider(String clientId, String clientSecret, String userName, String password) {
-        this.clientCred = new ClientCredential(clientId, clientSecret);
-        this.userCred = new UserCredential(userName, password);
-    }
-
-    @Override
-    public ClientCredential getClientCredential() {
-        return clientCred;
-    }
-
-    @Override
-    public UserCredential getUserCredential() {
-        return userCred;
-    }
-}

+ 0 - 132
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/TokenManager.java

@@ -1,132 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import org.apache.http.HttpEntity;
-import org.apache.http.NameValuePair;
-import org.apache.http.StatusLine;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpResponseException;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ContentType;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.message.BasicNameValuePair;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
-
-public class TokenManager implements Closeable {
-    private final CredentialProvider credentialProvider;
-    private final Object tokenLock;
-    private final Gson gson;
-    private final Logger logger;
-    private CloseableHttpClient http;
-    private final String idSvrUrl;
-
-    public TokenManager(CredentialProvider credentialProvider, LoggerFactory loggerFactory) {
-        this(credentialProvider, "https://account.flexem.com/core/", loggerFactory);
-    }
-
-    public TokenManager(CredentialProvider credentialProvider, String idSvrUrl, LoggerFactory loggerFactory) {
-        this(credentialProvider, idSvrUrl, null, loggerFactory);
-    }
-
-    public TokenManager(CredentialProvider credentialProvider, String idSvrUrl, CloseableHttpClient http, LoggerFactory loggerFactory) {
-        this.logger = loggerFactory.createLogger("TokenManager");
-        this.idSvrUrl = idSvrUrl;
-        this.credentialProvider = credentialProvider;
-        this.tokenLock = new Object();
-        this.http = http;
-        if (http == null) {
-            this.http = HttpClients.createDefault();
-        }
-        this.gson = new GsonBuilder().create();
-    }
-
-    private String accessToken;
-
-    public String getOrUpdateToken(String currentToken) throws IOException {
-        if (currentToken == null) {
-            String at = accessToken;
-            if (at != null)
-                return at;
-        }
-
-        synchronized (tokenLock) {
-            String at = accessToken;
-            if (at != null && at != currentToken)
-                return at;
-
-            at = fetchToken();
-            accessToken = at;
-            return at;
-        }
-    }
-
-    private String fetchToken() throws IOException {
-        ClientCredential clientCredential = credentialProvider.getClientCredential();
-        UserCredential userCredential = credentialProvider.getUserCredential();
-        // 登录接口,用于获取access_Token,access_Token有效期2小时
-        HttpPost request = new HttpPost(idSvrUrl + "connect/token");
-        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
-        formparams.add(new BasicNameValuePair("username", userCredential.userName));
-        formparams.add(new BasicNameValuePair("password", userCredential.password));
-        formparams.add(new BasicNameValuePair("scope", "openid offline_access fbox email profile"));
-        formparams.add(new BasicNameValuePair("client_id", clientCredential.clientId));
-        formparams.add(new BasicNameValuePair("client_secret", clientCredential.clientSecret));
-        formparams.add(new BasicNameValuePair("grant_type", "password"));
-        request.setEntity(new UrlEncodedFormEntity(formparams));
-        CloseableHttpResponse response = http.execute(request);
-        //401
-        final RequestConfig params = RequestConfig.custom().setConnectTimeout(8000).setSocketTimeout(8000).build();
-        request.setConfig(params);
-
-
-        try {
-            StatusLine statusLine = response.getStatusLine();
-            HttpEntity entity = response.getEntity();
-            int statusCode = statusLine.getStatusCode();
-            // the following status code range mostly caused by incorrect credential.
-            if (statusCode >= 400 && statusCode < 500 && statusCode != 429) {
-                throw new LoginFailedException(
-                        statusLine.getStatusCode(),
-                        statusLine.getReasonPhrase());
-            }
-            if (statusCode >= 300) {
-                throw new HttpResponseException(statusCode, statusLine.getReasonPhrase());
-            }
-            if (entity == null) {
-                throw new ClientProtocolException("Response contains no content");
-            }
-            ContentType contentType = ContentType.getOrDefault(entity);
-            Charset charset = contentType.getCharset();
-            Reader reader = new InputStreamReader(entity.getContent(), charset);
-            String at;
-            try {
-                at = (gson.fromJson(reader, TokenResponse.class)).access_token;
-            } finally {
-                reader.close();
-            }
-            this.logger.logTrace("Fetched new token.");
-            return at;
-        } finally {
-            response.close();
-        }
-    }
-
-    @Override
-    public void close() throws IOException {
-        if (this.http instanceof Closeable) {
-            ((Closeable) this.http).close();
-        }
-    }
-}

+ 0 - 5
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/TokenResponse.java

@@ -1,5 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public class TokenResponse {
-    public String access_token;
-}

+ 0 - 18
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/UserCredential.java

@@ -1,18 +0,0 @@
-package com.huimv.produce.sgd.fbox;
-
-public class UserCredential {
-    public UserCredential(String userName, String password) {
-        this.userName = userName;
-        this.password = password;
-    }
-
-    /// <summary>
-    /// 用户名
-    /// </summary>
-    public String userName;
-
-    /// <summary>
-    /// 密码
-    /// </summary>
-    public String password;
-}

+ 0 - 24
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/Box.java

@@ -1,24 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class Box {
-    public long id;
-    public String boxNo;
-    public int boxType;
-    public int connState;
-    public int net;
-    public int feat;
-    public Cs cs;
-
-    @Override
-    public String toString() {
-        return "Box{" +
-                "id=" + id +
-                ", boxNo='" + boxNo + '\'' +
-                ", boxType=" + boxType +
-                ", connState=" + connState +
-                ", net=" + net +
-                ", feat=" + feat +
-                ", cs=" + cs +
-                '}';
-    }
-}

+ 0 - 8
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxGroup.java

@@ -1,8 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class BoxGroup {
-    public long id;
-    public String name;
-    public BoxReg[] boxRegs;
-}
-

+ 0 - 18
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxReg.java

@@ -1,18 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class BoxReg {
-    public long id;
-    public String alias;
-    public String boxUid;
-    public Box box;
-
-    @Override
-    public String toString() {
-        return "BoxReg{" +
-                "id=" + id +
-                ", alias='" + alias + '\'' +
-                ", boxUid='" + boxUid + '\'' +
-                ", box=" + box +
-                '}';
-    }
-}

+ 0 - 7
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxStateChanged.java

@@ -1,7 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class BoxStateChanged {
-    public long id;
-    public int state;
-    public int net;
-}

+ 0 - 5
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/ByRowHdata.java

@@ -1,5 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class ByRowHdata {
-    public ByRowHdataRow[] rows;
-}

+ 0 - 19
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/ByRowHdataRow.java

@@ -1,19 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-import java.util.Date;
-
-public class ByRowHdataRow {
-    /**
-     * 时间戳(1970-1-1以来的毫秒数)
-     */
-    public long t;
-
-    public Date getTime (){
-        return new Date(t);
-    }
-
-    /**
-     * 一行中每个单元格的值
-     */
-    public Object[] c;
-}

+ 0 - 13
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/Cs.java

@@ -1,13 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-
-public class Cs {
-    public String signalRUrl;
-
-    @Override
-    public String toString() {
-        return "Cs{" +
-                "signalRUrl='" + signalRUrl + '\'' +
-                '}';
-    }
-}

+ 0 - 53
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DataSource.java

@@ -1,53 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class DataSource {
-    /**
-     * PLC别名
-     */
-    public String devAlias;
-
-    /**
-     * 站号
-     */
-    public int stationNo;
-
-    /**
-     * 数据类型
-     */
-    public int dataType;
-
-    /**
-     * 寄存器ID(与寄存器位宽联合使用)
-     */
-    public int regId;
-
-    /**
-     * 寄存器位宽 (与寄存器ID联合使用)
-     */
-    public int ioWidth;
-    /// <summary>
-    ///     寄存器名称
-    /// </summary>
-    public String regName;
-    /// <summary>
-    ///     主地址
-    /// </summary>
-    public int addr;
-    /// <summary>
-    ///     子地址
-    /// </summary>
-    public int subAddr;
-    /// <summary>
-    ///     数据块(DB块)
-    /// </summary>
-    public int addrBlk;
-    /// <summary>
-    /// 是否启用按位索引
-    /// </summary>
-    public boolean bitIndexEnabled;
-    /// <summary>
-    /// 按位索引号
-    /// </summary>
-    public int bitIndex;
-
-}

+ 0 - 76
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DataType.java

@@ -1,76 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;//package fbox.models;
-//
-//public enum DataType {
-//        /// <summary>
-//        /// 位
-//        /// </summary>
-//        Bit(0),
-//
-//            /// <summary>
-//            /// 16位无符号
-//            /// </summary>
-//        UInt16 = 1,
-//
-//            /// <summary>
-//            /// 16位有符号
-//            /// </summary>
-//        Int16 = 2,
-//
-//            /// <summary>
-//            /// 16位BCD
-//            /// </summary>
-//        Bcd16 = 3,
-//
-//            /// <summary>
-//            /// 16位16进制
-//            /// </summary>
-//        Hex16 = 4,
-//
-//            /// <summary>
-//            /// 16位二进制
-//            /// </summary>
-//        Binary16 = 5,
-//
-//            /// <summary>
-//            /// 32位无符号
-//            /// </summary>
-//            [Description("32位无符号")]
-//        UInt32 = 11,
-//
-//            /// <summary>
-//            /// 32位有符号
-//            /// </summary>
-//            [Description("32位有符号")]
-//        Int32 = 12,
-//
-//            /// <summary>
-//            /// 32位BCD
-//            /// </summary>
-//            [Description("32位BCD")]
-//        Bcd32 = 13,
-//
-//            /// <summary>
-//            /// 32位16进制
-//            /// </summary>
-//            [Description("32位16进制")]
-//        Hex32 = 14,
-//
-//            /// <summary>
-//            /// 32位二进制
-//            /// </summary>
-//            [Description("32位二进制")]
-//        Binary32 = 15,
-//
-//            /// <summary>
-//            /// 单精度浮点
-//            /// </summary>
-//            [Description("单精度浮点")]
-//        Single = 16,
-//
-//            /// <summary>
-//            /// 字符串
-//            /// </summary>
-//            [Description("字符串")]
-//        String = 30,
-//    }
-//}

+ 0 - 14
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DmonWriteValueArgs.java

@@ -1,14 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class DmonWriteValueArgs {
-    public DmonWriteValueArgs(String groupName, String name, String value) {
-        this.name = name;
-        this.value = value;
-        this.groupName = groupName;
-    }
-
-    public String name;
-    public int type = 0;
-    public String value;
-    public String groupName;
-}

+ 0 - 11
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetByChannelHdataArgs.java

@@ -1,11 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-import java.util.List;
-
-
-public class GetByChannelHdataArgs extends GetHdataArgs{
-    public GetByChannelHdataArgs(List<Long> ids, long begin, long end, int limit, int tr) {
-        super(1, ids, begin, end, limit, tr);
-    }
-}
-

+ 0 - 9
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetByRowHdataArgs.java

@@ -1,9 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-import java.util.List;
-
-public class GetByRowHdataArgs extends GetHdataArgs{
-    public GetByRowHdataArgs(List<Long> ids, long begin, long end, int limit, int tr) {
-        super(0, ids, begin, end, limit, tr);
-    }
-}

+ 0 - 9
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetDmonValuesById.java

@@ -1,9 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class GetDmonValuesById {
-    public GetDmonValuesById(long[] ids) {
-        this.ids = ids;
-    }
-
-    public long[] ids;
-}

+ 0 - 9
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetDmonValuesByName.java

@@ -1,9 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class GetDmonValuesByName {
-    public GetDmonValuesByName(String[] names) {
-        this.names = names;
-    }
-
-    public String[] names;
-}

+ 0 - 39
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetHdataArgs.java

@@ -1,39 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-import java.util.List;
-
-public class GetHdataArgs {
-    /**
-     * 通道ID列表
-     */
-    public List<Long> ids;
-    /**
-     * 开始时间(1970-1-1以来的毫秒数)
-     */
-    public long begin;
-    /**
-     * 结束时间(1970-1-1以来的毫秒数)
-     */
-    public long end;
-    /**
-     * 取值最大个数
-     * 正数表示从开始时间向结束时间取最多limit个,负值表示从结束时间向开始时间最多取limit个
-     */
-    public int limit;
-    /**
-     * 时间范围边界类型
-     * 0:全开区间, 1:左开右闭, 2: 左闭右开, 3:全闭区间
-     */
-    public int tr;
-
-    public int type;
-
-    public GetHdataArgs(int type, List<Long> ids, long begin, long end, int limit, int tr) {
-        this.ids = ids;
-        this.begin = begin;
-        this.end = end;
-        this.limit = limit;
-        this.tr = tr;
-        this.type = type;
-    }
-}

+ 0 - 33
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataChannelDef.java

@@ -1,33 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class HdataChannelDef extends DataSource {
-    /**
-     * 通道ID
-     */
-    public long uid;
-
-    /**
-     * 通道名称
-     */
-    public String name;
-
-    /**
-     * 单位
-     */
-    public String unit;
-
-    /**
-     * 描述
-     */
-    public String desc;
-
-    /**
-     * 整数位
-     */
-    public int intDigits;
-
-    /**
-     * 小数位
-     */
-    public int fracDigits;
-}

+ 0 - 5
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataControlOptions.java

@@ -1,5 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class HdataControlOptions extends DataSource {
-        public int ctrlType;
-}

+ 0 - 33
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataDef.java

@@ -1,33 +0,0 @@
-package com.huimv.produce.sgd.fbox.models;
-
-public class HdataDef {
-
-    public long uid;
-
-    /**
-     * 名称
-     */
-    public String name;
-
-    /**
-     * 采样时间
-     */
-    public int period;
-
-    /**
-     * 关联的盒子ID
-     */
-    public long boxId;
-
-    /**
-     * 是否使用使能设置
-     */
-    public boolean hasCtrl;
-
-    /**
-     * 使能控制详细配置
-     */
-    public HdataControlOptions ctrl;
-
-    public HdataChannelDef[] channels;
-}

+ 0 - 189
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/signalr/SignalRConnectionBase.java

@@ -1,189 +0,0 @@
-package com.huimv.produce.sgd.fbox.signalr;
-
-import com.github.signalr4j.client.ConnectionState;
-import com.github.signalr4j.client.http.java.JavaHttpConnection;
-import com.github.signalr4j.client.hubs.HubConnection;
-import com.github.signalr4j.client.hubs.HubProxy;
-import com.github.signalr4j.client.transport.ServerSentEventsTransport;
-import com.huimv.produce.sgd.fbox.Logger;
-import com.huimv.produce.sgd.fbox.LoggerFactory;
-import com.huimv.produce.sgd.fbox.LoginFailedException;
-import com.huimv.produce.sgd.fbox.TokenManager;
-
-import java.io.IOException;
-import java.net.Proxy;
-import java.util.Date;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-
-public abstract class SignalRConnectionBase {
-    private final Semaphore connectEvent;
-    private HubConnection hubConnection;
-    private HubProxy hubProxy;
-    private final Logger logger;
-    private final LoggerFactory loggerFactory;
-    private final SignalRLoggerWrapper javaconnLogger;
-    private final SignalRLoggerWrapper sseLogger;
-    private String hubUrl;
-    private String signalrClientId;
-    private Proxy proxy;
-    private TokenManager tokenManager;
-    private String accessToken;
-    private boolean shouldGetNewToken;
-    private int retryCount;
-    private long lastConnectedTime = 0;
-    private boolean reconnecting;
-    private boolean monitorStarted;
-
-    public SignalRConnectionBase(String hubUrl, String signalrClientId, TokenManager tokenManager, Proxy proxy, LoggerFactory loggerFactory) {
-        this.hubUrl = hubUrl;
-        this.signalrClientId = signalrClientId;
-        this.proxy = proxy;
-        this.loggerFactory = loggerFactory;
-        this.logger = loggerFactory.createLogger("SignalRConnectionBase");
-        this.sseLogger = new SignalRLoggerWrapper(this.loggerFactory.createLogger("ServerSentEventsTransport"));
-        this.javaconnLogger = new SignalRLoggerWrapper(this.loggerFactory.createLogger("SignalRTransportConnection"));
-        this.tokenManager = tokenManager;
-        this.connectEvent = new Semaphore(1);
-        new Thread(() -> {
-            try {
-                SignalRConnectWorker();
-            } catch (InterruptedException e) {
-                logger.logError("SignalR connect worker exited with " + e.toString());
-            }
-        }).start();
-    }
-
-    private void HookEvents() {
-        this.hubConnection.error(throwable -> onConnectionError(throwable));
-        this.hubConnection.reconnecting(() -> onReconnecting());
-        this.hubConnection.reconnected(() -> onReconnected());
-        this.hubConnection.closed(() -> onConnectionClosed());
-        this.hubConnection.connected(() -> connected());
-    }
-
-    private void UnhookEvents() {
-        this.hubConnection.error(null);
-        this.hubConnection.reconnecting(null);
-        this.hubConnection.reconnected(null);
-        this.hubConnection.closed(null);
-        this.hubConnection.connected(null);
-    }
-
-    private void onReconnecting() {
-        this.logger.logInformation("Reconnecting. hubconn=" + this.hubConnection.getUrl());
-    }
-
-    private void onReconnected() {
-        this.logger.logInformation("Reconnected. hubconn=" + this.hubConnection.getUrl());
-    }
-
-    private void onConnectionClosed() {
-        this.logger.logInformation("Closed. hubconn=" + this.hubConnection.getUrl());
-        this.connectEvent.release();
-    }
-
-    private void onConnectionError(Throwable e) {
-        this.logger.logInformation(String.format("Connection error. exception=%s. hubConnection=%s", e, this.hubConnection.getUrl()));
-        if (e != null) {
-            Throwable cause = e.getCause();
-            if (cause != null && cause.getMessage() != null && cause.getMessage().contains("401")) {
-                this.shouldGetNewToken = true;
-            }
-        }
-    }
-
-    protected abstract void onHubProxyCreated(HubProxy hubProxy);
-
-    protected abstract void onHubProxyDestroyed(HubProxy hubProxy);
-
-    public void connected() {
-        this.reconnecting = false;
-        this.logger.logInformation("Connected. hubconn=" + this.hubConnection.getUrl());
-    }
-
-    private void UpdateToken() throws LoginFailedException, InterruptedException {
-        int retryCount2 = 0;
-        for (; ; ) {
-            try {
-                this.accessToken = this.tokenManager.getOrUpdateToken(this.accessToken);
-                break;
-            } catch (LoginFailedException e) {
-                throw e;
-            } catch (IOException e) {
-                logger.logError("Get token failed. " + e.toString());
-                int waitTime2 = retryCount2++ * 1000;
-                if (waitTime2 > 300000) {
-                    waitTime2 = 5000;
-                }
-                Thread.sleep(waitTime2);
-            }
-        }
-    }
-
-    private void SignalRConnectWorker() throws InterruptedException {
-        //signalr重连代码
-        for (; ; ) {
-            do {
-//                this.logger.logTrace("Current connection state is " + this.hubConnection.getState());
-                this.connectEvent.acquire();
-            }
-            while (this.hubConnection != null && this.hubConnection.getState() == ConnectionState.Connected);
-
-            try {
-                //刷新token
-                UpdateToken();
-                if (this.hubConnection != null)
-                    this.UnhookEvents();
-                if (this.hubProxy != null) {
-                    onHubProxyDestroyed(this.hubProxy);
-                }
-                if (this.hubConnection != null)
-                    this.hubConnection.disconnect();
-                this.hubConnection = new HubConnection(hubUrl, "cid=" + signalrClientId, true, new SignalRLoggerWrapper(loggerFactory.createLogger("SignalR")));
-                this.hubConnection.setReconnectOnError(false);
-                this.HookEvents();
-                this.hubProxy = this.hubConnection.createHubProxy("clienthub");
-                this.onHubProxyCreated(this.hubProxy);
-                this.hubConnection.setCredentials(request -> request.addHeader("Authorization", "Bearer " + this.accessToken));
-                this.connectEvent.drainPermits();
-                this.hubConnection.start(new ServerSentEventsTransport(this.sseLogger, new JavaHttpConnection(this.javaconnLogger))).get(40, TimeUnit.SECONDS);
-                this.retryCount = 0;
-                this.shouldGetNewToken = false;
-                this.lastConnectedTime = new Date().getTime();
-            } catch (Exception e) {
-                assert hubConnection.getState() != ConnectionState.Connected;
-                if (e instanceof LoginFailedException) {
-                    this.logger.logError("Login error.");
-                } else {
-                    this.logger.logError("Hub connection start error. " + e.toString());
-                    e.printStackTrace();
-                }
-                Throwable cause = e.getCause();
-                if (cause != null) {
-                    String msg = cause.getMessage();
-                    if (msg != null && msg.contains("401"))
-                        this.shouldGetNewToken = true;
-                }
-
-                int waitTime = this.retryCount++ * 1000;
-                if (waitTime > 60000) {
-                    waitTime = 5000;
-                }
-
-                if (waitTime > 0)
-                    Thread.sleep(waitTime);
-                this.connectEvent.release();
-                this.reconnecting = true;
-            }
-        }
-    }
-
-    public void start() {
-        this.connectEvent.release();
-    }
-
-    public void stop() {
-        this.hubConnection.stop();
-    }
-}

+ 0 - 28
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/signalr/SignalRLoggerWrapper.java

@@ -1,28 +0,0 @@
-package com.huimv.produce.sgd.fbox.signalr;
-
-import com.github.signalr4j.client.LogLevel;
-import com.github.signalr4j.client.Logger;
-
-public class SignalRLoggerWrapper implements Logger {
-
-    private final  com.huimv.produce.sgd.fbox.Logger logger;
-
-    public SignalRLoggerWrapper( com.huimv.produce.sgd.fbox.Logger logger){
-        this.logger = logger;
-    }
-    @Override
-    public void log(String message, LogLevel level) {
-        switch (level) {
-            case Critical:
-                this.logger.logError(message);
-                break;
-            case Information:
-                this.logger.logInformation(message);
-                break;
-            case Verbose:
-                this.logger.logTrace(message);
-                break;
-        }
-    }
-
-}

+ 270 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/utils/DateUtil.java

@@ -0,0 +1,270 @@
+package com.huimv.produce.utils;
+
+import cn.hutool.core.date.DateTime;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+@Slf4j
+public class DateUtil {
+    /**
+     * 获取今天
+     * @return String
+     * */
+    public String getToday(){
+        return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+    }
+    /**
+     * 获取昨天
+     * @return String
+     * */
+    public String getYestoday(){
+        Calendar cal=Calendar.getInstance();
+        cal.add(Calendar.DATE,-1);
+        Date time=cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+    /**
+     * 获取本月开始日期
+     * @return String
+     * **/
+    public String getMonthStart(){
+        Calendar cal=Calendar.getInstance();
+        cal.add(Calendar.MONTH, 0);
+        cal.set(Calendar.DAY_OF_MONTH, 1);
+        Date time=cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+    /**
+     * 获取本月最后一天
+     * @return String
+     * **/
+    public String getMonthEnd(){
+        Calendar cal=Calendar.getInstance();
+        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
+        Date time=cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+    /**
+     * 获取本周的第一天
+     * @return String
+     * **/
+    public String getWeekStart(){
+        Calendar cal=Calendar.getInstance();
+        cal.add(Calendar.WEEK_OF_MONTH, 0);
+        cal.set(Calendar.DAY_OF_WEEK, 2);
+        Date time=cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+    /**
+     * 获取本周的最后一天
+     * @return String
+     * **/
+    public String getWeekEnd(){
+        Calendar cal=Calendar.getInstance();
+        cal.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
+        cal.add(Calendar.DAY_OF_WEEK, 1);
+        Date time=cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+    /**
+     * 获取本年的第一天
+     * @return String
+     * **/
+    public String getYearStart(){
+        return new SimpleDateFormat("yyyy").format(new Date())+"-01-01";
+    }
+
+    /**
+     * 获取本年的最后一天
+     * @return String
+     * **/
+    public String getYearEnd(){
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.MONTH,calendar.getActualMaximum(Calendar.MONTH));
+        calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+        Date currYearLast = calendar.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(currYearLast)+" 23:59:59";
+    }
+
+    //Long转换为Date格式
+    public String fromLongToDate(Long time ,String format) {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        Date date = new Date(time);
+        return sdf.format(date);
+    }
+
+    public String formatTimestampToDatetime(Timestamp timestamp){
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sdf.format(timestamp);
+    }
+
+    public String formatTimestampToDate(Timestamp timestamp){
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(timestamp);
+    }
+
+    //格式化本年
+    public String getThisYear(){
+        Calendar cal = Calendar.getInstance();
+        int year = cal.get(Calendar.YEAR);
+        return String.valueOf(year);
+    }
+
+    //格式化本月
+    public String getThisMonth(){
+        Calendar cal = Calendar.getInstance();
+        int month = cal.get(Calendar.MONTH) + 1;
+        if(String.valueOf(month).length()==1)
+        {
+            return "0"+String.valueOf(month);
+        }else{
+            return String.valueOf(month);
+        }
+    }
+
+    //格式化日期时间
+    public String formatDateTime(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = sdf.parse(dateText);
+        return sdf.format(date);
+    }
+
+    public Date parseDateTime(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sdf.parse(dateText);
+    }
+
+    public Date parseDate(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.parse(dateText);
+    }
+
+    public Long parseDateTimeLong(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = sdf.parse(dateText);
+        return date.getTime();
+    }
+
+
+
+    //
+    public Date getTodayDate() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.parse(sdf.format(new Date()));
+    }
+
+    public String getTodayDateText() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(new Date());
+    }
+
+    public String getTodayText() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sdf.format(new Date());
+    }
+
+    public String getTodayMissionText() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        return sdf.format(new Date());
+    }
+
+    public String getStartDateInThisMonth(){
+        DateTime date = cn.hutool.core.date.DateUtil.date();
+        return (cn.hutool.core.date.DateUtil.beginOfMonth(date) + "").substring(0, 10);
+    }
+
+    public String getEndDateInThisMonth(){
+        DateTime date = cn.hutool.core.date.DateUtil.date();
+        return (date + "").substring(0, 10);
+    }
+
+    /**
+     * 获取过去或者未来 任意天内的日期数组
+     * @param intervals      intervals天内
+     * @return              日期数组
+     */
+    public ArrayList<String> test(int intervals ) {
+        ArrayList<String> pastDaysList = new ArrayList<>();
+        ArrayList<String> fetureDaysList = new ArrayList<>();
+        for (int i = 0; i <intervals; i++) {
+            pastDaysList.add(getPastDate(i));
+            fetureDaysList.add(getFetureDate(i));
+        }
+        return pastDaysList;
+    }
+
+    /**
+     * 获取过去第几天的日期
+     *
+     * @param past
+     * @return
+     */
+    public String getPastDate(int past) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
+        Date today = calendar.getTime();
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        String result = format.format(today);
+        return result;
+    }
+
+    /**
+     * 获取未来 第 past 天的日期
+     * @param past
+     * @return
+     */
+    public String getFetureDate(int past) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
+        Date today = calendar.getTime();
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        String result = format.format(today);
+        return result;
+    }
+
+    //重新构建日期
+    public String rebuildDateTime(String text){
+        return text.substring(0,4)+"-"+text.substring(4,6)+"-"+text.substring(6,8)+" "+text.substring(8,10)+":"+text.substring(10,12)+":"+text.substring(12,14);
+    }
+
+    public static void main(String[] args){
+        DateUtil du = new DateUtil();
+        //
+        du.test1();
+    }
+
+    private void test1() {
+        String text = "20211201104300";
+//        String text = "1234567890abcd";
+        String date = text.substring(0,4)+"-"+text.substring(4,6)+"-"+text.substring(6,8)+" "+text.substring(8,10)+":"+text.substring(10,12)+":"+text.substring(12,14);
+        System.out.println("date="+date);
+    }
+}