From e976af0188c1d8d08427367ed83d4bc3bf6570da Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Fri, 8 Sep 2023 23:19:01 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../audit/event/type/AppEventType.java | 7 ------- .../employee/audit/event/type/EventType.java | 4 ---- .../controller/app/AppGroupController.java | 19 ------------------- .../converter/app/AppGroupConverter.java | 4 ++-- .../pojo/result/app/AppGroupGetResult.java | 6 ------ .../pojo/result/app/AppGroupListResult.java | 14 ++++---------- .../pojo/save/app/AppGroupCreateParam.java | 7 +++++++ .../pojo/update/app/AppGroupUpdateParam.java | 8 ++++---- .../service/app/impl/AppGroupServiceImpl.java | 15 +++++++++++---- 9 files changed, 28 insertions(+), 56 deletions(-) diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/type/AppEventType.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/type/AppEventType.java index e0c83e44..547d2fdf 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/type/AppEventType.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/type/AppEventType.java @@ -182,13 +182,6 @@ 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)); - /** * 移除应用分组关联 */ diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/type/EventType.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/type/EventType.java index a68bc15a..ea823c25 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/type/EventType.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/type/EventType.java @@ -504,10 +504,6 @@ public enum EventType { * 删除应用分组 */ DELETE_APP_GROUP(AppEventType.DELETE_APP_GROUP), - /** - * 添加应用组关联 - */ - ADD_APP_GROUP_ASSOCIATION(AppEventType.ADD_APP_GROUP_ASSOCIATION), /** * 移除应用组关联 */ diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppGroupController.java b/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppGroupController.java index a82533b1..4969c3fd 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppGroupController.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppGroupController.java @@ -176,25 +176,6 @@ 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(); - } - /** * 移除分组用户 * diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppGroupConverter.java b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppGroupConverter.java index 7385c535..3315f0f4 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppGroupConverter.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppGroupConverter.java @@ -73,7 +73,7 @@ public interface AppGroupConverter { * @param appGroupPo {@link AppGroupPO} * @return {@link AppGroupListResult} */ - AppGroupListResult entityConvertToAppGroupListResult(AppGroupPO appGroupPo); + AppGroupListResult entityConvertToAppGroupListResult(AppGroupPO appGroupPo); /** * 实体转分组返回 @@ -81,7 +81,7 @@ public interface AppGroupConverter { * @param entity {@link AppGroupEntity} * @return {@link AppGroupGetResult} */ - AppGroupGetResult entityConvertToAppGroupResult(AppGroupEntity entity); + AppGroupGetResult entityConvertToAppGroupResult(AppGroupEntity entity); /** * 将分组修改对象转换为entity diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupGetResult.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupGetResult.java index df29ba2f..d90f56cf 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupGetResult.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupGetResult.java @@ -51,12 +51,6 @@ public class AppGroupGetResult implements Serializable { @Parameter(description = "分组编码") private String code; - /** - * 是否启用 - */ - @Parameter(description = "分组是否启用") - private Boolean enabled; - /** * 创建时间 */ diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupListResult.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupListResult.java index e32cf3a6..cc845b88 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupListResult.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupListResult.java @@ -39,25 +39,19 @@ public class AppGroupListResult implements Serializable { * ID */ @Parameter(description = "ID") - private String id; + private String id; /** * 分组名称 */ @Parameter(description = "分组名称") - private String name; + private String name; /** * 分组编码 */ @Parameter(description = "分组编码") - private String code; - - /** - * 是否启用 - */ - @Parameter(description = "是否启用") - private Boolean enabled; + private String code; /** * 创建时间 @@ -69,6 +63,6 @@ public class AppGroupListResult implements Serializable { * 备注 */ @Parameter(description = "备注") - private String remark; + private String remark; } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java index 580f59d2..4e94a894 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java @@ -21,6 +21,7 @@ import java.io.Serializable; import lombok.Data; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; @@ -54,4 +55,10 @@ public class AppGroupCreateParam implements Serializable { @Schema(description = "备注") private String remark; + /** + * 应用分组ID + */ + @Parameter(description = "应用分组ID") + private String[] groupId; + } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/update/app/AppGroupUpdateParam.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/update/app/AppGroupUpdateParam.java index 903d74f1..ec5282b8 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/update/app/AppGroupUpdateParam.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/update/app/AppGroupUpdateParam.java @@ -39,23 +39,23 @@ public class AppGroupUpdateParam implements Serializable { */ @Schema(description = "分组id") @NotNull(message = "ID不能为空") - private Long id; + private Long id; /** * 分组名称 */ @Schema(description = "分组名称") - private String name; + private String name; /** * 分组排序 */ @Schema(description = "分组编码") - private String code; + private String code; /** * 备注 */ @Schema(description = "备注") - private String remark; + private String remark; } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java index 338be68b..d614399e 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java @@ -78,8 +78,8 @@ public class AppGroupServiceImpl implements AppGroupService { @Override public Page<AppGroupListResult> getAppGroupList(PageModel pageModel, AppGroupQuery query) { //查询映射 - org.springframework.data.domain.Page<AppGroupPO> list = appGroupRepository - .getAppGroupList(query, PageRequest.of(pageModel.getCurrent(), pageModel.getPageSize())); + org.springframework.data.domain.Page<AppGroupPO> list = appGroupRepository.getAppGroupList( + query, PageRequest.of(pageModel.getCurrent(), pageModel.getPageSize())); return appGroupConverter.entityConvertToAppGroupListResult(list); } @@ -92,9 +92,16 @@ public class AppGroupServiceImpl implements AppGroupService { @Override @Transactional(rollbackFor = Exception.class) public Boolean createAppGroup(AppGroupCreateParam param) { - // TODO 创建后没有数据权限 AppGroupEntity entity = appGroupConverter.appGroupCreateParamConvertToEntity(param); appGroupRepository.save(entity); + List<AppGroupAssociationEntity> list = new ArrayList<>(); + for (String groupId : param.getGroupId()) { + AppGroupAssociationEntity appGroupAssociationEntity = new AppGroupAssociationEntity(); + appGroupAssociationEntity.setGroupId(Long.valueOf(groupId)); + appGroupAssociationEntity.setAppId(entity.getId()); + list.add(appGroupAssociationEntity); + } + appGroupAssociationRepository.saveAll(list); AuditContext.setTarget( Target.builder().id(String.valueOf(entity.getId())).type(TargetType.APP_GROUP).build()); return true; @@ -230,7 +237,7 @@ public class AppGroupServiceImpl implements AppGroupService { * 批量移除应用 * * @param appIds {@link String} - * @param id {@link String} + * @param id {@link String} * @return {@link Boolean} */ @Override From 7a5bd096ddd222ce84b5df82cbb078ec40af132a Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Sat, 9 Sep 2023 00:11:54 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractApplicationService.java | 31 ++++++++++++++++--- ...AbstractCertificateApplicationService.java | 8 ++--- .../application/ApplicationService.java | 4 +-- .../form/AbstractFormApplicationService.java | 4 ++- .../FormStandardApplicationServiceImpl.java | 7 +++-- ...tractJwtCertificateApplicationService.java | 4 ++- ...dardCertificateApplicationServiceImpl.java | 5 +-- ...ractOidcCertificateApplicationService.java | 4 ++- ...dardCertificateApplicationServiceImpl.java | 5 +-- .../console/pojo/save/app/AppCreateParam.java | 4 +-- .../pojo/save/app/AppGroupCreateParam.java | 7 ----- .../service/app/impl/AppGroupServiceImpl.java | 8 ----- 12 files changed, 53 insertions(+), 38 deletions(-) diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java index afdba1d3..d3fb16df 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java +++ b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java @@ -17,6 +17,8 @@ */ package cn.topiam.employee.application; +import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity; +import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.util.AlternativeJdkIdGenerator; import org.springframework.util.IdGenerator; @@ -33,6 +35,9 @@ import cn.topiam.employee.common.repository.app.AppRepository; import lombok.extern.slf4j.Slf4j; +import java.util.ArrayList; +import java.util.List; + /** * AbstractApplicationService * @@ -55,7 +60,7 @@ public abstract class AbstractApplicationService implements ApplicationService { } @Override - public AppEntity createApp(String name, String icon, String remark, Long groupId, + public AppEntity createApp(String name, String icon, String remark, Long[] groupId, InitLoginType initLoginType, AuthorizationType authorizationType) { AppEntity appEntity = new AppEntity(); appEntity.setName(name); @@ -70,28 +75,44 @@ public abstract class AbstractApplicationService implements ApplicationService { appEntity.setInitLoginType(initLoginType); appEntity.setAuthorizationType(authorizationType); appEntity.setRemark(remark); - return appRepository.save(appEntity); + appRepository.save(appEntity); + List<AppGroupAssociationEntity> list = new ArrayList<>(); + for (Long id : groupId) { + AppGroupAssociationEntity appGroupAssociationEntity = new AppGroupAssociationEntity(); + appGroupAssociationEntity.setGroupId(id); + appGroupAssociationEntity.setAppId(appEntity.getId()); + list.add(appGroupAssociationEntity); + } + appGroupAssociationRepository.saveAll(list); + return appEntity; } /** * AppAccountRepository */ - protected final AppAccountRepository appAccountRepository; + protected final AppAccountRepository appAccountRepository; + + /** + * AppGroupAssociationRepository + */ + protected final AppGroupAssociationRepository appGroupAssociationRepository; /** * ApplicationRepository */ - protected final AppRepository appRepository; + protected final AppRepository appRepository; /** * IdGenerator */ - protected final IdGenerator idGenerator; + protected final IdGenerator idGenerator; protected AbstractApplicationService(AppAccountRepository appAccountRepository, + AppGroupAssociationRepository appGroupAssociationRepository, AppRepository appRepository) { this.appAccountRepository = appAccountRepository; this.appRepository = appRepository; + this.appGroupAssociationRepository = appGroupAssociationRepository; this.idGenerator = new AlternativeJdkIdGenerator(); } } diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractCertificateApplicationService.java b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractCertificateApplicationService.java index 19883897..6014acdb 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractCertificateApplicationService.java +++ b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractCertificateApplicationService.java @@ -22,6 +22,7 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; +import cn.topiam.employee.common.repository.app.*; import org.bouncycastle.asn1.x500.X500Name; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,10 +33,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import cn.topiam.employee.common.entity.app.AppCertEntity; import cn.topiam.employee.common.enums.app.AppCertUsingType; -import cn.topiam.employee.common.repository.app.AppAccessPolicyRepository; -import cn.topiam.employee.common.repository.app.AppAccountRepository; -import cn.topiam.employee.common.repository.app.AppCertRepository; -import cn.topiam.employee.common.repository.app.AppRepository; import cn.topiam.employee.support.exception.TopIamException; import cn.topiam.employee.support.util.CertUtils; import cn.topiam.employee.support.util.RsaUtils; @@ -128,8 +125,9 @@ public abstract class AbstractCertificateApplicationService extends AbstractAppl protected AbstractCertificateApplicationService(AppCertRepository appCertRepository, AppAccountRepository appAccountRepository, AppAccessPolicyRepository appAccessPolicyRepository, + AppGroupAssociationRepository appGroupAssociationRepository, AppRepository appRepository) { - super(appAccountRepository, appRepository); + super(appAccountRepository, appGroupAssociationRepository, appRepository); this.appCertRepository = appCertRepository; this.appAccessPolicyRepository = appAccessPolicyRepository; this.idGenerator = new AlternativeJdkIdGenerator(); diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/ApplicationService.java b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/ApplicationService.java index 649e95c8..e3590be3 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/ApplicationService.java +++ b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/ApplicationService.java @@ -96,7 +96,7 @@ public interface ApplicationService { * @return {@link Long} 应用ID */ @Transactional(rollbackFor = Exception.class) - String create(String name, String icon, String remark, Long groupId); + String create(String name, String icon, String remark, Long[] groupId); /** * 删除应用 @@ -142,6 +142,6 @@ public interface ApplicationService { * @param authorizationType {@link AuthorizationType} * @return {@link AppEntity} */ - AppEntity createApp(String name, String icon, String remark, Long groupId, + AppEntity createApp(String name, String icon, String remark, Long[] groupId, InitLoginType initLoginType, AuthorizationType authorizationType); } diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/AbstractFormApplicationService.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/AbstractFormApplicationService.java index 560858c4..e36f850b 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/AbstractFormApplicationService.java +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/AbstractFormApplicationService.java @@ -26,6 +26,7 @@ import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.entity.app.po.AppFormConfigPO; import cn.topiam.employee.common.repository.app.AppAccountRepository; import cn.topiam.employee.common.repository.app.AppFormConfigRepository; +import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; import cn.topiam.employee.common.repository.app.AppRepository; /** @@ -83,8 +84,9 @@ public abstract class AbstractFormApplicationService extends AbstractApplication protected AbstractFormApplicationService(AppRepository appRepository, AppAccountRepository appAccountRepository, + AppGroupAssociationRepository appGroupAssociationRepository, AppFormConfigRepository appFormConfigRepository) { - super(appAccountRepository, appRepository); + super(appAccountRepository, appGroupAssociationRepository, appRepository); this.appFormConfigRepository = appFormConfigRepository; } } diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java index 476f4066..d291e4d3 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; @@ -199,7 +200,7 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS * @param groupId {@link Long} 分组id */ @Override - public String create(String name, String icon, String remark, Long groupId) { + public String create(String name, String icon, String remark, Long[] groupId) { //1、创建应用 AppEntity appEntity = createApp(name, icon, remark, groupId, InitLoginType.PORTAL_OR_APP, AuthorizationType.AUTHORIZATION); @@ -216,8 +217,10 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS protected FormStandardApplicationServiceImpl(AppAccountRepository appAccountRepository, AppFormConfigRepository appFormConfigRepository, AppRepository appRepository, + AppGroupAssociationRepository appGroupAssociationRepository, AppFormConfigConverter appFormConfigConverter) { - super(appRepository, appAccountRepository, appFormConfigRepository); + super(appRepository, appAccountRepository, appGroupAssociationRepository, + appFormConfigRepository); this.appFormConfigConverter = appFormConfigConverter; } diff --git a/eiam-application/eiam-application-jwt/src/main/java/cn/topiam/employee/application/jwt/AbstractJwtCertificateApplicationService.java b/eiam-application/eiam-application-jwt/src/main/java/cn/topiam/employee/application/jwt/AbstractJwtCertificateApplicationService.java index 39bcd995..79ac825c 100644 --- a/eiam-application/eiam-application-jwt/src/main/java/cn/topiam/employee/application/jwt/AbstractJwtCertificateApplicationService.java +++ b/eiam-application/eiam-application-jwt/src/main/java/cn/topiam/employee/application/jwt/AbstractJwtCertificateApplicationService.java @@ -102,8 +102,10 @@ public abstract class AbstractJwtCertificateApplicationService extends AppCertRepository appCertRepository, AppRepository appRepository, AppAccountRepository appAccountRepository, + AppGroupAssociationRepository appGroupAssociationRepository, AppAccessPolicyRepository appAccessPolicyRepository) { - super(appCertRepository, appAccountRepository, appAccessPolicyRepository, appRepository); + super(appCertRepository, appAccountRepository, appAccessPolicyRepository, + appGroupAssociationRepository, appRepository); this.appCertRepository = appCertRepository; this.appRepository = appRepository; this.appJwtConfigRepository = appJwtConfigRepository; diff --git a/eiam-application/eiam-application-jwt/src/main/java/cn/topiam/employee/application/jwt/JwtStandardCertificateApplicationServiceImpl.java b/eiam-application/eiam-application-jwt/src/main/java/cn/topiam/employee/application/jwt/JwtStandardCertificateApplicationServiceImpl.java index 1f128b74..4eb09f70 100644 --- a/eiam-application/eiam-application-jwt/src/main/java/cn/topiam/employee/application/jwt/JwtStandardCertificateApplicationServiceImpl.java +++ b/eiam-application/eiam-application-jwt/src/main/java/cn/topiam/employee/application/jwt/JwtStandardCertificateApplicationServiceImpl.java @@ -204,7 +204,7 @@ public class JwtStandardCertificateApplicationServiceImpl extends * @param groupId {@link Long} 分组id */ @Override - public String create(String name, String icon, String remark, Long groupId) { + public String create(String name, String icon, String remark, Long[] groupId) { //1、创建应用 AppEntity appEntity = createApp(name, icon, remark, groupId, InitLoginType.PORTAL_OR_APP, AuthorizationType.AUTHORIZATION); @@ -229,9 +229,10 @@ public class JwtStandardCertificateApplicationServiceImpl extends AppCertRepository appCertRepository, AppRepository appRepository, AppAccountRepository appAccountRepository, + AppGroupAssociationRepository appGroupAssociationRepository, AppAccessPolicyRepository appAccessPolicyRepository) { super(appJwtConfigRepository, appCertRepository, appRepository, appAccountRepository, - appAccessPolicyRepository); + appGroupAssociationRepository, appAccessPolicyRepository); this.appJwtConfigConverter = appJwtConfigConverter; } } diff --git a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/AbstractOidcCertificateApplicationService.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/AbstractOidcCertificateApplicationService.java index 5cad8d99..99bc497d 100644 --- a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/AbstractOidcCertificateApplicationService.java +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/AbstractOidcCertificateApplicationService.java @@ -137,8 +137,10 @@ public abstract class AbstractOidcCertificateApplicationService extends AppAccountRepository appAccountRepository, AppAccessPolicyRepository appAccessPolicyRepository, AppRepository appRepository, + AppGroupAssociationRepository appGroupAssociationRepository, AppOidcConfigRepository appOidcConfigRepository) { - super(appCertRepository, appAccountRepository, appAccessPolicyRepository, appRepository); + super(appCertRepository, appAccountRepository, appAccessPolicyRepository, + appGroupAssociationRepository, appRepository); this.appCertRepository = appCertRepository; this.appRepository = appRepository; this.appOidcConfigRepository = appOidcConfigRepository; diff --git a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/OidcStandardCertificateApplicationServiceImpl.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/OidcStandardCertificateApplicationServiceImpl.java index 1358ae92..681e0082 100644 --- a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/OidcStandardCertificateApplicationServiceImpl.java +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/OidcStandardCertificateApplicationServiceImpl.java @@ -78,7 +78,7 @@ public class OidcStandardCertificateApplicationServiceImpl extends * @param groupId {@link Long} 分组id */ @Override - public String create(String name, String icon, String remark, Long groupId) { + public String create(String name, String icon, String remark, Long[] groupId) { //1、创建应用 AppEntity appEntity = createApp(name, icon, remark, groupId, InitLoginType.APP, AuthorizationType.AUTHORIZATION); @@ -275,9 +275,10 @@ public class OidcStandardCertificateApplicationServiceImpl extends AppAccessPolicyRepository appAccessPolicyRepository, AppRepository appRepository, AppOidcConfigRepository appOidcConfigRepository, + AppGroupAssociationRepository appGroupAssociationRepository, AppOidcStandardConfigConverter appOidcStandardConfigConverter) { super(appCertRepository, appAccountRepository, appAccessPolicyRepository, appRepository, - appOidcConfigRepository); + appGroupAssociationRepository, appOidcConfigRepository); this.appOidcStandardConfigConverter = appOidcStandardConfigConverter; } } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppCreateParam.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppCreateParam.java index 92b00b2b..46ef5bb0 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppCreateParam.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppCreateParam.java @@ -64,6 +64,6 @@ public class AppCreateParam implements Serializable { /** * 应用分组id */ - @Schema(description = "应用分组id") - private Long groupId; + @Schema(description = "应用分组ID") + private Long[] groupId; } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java index 4e94a894..4982a1cd 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java @@ -54,11 +54,4 @@ public class AppGroupCreateParam implements Serializable { */ @Schema(description = "备注") private String remark; - - /** - * 应用分组ID - */ - @Parameter(description = "应用分组ID") - private String[] groupId; - } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java index d614399e..585e584b 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java @@ -94,14 +94,6 @@ public class AppGroupServiceImpl implements AppGroupService { public Boolean createAppGroup(AppGroupCreateParam param) { AppGroupEntity entity = appGroupConverter.appGroupCreateParamConvertToEntity(param); appGroupRepository.save(entity); - List<AppGroupAssociationEntity> list = new ArrayList<>(); - for (String groupId : param.getGroupId()) { - AppGroupAssociationEntity appGroupAssociationEntity = new AppGroupAssociationEntity(); - appGroupAssociationEntity.setGroupId(Long.valueOf(groupId)); - appGroupAssociationEntity.setAppId(entity.getId()); - list.add(appGroupAssociationEntity); - } - appGroupAssociationRepository.saveAll(list); AuditContext.setTarget( Target.builder().id(String.valueOf(entity.getId())).type(TargetType.APP_GROUP).build()); return true; From 5ea64964ce0568610540aa7851fde62a1422051a Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Sat, 9 Sep 2023 17:18:43 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=86=E7=BB=84=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractApplicationService.java | 10 +-- ...AbstractCertificateApplicationService.java | 2 +- .../FormStandardApplicationServiceImpl.java | 2 +- .../common/entity/app/AppGroupEntity.java | 11 ++- .../common/enums/app/AppGroupType.java | 76 +++++++++++++++++++ .../app/converter/AppGroupTypeConverter.java | 67 ++++++++++++++++ .../repository/app/AppGroupRepository.java | 16 ---- .../AppGroupRepositoryCustomizedImpl.java | 1 + .../app/impl/mapper/AppGroupPoMapper.java | 4 +- .../src/main/resources/db/1.1.0-changelog.xml | 3 + .../controller/app/AppGroupController.java | 36 +-------- .../pojo/result/app/AppGroupListResult.java | 8 ++ .../pojo/save/app/AppGroupCreateParam.java | 1 - .../console/service/app/AppGroupService.java | 25 ------ .../service/app/impl/AppGroupServiceImpl.java | 66 +--------------- 15 files changed, 177 insertions(+), 151 deletions(-) create mode 100644 eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppGroupType.java create mode 100644 eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/AppGroupTypeConverter.java diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java index d3fb16df..8924f4d1 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java +++ b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java @@ -17,8 +17,9 @@ */ package cn.topiam.employee.application; -import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity; -import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; +import java.util.ArrayList; +import java.util.List; + import org.apache.commons.lang3.RandomStringUtils; import org.springframework.util.AlternativeJdkIdGenerator; import org.springframework.util.IdGenerator; @@ -27,17 +28,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; import cn.topiam.employee.common.entity.app.AppAccountEntity; import cn.topiam.employee.common.entity.app.AppEntity; +import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import cn.topiam.employee.common.exception.app.AppAccountNotExistException; import cn.topiam.employee.common.repository.app.AppAccountRepository; +import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; import cn.topiam.employee.common.repository.app.AppRepository; import lombok.extern.slf4j.Slf4j; -import java.util.ArrayList; -import java.util.List; - /** * AbstractApplicationService * diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractCertificateApplicationService.java b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractCertificateApplicationService.java index 6014acdb..4fe7510e 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractCertificateApplicationService.java +++ b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractCertificateApplicationService.java @@ -22,7 +22,6 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; -import cn.topiam.employee.common.repository.app.*; import org.bouncycastle.asn1.x500.X500Name; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +32,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import cn.topiam.employee.common.entity.app.AppCertEntity; import cn.topiam.employee.common.enums.app.AppCertUsingType; +import cn.topiam.employee.common.repository.app.*; import cn.topiam.employee.support.exception.TopIamException; import cn.topiam.employee.support.util.CertUtils; import cn.topiam.employee.support.util.RsaUtils; diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java index d291e4d3..ff797f54 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; @@ -36,6 +35,7 @@ import cn.topiam.employee.common.entity.app.po.AppFormConfigPO; import cn.topiam.employee.common.enums.app.*; import cn.topiam.employee.common.repository.app.AppAccountRepository; import cn.topiam.employee.common.repository.app.AppFormConfigRepository; +import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; import cn.topiam.employee.common.repository.app.AppRepository; import cn.topiam.employee.support.exception.TopIamException; import cn.topiam.employee.support.validation.ValidationUtils; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppGroupEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppGroupEntity.java index 95576907..17f60583 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppGroupEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppGroupEntity.java @@ -20,6 +20,7 @@ package cn.topiam.employee.common.entity.app; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; +import cn.topiam.employee.common.enums.app.AppGroupType; import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; @@ -53,11 +54,17 @@ public class AppGroupEntity extends LogicDeleteEntity<Long> { * 分组名称 */ @Column(name = "name_") - private String name; + private String name; /** * 分组编码 */ @Column(name = "code_") - private String code; + private String code; + + /** + * 分组类型 + */ + @Column(name = "type_") + private AppGroupType type; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppGroupType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppGroupType.java new file mode 100644 index 00000000..2bb4a120 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppGroupType.java @@ -0,0 +1,76 @@ +/* + * 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.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * 应用分组类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2023/9/9 16:22 + */ +public enum AppGroupType implements BaseEnum { + /** + * 默认分组 + */ + DEFAULT("default", "默认分组"), + /** + * 自定义分组 + */ + CUSTOM("custom", "自定义分组"); + + @JsonValue + private final String code; + private final String desc; + + AppGroupType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link AppGroupType} + */ + @EnumConvert + public static AppGroupType getType(String code) { + AppGroupType[] values = values(); + for (AppGroupType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/AppGroupTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/AppGroupTypeConverter.java new file mode 100644 index 00000000..bf2ed40c --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/AppGroupTypeConverter.java @@ -0,0 +1,67 @@ +/* + * 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.enums.app.converter; + +import java.util.Objects; + +import cn.topiam.employee.common.enums.app.AppGroupType; + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2023/9/9 16:23 + */ +@Converter(autoApply = true) +public class AppGroupTypeConverter implements AttributeConverter<AppGroupType, String> { + + /** + * Converts the value stored in the entity attribute into the + * data representation to be stored in the database. + * + * @param attribute the entity attribute value to be converted + * @return the converted data to be stored in the database + * column + */ + @Override + public String convertToDatabaseColumn(AppGroupType attribute) { + if (!Objects.isNull(attribute)) { + return attribute.getCode(); + } + return null; + } + + /** + * Converts the data stored in the database column into the + * value to be stored in the entity attribute. + * Note that it is the responsibility of the converter writer to + * specify the correct <code>dbData</code> type for the corresponding + * column for use by the JDBC driver: i.e., persistence providers are + * not expected to do such type conversion. + * + * @param dbData the data from the database column to be + * converted + * @return the converted value to be stored in the entity + * attribute + */ + @Override + public AppGroupType convertToEntityAttribute(String dbData) { + return AppGroupType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupRepository.java index 07007087..91090f5f 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupRepository.java @@ -24,12 +24,10 @@ import org.jetbrains.annotations.NotNull; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; -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.AppGroupEntity; import cn.topiam.employee.support.repository.LogicDeleteRepository; @@ -56,20 +54,6 @@ public interface AppGroupRepository extends LogicDeleteRepository<AppGroupEntity @CacheEvict(allEntries = true) <S extends AppGroupEntity> S save(@NotNull S entity); - /** - * 更新应用分组状态 - * - * @param id {@link Long} - * @param enabled {@link Boolean} - * @return {@link Boolean} - */ - @Modifying - @CacheEvict(allEntries = true) - @Transactional(rollbackFor = Exception.class) - @Query(value = "UPDATE app_group SET is_enabled = :enabled WHERE id_ = :id", nativeQuery = true) - Integer updateAppGroupStatus(@Param(value = "id") Long id, - @Param(value = "enabled") Boolean enabled); - /** * delete * diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppGroupRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppGroupRepositoryCustomizedImpl.java index a88b647c..8de124b1 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppGroupRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppGroupRepositoryCustomizedImpl.java @@ -58,6 +58,7 @@ public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCusto `group`.id_, `group`.name_, `group`.code_, + `group`.type_, `group`.create_time, `group`.remark_, IFNULL( ass.app_count, 0 ) AS app_count diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/mapper/AppGroupPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/mapper/AppGroupPoMapper.java index fa06687a..371661f7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/mapper/AppGroupPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/mapper/AppGroupPoMapper.java @@ -24,6 +24,7 @@ import java.time.LocalDateTime; import org.springframework.jdbc.core.RowMapper; import cn.topiam.employee.common.entity.app.po.AppGroupPO; +import cn.topiam.employee.common.enums.app.AppGroupType; /** * @author TopIAM @@ -47,8 +48,9 @@ public class AppGroupPoMapper implements RowMapper<AppGroupPO> { public AppGroupPO mapRow(ResultSet rs, int rowNum) throws SQLException { AppGroupPO appGroup = new AppGroupPO(); appGroup.setId(rs.getLong("id_")); - appGroup.setCode(rs.getString("code_")); appGroup.setName(rs.getString("name_")); + appGroup.setCode(rs.getString("code_")); + appGroup.setType(AppGroupType.getType(rs.getString("type_"))); appGroup.setRemark(rs.getString("remark_")); appGroup.setAppCount(rs.getInt("app_count")); appGroup.setCreateTime(rs.getObject("create_time", LocalDateTime.class)); diff --git a/eiam-common/src/main/resources/db/1.1.0-changelog.xml b/eiam-common/src/main/resources/db/1.1.0-changelog.xml index 9bdb8ac3..ceb1a98d 100644 --- a/eiam-common/src/main/resources/db/1.1.0-changelog.xml +++ b/eiam-common/src/main/resources/db/1.1.0-changelog.xml @@ -35,6 +35,9 @@ <column name="code_" remarks="分组编码" type="VARCHAR(64)"> <constraints nullable="false"/> </column> + <column name="type_" type="VARCHAR(20)" remarks="类型(默认、自定义)"> + <constraints nullable="false"/> + </column> <column name="create_by" remarks="创建者" type="VARCHAR(64)"> <constraints nullable="false"/> </column> diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppGroupController.java b/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppGroupController.java index 4969c3fd..49d3993a 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppGroupController.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppGroupController.java @@ -143,41 +143,7 @@ public class AppGroupController { } /** - * 启用应用分组 - * - * @param id {@link String} - * @return {@link Boolean} - */ - @Lock - @Preview - @Operation(summary = "启用应用分组") - @Audit(type = EventType.ENABLE_APP_GROUP) - @PutMapping(value = "/enable/{id}") - @PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)") - public ApiRestResult<Boolean> enableAppGroup(@PathVariable(value = "id") String id) { - boolean result = appGroupService.enableAppGroup(id); - return ApiRestResult.<Boolean> builder().result(result).build(); - } - - /** - * 禁用应用分组 - * - * @param id {@link String} - * @return {@link Boolean} - */ - @Lock - @Preview - @Operation(summary = "禁用应用分组") - @Audit(type = EventType.DISABLE_APP_GROUP) - @PutMapping(value = "/disable/{id}") - @PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)") - public ApiRestResult<Boolean> disableAppGroup(@PathVariable(value = "id") String id) { - boolean result = appGroupService.disableAppGroup(id); - return ApiRestResult.<Boolean> builder().result(result).build(); - } - - /** - * 移除分组用户 + * 移除应用组关联 * * @param id {@link String} * @return {@link Boolean} diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupListResult.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupListResult.java index cc845b88..3471caef 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupListResult.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGroupListResult.java @@ -20,6 +20,8 @@ package cn.topiam.employee.console.pojo.result.app; import java.io.Serializable; import java.time.LocalDateTime; +import cn.topiam.employee.common.enums.app.AppGroupType; + import lombok.Data; import io.swagger.v3.oas.annotations.Parameter; @@ -53,6 +55,12 @@ public class AppGroupListResult implements Serializable { @Parameter(description = "分组编码") private String code; + /** + * 分组类型 + */ + @Parameter(description = "分组类型") + private AppGroupType type; + /** * 创建时间 */ diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java index 4982a1cd..cccc97fa 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/save/app/AppGroupCreateParam.java @@ -21,7 +21,6 @@ import java.io.Serializable; import lombok.Data; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/AppGroupService.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/AppGroupService.java index 2e9ce2a7..cb2bbccb 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/AppGroupService.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/AppGroupService.java @@ -80,31 +80,6 @@ public interface AppGroupService { */ AppGroupGetResult getAppGroup(Long id); - /** - * 启用应用分组 - * - * @param id {@link String} - * @return {@link Boolean} - */ - Boolean enableAppGroup(String id); - - /** - * 禁用应用分组 - * - * @param id {@link String} - * @return {@link Boolean} - */ - Boolean disableAppGroup(String id); - - /** - * 添加应用 - * - * @param appIds {@link String} - * @param groupId {@link String} - * @return {@link Boolean} - */ - Boolean addAssociation(String groupId, String[] appIds); - /** * 批量移除应用 * diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java index 585e584b..0cfacb38 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java @@ -18,7 +18,6 @@ package cn.topiam.employee.console.service.app.impl; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -26,17 +25,15 @@ import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.google.common.collect.Lists; - 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.po.AppGroupPO; import cn.topiam.employee.common.entity.app.query.AppGroupAssociationListQuery; import cn.topiam.employee.common.entity.app.query.AppGroupQuery; +import cn.topiam.employee.common.enums.app.AppGroupType; import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; import cn.topiam.employee.common.repository.app.AppGroupRepository; import cn.topiam.employee.console.converter.app.AppConverter; @@ -93,6 +90,7 @@ public class AppGroupServiceImpl implements AppGroupService { @Transactional(rollbackFor = Exception.class) public Boolean createAppGroup(AppGroupCreateParam param) { AppGroupEntity entity = appGroupConverter.appGroupCreateParamConvertToEntity(param); + entity.setType(AppGroupType.CUSTOM); appGroupRepository.save(entity); AuditContext.setTarget( Target.builder().id(String.valueOf(entity.getId())).type(TargetType.APP_GROUP).build()); @@ -149,34 +147,6 @@ public class AppGroupServiceImpl implements AppGroupService { } - /** - * 启用应用分组 - * - * @param id {@link String} - * @return {@link Boolean} - */ - @Override - public Boolean enableAppGroup(String id) { - appGroupRequireNonNull(Long.valueOf(id)); - Integer count = appGroupRepository.updateAppGroupStatus(Long.valueOf(id), Boolean.TRUE); - AuditContext.setTarget(Target.builder().id(id).type(TargetType.APP_GROUP).build()); - return count > 0; - } - - /** - * 禁用应用分组 - * - * @param id {@link String} - * @return {@link Boolean} - */ - @Override - public Boolean disableAppGroup(String id) { - appGroupRequireNonNull(Long.valueOf(id)); - Integer count = appGroupRepository.updateAppGroupStatus(Long.valueOf(id), Boolean.FALSE); - AuditContext.setTarget(Target.builder().id(id).type(TargetType.APP_GROUP).build()); - return count > 0; - } - /** * 查询并检查分组是否为空,非空返回 * @@ -193,38 +163,6 @@ 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; - } - /** * 批量移除应用 * From a5ca4e2dadbfc5dc4577af5c0ad8bfd7f15fd8b6 Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Wed, 13 Sep 2023 14:47:09 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=88=86=E7=BB=84id=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/entity/app/query}/AppQuery.java | 10 ++- .../app/AppGroupAssociationRepository.java | 8 +++ .../app/AppRepositoryCustomized.java | 11 +++ .../app/impl/AppRepositoryCustomizedImpl.java | 51 +++++++++++++ .../console/controller/app/AppController.java | 2 +- .../console/converter/app/AppConverter.java | 2 +- .../pojo/update/app/AppUpdateParam.java | 7 ++ .../console/service/app/AppService.java | 2 +- .../service/app/impl/AppServiceImpl.java | 71 +++++++++---------- 9 files changed, 121 insertions(+), 43 deletions(-) rename {eiam-console/src/main/java/cn/topiam/employee/console/pojo/query/app => eiam-common/src/main/java/cn/topiam/employee/common/entity/app/query}/AppQuery.java (87%) diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/query/app/AppQuery.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/query/AppQuery.java similarity index 87% rename from eiam-console/src/main/java/cn/topiam/employee/console/pojo/query/app/AppQuery.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/query/AppQuery.java index 882ac49c..00366cf0 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/query/app/AppQuery.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/query/AppQuery.java @@ -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; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java index 652acc26..2ef21deb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java @@ -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); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppRepositoryCustomized.java index 448152ea..bea2c11f 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppRepositoryCustomized.java @@ -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); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppRepositoryCustomizedImpl.java index d356daf2..d52f075a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppRepositoryCustomizedImpl.java @@ -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 */ diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppController.java b/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppController.java index e4cdb35a..466c5b96 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppController.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/controller/app/AppController.java @@ -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; diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java index c37ffefa..fd00b4d2 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java @@ -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; diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/update/app/AppUpdateParam.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/update/app/AppUpdateParam.java index 777667e4..6d581f77 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/update/app/AppUpdateParam.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/update/app/AppUpdateParam.java @@ -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; } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/AppService.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/AppService.java index d4f6e057..b24e4517 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/AppService.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/AppService.java @@ -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; diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java index 5bf37d10..301f7280 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java @@ -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; } From 3f7e26aed95ed3e5a3b561047f14f40c8d09be35 Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Wed, 13 Sep 2023 16:14:17 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../topiam/employee/portal/converter/AppGroupConverter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/converter/AppGroupConverter.java b/eiam-portal/src/main/java/cn/topiam/employee/portal/converter/AppGroupConverter.java index 08428eba..6cc47f05 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/converter/AppGroupConverter.java +++ b/eiam-portal/src/main/java/cn/topiam/employee/portal/converter/AppGroupConverter.java @@ -20,6 +20,7 @@ package cn.topiam.employee.portal.converter; import java.util.ArrayList; import java.util.List; +import com.querydsl.core.types.ExpressionUtils; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -47,7 +48,7 @@ public interface AppGroupConverter { */ default Predicate queryPredicate() { QAppGroupEntity appGroup = QAppGroupEntity.appGroupEntity; - Predicate predicate = appGroup.deleted.eq(Boolean.FALSE); + Predicate predicate = ExpressionUtils.and(appGroup.isNotNull(), appGroup.deleted.eq(Boolean.FALSE)); //@formatter:on return predicate; } @@ -59,7 +60,7 @@ public interface AppGroupConverter { */ default Predicate queryAppGroupAssociationPredicate() { QAppGroupAssociationEntity appGroupAssociation = QAppGroupAssociationEntity.appGroupAssociationEntity; - return appGroupAssociation.deleted.eq(Boolean.FALSE); + return ExpressionUtils.and(appGroupAssociation.isNotNull(), appGroupAssociation.deleted.eq(Boolean.FALSE)); } /** From 00447e2edeebc35ce50433d252c1f9e08ac66023 Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Wed, 13 Sep 2023 21:07:33 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/AppGroupAssociationRepository.java | 14 ++++++++++++++ .../console/service/app/impl/AppServiceImpl.java | 1 + 2 files changed, 15 insertions(+) diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java index 2ef21deb..f2cecfa7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java @@ -53,6 +53,20 @@ public interface AppGroupAssociationRepository extends void deleteByGroupIdAndAppId(@Param("groupId") Long groupId, @Param("appId") Long appId); + /** + * 删除关联 + * + * @param appId {@link Long} + * @return {@link Boolean} + */ + @Modifying + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE app_group_association SET " + SOFT_DELETE_SET + + " WHERE app_id = :appId", nativeQuery = true) + void deleteAllByAppId(@Param(value = "appId") Long appId); + + + /** * 根据应用ID删除关联信息 * diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java index 301f7280..14fdfc46 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java @@ -137,6 +137,7 @@ public class AppServiceImpl implements AppService { public boolean deleteApp(Long id) { AppEntity app = appRequireNonNull(id); applicationServiceLoader.getApplicationService(app.getTemplate()).delete(id.toString()); + appGroupAssociationRepository.deleteAllByAppId(id); AuditContext .setTarget(Target.builder().id(id.toString()).type(TargetType.APPLICATION).build()); return true; From 6cb2c043ccc38c42fbe4bfbd898c79fe9cdd75fe Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Wed, 13 Sep 2023 21:52:59 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E5=BA=94=E7=94=A8=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=BA=94=E7=94=A8=E7=BB=84ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/AppGroupAssociationRepository.java | 13 +++++++++++++ .../console/converter/app/AppConverter.java | 4 +++- .../console/pojo/result/app/AppGetResult.java | 8 ++++++++ .../console/service/app/impl/AppServiceImpl.java | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java index f2cecfa7..0f8613b7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java @@ -26,6 +26,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity; import cn.topiam.employee.support.repository.LogicDeleteRepository; + +import java.util.List; + import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** @@ -73,4 +76,14 @@ public interface AppGroupAssociationRepository extends * @param appId {@link Long} */ void deleteByAppId(Long appId); + + + /** + * 根据应用ID 查询关联信息 + * + * @param appId {@link Long} + * @return {@link List} + */ + @Query(value = "SELECT group_id FROM `app_group_association` WHERE app_id = :appId AND is_deleted = '0'", nativeQuery = true) + List<Long> findGroupIdByAppId(Long appId); } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java index fd00b4d2..44547323 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java @@ -135,9 +135,10 @@ public interface AppConverter { * 实体转应用返回 * * @param entity {@link AppEntity} + * @param groupIds {@link List} * @return {@link AppGetResult} */ - default AppGetResult entityConvertToAppResult(AppEntity entity) { + default AppGetResult entityConvertToAppResult(AppEntity entity,List<Long> groupIds) { if (entity == null) { return null; } @@ -150,6 +151,7 @@ public interface AppConverter { appGetResult.setClientId(entity.getClientId()); appGetResult.setClientSecret(entity.getClientSecret()); appGetResult.setType(entity.getType()); + appGetResult.setGroupIds(groupIds); //图标未配置,所以先从模版中拿 if (StringUtils.isBlank(entity.getIcon())) { ApplicationService applicationService = getApplicationServiceLoader() diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGetResult.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGetResult.java index aeb20e53..9916f7a9 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGetResult.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGetResult.java @@ -19,6 +19,7 @@ package cn.topiam.employee.console.pojo.result.app; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.List; import cn.topiam.employee.common.enums.app.AppProtocol; import cn.topiam.employee.common.enums.app.AppType; @@ -104,4 +105,11 @@ public class AppGetResult implements Serializable { */ @Parameter(description = "备注") private String remark; + + + /** + * 应用组ID集合 + */ + @Parameter(description = "应用组ID集合") + private List<Long> groupIds; } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java index 14fdfc46..b4ee356e 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java @@ -154,7 +154,8 @@ public class AppServiceImpl implements AppService { Optional<AppEntity> optional = appRepository.findById(id); if (optional.isPresent()) { AppEntity entity = optional.get(); - return appConverter.entityConvertToAppResult(entity); + List<Long> groupIds = appGroupAssociationRepository.findGroupIdByAppId(id); + return appConverter.entityConvertToAppResult(entity,groupIds); } return null; From 96a966208c7590530bcb971cbae92dfbeb5e6c26 Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Wed, 13 Sep 2023 22:30:40 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E9=97=A8=E6=88=B7=E7=AB=AF=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=BB=84=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/AppGroupAssociationRepository.java | 11 +--- .../app/AppGroupRepositoryCustomized.java | 9 +++ .../AppGroupRepositoryCustomizedImpl.java | 27 +++++++++ .../console/converter/app/AppConverter.java | 25 +------- .../console/pojo/result/app/AppGetResult.java | 3 +- .../service/app/impl/AppServiceImpl.java | 2 +- .../portal/controller/AppController.java | 5 +- .../portal/converter/AppGroupConverter.java | 60 +++++-------------- .../employee/portal/service/AppService.java | 4 +- .../portal/service/impl/AppServiceImpl.java | 34 ++++------- 10 files changed, 73 insertions(+), 107 deletions(-) diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java index 0f8613b7..98bf67a2 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java @@ -17,6 +17,8 @@ */ package cn.topiam.employee.common.repository.app; +import java.util.List; + import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -26,9 +28,6 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity; import cn.topiam.employee.support.repository.LogicDeleteRepository; - -import java.util.List; - import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** @@ -55,7 +54,6 @@ public interface AppGroupAssociationRepository extends + " WHERE app_id = :appId and group_id = :groupId", nativeQuery = true) void deleteByGroupIdAndAppId(@Param("groupId") Long groupId, @Param("appId") Long appId); - /** * 删除关联 * @@ -65,11 +63,9 @@ public interface AppGroupAssociationRepository extends @Modifying @Transactional(rollbackFor = Exception.class) @Query(value = "UPDATE app_group_association SET " + SOFT_DELETE_SET - + " WHERE app_id = :appId", nativeQuery = true) + + " WHERE app_id = :appId", nativeQuery = true) void deleteAllByAppId(@Param(value = "appId") Long appId); - - /** * 根据应用ID删除关联信息 * @@ -77,7 +73,6 @@ public interface AppGroupAssociationRepository extends */ void deleteByAppId(Long appId); - /** * 根据应用ID 查询关联信息 * diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupRepositoryCustomized.java index 2317facd..af2d35e1 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupRepositoryCustomized.java @@ -17,6 +17,8 @@ */ package cn.topiam.employee.common.repository.app; +import java.util.List; + import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -38,4 +40,11 @@ public interface AppGroupRepositoryCustomized { * @return {@link Page} */ Page<AppGroupPO> getAppGroupList(AppGroupQuery query, Pageable pageable); + + /** + * 查询应用组列表 + * + * @return {@link List} + */ + List<AppGroupPO> getAppGroupList(AppGroupQuery query); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppGroupRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppGroupRepositoryCustomizedImpl.java index 2bf6cac8..eba16a39 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppGroupRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/impl/AppGroupRepositoryCustomizedImpl.java @@ -81,5 +81,32 @@ public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCusto 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; + } + private final JdbcTemplate jdbcTemplate; } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java index 44547323..bb4e00f9 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java @@ -25,14 +25,11 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import com.google.common.collect.Lists; -import com.querydsl.core.types.ExpressionUtils; -import com.querydsl.core.types.Predicate; + 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.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; @@ -48,24 +45,6 @@ import cn.topiam.employee.support.repository.page.domain.Page; @Mapper(componentModel = "spring") public interface AppConverter { - /** - * 查询应用列表参数转换为 Querydsl Predicate - * - * @param query {@link AppQuery} query - * @return {@link Predicate} - */ - default Predicate queryAppListParamConvertToPredicate(AppQuery query) { - QAppEntity application = QAppEntity.appEntity; - Predicate predicate = ExpressionUtils.and(application.isNotNull(), - application.deleted.eq(Boolean.FALSE)); - //查询条件 - //@formatter:off - predicate = StringUtils.isBlank(query.getName()) ? predicate : ExpressionUtils.and(predicate, application.name.like("%" + query.getName() + "%")); - predicate = Objects.isNull(query.getProtocol()) ? predicate : ExpressionUtils.and(predicate, application.protocol.eq(query.getProtocol())); - //@formatter:on - return predicate; - } - /** * 实体转换为应用列表结果 * @@ -138,7 +117,7 @@ public interface AppConverter { * @param groupIds {@link List} * @return {@link AppGetResult} */ - default AppGetResult entityConvertToAppResult(AppEntity entity,List<Long> groupIds) { + default AppGetResult entityConvertToAppResult(AppEntity entity, List<Long> groupIds) { if (entity == null) { return null; } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGetResult.java b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGetResult.java index 9916f7a9..3c310581 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGetResult.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/pojo/result/app/AppGetResult.java @@ -106,10 +106,9 @@ public class AppGetResult implements Serializable { @Parameter(description = "备注") private String remark; - /** * 应用组ID集合 */ @Parameter(description = "应用组ID集合") - private List<Long> groupIds; + private List<Long> groupIds; } diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java index 73f63ab2..d539015f 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppServiceImpl.java @@ -157,7 +157,7 @@ public class AppServiceImpl implements AppService { if (optional.isPresent()) { AppEntity entity = optional.get(); List<Long> groupIds = appGroupAssociationRepository.findGroupIdByAppId(id); - return appConverter.entityConvertToAppResult(entity,groupIds); + return appConverter.entityConvertToAppResult(entity, groupIds); } return null; diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/controller/AppController.java b/eiam-portal/src/main/java/cn/topiam/employee/portal/controller/AppController.java index 21995f93..440a7981 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/controller/AppController.java +++ b/eiam-portal/src/main/java/cn/topiam/employee/portal/controller/AppController.java @@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.topiam.employee.common.entity.app.query.AppGroupQuery; import cn.topiam.employee.portal.pojo.query.GetAppListQuery; import cn.topiam.employee.portal.pojo.result.AppGroupListResult; import cn.topiam.employee.portal.pojo.result.GetAppListResult; @@ -68,8 +69,8 @@ public class AppController { */ @Operation(summary = "获取分组应用列表") @GetMapping(value = "/group_list") - public ApiRestResult<List<AppGroupListResult>> getAppGroupList() { - List<AppGroupListResult> list = appService.getAppGroupList(); + public ApiRestResult<List<AppGroupListResult>> getAppGroupList(AppGroupQuery appGroupQuery) { + List<AppGroupListResult> list = appService.getAppGroupList(appGroupQuery); return ApiRestResult.ok(list); } diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/converter/AppGroupConverter.java b/eiam-portal/src/main/java/cn/topiam/employee/portal/converter/AppGroupConverter.java index d96e2b62..2985cf87 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/converter/AppGroupConverter.java +++ b/eiam-portal/src/main/java/cn/topiam/employee/portal/converter/AppGroupConverter.java @@ -17,19 +17,13 @@ */ package cn.topiam.employee.portal.converter; -import java.util.ArrayList; import java.util.List; -import com.querydsl.core.types.ExpressionUtils; import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import com.querydsl.core.types.Predicate; +import com.google.common.collect.Lists; -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.common.entity.app.po.AppGroupPO; import cn.topiam.employee.portal.pojo.result.AppGroupListResult; /** @@ -42,52 +36,26 @@ import cn.topiam.employee.portal.pojo.result.AppGroupListResult; public interface AppGroupConverter { /** - * queryPredicate + * 实体转换为分组列表结果 * - * @return {@link Predicate} + * @param appGroupPoList {@link List} + * @return {@link List} */ - default Predicate getQueryPredicate() { - QAppGroupEntity appGroup = QAppGroupEntity.appGroupEntity; - return ExpressionUtils.and(appGroup.isNotNull(), appGroup.deleted.eq(Boolean.FALSE)); - } - - /** - * 应用组与应用关联 Predicate - * - * @return {@link Predicate} - */ - default Predicate queryAppGroupAssociationPredicate() { - QAppGroupAssociationEntity appGroupAssociation = QAppGroupAssociationEntity.appGroupAssociationEntity; - return ExpressionUtils.and(appGroupAssociation.isNotNull(), appGroupAssociation.deleted.eq(Boolean.FALSE)); + default List<AppGroupListResult> entityConvertToAppGroupListResult(List<AppGroupPO> appGroupPoList) { + List<AppGroupListResult> list = Lists.newArrayList(); + for (AppGroupPO po : appGroupPoList) { + AppGroupListResult result = entityConvertToAppGroupListResult(po); + list.add(result); + } + return list; } /** * 实体转分组管理列表 * - * @param list {@link AppGroupEntity} - * @param appGroupAssociationList {@link AppGroupAssociationEntity} + * @param appGroupPo {@link AppGroupPO} * @return {@link AppGroupListResult} */ - default List<AppGroupListResult> entityConvertToAppGroupListResult(List<AppGroupEntity> list, - List<AppGroupAssociationEntity> appGroupAssociationList) { - List<AppGroupListResult> results = new ArrayList<>(); - for (AppGroupEntity entity : list) { - AppGroupListResult result = appGroupEntityConverterToResult(entity); - long count = appGroupAssociationList.stream() - .filter(t -> t.getGroupId().equals(entity.getId())).count(); - result.setAppCount(Integer.valueOf(Long.toString(count))); - results.add(result); - } - return results; - } - - /** - * 将分组实体对象转换为Result - * - * @param entity {@link AppGroupEntity} - * @return {@link AppGroupEntity} - */ - @Mapping(target = "appCount", ignore = true) - AppGroupListResult appGroupEntityConverterToResult(AppGroupEntity entity); + AppGroupListResult entityConvertToAppGroupListResult(AppGroupPO appGroupPo); } diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/service/AppService.java b/eiam-portal/src/main/java/cn/topiam/employee/portal/service/AppService.java index 2f043a72..3163ea14 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/service/AppService.java +++ b/eiam-portal/src/main/java/cn/topiam/employee/portal/service/AppService.java @@ -19,6 +19,7 @@ package cn.topiam.employee.portal.service; import java.util.List; +import cn.topiam.employee.common.entity.app.query.AppGroupQuery; import cn.topiam.employee.portal.pojo.query.GetAppListQuery; import cn.topiam.employee.portal.pojo.result.AppGroupListResult; import cn.topiam.employee.portal.pojo.result.GetAppListResult; @@ -44,7 +45,8 @@ public interface AppService { /** * 查询应用分组 * + * @param appGroupQuery {@link AppGroupQuery} * @return {@link AppGroupListResult} */ - List<AppGroupListResult> getAppGroupList(); + List<AppGroupListResult> getAppGroupList(AppGroupQuery appGroupQuery); } diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/service/impl/AppServiceImpl.java b/eiam-portal/src/main/java/cn/topiam/employee/portal/service/impl/AppServiceImpl.java index a034c654..807d7063 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/service/impl/AppServiceImpl.java +++ b/eiam-portal/src/main/java/cn/topiam/employee/portal/service/impl/AppServiceImpl.java @@ -22,12 +22,9 @@ import java.util.List; import org.springframework.data.querydsl.QPageRequest; 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.entity.app.po.AppGroupPO; +import cn.topiam.employee.common.entity.app.query.AppGroupQuery; import cn.topiam.employee.common.repository.app.AppGroupRepository; import cn.topiam.employee.common.repository.app.AppRepository; import cn.topiam.employee.portal.converter.AppConverter; @@ -67,51 +64,40 @@ public class AppServiceImpl implements AppService { /** * 查询应用分组 * + * @param appGroupQuery {@link AppGroupQuery} * @return {@link AppGroupListResult} */ @Override - public List<AppGroupListResult> getAppGroupList() { - Predicate predicate = appGroupConverter.getQueryPredicate(); - Predicate appGroupAssociationPredicate = appGroupConverter - .queryAppGroupAssociationPredicate(); - List<AppGroupAssociationEntity> appGroupAssociationList = (List<AppGroupAssociationEntity>) appGroupAssociationRepository - .findAll(appGroupAssociationPredicate); + public List<AppGroupListResult> getAppGroupList(AppGroupQuery appGroupQuery) { //查询映射 - List<AppGroupEntity> list = (List<AppGroupEntity>) appGroupRepository.findAll(predicate); - return appGroupConverter.entityConvertToAppGroupListResult(list, appGroupAssociationList); + List<AppGroupPO> list = appGroupRepository.getAppGroupList(appGroupQuery); + return appGroupConverter.entityConvertToAppGroupListResult(list); } /** * AppRepository */ - private final AppRepository appRepository; + private final AppRepository appRepository; /** * AppGroupRepository */ - private final AppGroupRepository appGroupRepository; - - /** - * AppGroupAssociationRepository - */ - private final AppGroupAssociationRepository appGroupAssociationRepository; + private final AppGroupRepository appGroupRepository; /** * 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; } From 4c80f8023d403815972516dc13ea49aa747beba6 Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Sat, 16 Sep 2023 21:35:27 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BB=84=E5=B9=B6=E5=88=A0=E9=99=A4=E5=85=B3=E8=81=94=E5=85=B3?= =?UTF-8?q?=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/AppGroupAssociationRepository.java | 15 ++++++++++++++- .../console/converter/app/AppConverter.java | 1 - .../service/app/impl/AppGroupServiceImpl.java | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java index 98bf67a2..f89e15bf 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java @@ -55,7 +55,7 @@ public interface AppGroupAssociationRepository extends void deleteByGroupIdAndAppId(@Param("groupId") Long groupId, @Param("appId") Long appId); /** - * 删除关联 + * 根据应用ID删除关联 * * @param appId {@link Long} * @return {@link Boolean} @@ -66,6 +66,19 @@ public interface AppGroupAssociationRepository extends + " WHERE app_id = :appId", nativeQuery = true) void deleteAllByAppId(@Param(value = "appId") Long appId); + + /** + * 根据应用组ID删除关联 + * + * @param groupId {@link Long} + * @return {@link Boolean} + */ + @Modifying + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE app_group_association SET " + SOFT_DELETE_SET + + " WHERE group_id = :groupId", nativeQuery = true) + void deleteAllByGroupId(@Param(value = "groupId") Long groupId); + /** * 根据应用ID删除关联信息 * diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java index bb4e00f9..07a90bb2 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/converter/app/AppConverter.java @@ -26,7 +26,6 @@ import org.mapstruct.Mapping; import com.google.common.collect.Lists; - import cn.topiam.employee.application.ApplicationService; import cn.topiam.employee.application.ApplicationServiceLoader; import cn.topiam.employee.common.entity.app.AppEntity; diff --git a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java index 0cfacb38..1d7395ad 100644 --- a/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java +++ b/eiam-console/src/main/java/cn/topiam/employee/console/service/app/impl/AppGroupServiceImpl.java @@ -125,6 +125,7 @@ public class AppGroupServiceImpl implements AppGroupService { public boolean deleteAppGroup(Long id) { appGroupRequireNonNull(id); appGroupRepository.deleteById(id); + appGroupAssociationRepository.deleteAllByGroupId(id); AuditContext .setTarget(Target.builder().id(id.toString()).type(TargetType.APP_GROUP).build()); return true; From 5c2524d12bb55a0af2a34429e512f159ac25a7cd Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Sat, 16 Sep 2023 23:31:58 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/repository/app/AppGroupAssociationRepository.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java index f89e15bf..579d0d7f 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java @@ -66,7 +66,6 @@ public interface AppGroupAssociationRepository extends + " WHERE app_id = :appId", nativeQuery = true) void deleteAllByAppId(@Param(value = "appId") Long appId); - /** * 根据应用组ID删除关联 * @@ -76,7 +75,7 @@ public interface AppGroupAssociationRepository extends @Modifying @Transactional(rollbackFor = Exception.class) @Query(value = "UPDATE app_group_association SET " + SOFT_DELETE_SET - + " WHERE group_id = :groupId", nativeQuery = true) + + " WHERE group_id = :groupId", nativeQuery = true) void deleteAllByGroupId(@Param(value = "groupId") Long groupId); /** @@ -92,6 +91,6 @@ public interface AppGroupAssociationRepository extends * @param appId {@link Long} * @return {@link List} */ - @Query(value = "SELECT group_id FROM `app_group_association` WHERE app_id = :appId AND is_deleted = '0'", nativeQuery = true) + @Query(value = "SELECT group_id FROM `app_group_association` ass LEFT JOIN app_group `group` ON ass.group_id = `group`.id_ WHERE ass.app_id = :appId AND ass.is_deleted = '0' AND `group`.is_deleted = '0'", nativeQuery = true) List<Long> findGroupIdByAppId(Long appId); } From 3421a4744683fd311b61bf691b7a09bc3008ebf8 Mon Sep 17 00:00:00 2001 From: shao1121353141 <> Date: Sat, 16 Sep 2023 23:34:17 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/AppGroupAssociationRepository.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java index 74265be8..579d0d7f 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppGroupAssociationRepository.java @@ -66,19 +66,6 @@ public interface AppGroupAssociationRepository extends + " WHERE app_id = :appId", nativeQuery = true) void deleteAllByAppId(@Param(value = "appId") Long appId); - - /** - * 根据应用组ID删除关联 - * - * @param groupId {@link Long} - * @return {@link Boolean} - */ - @Modifying - @Transactional(rollbackFor = Exception.class) - @Query(value = "UPDATE app_group_association SET " + SOFT_DELETE_SET - + " WHERE group_id = :groupId", nativeQuery = true) - void deleteAllByGroupId(@Param(value = "groupId") Long groupId); - /** * 根据应用组ID删除关联 *