mirror of https://gitee.com/topiam/eiam
⚡ 优化代码
parent
9a5c6d68d6
commit
5f281fa9a4
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* eiam-portal - Employee Identity and Access Management
|
||||
* eiam-common - Employee Identity and Access Management
|
||||
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -20,11 +20,11 @@ package cn.topiam.employee.common.entity.app.query;
|
|||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package cn.topiam.employee.common.repository.account.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
@ -105,7 +106,7 @@ public class UserGroupMemberRepositoryCustomizedImpl implements
|
|||
String countSql = "SELECT count(*) FROM (" + sql + ") user_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
|
|
@ -129,7 +129,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized {
|
|||
String countSql = "SELECT count(*) FROM (" + sql + ") user_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,7 +203,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized {
|
|||
String countSql = "SELECT COUNT(*) FROM(" + sql + ") user_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,12 +19,12 @@ package cn.topiam.employee.common.repository.app;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import cn.topiam.employee.common.entity.app.AppEntity;
|
||||
import cn.topiam.employee.common.entity.app.query.AppQuery;
|
||||
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
|
||||
|
||||
/**
|
||||
* 应用 Repository Customized
|
||||
|
|
|
@ -133,7 +133,7 @@ public class AppAccessPolicyRepositoryCustomizedImpl implements
|
|||
String countSql = "SELECT count(*) FROM (" + sql + ") app_access_policy_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package cn.topiam.employee.common.repository.app.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
@ -106,7 +107,7 @@ public class AppAccountRepositoryCustomizedImpl implements AppAccountRepositoryC
|
|||
String countSql = "SELECT count(*) FROM (" + sql + ") app_account_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package cn.topiam.employee.common.repository.app.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
@ -77,7 +78,7 @@ public class AppGroupAssociationRepositoryCustomizedImpl implements
|
|||
String countSql = "SELECT count(*) FROM (" + sql + ") app_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package cn.topiam.employee.common.repository.app.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -44,15 +45,38 @@ import lombok.AllArgsConstructor;
|
|||
public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCustomized {
|
||||
|
||||
/**
|
||||
* 获取应用组应用列表
|
||||
* 获取应用组应用列表(分页)
|
||||
*
|
||||
* @param query {@link UserGroupMemberListQuery}
|
||||
* @param pageable {@link Pageable}
|
||||
* @return {@link Page}
|
||||
*/
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Override
|
||||
public Page<AppGroupPO> getAppGroupList(AppGroupQuery query, Pageable pageable) {
|
||||
StringBuilder builder = getBaseAppGroupListSql(query);
|
||||
String sql = getBaseAppGroupListSql(query).toString();
|
||||
List<AppGroupPO> list = jdbcTemplate.query(
|
||||
builder.append(" LIMIT ").append(pageable.getPageNumber() * pageable.getPageSize())
|
||||
.append(",").append(pageable.getPageSize()).toString(),
|
||||
new AppGroupPoMapper());
|
||||
//@formatter:off
|
||||
String countSql = "SELECT count(*) FROM (" + sql + ") app_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询应用组列表(不分页)
|
||||
*
|
||||
* @return {@link List}
|
||||
*/
|
||||
@Override
|
||||
public List<AppGroupPO> getAppGroupList(AppGroupQuery query) {
|
||||
return jdbcTemplate.query(getBaseAppGroupListSql(query).toString(), new AppGroupPoMapper());
|
||||
}
|
||||
|
||||
private StringBuilder getBaseAppGroupListSql(AppGroupQuery query) {
|
||||
//@formatter:off
|
||||
StringBuilder builder = new StringBuilder("SELECT `group`.id_, `group`.name_, `group`.code_, `group`.type_, `group`.create_time, `group`.remark_, IFNULL( ass.app_count, 0) AS app_count FROM app_group `group` LEFT JOIN(SELECT aga.group_id, COUNT(*) AS `app_count` FROM app_group_association aga INNER JOIN app ON aga.app_id = app.id_ AND app.is_deleted = 0 GROUP BY aga.group_id ) ass ON `group`.id_ = ass.group_id WHERE is_deleted = '0'");
|
||||
//分组名称
|
||||
|
@ -69,43 +93,7 @@ public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCusto
|
|||
}
|
||||
builder.append(" ORDER BY `group`.create_time DESC");
|
||||
//@formatter:on
|
||||
String sql = builder.toString();
|
||||
List<AppGroupPO> list = jdbcTemplate.query(
|
||||
builder.append(" LIMIT ").append(pageable.getPageNumber() * pageable.getPageSize())
|
||||
.append(",").append(pageable.getPageSize()).toString(),
|
||||
new AppGroupPoMapper());
|
||||
//@formatter:off
|
||||
String countSql = "SELECT count(*) FROM (" + sql + ") app_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询应用组列表
|
||||
*
|
||||
* @return {@link List}
|
||||
*/
|
||||
@Override
|
||||
public List<AppGroupPO> getAppGroupList(AppGroupQuery query) {
|
||||
//@formatter:off
|
||||
StringBuilder builder = new StringBuilder("SELECT `group`.id_, `group`.name_, `group`.code_, `group`.type_, `group`.create_time, `group`.remark_, IFNULL( ass.app_count, 0) AS app_count FROM app_group `group` LEFT JOIN(SELECT aga.group_id, COUNT(*) AS `app_count` FROM app_group_association aga WHERE aga.is_deleted = '0' GROUP BY aga.group_id ) ass ON `group`.id_ = ass.group_id WHERE is_deleted = '0'");
|
||||
//分组名称
|
||||
if (StringUtils.isNoneBlank(query.getName())) {
|
||||
builder.append(" AND `group`.name_ like '%").append(query.getName()).append("%'");
|
||||
}
|
||||
//分组编码
|
||||
if (StringUtils.isNoneBlank(query.getCode())) {
|
||||
builder.append(" AND `group`.code_ like '%").append(query.getCode()).append("%'");
|
||||
}
|
||||
//分组类型
|
||||
if (ObjectUtils.isNotEmpty(query.getType())) {
|
||||
builder.append(" AND `group`.type_ like '%").append(query.getType().getCode()).append("%'");
|
||||
}
|
||||
builder.append(" ORDER BY `group`.create_time DESC");
|
||||
//@formatter:on
|
||||
List<AppGroupPO> list = jdbcTemplate.query(builder.toString(), new AppGroupPoMapper());
|
||||
return list;
|
||||
return builder;
|
||||
}
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
|
@ -37,12 +36,14 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity;
|
|||
import cn.topiam.employee.common.entity.account.UserGroupMemberEntity;
|
||||
import cn.topiam.employee.common.entity.app.AppEntity;
|
||||
import cn.topiam.employee.common.entity.app.query.AppQuery;
|
||||
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
|
||||
import cn.topiam.employee.common.repository.account.OrganizationMemberRepository;
|
||||
import cn.topiam.employee.common.repository.account.UserGroupMemberRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppRepositoryCustomized;
|
||||
import cn.topiam.employee.common.repository.app.impl.mapper.AppEntityMapper;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import static cn.topiam.employee.common.enums.app.AuthorizationType.ALL_ACCESS;
|
||||
|
||||
/**
|
||||
* App Repository Customized
|
||||
|
@ -58,8 +59,8 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
|
|||
* 获取我的应用列表
|
||||
*
|
||||
* @param userId {@link Long}
|
||||
* @param query {@link query}
|
||||
* @param pageable {@link String}
|
||||
* @param query {@link GetAppListQuery}
|
||||
* @param pageable {@link Pageable}
|
||||
* @return {@link List}
|
||||
*/
|
||||
@Override
|
||||
|
@ -77,18 +78,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
|
|||
Map<String, Object> paramMap = new HashMap<>(16);
|
||||
paramMap.put("subjectIds", paramList);
|
||||
//@formatter:off
|
||||
StringBuilder builder = new StringBuilder("""
|
||||
SELECT DISTINCT
|
||||
app.*
|
||||
FROM
|
||||
app
|
||||
LEFT JOIN app_access_policy app_acce ON app.id_ = app_acce.app_id AND app_acce.is_deleted = '0'
|
||||
LEFT JOIN app_group_association ass ON app.id_ = ass.app_id AND ass.is_deleted = '0'
|
||||
WHERE
|
||||
app.is_enabled = 1
|
||||
AND app.is_deleted = '0'
|
||||
AND (app_acce.subject_id IN (:subjectIds) OR app.authorization_type = 'all_access')
|
||||
""");
|
||||
StringBuilder builder = new StringBuilder("SELECT DISTINCT app.* FROM app LEFT JOIN app_access_policy app_acce ON app.id_ = app_acce.app_id AND app_acce.is_deleted = '0' LEFT JOIN app_group_association ass ON app.id_ = ass.app_id AND ass.is_deleted = '0' WHERE app.is_enabled = 1 AND app.is_deleted = '0' AND (app_acce.subject_id IN (:subjectIds) OR app.authorization_type = '"+ALL_ACCESS.getCode()+"')");
|
||||
//用户名
|
||||
if (StringUtils.isNoneBlank(query.getName())) {
|
||||
builder.append(" AND app.name_ like '%").append(query.getName()).append("%'");
|
||||
|
@ -108,7 +98,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
|
|||
//@formatter:on
|
||||
Integer count = namedParameterJdbcTemplate.queryForObject(countSql, paramMap,
|
||||
Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,6 +108,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
|
|||
* @param pageable {@link Pageable}
|
||||
* @return {@link List}
|
||||
*/
|
||||
@Override
|
||||
public Page<AppEntity> getAppList(AppQuery appQuery, Pageable pageable) {
|
||||
//@formatter:off
|
||||
StringBuilder builder = new StringBuilder("SELECT DISTINCT app.* FROM app LEFT JOIN app_group_association `group` ON app.id_ = `group`.app_id WHERE app.is_deleted =0");
|
||||
|
@ -145,7 +136,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
|
|||
String countSql = "SELECT count(*) FROM (" + sql + ") app_account_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
"@ant-design/maps": "^1.0.7",
|
||||
"@ant-design/pro-components": "^2.6.24",
|
||||
"ahooks": "^3.7.8",
|
||||
"antd": "^5.9.2",
|
||||
"antd": "^5.9.3",
|
||||
"antd-img-crop": "^4.13.0",
|
||||
"antd-style": "^3.5.0",
|
||||
"classnames": "^2.3.2",
|
||||
|
|
|
@ -25,11 +25,11 @@ import org.springframework.stereotype.Service;
|
|||
import cn.topiam.employee.common.entity.app.AppEntity;
|
||||
import cn.topiam.employee.common.entity.app.po.AppGroupPO;
|
||||
import cn.topiam.employee.common.entity.app.query.AppGroupQuery;
|
||||
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
|
||||
import cn.topiam.employee.common.repository.app.AppGroupRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppRepository;
|
||||
import cn.topiam.employee.portal.converter.AppConverter;
|
||||
import cn.topiam.employee.portal.converter.AppGroupConverter;
|
||||
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
|
||||
import cn.topiam.employee.portal.pojo.result.AppGroupListResult;
|
||||
import cn.topiam.employee.portal.pojo.result.GetAppListResult;
|
||||
import cn.topiam.employee.portal.service.AppService;
|
||||
|
@ -63,13 +63,12 @@ public class AppServiceImpl implements AppService {
|
|||
/**
|
||||
* 查询应用分组
|
||||
*
|
||||
* @param appGroupQuery {@link AppGroupQuery}
|
||||
* @param query {@link AppGroupQuery}
|
||||
* @return {@link AppGroupListResult}
|
||||
*/
|
||||
@Override
|
||||
public List<AppGroupListResult> getAppGroupList(AppGroupQuery appGroupQuery) {
|
||||
//查询映射
|
||||
List<AppGroupPO> list = appGroupRepository.getAppGroupList(appGroupQuery);
|
||||
public List<AppGroupListResult> getAppGroupList(AppGroupQuery query) {
|
||||
List<AppGroupPO> list = appGroupRepository.getAppGroupList(query);
|
||||
return appGroupConverter.entityConvertToAppGroupListResult(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
"@ant-design/maps": "^1.0.7",
|
||||
"@ant-design/pro-components": "^2.6.24",
|
||||
"ahooks": "^3.7.8",
|
||||
"antd": "^5.9.2",
|
||||
"antd": "^5.9.3",
|
||||
"antd-img-crop": "^4.13.0",
|
||||
"antd-style": "^3.5.0",
|
||||
"classnames": "^2.3.2",
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
export default {
|
||||
'pages.application.search.name': '应用名称',
|
||||
'pages.application.group_all': '全部',
|
||||
'pages.application.tab.list': '应用列表',
|
||||
'pages.application.tab.account': '应用账号',
|
||||
'pages.application.init.warning': '仅允许应用发起',
|
||||
|
|
Loading…
Reference in New Issue