Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/zy/omp/model/Device.java
#	src/main/java/com/zy/omp/schedule/DeviceStatusSchedule.java
#	src/main/resources/mapper/DeviceMapping.xml
chenyi406 2 years ago
parent
commit
c22f7ba6cf
59 changed files with 596 additions and 1062 deletions
  1. 6 20
      src/main/java/com/zy/omp/common/Constant.java
  2. 1 1
      src/main/java/com/zy/omp/common/controller/BaseController.java
  3. 0 43
      src/main/java/com/zy/omp/common/redis/DeviceLatestLocationManager.java
  4. 1 19
      src/main/java/com/zy/omp/common/redis/SessionManager.java
  5. 43 38
      src/main/java/com/zy/omp/config/mqtt/MqttCallbackHandler.java
  6. 0 58
      src/main/java/com/zy/omp/controller/pc/AdminController.java
  7. 2 10
      src/main/java/com/zy/omp/controller/pc/PcDeviceController.java
  8. 0 31
      src/main/java/com/zy/omp/controller/pc/PcLocationController.java
  9. 0 28
      src/main/java/com/zy/omp/controller/pc/PcMqttLogController.java
  10. 21 19
      src/main/java/com/zy/omp/controller/pc/PcSetController.java
  11. 49 48
      src/main/java/com/zy/omp/controller/wx/DeviceController.java
  12. 0 54
      src/main/java/com/zy/omp/controller/wx/IdiomsController.java
  13. 0 41
      src/main/java/com/zy/omp/controller/wx/LocationController.java
  14. 25 19
      src/main/java/com/zy/omp/controller/wx/SetController.java
  15. 5 5
      src/main/java/com/zy/omp/controller/wx/SetInfoController.java
  16. 2 2
      src/main/java/com/zy/omp/mapper/DeviceInfoRecordMapper.java
  17. 28 0
      src/main/java/com/zy/omp/mapper/DeviceInfoStateMapper.java
  18. 2 9
      src/main/java/com/zy/omp/mapper/DeviceMapper.java
  19. 2 2
      src/main/java/com/zy/omp/mapper/DeviceSetMapper.java
  20. 1 0
      src/main/java/com/zy/omp/mapper/IdiomsMapper.java
  21. 0 25
      src/main/java/com/zy/omp/mapper/LatestLocationMapper.java
  22. 7 7
      src/main/java/com/zy/omp/mapper/RelationMapper.java
  23. 1 1
      src/main/java/com/zy/omp/model/CallRecords.java
  24. 3 15
      src/main/java/com/zy/omp/model/Device.java
  25. 0 52
      src/main/java/com/zy/omp/model/DeviceDynamic.java
  26. 2 8
      src/main/java/com/zy/omp/model/DeviceInfoRecord.java
  27. 17 19
      src/main/java/com/zy/omp/model/DeviceInfoState.java
  28. 9 9
      src/main/java/com/zy/omp/model/DeviceSet.java
  29. 1 1
      src/main/java/com/zy/omp/model/News.java
  30. 42 0
      src/main/java/com/zy/omp/model/Relation.java
  31. 5 2
      src/main/java/com/zy/omp/model/User.java
  32. 1 1
      src/main/java/com/zy/omp/model/UserIdioms.java
  33. 2 2
      src/main/java/com/zy/omp/pojo/dto/MqttMsgDto.java
  34. 1 1
      src/main/java/com/zy/omp/pojo/io/pc/DeviceIO.java
  35. 0 26
      src/main/java/com/zy/omp/pojo/io/wechat/DeviceHistoryIO.java
  36. 0 3
      src/main/java/com/zy/omp/pojo/io/wechat/SetIO.java
  37. 6 15
      src/main/java/com/zy/omp/pojo/vo/DeviceListVo.java
  38. 78 0
      src/main/java/com/zy/omp/pojo/vo/WxLatestDeviceState.java
  39. 0 52
      src/main/java/com/zy/omp/schedule/DeviceStatusSchedule.java
  40. 0 61
      src/main/java/com/zy/omp/service/DeviceDynamicService.java
  41. 21 0
      src/main/java/com/zy/omp/service/DeviceInfoRecordService.java
  42. 33 0
      src/main/java/com/zy/omp/service/DeviceInfoStateService.java
  43. 3 34
      src/main/java/com/zy/omp/service/DeviceService.java
  44. 60 0
      src/main/java/com/zy/omp/service/DeviceSetService.java
  45. 1 0
      src/main/java/com/zy/omp/service/IdiomsService.java
  46. 0 26
      src/main/java/com/zy/omp/service/LatestLocationService.java
  47. 0 65
      src/main/java/com/zy/omp/service/LocationService.java
  48. 0 2
      src/main/java/com/zy/omp/service/MqttLogService.java
  49. 36 0
      src/main/java/com/zy/omp/service/RelationService.java
  50. 0 73
      src/main/java/com/zy/omp/service/SetBaseService.java
  51. 40 45
      src/main/java/com/zy/omp/service/SetService.java
  52. 10 4
      src/main/java/com/zy/omp/service/UserService.java
  53. 0 8
      src/main/java/com/zy/omp/websocket/WebSocketServer.java
  54. 1 1
      src/main/resources/application-dev.yml
  55. 15 0
      src/main/resources/mapper/DeviceInfoStateMapping.xml
  56. 10 37
      src/main/resources/mapper/DeviceMapping.xml
  57. 0 13
      src/main/resources/mapper/LatestLocationMapping.xml
  58. 0 4
      src/main/resources/mapper/LocationMapping.xml
  59. 3 3
      src/main/resources/mapper/RelationMapping.xml

+ 6 - 20
src/main/java/com/zy/omp/common/Constant.java

@@ -8,15 +8,12 @@ package com.zy.omp.common;
  */
 public class Constant {
 
-
-    public static final String OLD_PHONE_DEVICE_ID_PREFIX = "omp_";//老人机项目设备注册MQTT用户名前缀
-    public static final String LP_DEVICE_ID_PREFIX = "IMEI";//路牌项目设备注册MQTT用户名前缀
+    public static final String DEVICE_ID_PREFIX = "OMP";//老人机项目设备注册MQTT用户名前缀
 
     /**
      * redis key前缀
      */
-    public static final String REDIS_LOCATION = "omp:device:location";//数据上传位置信息前缀
-    public static final String REDIS_TOKEN_PREFIX = "omp:user:token:";//PC管理员登录token 前缀
+    public static final String REDIS_TOKEN_PREFIX = "bms:user:token:";//PC管理员登录token 前缀
 
     /**
      * MQTT 协议报文 中 M值
@@ -40,20 +37,9 @@ public class Constant {
     public static final String TOPIC_REGISTER_SERVER = "$regdtx";
     public static final String TOPIC_REGISTER_CLIENT = "$regdrx";
     public static final String TOPIC_DEVICE_SERVER = "$dtx/";
-    public static final String TOPIC_DEVICE_CLIENT = "$drx/";
-
-    /**
-     * 路牌
-     */
-    public static final String TOPIC_REGISTER_SERVER_LP = "$regdtx2";
-    public static final String TOPIC_REGISTER_CLIENT_LP = "$regdrx2";
-    public static final String TOPIC_DEVICE_SERVER_LP = "$dtxlp/";
-    public static final String TOPIC_DEVICE_CLIENT_LP = "$drxlp/IMEI";
+    public static final String TOPIC_DEVICE_CLIENT = "$drx/OMP";
 
-    /**
-     * 微信小程序登录相关配置
-     */
-    public static final String wxAppId = "wxe90699b45e28a0b6";// 小程序唯一标识
-    public static final String wxSecret = "66690a1ffcfe7f1d85a6dcfa38791f25";//小程序的 app secret
-    public static final String grant_type = "authorization_code"; // 授权(必填)
+    public static String getTopic(String openNum) {
+        return TOPIC_DEVICE_CLIENT + openNum;
+    }
 }

+ 1 - 1
src/main/java/com/zy/omp/common/controller/BaseController.java

@@ -27,7 +27,7 @@ public class BaseController {
      * 微信小程序
      * 获取用户ID
      */
-    public String getUserId() {
+    public String getOpenId() {
         String userId = AesUtils.decrypt(request.getHeader("user"));
         if (userId == null) throw new ApiRuntimeException("未登录");
         return userId;

+ 0 - 43
src/main/java/com/zy/omp/common/redis/DeviceLatestLocationManager.java

@@ -1,43 +0,0 @@
-package com.zy.omp.common.redis;
-
-import com.alibaba.fastjson.JSON;
-import com.zy.omp.common.Constant;
-import com.zy.omp.model.Location;
-import org.springframework.data.redis.core.RedisTemplate;
-
-import javax.annotation.Resource;
-
-/**
- * 设备最新的位置信息,存储在Redis缓存中
- * 弃用
- *
- * @author yang xiao kun
- * create on 2021/2/8
- */
-//@Component
-@Deprecated
-public class DeviceLatestLocationManager {
-
-    @Resource
-    private RedisTemplate<String, String> redisTemplate;
-
-    /**
-     * 将最新位置信息保存至redis中
-     *
-     * @param entity 位置信息
-     */
-    public void saveLocation(Location entity) {
-        redisTemplate.boundHashOps(Constant.REDIS_LOCATION).put(entity.getDeviceId(), JSON.toJSONString(entity));
-    }
-
-    /**
-     * 获取设备最新位置信息
-     *
-     * @param deviceId 设备ID
-     */
-    public Location getLocation(String deviceId) {
-        Object json = redisTemplate.boundHashOps(Constant.REDIS_LOCATION).get(deviceId);
-        if (json == null) return null;
-        return JSON.parseObject(json.toString(), Location.class);
-    }
-}

+ 1 - 19
src/main/java/com/zy/omp/common/redis/SessionManager.java

@@ -22,24 +22,6 @@ public class SessionManager {
     @Resource
     private StringRedisTemplate stringRedisTemplate;
 
-    /**
-     * 生成token
-     */
-    public String generateToken(Admin admin) {
-        String token = CodeGenerator.generateUUID();
-        stringRedisTemplate.opsForValue()
-                .set(Constant.REDIS_TOKEN_PREFIX + token, JSON.toJSONString(admin), 30, TimeUnit.MINUTES);
-        return token;
-    }
-
-    /**
-     * 删除Token
-     */
-    public void removeToken(String token) {
-        if (token == null) return;
-        stringRedisTemplate.delete(Constant.REDIS_TOKEN_PREFIX + token);
-    }
-
     /**
      * 获取登录的用户信息
      */
@@ -52,7 +34,7 @@ public class SessionManager {
      * 验证token有效
      */
     public boolean valid(String token) {
-        if (token == null || getUser(token) == null) return false;
+        if (getUser(token) == null) return false;
         stringRedisTemplate.expire(Constant.REDIS_TOKEN_PREFIX + token, 30, TimeUnit.MINUTES);
         return true;
     }

+ 43 - 38
src/main/java/com/zy/omp/config/mqtt/MqttCallbackHandler.java

@@ -1,5 +1,6 @@
 package com.zy.omp.config.mqtt;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.zy.omp.common.Constant;
 import com.zy.omp.pojo.dto.MqttMsgDto;
 import com.zy.omp.model.*;
@@ -9,6 +10,7 @@ import com.zy.omp.utils.CoordTransformUtil;
 import com.zy.omp.utils.GaoDeApiUtil;
 import com.zy.omp.websocket.WebSocketServer;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -27,11 +29,13 @@ public class MqttCallbackHandler {
     @Resource
     private DeviceService deviceService;
     @Resource
-    private SetBaseService setBaseService;
+    private DeviceInfoStateService deviceInfoStateService;
     @Resource
-    private SetService setService;
+    private DeviceInfoRecordService deviceInfoRecordService;
+    @Resource
+    private DeviceSetService deviceSetService;
     @Resource
-    private LocationService deviceLocationService;
+    private SetService setService;
     @Resource
     private WebSocketServer webSocketServer;
     @Resource
@@ -55,75 +59,76 @@ public class MqttCallbackHandler {
         switch (msgDto.getM()) {
             //设备端注册报文
             case Constant.M_CODE_REGISTER: {
-                registerHandler_OMP(msgDto);
+                doRegister(msgDto);
                 break;
             }
             // 设备位置信息上报
             case Constant.M_CODE_UPLOAD_LOCATION: {
-                uploadLocationHandler(msgDto);
+                doUploadLocation(msgDto);
                 break;
             }
             //设备上传通话记录
             case Constant.M_CODE_UPLOAD_CALL_RECORD: {
-                uploadCallRecordsHandler(msgDto);
+                doUploadCallRecord(msgDto);
                 break;
             }
         }
         //转发消息至网页,忽略注册的报文
         if (!topic.equals(Constant.TOPIC_REGISTER_SERVER)) {
-            webSocketServer.massMessage(msgDto.getDeviceId(), payload);
+            webSocketServer.massMessage(msgDto.getOpenNum(), payload);
         }
     }
 
     /**
      * 注册设备
-     * 老人机
      */
-    private void registerHandler_OMP(MqttMsgDto obj) {
-        String num = obj.getString("regnum");
+    private void doRegister(MqttMsgDto obj) {
+        String openNum = obj.getString("regnum");
         //查询数据库中是否有此设备
-        Device device = deviceService.getByNum(num);
+        Device device = deviceService.getOne(new QueryWrapper<Device>().eq("openNum", openNum));
         //没有该设备,保存至数据库
         if (device == null) {
             device = new Device();
-            device.setNum(num);
-            device.setClientId(Constant.OLD_PHONE_DEVICE_ID_PREFIX + num);
-            device.setPassword(MD5Util.MD5Encode(num));
+            device.setOpenNum(openNum);
+            device.setClientId(Constant.DEVICE_ID_PREFIX + openNum);
+            device.setPassword(MD5Util.MD5Encode(openNum));
             deviceService.save(device);
-            SetBase setBase = new SetBase();
-            setBase.setDeviceId(device.getClientId());
-            setBaseService.save(setBase);
+
+            DeviceSet deviceSet = new DeviceSet();
+            deviceSet.setOpenNum(device.getOpenNum());
+            deviceSetService.save(deviceSet);
         }
         //mqtt服务器注册用户
         rabbitMQApi.registerMqtt(device.getClientId(), device.getPassword());
         //发送消息
-        setService.returnCode_OMP(device);
+        setService.returnCode(device);
     }
 
     /**
      * 处理上传位置
-     * 老人机
      */
-    private void uploadLocationHandler(MqttMsgDto msg) {
+    private void doUploadLocation(MqttMsgDto msg) {
         try {
-            Location location = new Location();
-            location.setDeviceId(msg.getDeviceId());
-            location.setBatteryNum(msg.getInt("batterynum"));
-            location.setSignalNum(msg.getInt("signalnum"));
-            location.setMode(msg.getInt("mode"));
-            location.setLon(msg.getString("lon"));
-            location.setLat(msg.getString("lat"));
-            location.setSpeed(msg.getString("speed"));
-            location.setNum(msg.getInt("num"));
-            location.setUploadTime(msg.getDate("createtime"));
+            DeviceInfoState state = new DeviceInfoState();
+            state.setOpenNum(msg.getOpenNum());
+            state.setBatteryNum(msg.getInt("batterynum"));
+            state.setSignalNum(msg.getInt("signalnum"));
+            state.setMode(msg.getInt("mode"));
+            state.setLon(msg.getString("lon"));
+            state.setLat(msg.getString("lat"));
+            state.setSpeed(msg.getString("speed"));
+            state.setNum(msg.getInt("num"));
+            state.setUploadTime(msg.getDate("createtime"));
             //转换后的坐标
-            String[] gcj = CoordTransformUtil.wgs84toGcj02(location.getLon(), location.getLat());
-            location.setLonGcj(gcj[0]);
-            location.setLatGcj(gcj[1]);
+            String[] gcj = CoordTransformUtil.wgs84toGcj02(state.getLon(), state.getLat());
+            state.setLonGcj(gcj[0]);
+            state.setLatGcj(gcj[1]);
             // 逆地理位置解析
-            location.setSite(GaoDeApiUtil.regeo(location.getLonGcj(), location.getLatGcj()));
-            // 保存位置信息
-            deviceLocationService.saveLocation(location);
+            state.setSite(GaoDeApiUtil.regeo(state.getLonGcj(), state.getLatGcj()));
+            // 保存设备
+            deviceInfoStateService.save(state);
+            DeviceInfoRecord record = BeanUtil.cast(state, DeviceInfoRecord.class);
+            deviceInfoRecordService.save(record);
         } catch (Exception e) {
             log.error("老人机上传位置信息异常", e);
         }
@@ -132,9 +137,9 @@ public class MqttCallbackHandler {
     /**
      * 设备上传通话记录
      */
-    private void uploadCallRecordsHandler(MqttMsgDto obj) {
+    private void doUploadCallRecord(MqttMsgDto obj) {
         CallRecords callRecords = new CallRecords();
-        callRecords.setDeviceId(obj.getDeviceId());
+        callRecords.setOpenNum(obj.getOpenNum());
         callRecords.setCallType(obj.getInt("type"));
         callRecords.setKeyNum(obj.getString("key"));
         callRecords.setPhoneNum(obj.getString("phnoenum"));

+ 0 - 58
src/main/java/com/zy/omp/controller/pc/AdminController.java

@@ -1,58 +0,0 @@
-package com.zy.omp.controller.pc;
-
-import com.zy.omp.common.ServerResponse;
-import com.zy.omp.common.controller.BaseController;
-import com.zy.omp.model.Admin;
-import com.zy.omp.common.redis.SessionManager;
-import com.zy.omp.service.AdminService;
-import com.zy.omp.utils.MD5Util;
-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;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * 管理员Controller
- *
- * @author yang xiao kun
- * create on 2021/2/24
- */
-@RestController
-@RequestMapping("omp/api/pc/admin")
-public class AdminController extends BaseController {
-
-    @Resource
-    private AdminService adminService;
-
-    @Resource
-    private SessionManager sessionManager;
-
-    /**
-     * 登录
-     */
-    @PostMapping("login.do")
-    public ServerResponse login(String username, String password) {
-        Admin admin = adminService.getByUsername(username);
-        if (admin == null) return ServerResponse.createByWarning("用户不存在");
-        //MD5密码
-        password = MD5Util.MD5Encode(password);
-        if (!admin.getPassword().equals(password)) return ServerResponse.createByWarning("密码错误");
-        // 返回 token 和 昵称
-        Map<String, String> result = new HashMap<>();
-        result.put("token", sessionManager.generateToken(admin));
-        result.put("nickname", admin.getNickname());
-        return ServerResponse.createBySuccess(result);
-    }
-
-    /**
-     * token 验证
-     */
-    @GetMapping("verify.do")
-    public ServerResponse verify() {
-        return ServerResponse.createBySuccess();
-    }
-}

+ 2 - 10
src/main/java/com/zy/omp/controller/pc/PcDeviceController.java

@@ -4,7 +4,6 @@ import com.zy.omp.common.ServerResponse;
 import com.zy.omp.pojo.io.pc.DeviceIO;
 import com.zy.omp.service.DeviceService;
 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;
 
@@ -26,16 +25,9 @@ public class PcDeviceController {
     /**
      * 分页查询设备集合
      */
-    @PostMapping("listPage.do")
-    public ServerResponse getListPage(DeviceIO io) {
+    @GetMapping("listPage.do")
+    public ServerResponse listPage(DeviceIO io) {
         return ServerResponse.createBySuccess(deviceService.listPage(io));
     }
 
-    /**
-     * 通过ClientId 查询设备信息
-     */
-    @GetMapping("getDetailByClientId.do")
-    public ServerResponse getByClientId(String clientId) {
-        return ServerResponse.createBySuccess(deviceService.getByClientId(clientId));
-    }
 }

+ 0 - 31
src/main/java/com/zy/omp/controller/pc/PcLocationController.java

@@ -1,31 +0,0 @@
-package com.zy.omp.controller.pc;
-
-import com.zy.omp.common.ServerResponse;
-import com.zy.omp.service.LatestLocationService;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.annotation.Resource;
-
-/**
- * 设备定位相关
- *
- * @author yang xiao kun
- * create on 2021/1/21
- */
-@RestController
-@RequestMapping("omp/api/pc/location")
-public class PcLocationController {
-
-    @Resource
-    private LatestLocationService latestLocationService;
-
-    /**
-     * 获取所有设备的最新定位信息
-     */
-    @GetMapping("getLatestLocation.do")
-    public ServerResponse getLatestLocation() {
-        return ServerResponse.createBySuccess(latestLocationService.getLatestLocation());
-    }
-}

+ 0 - 28
src/main/java/com/zy/omp/controller/pc/PcMqttLogController.java

@@ -1,16 +1,13 @@
 package com.zy.omp.controller.pc;
 
-import com.zy.omp.common.Constant;
 import com.zy.omp.common.ServerResponse;
 import com.zy.omp.pojo.io.pc.MqttLogsIO;
 import com.zy.omp.service.MqttLogService;
-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;
-import java.util.HashMap;
 
 /**
  * mqtt收发日志
@@ -24,23 +21,6 @@ public class PcMqttLogController {
 
     @Resource
     private MqttLogService mqttLogService;
-    private static HashMap<String, String> instruction = new HashMap<>();
-
-    /*
-     * 所有指令暂时写死内存中
-     */
-    static {
-        instruction.put(Constant.M_CODE_REGISTER, "注册");
-        instruction.put(Constant.M_CODE_RETURN_CODE, "返回授权码");
-        instruction.put(Constant.M_CODE_UPLOAD_LOCATION, "上传位置信息");
-        instruction.put(Constant.M_CODE_GPS_RATE, "设置定位频率");
-        instruction.put(Constant.M_CODE_SOS, "设置联系人");
-        instruction.put(Constant.M_CODE_VOLUME, "设置音量");
-        instruction.put(Constant.M_CODE_AUTO_ANSWER, "设置自动接听");
-        instruction.put(Constant.M_CODE_NEWS, "设置语音播报");
-        instruction.put(Constant.M_CODE_UPLOAD_CALL_RECORD, "上传通话记录");
-        instruction.put(Constant.M_CODE_CONTINUE_GPS, "设置连续定位");
-    }
 
     /**
      * 分页查询日志
@@ -49,12 +29,4 @@ public class PcMqttLogController {
     public ServerResponse getListPage(MqttLogsIO io) {
         return ServerResponse.createBySuccess(mqttLogService.getListPage(io));
     }
-
-    /**
-     * 查询所有的指令
-     */
-    @GetMapping("getInstruction.do")
-    public ServerResponse getInstruction() {
-        return ServerResponse.createBySuccess(instruction);
-    }
 }

+ 21 - 19
src/main/java/com/zy/omp/controller/pc/PcSetController.java

@@ -2,8 +2,9 @@ package com.zy.omp.controller.pc;
 
 import com.zy.omp.common.Constant;
 import com.zy.omp.common.ServerResponse;
-import com.zy.omp.pojo.io.wechat.SetIO;
-import com.zy.omp.service.SetBaseService;
+import com.zy.omp.model.DeviceSet;
+import com.zy.omp.model.News;
+import com.zy.omp.service.DeviceSetService;
 import com.zy.omp.service.SetService;
 import org.springframework.web.bind.annotation.*;
 
@@ -20,26 +21,27 @@ import javax.annotation.Resource;
 public class PcSetController {
 
     @Resource
-    private SetBaseService setBaseService;
+    private DeviceSetService deviceSetService;
     @Resource
     private SetService setService;
 
     /**
      * 其他设置
      *
-     * @param deviceId 设备ID
+     * @param openNum 设备ID
      */
     @GetMapping("baseSet.do")
-    public ServerResponse getBaseSet(String deviceId) {
-        return ServerResponse.createBySuccess(setBaseService.getByDeviceId(deviceId));
+    public ServerResponse getBaseSet(String openNum) {
+        return ServerResponse.createBySuccess(deviceSetService.getByOpenNum(openNum));
     }
 
+
     /**
      * 设置音量
      */
     @PostMapping("volume.do")
-    public ServerResponse setVolume(SetIO io) {
-        setService.set(Constant.M_CODE_VOLUME, io);
+    public ServerResponse setVolume(DeviceSet param) {
+        setService.set(Constant.M_CODE_VOLUME, param);
         return ServerResponse.createBySuccess();
     }
 
@@ -47,19 +49,19 @@ public class PcSetController {
      * 设置定位频率
      */
     @PostMapping("gpsRate.do")
-    public ServerResponse setGpsRate(SetIO io) {
-        setService.set(Constant.M_CODE_GPS_RATE, io);
+    public ServerResponse gpsRate(DeviceSet param) {
+        setService.set(Constant.M_CODE_GPS_RATE, param);
         return ServerResponse.createBySuccess();
     }
 
     /**
      * 自动接听
      *
-     * @param io 设置参数
+     * @param param 设置参数
      */
     @PostMapping("autoAnswer.do")
-    public ServerResponse setAutoAnswer(SetIO io) {
-        setService.set(Constant.M_CODE_AUTO_ANSWER, io);
+    public ServerResponse setAutoAnswer(DeviceSet param) {
+        setService.set(Constant.M_CODE_AUTO_ANSWER, param);
         return ServerResponse.createBySuccess();
     }
 
@@ -67,8 +69,8 @@ public class PcSetController {
      * 设置语音播报
      */
     @PostMapping("news.do")
-    public ServerResponse setNews(SetIO io) {
-        setService.set(Constant.M_CODE_NEWS, io);
+    public ServerResponse setNews(News news) {
+        setService.saveNews(news);
         return ServerResponse.createBySuccess();
     }
 
@@ -76,8 +78,8 @@ public class PcSetController {
      * 设置SOS紧急呼叫
      */
     @PostMapping("sos.do")
-    public ServerResponse setSOS(SetIO io) {
-        setService.set(Constant.M_CODE_SOS, io);
+    public ServerResponse setSOS(DeviceSet param) {
+        setService.set(Constant.M_CODE_SOS, param);
         return ServerResponse.createBySuccess();
     }
 
@@ -85,8 +87,8 @@ public class PcSetController {
      * 设置持续定位
      */
     @PostMapping("continue.do")
-    public ServerResponse setContinue(SetIO io) {
-        setService.set(Constant.M_CODE_CONTINUE_GPS, io);
+    public ServerResponse setContinue(DeviceSet param) {
+        setService.set(Constant.M_CODE_CONTINUE_GPS, param);
         return ServerResponse.createBySuccess();
     }
 }

+ 49 - 48
src/main/java/com/zy/omp/controller/wx/DeviceController.java

@@ -1,12 +1,14 @@
 package com.zy.omp.controller.wx;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.zy.omp.common.ServerResponse;
 import com.zy.omp.common.controller.BaseController;
-import com.zy.omp.model.DeviceDynamic;
+import com.zy.omp.model.Device;
+import com.zy.omp.model.Relation;
+import com.zy.omp.service.DeviceInfoStateService;
 import com.zy.omp.service.DeviceService;
-import com.zy.omp.service.DeviceDynamicService;
+import com.zy.omp.service.RelationService;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,81 +17,80 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 
 /**
- * 用户设备绑定关系
+ * 设备 Controller
  *
- * @author chen_yi
- * Create on 2020/8/1
+ * @author yang xiao kun
+ * create on 2021/10/18
  */
 @RestController
 @RequestMapping("omp/api/wx/device")
 public class DeviceController extends BaseController {
 
     @Resource
-    private DeviceDynamicService deviceDynamicService;
-
+    private DeviceInfoStateService deviceInfoStateService;
+    @Resource
+    private RelationService relationService;
     @Resource
     private DeviceService deviceService;
 
     /**
-     * 更新设备名称
-     *
-     * @param num  设备随机 num
-     * @param name 设备名称
+     * 查询用户设备的最新数据
      */
-    @PostMapping("updateName.do")
-    public ServerResponse updateName(String num, String name) {
-        deviceDynamicService.updateName(getUserId(), num, name);
-        return ServerResponse.createBySuccess();
+    @GetMapping("getLatestState.do")
+    public ServerResponse getLatestState() {
+        return ServerResponse.createBySuccess(deviceInfoStateService.getLatestState(getOpenId()));
     }
 
     /**
-     * 添加绑定关系
+     * 设置默认设备
      */
-    @PostMapping("bind.do")
-    public ServerResponse bind(DeviceDynamic entity) {
-        if (deviceService.getByNum(entity.getDeviceNum()) == null)
-            return ServerResponse.createByWarning("无效设备码!");
-        if (deviceDynamicService.checkBind(entity.getDeviceNum()))
-            return ServerResponse.createByWarning("该设备已经有用户绑定!");
-        entity.setUserId(getUserId());
-        deviceDynamicService.save(entity);
+    @PostMapping("setDefault.do")
+    public ServerResponse setDefault(String openNum) {
+        relationService.update(new UpdateWrapper<Relation>()
+                .set("isDefault", 1)
+                .eq("openId", getOpenId())
+                .eq("openNum", openNum));
         return ServerResponse.createBySuccess();
     }
 
     /**
-     * 解除绑定关系
+     * 更新设备名称
      */
-    @PostMapping("unbind.do")
-    public ServerResponse unbind(String deviceNum) {
-        deviceDynamicService.unbind(deviceNum, getUserId());
+    @PostMapping("updateName.do")
+    public ServerResponse updateName(Relation relation) {
+        relationService.update(new UpdateWrapper<Relation>()
+                .set("deviceName", relation.getDeviceName())
+                .eq("openId", getOpenId())
+                .eq("openNum", relation.getOpenNum()));
         return ServerResponse.createBySuccess();
     }
 
     /**
-     * 查询用户的所有设备
+     * 添加绑定关系
      */
-    @GetMapping("getListByUserId.do")
-    public ServerResponse getListByUserId() {
-        QueryWrapper<DeviceDynamic> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("userId", getUserId());
-        queryWrapper.orderByDesc("isDefault");
-        return ServerResponse.createBySuccess(deviceDynamicService.list(queryWrapper));
+    @PostMapping("bind.do")
+    public ServerResponse bind(String openNum) {
+        //校验设备码有效性
+        if (deviceService.getOne(new QueryWrapper<Device>().eq("openNum", openNum)) == null)
+            return ServerResponse.createByWarning("设备码无效!");
+        //校验是否有绑定关系
+        if (relationService.checkBind(openNum)) return ServerResponse.createByWarning("该设备已经有用户绑定!");
+        Relation relation = new Relation();
+        relation.setOpenNum(openNum);
+        relation.setOpenId(getOpenId());
+        relationService.save(relation);
+        return ServerResponse.createBySuccess();
     }
 
     /**
-     * 修改默认设备
-     * 即登陆以后使用那个设备
-     *
-     * @param deviceNum 设备码
+     * 解除绑定关系
      */
-    @PostMapping("changeDefault.do")
-    public ServerResponse changeDefault(String deviceNum) {
-        //删除上一个默认设备
-        deviceDynamicService.update(Wrappers.<DeviceDynamic>lambdaUpdate().eq(DeviceDynamic::getIsDefault, 1)
-                .eq(DeviceDynamic::getUserId, getUserId()).set(DeviceDynamic::getIsDefault, 0));
-        //添加新的默认设备
-        deviceDynamicService.update(Wrappers.<DeviceDynamic>lambdaUpdate().eq(DeviceDynamic::getDeviceNum, deviceNum)
-                .set(DeviceDynamic::getIsDefault, 1));
+    @PostMapping("unbind.do")
+    public ServerResponse unbind(String openNum) {
+        relationService.remove(new QueryWrapper<Relation>()
+                .eq("openNum", openNum)
+                .eq("openId", getOpenId()));
         return ServerResponse.createBySuccess();
     }
+
 }

+ 0 - 54
src/main/java/com/zy/omp/controller/wx/IdiomsController.java

@@ -1,54 +0,0 @@
-package com.zy.omp.controller.wx;
-
-import com.zy.omp.common.ServerResponse;
-import com.zy.omp.common.controller.BaseController;
-import com.zy.omp.service.IdiomsService;
-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 yang xiao kun
- * create on 2021/1/22
- */
-@RestController
-@RequestMapping("omp/api/wx/idioms")
-public class IdiomsController extends BaseController {
-
-    @Resource
-    IdiomsService userIdiomsService;
-
-    /**
-     * 通过用户ID 查询用户常用语
-     */
-    @GetMapping("getList.do")
-    public ServerResponse getList() {
-        return ServerResponse.createBySuccess(userIdiomsService.getListByUserId(getUserId()));
-    }
-
-    /**
-     * 添加常用语
-     */
-    @PostMapping("save.do")
-    public ServerResponse save(String content) {
-        String userId = getUserId();
-        if (userIdiomsService.countByUserId(getUserId()) > 10) {
-            return ServerResponse.createByWarning("最多添加十条常用语");
-        }
-        userIdiomsService.saveEntity(userId, content);
-        return ServerResponse.createBySuccess();
-    }
-
-    /**
-     * 通过ID删除常用语
-     */
-    @PostMapping("delById.do")
-    public ServerResponse delById(Integer id) {
-        return ServerResponse.createBySuccess(userIdiomsService.delById(id, getUserId()));
-    }
-}

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

@@ -1,41 +0,0 @@
-package com.zy.omp.controller.wx;
-
-import com.zy.omp.common.ServerResponse;
-import com.zy.omp.pojo.io.wechat.DeviceHistoryIO;
-import com.zy.omp.service.LocationService;
-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 yang xiao kun
- * create on 2021/1/21
- */
-@RestController
-@RequestMapping("omp/api/wx/location")
-public class LocationController {
-
-    @Resource
-    private LocationService locationService;
-
-    /**
-     * 通过设备ID获取最新的定位信息
-     */
-    @GetMapping("getLocation.do")
-    public ServerResponse getLatestLocation(String deviceId) {
-        return ServerResponse.createBySuccess(locationService.getLatestLocation(deviceId));
-    }
-
-    /**
-     * 查看设备历史轨迹
-     */
-    @PostMapping("getHistory.do")
-    public ServerResponse getHistory(DeviceHistoryIO io) {
-        return ServerResponse.createBySuccess(locationService.getHistory(io));
-    }
-}

+ 25 - 19
src/main/java/com/zy/omp/controller/wx/SetController.java

@@ -3,9 +3,11 @@ package com.zy.omp.controller.wx;
 import com.zy.omp.common.Constant;
 import com.zy.omp.common.ServerResponse;
 import com.zy.omp.common.controller.BaseController;
-import com.zy.omp.pojo.io.wechat.SetIO;
-import com.zy.omp.service.DeviceDynamicService;
+import com.zy.omp.model.DeviceSet;
+import com.zy.omp.model.News;
+import com.zy.omp.service.RelationService;
 import com.zy.omp.service.SetService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -16,6 +18,7 @@ import javax.annotation.Resource;
  * @author yang xiao kun
  * create on 2021/1/21
  */
+@Slf4j
 @RestController
 @RequestMapping("omp/api/wx/set")
 public class SetController extends BaseController {
@@ -23,15 +26,15 @@ public class SetController extends BaseController {
     @Resource
     private SetService setService;
     @Resource
-    private DeviceDynamicService relationService;
+    private RelationService relationService;
 
     /**
      * 校验设备是否是该用户的设备
      */
-    private boolean verify(SetIO io) {
-        boolean flag = relationService.checkBelong(getUserId(), io.getDeviceId());
+    private boolean verify(DeviceSet param) {
+        boolean flag = relationService.checkBelong(getOpenId(), param.getOpenNum());
         if (!flag) {
-            System.out.println("非法请求----" + getUserId() + "-----" + io.getDeviceId());
+            log.error("非法请求 -- openId: " + getOpenId() + "openNum: " + param.getOpenNum());
         }
         return flag;
     }
@@ -40,8 +43,8 @@ public class SetController extends BaseController {
      * 设置音量
      */
     @PostMapping("volume.do")
-    public ServerResponse setVolume(SetIO io) {
-        if (verify(io)) setService.set(Constant.M_CODE_VOLUME, io);
+    public ServerResponse setVolume(DeviceSet param) {
+        if (verify(param)) setService.set(Constant.M_CODE_VOLUME, param);
         return ServerResponse.createBySuccess();
     }
 
@@ -49,19 +52,19 @@ public class SetController extends BaseController {
      * 设置定位频率
      */
     @PostMapping("gpsRate.do")
-    public ServerResponse gpsRate(SetIO io) {
-        if (verify(io)) setService.set(Constant.M_CODE_GPS_RATE, io);
+    public ServerResponse gpsRate(DeviceSet param) {
+        if (verify(param)) setService.set(Constant.M_CODE_GPS_RATE, param);
         return ServerResponse.createBySuccess();
     }
 
     /**
      * 自动接听
      *
-     * @param io 设置参数
+     * @param param 设置参数
      */
     @PostMapping("autoAnswer.do")
-    public ServerResponse setAutoAnswer(SetIO io) {
-        if (verify(io)) setService.set(Constant.M_CODE_AUTO_ANSWER, io);
+    public ServerResponse setAutoAnswer(DeviceSet param) {
+        if (verify(param)) setService.set(Constant.M_CODE_AUTO_ANSWER, param);
         return ServerResponse.createBySuccess();
     }
 
@@ -69,8 +72,11 @@ public class SetController extends BaseController {
      * 设置语音播报
      */
     @PostMapping("news.do")
-    public ServerResponse setNews(SetIO io) {
-        if (verify(io)) setService.set(Constant.M_CODE_NEWS, io);
+    public ServerResponse setNews(News news) {
+        if (relationService.checkBelong(getOpenId(), news.getOpenNum())) {
+            log.error("非法请求 -- openId: " + getOpenId() + "openNum: " + news.getOpenNum());
+        }
+        setService.saveNews(news);
         return ServerResponse.createBySuccess();
     }
 
@@ -78,8 +84,8 @@ public class SetController extends BaseController {
      * 设置SOS紧急呼叫
      */
     @PostMapping("sos.do")
-    public ServerResponse setSOS(SetIO io) {
-        if (verify(io)) setService.set(Constant.M_CODE_SOS, io);
+    public ServerResponse setSOS(DeviceSet param) {
+        if (verify(param)) setService.set(Constant.M_CODE_SOS, param);
         return ServerResponse.createBySuccess();
     }
 
@@ -87,8 +93,8 @@ public class SetController extends BaseController {
      * 设置持续定位
      */
     @PostMapping("continue.do")
-    public ServerResponse setContinue(SetIO io) {
-        if (verify(io)) setService.set(Constant.M_CODE_CONTINUE_GPS, io);
+    public ServerResponse setContinue(DeviceSet param) {
+        if (verify(param)) setService.set(Constant.M_CODE_CONTINUE_GPS, param);
         return ServerResponse.createBySuccess();
     }
 }

+ 5 - 5
src/main/java/com/zy/omp/controller/wx/SetInfoController.java

@@ -5,7 +5,7 @@ import com.zy.omp.common.controller.BaseController;
 import com.zy.omp.pojo.io.CallRecordsIO;
 import com.zy.omp.pojo.io.NewsIO;
 import com.zy.omp.service.CallRecordsService;
-import com.zy.omp.service.SetBaseService;
+import com.zy.omp.service.DeviceSetService;
 import com.zy.omp.service.NewsService;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,7 +24,7 @@ import javax.annotation.Resource;
 public class SetInfoController extends BaseController {
 
     @Resource
-    private SetBaseService setBaseService;
+    private DeviceSetService deviceSetService;
     @Resource
     private CallRecordsService callRecordsService;
     @Resource
@@ -38,7 +38,7 @@ public class SetInfoController extends BaseController {
      */
     @GetMapping("volume.do")
     public ServerResponse volume(String deviceId) {
-        return ServerResponse.createBySuccess(setBaseService.getVolumeSet(deviceId));
+        return ServerResponse.createBySuccess(deviceSetService.getVolumeSet(deviceId));
     }
 
     /**
@@ -49,7 +49,7 @@ public class SetInfoController extends BaseController {
      */
     @GetMapping("other.do")
     public ServerResponse other(String deviceId) {
-        return ServerResponse.createBySuccess(setBaseService.getOtherSet(deviceId));
+        return ServerResponse.createBySuccess(deviceSetService.getOtherSet(deviceId));
     }
 
     /**
@@ -59,7 +59,7 @@ public class SetInfoController extends BaseController {
      */
     @GetMapping("sos.do")
     public ServerResponse sos(String deviceId) {
-        return ServerResponse.createBySuccess(setBaseService.getSosSet(deviceId));
+        return ServerResponse.createBySuccess(deviceSetService.getSosSet(deviceId));
     }
 
     /**

+ 2 - 2
src/main/java/com/zy/omp/mapper/LocationMapper.java → src/main/java/com/zy/omp/mapper/DeviceInfoRecordMapper.java

@@ -1,7 +1,7 @@
 package com.zy.omp.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.zy.omp.model.Location;
+import com.zy.omp.model.DeviceInfoRecord;
 import org.apache.ibatis.annotations.Mapper;
 import org.springframework.stereotype.Repository;
 
@@ -13,5 +13,5 @@ import org.springframework.stereotype.Repository;
  */
 @Mapper
 @Repository
-public interface LocationMapper extends BaseMapper<Location> {
+public interface DeviceInfoRecordMapper extends BaseMapper<DeviceInfoRecord> {
 }

+ 28 - 0
src/main/java/com/zy/omp/mapper/DeviceInfoStateMapper.java

@@ -0,0 +1,28 @@
+package com.zy.omp.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zy.omp.model.DeviceInfoState;
+import com.zy.omp.pojo.vo.WxLatestDeviceState;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * 设备状态信息
+ *
+ * @author chenyi
+ * Create on 2020/4/10
+ */
+@Mapper
+@Repository
+public interface DeviceInfoStateMapper extends BaseMapper<DeviceInfoState> {
+
+    /**
+     * 通过用户openId 查询该用户的设备集合
+     *
+     * @param openId 用户openId
+     */
+    List<WxLatestDeviceState> listByUserId(@Param("openId") String openId);
+}

+ 2 - 9
src/main/java/com/zy/omp/mapper/DeviceMapper.java

@@ -3,14 +3,12 @@ package com.zy.omp.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.zy.omp.pojo.io.pc.DeviceIO;
-import com.zy.omp.pojo.vo.DeviceFullDataVo;
 import com.zy.omp.model.Device;
+import com.zy.omp.pojo.vo.DeviceListVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
-import java.util.List;
-
 /**
  * @author chenyi
  * Create on 2020/4/10
@@ -26,10 +24,5 @@ public interface DeviceMapper extends BaseMapper<Device> {
      * @param page 分页条件
      * @param io   查询条件
      */
-    IPage<DeviceFullDataVo> listPage(IPage<DeviceFullDataVo> page, @Param("io") DeviceIO io);
-
-    /**
-     * 批量更新设备在线状态
-     */
-    void updateDeviceStatus(@Param("devices") List<Device> devices);
+    IPage<DeviceListVo> listPage(IPage<DeviceListVo> page, @Param("io") DeviceIO io);
 }

+ 2 - 2
src/main/java/com/zy/omp/mapper/SetBaseMapper.java → src/main/java/com/zy/omp/mapper/DeviceSetMapper.java

@@ -1,7 +1,7 @@
 package com.zy.omp.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.zy.omp.model.SetBase;
+import com.zy.omp.model.DeviceSet;
 import org.apache.ibatis.annotations.Mapper;
 import org.springframework.stereotype.Repository;
 
@@ -13,6 +13,6 @@ import org.springframework.stereotype.Repository;
  */
 @Mapper
 @Repository
-public interface SetBaseMapper extends BaseMapper<SetBase> {
+public interface DeviceSetMapper extends BaseMapper<DeviceSet> {
 
 }

+ 1 - 0
src/main/java/com/zy/omp/mapper/IdiomsMapper.java

@@ -13,6 +13,7 @@ import org.springframework.stereotype.Repository;
  */
 @Mapper
 @Repository
+@Deprecated
 public interface IdiomsMapper extends BaseMapper<UserIdioms> {
 
 }

+ 0 - 25
src/main/java/com/zy/omp/mapper/LatestLocationMapper.java

@@ -1,25 +0,0 @@
-package com.zy.omp.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.zy.omp.pojo.vo.DeviceFullDataVo;
-import com.zy.omp.model.LatestLocation;
-import org.apache.ibatis.annotations.Mapper;
-import org.springframework.stereotype.Repository;
-
-import java.util.List;
-
-/**
- * 设备最新位置信息
- *
- * @author chenyi
- * Create on 2020/4/10
- */
-@Mapper
-@Repository
-public interface LatestLocationMapper extends BaseMapper<LatestLocation> {
-
-    /**
-     * 获取所有设备最新的位置信息
-     */
-    List<DeviceFullDataVo> getLatestLocation();
-}

+ 7 - 7
src/main/java/com/zy/omp/mapper/DeviceDynamicMapper.java → src/main/java/com/zy/omp/mapper/RelationMapper.java

@@ -1,7 +1,7 @@
 package com.zy.omp.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.zy.omp.model.DeviceDynamic;
+import com.zy.omp.model.Relation;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
@@ -14,20 +14,20 @@ import org.springframework.stereotype.Repository;
  */
 @Mapper
 @Repository
-public interface DeviceDynamicMapper extends BaseMapper<DeviceDynamic> {
+public interface RelationMapper extends BaseMapper<Relation> {
 
     /**
      * 查询设备是否有绑定用户
      *
-     * @param deviceNum 设备号
+     * @param openNum 设备号
      */
-    int checkBind(@Param("deviceNum") String deviceNum);
+    int checkBind(@Param("openNum") String openNum);
 
     /**
      * 查询设备是否属于某用户
      *
-     * @param userId   用户ID
-     * @param deviceId 设备ID
+     * @param openId  用户ID
+     * @param openNum 设备ID
      */
-    int checkBelong(@Param("userId") String userId, @Param("deviceId") String deviceId);
+    int checkBelong(@Param("openNum") String openNum, @Param("openId") String openId);
 }

+ 1 - 1
src/main/java/com/zy/omp/model/CallRecords.java

@@ -19,7 +19,7 @@ public class CallRecords {
     /**
      * 设备ID
      */
-    private String deviceId;
+    private String openNum;
 
     /**
      * 1:播出 2:接听

+ 3 - 15
src/main/java/com/zy/omp/model/Device.java

@@ -1,6 +1,5 @@
 package com.zy.omp.model;
 
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
@@ -11,7 +10,7 @@ import java.time.LocalDateTime;
  * 设备信息
  */
 @Data
-@TableName("device")
+@TableName("device_base")
 public class Device {
     @TableId
     private Integer id;
@@ -19,7 +18,7 @@ public class Device {
     /**
      * 设备随机码
      */
-    private String num;
+    private String openNum;
 
     /**
      * MQTT clientId
@@ -34,21 +33,10 @@ public class Device {
     /**
      * 设备组
      */
-    @TableField("`group`")
-    private String group;
+    private String groupId;
 
     /**
      * 创建时间
      */
     private LocalDateTime createTime;
-
-    /**
-     * 最后一次在线时间
-     */
-    private LocalDateTime lastOnlineTime;
-
-    /**
-     * 1:在线 0:离线
-     */
-    private Integer status;
 }

+ 0 - 52
src/main/java/com/zy/omp/model/DeviceDynamic.java

@@ -1,52 +0,0 @@
-package com.zy.omp.model;
-
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-
-import java.time.LocalDateTime;
-
-/**
- * 设备扩展信息表
- *
- * @author chen_yi
- * Create on 2020/8/1
- */
-@Data
-@TableName("device_dynamic")
-public class DeviceDynamic {
-
-    @TableId
-    private Integer id;
-
-    /**
-     * 用户ID
-     */
-    private String userId;
-
-    /**
-     * 设备ID
-     */
-    private String deviceId;
-
-    /**
-     * 设备随机码
-     */
-    private String deviceNum;
-
-    /**
-     * 是否是默认设备
-     * 0:否 1:是
-     */
-    private Integer isDefault;
-
-    /**
-     * 设备名
-     */
-    private String name;
-
-    /**
-     * 创建时间
-     */
-    private LocalDateTime createTime;
-}

+ 2 - 8
src/main/java/com/zy/omp/model/Location.java → src/main/java/com/zy/omp/model/DeviceInfoRecord.java

@@ -10,8 +10,7 @@ import java.time.LocalDateTime;
  * 设备定位信息表
  */
 @Data
-@TableName("location")
-public class Location {
+public class DeviceInfoRecord {
 
     @TableId
     private Integer id;
@@ -19,7 +18,7 @@ public class Location {
     /**
      * 设备ID
      */
-    private String deviceId;
+    private String openNum;
 
     /**
      * 电量
@@ -71,11 +70,6 @@ public class Location {
      */
     private Integer num;
 
-    /**
-     * 创建时间
-     */
-    private LocalDateTime createTime;
-
     /**
      * 数据上传时间
      */

+ 17 - 19
src/main/java/com/zy/omp/model/LatestLocation.java → src/main/java/com/zy/omp/model/DeviceInfoState.java

@@ -1,26 +1,34 @@
 package com.zy.omp.model;
 
 import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
 import java.time.LocalDateTime;
 
 /**
- * 设备最新的定位
+ * 设备状态信息表
+ *
+ * @author chen_yi
+ * Create on 2020/8/1
  */
 @Data
-@TableName("latest_location")
-public class LatestLocation {
-
+public class DeviceInfoState {
 
+    /**
+     * 设备ID
+     */
     @TableId
-    private Integer id;
+    private String openNum;
 
     /**
-     * 设备ID
+     * 0:无法定位,1:北斗定位,2:基站定位,3:GPS定位
+     */
+    private Integer mode;
+
+    /**
+     * 状态
      */
-    private String deviceId;
+    private Integer status;
 
     /**
      * 电量
@@ -32,11 +40,6 @@ public class LatestLocation {
      */
     private Integer signalNum;
 
-    /**
-     * 0:无法定位,1:北斗定位,2:基站定位,3:GPS定位
-     */
-    private Integer mode;
-
     /**
      * 经度
      */
@@ -68,7 +71,7 @@ public class LatestLocation {
     private String speed;
 
     /**
-     * 星颗数
+     * 星颗数
      */
     private Integer num;
 
@@ -76,9 +79,4 @@ public class LatestLocation {
      * 数据上传时间
      */
     private LocalDateTime uploadTime;
-
-    /**
-     * 最新的修改时间
-     */
-    private LocalDateTime modifyTime;
 }

+ 9 - 9
src/main/java/com/zy/omp/model/SetBase.java → src/main/java/com/zy/omp/model/DeviceSet.java

@@ -1,23 +1,19 @@
 package com.zy.omp.model;
 
 import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
 /**
  * 其他设置
  */
 @Data
-@TableName("set_base")
-public class SetBase {
-
-    @TableId
-    private Integer id;
+public class DeviceSet {
 
     /**
      * 设备ID
      */
-    private String deviceId;
+    @TableId
+    private String openNum;
 
     /**
      * 系统音量
@@ -76,8 +72,12 @@ public class SetBase {
      */
     private String key2Phone;
 
-    //服务器地址
+    /**
+     * 服务器地址
+     */
     private String serverHost;
-    //服务器端口
+    /**
+     * 服务器端口
+     */
     private Integer serverPort;
 }

+ 1 - 1
src/main/java/com/zy/omp/model/News.java

@@ -22,7 +22,7 @@ public class News {
     /**
      * 设备Id
      */
-    private String deviceId;
+    private String openNum;
 
     /**
      * 星期几的几点几分播报

+ 42 - 0
src/main/java/com/zy/omp/model/Relation.java

@@ -0,0 +1,42 @@
+package com.zy.omp.model;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * 用户设备关联关系表
+ *
+ * @author yang xiao kun
+ * create on 2021/10/13
+ */
+@Data
+public class Relation {
+    @TableId
+    private Integer id;
+
+    /**
+     * 设备随机码
+     */
+    private String openNum;
+
+    /**
+     * 用户ID
+     */
+    private String openId;
+
+    /**
+     * 设备名
+     */
+    private String deviceName;
+
+    /**
+     * 默认设备
+     */
+    private Integer isDefault;
+
+    private LocalDateTime createTime;
+
+    private LocalDateTime updateTime;
+}

+ 5 - 2
src/main/java/com/zy/omp/model/User.java

@@ -15,8 +15,6 @@ import java.time.LocalDateTime;
  * Create on 2020/7/31
  */
 @Data
-@ToString
-@TableName("user")
 @NoArgsConstructor
 public class User {
     @TableId
@@ -27,6 +25,11 @@ public class User {
      */
     private String openId;
 
+    /**
+     * 随机码
+     */
+    private String randomNum;
+
     /**
      * 头像
      */

+ 1 - 1
src/main/java/com/zy/omp/model/UserIdioms.java

@@ -10,7 +10,7 @@ import java.time.LocalDateTime;
  * 常用语
  */
 @Data
-@TableName("user_idioms")
+@Deprecated
 public class UserIdioms {
     @TableId
     private Integer id;

+ 2 - 2
src/main/java/com/zy/omp/pojo/dto/MqttMsgDto.java

@@ -112,9 +112,9 @@ public class MqttMsgDto {
     /**
      * 获取设备ID
      */
-    public String getDeviceId() {
+    public String getOpenNum() {
         if (r == null) return null;
-        String[] res = r.split("/");
+        String[] res = r.split("OMP");
         return res.length > 1 ? res[1] : null;
     }
 }

+ 1 - 1
src/main/java/com/zy/omp/pojo/io/pc/DeviceIO.java

@@ -14,7 +14,7 @@ public class DeviceIO extends PageIO {
     /**
      * 设备码
      */
-    private String num;
+    private String openNum;
     /**
      * 设备状态
      */

+ 0 - 26
src/main/java/com/zy/omp/pojo/io/wechat/DeviceHistoryIO.java

@@ -1,26 +0,0 @@
-package com.zy.omp.pojo.io.wechat;
-
-import lombok.Data;
-
-/**
- * 设备历史轨迹入参
- *
- * @author yang xiao kun
- * create on 2021/2/8
- */
-@Data
-public class DeviceHistoryIO {
-    /**
-     * 设备ID
-     */
-    private String deviceId;
-    /**
-     * 开始时间
-     */
-    private String startTime;
-
-    /**
-     * 结束时间
-     */
-    private String endTime;
-}

+ 0 - 3
src/main/java/com/zy/omp/pojo/io/wechat/SetIO.java

@@ -98,7 +98,4 @@ public class SetIO {
      */
     private String news;
 
-    public String getTopic() {
-        return Constant.TOPIC_DEVICE_CLIENT + deviceId;
-    }
 }

+ 6 - 15
src/main/java/com/zy/omp/pojo/vo/DeviceFullDataVo.java → src/main/java/com/zy/omp/pojo/vo/DeviceListVo.java

@@ -11,31 +11,22 @@ import java.time.LocalDateTime;
  * create on 2021/5/12
  */
 @Data
-public class DeviceFullDataVo {
+public class DeviceListVo {
     /**
-     * 设备随机
+     * 设备码
      */
-    private String deviceNum;
-    /**
-     * 设备ID
-     */
-    private String deviceId;
+    private String openNum;
 
     /**
-     * MQTT 密码
+     * 设备组
      */
-    private String password;
+    private String groupId;
 
     /**
      * 创建时间
      */
     private LocalDateTime createTime;
 
-    /**
-     * 最后一次在线时间
-     */
-    private LocalDateTime lastOnlineTime;
-
     /**
      * 1在线,0离线
      */
@@ -77,7 +68,7 @@ public class DeviceFullDataVo {
     private String speed;
 
     /**
-     * 星颗数
+     * 星颗数
      */
     private Integer num;
 

+ 78 - 0
src/main/java/com/zy/omp/pojo/vo/WxLatestDeviceState.java

@@ -0,0 +1,78 @@
+package com.zy.omp.pojo.vo;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * 设备最新状态信息
+ *
+ * @author yang xiao kun
+ * create on 2021/11/29
+ */
+@Data
+public class WxLatestDeviceState {
+
+    /**
+     * 设备ID
+     */
+    @TableId
+    private String openNum;
+
+    /**
+     * 0:无法定位,1:北斗定位,2:基站定位,3:GPS定位
+     */
+    private Integer mode;
+
+    /**
+     * 电量
+     */
+    private Integer batteryNum;
+
+    /**
+     * 信号强度
+     */
+    private Integer signalNum;
+
+    /**
+     * 经度
+     */
+    private String lon;
+
+    /**
+     * 纬度
+     */
+    private String lat;
+
+    /**
+     * 经度(gcj)
+     */
+    private String lonGcj;
+
+    /**
+     * 纬度(gcj)
+     */
+    private String latGcj;
+
+    /**
+     * 格式化的地理位置
+     */
+    private String site;
+
+    /**
+     * 卫星颗数
+     */
+    private Integer num;
+
+    /**
+     * 数据上传时间
+     */
+    private LocalDateTime uploadTime;
+
+    /**
+     * 设备名称
+     */
+    private String deviceName;
+
+}

+ 0 - 52
src/main/java/com/zy/omp/schedule/DeviceStatusSchedule.java

@@ -1,52 +0,0 @@
-package com.zy.omp.schedule;
-
-import com.zy.omp.model.Device;
-import com.zy.omp.service.DeviceService;
-import com.zy.omp.service.RabbitMQApi;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.scheduling.annotation.EnableAsync;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
-
-import java.time.LocalDateTime;
-import java.util.List;
-import java.util.Set;
-
-/**
- * 定时更新设备在线状态
- *
- * @author yang xiao kun
- * create on 2021/5/14
- */
-@EnableAsync
-@Configuration
-@EnableScheduling
-public class DeviceStatusSchedule {
-
-    @Autowired
-    private RabbitMQApi rabbitMQApi;
-    @Autowired
-    private DeviceService deviceService;
-
-    /**
-     * 更新频率 5分钟
-     * 定时更新设备在线状态
-     */
-    @Async
-    @Scheduled(cron = "0 0/5 * * * ?")
-    public void updateDeviceStatus() {
-        //全部的设备
-        List<Device> devices = deviceService.list();
-        Set<String> online = rabbitMQApi.getOnlineDevice();
-        for (Device item : devices) {
-            int status = online.contains(item.getClientId()) ? 1 : 0;
-            item.setStatus(status);
-            if (status == 1) {
-                item.setLastOnlineTime(LocalDateTime.now());
-            }
-        }
-        deviceService.updateDeviceStatus(devices);
-    }
-}

+ 0 - 61
src/main/java/com/zy/omp/service/DeviceDynamicService.java

@@ -1,61 +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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.zy.omp.mapper.DeviceDynamicMapper;
-import com.zy.omp.model.DeviceDynamic;
-import org.springframework.stereotype.Service;
-
-/**
- * 用户设备绑定关系Service
- *
- * @author chenyi
- * Create on 2020/4/10
- */
-@Service
-public class DeviceDynamicService extends ServiceImpl<DeviceDynamicMapper, DeviceDynamic> {
-
-    /**
-     * 通过设备号删除绑定关系
-     *
-     * @param deviceNum 设备号
-     */
-    public void unbind(String deviceNum, String userId) {
-        QueryWrapper<DeviceDynamic> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("deviceNum", deviceNum);
-        queryWrapper.eq("userId", userId);
-        baseMapper.delete(queryWrapper);
-    }
-
-    /**
-     * 查询设备是否有绑定关系
-     *
-     * @param deviceNum 设备号
-     */
-    public boolean checkBind(String deviceNum) {
-        return baseMapper.checkBind(deviceNum) > 0;
-    }
-
-    /**
-     * 查询设备是否属于该用户
-     *
-     * @param userId    用户ID
-     * @param deviceNum 设备码
-     */
-    public void updateName(String userId, String deviceNum, String newName) {
-        UpdateWrapper<DeviceDynamic> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.set("name", newName).eq("userId", userId).eq("deviceNum", deviceNum);
-        update(updateWrapper);
-    }
-
-    /**
-     * 查询设备是否属于该用户
-     *
-     * @param userId   用户ID
-     * @param deviceId 设备ID
-     */
-    public boolean checkBelong(String userId, String deviceId) {
-        return baseMapper.checkBelong(userId, deviceId) > 0;
-    }
-}

+ 21 - 0
src/main/java/com/zy/omp/service/DeviceInfoRecordService.java

@@ -0,0 +1,21 @@
+package com.zy.omp.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zy.omp.mapper.DeviceInfoRecordMapper;
+import com.zy.omp.mapper.DeviceInfoStateMapper;
+import com.zy.omp.model.DeviceInfoRecord;
+import com.zy.omp.model.DeviceInfoState;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 设备位置信息相关
+ *
+ * @author chenyi
+ * Create on 2020/4/10
+ */
+@Service
+public class DeviceInfoRecordService extends ServiceImpl<DeviceInfoRecordMapper, DeviceInfoRecord> {
+
+}

+ 33 - 0
src/main/java/com/zy/omp/service/DeviceInfoStateService.java

@@ -0,0 +1,33 @@
+package com.zy.omp.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zy.omp.mapper.DeviceInfoStateMapper;
+import com.zy.omp.model.DeviceInfoState;
+import com.zy.omp.pojo.vo.WxLatestDeviceState;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 设备位置信息相关
+ *
+ * @author chenyi
+ * Create on 2020/4/10
+ */
+@Service
+public class DeviceInfoStateService extends ServiceImpl<DeviceInfoStateMapper, DeviceInfoState> {
+
+    /**
+     * 通过用户openId 查询该用户的设备集合
+     *
+     * @param openId 用户openId
+     */
+    public WxLatestDeviceState getLatestState(String openId) {
+        //用户设备列表
+        List<WxLatestDeviceState> devices = baseMapper.listByUserId(openId);
+        if (devices != null && !devices.isEmpty()) {
+            return devices.get(0);
+        }
+        return null;
+    }
+}

+ 3 - 34
src/main/java/com/zy/omp/service/DeviceService.java

@@ -1,18 +1,14 @@
 package com.zy.omp.service;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zy.omp.pojo.io.pc.DeviceIO;
-import com.zy.omp.pojo.vo.DeviceFullDataVo;
 import com.zy.omp.mapper.DeviceMapper;
 import com.zy.omp.model.Device;
+import com.zy.omp.pojo.vo.DeviceListVo;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
-
-
 /**
  * 设备信息相关
  *
@@ -28,35 +24,8 @@ public class DeviceService extends ServiceImpl<DeviceMapper, Device> {
      *
      * @param io 查询条件
      */
-    public IPage<DeviceFullDataVo> listPage(DeviceIO io) {
-        Page<DeviceFullDataVo> page = new Page<>(io.getCurrent(), io.getSize());
+    public IPage<DeviceListVo> listPage(DeviceIO io) {
+        Page<DeviceListVo> page = new Page<>(io.getCurrent(), io.getSize());
         return baseMapper.listPage(page, io);
     }
-
-    /**
-     * 批量更新设备在线状态
-     */
-    public void updateDeviceStatus(List<Device> devices) {
-        baseMapper.updateDeviceStatus(devices);
-    }
-
-    /**
-     * 通过设备 num 获取设备信息
-     *
-     * @param num 设备号
-     */
-    public Device getByNum(String num) {
-        QueryWrapper<Device> queryWrapper = new QueryWrapper<Device>().eq("num", num);
-        return baseMapper.selectOne(queryWrapper);
-    }
-
-    /**
-     * 通过设备 clientId 获取设备信息
-     *
-     * @param clientId 设备 MQTT 登录账号
-     */
-    public Device getByClientId(String clientId) {
-        QueryWrapper<Device> queryWrapper = new QueryWrapper<Device>().eq("clientId", clientId);
-        return baseMapper.selectOne(queryWrapper);
-    }
 }

+ 60 - 0
src/main/java/com/zy/omp/service/DeviceSetService.java

@@ -0,0 +1,60 @@
+package com.zy.omp.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zy.omp.common.exception.ApiRuntimeException;
+import com.zy.omp.mapper.DeviceSetMapper;
+import com.zy.omp.model.DeviceSet;
+import org.springframework.stereotype.Service;
+
+/**
+ * 其他设置相关
+ *
+ * @author chenyi
+ * Create on 2020/4/10
+ */
+@Service
+public class DeviceSetService extends ServiceImpl<DeviceSetMapper, DeviceSet> {
+
+    /**
+     * 后台
+     * 获取全部的设置信息
+     *
+     * @param openNum 设备ID
+     */
+    public DeviceSet getByOpenNum(String openNum) {
+        QueryWrapper<DeviceSet> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("openNum", openNum);
+        return baseMapper.selectOne(queryWrapper);
+    }
+
+    /**
+     * 获取音量设置信息
+     */
+    public DeviceSet getVolumeSet(String deviceId) {
+        QueryWrapper<DeviceSet> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("openNum", "msgVol", "phoneVol", "ringVol");
+        queryWrapper.eq("openNum", deviceId);
+        return baseMapper.selectOne(queryWrapper);
+    }
+
+    /**
+     * 获取SOS设置信息
+     */
+    public DeviceSet getSosSet(String deviceId) {
+        QueryWrapper<DeviceSet> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("openNum", "key0Name", "key0Phone", "key1Name", "key1Phone", "key2Name", "key2Phone");
+        queryWrapper.eq("openNum", deviceId);
+        return baseMapper.selectOne(queryWrapper);
+    }
+
+    /**
+     * 获取其他设置设置信息
+     */
+    public DeviceSet getOtherSet(String deviceId) {
+        QueryWrapper<DeviceSet> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("openNum", "autoAnswer", "gpsRate", "highFreq");
+        queryWrapper.eq("openNum", deviceId);
+        return baseMapper.selectOne(queryWrapper);
+    }
+}

+ 1 - 0
src/main/java/com/zy/omp/service/IdiomsService.java

@@ -15,6 +15,7 @@ import java.util.List;
  * Create on 2020/4/10
  */
 @Service
+@Deprecated
 public class IdiomsService extends ServiceImpl<IdiomsMapper, UserIdioms> {
 
     /**

+ 0 - 26
src/main/java/com/zy/omp/service/LatestLocationService.java

@@ -1,26 +0,0 @@
-package com.zy.omp.service;
-
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.zy.omp.pojo.vo.DeviceFullDataVo;
-import com.zy.omp.mapper.LatestLocationMapper;
-import com.zy.omp.model.LatestLocation;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-/**
- * 设备位置信息相关
- *
- * @author chenyi
- * Create on 2020/4/10
- */
-@Service
-public class LatestLocationService extends ServiceImpl<LatestLocationMapper, LatestLocation> {
-
-    /**
-     * 获取所有设备最新的位置信息
-     */
-    public List<DeviceFullDataVo> getLatestLocation() {
-        return baseMapper.getLatestLocation();
-    }
-}

+ 0 - 65
src/main/java/com/zy/omp/service/LocationService.java

@@ -1,65 +0,0 @@
-package com.zy.omp.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.zy.omp.pojo.io.wechat.DeviceHistoryIO;
-import com.zy.omp.mapper.LocationMapper;
-import com.zy.omp.model.Location;
-import com.zy.omp.model.LatestLocation;
-import com.zy.omp.utils.BeanUtil;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.util.List;
-
-/**
- * 设备位置信息相关
- *
- * @author chenyi
- * Create on 2020/4/10
- */
-@Service
-public class LocationService extends ServiceImpl<LocationMapper, Location> {
-
-    @Resource
-    private LatestLocationService latestLocationService;
-
-    /**
-     * 保存位置信息
-     */
-    public void saveLocation(Location entity) {
-        save(entity);
-        //更新最新的位置信息
-        QueryWrapper<LatestLocation> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("deviceId", entity.getDeviceId());
-        LatestLocation latestLocation = BeanUtil.cast(entity, LatestLocation.class);
-        latestLocationService.saveOrUpdate(latestLocation, queryWrapper);
-    }
-
-    /**
-     * 获取设备的最新位置信息
-     *
-     * @param deviceId 设备ID
-     */
-    public LatestLocation getLatestLocation(String deviceId) {
-        QueryWrapper<LatestLocation> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("deviceId", deviceId);
-        return latestLocationService.getOne(queryWrapper);
-    }
-
-    /**
-     * 查看设备历史轨迹
-     *
-     * @param io 查询入参
-     */
-    public List<Location> getHistory(DeviceHistoryIO io) {
-        QueryWrapper<Location> queryWrapper = new QueryWrapper<>();
-        queryWrapper.select("lonGcj", "latGcj", "uploadTime")
-                .eq("deviceId", io.getDeviceId())
-                .ge("uploadTime", io.getStartTime())
-                .le("uploadTime", io.getEndTime())
-                .orderByDesc("uploadTime");
-        return baseMapper.selectList(queryWrapper);
-    }
-
-}

+ 0 - 2
src/main/java/com/zy/omp/service/MqttLogService.java

@@ -26,9 +26,7 @@ public class MqttLogService extends ServiceImpl<MqttLogMapper, MqttLog> {
 
     static {
         registerSet.add(Constant.TOPIC_REGISTER_CLIENT);
-        registerSet.add(Constant.TOPIC_REGISTER_CLIENT_LP);
         registerSet.add(Constant.TOPIC_REGISTER_SERVER);
-        registerSet.add(Constant.TOPIC_REGISTER_SERVER_LP);
     }
 
     /**

+ 36 - 0
src/main/java/com/zy/omp/service/RelationService.java

@@ -0,0 +1,36 @@
+package com.zy.omp.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zy.omp.mapper.RelationMapper;
+import com.zy.omp.model.Relation;
+import org.springframework.stereotype.Service;
+
+/**
+ * 用户设备绑定关系Service
+ *
+ * @author chenyi
+ * Create on 2020/4/10
+ */
+@Service
+public class RelationService extends ServiceImpl<RelationMapper, Relation> {
+
+
+    /**
+     * 查询设备是否有绑定关系
+     *
+     * @param openNum 设备ID
+     */
+    public boolean checkBind(String openNum) {
+        return baseMapper.checkBind(openNum) > 0;
+    }
+
+    /**
+     * 查询设备是否属于该用户
+     *
+     * @param openId  用户ID
+     * @param openNum 设备ID
+     */
+    public boolean checkBelong(String openNum, String openId) {
+        return baseMapper.checkBelong(openNum, openId) > 0;
+    }
+}

+ 0 - 73
src/main/java/com/zy/omp/service/SetBaseService.java

@@ -1,73 +0,0 @@
-package com.zy.omp.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.zy.omp.common.exception.ApiRuntimeException;
-import com.zy.omp.mapper.SetBaseMapper;
-import com.zy.omp.model.SetBase;
-import org.springframework.stereotype.Service;
-
-/**
- * 其他设置相关
- *
- * @author chenyi
- * Create on 2020/4/10
- */
-@Service
-public class SetBaseService extends ServiceImpl<SetBaseMapper, SetBase> {
-
-    /**
-     * 后台
-     * 获取全部的设置信息
-     *
-     * @param deviceId 设备ID
-     */
-    public SetBase getByDeviceId(String deviceId) {
-        QueryWrapper<SetBase> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("deviceId", deviceId);
-        return baseMapper.selectOne(queryWrapper);
-    }
-
-    /**
-     * 获取音量设置信息
-     */
-    public SetBase getVolumeSet(String deviceId) {
-        QueryWrapper<SetBase> queryWrapper = new QueryWrapper<>();
-        queryWrapper.select("deviceId", "msgVol", "phoneVol", "ringVol");
-        queryWrapper.eq("deviceId", deviceId);
-        return baseMapper.selectOne(queryWrapper);
-    }
-
-    /**
-     * 获取SOS设置信息
-     */
-    public SetBase getSosSet(String deviceId) {
-        QueryWrapper<SetBase> queryWrapper = new QueryWrapper<>();
-        queryWrapper.select("deviceId", "key0Name", "key0Phone", "key1Name", "key1Phone", "key2Name", "key2Phone");
-        queryWrapper.eq("deviceId", deviceId);
-        return baseMapper.selectOne(queryWrapper);
-    }
-
-    /**
-     * 获取其他设置设置信息
-     */
-    public SetBase getOtherSet(String deviceId) {
-        QueryWrapper<SetBase> queryWrapper = new QueryWrapper<>();
-        queryWrapper.select("deviceId", "autoAnswer", "gpsRate", "highFreq");
-        queryWrapper.eq("deviceId", deviceId);
-        return baseMapper.selectOne(queryWrapper);
-    }
-
-    /**
-     * 通过设备ID 更新设备信息
-     *
-     * @param entity 设备实体类
-     */
-    public void updateByDeviceId(SetBase entity) {
-        QueryWrapper<SetBase> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("deviceId", entity.getDeviceId());
-        if (baseMapper.update(entity, queryWrapper) < 1) {
-            throw new ApiRuntimeException("更新设备设置信息失败");
-        }
-    }
-}

+ 40 - 45
src/main/java/com/zy/omp/service/SetService.java

@@ -1,13 +1,11 @@
 package com.zy.omp.service;
 
 import com.zy.omp.common.Constant;
+import com.zy.omp.model.DeviceSet;
 import com.zy.omp.pojo.dto.MqttMsgDto;
 import com.zy.omp.config.mqtt.MqttGateway;
 import com.zy.omp.model.Device;
-import com.zy.omp.model.SetBase;
 import com.zy.omp.model.News;
-import com.zy.omp.pojo.io.wechat.SetIO;
-import com.zy.omp.utils.BeanUtil;
 import com.zy.omp.websocket.WebSocketServer;
 import org.springframework.stereotype.Component;
 
@@ -25,9 +23,9 @@ import java.util.Map;
 public class SetService {
 
     @Resource
-    private SetBaseService setBaseService;
+    private DeviceSetService deviceSetService;
     @Resource
-    private NewsService setNewsService;
+    private NewsService newsService;
     @Resource
     private MqttGateway mqttGateway;
     @Resource
@@ -36,78 +34,76 @@ public class SetService {
     private WebSocketServer webSocketServer;
 
     /**
-     * 设置设备
-     *
-     * @param code 设置指令
-     * @param io   设置信息
+     * 存储语音播报
      */
-    public void set(String code, SetIO io) {
-        MqttMsgDto msgDto = getMqttMsgDtoByCode(code, io);
+    public void saveNews(News news) {
+        MqttMsgDto msgDto = new MqttMsgDto(Constant.M_CODE_NEWS, news.getOpenNum());
+        msgDto.set("newstype", news.getNewsType()).set("newstime", news.getNewsTime()).set("news", news.getNews());
+        String topic = Constant.getTopic(news.getOpenNum());
         // 1. 向设备发送设置指令
-        mqttGateway.sendMsgToMqtt(msgDto.toJson(), io.getTopic());
+        mqttGateway.sendMsgToMqtt(msgDto.toJson(), topic);
         // 2. 设置信息保存至数据库
-        saveToDataBase(code, io);
+        newsService.save(news);
         // 3. 存储消息日志
-        mqttLogService.saveSendLog(io.getTopic(), msgDto.toJson());
+        mqttLogService.saveSendLog(topic, msgDto.toJson());
         // 4. 消息转发前端webSocket
-        String deviceId = io.getTopic().split("/")[1];
-        webSocketServer.massMessage(deviceId, msgDto.toJson());
+        webSocketServer.massMessage(news.getOpenNum(), msgDto.toJson());
     }
 
     /**
-     * 存储至数据库
+     * 设置设备
+     *
+     * @param code  设置指令
+     * @param param 设置信息
      */
-    private void saveToDataBase(String code, SetIO io) {
-        //发送语音播报单独处理
-        if (code.equals(Constant.M_CODE_NEWS)) {
-            News entity = BeanUtil.cast(io, News.class);
-            setNewsService.save(entity);
-        } else {
-            SetBase entity = BeanUtil.cast(io, SetBase.class);
-            setBaseService.updateByDeviceId(entity);
-        }
+    public void set(String code, DeviceSet param) {
+        MqttMsgDto msgDto = getMqttMsgDtoByCode(code, param);
+        String topic = Constant.getTopic(param.getOpenNum());
+        // 1. 向设备发送设置指令
+        mqttGateway.sendMsgToMqtt(msgDto.toJson(), topic);
+        // 2. 设置信息保存至数据库
+        deviceSetService.updateById(param);
+        // 3. 存储消息日志
+        mqttLogService.saveSendLog(topic, msgDto.toJson());
+        // 4. 消息转发前端webSocket
+//        webSocketServer.massMessage(param.getOpenNum(), msgDto.toJson());
     }
 
     /**
      * 组装需要发送的模板消息
      *
-     * @param code 协议中 M 值
-     * @param io   设置信息
+     * @param code  协议中 M 值
+     * @param param 设置信息
      * @return 模板消息对象
      */
-    private MqttMsgDto getMqttMsgDtoByCode(String code, SetIO io) {
-        MqttMsgDto result = new MqttMsgDto(code, io.getDeviceId());
+    private MqttMsgDto getMqttMsgDtoByCode(String code, DeviceSet param) {
+        MqttMsgDto result = new MqttMsgDto(code, param.getOpenNum());
         switch (code) {
             //自动接听
             case Constant.M_CODE_AUTO_ANSWER: {
-                result.set("autoanswer", io.getAutoAnswer());
+                result.set("autoanswer", param.getAutoAnswer());
                 break;
             }
             //音量
             case Constant.M_CODE_VOLUME: {
-                result.set("msgvol", io.getMsgVol()).set("phonevol", io.getPhoneVol()).set("msgtype", 1);
+                result.set("msgvol", param.getMsgVol()).set("phonevol", param.getPhoneVol()).set("msgtype", 1);
                 break;
             }
             //定位频率
             case Constant.M_CODE_GPS_RATE: {
-                result.set("GPS_rate", io.getGpsRate());
-                break;
-            }
-            //语音播报
-            case Constant.M_CODE_NEWS: {
-                result.set("newstype", io.getNewsType()).set("newstime", io.getNewsTime()).set("news", io.getNews());
+                result.set("GPS_rate", param.getGpsRate());
                 break;
             }
             //SOS紧急呼叫
             case Constant.M_CODE_SOS: {
-                result.set("key0_name", io.getKey0Name()).set("key0_phone", io.getKey0Phone())
-                        .set("key1_name", io.getKey1Name()).set("key1_phone", io.getKey1Phone())
-                        .set("key2_name", io.getKey2Name()).set("key2_phone", io.getKey2Phone());
+                result.set("key0_name", param.getKey0Name()).set("key0_phone", param.getKey0Phone())
+                        .set("key1_name", param.getKey1Name()).set("key1_phone", param.getKey1Phone())
+                        .set("key2_name", param.getKey2Name()).set("key2_phone", param.getKey2Phone());
                 break;
             }
             //持续定位
             case Constant.M_CODE_CONTINUE_GPS: {
-                result.set("highfreq", io.getHighFreq());
+                result.set("highfreq", param.getHighFreq());
                 break;
             }
         }
@@ -116,16 +112,15 @@ public class SetService {
 
     /**
      * 服务器返回授权码
-     * 老人机
      */
-    public void returnCode_OMP(Device device) {
+    public void returnCode(Device device) {
         //发送模板消息给设备
         MqttMsgDto msgDto = new MqttMsgDto();
         msgDto.setM(Constant.M_CODE_RETURN_CODE);
         msgDto.setR(Constant.TOPIC_REGISTER_CLIENT);
         msgDto.setT(Constant.TOPIC_REGISTER_SERVER);
         Map<String, Object> data = new HashMap<>();
-        data.put("regnum", device.getNum());
+        data.put("regnum", device.getOpenNum());
         data.put("deviceid", device.getClientId());
         data.put("password", device.getPassword());
         msgDto.setData(data);

+ 10 - 4
src/main/java/com/zy/omp/service/UserService.java

@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.zy.omp.common.Constant;
 import com.zy.omp.pojo.io.pc.UserIO;
 import com.zy.omp.mapper.UserMapper;
 import com.zy.omp.model.User;
@@ -23,6 +22,13 @@ import org.springframework.util.MultiValueMap;
 @Service
 public class UserService extends ServiceImpl<UserMapper, User> {
 
+    /**
+     * 微信小程序登录相关配置
+     */
+    private static final String wxAppId = "wxe90699b45e28a0b6";// 小程序唯一标识
+    private static final String wxSecret = "66690a1ffcfe7f1d85a6dcfa38791f25";//小程序的 app secret
+    private static final String grant_type = "authorization_code"; // 授权(必填)
+
     /**
      * 后台
      * 分页查询用户列表
@@ -48,10 +54,10 @@ public class UserService extends ServiceImpl<UserMapper, User> {
         try {
             // 请求参数
             MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
-            paramsMap.add("appid", Constant.wxAppId);
-            paramsMap.add("secret", Constant.wxSecret);
+            paramsMap.add("appid", wxAppId);
+            paramsMap.add("secret", wxSecret);
             paramsMap.add("js_code", code);
-            paramsMap.add("grant_type", Constant.grant_type);
+            paramsMap.add("grant_type", grant_type);
             String message = HttpUtil.post("https://api.weixin.qq.com/sns/jscode2session", null, paramsMap);
             return JSONObject.parseObject(message).getString("openid");
         } catch (Exception e) {

+ 0 - 8
src/main/java/com/zy/omp/websocket/WebSocketServer.java

@@ -43,14 +43,6 @@ public class WebSocketServer {
         webSocketMap.get(deviceId).remove(session);
     }
 
-    /**
-     * 连接错误
-     */
-    @OnError
-    public void onError(Session session, Throwable error, @PathParam("deviceId") String deviceId) {
-        webSocketMap.get(deviceId).remove(session);
-    }
-
     /**
      * 群发消息
      */

+ 1 - 1
src/main/resources/application-dev.yml

@@ -12,7 +12,7 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://59.110.141.39:3306/zy_mobile?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=true
+    url: jdbc:mysql://59.110.141.39:3306/old_phone?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=true
     username: useryxk
     password: CHENyi406@
     dbcp2:

+ 15 - 0
src/main/resources/mapper/DeviceInfoStateMapping.xml

@@ -0,0 +1,15 @@
+<?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.DeviceInfoStateMapper">
+
+    <select id="listByUserId" resultType="com.zy.omp.pojo.vo.WxLatestDeviceState">
+        SELECT
+            t1.deviceName,
+            t2.*
+        FROM
+            relation t1
+        LEFT JOIN device_info_state t2 ON t1.openNum = t2.openNum
+            WHERE t1.openId = #{openId}
+        ORDER BY t1.isDefault,t1.updateTime DESC
+    </select>
+</mapper>

+ 10 - 37
src/main/resources/mapper/DeviceMapping.xml

@@ -2,56 +2,29 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.zy.omp.mapper.DeviceMapper">
 
-    <select id="listPage" resultType="com.zy.omp.pojo.vo.DeviceFullDataVo">
+    <select id="listPage" resultType="com.zy.omp.pojo.vo.DeviceListVo">
         SELECT
-            t1.num             AS deviceNum,
-            t1.clientId        AS deviceId,
-            t1.password,
+            t1.openNum,
             t1.createTime,
-            t1.status,
-            t1.lastOnlineTime,
+            t2.batteryNum,
+            t2.signalNum,
             t2.`mode`,
             t2.lon,
             t2.lat,
-            t2.lonGcj,
-            t2.latGcj,
             t2.site,
-            t2.batteryNum,
-            t2.signalNum,
-            t2.num,
             t2.speed,
+            t2.num,
             t2.uploadTime
         FROM
-            device t1
-        LEFT JOIN latest_location t2 ON t1.clientId = t2.deviceId
+            device_base t1
+        LEFT JOIN device_info_state t2 ON t1.openNum = t2.openNum
         <where>
-            <if test="io.num != null and io.num != ''">
-                AND (t1.num LIKE CONCAT('%',#{io.num},'%') OR t1.clientId LIKE CONCAT('%',#{io.num},'%'))
-            </if>
-            <if test="io.status != null and io.status > -1">
-                AND t1.status = #{io.status}
+            <if test="io.openNum != null and io.openNum != ''">
+                AND t1.openNum LIKE CONCAT('%',#{io.openNum},'%')
             </if>
         </where>
         ORDER BY
-            t1.createTime DESC
+        t1.createTime DESC
     </select>
 
-    <update id="updateDeviceStatus">
-        UPDATE
-            device
-        SET
-            `status` = CASE clientId
-        <foreach collection="devices" item="device">
-            WHEN #{device.clientId} THEN #{device.status}
-        </foreach>
-        END,
-        `lastOnlineTime` = CASE clientId
-        WHEN '0' THEN '0'
-        <foreach collection="devices" item="device">
-            <if test="device.status == 1">
-                WHEN #{device.clientId} THEN #{device.lastOnlineTime}
-            </if>
-        </foreach>
-        END
-    </update>
 </mapper>

+ 0 - 13
src/main/resources/mapper/LatestLocationMapping.xml

@@ -1,13 +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.LatestLocationMapper">
-
-    <select id="getLatestLocation" resultType="com.zy.omp.pojo.vo.DeviceFullDataVo">
-        SELECT
-            t1.num AS deviceNum,
-            t2.*
-        FROM
-            device t1
-        LEFT JOIN latest_location t2 ON t1.clientId = t2.deviceId
-    </select>
-</mapper>

+ 0 - 4
src/main/resources/mapper/LocationMapping.xml

@@ -1,4 +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.LocationMapper">
-</mapper>

+ 3 - 3
src/main/resources/mapper/DeviceDynamicMapping.xml → src/main/resources/mapper/RelationMapping.xml

@@ -1,12 +1,12 @@
 <?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.DeviceDynamicMapper">
+<mapper namespace="com.zy.omp.mapper.RelationMapper">
 
     <select id="checkBind" resultType="java.lang.Integer">
-        SELECT IFNULL( (SELECT 1 FROM device_dynamic WHERE deviceNum = #{deviceNum} LIMIT 1) ,0)
+        SELECT IFNULL( (SELECT 1 FROM relation WHERE openNum = #{openNum} LIMIT 1) ,0)
     </select>
 
     <select id="checkBelong" resultType="java.lang.Integer">
-        SELECT IFNULL( (SELECT 1 FROM device_dynamic WHERE deviceId = #{deviceId} AND userId = #{userId} LIMIT 1), 0)
+        SELECT IFNULL( (SELECT 1 FROM relation WHERE openNum = #{openNum} AND openId = #{openId} LIMIT 1), 0)
     </select>
 </mapper>