ソースを参照

牧场取出环境报警,将环境报警放到数据中心端处理。

zhuoning 2 年 前
コミット
3b7c201e8b

+ 9 - 9
huimv-farm-device/huimv-farm-business/src/main/resources/application.properties

@@ -1,28 +1,28 @@
 #spring.profiles.active=dev
-spring.profiles.active=prod
+spring.profiles.active=prod2
 
-#时间格式配置
+#ʱ���ʽ����
 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
 spring.jackson.time-zone=GMT+8
 
-# 数据中心数据推送地
+# 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟酵碉拷
 dataCenter.ipAddr=http://120.27.234.126
 dataCenter.port=:8010
-#测试IP
+#锟斤拷锟斤拷IP
 #dataCenter.ipAddr=http://192.168.1.49
 #dataCenter.port=:10091
-# 日总称重数据服务
+# 锟斤拷锟杰筹拷锟斤拷锟斤拷锟捷凤拷锟斤拷
 dataCenter.service.dayWeight=/receiver/farm/weight/putDayWeight
-# 批次称重数据服务
+# 锟斤拷锟轿筹拷锟斤拷锟斤拷锟捷凤拷锟斤拷
 dataCenter.service.batchWeight=/receiver/farm/weight/putBatchWeight
-# 部署牧场ID(base_farm.id)
+# 锟斤拷锟斤拷锟斤拷锟斤拷ID锟斤拷base_farm.id锟斤拷
 local.farmID=1
-# 批次计算间隔
+# 锟斤拷锟轿硷拷锟斤拷锟斤拷
 weight.batch_interval=4
 weight.batch.prefix=W
 weight.batchCode.spacemark=-
 
-#数据中心端设备数据是否同步(true/false),默认是true(同步数据)
+#锟斤拷锟斤拷锟斤拷锟侥讹拷锟借备锟斤拷锟斤拷锟角凤拷同锟斤拷(true/false),默锟斤拷锟斤拷true锟斤拷同锟斤拷锟斤拷锟捷o拷
 dataCenter.device.sync=true
 dataCenter.device.addService=/center/device/syncAddFarmDevice
 dataCenter.device.editService=/center/device/syncEditFarmDevice

+ 3 - 0
huimv-farm-device/huimv-farm-cloud-environ/pom.xml

@@ -77,5 +77,8 @@
             <version>2.9.4</version>
         </dependency>
     </dependencies>
+<!--    <build>-->
+<!--        <finalName>environ</finalName>-->
+<!--    </build>-->
 
 </project>

+ 6 - 10
huimv-farm-device/huimv-farm-cloud-environ/src/main/java/com/huimv/environ/server/EnvironDataHandler.java

@@ -53,13 +53,7 @@ public class EnvironDataHandler {
 
     //
     public void handleReceiveData(String receiveData) throws ParseException {
-
-//        System.out.println("解析处理数据......");
         String[] receiveDataArray = receiveData.split(";");
-//        System.out.println("receiveDataArray="+receiveDataArray.length);
-//        for(int a=0;a<receiveDataArray.length;a++){
-//            System.out.println(a+" "+receiveDataArray[a]);
-//        }
         //System.currentTimeMillis()
         String stText = receiveDataArray[1];
         if(stText.indexOf("ST=") != -1){
@@ -84,11 +78,13 @@ public class EnvironDataHandler {
                         //保存分钟环保数据
                         EnvMinuteEntity envMinuteEntity = handleMinuteEnviron(farmID,st,cn,receiveDataArray);
 
-                        //发送分钟测试数据(测试)
-//                        environ.sendHourEnviron(JSON.toJSON(envMinuteEntity).toString());
+                        //发送分钟环保数据
+                        environ.sendMinuteEnviron(JSON.toJSON(envMinuteEntity).toString());
+                        //模拟/测试
+//                        environ.sendMinuteEnviron(JSON.toJSON(envMinuteEntity2).toString());
 
-                        //处理分钟环保数据报警
-                        environ.handleEnvironWarningInfo(JSON.toJSON(envMinuteEntity).toString());
+                        //处理分钟环保数据报警(阈值过滤放在服务端进行,牧场端暂时不处理)
+//                        environ.handleEnvironWarningInfo(JSON.toJSON(envMinuteEntity).toString());
                     }else  if(cn.trim().equalsIgnoreCase("2061")){
                         //小时采样数据
                         System.out.println(">>>>"+dateUtil.getTodayMissionText()+" -->当前处理小时采集数据.");

+ 1 - 1
huimv-farm-device/huimv-farm-cloud-environ/src/main/java/com/huimv/environ/server/EnvironServerHandler.java

@@ -45,10 +45,10 @@ public class EnvironServerHandler extends ChannelInboundHandlerAdapter{
 //        System.out.println(
 //                "Server received: " + in.toString(CharsetUtil.UTF_8)
 //        );
+
         System.out.println("接收到数据>>>>"+receiveData.trim());
         //处理接收环保实时数据
         environDataHandler.handleReceiveData(receiveData);
-//        handleReceiveData(receive);
 
         //将接收到的消息写给发送者,而不冲刷出站消息 (应答)
 //        ctx.write(in);

+ 4 - 0
huimv-farm-device/huimv-farm-cloud-environ/src/main/java/com/huimv/environ/service/IEnviron.java

@@ -17,4 +17,8 @@ public interface IEnviron {
     JSONArray getEnvironData();
 
     void handleEnvironWarningInfo(String data) throws ParseException;
+
+    void sendMinuteEnviron(String data);
+
+    void getMinuteEnv(Integer farmId);
 }

+ 43 - 0
huimv-farm-device/huimv-farm-cloud-environ/src/main/java/com/huimv/environ/service/impl/EnvironImpl.java

@@ -16,6 +16,7 @@ import com.huimv.environ.utils.HttpTemplete;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -24,6 +25,7 @@ import java.text.ParseException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * @Project : huimv.shiwan
@@ -54,6 +56,9 @@ public class EnvironImpl implements IEnviron {
     //小时数据服务
     @Value("${dataCenter.service.hourEnviron}")
     private String hourEnvironService;
+    //分钟数据服务
+    @Value("${dataCenter.service.minuteEnviron}")
+    private String hourMinuteService;
     //实时数据服务
     @Value("${dataCenter.service.realTimeEnviron}")
     private String realTimeEnvironService;
@@ -208,6 +213,44 @@ public class EnvironImpl implements IEnviron {
         }
     }
 
+    @Override
+    public void sendMinuteEnviron(String data) {
+        String url = ipAddr + port + hourMinuteService;
+        log.info("推送数据地址:"+url);
+        //
+        Map<String,String> paramsMap = new HashMap<String,String>();
+        paramsMap.put("data", data);
+        //
+        Map<String,Integer> timeoutMap = new HashMap<String,Integer>();
+        timeoutMap.put("connectTimeout", 5000);
+        timeoutMap.put("requestTimeout", 5000);
+        timeoutMap.put("socketTimeout", 5000);
+        try{
+            // 用Post方法推送接口数据
+            httpTemplete.doPost(url,paramsMap,timeoutMap);
+        } catch (IOException e) {
+            System.out.println("###错误信息:"+e.getMessage());
+        }
+    }
+
+    @Override
+    public void getMinuteEnv(Integer farmId) {
+        //读取分钟数据
+        EnvMinuteEntity envMinuteEntity = new EnvMinuteEntity();
+        envMinuteEntity.setId(129558);
+        Example<EnvMinuteEntity> example = Example.of(envMinuteEntity);
+        Optional<EnvMinuteEntity> opl = envMinuteRepo.findOne(example);
+        if(opl.isPresent()){
+            EnvMinuteEntity envMinuteEntity2 = opl.get();
+            //推送数据
+            sendMinuteEnviron(JSON.toJSON(envMinuteEntity2).toString());
+        }else{
+            System.out.println("数据不存在.");
+        }
+
+
+    }
+
     //向数据中心发送警报
     public void _sendAlarmToCenter(String alarmInfo,Integer alarmType) throws ParseException {
         log.info("警报内容>>"+alarmInfo);

+ 2 - 0
huimv-farm-device/huimv-farm-cloud-environ/src/main/resources/application.properties

@@ -12,6 +12,8 @@ dataCenter.port=:8010
 dataCenter.service.hourEnviron=/receiver/receiver/cloud/environ/putHourEnviron
 # ʵʱ�������ݷ���
 dataCenter.service.realTimeEnviron=/receiver/receiver/cloud/environ/putRealTimeEnviron
+# Minute data
+dataCenter.service.minuteEnviron=/receiver/receiver/cloud/environ/putMinuteEnviron
 # ������������
 dataCenter.service.alarm=/receiver/receiver/alarm/environ/putEnvironAlarm
 # ��������ID��base_farm.id��

+ 23 - 1
huimv-farm-device/huimv-farm-netip/src/main/java/com/huimv/huimvfarmnetip/utils/IPUtils.java

@@ -102,7 +102,29 @@ public class IPUtils {
         return false;
     }
 
-    public String run(String shellFile){
+    public String run(String file,String ip){
+        String[] shellFile = new String[]{"sh",file,ip};
+        try {
+            Process ps = Runtime.getRuntime().exec(shellFile);
+            ps.waitFor();
+
+            BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
+            StringBuffer sb = new StringBuffer();
+            String line;
+            while ((line = br.readLine()) != null) {
+                sb.append(line).append("\n");
+            }
+            String result = sb.toString();
+            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>"+result);
+            return result;
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public String run_old(String shellFile){
         try {
             Process ps = Runtime.getRuntime().exec(shellFile);
             ps.waitFor();

+ 6 - 1
huimv-farm-device/huimv-farm-netip/src/main/resources/application.properties

@@ -13,4 +13,9 @@ dataCenter.service.netIp=/receiver/ip/updateNetIp
 #farmID
 local.farmID=12
 local.shellFile=/opt/ip2/netIp.sh
-local.relay.port=:9080
+local.relay.port=:9080
+
+dataCenter.service.cameraService=/receiver/ip/cameraIp
+local.cameraFile=/opt/ip2/pingIp.sh
+
+

+ 4 - 0
huimv-farm-device/pom.xml

@@ -9,6 +9,9 @@
         <module>huimv-farm-business</module>
         <module>huimv-farm-dahua</module>
         <module>huimv-farm-eco</module>
+        <module>modbus</module>
+        <module>modbus2</module>
+        <module>test</module>
     </modules>
     <parent>
         <groupId>org.springframework.boot</groupId>
@@ -70,6 +73,7 @@
     </dependencies>
 
     <build>
+<!--        <finalName></finalName>-->
         <plugins>
             <plugin>
                 <groupId>org.springframework.boot</groupId>