Bladeren bron

修改用户默认租户

hanzhengyi 1 week geleden
bovenliggende
commit
0621e28b49

+ 16 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/controller/web/SysUserTenantController.java

@@ -5,10 +5,14 @@ import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.exception.BusinessErrorCode;
 import com.usky.common.log.annotation.Log;
 import com.usky.common.log.enums.BusinessType;
+import com.usky.common.security.utils.SecurityUtils;
 import com.usky.system.domain.SysTenant;
+import com.usky.system.domain.SysUser;
 import com.usky.system.domain.SysUserTenant;
 import com.usky.system.service.SysUserTenantService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -62,5 +66,17 @@ public class SysUserTenantController extends BaseController {
     {
         return ApiResult.success(sysUserTenantService.getTenantByUser(userId));
     }
+
+    /**
+     * 修改用户默认租户
+     */
+    @Log(title = "修改用户默认租户", businessType = BusinessType.UPDATE)
+    @Transactional
+    @PutMapping
+    public ApiResult<Void> edit(@Validated @RequestBody SysUserTenant userTenant)
+    {
+        sysUserTenantService.updateUserTenant(userTenant);
+        return ApiResult.success();
+    }
 }
 

+ 7 - 4
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/SysUserTenantService.java

@@ -3,6 +3,7 @@ package com.usky.system.service;
 import com.usky.system.domain.SysTenant;
 import com.usky.system.domain.SysUserTenant;
 import com.usky.common.mybatis.core.CrudService;
+import com.usky.system.service.vo.TenantPlatformVo;
 
 import java.util.List;
 
@@ -20,7 +21,7 @@ public interface SysUserTenantService extends CrudService<SysUserTenant> {
      *
      * @param sysUserTenant
      */
-    public void insertInviteUser(SysUserTenant sysUserTenant);
+    void insertInviteUser(SysUserTenant sysUserTenant);
 
     /**
      * 企业解绑用户
@@ -28,15 +29,17 @@ public interface SysUserTenantService extends CrudService<SysUserTenant> {
      * @param tenantId 租户ID
      * @param userId 用户ID
      */
-    public void deleteUserTenant(Integer tenantId,Long userId);
+    void deleteUserTenant(Integer tenantId,Long userId);
 
     /**
      * 根据用户查询企业下拉框
      */
-    public List<SysTenant> getTenantByUser(Long userId);
+    List<SysTenant> getTenantByUser(Long userId);
 
     /**
      * 根据用户查询绑定状态
      */
-    public Boolean getIdByUser(Integer tenantId,Long userId);
+    Boolean getIdByUser(Integer tenantId,Long userId);
+
+    void updateUserTenant(SysUserTenant userTenant);
 }

+ 17 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysUserTenantServiceImpl.java

@@ -1,6 +1,7 @@
 package com.usky.system.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.usky.common.core.exception.BusinessException;
@@ -13,6 +14,7 @@ import com.usky.system.mapper.SysUserTenantMapper;
 import com.usky.system.service.SysTenantService;
 import com.usky.system.service.SysUserTenantService;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.system.service.vo.TenantPlatformVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -107,4 +109,19 @@ public class SysUserTenantServiceImpl extends AbstractCrudService<SysUserTenantM
         List<SysUserTenant> userTenants = this.list(queryWrapper);
         return userTenants.get(0).getIsDefault();
     }
+
+    @Override
+    @Transactional
+    public void updateUserTenant(SysUserTenant userTenant) {
+        LambdaUpdateWrapper<SysUserTenant> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.set(SysUserTenant::getIsDefault, 0)
+                .eq(SysUserTenant::getUserId, userTenant.getUserId())
+                .eq(SysUserTenant::getIsDefault, 1);
+        this.update(updateWrapper);
+        LambdaUpdateWrapper<SysUserTenant> updateWrapper1 = new LambdaUpdateWrapper<>();
+        updateWrapper1.set(SysUserTenant::getIsDefault, 1)
+                .eq(SysUserTenant::getUserId, userTenant.getUserId())
+                .eq(SysUserTenant::getTenantId, userTenant.getTenantId());
+        this.update(updateWrapper1);
+    }
 }