瀏覽代碼

优化传感器代码,新增水压传感器方法,新增定时任务查询精讯数据方法

limeng 2 年之前
父節點
當前提交
e338a66821
共有 22 個文件被更改,包括 203 次插入961 次删除
  1. 21 0
      ruoyi-admin/pom.xml
  2. 0 119
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/controller/HwMeetingController.java
  3. 0 24
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/HwMeetingService.java
  4. 0 46
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/impl/HwMeetingApi.java
  5. 0 125
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/impl/HwMeetingServiceImpl.java
  6. 0 53
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/util/HmacSHA256.java
  7. 0 96
      ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/util/hwMeetingCacheUtil.java
  8. 21 4
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/controller/WaterPressureController.java
  9. 8 0
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/service/WaterPressureService.java
  10. 36 0
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/service/impl/WaterPressureServiceImpl.java
  11. 1 1
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/sennor/API.java
  12. 3 0
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/sennor/service/SennorService.java
  13. 27 1
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/sennor/service/impl/SennorServiceImpl.java
  14. 1 1
      ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/shuicejia/TcpServer.java
  15. 73 0
      ruoyi-admin/src/main/java/com/ruoyi/scheduleTask/StaticScheduleTask.java
  16. 0 127
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/MailTools.java
  17. 0 32
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/SendMessageController.java
  18. 0 238
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/SendSms.java
  19. 0 68
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/domain/MessageContent.java
  20. 0 7
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/service/SendMessageService.java
  21. 0 15
      ruoyi-admin/src/main/java/com/ruoyi/sendSMS/service/impl/SendMessageServiceImpl.java
  22. 12 4
      ruoyi-admin/src/main/resources/application.yml

+ 21 - 0
ruoyi-admin/pom.xml

@@ -117,8 +117,29 @@
             <artifactId>poi-scratchpad</artifactId>
             <version>3.17</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.rocketmq</groupId>
+            <artifactId>rocketmq-client-java</artifactId>
+            <version>5.0.5</version>
+        </dependency>
+
+        <!-- rocketmq相关依赖 -->
+        <dependency>
+            <groupId>org.apache.rocketmq</groupId>
+            <artifactId>rocketmq-spring-boot-starter</artifactId>
+            <version>2.2.3</version>
+        </dependency>
+
+
+
+
+
     </dependencies>
 
+
+
+
     <build>
         <plugins>
             <plugin>

+ 0 - 119
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/controller/HwMeetingController.java

@@ -1,119 +0,0 @@
-package com.ruoyi.hwMeeting.controller;
-
-
-import cn.hutool.json.JSONArray;
-import cn.hutool.json.JSONObject;
-import cn.hutool.json.JSONUtil;
-import com.dahuatech.hutool.json.JSONTokener;
-import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.hwMeeting.util.hwMeetingCacheUtil;
-import com.ruoyi.hwMeeting.service.HwMeetingService;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.*;
-import javax.annotation.Resource;
-
-/**
- * 华为云会议控制器
- */
-@Controller
-@RequestMapping("/hwMeeting")
-public class HwMeetingController {
-
-    private String prefix = "hwMeeting/meeting";
-
-    @Resource
-    private HwMeetingService hwMeetingService;
-
-    /**
-     * 创建或加入会议
-     */
-    @GetMapping("/joinConferences/{eventId}/{subject}/{nickName}")
-    public String hasConferences(@PathVariable(name = "eventId") String eventId,
-                                     @PathVariable(name = "subject") String subject,
-                                     @PathVariable(name = "nickName") String nickName,
-                                     ModelMap mmap) {
-        if (hwMeetingCacheUtil.has(eventId)) {
-            Object ob = hwMeetingCacheUtil.get(eventId);
-            //ob转换为JSONObject 取来宾入会信息返回
-            JSONObject object = JSONUtil.parseObj(ob);
-            //取密码数组 passwordEntry
-            JSONArray array = JSONUtil.parseArray(object.get("passwordEntry"));
-            for (Object o : array) {
-                JSONObject password = JSONUtil.parseObj(o);
-                JSONObject generalInfo = new JSONObject();
-                if (password.getStr("conferenceRole").equals("general")) {
-                    generalInfo.set("conferenceID", object.getStr("conferenceID"));
-                    generalInfo.set("password", password.getStr("password"));
-                    mmap.put("info",generalInfo);
-                }
-            }
-            mmap.put("nickName",nickName);
-            return prefix;
-        }else{
-            this.createConferences(eventId,subject,mmap);
-            mmap.put("nickName",nickName);
-            return prefix;
-        }
-    }
-
-    /**
-     * 创建会议
-     */
-    public boolean createConferences(String eventId,String subject,ModelMap mmap) {
-        String result = hwMeetingService.conferences(subject);
-        if (isSuccess(result)) {
-            /**将会议信息保存到数据库**/
-            //将结果转换为json数组,当处理成功时返回的格式为数组
-            Object ob = JSONUtil.parseArray(result).get(0);
-            //会议信息存入缓存
-            hwMeetingCacheUtil.put(eventId,JSONUtil.parseObj(ob));
-            //ob转换为JSONObject 取主持人入会信息返回
-            JSONObject object = JSONUtil.parseObj(ob);
-            //取密码数组 passwordEntry
-            JSONArray array = JSONUtil.parseArray(object.get("passwordEntry"));
-            for (Object o : array) {
-                JSONObject password = JSONUtil.parseObj(o);
-                JSONObject chairInfo = new JSONObject();
-                if (password.getStr("conferenceRole").equals("chair")) {
-                    chairInfo.set("conferenceID", object.getStr("conferenceID"));
-                    chairInfo.set("password", password.getStr("password"));
-                    mmap.put("info",chairInfo);
-                }
-            }
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * 获取加入会议URI
-     */
-    @ResponseBody
-    @GetMapping("/guestJoinUri/{eventId}")
-    public AjaxResult guestJoinUri(@PathVariable(name = "eventId") String eventId) {
-        Object ob = hwMeetingCacheUtil.get(eventId);
-        if(ob != null){
-            JSONObject object = JSONUtil.parseObj(ob);
-            return AjaxResult.success(object.get("guestJoinUri"));
-        }
-        return AjaxResult.error("未查询到数据");
-    }
-
-    /**
-     * 判断返回数据是JSONArray还是JSONObject,
-     * 如果是Array 则表示成功
-     * 反之失败
-     * */
-    private boolean isSuccess(String result) {
-        Object object = new JSONTokener(result).nextValue();
-        if (object instanceof JSONObject) {
-            JSONObject jsonObject = (JSONObject) object;
-            String error_code = jsonObject.get("error_code").toString();
-            System.err.println(error_code);
-            return false;
-        }
-        return true;
-    }
-
-}

+ 0 - 24
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/HwMeetingService.java

@@ -1,24 +0,0 @@
-package com.ruoyi.hwMeeting.service;
-
-public interface HwMeetingService {
-
-    /**
-     * appId鉴权方法 获取token
-     */
-    String appauth();
-
-    /**
-     * 构成Authorization
-     */
-    String getAuthorization(String appId, String userId, String nonce);
-
-    /**
-     * 绑定给当前创会帐号的VMR ID。通过查询云会议室及个人会议ID接口获取。
-     */
-    String vmrID(String token);
-
-    /**
-     * 创建会议
-     */
-    String conferences(String subject);
-}

+ 0 - 46
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/impl/HwMeetingApi.java

@@ -1,46 +0,0 @@
-package com.ruoyi.hwMeeting.service.impl;
-
-import org.springframework.beans.factory.annotation.Value;
-
-/**
- * 华为接口类
- */
-public abstract class HwMeetingApi {
-
-    /**
-     * 请求地址
-     **/
-    public static final String url = "https://api.meeting.huaweicloud.com";
-
-    /**
-     * appId
-     **/
-    @Value("${HwM.appId}")
-    public static final String appId = "3f989ae3a9664bbd8e78dde9d29a5a22";
-
-    /**
-     * appKey 也是HmacSHA256加密秘钥
-     **/
-    @Value("${HwM.appKey}")
-    public static final String appKey = "a48cbf11d0172b1c9fd4e9017bd8cf4dca674aa3a40696bd59f2542e746552fa";
-
-    /**
-     * 第三方平台的userId
-     **/
-    public static final String userId = "1001";
-
-    /**
-     * 执行AppID鉴权
-     */
-    public static final String appauth = "/v2/usg/acs/auth/appauth";
-
-    /**
-     * 普通用户分页查询云会议室及个人会议ID
-     **/
-    public static final String vmr = "/v1/usg/dcs/member/vmr";
-
-    /**
-     * 创建会议
-     */
-    public static final String conferences = "/v1/mmc/management/conferences";
-}

+ 0 - 125
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/service/impl/HwMeetingServiceImpl.java

@@ -1,125 +0,0 @@
-package com.ruoyi.hwMeeting.service.impl;
-
-import com.dahuatech.hutool.core.util.RandomUtil;
-import com.dahuatech.hutool.http.HttpRequest;
-import com.dahuatech.hutool.json.JSONArray;
-import com.dahuatech.hutool.json.JSONObject;
-import com.dahuatech.hutool.json.JSONUtil;
-import com.ruoyi.config.service.IMeetingConfigService;
-import com.ruoyi.hwMeeting.service.HwMeetingService;
-import com.ruoyi.hwMeeting.util.HmacSHA256;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-@Service
-public class HwMeetingServiceImpl implements HwMeetingService {
-
-    private static final Logger log = LoggerFactory.getLogger(HwMeetingServiceImpl.class);
-
-    @Autowired
-    private IMeetingConfigService meetingConfigService;
-
-    /**
-     * appId鉴权方法 获取token
-     */
-    @Override
-    public String appauth() {
-        String appId = meetingConfigService.selectMeetingConfigById((long) 2).getVal();
-        String userId = meetingConfigService.selectMeetingConfigById((long) 4).getVal();
-        String url = meetingConfigService.selectMeetingConfigById((long) 1).getVal();
-        String appauth = meetingConfigService.selectMeetingConfigById((long) 5).getVal();
-        //64位随机字符串
-        String nonce = RandomUtil.randomString(64);
-        log.info("nonce:{}", nonce);
-        //鉴权信息
-        String authorization = getAuthorization(appId, userId, nonce);
-        log.info("authorization:{}", authorization);
-        //body
-        JSONObject json = new JSONObject();
-        json.put("appId", appId);
-        json.put("expireTime", 0);
-        json.put("nonce", nonce);
-        json.put("userId", userId);
-        json.put("clientType", 72);
-        //请求结果
-        String result = HttpRequest.post(url + appauth)
-                .header("Authorization", authorization)
-                .header("Content-Type", "application/json")
-                .body(json)
-                .execute().body();
-        //打印
-        log.info("result:{}", result);
-        return JSONUtil.parseObj(result).get("accessToken").toString();
-    }
-
-    /**
-     * 构成Authorization
-     */
-    @Override
-    public String getAuthorization(String appId, String userId, String nonce) {
-        String appKey = meetingConfigService.selectMeetingConfigById((long) 3).getVal();
-        String data = appId + ":" + userId + ":" + 0 + ":" + nonce;
-        String authorization = "HMAC-SHA256 signature=" + HmacSHA256.encode(data, appKey);
-        return authorization;
-    }
-
-    /**
-     * 绑定给当前创会帐号的VMR_ID。通过查询云会议室及个人会议ID接口获取。
-     */
-    @Override
-    public String vmrID(String token) {
-        String url = meetingConfigService.selectMeetingConfigById((long) 1).getVal();
-        String vmr = meetingConfigService.selectMeetingConfigById((long) 6).getVal();
-        //body
-        String result = HttpRequest.get(url + vmr)
-                .header("X-Access-Token", token)
-                .header("Content-Type", "application/json")
-                .execute().body();
-        log.info("vmr:{}", result);
-        JSONArray rooms = JSONUtil.parseArray(JSONUtil.parseObj(result).get("data"));
-        log.info("rooms.get(0):{}", rooms.get(0));
-        log.info("JSONUtil.parseObj(rooms.get(0)):{}", JSONUtil.parseObj(rooms.get(0)));
-        log.info("vmrID:{}", JSONUtil.parseObj(rooms.get(0)).get("vmrId"));
-        return JSONUtil.parseObj(rooms.get(0)).get("id").toString();
-    }
-
-    /**
-     * 创建会议
-     */
-    @Override
-    public String conferences(String subject) {
-        String url = meetingConfigService.selectMeetingConfigById((long) 1).getVal();
-        String conferences = meetingConfigService.selectMeetingConfigById((long) 7).getVal();
-        String token = appauth();
-        String vmrID = vmrID(token);
-        //body
-        JSONObject json = new JSONObject();
-        /**会议的媒体类型。Voice:语音会议,HDVideo:视频会议**/
-        json.put("mediaTypes", "HDVideo");
-        /**
-         * 会议持续时长,单位分钟。默认30分钟。
-         * 最大1440分钟(24小时),最小15分钟。
-         * */
-        json.put("length", 15);
-        /**会议主题。最多128个字符。**/
-        json.put("subject", subject);
-        /**
-         * 是否使用云会议室或者个人会议ID召开预约会议。默认0。
-         * 0:不使用云会议室或者个人会议ID
-         * 1:使用云会议室或者个人会议ID
-         * */
-        json.put("vmrFlag", 1);
-        /**绑定给当前创会帐号的VMR ID。通过查询云会议室及个人会议ID接口获取。**/
-        json.put("vmrID", vmrID);
-        //请求
-        String result = HttpRequest.post(url + conferences)
-                .header("X-Access-Token", token)
-                .header("Content-Type", "application/json")
-                .body(json)
-                .execute().body();
-        log.info("创建会议:{}", result);
-        return result;
-    }
-}

+ 0 - 53
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/util/HmacSHA256.java

@@ -1,53 +0,0 @@
-package com.ruoyi.hwMeeting.util;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import java.io.UnsupportedEncodingException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-
-public class HmacSHA256 {
-
-    //十六进制字符集
-    private final static char[] DIGEST_ARRAYS = {
-            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
-    };
-
-    /**
-     * 功能:Signature生成算法
-     * 输入参数:
-     *          1.data: HMAC-SHA256的输入数据
-     *          2.key: App Key
-     * 输出参数:十六进制字符串编码的HMAC-SHA256值
-     */
-    public static String encode(String data, String key) {
-        byte[] hashByte;
-        try {
-            Mac sha256HMAC = Mac.getInstance("HmacSHA256");
-            SecretKeySpec secretKey = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
-            sha256HMAC.init(secretKey);
-
-            hashByte = sha256HMAC.doFinal(data.getBytes("UTF-8"));
-        } catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) {
-            return null;
-        }
-
-        return bytesToHex(hashByte);
-    }
-
-    /**
-     * 功能:byte类型数组转换成十六进制字符串
-     * 输入参数:
-     *          1.bytes:被转换的字节数组
-     * 输出参数:十六进制字符串
-     */
-    private static String bytesToHex(byte[] bytes) {
-        StringBuffer hexStr = new StringBuffer();
-        for (int i = 0; i < bytes.length; i++) {
-            hexStr.append(DIGEST_ARRAYS[bytes[i] >>> 4 & 0X0F]);
-            hexStr.append(DIGEST_ARRAYS[bytes[i] & 0X0F]);
-        }
-
-        return hexStr.toString();
-    }
-}

+ 0 - 96
ruoyi-admin/src/main/java/com/ruoyi/hwMeeting/util/hwMeetingCacheUtil.java

@@ -1,96 +0,0 @@
-package com.ruoyi.hwMeeting.util;
-
-import com.ruoyi.common.utils.CacheUtils;
-import com.ruoyi.common.utils.spring.SpringUtils;
-import org.apache.shiro.cache.Cache;
-import org.apache.shiro.cache.CacheManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class hwMeetingCacheUtil {
-
-    private static Logger logger = LoggerFactory.getLogger(CacheUtils.class);
-
-    private static CacheManager cacheManager = SpringUtils.getBean(CacheManager.class);
-
-    private static final String CACHE = "hwMeetingCache";
-
-    /**
-     * 获取CACHE缓存
-     *
-     * @param key
-     * @return
-     */
-    public static Object get(String key)
-    {
-        return get(CACHE, key);
-    }
-
-    /**
-     * 获取缓存
-     *
-     * @param cacheName
-     * @param key
-     * @return
-     */
-    private static Object get(String cacheName, String key)
-    {
-        return getCache(cacheName).get(key);
-    }
-
-    /**
-     * 写入CACHE缓存
-     *
-     * @param key
-     * @return
-     */
-    public static void put(String key, Object value)
-    {
-        put(CACHE, key, value);
-    }
-
-
-    /**
-     * 写入缓存
-     *
-     * @param cacheName
-     * @param key
-     * @param value
-     */
-    private static void put(String cacheName, String key, Object value)
-    {
-        getCache(cacheName).put(key, value);
-    }
-
-    /**
-     * 判断是否有CACHE缓存
-     *
-     * @param key
-     * @return
-     */
-    public static boolean has(String key)
-    {
-        Object o = getCache(CACHE).get(key);
-        if(o == null){
-            return false;
-        }
-        return true;
-    }
-
-
-    /**
-     * 获得一个Cache,没有则显示日志。
-     *
-     * @param cacheName
-     * @return
-     */
-    private static Cache<String, Object> getCache(String cacheName)
-    {
-        Cache<String, Object> cache = cacheManager.getCache(cacheName);
-        if (cache == null)
-        {
-            throw new RuntimeException("当前系统中没有定义“" + cacheName + "”这个缓存。");
-        }
-        return cache;
-    }
-}

+ 21 - 4
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/controller/WaterPressureController.java

@@ -1,18 +1,35 @@
 package com.ruoyi.monitorInterface.chenganshengbang.controller;
 
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.monitorInterface.chenganshengbang.service.WaterPressureService;
+import com.ruoyi.monitorInterface.sennor.service.SennorService;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
+
 @RestController
 @RequestMapping("/api/WaterPressure")
 public class WaterPressureController {
 
+    @Resource
+    private WaterPressureService waterPressureService;
+
     /**
      * 水压传感器上报数据
      * */
-    @PostMapping("/selWaterPressureData")
-    public AjaxResult selWaterPressureData(String data){
-        System.out.println("res=====>"+data);
-        return null;
+    @PostMapping("/waterPressureMessageReceiver")
+    public byte[] waterPressureMessageReceiver(@RequestBody String data){
+        waterPressureService.waterPressureMessageReceiver(data);
+        return responseData();
+    }
+
+    public static byte[] responseData(){
+        int xiangyingma = 200;
+        byte[] xiangyingbytes = new byte[4];
+        xiangyingbytes[3] = (byte) (xiangyingma & 0xff);
+        xiangyingbytes[2] = (byte) (xiangyingma >> 8 & 0xff);
+        xiangyingbytes[1] = (byte) (xiangyingma >> 16 & 0xff);
+        xiangyingbytes[0] = (byte) (xiangyingma >> 24 & 0xff);
+        return xiangyingbytes;
     }
 }

+ 8 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/service/WaterPressureService.java

@@ -0,0 +1,8 @@
+package com.ruoyi.monitorInterface.chenganshengbang.service;
+
+import org.springframework.web.bind.annotation.RequestBody;
+
+public interface WaterPressureService {
+
+    String waterPressureMessageReceiver(String data);
+}

+ 36 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/chenganshengbang/service/impl/WaterPressureServiceImpl.java

@@ -0,0 +1,36 @@
+package com.ruoyi.monitorInterface.chenganshengbang.service.impl;
+
+import cn.hutool.http.HttpRequest;
+import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.framework.web.service.ConfigService;
+import com.ruoyi.monitorInterface.sennor.service.impl.SennorServiceImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Resource;
+
+public class WaterPressureServiceImpl {
+
+    private static final Logger log = LoggerFactory.getLogger(WaterPressureServiceImpl.class);
+
+    @Resource
+    private ConfigService configService;
+
+    public void waterPressureMessageReceiver(String data){
+        log.info("WaterPressure 接到数据 ==>",data);
+        JSONObject object;
+        String res;
+        try {
+            object = JSONObject.parseObject(data);
+            res = HttpRequest.post(configService.getKey("centerMonitorURL")+"device/saveWaterPressureDeviceData")
+                    .header("Content-Type", "application/json")
+                    .body(object.toJSONString())
+                    .execute().body();
+            log.info("数据推送成功! data ===> {} , result ===> {}",data, res);
+        }catch(Exception e){
+            e.printStackTrace();
+            log.error("数据推送失败! data ===> {} , result ===> {}",data, e.getMessage());
+        }
+    }
+}

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/sennor/API.java

@@ -1,4 +1,4 @@
-package com.ruoyi.monitorInterface.sennor;
+package com.ruoyi.monitorInterface.sennor.api;
 
 public class API {
 

+ 3 - 0
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/sennor/service/SennorService.java

@@ -1,5 +1,6 @@
 package com.ruoyi.monitorInterface.sennor.service;
 
+import com.alibaba.fastjson.JSONArray;
 import com.ruoyi.common.core.domain.AjaxResult;
 
 public interface SennorService {
@@ -8,4 +9,6 @@ public interface SennorService {
      * 查询设备节点数据
      * */
     AjaxResult getDeviceInfo(String deviceNumber);
+
+    JSONArray getDevideCodeMapByTypes(String types);
 }

+ 27 - 1
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/sennor/service/impl/SennorServiceImpl.java

@@ -1,10 +1,11 @@
 package com.ruoyi.monitorInterface.sennor.service.impl;
 
 import cn.hutool.http.HttpRequest;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.framework.web.service.ConfigService;
-import com.ruoyi.monitorInterface.sennor.API;
+import com.ruoyi.monitorInterface.sennor.api.API;
 import com.ruoyi.monitorInterface.sennor.service.SennorService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -22,6 +23,8 @@ public class SennorServiceImpl implements SennorService {
 
     private String secretKey;
 
+
+
     //这个方法应该用定时任务三分钟调用一次
     @Override
     public AjaxResult getDeviceInfo(String deviceNumber) {
@@ -33,6 +36,7 @@ public class SennorServiceImpl implements SennorService {
         String result = HttpRequest.get(URI.toString())
                 .header("Content-Type", "application/json")
                 .execute().body();
+        log.info("Sennor 收到数据 ==> {}", result);
         //后推送
         JSONObject object;
         String res;
@@ -51,4 +55,26 @@ public class SennorServiceImpl implements SennorService {
         }
 
     }
+
+    @Override
+    public JSONArray getDevideCodeMapByTypes(String types) {
+        //先请求
+        StringBuffer URI = new StringBuffer(configService.getKey("centerMonitorURL")+ "device/getDevideCodeMapByTypes");
+        URI.append("?types=").append(types);
+        String result = HttpRequest.get(URI.toString())
+                .header("Content-Type", "application/json")
+                .execute().body();
+        //后推送
+        JSONObject object;
+        try {
+            object = JSONObject.parseObject(result);
+            if(object.getInteger("code") == 200){
+                return object.getJSONArray("data");
+            }
+        }catch(Exception e){
+            e.printStackTrace();
+            log.error("服务端数据校验失败! data ===> {} , result ===> {}",result, e.getMessage());
+        }
+        return new JSONArray();
+    }
 }

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/monitorInterface/shuicejia/TcpServer.java

@@ -58,6 +58,7 @@ public class TcpServer  extends Thread implements CommandLineRunner {
 
     public void readAndWrite(SocketChannel channel, String response) throws IOException {
         JSONObject object;
+        log.info("TCPServer 收到数据 ==> {}", response);
         try {
             object = JSONObject.parseObject(response);
             //先推送
@@ -65,7 +66,6 @@ public class TcpServer  extends Thread implements CommandLineRunner {
                     .header("Content-Type", "application/json")
                     .body(object.toJSONString())
                     .execute().body();
-            System.out.println(result);
         } catch (Exception e) {
             e.printStackTrace();
             return;

+ 73 - 0
ruoyi-admin/src/main/java/com/ruoyi/scheduleTask/StaticScheduleTask.java

@@ -0,0 +1,73 @@
+package com.ruoyi.scheduleTask;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.framework.web.service.ConfigService;
+import com.ruoyi.monitorInterface.sennor.service.SennorService;
+import org.apache.commons.lang3.time.FastDateFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import javax.annotation.Resource;
+import java.text.ParseException;
+import java.util.Calendar;
+
+/**
+ * @author limeng
+ * @date 2023年11月30日 8:50
+ */
+@Configuration
+@EnableScheduling
+public class StaticScheduleTask {
+
+    protected static final Logger logger = LoggerFactory.getLogger(StaticScheduleTask.class);
+
+    private static FastDateFormat simpleDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
+
+    @Resource
+    private SennorService sennorService;
+
+    @Resource
+    private ConfigService configService;
+
+    //添加定时任务 每三分钟执行
+    @Scheduled(cron = "0 */3 * * * ?")
+    private void configureTasks() {
+
+        logger.info("执行定时任务=>{}", DateUtils.dateTimeNow());
+        String types = configService.getKey("sennorDeviceTypes");
+        JSONArray jsonArray = sennorService.getDevideCodeMapByTypes(types);
+        for (Object object : jsonArray){
+            JSONObject jsonObject = JSONObject.parseObject(object.toString());
+            sennorService.getDeviceInfo(jsonObject.getString("device_code"));
+        }
+    }
+
+
+    /**
+     * 比较两个日期大小
+     **/
+    private boolean daysBefore(String time) {
+        boolean result = false;
+        try {
+            Calendar calendar = getCalendar(time);
+            Calendar now = Calendar.getInstance();
+            result = calendar.before(now);
+        } catch (ParseException e) {
+            logger.error(e.getMessage());
+        }
+        return result;
+    }
+
+    /**
+     * 将String时间转换为Calendar
+     **/
+    private static Calendar getCalendar(String time) throws ParseException {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(simpleDateFormat.parse(time));
+        return calendar;
+    }
+}

+ 0 - 127
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/MailTools.java

@@ -1,127 +0,0 @@
-package com.ruoyi.sendSMS.controller;
-
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import java.util.Date;
-import java.util.Properties;
-
-public class MailTools {
-
-    // 发件人的 邮箱 和 密码(替换为自己的邮箱和密码)
-    // PS: 某些邮箱服务器为了增加邮箱本身密码的安全性,给 SMTP 客户端设置了独立密码(有的邮箱称为“授权码”),
-    //     对于开启了独立密码的邮箱, 这里的邮箱密码必需使用这个独立密码(授权码)。
-    public static String myEmailAccount = "sys5923812@163.com";
-    public static String myEmailPassword = "sys200888";
-
-    public static String fromuser = "二道应急局";
-
-    // 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般(只是一般, 绝非绝对)格式为: smtp.xxx.com
-    // 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
-    public static String myEmailSMTPHost = "smtp.163.com";
-
-//    // 收件人邮箱(替换为自己知道的有效邮箱)
-//    public static String receiveMailAccount = "sys5923812@126.com";
-
-    public static void main(String[] args) {
-        try {
-        String mail = "huapyluo@126.com";
-        String title = "隐患限期整改告知书";
-        String count = ("测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容测试附件内容");
-            sendMain(mail, title, count);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-
-    public static void sendMain(String tomail, String title, String content) throws Exception {
-        // 1. 创建参数配置, 用于连接邮件服务器的参数配置
-        Properties props = new Properties();                    // 参数配置
-        props.setProperty("mail.transport.protocol", "smtp");   // 使用的协议(JavaMail规范要求)
-        props.setProperty("mail.smtp.host", myEmailSMTPHost);   // 发件人的邮箱的 SMTP 服务器地址
-        props.setProperty("mail.smtp.auth", "true");            // 需要请求认证
-
-        // PS: 某些邮箱服务器要求 SMTP 连接需要使用 SSL 安全认证 (为了提高安全性, 邮箱支持SSL连接, 也可以自己开启),
-        //     如果无法连接邮件服务器, 仔细查看控制台打印的 log, 如果有有类似 “连接失败, 要求 SSL 安全连接” 等错误,
-        //     打开下面 /* ... */ 之间的注释代码, 开启 SSL 安全连接。
-        /*
-        // SMTP 服务器的端口 (非 SSL 连接的端口一般默认为 25, 可以不添加, 如果开启了 SSL 连接,
-        //                  需要改为对应邮箱的 SMTP 服务器的端口, 具体可查看对应邮箱服务的帮助,
-        //                  QQ邮箱的SMTP(SLL)端口为465或587, 其他邮箱自行去查看)
-        final String smtpPort = "465";
-        props.setProperty("mail.smtp.port", smtpPort);
-        props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
-        props.setProperty("mail.smtp.socketFactory.fallback", "false");
-        props.setProperty("mail.smtp.socketFactory.port", smtpPort);
-        */
-
-        // 2. 根据配置创建会话对象, 用于和邮件服务器交互
-        Session session = Session.getDefaultInstance(props);
-        session.setDebug(true);                                 // 设置为debug模式, 可以查看详细的发送 log
-
-        // 3. 创建一封邮件
-        MimeMessage message = createMimeMessage(session, myEmailAccount, tomail, title, content);
-
-        // 4. 根据 Session 获取邮件传输对象
-        Transport transport = session.getTransport();
-
-        // 5. 使用 邮箱账号 和 密码 连接邮件服务器, 这里认证的邮箱必须与 message 中的发件人邮箱一致, 否则报错
-        //
-        //    PS_01: 成败的判断关键在此一句, 如果连接服务器失败, 都会在控制台输出相应失败原因的 log,
-        //           仔细查看失败原因, 有些邮箱服务器会返回错误码或查看错误类型的链接, 根据给出的错误
-        //           类型到对应邮件服务器的帮助网站上查看具体失败原因。
-        //
-        //    PS_02: 连接失败的原因通常为以下几点, 仔细检查代码:
-        //           (1) 邮箱没有开启 SMTP 服务;
-        //           (2) 邮箱密码错误, 例如某些邮箱开启了独立密码;
-        //           (3) 邮箱服务器要求必须要使用 SSL 安全连接;
-        //           (4) 请求过于频繁或其他原因, 被邮件服务器拒绝服务;
-        //           (5) 如果以上几点都确定无误, 到邮件服务器网站查找帮助。
-        //
-        //    PS_03: 仔细看log, 认真看log, 看懂log, 错误原因都在log已说明。
-        transport.connect(myEmailAccount, myEmailPassword);
-
-        // 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
-        transport.sendMessage(message, message.getAllRecipients());
-
-        // 7. 关闭连接
-        transport.close();
-    }
-
-    /**
-     * 创建一封只包含文本的简单邮件
-     *
-     * @param session     和服务器交互的会话
-     * @param sendMail    发件人邮箱
-     * @param receiveMail 收件人邮箱
-     * @return
-     * @throws Exception
-     */
-    public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String title, String content) throws Exception {
-        // 1. 创建一封邮件
-        MimeMessage message = new MimeMessage(session);
-
-        // 2. From: 发件人
-        message.setFrom(new InternetAddress(sendMail, fromuser, "UTF-8"));
-
-        // 3. To: 收件人(可以增加多个收件人、抄送、密送)
-        message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "XX用户", "UTF-8"));
-
-        // 4. Subject: 邮件主题
-        message.setSubject(title, "UTF-8");
-
-        // 5. Content: 邮件正文(可以使用html标签)
-        message.setContent(content, "text/html;charset=UTF-8");
-
-        // 6. 设置发件时间
-        message.setSentDate(new Date());
-
-        // 7. 保存设置
-        message.saveChanges();
-
-        return message;
-    }
-
-}

+ 0 - 32
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/SendMessageController.java

@@ -1,32 +0,0 @@
-package com.ruoyi.sendSMS.controller;
-
-import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.sendSMS.domain.MessageContent;
-import com.ruoyi.sendSMS.service.SendMessageService;
-import org.springframework.web.bind.annotation.*;
-
-import javax.annotation.Resource;
-import java.util.List;
-
-@RestController
-@RequestMapping("/sendMessageController")
-public class SendMessageController {
-
-    @Resource
-    SendMessageService sendMessageService;
-
-    @PostMapping("/sendMessage")
-    public String sendMessage(@RequestBody MessageContent messageContent) {
-        return sendMessageService.sendMessage(messageContent.getPhone(), messageContent.getStr(), messageContent.getSMSsignature());
-    }
-
-    @PostMapping("/sendEmail")
-    public AjaxResult sendEmail(@RequestBody MessageContent messageContent) {
-        try {
-            MailTools.sendMain(messageContent.getMail(), messageContent.getTitle(), messageContent.getCount());
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return AjaxResult.success("操作成功!");
-    }
-}

+ 0 - 238
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/controller/SendSms.java

@@ -1,238 +0,0 @@
-package com.ruoyi.sendSMS.controller;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import javax.net.ssl.*;
-import java.io.*;
-import java.net.URL;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-
-// If the JDK version is earlier than 1.8, use the third-party library to provide the Base64 class.
-public class SendSms {
-    /**
-     * 设置不验证主机
-     */
-    private static final HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
-        @Override
-        public boolean verify(String hostname, SSLSession session) {
-            return true;
-        }
-    };
-
-    public static void main(String[] args) throws Exception {
-        sendMessage("17612476018", "1231231321", "数字梨树");
-    }
-
-    public static Map<String, Object> buildRequestBody(String msisdn, String smsTemplateId,
-                                                       Map<String, String> paramValues, String accout, String passward, String SMSsignature) {
-        if (null == msisdn || null == smsTemplateId || null == accout || null == passward) {
-            System.out.println(
-                    "buildRequestBody(): mobiles, templateId or templateParas or account or password is null.");
-            return null;
-        }
-
-        Map<String, Object> map = new HashMap<String, Object>();
-        List<MtSmsMessage> requestLists = new ArrayList<MtSmsMessage>();
-        MtSmsMessage mtSmsMessage = new MtSmsMessage();
-        List<String> mobiles = new ArrayList<String>();
-        mobiles.add(msisdn);
-        mtSmsMessage.setMobiles(mobiles);
-        mtSmsMessage.setTemplateId(smsTemplateId);
-        mtSmsMessage.setTemplateParas(paramValues);
-        mtSmsMessage.setSignature("【"+SMSsignature+"】");
-        requestLists.add(mtSmsMessage);
-        map.put("account", accout);
-        map.put("password", passward);
-        map.put("requestLists", requestLists);
-        return map;
-    }
-
-    public static class MtSmsMessage {
-        List<String> mobiles;
-        String templateId;
-        Map<String, String> templateParas;
-        String signature;
-        String messageId;
-        String extCode;
-        List<NamedPatameter> extendInfos;
-
-        public List<String> getMobiles() {
-            return mobiles;
-        }
-
-        public void setMobiles(List<String> mobiles) {
-            this.mobiles = mobiles;
-        }
-
-        public String getTemplateId() {
-            return templateId;
-        }
-
-        public void setTemplateId(String templateId) {
-            this.templateId = templateId;
-        }
-
-        public Map<String, String> getTemplateParas() {
-            return templateParas;
-        }
-
-        public void setTemplateParas(Map<String, String> templateParas) {
-            this.templateParas = templateParas;
-        }
-
-        public String getSignature() {
-            return signature;
-        }
-
-        public void setSignature(String signature) {
-            this.signature = signature;
-        }
-
-        public String getMessageId() {
-            return messageId;
-        }
-
-        public void setMessageId(String messageId) {
-            this.messageId = messageId;
-        }
-
-        public String getExtCode() {
-            return extCode;
-        }
-
-        public void setExtCode(String extCode) {
-            this.extCode = extCode;
-        }
-
-        public List<NamedPatameter> getExtendInfos() {
-            return extendInfos;
-        }
-
-        public void setExtendInfos(List<NamedPatameter> extendInfos) {
-            this.extendInfos = extendInfos;
-        }
-    }
-
-    public class NamedPatameter {
-        String key;
-        String value;
-
-        public String getKey() {
-            return key;
-        }
-
-        public void setKey(String key) {
-            this.key = key;
-        }
-
-        public String getValue() {
-            return value;
-        }
-
-        public void setValue(String value) {
-            this.value = value;
-        }
-    }
-
-    static void trustAllHttpsCertificates() throws Exception {
-        TrustManager[] trustAllCerts = new TrustManager[]{
-                new X509TrustManager() {
-                    @Override
-                    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
-                        return;
-                    }
-
-
-                    @Override
-                    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
-                        return;
-                    }
-
-
-                    @Override
-                    public X509Certificate[] getAcceptedIssuers() {
-                        return null;
-                    }
-                }
-        };
-        SSLContext sc = SSLContext.getInstance("SSL");
-        sc.init(null, trustAllCerts, null);
-        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
-    }
-
-    public static String sendMessage(String phone, String message, String SMSsignature) {
-
-        String url = "https://139.9.32.119:18312/common/sms/sendTemplateMessage";
-
-        //【数字梨树】
-//        String smsTemplateId = "SMS_21010400002";
-        //【四平市林业局】
-        String smsTemplateId = "SMS_21030400002";
-        Map<String, String> templateParas = new HashMap<String, String>();
-        templateParas.put("dxnr", message);
-        String accout = "760395"; //实际账号
-        String passward = "Mds*e&sd2D"; //实际密码
-        // If the request body does not contain the signature name, set signature to null.
-        Map<String, Object> body = buildRequestBody(phone, smsTemplateId, templateParas, accout, passward,SMSsignature);
-        if (null == body || body.isEmpty()) {
-            System.out.println("body is null.");
-            return "body is null";
-        }
-        HttpsURLConnection connection = null;
-        InputStream is = null;
-        BufferedReader br = null;
-        try {
-            trustAllHttpsCertificates();
-            URL realUrl = new URL(url);
-            connection = (HttpsURLConnection) realUrl.openConnection();
-            connection.setHostnameVerifier(DO_NOT_VERIFY);
-            connection.setDoInput(true); // 设置可输入
-            connection.setDoOutput(true); // 设置该连接是可以输出的
-            connection.setRequestMethod("POST"); // 设置请求方式
-            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
-            // connection.connect();
-            ObjectMapper objectMapper = new ObjectMapper();
-            PrintWriter pw = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8"));
-            pw.write(objectMapper.writeValueAsString(body));
-            pw.flush();
-            pw.close();
-
-            br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
-            int status = connection.getResponseCode();
-            if (200 == status) { // 200
-                is = connection.getInputStream();
-            } else { // 400/401
-                is = connection.getErrorStream();
-            }
-            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-            String line = null;
-            StringBuilder result = new StringBuilder();
-            while ((line = br.readLine()) != null) { // 读取数据
-                result.append(line + "\n");
-            }
-            connection.disconnect();
-            System.out.println(result.toString());
-            return result.toString();
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                if (null != is) {
-                    is.close();
-                }
-                if (null != br) {
-                    br.close();
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-        return null;
-    }
-}

+ 0 - 68
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/domain/MessageContent.java

@@ -1,68 +0,0 @@
-package com.ruoyi.sendSMS.domain;
-
-/**
- * @author pengyu
- * @date 2023年05月02日 13:06
- */
-
-public class MessageContent {
-
-    //短信发送需要字段
-    public  String phone;
-    public  String str;
-    public  String SMSsignature;
-
-
-    //邮箱发送需要字段
-    public  String mail;
-    public  String title;
-    public  String count;
-
-    public String getPhone() {
-        return phone;
-    }
-
-    public void setPhone(String phone) {
-        this.phone = phone;
-    }
-
-    public String getStr() {
-        return str;
-    }
-
-    public void setStr(String str) {
-        this.str = str;
-    }
-
-    public String getSMSsignature() {
-        return SMSsignature;
-    }
-
-    public void setSMSsignature(String SMSsignature) {
-        this.SMSsignature = SMSsignature;
-    }
-
-    public String getMail() {
-        return mail;
-    }
-
-    public void setMail(String mail) {
-        this.mail = mail;
-    }
-
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public String getCount() {
-        return count;
-    }
-
-    public void setCount(String count) {
-        this.count = count;
-    }
-}

+ 0 - 7
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/service/SendMessageService.java

@@ -1,7 +0,0 @@
-package com.ruoyi.sendSMS.service;
-
-public interface SendMessageService {
-
-    public String sendMessage(String phone, String str, String SMSsignature);
-
-}

+ 0 - 15
ruoyi-admin/src/main/java/com/ruoyi/sendSMS/service/impl/SendMessageServiceImpl.java

@@ -1,15 +0,0 @@
-package com.ruoyi.sendSMS.service.impl;
-
-import com.ruoyi.sendSMS.controller.SendSms;
-import com.ruoyi.sendSMS.service.SendMessageService;
-import org.springframework.stereotype.Service;
-
-@Service
-public class SendMessageServiceImpl implements SendMessageService {
-
-
-    public String sendMessage(String phone, String message, String SMSsignature) {
-
-        return  SendSms.sendMessage(phone, message,SMSsignature);
-    }
-}

+ 12 - 4
ruoyi-admin/src/main/resources/application.yml

@@ -13,14 +13,22 @@ ruoyi:
   # 获取ip地址开关
   addressEnabled: false
 
+# rocketMQ配置
+#rocketmq:
+#  # NameServer
+#  name-server: 127.0.0.1:9876
+#  # 默认的消息组
+#  producer:
+#    group: group1
+
 # 开发环境配置(视频会议配置)
 server:
   # 服务器的HTTP端口,默认为80
   port: 41000
-  ssl:
-    key-store: classpath:keystore.jks
-    key-store-password: 123456
-    key-password: 123456
+#  ssl:
+#    key-store: classpath:keystore.jks
+#    key-store-password: 123456
+#    key-password: 123456
 ## 开发环境配置(短信服务配置)
 #server:
 #  # 服务器的HTTP端口,默认为80