瀏覽代碼

超管设备解绑

chejianzheng 1 月之前
父節點
當前提交
eb0ff538c3
共有 14 個文件被更改,包括 313 次插入3 次删除
  1. 38 0
      portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebAdminDealController.java
  2. 38 0
      portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebAdminQueryController.java
  3. 16 0
      portal-service-common/src/main/java/com/hfln/portal/common/request/web/AdminDealUnbindParam.java
  4. 16 0
      portal-service-common/src/main/java/com/hfln/portal/common/request/web/AdminQueryWxUserParam.java
  5. 45 0
      portal-service-common/src/main/java/com/hfln/portal/common/response/user/UserInfoDto.java
  6. 6 0
      portal-service-domain/src/main/java/com/hfln/portal/domain/customer/OprLogType.java
  7. 13 0
      portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/WebAdminDealGateway.java
  8. 91 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebAdminDealGatewayImpl.java
  9. 0 3
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebGatewayImpl.java
  10. 33 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mapper/DevInfoMapper.java
  11. 2 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/DevInfoService.java
  12. 2 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/GroupDevMapService.java
  13. 5 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/DevInfoServiceImpl.java
  14. 8 0
      portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/GroupDevMapServiceImpl.java

+ 38 - 0
portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebAdminDealController.java

@@ -0,0 +1,38 @@
+
+package com.hfln.portal.application.controller.web;
+
+
+import cn.hfln.framework.catchlog.CatchAndLog;
+import cn.hfln.framework.dto.ApiResult;
+import com.hfln.portal.common.request.web.AdminDealUnbindParam;
+import com.hfln.portal.domain.gateway.WebAdminDealGateway;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+@RestController
+@CatchAndLog
+@Tag(name = "web端后台超管特权处理相关")
+@Slf4j
+@RequestMapping("/web/admin-deal")
+public class WebAdminDealController {
+
+    @Autowired
+    private WebAdminDealGateway webAdminDealGateway;
+
+    @PostMapping("/unbind")
+    @Operation(summary = "解绑用户")
+    public ApiResult<Void> unbind(@Valid @RequestBody AdminDealUnbindParam param) {
+
+        webAdminDealGateway.unbind(param);
+        return ApiResult.success();
+    }
+
+}

+ 38 - 0
portal-service-application/src/main/java/com/hfln/portal/application/controller/web/WebAdminQueryController.java

@@ -0,0 +1,38 @@
+
+package com.hfln.portal.application.controller.web;
+
+
+import cn.hfln.framework.catchlog.CatchAndLog;
+import cn.hfln.framework.dto.ApiResult;
+import com.hfln.portal.common.request.web.AdminQueryWxUserParam;
+import com.hfln.portal.common.response.user.UserInfoDto;
+import com.hfln.portal.domain.gateway.WebAdminDealGateway;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+@RestController
+@CatchAndLog
+@Tag(name = "web端后台超管查询相关")
+@Slf4j
+@RequestMapping("/web/admin/query")
+public class WebAdminQueryController {
+
+    @Autowired
+    private WebAdminDealGateway webAdminDealGateway;
+
+    @PostMapping("/wxUser")
+    @Operation(summary = "小程序后台用户")
+    public ApiResult<UserInfoDto> queryWxUser(@Valid @RequestBody AdminQueryWxUserParam param) {
+
+        return ApiResult.success(webAdminDealGateway.queryWxUser(param));
+    }
+
+}

+ 16 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/web/AdminDealUnbindParam.java

@@ -0,0 +1,16 @@
+package com.hfln.portal.common.request.web;
+
+import com.hfln.portal.common.vo.BaseVO;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+
+@Data
+public class AdminDealUnbindParam extends BaseVO {
+
+    @Schema(description = "设备ID")
+    @NotNull(message = "设备ID不能为空")
+    private Long devId;
+}

+ 16 - 0
portal-service-common/src/main/java/com/hfln/portal/common/request/web/AdminQueryWxUserParam.java

@@ -0,0 +1,16 @@
+package com.hfln.portal.common.request.web;
+
+import com.hfln.portal.common.vo.BaseVO;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+
+@Data
+public class AdminQueryWxUserParam extends BaseVO {
+
+    @Schema(description = "用户ID")
+    @NotNull(message = "用户ID不能为空")
+    private Long userId;
+}

+ 45 - 0
portal-service-common/src/main/java/com/hfln/portal/common/response/user/UserInfoDto.java

@@ -0,0 +1,45 @@
+package com.hfln.portal.common.response.user;
+
+
+import com.hfln.portal.common.vo.BaseVO;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Schema(description = "从微信查询用户信息")
+public class UserInfoDto extends BaseVO {
+
+    private Long userId;
+
+    @Schema(description = "用户openid,唯一标识")
+    private String openid;
+
+    @Schema(description = "用户unionid,微信开发平台下唯一标识")
+    private String unionId;
+
+    @Schema(description = "手机号")
+    private String phone;
+
+    @Schema(description = "昵称")
+    private String nickname;
+
+    @Schema(description = "头像URL")
+    private String avatarUrl;
+
+    @Schema(description = "性别:0-未知,1-男,2-女")
+    private Integer gender;
+
+    @Schema(description = "国家")
+    private String country;
+
+    @Schema(description = "省份")
+    private String province;
+
+    @Schema(description = "城市")
+    private String city;
+
+    @Schema(description = "语言")
+    private String language;
+}

+ 6 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/customer/OprLogType.java

@@ -38,6 +38,12 @@ public enum OprLogType {
     DEL_TIME_PLAN("DEL_TIME_PLAN", "删除时间计划"),
 
     CANCEL_SHARE("CANCEL_SHARE", "取消分享"),
+
+
+    /**
+     * 超管特权操作
+     */
+    ADMIN_DEAL_UNBIND("ADMIN_DEAL_UNBIND", "超管解绑设备"),
     ;
 
     String code;

+ 13 - 0
portal-service-domain/src/main/java/com/hfln/portal/domain/gateway/WebAdminDealGateway.java

@@ -0,0 +1,13 @@
+package com.hfln.portal.domain.gateway;
+
+import com.hfln.portal.common.request.web.AdminDealUnbindParam;
+import com.hfln.portal.common.request.web.AdminQueryWxUserParam;
+import com.hfln.portal.common.response.user.UserInfoDto;
+
+public interface WebAdminDealGateway {
+
+    // 后台管理员 管理用户
+    void unbind(AdminDealUnbindParam param);
+
+    UserInfoDto queryWxUser(AdminQueryWxUserParam param);
+}

+ 91 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebAdminDealGatewayImpl.java

@@ -0,0 +1,91 @@
+package com.hfln.portal.infrastructure.gateway.impl;
+
+
+import cn.hfln.framework.extension.BizException;
+import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.hfln.portal.common.request.web.AdminDealUnbindParam;
+import com.hfln.portal.common.request.web.AdminQueryWxUserParam;
+import com.hfln.portal.common.response.user.UserInfoDto;
+import com.hfln.portal.domain.customer.OprLogType;
+import com.hfln.portal.domain.customer.util.CopyUtils;
+import com.hfln.portal.domain.exception.ErrorEnum;
+import com.hfln.portal.domain.gateway.WebAdminDealGateway;
+import com.hfln.portal.infrastructure.po.DevInfo;
+import com.hfln.portal.infrastructure.po.DevShare;
+import com.hfln.portal.infrastructure.po.GroupDevMap;
+import com.hfln.portal.infrastructure.po.UserInfo;
+import com.hfln.portal.infrastructure.service.*;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Service
+@Slf4j
+public class WebAdminDealGatewayImpl implements WebAdminDealGateway {
+
+    @Autowired
+    private DevInfoService devInfoService;
+    @Autowired
+    private DevShareService devShareService;
+    @Autowired
+    private GroupDevMapService groupDevMapService;
+    @Autowired
+    private TblOprLogService tblOprLogService;
+    @Autowired
+    private UserService userService;
+
+    @Override
+    @Transactional
+    public void unbind(AdminDealUnbindParam param) {
+
+        // 设备解绑
+        // 1 设备主绑人 解绑
+        // 3 设备所属租户 解绑
+        // 2 设备被分享者 逻辑删除
+        // 4 群组分享表 逻辑删除
+        log.info("超管对设备devId:{}, 进行解绑", param.getDevId());
+
+        DevInfo devInfo = devInfoService.getById(param.getDevId());
+        if (devInfo == null) {
+            throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
+        }
+
+        tblOprLogService.saveLog(OprLogType.ADMIN_DEAL_UNBIND.getCode(), devInfo);
+        log.info("设备信息:{}", JSON.toJSONString(devInfo));
+
+        // 查询设备分享者 逻辑删除
+        List<DevShare> shares = devShareService.list(new LambdaQueryWrapper<DevShare>().eq(DevShare::getDevId, devInfo.getDevId()));
+        log.info("设备被分享者:{}", JSON.toJSONString(shares));
+        devShareService.update(
+                Wrappers.<DevShare>lambdaUpdate()
+                        .eq(DevShare::getDevId, devInfo.getDevId())
+                        .eq(DevShare::getIsDeleted, 0)
+                        .set(DevShare::getIsDeleted, 1)
+        );
+        // 群组设备分享表 逻辑删除
+        List<GroupDevMap> groupDevMaps = groupDevMapService.queryByDevId(devInfo.getDevId());
+        log.info("群组设备分享表:{}", JSON.toJSONString(groupDevMaps));
+        groupDevMapService.update(
+                Wrappers.<GroupDevMap>lambdaUpdate()
+                        .eq(GroupDevMap::getDevId, devInfo.getDevId())
+                        .eq(GroupDevMap::getIsDeleted, 0)
+                        .set(GroupDevMap::getIsDeleted, 1)
+        );
+
+        // 对设备 绑定信息置空信息
+        devInfoService.resetDevInfo(devInfo.getDevId());
+        log.info("超管设备解绑完成");
+    }
+
+    @Override
+    public UserInfoDto queryWxUser(AdminQueryWxUserParam param) {
+
+        UserInfo userInfo = userService.queryById(param.getUserId());
+        return CopyUtils.copy(userInfo, UserInfoDto.class);
+    }
+}

+ 0 - 3
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebGatewayImpl.java

@@ -97,9 +97,6 @@ public class WebGatewayImpl implements WebGateway {
     private TblDicItemService tblDicItemService;
 
     @Autowired
-    private UserService userService;
-
-    @Autowired
     private TblTenantService tblTenantService;
 
     @Autowired

+ 33 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mapper/DevInfoMapper.java

@@ -3,10 +3,43 @@ package com.hfln.portal.infrastructure.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.hfln.portal.infrastructure.po.DevInfo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Update;
 
 /**
  * 设备信息表 Mapper 接口
  */
 @Mapper
 public interface DevInfoMapper extends BaseMapper<DevInfo> {
+
+    @Update("UPDATE dev_info " +
+            "SET " +
+            "user_id = null , " +
+            "tenant_id = null , " +
+            "online = 0 , " +
+            "offline_time = null , " +
+            "dev_warn = null , " +
+            "wifi_name = null , " +
+            "wifi_password = null , " +
+            "ip = null , " +
+            "mount_plain = null , " +
+            "install_position = null , " +
+            "start_x = null , " +
+            "start_y = null , " +
+            "start_z = null , " +
+            "stop_x = null , " +
+            "stop_y = null , " +
+            "stop_z = null , " +
+            "height = null , " +
+            "length = null , " +
+            "width = null , " +
+            "north_angle = null , " +
+            "y = null , " +
+            "x = null , " +
+            "active_time = null , " +
+            "falling_confirm = null , " +
+            "exist_flag = null , " +
+            "presence_change_time = null " +
+
+            "WHERE dev_id = #{devId}")
+    void reset(Long devId);
 }

+ 2 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/DevInfoService.java

@@ -34,4 +34,6 @@ public interface DevInfoService extends IService<DevInfo> {
     List<Long> queryByUserId (Long userId);
 
     List<String> devIdsChangeClientIds (List<Long> devIds);
+
+    void resetDevInfo(Long devId);
 }

+ 2 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/GroupDevMapService.java

@@ -9,4 +9,6 @@ public interface GroupDevMapService extends IService<GroupDevMap> {
 
 
     List<GroupDevMap> queryByGroupUuid(String groupUuid);
+
+    List<GroupDevMap> queryByDevId(Long devId);
 }

+ 5 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/DevInfoServiceImpl.java

@@ -267,4 +267,9 @@ public class DevInfoServiceImpl extends ServiceImpl<DevInfoMapper, DevInfo> impl
                 .filter(Objects::nonNull)
                 .collect(Collectors.toList());
     }
+
+    @Override
+    public void resetDevInfo(Long devId) {
+        this.baseMapper.reset(devId);
+    }
 }

+ 8 - 0
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/service/impl/GroupDevMapServiceImpl.java

@@ -19,4 +19,12 @@ public class GroupDevMapServiceImpl extends ServiceImpl<GroupDevMapMapper, Group
 
         return this.baseMapper.selectList(new LambdaQueryWrapper<GroupDevMap>().eq(GroupDevMap::getGroupUuid, groupUuid).eq(GroupDevMap::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED));
     }
+
+    @Override
+    public List<GroupDevMap> queryByDevId(Long devId) {
+
+        LambdaQueryWrapper<GroupDevMap> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(GroupDevMap::getDevId, devId);
+        return this.baseMapper.selectList(wrapper);
+    }
 }