瀏覽代碼

删除路牌设备

yangxiaokun 3 年之前
父節點
當前提交
3679a4a796

+ 0 - 4
src/main/java/com/zy/omp/common/Constant.java

@@ -32,10 +32,6 @@ public class Constant {
     public static final String M_CODE_UPLOAD_CALL_RECORD = "40";//设备上传通话记录
     public static final String M_CODE_CONTINUE_GPS = "41";//设备连续定位设置
 
-    public static final String M_CODE_UPLOAD_INFO_LP = "70";//路牌设备上传信息
-    public static final String M_CODE_UPDATE_DEVICE_INFO_LP = "71";//同步更新路牌设备信息
-    public static final String M_CODE_UPLOAD_LOCATION_INFO_LP = "72";//路牌设备上传定位信息
-
     /**
      * 主题前缀
      * SERVER为服务器订阅主题  用来接收设备发来消息

+ 17 - 146
src/main/java/com/zy/omp/config/mqtt/MqttCallbackHandler.java

@@ -12,7 +12,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
-import java.time.LocalDateTime;
 
 /**
  * MQTT 消息返回处理类
@@ -27,8 +26,6 @@ public class MqttCallbackHandler {
     @Resource
     private DeviceService deviceService;
     @Resource
-    private DeviceLpService deviceLpService;
-    @Resource
     private SetBaseService setBaseService;
     @Resource
     private SetService setService;
@@ -54,50 +51,27 @@ public class MqttCallbackHandler {
         mqttLogService.saveReceiveLog(topic, payload);
         //消息返回JSON转Object
         MqttMsgDto msgDto = MqttMsgDto.parse(payload);
-        //路牌项目
-        if (topic.startsWith("$regdtx2") || topic.startsWith("$dtxlp")) {
-            switch (msgDto.getM()) {
-                //设备端注册报文
-                case Constant.M_CODE_REGISTER: {
-                    registerHandler_LP(msgDto);
-                    break;
-                }
-                // 设备上传定位信息
-                case Constant.M_CODE_UPLOAD_LOCATION_INFO_LP: {
-                    uploadLocationInfoLPHandler(topic, msgDto);
-                    break;
-                }
-                // 设备上传基本信息
-                case Constant.M_CODE_UPLOAD_INFO_LP: {
-                    uploadDeviceInfoLPHandler(topic, msgDto);
-                    break;
-                }
+        switch (msgDto.getM()) {
+            //设备端注册报文
+            case Constant.M_CODE_REGISTER: {
+                registerHandler_OMP(msgDto);
+                break;
             }
-        }
-        //老人机项目
-        else {
-            switch (msgDto.getM()) {
-                //设备端注册报文
-                case Constant.M_CODE_REGISTER: {
-                    registerHandler_OMP(msgDto);
-                    break;
-                }
-                // 设备位置信息上报
-                case Constant.M_CODE_UPLOAD_LOCATION: {
-                    uploadLocationHandler(msgDto);
-                    break;
-                }
-                //设备上传通话记录
-                case Constant.M_CODE_UPLOAD_CALL_RECORD: {
-                    uploadCallRecordsHandler(msgDto);
-                    break;
-                }
+            // 设备位置信息上报
+            case Constant.M_CODE_UPLOAD_LOCATION: {
+                uploadLocationHandler(msgDto);
+                break;
             }
-            //转发消息至网页,忽略注册的报文
-            if (!topic.equals(Constant.TOPIC_REGISTER_SERVER)) {
-                webSocketServer.massMessage(msgDto.getDeviceId(), payload);
+            //设备上传通话记录
+            case Constant.M_CODE_UPLOAD_CALL_RECORD: {
+                uploadCallRecordsHandler(msgDto);
+                break;
             }
         }
+        //转发消息至网页,忽略注册的报文
+        if (!topic.equals(Constant.TOPIC_REGISTER_SERVER)) {
+            webSocketServer.massMessage(msgDto.getDeviceId(), payload);
+        }
     }
 
     /**
@@ -125,29 +99,6 @@ public class MqttCallbackHandler {
         setService.returnCode_OMP(device);
     }
 
-    /**
-     * 注册设备
-     * 路牌
-     */
-    private void registerHandler_LP(MqttMsgDto obj) {
-        String num = obj.getString("regnum");
-        //查询数据库中是否有此设备
-        DeviceLp deviceLp = deviceLpService.getByNum(num);
-        //没有该设备,保存至数据库
-        if (deviceLp == null) {
-            deviceLp = new DeviceLp();
-            deviceLp.setNum(num);
-            deviceLp.setClientId(Constant.LP_DEVICE_ID_PREFIX + num);
-            deviceLp.setPassword(MD5Util.encodeCut(num));
-            deviceLp.setGroup(obj.getString("group"));
-            deviceLpService.save(deviceLp);
-        }
-        //mqtt服务器注册用户
-        rabbitMQApi.registerMqtt(deviceLp.getClientId(), deviceLp.getPassword());
-        //发送消息
-        setService.returnCode_LP(deviceLp);
-    }
-
     /**
      * 处理上传位置
      * 老人机
@@ -177,86 +128,6 @@ public class MqttCallbackHandler {
         }
     }
 
-    /**
-     * 处理设备定位信息上传
-     * 路牌
-     */
-    private void uploadLocationInfoLPHandler(String topic, MqttMsgDto msg) {
-        try {
-            String num = topic.split("IMEI")[1];
-            DeviceLp deviceLp = new DeviceLp();
-            deviceLp.setMode(msg.getInt("mode"));
-            deviceLp.setLon(msg.getString("lng"));
-            deviceLp.setLat(msg.getString("lat"));
-            //转换后的坐标
-            String[] gcj = CoordTransformUtil.wgs84toGcj02(deviceLp.getLon(), deviceLp.getLat());
-            deviceLp.setLonGcj(gcj[0]);
-            deviceLp.setLatGcj(gcj[1]);
-            // 逆地理位置解析
-            deviceLp.setSite(GaoDeApiUtil.regeo(deviceLp.getLonGcj(), deviceLp.getLatGcj()));
-            // 保存基本信息
-            deviceLpService.updateByNum(deviceLp, num);
-        } catch (Exception e) {
-            log.error("路牌上传位置信息异常", e);
-        }
-    }
-
-    /**
-     * 处理设备基本信息上传
-     * 路牌
-     */
-    private void uploadDeviceInfoLPHandler(String topic, MqttMsgDto msg) {
-        try {
-            String num = topic.split("IMEI")[1];
-            //setService.getDeviceLocation_LP(num);
-            DeviceLp dbDevice = deviceLpService.getByNum(num);
-            if (dbDevice == null) {
-                log.warn("设备需要手动添加至数据库:" + num);
-                return;
-            }
-            DeviceLp deviceLp = new DeviceLp();
-            Double wakeInt = msg.getDouble("sleept");
-            Integer thresh = msg.getInt("thresh");
-            //若数据库中没有设置唤醒时间和阈值则直接同步设备数据
-            if (dbDevice.getThresh() == null || dbDevice.getWakeInt() == null) {
-                deviceLp.setWakeInt(wakeInt);
-                deviceLp.setThresh(thresh);
-            } else {
-                //如果远程设备的(唤醒时间,阈值)与数据库的数据不一致,则发送消息更新设备的设置数据与数据库保持一致
-                if (!dbDevice.getWakeInt().equals(wakeInt) || !dbDevice.getThresh().equals(thresh)) {
-                    setService.updateDevice_LP(num, dbDevice.getWakeInt(), dbDevice.getThresh());
-                }
-            }
-            deviceLp.setDataType(msg.getString("datetype"));
-            deviceLp.setBattery(msg.getString("batterynum"));
-            deviceLp.setS4g(msg.getString("s4g"));
-            deviceLp.setX(msg.getString("x"));
-            deviceLp.setY(msg.getString("y"));
-            deviceLp.setZ(msg.getString("z"));
-            deviceLp.setAnglex(msg.getString("anglex"));
-            deviceLp.setAngley(msg.getString("angley"));
-            deviceLp.setAnglez(msg.getString("anglez"));
-            deviceLp.setTemp(msg.getString("temp"));
-            deviceLp.setUpdateTime(LocalDateTime.now());
-            //临时解决方案
-            if (msg.getString("lng")!=null){
-                deviceLp.setMode(msg.getInt("mode"));
-                deviceLp.setLon(msg.getString("lng"));
-                deviceLp.setLat(msg.getString("lat"));
-                //转换后的坐标
-                String[] gcj = CoordTransformUtil.wgs84toGcj02(deviceLp.getLon(), deviceLp.getLat());
-                deviceLp.setLonGcj(gcj[0]);
-                deviceLp.setLatGcj(gcj[1]);
-                // 逆地理位置解析
-                deviceLp.setSite(GaoDeApiUtil.regeo(deviceLp.getLonGcj(), deviceLp.getLatGcj()));
-            }
-            // 保存基本信息
-            deviceLpService.updateByNum(deviceLp, num);
-        } catch (Exception e) {
-            log.error("路牌上传基本信息异常", e);
-        }
-    }
-
     /**
      * 设备上传通话记录
      */

+ 2 - 2
src/main/java/com/zy/omp/config/mqtt/MqttConsumerCfg.java

@@ -31,7 +31,7 @@ public class MqttConsumerCfg {
     private MqttPahoClientFactory mqttClientFactory;
 
     //默认监听主题
-    private final String[] defaultTopic = new String[]{"$regdtx", "$dtx/#","$regdtx2","$dtxlp/#"};
+    private final String[] defaultTopic = new String[]{"$regdtx", "$dtx/#"};
 
     /**
      * MQTT 消息订阅绑定(消费者)
@@ -40,7 +40,7 @@ public class MqttConsumerCfg {
     @Bean
     public MessageProducer inbound() {
         // 初始化入站通道适配器,使用的是Eclipse Paho MQTT客户端库
-        MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(CodeGenerator.generateUUID(), mqttClientFactory, defaultTopic);
+        MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(CodeGenerator.shortUuid() + "_Consumer", mqttClientFactory, defaultTopic);
         // 设置连接超时时长 毫秒
         adapter.setCompletionTimeout(5000);
         // 配置默认Paho消息转换器(qos=0, retain=false, charset=UTF-8)

+ 1 - 1
src/main/java/com/zy/omp/config/mqtt/MqttProducerCfg.java

@@ -37,7 +37,7 @@ public class MqttProducerCfg {
     @Bean
     @ServiceActivator(inputChannel = "mqttOutboundChannel")
     public MessageHandler mqttOutbound() {
-        MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(CodeGenerator.generateUUID(), mqttClientFactory);
+        MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(CodeGenerator.shortUuid() + "_Producer", mqttClientFactory);
         // 设置异步发送,默认是false(发送时阻塞)
         messageHandler.setAsync(true);
         // 设置默认的服务质量

+ 0 - 41
src/main/java/com/zy/omp/controller/wx/DeviceLpController.java

@@ -1,41 +0,0 @@
-package com.zy.omp.controller.wx;
-
-import com.zy.omp.common.ServerResponse;
-import com.zy.omp.model.DeviceLp;
-import com.zy.omp.service.DeviceLpService;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.annotation.Resource;
-
-/**
- * 设备-路牌 前端控制器
- *
- * @author chenyi
- * @since 2021-06-12
- */
-@RestController
-@RequestMapping("/omp/api/wx/device/lp")
-public class DeviceLpController {
-    @Resource
-    private DeviceLpService deviceLpService;
-
-    /**
-     * 查询所有设备
-     */
-    @GetMapping("list.do")
-    public ServerResponse getListByUserId() {
-        return ServerResponse.createBySuccess(deviceLpService.list());
-    }
-
-    /**
-     * 更新设备设置
-     */
-    @PostMapping("update.do")
-    public ServerResponse update(DeviceLp deviceLp) {
-        deviceLpService.updateParam(deviceLp);
-        return ServerResponse.createBySuccess();
-    }
-}

+ 0 - 24
src/main/java/com/zy/omp/mapper/DeviceLpMapper.java

@@ -1,24 +0,0 @@
-package com.zy.omp.mapper;
-
-import com.zy.omp.model.DeviceLp;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.springframework.stereotype.Repository;
-
-/**
- * <p>
- * 设备-路牌 Mapper 接口
- * </p>
- *
- * @author chenyi
- * @since 2021-06-12
- */
-@Mapper
-@Repository
-public interface DeviceLpMapper extends BaseMapper<DeviceLp> {
-    /**
-     * 更新可设置参数
-     */
-    void updateParam(@Param("entity") DeviceLp deviceLp);
-}

+ 0 - 140
src/main/java/com/zy/omp/model/DeviceLp.java

@@ -1,140 +0,0 @@
-package com.zy.omp.model;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-
-/**
- * <p>
- * 设备-路牌
- * </p>
- *
- * @author chenyi
- * @since 2021-06-12
- */
-@Data
-@TableName("device_lp")
-public class DeviceLp implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @TableId(value = "id", type = IdType.AUTO)
-    private Integer id;
-
-    /**
-     * 设备IMEI
-     */
-    private String num;
-
-    /**
-     * 登录MQTT 用户名
-     */
-    private String clientId;
-
-    /**
-     * 登录MQTT 密码
-     */
-    private String password;
-
-    /**
-     * 设备组
-     */
-    @TableField("`group`")
-    private String group;
-
-    /**
-     * SN码
-     */
-    private String sn;
-
-    /**
-     * 定时唤醒时间
-     */
-    private Double wakeInt;
-
-    /**
-     * 阈值
-     */
-    private Integer thresh;
-
-    /**
-     * 电量
-     */
-    private String battery;
-
-    /**
-     * 信号
-     */
-    private String s4g;
-
-    private String x;
-
-    private String y;
-
-    private String z;
-
-    private String anglex;
-
-    private String angley;
-
-    private String anglez;
-
-    /**
-     * 温度
-     */
-    private String temp;
-
-    /**
-     * 经度
-     */
-    private String lon;
-
-    /**
-     * 纬度
-     */
-    private String lat;
-
-    /**
-     * 经度(gcj)
-     */
-    private String lonGcj;
-
-    /**
-     * 纬度(gcj)
-     */
-    private String latGcj;
-
-    /**
-     * 格式化的地理位置
-     */
-    private String site;
-
-    /**
-     * 定位模式 1:GPS 2:基站
-     */
-    private Integer mode;
-
-    /**
-     * 上传类型
-     */
-    private String dataType;
-
-    /**
-     * 数据更新时间
-     */
-    private LocalDateTime updateTime;
-
-    /**
-     * 获取在线状态
-     */
-    public Integer getStatus() {
-        if (updateTime == null || wakeInt == null) return 0;
-        return updateTime.compareTo(LocalDateTime.now().minusMinutes((int) (wakeInt * 60) + 5));
-    }
-}

+ 0 - 50
src/main/java/com/zy/omp/service/DeviceLpService.java

@@ -1,50 +0,0 @@
-package com.zy.omp.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.zy.omp.model.DeviceLp;
-import com.zy.omp.mapper.DeviceLpMapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-
-/**
- * <p>
- * 设备-路牌 服务实现类
- * </p>
- *
- * @author chenyi
- * @since 2021-06-12
- */
-@Service
-public class DeviceLpService extends ServiceImpl<DeviceLpMapper, DeviceLp> {
-    @Resource
-    private SetService setService;
-
-    /**
-     * 通过设备 num 获取设备信息
-     *
-     * @param num 设备号
-     */
-    public DeviceLp getByNum(String num) {
-        QueryWrapper<DeviceLp> queryWrapper = new QueryWrapper<DeviceLp>().eq("num", num);
-        return baseMapper.selectOne(queryWrapper);
-    }
-
-    /**
-     * 更新设备信息
-     */
-    public void updateByNum(DeviceLp entity, String num) {
-        UpdateWrapper<DeviceLp> updateWrapper = new UpdateWrapper<DeviceLp>().eq("num", num);
-        baseMapper.update(entity, updateWrapper);
-    }
-
-    /**
-     * 更新可设置参数
-     */
-    public void updateParam(DeviceLp entity) {
-        setService.updateDevice_LP(entity.getNum(), entity.getWakeInt(), entity.getThresh());
-        baseMapper.updateParam(entity);
-    }
-}

+ 0 - 54
src/main/java/com/zy/omp/service/SetService.java

@@ -1,7 +1,6 @@
 package com.zy.omp.service;
 
 import com.zy.omp.common.Constant;
-import com.zy.omp.model.DeviceLp;
 import com.zy.omp.pojo.dto.MqttMsgDto;
 import com.zy.omp.config.mqtt.MqttGateway;
 import com.zy.omp.model.Device;
@@ -135,57 +134,4 @@ public class SetService {
         mqttLogService.saveSendLog(Constant.TOPIC_REGISTER_CLIENT, msgDto.toJson());
     }
 
-    /**
-     * 服务器返回授权码
-     * 路牌
-     */
-    public void returnCode_LP(DeviceLp device) {
-        //发送模板消息给设备
-        MqttMsgDto msgDto = new MqttMsgDto();
-        msgDto.setM(Constant.M_CODE_RETURN_CODE);
-        Map<String, Object> data = new HashMap<>();
-        data.put("regnum", device.getNum());
-        data.put("sn", "SN" + device.getNum());
-        data.put("password", device.getPassword());
-        data.put("group", device.getGroup());
-        msgDto.setData(data);
-        mqttGateway.sendMsgToMqtt(msgDto.toJson(), Constant.TOPIC_REGISTER_CLIENT_LP);
-        // 3. 存储消息日志
-        mqttLogService.saveSendLog(Constant.TOPIC_REGISTER_CLIENT_LP, msgDto.toJson());
-    }
-
-    /**
-     * 服务器返回授权码
-     * 路牌
-     */
-    public void updateDevice_LP(String num, Double wakeInt, Integer thresh) {
-        //发送模板消息给设备
-        MqttMsgDto msgDto = new MqttMsgDto();
-        msgDto.setM(Constant.M_CODE_UPDATE_DEVICE_INFO_LP);
-        Map<String, Object> data = new HashMap<>();
-        data.put("setf", "true");
-        data.put("wakeint", wakeInt);
-        data.put("thresh", thresh);
-        msgDto.setData(data);
-        mqttGateway.sendMsgToMqtt(msgDto.toJson(), Constant.TOPIC_DEVICE_CLIENT_LP + num);
-        // 3. 存储消息日志
-        mqttLogService.saveSendLog(Constant.TOPIC_DEVICE_CLIENT_LP + num, msgDto.toJson());
-    }
-
-    /**
-     * 获取路牌定位信息
-     * 路牌
-     */
-    public void getDeviceLocation_LP(String num) {
-        //发送模板消息给设备
-        MqttMsgDto msgDto = new MqttMsgDto();
-        msgDto.setM(Constant.M_CODE_UPDATE_DEVICE_INFO_LP);
-        Map<String, Object> data = new HashMap<>();
-        data.put("setf", "false");
-        data.put("getlocation", "true");
-        msgDto.setData(data);
-        mqttGateway.sendMsgToMqtt(msgDto.toJson(), Constant.TOPIC_DEVICE_CLIENT_LP + num);
-        // 3. 存储消息日志
-        mqttLogService.saveSendLog(Constant.TOPIC_DEVICE_CLIENT_LP + num, msgDto.toJson());
-    }
 }

+ 0 - 24
src/main/java/com/zy/omp/utils/MD5Util.java

@@ -33,28 +33,4 @@ public class MD5Util {
         }
     }
 
-    /**
-     * MD5 字符串加密
-     * 裁剪 用作密码,短几位
-     *
-     * @param plainText 加密字符串
-     */
-    public static String encodeCut(String plainText) {
-        try {
-            StringBuilder stringBuilder = new StringBuilder();
-            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
-            messageDigest.update(plainText.getBytes());
-            byte[] bytes = messageDigest.digest();
-            int i;
-            for (byte value : bytes) {
-                i = value;
-                if (i < 0) i += 256;
-                if (i < 16) stringBuilder.append("0");
-                stringBuilder.append(Integer.toHexString(i));
-            }
-            return stringBuilder.toString().substring(16);
-        } catch (Exception e) {
-            return "MD5";
-        }
-    }
 }

+ 5 - 5
src/main/resources/application-prod.yml

@@ -1,11 +1,11 @@
 server:
-  port: 9001 # Key product method
+  port: 9000 # Key product method
 spring:
   redis:
     host: localhost
     port: 6379
     timeout: 9000
-    password: CHENyi_406
+#    password: CHENyi_406
   jackson:
     default-property-inclusion: non_null
     date-format: yyyy-MM-dd HH:mm:ss
@@ -14,9 +14,9 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://localhost:3306/zy_mobile?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=true
-    username: root
-    password: kun95736489+
+    url: jdbc:mysql://59.110.141.39:3306/zy_mobile?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=true
+    username: useryxk
+    password: CHENyi406@
     dbcp2:
       min-idle: 10
       initial-size: 15

+ 0 - 11
src/main/resources/mapper/DeviceLpMapper.xml

@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.zy.omp.mapper.DeviceLpMapper">
-    <update id="updateParam">
-        UPDATE
-            device_lp
-        SET wakeInt = #{entity.wakeInt},
-            thresh  = #{entity.thresh}
-        WHERE num = #{entity.num}
-    </update>
-</mapper>