Browse Source

修复BUG

chenyi406 2 years ago
parent
commit
d248d07fb1

+ 11 - 2
src/main/java/com/zy/omp/controller/wx/DeviceController.java

@@ -59,12 +59,21 @@ public class DeviceController extends BaseController {
     /**
      * 更新设备名称
      */
-    @PostMapping("updateName.do")
-    public ServerResponse updateName(Relation relation) {
+    @PostMapping("updateBindInfo.do")
+    public ServerResponse updateBindInfo(Relation relation) {
         relation.setOpenId(getOpenId());
         return ServerResponse.createBySuccess(relationService.updateDeviceName(relation));
     }
 
+    /**
+     * 更新设备名称
+     */
+    @GetMapping("getBindInfo.do")
+    public ServerResponse getBindInfo() {
+        return ServerResponse.createBySuccess(relationService.getByOpenId(getOpenId()));
+    }
+
+
     /**
      * 添加绑定关系
      */

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

@@ -1,5 +1,6 @@
 package com.zy.omp.model;
 
+import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import lombok.Data;
 
@@ -12,7 +13,7 @@ public class DeviceSet {
     /**
      * 设备ID
      */
-    @TableId
+    @TableId(type = IdType.INPUT)
     private String openNum;
 
     /**

+ 10 - 2
src/main/java/com/zy/omp/service/RelationService.java

@@ -28,6 +28,16 @@ public class RelationService extends ServiceImpl<RelationMapper, Relation> {
                 .eq("openId", openId).orderByDesc("isDefault", "updateTime"));
     }
 
+    /**
+     * 查询用户当前默认设备的绑定信息
+     *
+     * @param openId 用户ID
+     */
+    public Relation getByOpenId(String openId) {
+        return baseMapper.selectOne(new QueryWrapper<Relation>().select("openNum", "deviceName")
+                .eq("openId", openId).eq("isDefault", 1));
+    }
+
     /**
      * 切换默认设备
      */
@@ -47,8 +57,6 @@ public class RelationService extends ServiceImpl<RelationMapper, Relation> {
 
     /**
      * 保存设备绑定关系
-     *
-     * @return 当前绑定的设备列表
      */
     public void saveRelation(Relation relation) {
         //保存新纪录