From 0473ca0e7c6e36a4a8de860bc0210d52c5108ceb Mon Sep 17 00:00:00 2001 From: smallbun <2689170096@qq.com> Date: Wed, 13 Sep 2023 21:55:12 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/ApplicationService.java | 14 ++++++++ .../service/app/impl/AppServiceImpl.java | 35 ++++++++++--------- 2 files changed, 33 insertions(+), 16 deletions(-) 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 e4f2c028..47ba8a7d 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 @@ -17,6 +17,7 @@ */ package cn.topiam.employee.application; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -86,6 +87,19 @@ public interface ApplicationService { */ String getBase64Icon(); + /** + * 创建应用 + * + * @param name {@link String} 名称 + * @param icon {@link String} 图标 + * @param remark {@link String} 备注 + * @return {@link Long} 应用ID + */ + @Transactional(rollbackFor = Exception.class) + default String create(String name, String icon, String remark) { + return create(name, icon, remark, new ArrayList<>()); + } + /** * 创建应用 * 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..2ee496f1 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,10 +17,7 @@ */ package cn.topiam.employee.console.service.app.impl; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity; import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; @@ -52,6 +49,7 @@ import cn.topiam.employee.support.util.BeanUtils; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.CollectionUtils; import static cn.topiam.employee.support.repository.domain.BaseEntity.LAST_MODIFIED_BY; import static cn.topiam.employee.support.repository.domain.BaseEntity.LAST_MODIFIED_TIME; @@ -78,7 +76,7 @@ public class AppServiceImpl implements AppService { public Page getAppList(PageModel pageModel, AppQuery query) { //查询映射 org.springframework.data.domain.Page list = appRepository.getAppList(query, - PageRequest.of(pageModel.getCurrent(), pageModel.getPageSize())); + PageRequest.of(pageModel.getCurrent(), pageModel.getPageSize())); return appConverter.entityConvertToAppListResult(list); } @@ -92,9 +90,14 @@ public class AppServiceImpl implements AppService { @Transactional(rollbackFor = Exception.class) public AppCreateResult createApp(AppCreateParam param) { ApplicationService applicationService = applicationServiceLoader - .getApplicationService(param.getTemplate()); - String appId = applicationService.create(param.getName(), param.getIcon(), - param.getRemark(), param.getGroupIds()); + .getApplicationService(param.getTemplate()); + String appId; + if (!CollectionUtils.isEmpty(param.getGroupIds())) { + appId = applicationService.create(param.getName(), param.getIcon(), param.getRemark(), + param.getGroupIds()); + } else { + appId = applicationService.create(param.getName(), param.getIcon(), param.getRemark()); + } AuditContext.setTarget(Target.builder().id(appId).type(TargetType.APPLICATION).build()); return new AppCreateResult(appId); } @@ -122,7 +125,7 @@ public class AppServiceImpl implements AppService { } 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; } @@ -138,7 +141,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; } @@ -196,10 +199,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; } @@ -214,7 +217,7 @@ public class AppServiceImpl implements AppService { Optional 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(); @@ -239,17 +242,17 @@ public class AppServiceImpl implements AppService { /** * ApplicationTemplateLoader */ - private final ApplicationServiceLoader applicationServiceLoader; + private final ApplicationServiceLoader applicationServiceLoader; /** * ApplicationRepository */ - private final AppRepository appRepository; + private final AppRepository appRepository; /** * ApplicationConverter */ - private final AppConverter appConverter; + private final AppConverter appConverter; /** * AppGroupAssociationRepositorys