Procházet zdrojové kódy

Merge branch '20240909_sun' of sckj/yl-service into master

sckj před 1 měsícem
rodič
revize
a89dcace06

+ 6 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/WlfwJkyjController.java

@@ -89,6 +89,12 @@ public class WlfwJkyjController extends BaseController
         return toAjax(wlfwJkyjService.insertWlfwJkyj(wlfwJkyj),wlfwJkyj.getId());
     }
 
+    @PostMapping("/device")
+    public AjaxResult device(@RequestBody WlfwJkyj wlfwJkyj)
+    {
+        return AjaxResult.success(wlfwJkyjService.device(wlfwJkyj));
+    }
+
     /**
      * 修改为老服务监控硬件信息
      */

+ 10 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/WlfwJkyj.java

@@ -171,4 +171,14 @@ public class WlfwJkyj extends BaseEntity
 
     @TableField(exist = false)
     private String lrDz;
+
+    private String sbcs1;
+
+    private String sbcs2;
+
+    private String sbcs3;
+
+    private String sbcs4;
+
+    private String sbcs5;
 }

+ 11 - 7
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IWlfwJkyjService.java

@@ -1,19 +1,21 @@
 package com.ruoyi.system.service;
 
 import java.util.List;
+
+import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.system.domain.WlfwJkyj;
 
 /**
  * 为老服务监控硬件信息Service接口
- * 
+ *
  * @author sun
  * @date 2023-07-24
  */
-public interface IWlfwJkyjService 
+public interface IWlfwJkyjService
 {
     /**
      * 查询为老服务监控硬件信息
-     * 
+     *
      * @param id 为老服务监控硬件信息主键
      * @return 为老服务监控硬件信息
      */
@@ -21,7 +23,7 @@ public interface IWlfwJkyjService
 
     /**
      * 查询为老服务监控硬件信息列表
-     * 
+     *
      * @param wlfwJkyj 为老服务监控硬件信息
      * @return 为老服务监控硬件信息集合
      */
@@ -29,15 +31,17 @@ public interface IWlfwJkyjService
 
     /**
      * 新增为老服务监控硬件信息
-     * 
+     *
      * @param wlfwJkyj 为老服务监控硬件信息
      * @return 结果
      */
     public int insertWlfwJkyj(WlfwJkyj wlfwJkyj);
 
+    public JSONObject device(WlfwJkyj wlfwJkyj);
+
     /**
      * 修改为老服务监控硬件信息
-     * 
+     *
      * @param wlfwJkyj 为老服务监控硬件信息
      * @return 结果
      */
@@ -45,7 +49,7 @@ public interface IWlfwJkyjService
 
     /**
      * 批量删除为老服务监控硬件信息
-     * 
+     *
      * @param ids 需要删除的为老服务监控硬件信息主键集合
      * @return 结果
      */

+ 37 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MyX509TrustManager.java

@@ -0,0 +1,37 @@
+package com.ruoyi.system.service.impl;
+
+import javax.net.ssl.X509TrustManager;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+public class MyX509TrustManager implements X509TrustManager {
+
+    /**
+     * 检查客户端证书
+     * @param chain
+     * @param authType
+     * @throws CertificateException
+     */
+    @Override
+    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+    }
+
+    /**
+     * 检查服务器端证书
+     * @param chain
+     * @param authType
+     * @throws CertificateException
+     */
+    @Override
+    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+    }
+
+    /**
+     * 返回受信任的X509证书数组
+     * @return
+     */
+    @Override
+    public X509Certificate[] getAcceptedIssuers() {
+        return null;
+    }
+}

+ 69 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WlfwJkyjServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ruoyi.business.domain.ZwywLrJbxx;
 import com.ruoyi.common.core.utils.StringUtils;
@@ -12,6 +13,16 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.ConnectException;
+import java.net.URL;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -82,6 +93,12 @@ public class WlfwJkyjServiceImpl implements IWlfwJkyjService
         return wlfwJkyjMapper.insert(wlfwJkyj);
     }
 
+    @Override
+    public JSONObject device(WlfwJkyj wlfwJkyj) {
+        return httpsRequest("http://121.36.73.159:8090/setdevicePara",
+                "POST", "{}");
+    }
+
     /**
      * 修改为老服务监控硬件信息
      *
@@ -106,4 +123,56 @@ public class WlfwJkyjServiceImpl implements IWlfwJkyjService
         return wlfwJkyjMapper.deleteBatchIds(Arrays.asList(ids));
     }
 
+    public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) {
+        JSONObject jsonObject = null;
+        try {
+            // 创建SSLContext对象,并使用我们指定的信任管理器初始化
+            TrustManager[] tm = {new MyX509TrustManager()};
+            SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
+            sslContext.init(null, tm, new java.security.SecureRandom());
+            // 从上述SSLContext对象中得到SSLSocketFactory对象
+            SSLSocketFactory ssf = sslContext.getSocketFactory();
+
+            URL url = new URL(requestUrl);
+            HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
+            conn.setSSLSocketFactory(ssf);
+
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            conn.setUseCaches(false);
+            // 设置请求方式(GET/POST)
+            conn.setRequestMethod(requestMethod);
+
+            // 当outputStr不为null时向输出流写数据
+            if (null != outputStr) {
+                OutputStream outputStream = conn.getOutputStream();
+                // 注意编码格式
+                outputStream.write(outputStr.getBytes("UTF-8"));
+                outputStream.close();
+            }
+
+            // 从输入流读取返回内容
+            InputStream inputStream = conn.getInputStream();
+            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
+            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+            String str = null;
+            StringBuffer buffer = new StringBuffer();
+            while ((str = bufferedReader.readLine()) != null) {
+                buffer.append(str);
+            }
+
+            // 释放资源
+            bufferedReader.close();
+            inputStreamReader.close();
+            inputStream.close();
+            inputStream = null;
+            conn.disconnect();
+            jsonObject = JSONObject.parseObject(buffer.toString());
+        } catch (ConnectException ce) {
+            System.out.println("连接超时:{}" + ce);
+        } catch (Exception e) {
+            System.out.println("请求异常:{}" + e);
+        }
+        return jsonObject;
+    }
 }

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/WlfwJkyjMapper.xml

@@ -38,6 +38,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updateUnit"    column="update_unit"    />
         <result property="updateUnitName"    column="update_unit_name"    />
         <result property="state"    column="state"    />
+        <result property="sbcs1"    column="sbcs1"    />
+        <result property="sbcs2"    column="sbcs2"    />
+        <result property="sbcs3"    column="sbcs3"    />
+        <result property="sbcs4"    column="sbcs4"    />
+        <result property="sbcs5"    column="sbcs5"    />
     </resultMap>
 
     <select id="selectLrById" parameterType="String" resultType="java.util.HashMap">