应用分组优化

pull/43/head
Friday 2023-09-07 23:19:36 +00:00 committed by smallbun
parent 7943717b3a
commit dac0eb6342
16 changed files with 571 additions and 27 deletions

View File

@ -60,7 +60,6 @@ public abstract class AbstractApplicationService implements ApplicationService {
AppEntity appEntity = new AppEntity();
appEntity.setName(name);
appEntity.setIcon(icon);
appEntity.setGroupId(null == groupId ? 0L : groupId);
appEntity.setCode(RandomStringUtils.randomAlphanumeric(32).toLowerCase());
appEntity.setTemplate(getCode());
appEntity.setType(getType());

View File

@ -182,4 +182,18 @@ public class AppEventType {
public static Type DELETE_APP_GROUP = new Type("eiam:event:app_group:delete",
"删除应用分组", APP_GROUP_RESOURCE, List.of(UserType.ADMIN));
/**
*
*/
public static Type ADD_APP_GROUP_ASSOCIATION = new Type(
"eiam:event:add_app_group_association", "添加应用分组关联", APP_GROUP_RESOURCE,
List.of(UserType.ADMIN));
/**
*
*/
public static Type REMOVE_APP_GROUP_ASSOCIATION = new Type(
"eiam:event:remove_app_group_association", "移除应用分组关联", APP_GROUP_RESOURCE,
List.of(UserType.ADMIN));
}

View File

@ -503,7 +503,15 @@ public enum EventType {
/**
*
*/
DELETE_APP_GROUP(AppEventType.DELETE_APP_GROUP);
DELETE_APP_GROUP(AppEventType.DELETE_APP_GROUP),
/**
*
*/
ADD_APP_GROUP_ASSOCIATION(AppEventType.ADD_APP_GROUP_ASSOCIATION),
/**
*
*/
REMOVE_APP_GROUP_ASSOCIATION(AppEventType.REMOVE_APP_GROUP_ASSOCIATION);
/**
* code

View File

@ -100,12 +100,6 @@ public class AppEntity extends LogicDeleteEntity<Long> {
@Column(name = "icon_")
private String icon;
/**
* id
*/
@Column(name = "group_id")
private Long groupId;
/**
* SSO
*/

View File

@ -0,0 +1,63 @@
/*
* 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
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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.common.entity.app;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import cn.topiam.employee.support.repository.domain.LogicDeleteEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET;
import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023090622:03:21
*/
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Entity
@Table(name = "app_group_association")
@SQLDelete(sql = "update app_group_association set " + SOFT_DELETE_SET + " where id_ = ?")
@Where(clause = SOFT_DELETE_WHERE)
public class AppGroupAssociationEntity extends LogicDeleteEntity<Long> {
/**
* ID
*/
@Column(name = "group_id")
private Long groupId;
/**
* ID
*/
@Column(name = "app_id")
private Long appId;
}

View File

@ -0,0 +1,55 @@
/*
* 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
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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.common.entity.app.query;
import java.io.Serial;
import java.io.Serializable;
import org.springdoc.core.annotations.ParameterObject;
import lombok.Data;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2020/8/11 23:08
*/
@Data
@Schema(description = "查询应用组应用列表入参")
@ParameterObject
public class AppGroupAssociationListQuery implements Serializable {
@Serial
private static final long serialVersionUID = -7110595216804896858L;
/**
* ID
*/
@NotEmpty(message = "组ID不能为空")
@Parameter(description = "组ID")
private String id;
/**
*
*/
@Parameter(description = "应用名称")
private String appName;
}

View File

@ -0,0 +1,54 @@
/*
* 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
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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.common.repository.app;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity;
import cn.topiam.employee.support.repository.LogicDeleteRepository;
import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023090622:03:18
*/
@Repository
public interface AppGroupAssociationRepository extends
LogicDeleteRepository<AppGroupAssociationEntity, Long>,
QuerydslPredicateExecutor<AppGroupAssociationEntity>,
AppGroupAssociationRepositoryCustomized {
/**
* IDID
*
* @param groupId {@link String}
* @param appId {@link String}
*/
@Modifying
@Transactional(rollbackFor = Exception.class)
@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);
}

View File

@ -0,0 +1,41 @@
/*
* 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
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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.common.repository.app;
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.AppGroupAssociationListQuery;
/**
* @author TopIAM
* Created by support@topiam.cn on 2023/9/7 21:27
*/
public interface AppGroupAssociationRepositoryCustomized {
/**
*
*
* @param query {@link AppGroupAssociationListQuery}
* @param pageable {@link Pageable}
* @return {@link Page}
*/
Page<AppEntity> getAppGroupAssociationList(AppGroupAssociationListQuery query,
Pageable pageable);
}

View File

@ -0,0 +1,84 @@
/*
* 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
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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.common.repository.app.impl;
import java.util.List;
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.stereotype.Repository;
import cn.topiam.employee.common.entity.account.query.UserGroupMemberListQuery;
import cn.topiam.employee.common.entity.app.AppEntity;
import cn.topiam.employee.common.entity.app.query.AppGroupAssociationListQuery;
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepositoryCustomized;
import cn.topiam.employee.common.repository.app.impl.mapper.AppEntityMapper;
import lombok.AllArgsConstructor;
/**
* @author TopIAM
* Created by support@topiam.cn on 2023/9/7 21:27
*/
@Repository
@AllArgsConstructor
public class AppGroupAssociationRepositoryCustomizedImpl implements
AppGroupAssociationRepositoryCustomized {
/**
*
*
* @param query {@link UserGroupMemberListQuery}
* @param pageable {@link Pageable}
* @return {@link Page}
*/
@SuppressWarnings("DuplicatedCode")
@Override
public Page<AppEntity> getAppGroupAssociationList(AppGroupAssociationListQuery query,
Pageable pageable) {
//@formatter:off
StringBuilder builder = new StringBuilder("""
SELECT
app.*
FROM
app app LEFT JOIN app_group_association ass ON app.id_ = ass.app_id AND app.is_deleted = 0 AND ass.is_deleted = 0
WHERE ass.group_id = '%s'
""".formatted(query.getId()));
//应用名称
if (StringUtils.isNoneBlank(query.getAppName())) {
builder.append(" AND app.name_ like '%").append(query.getAppName()).append("%'");
}
builder.append(" ORDER BY `app`.create_time DESC");
//@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_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
}
private final JdbcTemplate jdbcTemplate;
}

View File

@ -79,6 +79,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
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'
@ -90,7 +91,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
}
//分组id
if (null!=groupId) {
builder.append(" AND app.group_id = ").append(groupId);
builder.append(" AND ass.group_id = ").append(groupId);
}
//@formatter:on
String sql = builder.toString();

View File

@ -53,12 +53,33 @@
</column>
<column name="remark_" remarks="备注" type="TEXT"/>
</createTable>
<!--应用表添加分组字段-->
<addColumn tableName="app">
<createTable remarks="应用组关联" tableName="app_group_association">
<column name="id_" remarks="主键ID" type="BIGINT">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="group_id" remarks="应用组ID" type="BIGINT">
<constraints nullable="false"/>
</column>
</addColumn>
<column name="app_id" remarks="应用ID" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="create_by" remarks="创建者" type="VARCHAR(64)">
<constraints nullable="false"/>
</column>
<column defaultValueComputed="CURRENT_TIMESTAMP" name="create_time" remarks="创建时间" type="datetime">
<constraints nullable="false"/>
</column>
<column name="update_by" remarks="修改者" type="VARCHAR(64)">
<constraints nullable="false"/>
</column>
<column defaultValueComputed="CURRENT_TIMESTAMP" name="update_time" remarks="修改时间" type="datetime">
<constraints nullable="false"/>
</column>
<column name="remark_" remarks="备注" type="TEXT"/>
<column name="is_deleted" remarks="删除标记" type="TINYINT(1)" defaultValueNumeric="0">
<constraints nullable="true"/>
</column>
</createTable>
<createTable remarks="应用权限资源" tableName="app_permission_resource">
<column name="id_" remarks="主键ID" type="BIGINT">
<constraints nullable="false" primaryKey="true"/>
@ -196,5 +217,10 @@
<constraints nullable="true"/>
</column>
</createTable>
<createIndex tableName="app_group_association" indexName="uk_app_group_association" unique="true">
<column name="group_id"/>
<column name="app_id"/>
<column name="is_deleted"/>
</createIndex>
</changeSet>
</databaseChangeLog>

View File

@ -22,11 +22,16 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.google.common.collect.Lists;
import cn.topiam.employee.audit.annotation.Audit;
import cn.topiam.employee.audit.event.type.EventType;
import cn.topiam.employee.common.entity.account.query.UserGroupMemberListQuery;
import cn.topiam.employee.common.entity.app.query.AppGroupAssociationListQuery;
import cn.topiam.employee.console.pojo.query.app.AppGroupQuery;
import cn.topiam.employee.console.pojo.result.app.AppGroupGetResult;
import cn.topiam.employee.console.pojo.result.app.AppGroupListResult;
import cn.topiam.employee.console.pojo.result.app.AppListResult;
import cn.topiam.employee.console.pojo.save.app.AppGroupCreateParam;
import cn.topiam.employee.console.pojo.update.app.AppGroupUpdateParam;
import cn.topiam.employee.console.service.app.AppGroupService;
@ -39,7 +44,9 @@ import cn.topiam.employee.support.result.ApiRestResult;
import lombok.AllArgsConstructor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotEmpty;
import static cn.topiam.employee.common.constant.AppConstants.APP_PATH;
/**
@ -169,6 +176,58 @@ public class AppGroupController {
return ApiRestResult.<Boolean> builder().result(result).build();
}
/**
*
*
* @param appIds {@link String}
* @return {@link Boolean}
*/
@Lock
@Preview
@Validated
@Operation(summary = "添加应用组关联")
@Audit(type = EventType.ADD_APP_GROUP_ASSOCIATION)
@PostMapping(value = "/add_association/{id}")
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
public ApiRestResult<Boolean> addAssociation(@PathVariable(value = "id") String id,
@Parameter(description = "应用ID") String[] appIds) {
return ApiRestResult.<Boolean> builder().result(appGroupService.addAssociation(id, appIds))
.build();
}
/**
*
*
* @param id {@link String}
* @return {@link Boolean}
*/
@Lock
@Preview
@Operation(summary = "移除应用组关联")
@Audit(type = EventType.REMOVE_APP_GROUP_ASSOCIATION)
@DeleteMapping(value = "/remove_association/{id}")
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
public ApiRestResult<Boolean> removeAssociation(@PathVariable(value = "id") String id,
@NotEmpty(message = "应用ID不能为空") @Parameter(description = "应用ID集合") String[] appIds) {
return ApiRestResult.<Boolean> builder()
.result(appGroupService.batchRemoveAssociation(id, Lists.newArrayList(appIds))).build();
}
/**
*
*
* @param query {@link UserGroupMemberListQuery}
* @return {@link Boolean}
*/
@Operation(summary = "获取应用组内应用")
@GetMapping(value = "/{id}/app_list")
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
public ApiRestResult<Page<AppListResult>> getAppGroupAssociationList(PageModel model,
AppGroupAssociationListQuery query) {
return ApiRestResult.<Page<AppListResult>> builder()
.result(appGroupService.getAppGroupAssociationList(model, query)).build();
}
/**
* AppGroupService
*/

View File

@ -17,9 +17,13 @@
*/
package cn.topiam.employee.console.service.app;
import java.util.List;
import cn.topiam.employee.common.entity.app.query.AppGroupAssociationListQuery;
import cn.topiam.employee.console.pojo.query.app.AppGroupQuery;
import cn.topiam.employee.console.pojo.result.app.AppGroupGetResult;
import cn.topiam.employee.console.pojo.result.app.AppGroupListResult;
import cn.topiam.employee.console.pojo.result.app.AppListResult;
import cn.topiam.employee.console.pojo.save.app.AppGroupCreateParam;
import cn.topiam.employee.console.pojo.update.app.AppGroupUpdateParam;
import cn.topiam.employee.support.repository.page.domain.Page;
@ -91,4 +95,32 @@ public interface AppGroupService {
* @return {@link Boolean}
*/
Boolean disableAppGroup(String id);
/**
*
*
* @param appIds {@link String}
* @param groupId {@link String}
* @return {@link Boolean}
*/
Boolean addAssociation(String groupId, String[] appIds);
/**
*
*
* @param id {@link String}
* @param appIds {@link String}
* @return {@link Boolean}
*/
Boolean batchRemoveAssociation(String id, List<String> appIds);
/**
*
*
* @param query {@link AppGroupAssociationListQuery}
* @param page {@link PageModel}
* @return {@link AppListResult}
*/
Page<AppListResult> getAppGroupAssociationList(PageModel page,
AppGroupAssociationListQuery query);
}

View File

@ -18,25 +18,36 @@
package cn.topiam.employee.console.service.app.impl;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.querydsl.QPageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Predicate;
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.AppGroupAssociationEntity;
import cn.topiam.employee.common.entity.app.AppGroupEntity;
import cn.topiam.employee.common.entity.app.QAppGroupEntity;
import cn.topiam.employee.common.entity.app.query.AppGroupAssociationListQuery;
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
import cn.topiam.employee.common.repository.app.AppGroupRepository;
import cn.topiam.employee.console.converter.app.AppConverter;
import cn.topiam.employee.console.converter.app.AppGroupConverter;
import cn.topiam.employee.console.pojo.query.app.AppGroupQuery;
import cn.topiam.employee.console.pojo.result.app.AppGroupGetResult;
import cn.topiam.employee.console.pojo.result.app.AppGroupListResult;
import cn.topiam.employee.console.pojo.result.app.AppListResult;
import cn.topiam.employee.console.pojo.save.app.AppGroupCreateParam;
import cn.topiam.employee.console.pojo.update.app.AppGroupUpdateParam;
import cn.topiam.employee.console.service.app.AppGroupService;
@ -93,7 +104,6 @@ public class AppGroupServiceImpl implements AppGroupService {
public Boolean createAppGroup(AppGroupCreateParam param) {
// TODO 创建后没有数据权限
AppGroupEntity entity = appGroupConverter.appGroupCreateParamConvertToEntity(param);
entity.setEnabled(true);
appGroupRepository.save(entity);
AuditContext.setTarget(
Target.builder().id(String.valueOf(entity.getId())).type(TargetType.APP_GROUP).build());
@ -194,13 +204,92 @@ public class AppGroupServiceImpl implements AppGroupService {
return optional.get();
}
/**
*
*
* @param appIds {@link String}
* @param groupId {@link String}
* @return {@link Boolean}
*/
@Override
public Boolean addAssociation(String groupId, String[] appIds) {
Optional<AppGroupEntity> optional = appGroupRepository.findById(Long.valueOf(groupId));
//用户组不存在
if (optional.isEmpty()) {
AuditContext.setContent("操作失败,应用组不存在");
log.warn(AuditContext.getContent());
throw new TopIamException(AuditContext.getContent());
}
List<AppGroupAssociationEntity> list = new ArrayList<>();
Lists.newArrayList(appIds).forEach(id -> {
AppGroupAssociationEntity member = new AppGroupAssociationEntity();
member.setGroupId(Long.valueOf(groupId));
member.setAppId(Long.valueOf(id));
list.add(member);
});
//添加
appGroupAssociationRepository.saveAll(list);
List<Target> targets = new ArrayList<>(Arrays.stream(appIds)
.map(i -> Target.builder().id(i).type(TargetType.APPLICATION).build()).toList());
targets.add(Target.builder().id(groupId).type(TargetType.APP_GROUP).build());
AuditContext.setTarget(targets);
return true;
}
/**
*
*
* @param appIds {@link String}
* @param id {@link String}
* @return {@link Boolean}
*/
@Override
public Boolean batchRemoveAssociation(String id, List<String> appIds) {
Optional<AppGroupEntity> optional = appGroupRepository.findById(Long.valueOf(id));
//用户组不存在
if (optional.isEmpty()) {
AuditContext.setContent("操作失败,应用组不存在");
log.warn(AuditContext.getContent());
throw new TopIamException(AuditContext.getContent());
}
appIds.forEach(userId -> appGroupAssociationRepository
.deleteByGroupIdAndAppId(Long.valueOf(id), Long.valueOf(userId)));
List<Target> targets = new ArrayList<>(appIds.stream()
.map(i -> Target.builder().id(i).type(TargetType.APPLICATION).build()).toList());
targets.add(Target.builder().id(id).type(TargetType.APP_GROUP).build());
AuditContext.setTarget(targets);
return true;
}
/**
*
*
* @param query {@link AppGroupAssociationListQuery}
* @return {@link AppListResult}
*/
@Override
public Page<AppListResult> getAppGroupAssociationList(PageModel model,
AppGroupAssociationListQuery query) {
org.springframework.data.domain.Page<AppEntity> page = appGroupAssociationRepository
.getAppGroupAssociationList(query,
PageRequest.of(model.getCurrent(), model.getPageSize()));
return appConverter.entityConvertToAppListResult(page);
}
/**
* AppGroupRepository
*/
private final AppGroupRepository appGroupRepository;
private final AppGroupRepository appGroupRepository;
/**
* AppGroupConverter
*/
private final AppGroupConverter appGroupConverter;
private final AppGroupConverter appGroupConverter;
private final AppConverter appConverter;
/**
* AppGroupAssociationRepository
*/
private final AppGroupAssociationRepository appGroupAssociationRepository;
}

View File

@ -25,8 +25,9 @@ import org.mapstruct.Mapper;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import cn.topiam.employee.common.entity.app.AppEntity;
import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity;
import cn.topiam.employee.common.entity.app.AppGroupEntity;
import cn.topiam.employee.common.entity.app.QAppGroupAssociationEntity;
import cn.topiam.employee.common.entity.app.QAppGroupEntity;
import cn.topiam.employee.portal.pojo.result.AppGroupListResult;
@ -53,20 +54,32 @@ public interface AppGroupConverter {
return predicate;
}
/**
* Predicate
*
* @return {@link Predicate}
*/
default Predicate queryAppGroupAssociationPredicate() {
QAppGroupAssociationEntity appGroupAssociation = QAppGroupAssociationEntity.appGroupAssociationEntity;
Predicate predicate = appGroupAssociation.deleted.eq(Boolean.FALSE);
//@formatter:on
return predicate;
}
/**
*
*
* @param list {@link AppGroupEntity}
* @param appList {@link AppEntity}
* @param list {@link AppGroupEntity}
* @param appGroupAssociationList {@link AppGroupAssociationEntity}
* @return {@link AppGroupListResult}
*/
default List<AppGroupListResult> entityConvertToAppGroupListResult(List<AppGroupEntity> list,
List<AppEntity> appList) {
List<AppGroupAssociationEntity> appGroupAssociationList) {
List<AppGroupListResult> results = new ArrayList<>();
for (AppGroupEntity entity : list) {
AppGroupListResult result = appGroupEntityConverterToResult(entity);
Long count = appList.stream().filter(t -> t.getGroupId().equals(entity.getId()))
.count();
Long count = appGroupAssociationList.stream()
.filter(t -> t.getGroupId().equals(entity.getId())).count();
result.setAppCount(Integer.valueOf(count.toString()));
results.add(result);
}

View File

@ -25,7 +25,9 @@ import org.springframework.stereotype.Service;
import com.querydsl.core.types.Predicate;
import cn.topiam.employee.common.entity.app.AppEntity;
import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity;
import cn.topiam.employee.common.entity.app.AppGroupEntity;
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
import cn.topiam.employee.common.repository.app.AppGroupRepository;
import cn.topiam.employee.common.repository.app.AppRepository;
import cn.topiam.employee.portal.converter.AppConverter;
@ -70,36 +72,46 @@ public class AppServiceImpl implements AppService {
@Override
public List<AppGroupListResult> getAppGroupList() {
Predicate predicate = appGroupConverter.queryPredicate();
List<AppEntity> appList = appRepository.getAppListByGroup();
Predicate appGroupAssociationPredicate = appGroupConverter
.queryAppGroupAssociationPredicate();
List<AppGroupAssociationEntity> appGroupAssociationList = (List<AppGroupAssociationEntity>) appGroupAssociationRepository
.findAll(appGroupAssociationPredicate);
//查询映射
List<AppGroupEntity> list = (List<AppGroupEntity>) appGroupRepository.findAll(predicate);
return appGroupConverter.entityConvertToAppGroupListResult(list, appList);
return appGroupConverter.entityConvertToAppGroupListResult(list, appGroupAssociationList);
}
/**
* AppRepository
*/
private final AppRepository appRepository;
private final AppRepository appRepository;
/**
* AppGroupRepository
*/
private final AppGroupRepository appGroupRepository;
private final AppGroupRepository appGroupRepository;
/**
* AppGroupAssociationRepository
*/
private final AppGroupAssociationRepository appGroupAssociationRepository;
/**
* AppConverter
*/
private final AppConverter appConverter;
private final AppConverter appConverter;
/**
* AppGroupConverter
*/
private final AppGroupConverter appGroupConverter;
private final AppGroupConverter appGroupConverter;
public AppServiceImpl(AppRepository appRepository, AppGroupRepository appGroupRepository,
AppGroupAssociationRepository appGroupAssociationRepository,
AppConverter appConverter, AppGroupConverter appGroupConverter) {
this.appRepository = appRepository;
this.appGroupRepository = appGroupRepository;
this.appGroupAssociationRepository = appGroupAssociationRepository;
this.appConverter = appConverter;
this.appGroupConverter = appGroupConverter;
}