Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
*/
public interface LoginUserContext {
/**
* 返回当前用户所诉的业务租户信息
* @return 租户ID
* 返回当前用户所在的业务租户id
* @return 租户Id
*/
String getTenantId();

/**
* 返回当前用户所在的业务租户信息
* @return 租户
*/
List<Tenant> getTenants();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public class SSOInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {

String token = request.getHeader("Authorization");
String requestURI = request.getRequestURI();

log.info("Intercepting: {}, Token: {}", requestURI, token != null ? "present" : "null");

String authorization = request.getHeader("Authorization");
// 如果没有token,重定向到登录页
if (token == null || token.isEmpty()) {
if (authorization == null || authorization.isEmpty()) {
log.info("No token, redirecting to: {}", SSO_SERVER);
response.sendRedirect(SSO_SERVER);
return false;
}
String token = jwtUtil.getTokenFromRequest(authorization);
String requestURI = request.getRequestURI();

log.info("Intercepting: {}, Token: {}", requestURI, token != null ? "present" : "null");

try {
// 验证token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ public class DefaultLoginUserContext implements LoginUserContext {
private static final ThreadLocal<UserInfo> CURRENT_USER = new ThreadLocal<>();

private static final int DEFAULT_PLATFORM = 1;
private static final String DEFAULT_TENANT = "1";

/**
* 返回当前用户所在的业务租户id
*
* @return 租户Id
*/
@Override
public String getTenantId() {
UserInfo userInfo = CURRENT_USER.get();
List<Tenant> tenantList = userInfo != null ? userInfo.getTenants() : null;
if (tenantList == null || tenantList.isEmpty()) {
return DEFAULT_TENANT;
}

return tenantList.get(0).getId();
}

@Override
public List<Tenant> getTenants() {
Expand Down
24 changes: 12 additions & 12 deletions base/src/main/java/com/tinyengine/it/mapper/AppMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface AppMapper extends BaseMapper<App> {
*
* @return the list
*/
List<App> queryAllApp();
List<App> queryAllApp(String tenantId);

/**
* 分页查询应用所有信息
Expand All @@ -45,24 +45,24 @@ public interface AppMapper extends BaseMapper<App> {
* @param createdBy the createdBy
* @return the list
*/
List<App> queryAllAppByPage(Integer pageSize, Integer offset, String name,
Integer industryId, Integer sceneId, String framework, String orderBy, String createdBy);
List<App> queryAllAppByPage(Integer pageSize, Integer offset, String name, Integer industryId,
Integer sceneId, String framework, String orderBy, String createdBy, String tenantId);

/**
* 查询表t_app 应用总数
*
* @return the int
*/
@Select("SELECT COUNT(id) FROM t_app WHERE is_template IS NOT TRUE")
int queryAppTotal();
@Select("SELECT COUNT(id) FROM t_app WHERE tenant_id = #{tenantId} AND is_template IS NOT TRUE")
int queryAppTotal(String tenantId);

/**
* 查询表t_app 模版总数
*
* @return the int
*/
@Select("SELECT COUNT(id) FROM t_app WHERE is_template = TRUE")
int queryAppTemplateTotal();
@Select("SELECT COUNT(id) FROM t_app WHERE tenant_id = #{tenantId} AND is_template = TRUE")
int queryAppTemplateTotal(String tenantId);

/**
* 分页查询应用模版所有信息
Expand All @@ -76,24 +76,24 @@ List<App> queryAllAppByPage(Integer pageSize, Integer offset, String name,
* @param createdBy the createdBy
* @return the list
*/
List<App> queryAllAppTemplate(Integer pageSize, Integer offset, String name,
Integer industryId, Integer sceneId, String framework, String orderBy, String createdBy);
List<App> queryAllAppTemplate(Integer pageSize, Integer offset, String name, Integer industryId,
Integer sceneId, String framework, String orderBy, String createdBy, String tenantId);

/**
* 根据主键id查询应用模版数据
*
* @param id the id
* @return the app
*/
App queryAppTemplateById(Integer id);
App queryAppTemplateById(Integer id, String tenantId);

/**
* 根据主键id查询表t_app数据
*
* @param id the id
* @return the app
*/
App queryAppById(Integer id);
App queryAppById(Integer id, String tenantId);

/**
* 根据条件查询表t_app数据
Expand All @@ -109,7 +109,7 @@ List<App> queryAllAppTemplate(Integer pageSize, Integer offset, String name,
* @param id the id
* @return the integer
*/
Integer deleteAppById(@Param("id") Integer id);
Integer deleteAppById(@Param("id") Integer id, String tenantId);

/**
* 根据主键id更新表t_app数据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.common.context.LoginUserContext;
import com.tinyengine.it.common.enums.Enums;
import com.tinyengine.it.common.exception.ExceptionEnum;
import com.tinyengine.it.common.log.SystemServiceLog;
Expand All @@ -28,6 +29,7 @@
import com.tinyengine.it.model.entity.App;
import com.tinyengine.it.model.entity.I18nEntry;
import com.tinyengine.it.model.entity.Platform;
import com.tinyengine.it.model.entity.Tenant;
import com.tinyengine.it.service.app.AppService;
import com.tinyengine.it.service.app.I18nEntryService;
import com.tinyengine.it.service.app.impl.v1.AppV1ServiceImpl;
Expand Down Expand Up @@ -74,14 +76,17 @@ public class AppServiceImpl extends ServiceImpl<AppMapper, App> implements AppSe
@Autowired
private AppV1ServiceImpl appV1ServiceImpl;

@Autowired
private LoginUserContext loginUserContext;

/**
* 查询表t_app所有数据
*
* @return App
*/
@Override
public List<App> queryAllApp() {
return baseMapper.queryAllApp();
return baseMapper.queryAllApp(loginUserContext.getTenantId());
}

/**
Expand All @@ -105,8 +110,9 @@ public AppDto queryAllAppByPage(Integer currentPage, Integer pageSize, String or
}
int offset = (currentPage - 1) * pageSize;
List<App> apps = this.baseMapper.queryAllAppByPage(pageSize, offset, app.getName(),
app.getIndustryId(), app.getSceneId(), app.getFramework(), orderBy, app.getCreatedBy());
Integer total = this.baseMapper.queryAppTotal();
app.getIndustryId(), app.getSceneId(), app.getFramework(), orderBy, app.getCreatedBy(),
loginUserContext.getTenantId());
Integer total = this.baseMapper.queryAppTotal(loginUserContext.getTenantId());
AppDto appDto = new AppDto();
appDto.setApps(apps);
appDto.setTotal(total);
Expand All @@ -122,7 +128,7 @@ public AppDto queryAllAppByPage(Integer currentPage, Integer pageSize, String or
@Override
@SystemServiceLog(description = "通过id查询应用实现方法")
public Result<App> queryAppById(Integer id) {
App app = baseMapper.queryAppById(id);
App app = baseMapper.queryAppById(id, loginUserContext.getTenantId());
if (app == null) {
return Result.failed(ExceptionEnum.CM009);
}
Expand All @@ -149,8 +155,8 @@ public List<App> queryAppByCondition(App app) {
@Override
@SystemServiceLog(description = "应用删除实现方法")
public Result<App> deleteAppById(Integer id) {
App app = baseMapper.queryAppById(id);
int result = baseMapper.deleteAppById(id);
App app = baseMapper.queryAppById(id, loginUserContext.getTenantId());
int result = baseMapper.deleteAppById(id, loginUserContext.getTenantId());
if (result < 1) {
return Result.failed(ExceptionEnum.CM009);
}
Expand All @@ -168,7 +174,7 @@ public Result<App> deleteAppById(Integer id) {
public Result<App> updateAppById(App app) {
// 如果更新extend_config字段,从platform获取数据,继承非route部分
if (app.getExtendConfig() != null && !app.getExtendConfig().isEmpty()) {
App appResult = baseMapper.queryAppById(app.getId());
App appResult = baseMapper.queryAppById(app.getId(), loginUserContext.getTenantId());
Platform platform = platformService.queryPlatformById(appResult.getPlatformId());
Map<String, Object> appExtendConfig = platform.getAppExtendConfig();
appExtendConfig.remove("route");
Expand All @@ -178,7 +184,7 @@ public Result<App> updateAppById(App app) {
if (result < 1) {
return Result.failed(ExceptionEnum.CM001);
}
App selectedApp = baseMapper.queryAppById(app.getId());
App selectedApp = baseMapper.queryAppById(app.getId(), loginUserContext.getTenantId());
return Result.success(selectedApp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.common.context.LoginUserContext;
import com.tinyengine.it.common.exception.ExceptionEnum;
import com.tinyengine.it.common.exception.ServiceException;
import com.tinyengine.it.mapper.AppExtensionMapper;
Expand Down Expand Up @@ -91,6 +92,9 @@ public class AppTemplateServiceImpl extends ServiceImpl<AppMapper, App> implemen
@Autowired
private ModelMapper modelMapper;

@Autowired
private LoginUserContext loginUserContext;

/**
* 分页查询应用模版所有信息
* @param currentPage the currentPage
Expand All @@ -113,8 +117,9 @@ public AppDto queryAllAppTemplate(Integer currentPage, Integer pageSize, String
int offset = (currentPage - 1) * pageSize;

List<App> apps = this.baseMapper.queryAllAppTemplate(pageSize, offset, app.getName(),
app.getIndustryId(), app.getSceneId(), app.getFramework(), orderBy, app.getCreatedBy());
Integer total = this.baseMapper.queryAppTemplateTotal();
app.getIndustryId(), app.getSceneId(), app.getFramework(), orderBy, app.getCreatedBy(),
loginUserContext.getTenantId());
Integer total = this.baseMapper.queryAppTemplateTotal(loginUserContext.getTenantId());
AppDto appDto = new AppDto();
appDto.setApps(apps);
appDto.setTotal(total);
Expand All @@ -129,7 +134,7 @@ public AppDto queryAllAppTemplate(Integer currentPage, Integer pageSize, String
*/
@Override
public Result<App> queryAppTemplateById(Integer id) {
App app = baseMapper.queryAppTemplateById(id);
App app = baseMapper.queryAppTemplateById(id, loginUserContext.getTenantId());
if (app == null) {
return Result.failed(ExceptionEnum.CM009);
}
Expand Down Expand Up @@ -157,7 +162,7 @@ public App createAppByTemplate(App app) {
throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());
}
copyData(templateId, app.getId());
return appMapper.queryAppById(app.getId());
return appMapper.queryAppById(app.getId(), loginUserContext.getTenantId());
}

private void copyData(int templateId, int appId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public List<Page> queryAllPage(Integer aid) {
public Page queryPageById(Integer id) {
Page pageInfo = baseMapper.queryPageById(id);
// 获取schemaMeta进行获取materialHistory中的framework进行判断
String framework = appMapper.queryAppById(pageInfo.getApp()).getFramework();
String framework = appMapper.queryAppById(pageInfo.getApp(), loginUserContext.getTenantId()).getFramework();
if (framework.isEmpty()) {
throw new ServiceException(ExceptionEnum.CM312.getResultCode(), ExceptionEnum.CM312.getResultMsg());
}
Expand Down Expand Up @@ -495,7 +495,7 @@ public Page addIsHome(Page pageInfo) {
* @return the app home page id
*/
public int getAppHomePageId(int appId) {
App appInfo = appMapper.queryAppById(appId);
App appInfo = appMapper.queryAppById(appId, loginUserContext.getTenantId());
// appHomePageId 存在为null的情况,即app没有设置首页
Integer homePage = appInfo.getHomePage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static com.tinyengine.it.common.utils.Utils.findMaxVersion;

import com.fasterxml.jackson.core.type.TypeReference;
import com.tinyengine.it.common.context.LoginUserContext;
import com.tinyengine.it.common.exception.ServiceException;
import com.tinyengine.it.common.log.SystemServiceLog;
import com.tinyengine.it.common.utils.Schema;
Expand Down Expand Up @@ -142,6 +143,9 @@ public class AppV1ServiceImpl implements AppV1Service {
@Autowired
private ComponentLibraryMapper componentLibraryMapper;

@Autowired
private LoginUserContext loginUserContext;

/**
* 获取应用schema
*
Expand Down Expand Up @@ -275,7 +279,7 @@ private List<PackagesDto> getPackages() {
* @return the meta
*/
public MetaDto getMetaDto(Integer id) {
App app = appMapper.queryAppById(id);
App app = appMapper.queryAppById(id, loginUserContext.getTenantId());

Platform platform = platformService.queryPlatformById(app.getPlatformId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public Result<List<Block>> listNew(String appId, String groupId) {
if (appId != null && !appId.isEmpty()) {
appIdTemp = Integer.parseInt(appId);
}
App apps = appMapper.queryAppById(appIdTemp);
App apps = appMapper.queryAppById(appIdTemp, loginUserContext.getTenantId());
if (groupIdTemp != 0) {
if (!apps.getId().equals(appIdTemp)) {
return Result.failed(ExceptionEnum.CM206);
Expand Down
17 changes: 12 additions & 5 deletions base/src/main/resources/mappers/AppMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
SELECT
<include refid="Common_Column_List"/>
<include refid="Common_Join"/>
WHERE A.is_template IS NOT TRUE
WHERE A.is_template IS NOT TRUE AND A.tenant_id = #{tenantId}
ORDER BY A.created_time DESC
</select>

Expand All @@ -455,6 +455,9 @@
<if test="createdBy != null">
AND A.created_by = #{createdBy}
</if>
<if test="tenantId != null">
AND A.tenant_id = #{tenantId}
</if>
</where>
ORDER BY
<choose>
Expand Down Expand Up @@ -488,6 +491,9 @@
<if test="createdBy != null">
AND A.created_by = #{createdBy}
</if>
<if test="tenantId != null">
AND A.tenant_id = #{tenantId}
</if>
</where>
ORDER BY
<choose>
Expand All @@ -505,7 +511,7 @@
<include refid="Common_Column_List"/>
<include refid="Common_Join"/>
<where>
A.id = #{id}
A.id = #{id} AND A.tenant_id = #{tenantId}
</where>
</select>

Expand All @@ -515,7 +521,8 @@
<include refid="Common_Column_List"/>
<include refid="Common_Join"/>
<where>
A.id = #{id} AND A.is_template = true
A.tenant_id = #{tenantId} AND
A.id = #{id} AND A.is_template = true
</where>
</select>

Expand All @@ -532,7 +539,7 @@
<delete id="deleteAppById">
DELETE
FROM t_app
WHERE id = #{id}
WHERE id = #{id} AND tenant_id = #{tenantId}
</delete>

<!-- 根据主键id更新表t_app数据 -->
Expand All @@ -542,7 +549,7 @@
<include refid="AppSetColumns"/>
</set>
WHERE
id=#{id}
id = #{id} AND tenant_id = #{tenantId}
</update>

<!-- 新增表t_app数据 -->
Expand Down
Loading
Loading