bihuisong 1 سال پیش
والد
کامیت
2aaa919783

+ 44 - 44
src/main/java/com/sooka/sponest/dataexchange/monitoringEquipment/chenganshengbang/controller/WaterPressureController.java

@@ -1,44 +1,44 @@
-package com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.controller;
-
-import com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.service.WaterPressureService;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.annotation.Resource;
-
-@RestController
-@RequestMapping("/api/WaterPressure")
-public class WaterPressureController {
-
-    @Resource
-    private WaterPressureService waterPressureService;
-
-    /**
-     * 水压传感器上报数据
-     * */
-    @PostMapping("/waterPressureMessageReceiver")
-    public byte[] waterPressureMessageReceiver(@RequestBody String data){
-        waterPressureService.waterPressureMessageReceiver(data);
-        return responseData();
-    }
-
-    /**
-     * 水压传感器指令下发
-     * */
-    @PostMapping("/command")
-    public String command(@RequestBody String data){
-        return waterPressureService.command(data);
-    }
-
-    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;
-    }
-}
+//package com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.controller;
+//
+//import com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.service.WaterPressureService;
+//import org.springframework.web.bind.annotation.PostMapping;
+//import org.springframework.web.bind.annotation.RequestBody;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//
+//import javax.annotation.Resource;
+//
+//@RestController
+//@RequestMapping("/api/WaterPressure")
+//public class WaterPressureController {
+//
+//    @Resource
+//    private WaterPressureService waterPressureService;
+//
+//    /**
+//     * 水压传感器上报数据
+//     * */
+//    @PostMapping("/waterPressureMessageReceiver")
+//    public byte[] waterPressureMessageReceiver(@RequestBody String data){
+//        waterPressureService.waterPressureMessageReceiver(data);
+//        return responseData();
+//    }
+//
+//    /**
+//     * 水压传感器指令下发
+//     * */
+//    @PostMapping("/command")
+//    public String command(@RequestBody String data){
+//        return waterPressureService.command(data);
+//    }
+//
+//    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;
+//    }
+//}

+ 9 - 9
src/main/java/com/sooka/sponest/dataexchange/monitoringEquipment/chenganshengbang/service/WaterPressureService.java

@@ -1,9 +1,9 @@
-package com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.service;
-
-
-public interface WaterPressureService {
-
-    void waterPressureMessageReceiver(String data);
-
-    String command(String data);
-}
+//package com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.service;
+//
+//
+//public interface WaterPressureService {
+//
+//    void waterPressureMessageReceiver(String data);
+//
+//    String command(String data);
+//}

+ 60 - 60
src/main/java/com/sooka/sponest/dataexchange/monitoringEquipment/chenganshengbang/service/impl/WaterPressureServiceImpl.java

@@ -1,60 +1,60 @@
-package com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.service.impl;
-
-import cn.hutool.http.HttpRequest;
-import com.alibaba.fastjson.JSONObject;
-import com.ruoyi.common.core.web.domain.AjaxResult;
-import com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.service.WaterPressureService;
-import com.sooka.sponest.dataexchange.remoteapi.service.center.monitor.RemoteMonitorService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-
-@Service
-public class WaterPressureServiceImpl implements WaterPressureService {
-
-    private static final Logger log = LoggerFactory.getLogger(WaterPressureServiceImpl.class);
-
-    @Resource
-    public RemoteMonitorService remoteMonitorService;
-
-    /**水压传感器指令地址**/
-    @Value("${monitoringEquipment.waterPressure.commandURL:}")
-    public String commandURL;
-
-
-    public void waterPressureMessageReceiver(String data){
-        log.info("WaterPressure 接到数据 ==>{}",data);
-        JSONObject object;
-        AjaxResult res;
-        try {
-            object = JSONObject.parseObject(data);
-            res = remoteMonitorService.saveWaterPressureDeviceData(object);
-            log.info("WaterPressure 数据推送成功! data ===> {} , result ===> {}",data, res);
-        }catch(Exception e){
-            e.printStackTrace();
-            log.error("WaterPressure 数据推送失败! data ===> {} , result ===> {}",data, e.getMessage());
-        }
-    }
-
-    public String command(String data){
-        log.info("WaterPressure-command 接到指令 ==>{}",data);
-        JSONObject object;
-        String res = null;
-        try {
-            object = JSONObject.parseObject(data);
-            res = HttpRequest.post(commandURL)
-                    .header("Content-Type", "application/json")
-                    .body(object.toJSONString())
-                    .execute().body();
-            log.info("指令下发成功! data ===> {} , result ===> {}",data, res);
-            return res;
-        }catch(Exception e){
-            e.printStackTrace();
-            log.error("指令下发失败! data ===> {} , result ===> {}",data, e.getMessage());
-            return res;
-        }
-    }
-}
+//package com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.service.impl;
+//
+//import cn.hutool.http.HttpRequest;
+//import com.alibaba.fastjson.JSONObject;
+//import com.ruoyi.common.core.web.domain.AjaxResult;
+//import com.sooka.sponest.dataexchange.monitoringEquipment.chenganshengbang.service.WaterPressureService;
+//import com.sooka.sponest.dataexchange.remoteapi.service.center.monitor.RemoteMonitorService;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.stereotype.Service;
+//
+//import javax.annotation.Resource;
+//
+//@Service
+//public class WaterPressureServiceImpl implements WaterPressureService {
+//
+//    private static final Logger log = LoggerFactory.getLogger(WaterPressureServiceImpl.class);
+//
+//    @Resource
+//    public RemoteMonitorService remoteMonitorService;
+//
+//    /**水压传感器指令地址**/
+//    @Value("${monitoringEquipment.waterPressure.commandURL:}")
+//    public String commandURL;
+//
+//
+//    public void waterPressureMessageReceiver(String data){
+//        log.info("WaterPressure 接到数据 ==>{}",data);
+//        JSONObject object;
+//        AjaxResult res;
+//        try {
+//            object = JSONObject.parseObject(data);
+//            res = remoteMonitorService.saveWaterPressureDeviceData(object);
+//            log.info("WaterPressure 数据推送成功! data ===> {} , result ===> {}",data, res);
+//        }catch(Exception e){
+//            e.printStackTrace();
+//            log.error("WaterPressure 数据推送失败! data ===> {} , result ===> {}",data, e.getMessage());
+//        }
+//    }
+//
+//    public String command(String data){
+//        log.info("WaterPressure-command 接到指令 ==>{}",data);
+//        JSONObject object;
+//        String res = null;
+//        try {
+//            object = JSONObject.parseObject(data);
+//            res = HttpRequest.post(commandURL)
+//                    .header("Content-Type", "application/json")
+//                    .body(object.toJSONString())
+//                    .execute().body();
+//            log.info("指令下发成功! data ===> {} , result ===> {}",data, res);
+//            return res;
+//        }catch(Exception e){
+//            e.printStackTrace();
+//            log.error("指令下发失败! data ===> {} , result ===> {}",data, e.getMessage());
+//            return res;
+//        }
+//    }
+//}

+ 114 - 114
src/main/java/com/sooka/sponest/dataexchange/monitoringEquipment/shuicejia/TcpServer.java

@@ -1,114 +1,114 @@
-package com.sooka.sponest.dataexchange.monitoringEquipment.shuicejia;
-
-import cn.hutool.core.io.BufferUtil;
-import cn.hutool.core.io.IORuntimeException;
-import cn.hutool.core.io.IoUtil;
-import cn.hutool.core.util.StrUtil;
-import cn.hutool.socket.nio.NioServer;
-import com.alibaba.fastjson.JSONObject;
-import com.ruoyi.common.core.web.domain.AjaxResult;
-import com.sooka.sponest.dataexchange.remoteapi.service.center.monitor.RemoteMonitorService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-@Component
-public class TcpServer extends Thread implements CommandLineRunner {
-
-    private static final Logger log = LoggerFactory.getLogger(TcpServer.class);
-    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
-    /**服务器地址**/
-    @Value("${monitoringEquipment.tcp.port:}")
-    public Integer port;
-
-    @Resource
-    public RemoteMonitorService remoteMonitorService;
-
-
-    @Override
-    public void run(String... args){
-        NioServer server = new NioServer(port);
-        server.setChannelHandler((sc)->{
-            ByteBuffer readBuffer = ByteBuffer.allocate(1024);
-            try{
-                int readBytes = sc.read(readBuffer);
-                if (readBytes > 0) {
-                    readBuffer.flip();
-                    byte[] bytes = new byte[readBuffer.remaining()];
-                    readBuffer.get(bytes);
-                    String body = StrUtil.utf8Str(bytes);
-                    readAndWrite(sc, body);
-                } else if (readBytes < 0) {
-                    IoUtil.close(sc);
-                }
-            } catch (IOException e){
-                throw new IORuntimeException(e);
-            }
-        });
-        server.listen();
-    }
-
-    public void readAndWrite(SocketChannel channel, String response) throws IOException {
-        JSONObject object;
-        AjaxResult result;
-        log.info("TCPServer 收到数据 ==> {}", response);
-        try {
-            object = JSONObject.parseObject(response);
-            //推送数据到监控中心
-            result = remoteMonitorService.saveWaterMonitoringData(object);
-            log.info("TCPServer 数据推送成功! result ===> {}", result);
-        } catch (Exception e) {
-            e.printStackTrace();
-            log.info("TCPServer 数据推送失败! result ===> {}", e.getMessage());
-            return;
-        }
-        //返回客户端数据
-        String st = object.get("ST").toString();
-        Integer serial = Integer.parseInt(object.get("SERIAL").toString());
-        JSONObject res = new JSONObject();
-        res.put("ST",st);
-        res.put("SERIAL",serial);
-        res.put("MARK",1);
-        res.put("TM", sdf.format(new Date()));
-        //将缓冲数据写入渠道,返回给客户端
-        channel.write(BufferUtil.createUtf8(res.toJSONString()));
-    }
-
-
-    /**
-     * 对象转Map
-     * @param object
-     * @return
-     * @throws IllegalAccessException
-     */
-    public static Map beanToMap(Object object){
-        Map<String, Object> map = new HashMap<>();
-        Field[] fields = object.getClass().getDeclaredFields();
-        for (Field field : fields) {
-            field.setAccessible(true);
-            try {
-                map.put(field.getName(), field.get(object));
-            } catch (IllegalAccessException e) {
-                e.printStackTrace();
-            }
-        }
-        return map;
-    }
-
-
-}
-
-
+//package com.sooka.sponest.dataexchange.monitoringEquipment.shuicejia;
+//
+//import cn.hutool.core.io.BufferUtil;
+//import cn.hutool.core.io.IORuntimeException;
+//import cn.hutool.core.io.IoUtil;
+//import cn.hutool.core.util.StrUtil;
+//import cn.hutool.socket.nio.NioServer;
+//import com.alibaba.fastjson.JSONObject;
+//import com.ruoyi.common.core.web.domain.AjaxResult;
+//import com.sooka.sponest.dataexchange.remoteapi.service.center.monitor.RemoteMonitorService;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.boot.CommandLineRunner;
+//import org.springframework.stereotype.Component;
+//
+//import javax.annotation.Resource;
+//import java.io.IOException;
+//import java.lang.reflect.Field;
+//import java.nio.ByteBuffer;
+//import java.nio.channels.SocketChannel;
+//import java.text.SimpleDateFormat;
+//import java.util.Date;
+//import java.util.HashMap;
+//import java.util.Map;
+//
+//@Component
+//public class TcpServer extends Thread implements CommandLineRunner {
+//
+//    private static final Logger log = LoggerFactory.getLogger(TcpServer.class);
+//    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//
+//    /**服务器地址**/
+//    @Value("${monitoringEquipment.tcp.port:}")
+//    public Integer port;
+//
+//    @Resource
+//    public RemoteMonitorService remoteMonitorService;
+//
+//
+//    @Override
+//    public void run(String... args){
+//        NioServer server = new NioServer(port);
+//        server.setChannelHandler((sc)->{
+//            ByteBuffer readBuffer = ByteBuffer.allocate(1024);
+//            try{
+//                int readBytes = sc.read(readBuffer);
+//                if (readBytes > 0) {
+//                    readBuffer.flip();
+//                    byte[] bytes = new byte[readBuffer.remaining()];
+//                    readBuffer.get(bytes);
+//                    String body = StrUtil.utf8Str(bytes);
+//                    readAndWrite(sc, body);
+//                } else if (readBytes < 0) {
+//                    IoUtil.close(sc);
+//                }
+//            } catch (IOException e){
+//                throw new IORuntimeException(e);
+//            }
+//        });
+//        server.listen();
+//    }
+//
+//    public void readAndWrite(SocketChannel channel, String response) throws IOException {
+//        JSONObject object;
+//        AjaxResult result;
+//        log.info("TCPServer 收到数据 ==> {}", response);
+//        try {
+//            object = JSONObject.parseObject(response);
+//            //推送数据到监控中心
+//            result = remoteMonitorService.saveWaterMonitoringData(object);
+//            log.info("TCPServer 数据推送成功! result ===> {}", result);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            log.info("TCPServer 数据推送失败! result ===> {}", e.getMessage());
+//            return;
+//        }
+//        //返回客户端数据
+//        String st = object.get("ST").toString();
+//        Integer serial = Integer.parseInt(object.get("SERIAL").toString());
+//        JSONObject res = new JSONObject();
+//        res.put("ST",st);
+//        res.put("SERIAL",serial);
+//        res.put("MARK",1);
+//        res.put("TM", sdf.format(new Date()));
+//        //将缓冲数据写入渠道,返回给客户端
+//        channel.write(BufferUtil.createUtf8(res.toJSONString()));
+//    }
+//
+//
+//    /**
+//     * 对象转Map
+//     * @param object
+//     * @return
+//     * @throws IllegalAccessException
+//     */
+//    public static Map beanToMap(Object object){
+//        Map<String, Object> map = new HashMap<>();
+//        Field[] fields = object.getClass().getDeclaredFields();
+//        for (Field field : fields) {
+//            field.setAccessible(true);
+//            try {
+//                map.put(field.getName(), field.get(object));
+//            } catch (IllegalAccessException e) {
+//                e.printStackTrace();
+//            }
+//        }
+//        return map;
+//    }
+//
+//
+//}
+//
+//