1. 增加【默认】的系统租户的概念,禁止修改与删除等操作

2. 修复定时任务在刷新本地缓存时,会过滤租户的问题
3. 调整短信的回调地址,并进行租户的白名单
This commit is contained in:
YunaiV
2022-02-24 00:53:28 +08:00
parent fa62ace6af
commit 75928525ca
13 changed files with 77 additions and 40 deletions

View File

@ -19,7 +19,6 @@ import javax.servlet.http.HttpServletRequest;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
// TODO 芋艿:这块的接口命名,在纠结下
@Api(tags = "管理后台 - 短信回调")
@RestController
@RequestMapping("/system/sms/callback")
@ -28,7 +27,7 @@ public class SmsCallbackController {
@Resource
private SmsSendService smsSendService;
@PostMapping("/sms/yunpian")
@PostMapping("/yunpian")
@ApiOperation(value = "云片短信的回调", notes = "参见 https://www.yunpian.com/official/document/sms/zh_cn/domestic_push_report 文档")
@ApiImplicitParam(name = "sms_status", value = "发送状态", required = true, example = "[{具体内容}]", dataTypeClass = String.class)
@OperateLog(enable = false)
@ -38,7 +37,7 @@ public class SmsCallbackController {
return "SUCCESS"; // 约定返回 SUCCESS 为成功
}
@PostMapping("/sms/aliyun")
@PostMapping("/aliyun")
@ApiOperation(value = "阿里云短信的回调", notes = "参见 https://help.aliyun.com/document_detail/120998.html 文档")
@OperateLog(enable = false)
public CommonResult<Boolean> receiveAliyunSmsStatus(HttpServletRequest request) throws Throwable {

View File

@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -63,15 +62,6 @@ public class TenantPackageController {
return success(TenantPackageConvert.INSTANCE.convert(tenantPackage));
}
@GetMapping("/list")
@ApiOperation("获得租户套餐列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('system:tenant-package:query')")
public CommonResult<List<TenantPackageRespVO>> getTenantPackageList(@RequestParam("ids") Collection<Long> ids) {
List<TenantPackageDO> list = tenantPackageService.getTenantPackageList(ids);
return success(TenantPackageConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得租户套餐分页")
@PreAuthorize("@ss.hasPermission('system:tenant-package:query')")

View File

@ -22,6 +22,11 @@ import java.util.Date;
@NoArgsConstructor
public class TenantDO extends BaseDO {
/**
* 套餐编号 - 系统
*/
public static final Long PACKAGE_ID_SYSTEM = 0L;
/**
* 租户编号,自增
*/
@ -60,6 +65,7 @@ public class TenantDO extends BaseDO {
* 租户套餐编号
*
* 关联 {@link TenantPackageDO#getId()}
* 特殊逻辑:系统内置租户,不使用套餐,暂时使用 {@link #PACKAGE_ID_SYSTEM} 标识
*/
private Long packageId;
/**

View File

@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -90,6 +91,10 @@ public class PermissionServiceImpl implements PermissionService {
@Resource
private PermissionProducer permissionProducer;
@Resource
@Lazy // 注入自己,所以延迟加载
private PermissionService self;
/**
* 初始化 {@link #roleMenuCache} 和 {@link #menuRoleCache} 缓存
*/
@ -118,7 +123,7 @@ public class PermissionServiceImpl implements PermissionService {
@Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD)
public void schedulePeriodicRefresh() {
initLocalCache();
self.initLocalCache();
}
/**

View File

@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.system.enums.permission.RoleTypeEnum;
import cn.iocoder.yudao.module.system.mq.producer.permission.RoleProducer;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@ -72,6 +73,10 @@ public class RoleServiceImpl implements RoleService {
@Resource
private RoleProducer roleProducer;
@Resource
@Lazy // 注入自己,所以延迟加载
private RoleService self;
/**
* 初始化 {@link #roleCache} 缓存
*/
@ -93,7 +98,7 @@ public class RoleServiceImpl implements RoleService {
@Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD)
public void schedulePeriodicRefresh() {
initLocalCache();
self.initLocalCache();
}
/**

View File

@ -7,7 +7,6 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.Tenant
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
@ -47,14 +46,6 @@ public interface TenantPackageService {
*/
TenantPackageDO getTenantPackage(Long id);
/**
* 获得租户套餐列表
*
* @param ids 编号
* @return 租户套餐列表
*/
List<TenantPackageDO> getTenantPackageList(Collection<Long> ids);
/**
* 获得租户套餐分页
*

View File

@ -16,7 +16,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -91,11 +90,6 @@ public class TenantPackageServiceImpl implements TenantPackageService {
return tenantPackageMapper.selectById(id);
}
@Override
public List<TenantPackageDO> getTenantPackageList(Collection<Long> ids) {
return tenantPackageMapper.selectBatchIds(ids);
}
@Override
public PageResult<TenantPackageDO> getTenantPackagePage(TenantPackagePageReqVO pageReqVO) {
return tenantPackageMapper.selectPage(pageReqVO);

View File

@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantEx
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
@ -23,6 +24,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper;
import cn.iocoder.yudao.module.system.enums.permission.RoleCodeEnum;
import cn.iocoder.yudao.module.system.enums.permission.RoleTypeEnum;
import cn.iocoder.yudao.module.system.mq.producer.tenant.TenantProducer;
import cn.iocoder.yudao.module.system.service.permission.MenuService;
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
import cn.iocoder.yudao.module.system.service.permission.RoleService;
import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler;
@ -86,6 +88,8 @@ public class TenantServiceImpl implements TenantService {
@Resource
private RoleService roleService;
@Resource
private MenuService menuService;
@Resource
private PermissionService permissionService;
@Resource
@ -205,7 +209,7 @@ public class TenantServiceImpl implements TenantService {
@Transactional(rollbackFor = Exception.class)
public void updateTenant(TenantUpdateReqVO updateReqVO) {
// 校验存在
TenantDO tenant = validateTenantExists(updateReqVO.getId());
TenantDO tenant = checkUpdateTenant(updateReqVO.getId());
// 校验套餐被禁用
TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId());
@ -253,16 +257,20 @@ public class TenantServiceImpl implements TenantService {
@Override
public void deleteTenant(Long id) {
// 校验存在
validateTenantExists(id);
checkUpdateTenant(id);
// 删除
tenantMapper.deleteById(id);
}
private TenantDO validateTenantExists(Long id) {
private TenantDO checkUpdateTenant(Long id) {
TenantDO tenant = tenantMapper.selectById(id);
if (tenant == null) {
throw exception(TENANT_NOT_EXISTS);
}
// 内置租户,不允许删除
if (isSystemTenant(tenant)) {
throw exception(TENANT_CAN_NOT_UPDATE_SYSTEM);
}
return tenant;
}
@ -321,9 +329,18 @@ public class TenantServiceImpl implements TenantService {
}
// 获得租户,然后获得菜单
TenantDO tenant = getTenant(TenantContextHolder.getRequiredTenantId());
TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(tenant.getPackageId());
Set<Long> menuIds;
if (isSystemTenant(tenant)) { // 系统租户,菜单是全量的
menuIds = CollectionUtils.convertSet(menuService.getMenus(), MenuDO::getId);
} else {
menuIds = tenantPackageService.getTenantPackage(tenant.getPackageId()).getMenuIds();
}
// 执行处理器
handler.handle(tenantPackage.getMenuIds());
handler.handle(menuIds);
}
private static boolean isSystemTenant(TenantDO tenant) {
return Objects.equals(tenant.getPackageId(), TenantDO.PACKAGE_ID_SYSTEM);
}
}