2021与蓝度共同重构项目,服务端
liuhaonan
2022-10-26 c7be2ef037c5aebb0cd8f1f33e5fa934389e6083
changes
已修改5个文件
96 ■■■■■ 文件已修改
dao/src/main/resources/mapper/LightMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxRequestUtil.java 58 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/resources/mapper/LightMapper.xml
@@ -42,8 +42,8 @@
        t3.light_address AS light_address
        FROM
        light t1
        LEFT JOIN pole_binding t5 USING ( device_code )
        LEFT JOIN pole t2 ON t2.id=t5.pole_id
        LEFT JOIN pole_binding t5 ON t1.device_code = t5.device_code
        LEFT JOIN pole t2 ON t2.id=t5.pole_id AND t5.device_type=0
        LEFT JOIN light_task_pole_relation t3 ON t3.pole_id = t2.id
        LEFT JOIN light_task t4 ON t3.task_id = t4.task_id
        <where>
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/PoleController.java
@@ -223,7 +223,7 @@
        if (!permissionConfig.check(MenuEnum.UNBIND.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        boolean result = poleService.unBindPole(poleId, param.getDeviceCode());
        boolean result = poleService.unBindPole(poleId, param.getDeviceCode(),param.getDeviceType());
        if (result) {
            //设备类型,0路灯,1led屏幕,2充电桩,3大气监测,4水质监测,5ip音柱,6lcd广告机,7摄像头,8杆体倾测,9一键救助, 10熙讯, 11农耕
            switch (param.getDeviceType().toString()) {
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleBindingService.java
@@ -190,6 +190,32 @@
        }
    }
    /**
     * 灯杆解绑设备,删除设备前需要解绑
     *
     * @param deviceCode
     */
    public boolean unBindPole(Long poleId, String deviceCode,Integer deviceType) {
        if (deviceCode == null) {
            throw new BusinessException("设备编号不能为空");
        }
        PoleBinding one;
        //直接删除设备不需要灯杆ID
        if (poleId == null) {
            one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode).eq(PoleBinding::getDeviceType, deviceType));
        } else {
            one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode)
                    .eq(PoleBinding::getDeviceType, deviceType).eq(PoleBinding::getPoleId, poleId));
        }
        if (one != null) {
            return removeById(one.getId());
        } else {
            throw new BusinessException("设备不存在绑定情况或灯杆ID不正确");
        }
    }
    /**
     * 设备删除,直接解绑设备相关绑定数据
     *
@@ -217,7 +243,7 @@
    }
    public PoleBinding getPoleIdByMac(String deviceCode) {
        return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode));
        return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode).eq(PoleBinding::getDeviceType,0));
    }
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
@@ -863,8 +863,8 @@
     *
     * @return 是否成功
     */
    public boolean unBindPole(Long poleId, String deviceCode) {
        return poleBindingService.unBindPole(poleId, deviceCode);
    public boolean unBindPole(Long poleId, String deviceCode,Integer deviceType) {
        return poleBindingService.unBindPole(poleId, deviceCode,deviceType);
    }
ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxRequestUtil.java
@@ -1,12 +1,13 @@
package com.sandu.ximon.admin.utils;
import com.alibaba.fastjson.JSON;
import com.sandu.ximon.admin.utils.request.CommonHeader;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
@@ -24,7 +25,7 @@
    private static final String UTF8 = "utf-8";
    public static String get(String url){
    public static String get(String url) {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpGet get = new HttpGet(url);
        String result = null;
@@ -32,7 +33,7 @@
            HttpResponse httpResponse = client.execute(get);
            InputStream inStream = httpResponse.getEntity().getContent();
            result = streamToString(inStream,UTF8);
            result = streamToString(inStream, UTF8);
            inStream.close();
        } catch (Exception e) {
@@ -41,39 +42,38 @@
        return result;
    }
public static String GetWithHeader (String url, List<NameValuePair> urlParameters, Map<String, String> header) throws URISyntaxException {
    public static String GetWithHeader(String url, List<NameValuePair> urlParameters, Map<String, String> header) throws URISyntaxException {
    URI finalURI = new URIBuilder(url).setParameters(urlParameters).build();
    CloseableHttpClient client = HttpClients.createDefault();
    HttpGet get = new HttpGet(finalURI);
    for(String key: header.keySet()) {
        get.setHeader(key, header.get(key));
    }
    String result = null;
    try {
        URI finalURI = new URIBuilder(url).setParameters(urlParameters).build();
        CloseableHttpClient client = HttpClients.createDefault();
        HttpGet get = new HttpGet(finalURI);
        for (String key : header.keySet()) {
            get.setHeader(key, header.get(key));
        }
        String result = null;
        try {
//            StringEntity s = new StringEntity(params, UTF8);
//            s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
//                    "application/json"));
        HttpResponse httpResponse = client.execute(get);
        InputStream inStream = httpResponse.getEntity().getContent();
            HttpResponse httpResponse = client.execute(get);
            InputStream inStream = httpResponse.getEntity().getContent();
        result = streamToString(inStream, UTF8);
            result = streamToString(inStream, UTF8);
        inStream.close();
    } catch (Exception e) {
        return null;
            inStream.close();
        } catch (Exception e) {
            return null;
        }
        return result;
    }
    return result;
}
    public static String PostWithHeader (String URL, String json, CommonHeader header) {
    public static String PostWithHeader(String URL, String json, CommonHeader header) {
        System.out.println("****************************************");
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(URL);
        for(String key: header.keySet()) {
        for (String key : header.keySet()) {
            post.setHeader(key, header.get(key));
        }
        String result = null;
@@ -84,29 +84,29 @@
            post.setEntity(s);
            HttpResponse httpResponse = client.execute(post);
            InputStream inStream = httpResponse.getEntity().getContent();
            System.out.println("post: " + JSON.toJSONString(post));
            result = streamToString(inStream,UTF8);
            result = streamToString(inStream, UTF8);
            inStream.close();
        } catch (Exception e) {
            System.out.println("error"   + e.getMessage());
            System.out.println("error" + e.getMessage());
            return null;
        }
        return result;
    }
    public static String streamToString(InputStream in, String encoding){
    public static String streamToString(InputStream in, String encoding) {
        // 将流转换为字符串
        try {
            StringBuffer sb = new StringBuffer();
            byte[] b = new byte[1024];
            for (int n; (n = in.read(b)) != -1;) {
            for (int n; (n = in.read(b)) != -1; ) {
                sb.append(new String(b, 0, n, encoding));
            }
            return sb.toString();
        }  catch (IOException e) {
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("提取 requestBody 异常", e);
        }