bmmx vor 1 Jahr
Ursprung
Commit
3f36b0c9e5

+ 7 - 0
src/main/java/com/om/controller/admin/AppUserController.java

@@ -122,6 +122,13 @@ public class AppUserController {
         return userService.bindingVci(bindVO);
     }
 
+    @PostMapping("/relieveVci")
+    @ApiOperation("解绑vci")
+    Result relieveVci(@RequestBody AppBindVO bindVO){
+
+        return userService.relieveVci(bindVO);
+    }
+
     @GetMapping("/getVciByUserId")
     @ApiOperation("根据用户id获取vci设备列表")
     public Result<List<VciInfo>> getVciByUserId(@RequestParam Integer userId){

+ 2 - 0
src/main/java/com/om/service/IUserService.java

@@ -5,6 +5,7 @@ import com.om.entity.dto.AppBaseDTO;
 import com.om.entity.dto.AppUserUpdatePwdDTO;
 import com.om.entity.dto.UserLoginDTO;
 import com.om.entity.dto.UserQueryPageDTO;
+import com.om.entity.po.Device;
 import com.om.entity.po.User;
 import com.om.entity.po.VciInfo;
 import com.om.entity.vo.AppBindVO;
@@ -59,4 +60,5 @@ public interface IUserService extends IService<User> {
 
     Result<List<VciInfo>> getVciByUserId(Integer userId);
 
+    Result relieveVci(AppBindVO bindVO);
 }

+ 39 - 3
src/main/java/com/om/service/impl/UserServiceImpl.java

@@ -593,6 +593,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
         if (vciInfo == null) {
             return Result.error().message("VCI设备不存在").result(ResultCode.SERVICE_HANDLE_ERROR);
         }
+        UserVci one = userVciService.lambdaQuery()
+                .eq(UserVci::getUserId, userId)
+                .eq(UserVci::getVciInfoId, vciInfo.getId())
+                .one();
+        if (BeanUtil.isNotEmpty(one)) {
+            throw new BadReqException("该vci设备已被该用户绑定");
+        }
+
         UserVci userVci = new UserVci();
         userVci.setUserId(userId);
         userVci.setVciInfoId(vciInfo.getId());
@@ -613,11 +621,39 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
         List<UserVci> list = userVciService.lambdaQuery()
                 .eq(UserVci::getUserId, userId)
                 .list();
-        if (list.isEmpty()) {
-            return Result.ok();
+        List<VciInfo> vciInfoList = new ArrayList<>();
+        if (!list.isEmpty()) {
+            List<Integer> vciIds = list.stream().map(c -> c.getVciInfoId()).collect(Collectors.toList());
+
+            vciInfoList = vciInfoService.listByIds(vciIds);
+        }
+        return Result.ok(vciInfoList);
+    }
+
+    @Override
+    public Result relieveVci(AppBindVO bindVO) {
+        if (BeanUtil.isEmpty(bindVO)) {
+            return Result.error().message("参数为空").result(ResultCode.NO_DATA);
+        }
+        Integer userId = bindVO.getUserId();
+        String vciNum = bindVO.getVciSn();
+        LambdaQueryWrapper<VciInfo> vciInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        vciInfoLambdaQueryWrapper.eq(VciInfo::getVciNum, vciNum);
+        VciInfo vciInfo = vciInfoService.getOne(vciInfoLambdaQueryWrapper);
+        if (vciInfo == null) {
+            return Result.error().message("VCI设备不存在").result(ResultCode.SERVICE_HANDLE_ERROR);
         }
 
+        UserVci one = userVciService.lambdaQuery()
+                .eq(UserVci::getUserId, userId)
+                .eq(UserVci::getVciInfoId, vciInfo.getId())
+                .one();
+        if (BeanUtil.isEmpty(one)) {
+            throw new BadReqException("该客户端账号没有绑定该vci设备");
+        }
+        this.removeById(one.getId());
 
-        return null;
+        return Result.ok();
     }
+
 }