!341 优化忽略租户写法,在抛出异常时可以正确关闭忽略; 修复 oracle脚本字段缺失
* update 优化忽略租户写法,在抛出异常时可以正确关闭忽略 * fix 修复 oracle脚本字段缺失
This commit is contained in:
parent
8d0d85444a
commit
1bfcbfa456
@ -6,14 +6,16 @@ import cn.hutool.core.convert.Convert;
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
|
||||
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 租户助手
|
||||
@ -49,6 +51,34 @@ public class TenantHelper {
|
||||
InterceptorIgnoreHelper.clearIgnoreStrategy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 在忽略租户中执行
|
||||
*
|
||||
* @param handle 处理执行方法
|
||||
*/
|
||||
public static void ignore(Runnable handle) {
|
||||
enableIgnore();
|
||||
try {
|
||||
handle.run();
|
||||
} finally {
|
||||
disableIgnore();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在忽略租户中执行
|
||||
*
|
||||
* @param handle 处理执行方法
|
||||
*/
|
||||
public static <T> T ignore(Supplier<T> handle) {
|
||||
enableIgnore();
|
||||
try {
|
||||
return handle.get();
|
||||
} finally {
|
||||
disableIgnore();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置动态租户(一直有效 需要手动清理)
|
||||
* <p>
|
||||
|
@ -3,6 +3,11 @@ package org.dromara.system.controller.system;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||
import com.baomidou.lock.annotation.Lock4j;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.constant.TenantConstants;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
@ -18,13 +23,15 @@ import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.system.domain.bo.SysTenantBo;
|
||||
import org.dromara.system.domain.vo.SysTenantVo;
|
||||
import org.dromara.system.service.ISysTenantService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -72,7 +79,7 @@ public class SysTenantController extends BaseController {
|
||||
@SaCheckPermission("system:tenant:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<SysTenantVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
@PathVariable Long id) {
|
||||
return R.ok(tenantService.queryById(id));
|
||||
}
|
||||
|
||||
@ -89,7 +96,7 @@ public class SysTenantController extends BaseController {
|
||||
if (!tenantService.checkCompanyNameUnique(bo)) {
|
||||
return R.fail("新增租户'" + bo.getCompanyName() + "'失败,企业名称已存在");
|
||||
}
|
||||
return toAjax(tenantService.insertByBo(bo));
|
||||
return toAjax(TenantHelper.ignore(() -> tenantService.insertByBo(bo)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,7 +175,7 @@ public class SysTenantController extends BaseController {
|
||||
@Log(title = "租户", businessType = BusinessType.UPDATE)
|
||||
@GetMapping("/syncTenantPackage")
|
||||
public R<Void> syncTenantPackage(@NotBlank(message = "租户ID不能为空") String tenantId, @NotBlank(message = "套餐ID不能为空") String packageId) {
|
||||
return toAjax(tenantService.syncTenantPackage(tenantId, packageId));
|
||||
return toAjax(TenantHelper.ignore(() -> tenantService.syncTenantPackage(tenantId, packageId)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
@ -24,8 +26,6 @@ import org.dromara.system.domain.bo.SysOssConfigBo;
|
||||
import org.dromara.system.domain.vo.SysOssConfigVo;
|
||||
import org.dromara.system.mapper.SysOssConfigMapper;
|
||||
import org.dromara.system.service.ISysOssConfigService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -52,23 +52,26 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
TenantHelper.enableIgnore();
|
||||
List<SysOssConfig> list = baseMapper.selectList(
|
||||
new LambdaQueryWrapper<SysOssConfig>().orderByAsc(TenantEntity::getTenantId));
|
||||
TenantHelper.disableIgnore();
|
||||
List<SysOssConfig> list = TenantHelper.ignore(() ->
|
||||
baseMapper.selectList(
|
||||
new LambdaQueryWrapper<SysOssConfig>().orderByAsc(TenantEntity::getTenantId))
|
||||
);
|
||||
Map<String, List<SysOssConfig>> map = StreamUtils.groupByKey(list, SysOssConfig::getTenantId);
|
||||
for (String tenantId : map.keySet()) {
|
||||
TenantHelper.setDynamic(tenantId);
|
||||
// 加载OSS初始化配置
|
||||
for (SysOssConfig config : map.get(tenantId)) {
|
||||
String configKey = config.getConfigKey();
|
||||
if ("0".equals(config.getStatus())) {
|
||||
RedisUtils.setCacheObject(OssConstant.DEFAULT_CONFIG_KEY, configKey);
|
||||
try {
|
||||
for (String tenantId : map.keySet()) {
|
||||
TenantHelper.setDynamic(tenantId);
|
||||
// 加载OSS初始化配置
|
||||
for (SysOssConfig config : map.get(tenantId)) {
|
||||
String configKey = config.getConfigKey();
|
||||
if ("0".equals(config.getStatus())) {
|
||||
RedisUtils.setCacheObject(OssConstant.DEFAULT_CONFIG_KEY, configKey);
|
||||
}
|
||||
CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config));
|
||||
}
|
||||
CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config));
|
||||
}
|
||||
} finally {
|
||||
TenantHelper.clearDynamic();
|
||||
}
|
||||
TenantHelper.clearDynamic();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,6 @@ import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.system.domain.*;
|
||||
import org.dromara.system.domain.bo.SysTenantBo;
|
||||
import org.dromara.system.domain.vo.SysTenantVo;
|
||||
@ -113,8 +112,6 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean insertByBo(SysTenantBo bo) {
|
||||
TenantHelper.enableIgnore();
|
||||
|
||||
SysTenant add = MapstructUtils.convert(bo, SysTenant.class);
|
||||
|
||||
// 获取所有租户编号
|
||||
@ -124,7 +121,6 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
add.setTenantId(tenantId);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (!flag) {
|
||||
TenantHelper.disableIgnore();
|
||||
throw new ServiceException("创建租户失败");
|
||||
}
|
||||
bo.setId(add.getId());
|
||||
@ -186,8 +182,6 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
config.setTenantId(tenantId);
|
||||
}
|
||||
configMapper.insertBatch(sysConfigList);
|
||||
|
||||
TenantHelper.disableIgnore();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -344,7 +338,6 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean syncTenantPackage(String tenantId, String packageId) {
|
||||
TenantHelper.enableIgnore();
|
||||
SysTenantPackage tenantPackage = tenantPackageMapper.selectById(packageId);
|
||||
List<SysRole> roles = roleMapper.selectList(
|
||||
new LambdaQueryWrapper<SysRole>().eq(SysRole::getTenantId, tenantId));
|
||||
@ -369,7 +362,6 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||
roleMenuMapper.delete(
|
||||
new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, roleIds).notIn(!menuIds.isEmpty(), SysRoleMenu::getMenuId, menuIds));
|
||||
}
|
||||
TenantHelper.disableIgnore();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ comment on column test_tree.update_time is '更新时间';
|
||||
comment on column test_tree.update_by is '更新人';
|
||||
comment on column test_tree.del_flag is '删除标志';
|
||||
|
||||
insert into sys_user(user_id, tenant_id, dept_id, user_name, nick_name, user_type, email, phonenumber, sex, avatar, password, status, del_flag, login_ip, login_date, create_dept, create_by, create_time, update_by, update_time, remark) values (3, '000000', 108, 'test', '本部门及以下 密码666666', 'sys_user', '', '', '0', null, '$2a$10$b8yUzN0C71sbz.PhNOCgJe.Tu1yWC3RNrTyjSQ8p1W0.aaUXUJ.Ne', '0', '0', '127.0.0.1', sysdate, 103, sysdate, 1, sysdate, 3, sysdate, null);
|
||||
insert into sys_user(user_id, tenant_id, dept_id, user_name, nick_name, user_type, email, phonenumber, sex, avatar, password, status, del_flag, login_ip, login_date, create_dept, create_by, create_time, update_by, update_time, remark) values (4, '000000', 102, 'test1', '仅本人 密码666666', 'sys_user', '', '', '0', null, '$2a$10$b8yUzN0C71sbz.PhNOCgJe.Tu1yWC3RNrTyjSQ8p1W0.aaUXUJ.Ne', '0', '0', '127.0.0.1', sysdate, 103, sysdate, 1, sysdate, 4, sysdate, null);
|
||||
insert into sys_user(user_id, tenant_id, dept_id, user_name, nick_name, user_type, email, phonenumber, sex, avatar, password, status, del_flag, login_ip, login_date, create_dept, create_by, create_time, update_by, update_time, remark) values (3, '000000', 108, 'test', '本部门及以下 密码666666', 'sys_user', '', '', '0', null, '$2a$10$b8yUzN0C71sbz.PhNOCgJe.Tu1yWC3RNrTyjSQ8p1W0.aaUXUJ.Ne', '0', '0', '127.0.0.1', sysdate, 103, 1, sysdate, 3, sysdate, null);
|
||||
insert into sys_user(user_id, tenant_id, dept_id, user_name, nick_name, user_type, email, phonenumber, sex, avatar, password, status, del_flag, login_ip, login_date, create_dept, create_by, create_time, update_by, update_time, remark) values (4, '000000', 102, 'test1', '仅本人 密码666666', 'sys_user', '', '', '0', null, '$2a$10$b8yUzN0C71sbz.PhNOCgJe.Tu1yWC3RNrTyjSQ8p1W0.aaUXUJ.Ne', '0', '0', '127.0.0.1', sysdate, 103, 1, sysdate, 4, sysdate, null);
|
||||
|
||||
insert into sys_menu(menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) values (5, '测试菜单', 0, 5, 'demo', null, 1, 0, 'M', '0', '0', null, 'star', 103, 1, sysdate, 1, sysdate, '');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user