Quellcode durchsuchen

Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	src/main/java/com/zy/bms/config/mqtt/MqttCallbackHandler.java
chenyi406 vor 4 Jahren
Ursprung
Commit
e620006f83

+ 22 - 22
src/main/java/com/zy/bms/config/mqtt/MqttCallbackHandler.java

@@ -7,11 +7,13 @@ import com.zy.bms.model.*;
 import com.zy.bms.redis.DeviceManager;
 import com.zy.bms.service.*;
 import com.zy.bms.utils.*;
+import com.zy.bms.utils.CodeGenerator;
+import com.zy.bms.utils.CoordTransformUtil;
+import com.zy.bms.utils.GaoDeApiUtil;
 import com.zy.bms.websocket.WebSocketServer;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
-import java.util.Map;
 
 /**
  * MQTT 消息返回处理类
@@ -71,7 +73,7 @@ public class MqttCallbackHandler {
      * 注册设备
      */
     private void registerDevice(MqttMsgDto obj) {
-        String num = obj.getData().get("regnum").toString();
+        String num = obj.getString("num");
         //查询数据库中是否有此设备
         Device device = deviceService.getByNum(num);
         //没有该设备,保存至数据库
@@ -101,11 +103,11 @@ public class MqttCallbackHandler {
     private void CallRecordsHandler(MqttMsgDto obj) {
         CallRecords callRecords = new CallRecords();
         callRecords.setDeviceId(obj.getR().split("/")[1]);
-        callRecords.setCallType((int) obj.getData().get("type"));
-        callRecords.setKeyNum((String) obj.getData().get("key"));
-        callRecords.setPhoneNum((String) obj.getData().get("phnoenum"));
-        callRecords.setTalkTime((int) obj.getData().get("talktime"));
-        callRecords.setEndTime((String) obj.getData().get("endtime"));
+        callRecords.setCallType(obj.getInt("type"));
+        callRecords.setKeyNum(obj.getString("key"));
+        callRecords.setPhoneNum(obj.getString("phnoenum"));
+        callRecords.setTalkTime(obj.getInt("talktime"));
+        callRecords.setEndTime(obj.getString("endtime"));
         callRecordsService.save(callRecords);
     }
 
@@ -132,23 +134,21 @@ public class MqttCallbackHandler {
     /**
      * 解析信息转为位置对象
      */
-    private DeviceLocation MqttMsgToLocation(MqttMsgDto msg) {
+    private DeviceLocation MqttMsgToLocation(MqttMsgDto obj) {
         try {
             DeviceLocation location = new DeviceLocation();
-            Map<String, Object> dataMap = msg.getData();
-            location.setDeviceId(msg.getR().split("/")[1]);
-            location.setBatteryNum((int) dataMap.get("batterynum"));
-            location.setSignalNum((int) dataMap.get("signalnum"));
-            location.setMode((int) dataMap.get("mode"));
-            location.setLon(dataMap.get("lon").toString());
-            location.setLat(dataMap.get("lat").toString());
-            location.setSpeed(dataMap.get("speed").toString());
-            location.setNum((int) dataMap.get("num"));
-            location.setUploadTime(DateTimeUtil.strToTime((String) dataMap.get("createtime")));
-            Object cellInfo = dataMap.get("cellInfo");
-            if (cellInfo != null) {
-                location.setCellInfo(cellInfo.toString());
-            }
+            location.setDeviceId(obj.getDeviceId());
+            location.setBatteryNum(obj.getInt("batterynum"));
+            location.setSignalNum(obj.getInt("signalnum"));
+            location.setMode(obj.getInt("mode"));
+            location.setLon(obj.getString("lon"));
+            location.setLon(obj.getString("lat"));
+            location.setSpeed(obj.getString("speed"));
+            location.setNum(obj.getInt("num"));
+            location.setUploadTime(obj.getDate("createtime"));
+            Object cellInfo = obj.getObject("cellInfo");
+            //该数据项可能为空
+            if (cellInfo != null) location.setCellInfo(cellInfo.toString());
             //转换后的坐标
             String[] gcj = CoordTransformUtil.wgs84toGcj02(location.getLon(), location.getLat());
             location.setLonGcj(gcj[0]);

+ 2 - 2
src/main/java/com/zy/bms/controller/IdiomsController.java

@@ -38,8 +38,8 @@ public class IdiomsController {
      */
     @PostMapping("save.do")
     public ServerResponse save(UserIdioms entity) {
-        if (userIdiomsService.countByUserId(entity.getUserId()) > 5) {
-            return ServerResponse.createByWarningMsg("最多添加条常用语");
+        if (userIdiomsService.countByUserId(entity.getUserId()) > 10) {
+            return ServerResponse.createByWarningMsg("最多添加条常用语");
         }
         return ServerResponse.createBySuccess(userIdiomsService.save(entity));
     }

+ 2 - 2
src/main/java/com/zy/bms/controller/LocationController.java

@@ -25,14 +25,14 @@ public class LocationController {
     private DeviceLocationService locationService;
 
     @Resource
-    private DeviceManager redisService;
+    private DeviceManager redisDeviceManager;
 
     /**
      * 通过设备ID获取最新的定位信息
      */
     @GetMapping("getLocation.do")
     public ServerResponse getLocation(String deviceId) {
-        return ServerResponse.createBySuccess(redisService.getLocation(deviceId));
+        return ServerResponse.createBySuccess(redisDeviceManager.getLocation(deviceId));
     }
 
     /**

+ 0 - 1
src/main/java/com/zy/bms/mapper/BaseStationMapper.java

@@ -1,7 +1,6 @@
 package com.zy.bms.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.zy.bms.model.BaseStation;
 import org.apache.ibatis.annotations.Mapper;
 import org.springframework.stereotype.Repository;
 

+ 2 - 0
src/main/java/com/zy/bms/mapper/IdiomsMapper.java

@@ -6,6 +6,8 @@ import org.apache.ibatis.annotations.Mapper;
 import org.springframework.stereotype.Repository;
 
 /**
+ * 常用语 Mapper
+ *
  * @author chenyi
  * Create on 2020/4/10
  */

+ 0 - 32
src/main/java/com/zy/bms/model/BaseStation.java

@@ -1,32 +0,0 @@
-package com.zy.bms.model;
-
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-
-import java.time.LocalDateTime;
-
-/**
- * 基站信息
- */
-@Data
-@TableName("base_station")
-public class BaseStation {
-    @TableId
-    private Integer id;
-
-    //设备ID
-    private String deviceId;
-
-    //临近基站1
-    private String cellInf0;
-
-    //临近基站2
-    private String cellInf1;
-
-    //数据更新时间
-    private String uploadTime;
-
-    //记录创建时间
-    private LocalDateTime createTime;
-}

+ 42 - 0
src/main/java/com/zy/bms/model/MqttMsgDto.java

@@ -2,9 +2,11 @@ package com.zy.bms.model;
 
 import com.alibaba.fastjson.JSON;
 import com.zy.bms.common.Constant;
+import com.zy.bms.utils.DateTimeUtil;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -55,4 +57,44 @@ public class MqttMsgDto {
     public String toJson() {
         return JSON.toJSONString(this);
     }
+
+    /**
+     * 获取 Object 数据
+     */
+    public Object getObject(String key) {
+        return data.get(key);
+    }
+
+    /**
+     * 获取String 数据
+     */
+    public String getString(String key) {
+        return data.get(key).toString();
+    }
+
+    /**
+     * 获取 Integer 数据
+     */
+    public Integer getInt(String key) {
+        return Integer.parseInt(data.get(key).toString());
+    }
+
+    /**
+     * 获取 Double 数据
+     */
+    public Double getDouble(String key) {
+        return Double.parseDouble(data.get(key).toString());
+    }
+
+    /**
+     * 获取 日期数据 数据
+     */
+    public LocalDateTime getDate(String key) {
+        return DateTimeUtil.strToTime(data.get(key).toString());
+    }
+
+    public String getDeviceId() {
+        String[] res = r.split("/");
+        return res.length > 1 ? res[1] : "";
+    }
 }

+ 4 - 2
src/main/java/com/zy/bms/redis/DeviceManager.java

@@ -7,6 +7,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 设备信息,存放在缓存中的数据
@@ -22,12 +23,13 @@ public class DeviceManager {
 
     /**
      * 将最新位置信息保存至redis中
-     * 过期
+     * 24小时过期
      *
      * @param entity 位置信息
      */
     public void saveLocation(DeviceLocation entity) {
-        redisTemplate.opsForValue().set(Constant.REDIS_PREFIX_LOCATION + entity.getDeviceId(), JSON.toJSONString(entity));
+        redisTemplate.opsForValue().set(Constant.REDIS_PREFIX_LOCATION + entity.getDeviceId(),
+                JSON.toJSONString(entity), 24, TimeUnit.MINUTES);
     }
 
     /**

+ 0 - 1
src/main/java/com/zy/bms/service/BaseStationService.java

@@ -3,7 +3,6 @@ package com.zy.bms.service;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zy.bms.mapper.BaseStationMapper;
-import com.zy.bms.model.BaseStation;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;