应用分组

pull/42/head
kingsley 2023-09-05 21:14:50 +08:00 committed by GitHub
parent f993a5198c
commit 59365426ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 1610 additions and 23 deletions

View File

@ -55,11 +55,12 @@ public abstract class AbstractApplicationService implements ApplicationService {
}
@Override
public AppEntity createApp(String name, String icon, String remark, InitLoginType initLoginType,
AuthorizationType authorizationType) {
public AppEntity createApp(String name, String icon, String remark, Long groupId,
InitLoginType initLoginType, AuthorizationType authorizationType) {
AppEntity appEntity = new AppEntity();
appEntity.setName(name);
appEntity.setIcon(icon);
appEntity.setGroupId(null == groupId ? 0L : groupId);
appEntity.setCode(RandomStringUtils.randomAlphanumeric(32).toLowerCase());
appEntity.setTemplate(getCode());
appEntity.setType(getType());

View File

@ -92,10 +92,11 @@ public interface ApplicationService {
* @param name {@link String}
* @param icon {@link String}
* @param remark {@link String}
* @return {@link String} ID
* @param groupId {@link String} id
* @return {@link Long} ID
*/
@Transactional(rollbackFor = Exception.class)
String create(String name, String icon, String remark);
String create(String name, String icon, String remark, Long groupId);
/**
*
@ -136,10 +137,11 @@ public interface ApplicationService {
* @param name {@link String}
* @param icon {@link String}
* @param remark {@link String}
* @param groupId {@link Long} id
* @param initLoginType {@link InitLoginType}
* @param authorizationType {@link AuthorizationType}
* @return {@link AppEntity}
*/
AppEntity createApp(String name, String icon, String remark, InitLoginType initLoginType,
AuthorizationType authorizationType);
AppEntity createApp(String name, String icon, String remark, Long groupId,
InitLoginType initLoginType, AuthorizationType authorizationType);
}

View File

@ -196,11 +196,12 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS
* @param name {@link String}
* @param icon {@link String}
* @param remark {@link String}
* @param groupId {@link Long} id
*/
@Override
public String create(String name, String icon, String remark) {
public String create(String name, String icon, String remark, Long groupId) {
//1、创建应用
AppEntity appEntity = createApp(name, icon, remark, InitLoginType.PORTAL_OR_APP,
AppEntity appEntity = createApp(name, icon, remark, groupId, InitLoginType.PORTAL_OR_APP,
AuthorizationType.AUTHORIZATION);
AppFormConfigEntity appFormConfig = new AppFormConfigEntity();
appFormConfig.setAppId(appEntity.getId());

View File

@ -201,11 +201,12 @@ public class JwtStandardCertificateApplicationServiceImpl extends
* @param name {@link String}
* @param icon {@link String}
* @param remark {@link String}
* @param groupId {@link Long} id
*/
@Override
public String create(String name, String icon, String remark) {
public String create(String name, String icon, String remark, Long groupId) {
//1、创建应用
AppEntity appEntity = createApp(name, icon, remark, InitLoginType.PORTAL_OR_APP,
AppEntity appEntity = createApp(name, icon, remark, groupId, InitLoginType.PORTAL_OR_APP,
AuthorizationType.AUTHORIZATION);
//jwt配置
AppJwtConfigEntity jwtConfigEntity = new AppJwtConfigEntity();

View File

@ -75,11 +75,12 @@ public class OidcStandardCertificateApplicationServiceImpl extends
* @param name {@link String}
* @param icon {@link String}
* @param remark {@link String}
* @param groupId {@link Long} id
*/
@Override
public String create(String name, String icon, String remark) {
public String create(String name, String icon, String remark, Long groupId) {
//1、创建应用
AppEntity appEntity = createApp(name, icon, remark, InitLoginType.APP,
AppEntity appEntity = createApp(name, icon, remark, groupId, InitLoginType.APP,
AuthorizationType.AUTHORIZATION);
//2、创建证书
createCertificate(appEntity.getId(), appEntity.getCode(), AppCertUsingType.OIDC_JWK);

View File

@ -91,6 +91,11 @@ public enum TargetType {
*
*/
APP_PERMISSION_ROLE("app_permission_role", "应用权限角色"),
/**
*
*/
APP_GROUP("app_group", "应用分组"),
/**
*
*/

View File

@ -122,4 +122,10 @@ public class ConsoleResource extends Resource {
*/
public static ConsoleResource SESSION_RESOURCE = new ConsoleResource(
"eiam:event:resource:session", "会话管理");
/**
*
*/
public static ConsoleResource APP_GROUP_RESOURCE = new ConsoleResource(
"eiam:event:resource:app_group", "应用分组管理");
}

View File

@ -21,6 +21,7 @@ import java.util.List;
import cn.topiam.employee.audit.event.Type;
import cn.topiam.employee.support.security.userdetails.UserType;
import static cn.topiam.employee.audit.event.ConsoleResource.APP_GROUP_RESOURCE;
import static cn.topiam.employee.audit.event.ConsoleResource.APP_RESOURCE;
/**
@ -154,4 +155,31 @@ public class AppEventType {
"eiam:event:app:delete_app_permission_role", "删除应用角色", APP_RESOURCE,
List.of(UserType.ADMIN));
/**
*
*/
public static Type ADD_APP_GROUP = new Type("eiam:event:app_group:create",
"添加应用分组", APP_GROUP_RESOURCE, List.of(UserType.ADMIN));
/**
*
*/
public static Type ENABLE_APP_GROUP = new Type("eiam:event:app_group:enabled",
"启用应用分组", APP_GROUP_RESOURCE, List.of(UserType.ADMIN));
/**
*
*/
public static Type DISABLE_APP_GROUP = new Type("eiam:event:app_group:disabled",
"禁用应用分组", APP_GROUP_RESOURCE, List.of(UserType.ADMIN));
/**
*
*/
public static Type UPDATE_APP_GROUP = new Type("eiam:event:app_group:update",
"修改应用分组", APP_GROUP_RESOURCE, List.of(UserType.ADMIN));
/**
*
*/
public static Type DELETE_APP_GROUP = new Type("eiam:event:app_group:delete",
"删除应用分组", APP_GROUP_RESOURCE, List.of(UserType.ADMIN));
}

View File

@ -482,7 +482,28 @@ public enum EventType {
/**
* 线
*/
DOWN_LINE_SESSION(MonitorEventType.DOWN_LINE_SESSION),;
DOWN_LINE_SESSION(MonitorEventType.DOWN_LINE_SESSION),
/**
*
*/
ADD_APP_GROUP(AppEventType.ADD_APP_GROUP),
/**
*
*/
ENABLE_APP_GROUP(AppEventType.ENABLE_APP_GROUP),
/**
*
*/
DISABLE_APP_GROUP(AppEventType.DISABLE_APP_GROUP),
/**
*
*/
UPDATE_APP_GROUP(AppEventType.UPDATE_APP_GROUP),
/**
*
*/
DELETE_APP_GROUP(AppEventType.DELETE_APP_GROUP);
/**
* code

View File

@ -0,0 +1,50 @@
/*
* 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.constant;
import static cn.topiam.employee.support.constant.EiamConstants.COLON;
import static cn.topiam.employee.support.constant.EiamConstants.V1_API_PATH;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 11:07
*/
public final class AppGroupConstants {
/**
* API
*/
public final static String APP_GROUP_PATH = V1_API_PATH + "/app_group";
/**
*
*/
public static final String APP_GROUP_GROUP_NAME = "分组管理";
/**
*
*/
public static final String APP_GROUP_CACHE_NAME_PREFIX = "app_group" + COLON;
/**
*
*/
public static final String APP_GROUP_CACHE_NAME = APP_GROUP_CACHE_NAME_PREFIX + "basic";
}

View File

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

View File

@ -0,0 +1,69 @@
/*
* eiam-common - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.common.entity.app;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import cn.topiam.employee.support.repository.domain.LogicDeleteEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET;
import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 11:25
*/
@Getter
@Setter
@ToString
@Entity
@Accessors(chain = true)
@Table(name = "app_group")
@SQLDelete(sql = "update app_group set " + SOFT_DELETE_SET + " where id_ = ?")
@Where(clause = SOFT_DELETE_WHERE)
public class AppGroupEntity extends LogicDeleteEntity<Long> {
/**
*
*/
@Column(name = "name_")
private String name;
/**
*
*/
@Column(name = "code_")
private String code;
/**
*
*/
@Column(name = "is_enabled")
private Boolean enabled;
}

View File

@ -0,0 +1,105 @@
/*
* eiam-common - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.common.repository.app;
import java.util.List;
import java.util.Optional;
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;
import static cn.topiam.employee.common.constant.AppGroupConstants.APP_GROUP_CACHE_NAME;
/**
* @author TopIAM
*/
@Repository
@CacheConfig(cacheNames = { APP_GROUP_CACHE_NAME })
public interface AppGroupRepository extends LogicDeleteRepository<AppGroupEntity, Long>,
QuerydslPredicateExecutor<AppGroupEntity> {
/**
* save
*
* @param entity must not be {@literal null}.
* @param <S> {@link S}
* @return {@link AppGroupEntity}
*/
@NotNull
@Override
@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
*
* @param id must not be {@literal null}.
*/
@Override
@CacheEvict(allEntries = true)
void deleteById(@NotNull Long id);
/**
* find by id
*
* @param id must not be {@literal null}.
* @return {@link AppGroupEntity}
*/
@NotNull
@Override
Optional<AppGroupEntity> findById(@NotNull Long id);
/**
* find by id
*
* @param id must not be {@literal null}.
* @return {@link AppGroupEntity}
*/
@NotNull
@Cacheable
@Query(value = "SELECT * FROM app_group WHERE id_ = :id", nativeQuery = true)
Optional<AppGroupEntity> findByIdContainsDeleted(@NotNull @Param(value = "id") Long id);
@Query(value = "SELECT * FROM app_group WHERE is_deleted = 0", nativeQuery = true)
List<AppGroupEntity> getAppGroupList();
}

View File

@ -17,6 +17,7 @@
*/
package cn.topiam.employee.common.repository.app;
import java.util.List;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;
@ -108,6 +109,14 @@ public interface AppRepository extends LogicDeleteRepository<AppEntity, Long>,
@Query(value = "SELECT * FROM app WHERE id_ = :id", nativeQuery = true)
Optional<AppEntity> findByIdContainsDeleted(@NotNull @Param(value = "id") Long id);
/**
*
* @return {@link AppEntity}
*/
@NotNull
@Query(value = "SELECT a.* from app a LEFT JOIN app_group ag on a.group_id =ag.id_ WHERE a.group_id IS NOT NULL", nativeQuery = true)
List<AppEntity> getAppListByGroup();
/**
* clientId
*

View File

@ -41,5 +41,5 @@ public interface AppRepositoryCustomized {
* @param pageable {@link Pageable}
* @return {@link List}
*/
Page<AppEntity> getAppList(Long userId, String name, Pageable pageable);
Page<AppEntity> getAppList(Long userId, String name, Long groupId, Pageable pageable);
}

View File

@ -54,12 +54,12 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
*
*
* @param name {@link String}
* @param userId {@link Long}
* @param userId {@link Long}
* @param pageable {@link String}
* @return {@link List}
*/
@Override
public Page<AppEntity> getAppList(Long userId, String name, Pageable pageable) {
public Page<AppEntity> getAppList(Long userId, String name, Long groupId, Pageable pageable) {
List<Object> paramList = Lists.newArrayList();
//当前用户加入的用户组Id
List<Long> groupIdList = userGroupMemberRepository.findByUserId(userId).stream()
@ -88,6 +88,10 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
if (StringUtils.isNoneBlank(name)) {
builder.append(" AND app.name_ like '%").append(name).append("%'");
}
//分组id
if (null!=groupId) {
builder.append(" AND app.group_id = ").append(groupId);
}
//@formatter:on
String sql = builder.toString();
List<AppEntity> list = namedParameterJdbcTemplate.query(

View File

@ -0,0 +1,62 @@
<!--
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/>.
-->
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd
http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/pro/liquibase-pro-4.3.xsd">
<changeSet author="TopIAM" id="1.0.2">
<!--应用分组-->
<createTable remarks="应用分组" tableName="app_group">
<column name="id_" remarks="主键ID" type="BIGINT">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="name_" remarks="分组名称" type="VARCHAR(64)">
<constraints nullable="false"/>
</column>
<column name="code_" remarks="分组编码" type="VARCHAR(64)">
<constraints nullable="false"/>
</column>
<column name="is_enabled" remarks="是否启用" type="TINYINT(1)" defaultValueNumeric="0"/>
<column name="create_by" remarks="创建者" type="VARCHAR(64)">
<constraints nullable="false"/>
</column>
<column defaultValueComputed="CURRENT_TIMESTAMP" name="create_time" remarks="创建时间" type="datetime">
<constraints nullable="false"/>
</column>
<column name="update_by" remarks="修改者" type="VARCHAR(64)">
<constraints nullable="false"/>
</column>
<column defaultValueComputed="CURRENT_TIMESTAMP" name="update_time" remarks="修改时间" type="datetime">
<constraints nullable="false"/>
</column>
<column name="is_deleted" remarks="删除标记" type="TINYINT(1)" defaultValueNumeric="0">
<constraints nullable="true"/>
</column>
<column name="remark_" remarks="备注" type="TEXT"/>
</createTable>
<!--应用表添加分组字段-->
<addColumn tableName="app">
<column name="group_id" remarks="应用组ID" type="BIGINT">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@ -24,6 +24,7 @@
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd
http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/pro/liquibase-pro-4.3.xsd">
<include file="db/1.0.0-changelog.xml" relativeToChangelogFile="false"/>
<include file="db/1.0.2-changelog.xml" relativeToChangelogFile="false"/>
<include file="db/1.1.0-changelog.xml" relativeToChangelogFile="false"/>
<!-- 引入Quartz -->
<include file="org/quartz/impl/jdbcjobstore/liquibase.quartz.init.xml" relativeToChangelogFile="false"/>

View File

@ -33,8 +33,7 @@ import static cn.topiam.employee.common.constant.AccountConstants.ACCOUNT_API_DO
import static cn.topiam.employee.common.constant.AccountConstants.ACCOUNT_API_PATHS;
import static cn.topiam.employee.common.constant.AnalysisConstants.ANALYSIS_GROUP_NAME;
import static cn.topiam.employee.common.constant.AnalysisConstants.ANALYSIS_PATH;
import static cn.topiam.employee.common.constant.AppConstants.APP_GROUP_NAME;
import static cn.topiam.employee.common.constant.AppConstants.APP_PATH;
import static cn.topiam.employee.common.constant.AppConstants.*;
import static cn.topiam.employee.common.constant.AuthnConstants.AUTHN_PATH;
import static cn.topiam.employee.common.constant.SettingConstants.SETTING_GROUP_NAME;
import static cn.topiam.employee.common.constant.SettingConstants.SETTING_PATH;

View File

@ -0,0 +1,176 @@
/*
* eiam-console - 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.console.controller.app;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
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.AppGroupQuery;
import cn.topiam.employee.console.pojo.result.app.AppGroupGetResult;
import cn.topiam.employee.console.pojo.result.app.AppGroupListResult;
import cn.topiam.employee.console.pojo.save.app.AppGroupCreateParam;
import cn.topiam.employee.console.pojo.update.app.AppGroupUpdateParam;
import cn.topiam.employee.console.service.app.AppGroupService;
import cn.topiam.employee.support.lock.Lock;
import cn.topiam.employee.support.preview.Preview;
import cn.topiam.employee.support.repository.page.domain.Page;
import cn.topiam.employee.support.repository.page.domain.PageModel;
import cn.topiam.employee.support.result.ApiRestResult;
import lombok.AllArgsConstructor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import static cn.topiam.employee.common.constant.AppConstants.APP_PATH;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 15:35
*/
@Validated
@Tag(name = "应用分组管理")
@RestController
@AllArgsConstructor
@RequestMapping(value = APP_PATH + "/app_group", produces = MediaType.APPLICATION_JSON_VALUE)
public class AppGroupController {
/**
*
*
* @param page {@link PageModel}
* @return {@link AppGroupQuery}
*/
@Operation(summary = "获取分组列表")
@GetMapping(value = "/list")
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
public ApiRestResult<Page<AppGroupListResult>> getAppGroupList(PageModel page,
AppGroupQuery query) {
Page<AppGroupListResult> list = appGroupService.getAppGroupList(page, query);
return ApiRestResult.<Page<AppGroupListResult>> builder().result(list).build();
}
/**
*
*
* @param param {@link AppGroupCreateParam}
* @return {@link Boolean}
*/
@Lock
@Preview
@Operation(summary = "创建应用分组")
@Audit(type = EventType.ADD_APP_GROUP)
@PostMapping(value = "/create")
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
public ApiRestResult<Boolean> createAppGroup(@RequestBody @Validated AppGroupCreateParam param) {
return ApiRestResult.<Boolean> builder().result(appGroupService.createAppGroup(param))
.build();
}
/**
*
*
* @param param {@link AppGroupUpdateParam}
* @return {@link Boolean}
*/
@Lock
@Preview
@Operation(summary = "修改应用分组")
@Audit(type = EventType.UPDATE_APP_GROUP)
@PutMapping(value = "/update")
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
public ApiRestResult<Boolean> updateAppGroup(@RequestBody @Validated AppGroupUpdateParam param) {
return ApiRestResult.<Boolean> builder().result(appGroupService.updateAppGroup(param))
.build();
}
/**
*
*
* @param id {@link Long}
* @return {@link Boolean}
*/
@Lock
@Preview
@Operation(summary = "删除应用分组")
@Audit(type = EventType.DELETE_APP_GROUP)
@DeleteMapping(value = "/delete/{id}")
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
public ApiRestResult<Boolean> deleteAppGroup(@PathVariable(value = "id") String id) {
return ApiRestResult.<Boolean> builder()
.result(appGroupService.deleteAppGroup(Long.valueOf(id))).build();
}
/**
*
*
* @param id {@link String}
* @return {@link Boolean}
*/
@Operation(summary = "获取应用分组信息")
@GetMapping(value = "/get/{id}")
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
public ApiRestResult<AppGroupGetResult> getAppGroup(@PathVariable(value = "id") String id) {
AppGroupGetResult result = appGroupService.getAppGroup(Long.valueOf(id));
return ApiRestResult.<AppGroupGetResult> builder().result(result).build();
}
/**
*
*
* @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();
}
/**
* AppGroupService
*/
private final AppGroupService appGroupService;
}

View File

@ -0,0 +1,164 @@
/*
* eiam-console - 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.console.converter.app;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
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.common.entity.app.AppAccountEntity;
import cn.topiam.employee.common.entity.app.AppGroupEntity;
import cn.topiam.employee.common.entity.app.QAppGroupEntity;
import cn.topiam.employee.console.pojo.query.app.AppGroupQuery;
import cn.topiam.employee.console.pojo.result.app.AppGroupGetResult;
import cn.topiam.employee.console.pojo.result.app.AppGroupListResult;
import cn.topiam.employee.console.pojo.save.app.AppAccountCreateParam;
import cn.topiam.employee.console.pojo.save.app.AppGroupCreateParam;
import cn.topiam.employee.console.pojo.update.app.AppGroupUpdateParam;
import cn.topiam.employee.support.repository.page.domain.Page;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 15:45
*/
@Mapper(componentModel = "spring")
public interface AppGroupConverter {
/**
* Querydsl Predicate
*
* @param query {@link AppGroupQuery} query
* @return {@link Predicate}
*/
default Predicate queryAppGroupListParamConvertToPredicate(AppGroupQuery query) {
QAppGroupEntity appGroup = QAppGroupEntity.appGroupEntity;
Predicate predicate = ExpressionUtils.and(appGroup.isNotNull(),
appGroup.deleted.eq(Boolean.FALSE));
//查询条件
//@formatter:off
predicate = StringUtils.isBlank(query.getName()) ? predicate : ExpressionUtils.and(predicate, appGroup.name.like("%" + query.getName() + "%"));
predicate = Objects.isNull(query.getEnabled()) ? predicate : ExpressionUtils.and(predicate, appGroup.enabled.eq(query.getEnabled()));
//@formatter:on
return predicate;
}
/**
*
*
* @param entityPage {@link List}
* @return {@link List}
*/
default Page<AppGroupListResult> entityConvertToAppGroupListResult(org.springframework.data.domain.Page<AppGroupEntity> entityPage) {
Page<AppGroupListResult> page = new Page<>();
List<AppGroupListResult> list = Lists.newArrayList();
for (AppGroupEntity entity : entityPage.getContent()) {
AppGroupListResult result = entityConvertToAppGroupListResult(entity);
list.add(result);
}
page.setList(list);
//@formatter:off
page.setPagination(Page.Pagination.builder()
.total(entityPage.getTotalElements())
.totalPages(entityPage.getTotalPages())
.current(entityPage.getPageable().getPageNumber() + 1)
.build());
//@formatter:on
return page;
}
/**
*
*
* @param entity {@link AppGroupEntity}
* @return {@link AppGroupListResult}
*/
default AppGroupListResult entityConvertToAppGroupListResult(AppGroupEntity entity) {
if (entity == null) {
return null;
}
AppGroupListResult appGroupListResult = new AppGroupListResult();
if (entity.getId() != null) {
appGroupListResult.setId(String.valueOf(entity.getId()));
}
appGroupListResult.setName(entity.getName());
appGroupListResult.setCode(entity.getCode());
appGroupListResult.setEnabled(entity.getEnabled());
appGroupListResult.setRemark(entity.getRemark());
return appGroupListResult;
}
/**
*
*
* @param entity {@link AppGroupEntity}
* @return {@link AppGroupGetResult}
*/
default AppGroupGetResult entityConvertToAppGroupResult(AppGroupEntity entity) {
if (entity == null) {
return null;
}
AppGroupGetResult appGroupGetResult = new AppGroupGetResult();
if (entity.getId() != null) {
appGroupGetResult.setId(String.valueOf(entity.getId()));
}
appGroupGetResult.setName(entity.getName());
appGroupGetResult.setEnabled(entity.getEnabled());
appGroupGetResult.setCreateTime(entity.getCreateTime());
return appGroupGetResult;
}
/**
* entity
*
* @param param {@link AppGroupUpdateParam}
* @return {@link AppGroupEntity}
*/
@Mapping(target = "deleted", ignore = true)
@Mapping(target = "updateTime", ignore = true)
@Mapping(target = "updateBy", ignore = true)
@Mapping(target = "createTime", ignore = true)
@Mapping(target = "createBy", ignore = true)
@Mapping(target = "enabled", ignore = false)
AppGroupEntity appGroupUpdateParamConverterToEntity(AppGroupUpdateParam param);
/**
*
*
* @param param {@link AppAccountCreateParam}
* @return {@link AppAccountEntity}
*/
@Mapping(target = "deleted", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "updateTime", ignore = true)
@Mapping(target = "updateBy", ignore = true)
@Mapping(target = "createTime", ignore = true)
@Mapping(target = "createBy", ignore = true)
AppGroupEntity appGroupCreateParamConvertToEntity(AppGroupCreateParam param);
}

View File

@ -0,0 +1,58 @@
/*
* eiam-console - 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.console.pojo.query.app;
import java.io.Serializable;
import org.springdoc.core.annotations.ParameterObject;
import lombok.Data;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 9:08
*/
@Data
@Schema(description = "查询分组列表入参")
@ParameterObject
public class AppGroupQuery implements Serializable {
/**
*
*/
@Parameter(description = "分组名称")
private String name;
/**
*
*/
@Parameter(description = "分组是否启用")
private Boolean enabled;
/**
*
*/
@Parameter(description = "分组编码")
private String code;
}

View File

@ -0,0 +1,71 @@
/*
* eiam-console - 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.console.pojo.result.app;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 11:25
*/
@Data
@Schema(description = "获取分组返回响应")
public class AppGroupGetResult implements Serializable {
/**
* ID
*/
@Parameter(description = "ID")
private String id;
/**
*
*/
@Parameter(description = "分组名称")
private String name;
/**
*
*/
@Parameter(description = "分组编码")
private String code;
/**
*
*/
@Parameter(description = "分组是否启用")
private Boolean enabled;
/**
*
*/
@Parameter(description = "创建时间")
private LocalDateTime createTime;
/**
*
*/
@Parameter(description = "备注")
private String remark;
}

View File

@ -0,0 +1,67 @@
/*
* eiam-console - 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.console.pojo.result.app;
import java.io.Serializable;
import lombok.Data;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 10:29
*/
@Data
@Schema(description = "分组列表返回")
public class AppGroupListResult implements Serializable {
/**
* ID
*/
@Parameter(description = "ID")
private String id;
/**
*
*/
@Parameter(description = "分组名称")
private String name;
/**
*
*/
@Parameter(description = "分组编码")
private String code;
/**
*
*/
@Parameter(description = "是否启用")
private Boolean enabled;
/**
*
*/
@Parameter(description = "备注")
private String remark;
}

View File

@ -60,4 +60,10 @@ public class AppCreateParam implements Serializable {
*/
@Schema(description = "备注")
private String remark;
/**
* id
*/
@Schema(description = "应用分组id")
private Long groupId;
}

View File

@ -0,0 +1,56 @@
/*
* eiam-console - 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.console.pojo.save.app;
import java.io.Serializable;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 23:26
*/
@Data
@Schema(description = "分组保存入参")
public class AppGroupCreateParam implements Serializable {
/**
*
*/
@NotBlank(message = "分组名称不能为空")
@Schema(description = "分组名称")
private String name;
/**
*
*/
@Schema(description = "备注")
private String remark;
/**
*
*/
@Schema(description = "分组编码")
private String code;
}

View File

@ -0,0 +1,67 @@
/*
* eiam-console - 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.console.pojo.update.app;
import java.io.Serializable;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2021/7/18 23:26
*/
@Data
@Schema(description = "分组修改入参")
public class AppGroupUpdateParam implements Serializable {
/**
* id
*/
@Schema(description = "分组id")
@NotNull(message = "ID不能为空")
private Long id;
/**
*
*/
@Schema(description = "分组名称")
private String name;
/**
*
*/
@Schema(description = "分组编码")
private String code;
/**
*
*/
@Schema(description = "分组是否启用")
private Boolean enabled;
/**
*
*/
@Schema(description = "备注")
private String remark;
}

View File

@ -0,0 +1,94 @@
/*
* eiam-console - 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.console.service.app;
import cn.topiam.employee.console.pojo.query.app.AppGroupQuery;
import cn.topiam.employee.console.pojo.result.app.AppGroupGetResult;
import cn.topiam.employee.console.pojo.result.app.AppGroupListResult;
import cn.topiam.employee.console.pojo.save.app.AppGroupCreateParam;
import cn.topiam.employee.console.pojo.update.app.AppGroupUpdateParam;
import cn.topiam.employee.support.repository.page.domain.Page;
import cn.topiam.employee.support.repository.page.domain.PageModel;
/**
* <p>
*
* </p>
*
* @author TopIAM
* Created by support@topiam.cn on 2023-08-31
*/
public interface AppGroupService {
/**
*
*
* @param pageModel {@link PageModel}
* @param query {@link AppGroupQuery}
* @return {@link AppGroupListResult}
*/
Page<AppGroupListResult> getAppGroupList(PageModel pageModel, AppGroupQuery query);
/**
*
*
* @param param {@link AppGroupCreateParam}
* @return {@link Boolean}
*/
Boolean createAppGroup(AppGroupCreateParam param);
/**
*
*
* @param param {@link AppGroupUpdateParam}
* @return {@link Boolean}
*/
boolean updateAppGroup(AppGroupUpdateParam param);
/**
*
*
* @param id {@link Long}
* @return {@link Boolean}
*/
boolean deleteAppGroup(Long id);
/**
*
*
* @param id {@link Long}
* @return {@link AppGroupGetResult}
*/
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);
}

View File

@ -0,0 +1,206 @@
/*
* eiam-console - 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.console.service.app.impl;
import java.time.LocalDateTime;
import java.util.Optional;
import org.springframework.data.querydsl.QPageRequest;
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.audit.context.AuditContext;
import cn.topiam.employee.audit.entity.Target;
import cn.topiam.employee.audit.enums.TargetType;
import cn.topiam.employee.common.entity.app.AppGroupEntity;
import cn.topiam.employee.common.entity.app.QAppGroupEntity;
import cn.topiam.employee.common.repository.app.AppGroupRepository;
import cn.topiam.employee.console.converter.app.AppGroupConverter;
import cn.topiam.employee.console.pojo.query.app.AppGroupQuery;
import cn.topiam.employee.console.pojo.result.app.AppGroupGetResult;
import cn.topiam.employee.console.pojo.result.app.AppGroupListResult;
import cn.topiam.employee.console.pojo.save.app.AppGroupCreateParam;
import cn.topiam.employee.console.pojo.update.app.AppGroupUpdateParam;
import cn.topiam.employee.console.service.app.AppGroupService;
import cn.topiam.employee.support.exception.TopIamException;
import cn.topiam.employee.support.repository.page.domain.Page;
import cn.topiam.employee.support.repository.page.domain.PageModel;
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;
/**
* AppGroupServiceImpl
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 14:23
*/
@Service
@Slf4j
@AllArgsConstructor
public class AppGroupServiceImpl implements AppGroupService {
/**
*
*
* @param pageModel {@link PageModel}
* @param query {@link AppGroupQuery}
* @return {@link AppGroupListResult}
*/
@Override
public Page<AppGroupListResult> getAppGroupList(PageModel pageModel, AppGroupQuery query) {
//查询条件
Predicate predicate = appGroupConverter.queryAppGroupListParamConvertToPredicate(query);
OrderSpecifier<LocalDateTime> desc = QAppGroupEntity.appGroupEntity.updateTime.desc();
//分页条件
QPageRequest request = QPageRequest.of(pageModel.getCurrent(), pageModel.getPageSize(),
desc);
//查询映射
org.springframework.data.domain.Page<AppGroupEntity> list = appGroupRepository
.findAll(predicate, request);
return appGroupConverter.entityConvertToAppGroupListResult(list);
}
/**
*
*
* @param param {@link AppGroupCreateParam}
* @return {@link Boolean}
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean createAppGroup(AppGroupCreateParam param) {
// TODO 创建后没有数据权限
AppGroupEntity entity = appGroupConverter.appGroupCreateParamConvertToEntity(param);
entity.setEnabled(true);
appGroupRepository.save(entity);
AuditContext.setTarget(
Target.builder().id(String.valueOf(entity.getId())).type(TargetType.APP_GROUP).build());
return true;
}
/**
*
*
* @param param {@link AppGroupUpdateParam}
* @return {@link Boolean}
*/
@Override
public boolean updateAppGroup(AppGroupUpdateParam param) {
AppGroupEntity appGroup = appGroupRequireNonNull(param.getId());
AppGroupEntity entity = appGroupConverter.appGroupUpdateParamConverterToEntity(param);
BeanUtils.merge(entity, appGroup, LAST_MODIFIED_TIME, LAST_MODIFIED_BY);
appGroupRepository.save(appGroup);
AuditContext.setTarget(
Target.builder().id(param.getId().toString()).type(TargetType.APP_GROUP).build());
return true;
}
/**
*
*
* @param id {@link String}
* @return {@link Boolean}
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteAppGroup(Long id) {
appGroupRequireNonNull(id);
appGroupRepository.deleteById(id);
AuditContext
.setTarget(Target.builder().id(id.toString()).type(TargetType.APP_GROUP).build());
return true;
}
/**
*
*
* @param id {@link Long}
* @return {@link AppGroupEntity}
*/
@Override
public AppGroupGetResult getAppGroup(Long id) {
Optional<AppGroupEntity> optional = appGroupRepository.findById(id);
if (optional.isPresent()) {
AppGroupEntity entity = optional.get();
return appGroupConverter.entityConvertToAppGroupResult(entity);
}
return null;
}
/**
*
*
* @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;
}
/**
*
*
* @param id {@link Long}
* @return {@link AppGroupEntity}
*/
private AppGroupEntity appGroupRequireNonNull(Long id) {
Optional<AppGroupEntity> optional = appGroupRepository.findById(id);
if (optional.isEmpty()) {
AuditContext.setContent("操作失败,应用分组不存在");
log.warn(AuditContext.getContent());
throw new TopIamException(AuditContext.getContent());
}
return optional.get();
}
/**
* AppGroupRepository
*/
private final AppGroupRepository appGroupRepository;
/**
* AppGroupConverter
*/
private final AppGroupConverter appGroupConverter;
}

View File

@ -101,7 +101,7 @@ public class AppServiceImpl implements AppService {
ApplicationService applicationService = applicationServiceLoader
.getApplicationService(param.getTemplate());
String appId = applicationService.create(param.getName(), param.getIcon(),
param.getRemark());
param.getRemark(), param.getGroupId());
AuditContext.setTarget(Target.builder().id(appId).type(TargetType.APPLICATION).build());
return new AppCreateResult(appId);
}

View File

@ -17,11 +17,14 @@
*/
package cn.topiam.employee.portal.controller;
import java.util.List;
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.portal.pojo.query.GetAppListQuery;
import cn.topiam.employee.portal.pojo.result.AppGroupListResult;
import cn.topiam.employee.portal.pojo.result.GetAppListResult;
import cn.topiam.employee.portal.service.AppService;
import cn.topiam.employee.support.repository.page.domain.Page;
@ -58,6 +61,18 @@ public class AppController {
return ApiRestResult.ok(list);
}
/**
*
*
* @return {@link AppGroupListResult}
*/
@Operation(summary = "获取分组应用列表")
@GetMapping(value = "/getAppGroupList")
public ApiRestResult<List<AppGroupListResult>> getAppGroupList() {
List<AppGroupListResult> list = appService.getAppGroupList();
return ApiRestResult.ok(list);
}
/**
* AppService
*/

View File

@ -95,6 +95,43 @@ public interface AppConverter {
return page;
}
default List<GetAppListResult> entityConvertToAppListResult(List<AppEntity> list) {
//@formatter:off
List<GetAppListResult> results = new ArrayList<>();
for (AppEntity entity : list) {
GetAppListResult result = new GetAppListResult();
result.setId(entity.getId().toString());
result.setName(entity.getName());
result.setType(entity.getType());
result.setProtocol(entity.getProtocol());
result.setTemplate(entity.getTemplate());
result.setInitLoginType(entity.getInitLoginType());
//登录发起URL
if (PORTAL_OR_APP.equals(entity.getInitLoginType())){
result.setInitLoginUrl(StringUtils.defaultIfBlank(entity.getInitLoginUrl(), getIdpInitUrl(entity.getProtocol(), entity.getCode())));
}
result.setIcon(entity.getIcon());
//图标未配置,所以先从模版中拿
if (StringUtils.isBlank(entity.getIcon())){
ApplicationService applicationService = getApplicationServiceLoader()
.getApplicationService(entity.getTemplate());
result.setIcon(applicationService.getBase64Icon());
}
if (StringUtils.isNotBlank(entity.getRemark())){
result.setDescription(entity.getRemark());
}else {
ApplicationServiceLoader loader = ApplicationContextHelp.getBean(ApplicationServiceLoader.class);
ApplicationService applicationService = loader.getApplicationService(entity.getTemplate());
if (!Objects.isNull(applicationService)){
result.setDescription(applicationService.getDescription());
}
}
results.add(result);
}
//@formatter:on
return results;
}
/**
* idp init url
*

View File

@ -0,0 +1,84 @@
/*
* eiam-portal - 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.portal.converter;
import java.util.ArrayList;
import java.util.List;
import org.mapstruct.Mapper;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import cn.topiam.employee.common.entity.app.AppEntity;
import cn.topiam.employee.common.entity.app.AppGroupEntity;
import cn.topiam.employee.common.entity.app.QAppGroupEntity;
import cn.topiam.employee.portal.pojo.result.AppGroupListResult;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/8/31 15:45
*/
@Mapper(componentModel = "spring")
public interface AppGroupConverter {
/**
* queryPredicate
*
* @return {@link Predicate}
*/
default Predicate queryPredicate() {
QAppGroupEntity appGroup = QAppGroupEntity.appGroupEntity;
Predicate predicate = appGroup.deleted.eq(Boolean.FALSE);
//@formatter:off
predicate = ExpressionUtils.and(predicate, appGroup.enabled.eq(Boolean.TRUE));
//@formatter:on
return predicate;
}
/**
*
*
* @param list {@link AppGroupEntity}
* @param appList {@link AppEntity}
* @return {@link AppGroupListResult}
*/
default List<AppGroupListResult> entityConvertToAppGroupListResult(List<AppGroupEntity> list,
List<AppEntity> appList) {
List<AppGroupListResult> results = new ArrayList<>();
for (AppGroupEntity entity : list) {
AppGroupListResult result = appGroupEntityConverterToResult(entity);
Long count = appList.stream().filter(t -> t.getGroupId().equals(entity.getId()))
.count();
result.setAppCount(Integer.valueOf(count.toString()));
results.add(result);
}
return results;
}
/**
* Result
*
* @param entity {@link AppGroupEntity}
* @return {@link AppGroupEntity}
*/
AppGroupListResult appGroupEntityConverterToResult(AppGroupEntity entity);
}

View File

@ -44,4 +44,9 @@ public class GetAppListQuery implements Serializable {
*/
private String name;
/**
* groupId
*/
private Long groupId;
}

View File

@ -0,0 +1,58 @@
/*
* eiam-portal - 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.portal.pojo.result;
import java.io.Serial;
import java.io.Serializable;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/9/1 11:58
*/
@Data
@Schema(description = "获取分组应用列表")
public class AppGroupListResult implements Serializable {
@Serial
private static final long serialVersionUID = 1263170640092199401L;
/**
* ID
*/
@Schema(description = "应用分组ID")
private Long id;
/**
*
*/
@Schema(description = "应用分组名称")
private String name;
/**
* APP
*/
@Schema(description = "APP数量")
private Integer appCount;
}

View File

@ -17,7 +17,10 @@
*/
package cn.topiam.employee.portal.service;
import java.util.List;
import cn.topiam.employee.portal.pojo.query.GetAppListQuery;
import cn.topiam.employee.portal.pojo.result.AppGroupListResult;
import cn.topiam.employee.portal.pojo.result.GetAppListResult;
import cn.topiam.employee.support.repository.page.domain.Page;
import cn.topiam.employee.support.repository.page.domain.PageModel;
@ -37,4 +40,11 @@ public interface AppService {
* @return {@link Page}
*/
Page<GetAppListResult> getAppList(GetAppListQuery query, PageModel pageModel);
/**
*
*
* @return {@link AppGroupListResult}
*/
List<AppGroupListResult> getAppGroupList();
}

View File

@ -17,13 +17,21 @@
*/
package cn.topiam.employee.portal.service.impl;
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.AppGroupEntity;
import cn.topiam.employee.common.repository.app.AppGroupRepository;
import cn.topiam.employee.common.repository.app.AppRepository;
import cn.topiam.employee.portal.converter.AppConverter;
import cn.topiam.employee.portal.converter.AppGroupConverter;
import cn.topiam.employee.portal.pojo.query.GetAppListQuery;
import cn.topiam.employee.portal.pojo.result.AppGroupListResult;
import cn.topiam.employee.portal.pojo.result.GetAppListResult;
import cn.topiam.employee.portal.service.AppService;
import cn.topiam.employee.support.repository.page.domain.Page;
@ -49,17 +57,51 @@ public class AppServiceImpl implements AppService {
public Page<GetAppListResult> getAppList(GetAppListQuery query, PageModel pageModel) {
Long userId = Long.valueOf(SecurityUtils.getCurrentUserId());
org.springframework.data.domain.Page<AppEntity> list = appRepository.getAppList(userId,
query.getName(), QPageRequest.of(pageModel.getCurrent(), pageModel.getPageSize()));
query.getName(), query.getGroupId(),
QPageRequest.of(pageModel.getCurrent(), pageModel.getPageSize()));
return appConverter.entityConvertToAppListResult(list);
}
private final AppRepository appRepository;
/**
*
*
* @return {@link AppGroupListResult}
*/
@Override
public List<AppGroupListResult> getAppGroupList() {
Predicate predicate = appGroupConverter.queryPredicate();
List<AppEntity> appList = appRepository.getAppListByGroup();
//查询映射
List<AppGroupEntity> list = (List<AppGroupEntity>) appGroupRepository.findAll(predicate);
return appGroupConverter.entityConvertToAppGroupListResult(list, appList);
}
private final AppConverter appConverter;
/**
* AppRepository
*/
private final AppRepository appRepository;
public AppServiceImpl(AppRepository appRepository, AppConverter appConverter) {
/**
* AppGroupRepository
*/
private final AppGroupRepository appGroupRepository;
/**
* AppConverter
*/
private final AppConverter appConverter;
/**
* AppGroupConverter
*/
private final AppGroupConverter appGroupConverter;
public AppServiceImpl(AppRepository appRepository, AppGroupRepository appGroupRepository,
AppConverter appConverter, AppGroupConverter appGroupConverter) {
this.appRepository = appRepository;
this.appGroupRepository = appGroupRepository;
this.appConverter = appConverter;
this.appGroupConverter = appGroupConverter;
}
}