Browse Source

接收服务

523096025 2 years ago
parent
commit
44998dd1c2

+ 26 - 26
huimv-admin/src/main/java/com/huimv/admin/config/InterceptorConfig.java

@@ -1,26 +1,26 @@
-package com.huimv.admin.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
-/**
- * @Description: 注册验证tocken的拦截器
- * @Author
- * @Date 2021/4/19 20:41
- * @Version V1.0
- */
-@Configuration
-public class InterceptorConfig implements WebMvcConfigurer {
-    @Bean
-    public JWTInterceptor jwtInterceptor(){
-        return new JWTInterceptor();
-    }
-
-    @Override
-    public void addInterceptors(InterceptorRegistry registry) {
-        registry.addInterceptor(jwtInterceptor()).
-                excludePathPatterns("/*/my/*");
-    }
-}
+//package com.huimv.admin.config;
+//
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+//
+///**
+// * @Description: 注册验证tocken的拦截器
+// * @Author
+// * @Date 2021/4/19 20:41
+// * @Version V1.0
+// */
+//@Configuration
+//public class InterceptorConfig implements WebMvcConfigurer {
+//    @Bean
+//    public JWTInterceptor jwtInterceptor(){
+//        return new JWTInterceptor();
+//    }
+//
+//    @Override
+//    public void addInterceptors(InterceptorRegistry registry) {
+//        registry.addInterceptor(jwtInterceptor()).
+//                excludePathPatterns("/*/my/*");
+//    }
+//}

+ 81 - 81
huimv-admin/src/main/java/com/huimv/admin/config/JWTInterceptor.java

@@ -1,81 +1,81 @@
-package com.huimv.admin.config;
-
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.admin.common.token.TokenConstant;
-import com.huimv.admin.common.token.TokenSign;
-import io.jsonwebtoken.Claims;
-import org.springframework.web.method.HandlerMethod;
-import org.springframework.web.servlet.HandlerInterceptor;
-import org.springframework.web.servlet.ModelAndView;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * <p>
- *  jwt拦截器
- * </p>
- * @since 2021/4/19
- */
-public class JWTInterceptor implements HandlerInterceptor {
-
-
-    @Override
-    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
-        // 如果不是映射到方法,则直接通过
-        if (!(handler instanceof HandlerMethod)) {
-            return true;
-        }
-
-        response.setContentType("application/json;charset=utf-8");
-        // 获取token
-        String token=request.getHeader("accessToken");
-
-
-        if (null==token){
-            Map<String,Object> map=new HashMap<>();
-            map.put("data","token is null");
-            map.put("code","401");
-            response.setStatus(401);
-            response.getWriter().write(JSONObject.toJSONString(map));
-            return false;
-        }else {
-            Claims claims = TokenSign.getClaims(token);
-            if (claims == null){
-                Map<String,Object> map=new HashMap<>();
-                map.put("data","token is overdue");
-                map.put("code","403");
-                response.setStatus(403);
-                response.getWriter().write(JSONObject.toJSONString(map));
-                return false;
-            }
-
-            boolean result= TokenSign.verify(token);
-            if (result){
-                //更新存储的token信息
-                TokenConstant.updateTokenMap(token);
-                return true;
-            }
-            Map<String,Object> map=new HashMap<>();
-            map.put("data","token is null");
-            map.put("code","401");
-            response.setStatus(401);
-            response.getWriter().write(JSONObject.toJSONString(map));
-            return false;
-
-        }
-    }
-
-
-    @Override
-    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
-
-    }
-
-    @Override
-    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
-
-    }
-}
+//package com.huimv.admin.config;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.huimv.admin.common.token.TokenConstant;
+//import com.huimv.admin.common.token.TokenSign;
+//import io.jsonwebtoken.Claims;
+//import org.springframework.web.method.HandlerMethod;
+//import org.springframework.web.servlet.HandlerInterceptor;
+//import org.springframework.web.servlet.ModelAndView;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.util.HashMap;
+//import java.util.Map;
+//
+///**
+// * <p>
+// *  jwt拦截器
+// * </p>
+// * @since 2021/4/19
+// */
+//public class JWTInterceptor implements HandlerInterceptor {
+//
+//
+//    @Override
+//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+//        // 如果不是映射到方法,则直接通过
+//        if (!(handler instanceof HandlerMethod)) {
+//            return true;
+//        }
+//
+//        response.setContentType("application/json;charset=utf-8");
+//        // 获取token
+//        String token=request.getHeader("accessToken");
+//
+//
+//        if (null==token){
+//            Map<String,Object> map=new HashMap<>();
+//            map.put("data","token is null");
+//            map.put("code","401");
+//            response.setStatus(401);
+//            response.getWriter().write(JSONObject.toJSONString(map));
+//            return false;
+//        }else {
+//            Claims claims = TokenSign.getClaims(token);
+//            if (claims == null){
+//                Map<String,Object> map=new HashMap<>();
+//                map.put("data","token is overdue");
+//                map.put("code","403");
+//                response.setStatus(403);
+//                response.getWriter().write(JSONObject.toJSONString(map));
+//                return false;
+//            }
+//
+//            boolean result= TokenSign.verify(token);
+//            if (result){
+//                //更新存储的token信息
+//                TokenConstant.updateTokenMap(token);
+//                return true;
+//            }
+//            Map<String,Object> map=new HashMap<>();
+//            map.put("data","token is null");
+//            map.put("code","401");
+//            response.setStatus(401);
+//            response.getWriter().write(JSONObject.toJSONString(map));
+//            return false;
+//
+//        }
+//    }
+//
+//
+//    @Override
+//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
+//
+//    }
+//
+//    @Override
+//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+//
+//    }
+//}

+ 4 - 2
huimv-admin/src/main/java/com/huimv/admin/entity/EnvWarningInfo.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import java.time.LocalTime;
 import java.io.Serializable;
+import java.util.Date;
+
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -56,12 +58,12 @@ public class EnvWarningInfo implements Serializable {
     /**
      * 设备id
      */
-    private Integer deviceId;
+    private String deviceId;
 
     /**
      * 日期
      */
-    private LocalTime date;
+    private Date date;
 
     /**
      * 人员id

+ 112 - 42
huimv-admin/src/main/java/com/huimv/admin/timer/CarmeraTimer.java

@@ -10,6 +10,7 @@ import com.hikvision.cms.api.common.util.Digests;
 import com.hikvision.cms.api.common.util.HttpClientSSLUtils;
 import com.huimv.admin.entity.EnvData;
 import com.huimv.admin.entity.EnvDevice;
+import com.huimv.admin.entity.EnvWarningInfo;
 import com.huimv.admin.entity.EnvWarningThreshold;
 import com.huimv.admin.entity.hkwsdto.CameraDto1;
 import com.huimv.admin.entity.hkwsdto.HkvsCameraDto;
@@ -26,9 +27,7 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
-import java.io.IOException;
-import java.sql.Timestamp;
-import java.text.ParseException;
+import javax.sound.midi.Soundbank;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -104,8 +103,8 @@ public class CarmeraTimer {
     String passwordMD5 = "21218cca77804d2ba1922c33e0151105";
     String baseurl ="https://yzwlw.loongk.com/";
 
-//    @Scheduled(cron = "0 * * * * ? ")
-//    @Transactional
+    @Scheduled(cron = "0 0/11 * * * ?  ")
+    @Transactional
     private void getHuanKong() throws Exception {
         //目前是这家
         Integer farmId = 21;
@@ -119,49 +118,120 @@ public class CarmeraTimer {
         //只有一家,先拿全部
         List<EnvDevice> list = envDeviceService.list();
         for (EnvDevice envDevice : list) {
-            ResponseEntity<String> exchange = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackDatas/" + envDevice.getDeviceCode(), HttpMethod.GET, requestEntity, String.class);
-            String shishiBody = exchange.getBody();
-            System.out.println(new Date() +"实时数据"+ shishiBody);
-            ShackDatasDto shackDatasDto = JSONUtil.toBean(shishiBody, ShackDatasDto.class);
-            List<ShackDatasSensor> sensorDatas = shackDatasDto.getData().getSensorDatas();
-            EnvData envData = new EnvData();
-            for (ShackDatasSensor sensorData : sensorDatas) {
-                if (sensorData.getId().equals(envDevice.getOhter1())){
-                    String val = sensorData.getVal();
-                    //TODO 预警
-                    saveTemWarning(val,envWarningThreshold);
-                    envData.setEnvTemp(val);
+            if (ObjectUtil.isNotEmpty(envDevice) && StringUtils.isNotBlank(envDevice.getDeviceCode())){
+                ResponseEntity<String> exchange = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackDatas/" + envDevice.getDeviceCode(), HttpMethod.GET, requestEntity, String.class);
+                String shishiBody = exchange.getBody();
+                if (ObjectUtil.isEmpty(shishiBody)){
+                    System.out.println(new Date() +"实时数据"+ shishiBody);
+                    return;
                 }
-                if (sensorData.getId().equals(envDevice.getOhter2())){
-                    String val = sensorData.getVal();
-                    //TODO 预警
-//                    saveWarning(val,);
-                    envData.setEnvHum(val);
+                ShackDatasDto shackDatasDto = JSONUtil.toBean(shishiBody, ShackDatasDto.class);
+                List<ShackDatasSensor> sensorDatas = shackDatasDto.getData().getSensorDatas();
+                EnvData envData = new EnvData();
+                for (ShackDatasSensor sensorData : sensorDatas) {
+                    if (sensorData.getId().equals(envDevice.getOhter1())){
+                        String val = sensorData.getVal();
+                        //TODO 预警
+                        saveTemWarning(val,envWarningThreshold,envDevice,farmId);
+                        envData.setEnvTemp(val);
+                    }
+                    if (sensorData.getId().equals(envDevice.getOhter2())){
+                        String val = sensorData.getVal();
+                        //TODO 预警
+                        saveHumWarning(val,envWarningThreshold,envDevice,farmId);
+                        envData.setEnvHum(val);
+                    }
                 }
+                envData.setCreateTime(new Date());
+                envData.setDeviceId(envDevice.getDeviceCode());
+                envData.setFarmId(farmId);
+                envData.setUnitId(envDevice.getUnitId());
+                envDataService.save(envData);
             }
-            envData.setCreateTime(new Date());
-            envData.setDeviceId(envDevice.getDeviceCode());
-            envData.setFarmId(farmId);
-            envData.setUnitId(envDevice.getUnitId());
-            envDataService.save(envData);
         }
     }
 
-    private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold) {
-        String maxTem ;
-        String minTem ;
-        if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxTem())){
-            maxTem ="40";
-        }else {
-            maxTem = envWarningThreshold.getMaxTem();
-        }
-        if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinTem())){
-            minTem ="0";
-        }else {
-            minTem =envWarningThreshold.getMinTem();
+    private void saveHumWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
+        if (StringUtils.isNotBlank(val)){
+            String maxHum ;
+            String minHum ;
+            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxHum())){
+                maxHum ="40";
+            }else {
+                maxHum = envWarningThreshold.getMaxHum();
+            }
+            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinHum())){
+                minHum ="0";
+            }else {
+                minHum =envWarningThreshold.getMinHum();
+            }
+            if (Double.parseDouble(maxHum) > Double.parseDouble(val)){
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(farmId);
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前湿度为"+val+"%超过阈值,请及时检查");
+                envWarningInfo.setWarningType(2);
+            }
+            if (Double.parseDouble(minHum) <Double.parseDouble(val)){
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(farmId);
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前湿度为"+val+"%低于阈值,请及时检查");
+                envWarningInfo.setWarningType(2);
+
+            }
         }
-        if (Double.parseDouble(maxTem) >Double.parseDouble(val)){
+    }
 
+    private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold,EnvDevice envDevice,Integer farmId) {
+        if (StringUtils.isNotBlank(val)){
+            String maxTem ;
+            String minTem ;
+            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMaxTem())){
+                maxTem ="40";
+            }else {
+                maxTem = envWarningThreshold.getMaxTem();
+            }
+            if (ObjectUtil.isEmpty(envWarningThreshold) || StringUtils.isBlank(envWarningThreshold.getMinTem())){
+                minTem ="0";
+            }else {
+                minTem =envWarningThreshold.getMinTem();
+            }
+            if (Double.parseDouble(maxTem) > Double.parseDouble(val)){
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(farmId);
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前温度为"+val+"°超过阈值,请及时检查");
+                envWarningInfo.setWarningType(1);
+            }
+            if (Double.parseDouble(minTem) <Double.parseDouble(val)){
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(farmId);
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前温度为"+val+"°低于阈值,请及时检查");
+                envWarningInfo.setWarningType(1);
+
+            }
         }
     }
 
@@ -187,10 +257,10 @@ public class CarmeraTimer {
         HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
         RestTemplate restTemplate = new RestTemplate();
 
-        ResponseEntity<String> exchangePeizhi = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackConfig/"+"2c92083a78910dbc0178e98c06080207", HttpMethod.GET, requestEntity, String.class);
+        ResponseEntity<String> exchangePeizhi = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackConfig/"+"2c92083a83f8673701854cde3f6203bb", HttpMethod.GET, requestEntity, String.class);
         System.out.println("peizhi"+exchangePeizhi.getBody());
 
-        ResponseEntity<String> exchangeShishi = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackDatas/"+"2c92083a78910dbc0178e98c06080207", HttpMethod.GET, requestEntity, String.class);
+        ResponseEntity<String> exchangeShishi = restTemplate.exchange("https://yzwlw.loongk.com/mobile/loadShackDatas/"+"2c92083a83f8673701854cde3f6203bb", HttpMethod.GET, requestEntity, String.class);
         System.out.println("shishi"+exchangeShishi.getBody());
 
         System.out.println(s);