pull/48/head
smallbun 1 year ago
parent efff5b4613
commit 0473ca0e7c

@ -17,6 +17,7 @@
*/ */
package cn.topiam.employee.application; package cn.topiam.employee.application;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -86,6 +87,19 @@ public interface ApplicationService {
*/ */
String getBase64Icon(); 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<>());
}
/** /**
* *
* *

@ -17,10 +17,7 @@
*/ */
package cn.topiam.employee.console.service.app.impl; package cn.topiam.employee.console.service.app.impl;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity; import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity;
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository; import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
@ -52,6 +49,7 @@ import cn.topiam.employee.support.util.BeanUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; 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_BY;
import static cn.topiam.employee.support.repository.domain.BaseEntity.LAST_MODIFIED_TIME; import static cn.topiam.employee.support.repository.domain.BaseEntity.LAST_MODIFIED_TIME;
@ -78,7 +76,7 @@ public class AppServiceImpl implements AppService {
public Page<AppListResult> getAppList(PageModel pageModel, AppQuery query) { public Page<AppListResult> getAppList(PageModel pageModel, AppQuery query) {
//查询映射 //查询映射
org.springframework.data.domain.Page<AppEntity> list = appRepository.getAppList(query, org.springframework.data.domain.Page<AppEntity> list = appRepository.getAppList(query,
PageRequest.of(pageModel.getCurrent(), pageModel.getPageSize())); PageRequest.of(pageModel.getCurrent(), pageModel.getPageSize()));
return appConverter.entityConvertToAppListResult(list); return appConverter.entityConvertToAppListResult(list);
} }
@ -92,9 +90,14 @@ public class AppServiceImpl implements AppService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public AppCreateResult createApp(AppCreateParam param) { public AppCreateResult createApp(AppCreateParam param) {
ApplicationService applicationService = applicationServiceLoader ApplicationService applicationService = applicationServiceLoader
.getApplicationService(param.getTemplate()); .getApplicationService(param.getTemplate());
String appId = applicationService.create(param.getName(), param.getIcon(), String appId;
param.getRemark(), param.getGroupIds()); 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()); AuditContext.setTarget(Target.builder().id(appId).type(TargetType.APPLICATION).build());
return new AppCreateResult(appId); return new AppCreateResult(appId);
} }
@ -122,7 +125,7 @@ public class AppServiceImpl implements AppService {
} }
appGroupAssociationRepository.saveAll(list); appGroupAssociationRepository.saveAll(list);
AuditContext.setTarget( AuditContext.setTarget(
Target.builder().id(param.getId().toString()).type(TargetType.APPLICATION).build()); Target.builder().id(param.getId().toString()).type(TargetType.APPLICATION).build());
return true; return true;
} }
@ -138,7 +141,7 @@ public class AppServiceImpl implements AppService {
AppEntity app = appRequireNonNull(id); AppEntity app = appRequireNonNull(id);
applicationServiceLoader.getApplicationService(app.getTemplate()).delete(id.toString()); applicationServiceLoader.getApplicationService(app.getTemplate()).delete(id.toString());
AuditContext AuditContext
.setTarget(Target.builder().id(id.toString()).type(TargetType.APPLICATION).build()); .setTarget(Target.builder().id(id.toString()).type(TargetType.APPLICATION).build());
return true; return true;
} }
@ -196,10 +199,10 @@ public class AppServiceImpl implements AppService {
@Override @Override
public Boolean saveAppConfig(AppSaveConfigParam param) { public Boolean saveAppConfig(AppSaveConfigParam param) {
ApplicationService applicationService = applicationServiceLoader ApplicationService applicationService = applicationServiceLoader
.getApplicationService(param.getTemplate()); .getApplicationService(param.getTemplate());
applicationService.saveConfig(param.getId(), param.getConfig()); applicationService.saveConfig(param.getId(), param.getConfig());
AuditContext AuditContext
.setTarget(Target.builder().id(param.getId()).type(TargetType.APPLICATION).build()); .setTarget(Target.builder().id(param.getId()).type(TargetType.APPLICATION).build());
return true; return true;
} }
@ -214,7 +217,7 @@ public class AppServiceImpl implements AppService {
Optional<AppEntity> optional = appRepository.findById(Long.valueOf(appId)); Optional<AppEntity> optional = appRepository.findById(Long.valueOf(appId));
if (optional.isPresent()) { if (optional.isPresent()) {
ApplicationService applicationService = applicationServiceLoader ApplicationService applicationService = applicationServiceLoader
.getApplicationService(optional.get().getTemplate()); .getApplicationService(optional.get().getTemplate());
return applicationService.getConfig(appId); return applicationService.getConfig(appId);
} }
throw new AppNotExistException(); throw new AppNotExistException();
@ -239,17 +242,17 @@ public class AppServiceImpl implements AppService {
/** /**
* ApplicationTemplateLoader * ApplicationTemplateLoader
*/ */
private final ApplicationServiceLoader applicationServiceLoader; private final ApplicationServiceLoader applicationServiceLoader;
/** /**
* ApplicationRepository * ApplicationRepository
*/ */
private final AppRepository appRepository; private final AppRepository appRepository;
/** /**
* ApplicationConverter * ApplicationConverter
*/ */
private final AppConverter appConverter; private final AppConverter appConverter;
/** /**
* AppGroupAssociationRepositorys * AppGroupAssociationRepositorys

Loading…
Cancel
Save