mirror of https://gitee.com/topiam/eiam
应用列表根据分组id查询
parent
f55fbb3a16
commit
a5ca4e2dad
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* eiam-console - 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
|
||||
|
@ -15,7 +15,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package cn.topiam.employee.console.pojo.query.app;
|
||||
package cn.topiam.employee.common.entity.app.query;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
@ -50,4 +50,10 @@ public class AppQuery implements Serializable {
|
|||
*/
|
||||
@Parameter(description = "协议类型")
|
||||
private AppProtocol protocol;
|
||||
|
||||
/**
|
||||
* 应用组ID
|
||||
*/
|
||||
@Parameter(description = "应用组ID")
|
||||
private Long groupId;
|
||||
}
|
|
@ -51,4 +51,12 @@ public interface AppGroupAssociationRepository extends
|
|||
@Query(value = "UPDATE app_group_association SET " + SOFT_DELETE_SET
|
||||
+ " WHERE app_id = :appId and group_id = :groupId", nativeQuery = true)
|
||||
void deleteByGroupIdAndAppId(@Param("groupId") Long groupId, @Param("appId") Long appId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据应用ID删除关联信息
|
||||
*
|
||||
* @param appId {@link Long}
|
||||
*/
|
||||
void deleteByAppId(Long appId);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ 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;
|
||||
|
||||
/**
|
||||
* 应用 Repository Customized
|
||||
|
@ -42,4 +43,14 @@ public interface AppRepositoryCustomized {
|
|||
* @return {@link List}
|
||||
*/
|
||||
Page<AppEntity> getAppList(Long userId, String name, Long groupId, Pageable pageable);
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取应用列表
|
||||
*
|
||||
* @param appQuery {@link AppQuery}
|
||||
* @param pageable {@link Pageable}
|
||||
* @return {@link List}
|
||||
*/
|
||||
Page<AppEntity> getAppList(AppQuery appQuery, Pageable pageable);
|
||||
}
|
||||
|
|
|
@ -20,11 +20,13 @@ package cn.topiam.employee.common.repository.app.impl;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -33,6 +35,7 @@ import com.google.common.collect.Lists;
|
|||
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.repository.account.OrganizationMemberRepository;
|
||||
import cn.topiam.employee.common.repository.account.UserGroupMemberRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppRepositoryCustomized;
|
||||
|
@ -107,6 +110,54 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
|
|||
return new PageImpl<>(list, pageable, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用列表
|
||||
*
|
||||
* @param appQuery {@link AppQuery}
|
||||
* @param pageable {@link Pageable}
|
||||
* @return {@link List}
|
||||
*/
|
||||
public Page<AppEntity> getAppList(AppQuery appQuery, Pageable pageable) {
|
||||
//@formatter:off
|
||||
StringBuilder builder = new StringBuilder("""
|
||||
SELECT DISTINCT
|
||||
app.*
|
||||
FROM
|
||||
app
|
||||
INNER JOIN app_group_association `group` ON app.id_ = `group`.app_id
|
||||
""");
|
||||
|
||||
//应用名称
|
||||
if (StringUtils.isNoneBlank(appQuery.getName())) {
|
||||
builder.append(" AND app.name_ like '%").append(appQuery.getName()).append("%'");
|
||||
}
|
||||
//协议类型
|
||||
if (Objects.nonNull(appQuery.getProtocol())) {
|
||||
builder.append(" AND app.protocol_ = ").append(appQuery.getProtocol().getCode());
|
||||
}
|
||||
//应用组ID
|
||||
if(Objects.nonNull(appQuery.getGroupId())){
|
||||
builder.append(" AND group.group_id = ").append(appQuery.getGroupId());
|
||||
}
|
||||
|
||||
//@formatter:on
|
||||
String sql = builder.toString();
|
||||
List<AppEntity> list = jdbcTemplate.query(
|
||||
builder.append(" LIMIT ").append(pageable.getPageNumber() * pageable.getPageSize())
|
||||
.append(",").append(pageable.getPageSize()).toString(),
|
||||
new AppEntityMapper());
|
||||
//@formatter:off
|
||||
String countSql = "SELECT count(*) FROM (" + sql + ") app_account_";
|
||||
//@formatter:on
|
||||
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
|
||||
return new PageImpl<>(list, pageable, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* JdbcTemplate
|
||||
*/
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
/**
|
||||
* NamedParameterJdbcTemplate
|
||||
*/
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import cn.topiam.employee.audit.annotation.Audit;
|
||||
import cn.topiam.employee.audit.event.type.EventType;
|
||||
import cn.topiam.employee.console.pojo.query.app.AppQuery;
|
||||
import cn.topiam.employee.common.entity.app.query.AppQuery;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppCreateResult;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppGetResult;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppListResult;
|
||||
|
|
|
@ -32,7 +32,7 @@ import cn.topiam.employee.application.ApplicationService;
|
|||
import cn.topiam.employee.application.ApplicationServiceLoader;
|
||||
import cn.topiam.employee.common.entity.app.AppEntity;
|
||||
import cn.topiam.employee.common.entity.app.QAppEntity;
|
||||
import cn.topiam.employee.console.pojo.query.app.AppQuery;
|
||||
import cn.topiam.employee.common.entity.app.query.AppQuery;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppGetResult;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppListResult;
|
||||
import cn.topiam.employee.console.pojo.update.app.AppUpdateParam;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package cn.topiam.employee.console.pojo.update.app;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -58,4 +59,10 @@ public class AppUpdateParam implements Serializable {
|
|||
*/
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 应用分组id
|
||||
*/
|
||||
@Schema(description = "应用分组")
|
||||
private List<String> groupIds;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package cn.topiam.employee.console.service.app;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import cn.topiam.employee.console.pojo.query.app.AppQuery;
|
||||
import cn.topiam.employee.common.entity.app.query.AppQuery;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppCreateResult;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppGetResult;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppListResult;
|
||||
|
|
|
@ -17,17 +17,17 @@
|
|||
*/
|
||||
package cn.topiam.employee.console.service.app.impl;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.querydsl.QPageRequest;
|
||||
import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity;
|
||||
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
import cn.topiam.employee.application.ApplicationService;
|
||||
import cn.topiam.employee.application.ApplicationServiceLoader;
|
||||
import cn.topiam.employee.application.exception.AppNotExistException;
|
||||
|
@ -35,10 +35,9 @@ import cn.topiam.employee.audit.context.AuditContext;
|
|||
import cn.topiam.employee.audit.entity.Target;
|
||||
import cn.topiam.employee.audit.enums.TargetType;
|
||||
import cn.topiam.employee.common.entity.app.AppEntity;
|
||||
import cn.topiam.employee.common.entity.app.QAppEntity;
|
||||
import cn.topiam.employee.common.entity.app.query.AppQuery;
|
||||
import cn.topiam.employee.common.repository.app.AppRepository;
|
||||
import cn.topiam.employee.console.converter.app.AppConverter;
|
||||
import cn.topiam.employee.console.pojo.query.app.AppQuery;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppCreateResult;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppGetResult;
|
||||
import cn.topiam.employee.console.pojo.result.app.AppListResult;
|
||||
|
@ -53,6 +52,7 @@ import cn.topiam.employee.support.util.BeanUtils;
|
|||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static cn.topiam.employee.support.repository.domain.BaseEntity.LAST_MODIFIED_BY;
|
||||
import static cn.topiam.employee.support.repository.domain.BaseEntity.LAST_MODIFIED_TIME;
|
||||
|
||||
|
@ -76,15 +76,9 @@ public class AppServiceImpl implements AppService {
|
|||
*/
|
||||
@Override
|
||||
public Page<AppListResult> getAppList(PageModel pageModel, AppQuery query) {
|
||||
//查询条件
|
||||
Predicate predicate = appConverter.queryAppListParamConvertToPredicate(query);
|
||||
OrderSpecifier<LocalDateTime> desc = QAppEntity.appEntity.updateTime.desc();
|
||||
//分页条件
|
||||
QPageRequest request = QPageRequest.of(pageModel.getCurrent(), pageModel.getPageSize(),
|
||||
desc);
|
||||
//查询映射
|
||||
org.springframework.data.domain.Page<AppEntity> list = appRepository.findAll(predicate,
|
||||
request);
|
||||
org.springframework.data.domain.Page<AppEntity> list = appRepository.getAppList(query,
|
||||
PageRequest.of(pageModel.getCurrent(), pageModel.getPageSize()));
|
||||
return appConverter.entityConvertToAppListResult(list);
|
||||
}
|
||||
|
||||
|
@ -98,9 +92,9 @@ public class AppServiceImpl implements AppService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public AppCreateResult createApp(AppCreateParam param) {
|
||||
ApplicationService applicationService = applicationServiceLoader
|
||||
.getApplicationService(param.getTemplate());
|
||||
.getApplicationService(param.getTemplate());
|
||||
String appId = applicationService.create(param.getName(), param.getIcon(),
|
||||
param.getRemark(), param.getGroupIds());
|
||||
param.getRemark(), param.getGroupIds());
|
||||
AuditContext.setTarget(Target.builder().id(appId).type(TargetType.APPLICATION).build());
|
||||
return new AppCreateResult(appId);
|
||||
}
|
||||
|
@ -112,13 +106,23 @@ public class AppServiceImpl implements AppService {
|
|||
* @return {@link Boolean}
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateApp(AppUpdateParam param) {
|
||||
AppEntity app = appRequireNonNull(param.getId());
|
||||
AppEntity entity = appConverter.appUpdateParamConverterToEntity(param);
|
||||
BeanUtils.merge(entity, app, LAST_MODIFIED_TIME, LAST_MODIFIED_BY);
|
||||
appRepository.save(app);
|
||||
appGroupAssociationRepository.deleteByAppId(app.getId());
|
||||
List<AppGroupAssociationEntity> list = new ArrayList<>();
|
||||
for (String id : param.getGroupIds()) {
|
||||
AppGroupAssociationEntity appGroupAssociationEntity = new AppGroupAssociationEntity();
|
||||
appGroupAssociationEntity.setGroupId(Long.valueOf(id));
|
||||
appGroupAssociationEntity.setAppId(app.getId());
|
||||
list.add(appGroupAssociationEntity);
|
||||
}
|
||||
appGroupAssociationRepository.saveAll(list);
|
||||
AuditContext.setTarget(
|
||||
Target.builder().id(param.getId().toString()).type(TargetType.APPLICATION).build());
|
||||
Target.builder().id(param.getId().toString()).type(TargetType.APPLICATION).build());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -134,7 +138,7 @@ public class AppServiceImpl implements AppService {
|
|||
AppEntity app = appRequireNonNull(id);
|
||||
applicationServiceLoader.getApplicationService(app.getTemplate()).delete(id.toString());
|
||||
AuditContext
|
||||
.setTarget(Target.builder().id(id.toString()).type(TargetType.APPLICATION).build());
|
||||
.setTarget(Target.builder().id(id.toString()).type(TargetType.APPLICATION).build());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -192,10 +196,10 @@ public class AppServiceImpl implements AppService {
|
|||
@Override
|
||||
public Boolean saveAppConfig(AppSaveConfigParam param) {
|
||||
ApplicationService applicationService = applicationServiceLoader
|
||||
.getApplicationService(param.getTemplate());
|
||||
.getApplicationService(param.getTemplate());
|
||||
applicationService.saveConfig(param.getId(), param.getConfig());
|
||||
AuditContext
|
||||
.setTarget(Target.builder().id(param.getId()).type(TargetType.APPLICATION).build());
|
||||
.setTarget(Target.builder().id(param.getId()).type(TargetType.APPLICATION).build());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -210,7 +214,7 @@ public class AppServiceImpl implements AppService {
|
|||
Optional<AppEntity> optional = appRepository.findById(Long.valueOf(appId));
|
||||
if (optional.isPresent()) {
|
||||
ApplicationService applicationService = applicationServiceLoader
|
||||
.getApplicationService(optional.get().getTemplate());
|
||||
.getApplicationService(optional.get().getTemplate());
|
||||
return applicationService.getConfig(appId);
|
||||
}
|
||||
throw new AppNotExistException();
|
||||
|
@ -240,24 +244,15 @@ public class AppServiceImpl implements AppService {
|
|||
/**
|
||||
* ApplicationRepository
|
||||
*/
|
||||
private final AppRepository appRepository;
|
||||
|
||||
// /**
|
||||
// * 应用证书
|
||||
// */
|
||||
// private final AppCertRepository appCertRepository;
|
||||
//
|
||||
// /**
|
||||
// * 应用账户
|
||||
// */
|
||||
// private final AppAccountRepository appAccountRepository;
|
||||
// /**
|
||||
// * 应用策略
|
||||
// */
|
||||
// private final AppAccessPolicyRepository appAccessPolicyRepository;
|
||||
private final AppRepository appRepository;
|
||||
|
||||
/**
|
||||
* ApplicationConverter
|
||||
*/
|
||||
private final AppConverter appConverter;
|
||||
private final AppConverter appConverter;
|
||||
|
||||
/**
|
||||
* AppGroupAssociationRepositorys
|
||||
*/
|
||||
private final AppGroupAssociationRepository appGroupAssociationRepository;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue