删除多租户
This commit is contained in:
parent
13b5d32cc6
commit
b280c02adf
@ -1,50 +0,0 @@
|
||||
package com.cdzy.user.component;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.model.response.CommonEbikeRole;
|
||||
import com.cdzy.common.model.response.CommonStaffInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.mybatisflex.core.tenant.TenantFactory;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class EbikeTenantFactory implements TenantFactory {
|
||||
|
||||
public Object[] getTenantIds() {
|
||||
if (StpUtil.isLogin()) {
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
Object attribute = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
|
||||
if (attribute != null) {
|
||||
String id = (String) StpUtil.getLoginId();
|
||||
Object object = StpUtil.getSessionByLoginId(id).get(id);
|
||||
ObjectMapper objectMapper = new ObjectMapper()
|
||||
.registerModule(new JavaTimeModule())
|
||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||
CommonStaffInfo staffInfo = objectMapper.convertValue(object, CommonStaffInfo.class);
|
||||
List<CommonEbikeRole> roles = staffInfo.getRoles();
|
||||
boolean isSysAdmin = false;
|
||||
for (CommonEbikeRole role : roles) {
|
||||
if (role.getSysAdmin()) {
|
||||
isSysAdmin = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
long tenantId = Long.parseLong(attribute.toString());
|
||||
//系统管理员
|
||||
if (isSysAdmin) {
|
||||
return null;
|
||||
} else {
|
||||
return new Object[]{tenantId};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
package com.cdzy.user.config;
|
||||
|
||||
import com.cdzy.common.enums.EbikeContents;
|
||||
import com.cdzy.user.component.EbikeTenantFactory;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
@ -54,15 +53,4 @@ public class MyBatisFlexConfiguration {
|
||||
//设置数据已被删除时的值
|
||||
globalConfig.setDeletedValueOfLogicDelete(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详细的租户工厂配置
|
||||
*/
|
||||
@Bean
|
||||
public static TenantFactory tenantFactory() {
|
||||
logger.info("开始初始化租户工厂");
|
||||
EbikeTenantFactory factory = new EbikeTenantFactory();
|
||||
TenantManager.setTenantFactory(factory);
|
||||
return new EbikeTenantFactory();
|
||||
}
|
||||
}
|
||||
@ -90,15 +90,6 @@ public class EbikeUserController {
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户退出登录
|
||||
*/
|
||||
@GetMapping("logout")
|
||||
public JsonResult<?> logout() {
|
||||
StpUtil.logout();
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户实名验证
|
||||
*
|
||||
@ -110,18 +101,6 @@ public class EbikeUserController {
|
||||
return verifyUtil.verifyRealName(userValidateDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除用户信息。
|
||||
*
|
||||
* @param userId 主键
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
*/
|
||||
@PostMapping("remove")
|
||||
public JsonResult<?> remove(@RequestParam(name = "userId") Long userId) {
|
||||
ebikeUserService.removeById(userId);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销用户信息。
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user