feat(sj_1.0.0): 完成组导入导出
This commit is contained in:
parent
50483b5c2a
commit
285ead5518
@ -102,7 +102,7 @@ public class GroupConfigController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@LoginRequired
|
@LoginRequired(role = RoleEnum.ADMIN)
|
||||||
public void importScene(@RequestPart("file") MultipartFile file) throws IOException {
|
public void importScene(@RequestPart("file") MultipartFile file) throws IOException {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
throw new SnailJobCommonException("Please select a file to upload");
|
throw new SnailJobCommonException("Please select a file to upload");
|
||||||
@ -119,6 +119,8 @@ public class GroupConfigController {
|
|||||||
List<GroupConfigRequestVO> requestList = JsonUtil.parseList(JsonUtil.toJsonString(node),
|
List<GroupConfigRequestVO> requestList = JsonUtil.parseList(JsonUtil.toJsonString(node),
|
||||||
GroupConfigRequestVO.class);
|
GroupConfigRequestVO.class);
|
||||||
|
|
||||||
|
Assert.notEmpty(requestList, () -> new SnailJobServerException("导入数据不能为空"));
|
||||||
|
|
||||||
// 校验参数是否合法
|
// 校验参数是否合法
|
||||||
for (final GroupConfigRequestVO groupConfigRequestVO : requestList) {
|
for (final GroupConfigRequestVO groupConfigRequestVO : requestList) {
|
||||||
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
||||||
@ -133,10 +135,9 @@ public class GroupConfigController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
@LoginRequired
|
@LoginRequired(role = RoleEnum.ADMIN)
|
||||||
@OriginalControllerReturnValue
|
@OriginalControllerReturnValue
|
||||||
public ResponseEntity<String> exportGroup(@RequestBody Set<Long> groupIds) {
|
public ResponseEntity<String> exportGroup(@RequestBody Set<Long> groupIds) {
|
||||||
Assert.notEmpty(groupIds, () -> new SnailJobServerException("参数错误"));
|
|
||||||
|
|
||||||
String configs = groupConfigService.exportGroup(groupIds);
|
String configs = groupConfigService.exportGroup(groupIds);
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.aizuda.snailjob.server.web.controller;
|
package com.aizuda.snailjob.server.web.controller;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import com.aizuda.snailjob.common.core.annotation.OriginalControllerReturnValue;
|
import com.aizuda.snailjob.common.core.annotation.OriginalControllerReturnValue;
|
||||||
import com.aizuda.snailjob.common.core.exception.SnailJobCommonException;
|
import com.aizuda.snailjob.common.core.exception.SnailJobCommonException;
|
||||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||||
|
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
||||||
import com.aizuda.snailjob.server.common.util.DateUtils;
|
import com.aizuda.snailjob.server.common.util.DateUtils;
|
||||||
import com.aizuda.snailjob.server.web.annotation.LoginRequired;
|
import com.aizuda.snailjob.server.web.annotation.LoginRequired;
|
||||||
import com.aizuda.snailjob.server.web.model.base.PageResult;
|
import com.aizuda.snailjob.server.web.model.base.PageResult;
|
||||||
@ -97,6 +99,8 @@ public class SceneConfigController {
|
|||||||
List<SceneConfigRequestVO> requestList = JsonUtil.parseList(JsonUtil.toJsonString(node),
|
List<SceneConfigRequestVO> requestList = JsonUtil.parseList(JsonUtil.toJsonString(node),
|
||||||
SceneConfigRequestVO.class);
|
SceneConfigRequestVO.class);
|
||||||
|
|
||||||
|
Assert.notEmpty(requestList, () -> new SnailJobServerException("导入数据不能为空"));
|
||||||
|
|
||||||
// 校验参数是否合法
|
// 校验参数是否合法
|
||||||
for (final SceneConfigRequestVO sceneConfigRequestVO : requestList) {
|
for (final SceneConfigRequestVO sceneConfigRequestVO : requestList) {
|
||||||
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
||||||
|
@ -26,6 +26,7 @@ public class GroupConfigRequestVO {
|
|||||||
/**
|
/**
|
||||||
* 令牌
|
* 令牌
|
||||||
*/
|
*/
|
||||||
|
@NotBlank(message = "令牌不能为空")
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,17 +37,20 @@ public class GroupConfigRequestVO {
|
|||||||
/**
|
/**
|
||||||
* 分区
|
* 分区
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "分区不能为空")
|
||||||
private Integer groupPartition;
|
private Integer groupPartition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 唯一id生成模式
|
* 唯一id生成模式
|
||||||
* {@link IdGeneratorModeEnum}
|
* {@link IdGeneratorModeEnum}
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "id生成模式不能为空")
|
||||||
private Integer idGeneratorMode;
|
private Integer idGeneratorMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否初始化场景
|
* 是否初始化场景
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "初始化场不能为空")
|
||||||
private Integer initScene;
|
private Integer initScene;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -77,9 +77,9 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
|
|
||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
Assert.isTrue(groupConfigAccess.count(new LambdaQueryWrapper<GroupConfig>()
|
Assert.isTrue(groupConfigAccess.count(new LambdaQueryWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, namespaceId)
|
.eq(GroupConfig::getNamespaceId, namespaceId)
|
||||||
.eq(GroupConfig::getGroupName, groupConfigRequestVO.getGroupName())) == 0,
|
.eq(GroupConfig::getGroupName, groupConfigRequestVO.getGroupName())) == 0,
|
||||||
() -> new SnailJobServerException("GroupName已经存在 {}", groupConfigRequestVO.getGroupName()));
|
() -> new SnailJobServerException("GroupName已经存在 {}", groupConfigRequestVO.getGroupName()));
|
||||||
|
|
||||||
// 保存组配置
|
// 保存组配置
|
||||||
Boolean isSuccess = doSaveGroupConfig(namespaceId, groupConfigRequestVO);
|
Boolean isSuccess = doSaveGroupConfig(namespaceId, groupConfigRequestVO);
|
||||||
@ -103,8 +103,8 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
sequenceAlloc.setStep(systemProperties.getStep());
|
sequenceAlloc.setStep(systemProperties.getStep());
|
||||||
sequenceAlloc.setUpdateDt(LocalDateTime.now());
|
sequenceAlloc.setUpdateDt(LocalDateTime.now());
|
||||||
Assert.isTrue(1 == sequenceAllocMapper.insert(sequenceAlloc),
|
Assert.isTrue(1 == sequenceAllocMapper.insert(sequenceAlloc),
|
||||||
() -> new SnailJobServerException("failed to save sequence generation rule configuration [{}].",
|
() -> new SnailJobServerException("failed to save sequence generation rule configuration [{}].",
|
||||||
groupConfigRequestVO.getGroupName()));
|
groupConfigRequestVO.getGroupName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -121,9 +121,9 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
|
|
||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
long count = groupConfigAccess.count(
|
long count = groupConfigAccess.count(
|
||||||
new LambdaQueryWrapper<GroupConfig>()
|
new LambdaQueryWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, namespaceId)
|
.eq(GroupConfig::getNamespaceId, namespaceId)
|
||||||
.eq(GroupConfig::getGroupName, groupName));
|
.eq(GroupConfig::getGroupName, groupName));
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -134,19 +134,19 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
groupConfig.setVersion(1);
|
groupConfig.setVersion(1);
|
||||||
groupConfig.setToken(null);
|
groupConfig.setToken(null);
|
||||||
Assert.isTrue(tablePartitionList.contains(groupConfigRequestVO.getGroupPartition()),
|
Assert.isTrue(tablePartitionList.contains(groupConfigRequestVO.getGroupPartition()),
|
||||||
() -> new SnailJobServerException("分区不存在. [{}]", tablePartitionList));
|
() -> new SnailJobServerException("分区不存在. [{}]", tablePartitionList));
|
||||||
Assert.isTrue(groupConfigRequestVO.getGroupPartition() >= 0,
|
Assert.isTrue(groupConfigRequestVO.getGroupPartition() >= 0,
|
||||||
() -> new SnailJobServerException("分区不能是负数."));
|
() -> new SnailJobServerException("分区不能是负数."));
|
||||||
|
|
||||||
// 校验retry_task_x和retry_dead_letter_x是否存在
|
// 校验retry_task_x和retry_dead_letter_x是否存在
|
||||||
checkGroupPartition(groupConfig, namespaceId);
|
checkGroupPartition(groupConfig, namespaceId);
|
||||||
|
|
||||||
Assert.isTrue(1 == groupConfigAccess.update(groupConfig,
|
Assert.isTrue(1 == groupConfigAccess.update(groupConfig,
|
||||||
new LambdaUpdateWrapper<GroupConfig>()
|
new LambdaUpdateWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, namespaceId)
|
.eq(GroupConfig::getNamespaceId, namespaceId)
|
||||||
.eq(GroupConfig::getGroupName, groupName)),
|
.eq(GroupConfig::getGroupName, groupName)),
|
||||||
() -> new SnailJobServerException("exception occurred while adding group. groupConfigVO[{}]",
|
() -> new SnailJobServerException("exception occurred while adding group. groupConfigVO[{}]",
|
||||||
groupConfigRequestVO));
|
groupConfigRequestVO));
|
||||||
|
|
||||||
// 同步版本, 版本为0代表需要同步到客户端
|
// 同步版本, 版本为0代表需要同步到客户端
|
||||||
boolean add = configVersionSyncHandler.addSyncTask(groupName, namespaceId, 0);
|
boolean add = configVersionSyncHandler.addSyncTask(groupName, namespaceId, 0);
|
||||||
@ -163,9 +163,9 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
groupConfig.setGroupStatus(status);
|
groupConfig.setGroupStatus(status);
|
||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
return groupConfigAccess.update(groupConfig,
|
return groupConfigAccess.update(groupConfig,
|
||||||
new LambdaUpdateWrapper<GroupConfig>()
|
new LambdaUpdateWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, UserSessionUtils.currentUserSession().getNamespaceId())
|
.eq(GroupConfig::getNamespaceId, UserSessionUtils.currentUserSession().getNamespaceId())
|
||||||
.eq(GroupConfig::getGroupName, groupName)) == 1;
|
.eq(GroupConfig::getGroupName, groupName)) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -176,30 +176,30 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
|
|
||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
PageDTO<GroupConfig> groupConfigPageDTO = groupConfigAccess.listPage(
|
PageDTO<GroupConfig> groupConfigPageDTO = groupConfigAccess.listPage(
|
||||||
new PageDTO<>(queryVO.getPage(), queryVO.getSize()),
|
new PageDTO<>(queryVO.getPage(), queryVO.getSize()),
|
||||||
new LambdaQueryWrapper<GroupConfig>()
|
new LambdaQueryWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, namespaceId)
|
.eq(GroupConfig::getNamespaceId, namespaceId)
|
||||||
.in(userSessionVO.isUser(), GroupConfig::getGroupName, userSessionVO.getGroupNames())
|
.in(userSessionVO.isUser(), GroupConfig::getGroupName, userSessionVO.getGroupNames())
|
||||||
.likeRight(StrUtil.isNotBlank(queryVO.getGroupName()), GroupConfig::getGroupName,
|
.likeRight(StrUtil.isNotBlank(queryVO.getGroupName()), GroupConfig::getGroupName,
|
||||||
StrUtil.trim(queryVO.getGroupName()))
|
StrUtil.trim(queryVO.getGroupName()))
|
||||||
.orderByDesc(GroupConfig::getId));
|
.orderByDesc(GroupConfig::getId));
|
||||||
List<GroupConfig> records = groupConfigPageDTO.getRecords();
|
List<GroupConfig> records = groupConfigPageDTO.getRecords();
|
||||||
if (CollUtil.isEmpty(records)) {
|
if (CollUtil.isEmpty(records)) {
|
||||||
return new PageResult<>(groupConfigPageDTO.getCurrent(), groupConfigPageDTO.getSize(),
|
return new PageResult<>(groupConfigPageDTO.getCurrent(), groupConfigPageDTO.getSize(),
|
||||||
groupConfigPageDTO.getTotal());
|
groupConfigPageDTO.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
PageResult<List<GroupConfigResponseVO>> pageResult = new PageResult<>(groupConfigPageDTO.getCurrent(),
|
PageResult<List<GroupConfigResponseVO>> pageResult = new PageResult<>(groupConfigPageDTO.getCurrent(),
|
||||||
groupConfigPageDTO.getSize(), groupConfigPageDTO.getTotal());
|
groupConfigPageDTO.getSize(), groupConfigPageDTO.getTotal());
|
||||||
|
|
||||||
List<GroupConfigResponseVO> responseVOList = GroupConfigResponseVOConverter.INSTANCE.convertList(
|
List<GroupConfigResponseVO> responseVOList = GroupConfigResponseVOConverter.INSTANCE.convertList(
|
||||||
records);
|
records);
|
||||||
|
|
||||||
for (GroupConfigResponseVO groupConfigResponseVO : responseVOList) {
|
for (GroupConfigResponseVO groupConfigResponseVO : responseVOList) {
|
||||||
Optional.ofNullable(IdGeneratorModeEnum.modeOf(groupConfigResponseVO.getIdGeneratorMode()))
|
Optional.ofNullable(IdGeneratorModeEnum.modeOf(groupConfigResponseVO.getIdGeneratorMode()))
|
||||||
.ifPresent(idGeneratorMode -> {
|
.ifPresent(idGeneratorMode -> {
|
||||||
groupConfigResponseVO.setIdGeneratorModeName(idGeneratorMode.getDesc());
|
groupConfigResponseVO.setIdGeneratorModeName(idGeneratorMode.getDesc());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pageResult.setData(responseVOList);
|
pageResult.setData(responseVOList);
|
||||||
@ -222,19 +222,19 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
groupConfig.setDescription(Optional.ofNullable(groupConfigRequestVO.getDescription()).orElse(StrUtil.EMPTY));
|
groupConfig.setDescription(Optional.ofNullable(groupConfigRequestVO.getDescription()).orElse(StrUtil.EMPTY));
|
||||||
if (Objects.isNull(groupConfigRequestVO.getGroupPartition())) {
|
if (Objects.isNull(groupConfigRequestVO.getGroupPartition())) {
|
||||||
groupConfig.setGroupPartition(
|
groupConfig.setGroupPartition(
|
||||||
HashUtil.bkdrHash(groupConfigRequestVO.getGroupName()) % tablePartitionList.size());
|
HashUtil.bkdrHash(groupConfigRequestVO.getGroupName()) % tablePartitionList.size());
|
||||||
} else {
|
} else {
|
||||||
Assert.isTrue(tablePartitionList.contains(groupConfigRequestVO.getGroupPartition()),
|
Assert.isTrue(tablePartitionList.contains(groupConfigRequestVO.getGroupPartition()),
|
||||||
() -> new SnailJobServerException("分区不存在. [{}]", tablePartitionList));
|
() -> new SnailJobServerException("分区不存在. [{}]", tablePartitionList));
|
||||||
Assert.isTrue(groupConfigRequestVO.getGroupPartition() >= 0,
|
Assert.isTrue(groupConfigRequestVO.getGroupPartition() >= 0,
|
||||||
() -> new SnailJobServerException("分区不能是负数."));
|
() -> new SnailJobServerException("分区不能是负数."));
|
||||||
}
|
}
|
||||||
|
|
||||||
groupConfig.setBucketIndex(
|
groupConfig.setBucketIndex(
|
||||||
HashUtil.bkdrHash(groupConfigRequestVO.getGroupName()) % systemProperties.getBucketTotal());
|
HashUtil.bkdrHash(groupConfigRequestVO.getGroupName()) % systemProperties.getBucketTotal());
|
||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
Assert.isTrue(1 == groupConfigAccess.insert(groupConfig),
|
Assert.isTrue(1 == groupConfigAccess.insert(groupConfig),
|
||||||
() -> new SnailJobServerException("新增组异常异常 groupConfigVO[{}]", groupConfigRequestVO));
|
() -> new SnailJobServerException("新增组异常异常 groupConfigVO[{}]", groupConfigRequestVO));
|
||||||
|
|
||||||
// 校验retry_task_x和retry_dead_letter_x是否存在
|
// 校验retry_task_x和retry_dead_letter_x是否存在
|
||||||
checkGroupPartition(groupConfig, namespaceId);
|
checkGroupPartition(groupConfig, namespaceId);
|
||||||
@ -249,12 +249,12 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
try {
|
try {
|
||||||
TaskAccess<RetryTask> retryTaskAccess = accessTemplate.getRetryTaskAccess();
|
TaskAccess<RetryTask> retryTaskAccess = accessTemplate.getRetryTaskAccess();
|
||||||
retryTaskAccess.count(groupConfig.getGroupName(), namespaceId,
|
retryTaskAccess.count(groupConfig.getGroupName(), namespaceId,
|
||||||
new LambdaQueryWrapper<RetryTask>().eq(RetryTask::getId, 1));
|
new LambdaQueryWrapper<RetryTask>().eq(RetryTask::getId, 1));
|
||||||
} catch (BadSqlGrammarException e) {
|
} catch (BadSqlGrammarException e) {
|
||||||
Optional.ofNullable(e.getMessage()).ifPresent(s -> {
|
Optional.ofNullable(e.getMessage()).ifPresent(s -> {
|
||||||
if (s.contains("retry_task_" + groupConfig.getGroupPartition()) && s.contains("doesn't exist")) {
|
if (s.contains("retry_task_" + groupConfig.getGroupPartition()) && s.contains("doesn't exist")) {
|
||||||
throw new SnailJobServerException("分区:[{}] '未配置表retry_task_{}', 请联系管理员进行配置",
|
throw new SnailJobServerException("分区:[{}] '未配置表retry_task_{}', 请联系管理员进行配置",
|
||||||
groupConfig.getGroupPartition(), groupConfig.getGroupPartition());
|
groupConfig.getGroupPartition(), groupConfig.getGroupPartition());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -262,12 +262,12 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
try {
|
try {
|
||||||
TaskAccess<RetryDeadLetter> retryTaskAccess = accessTemplate.getRetryDeadLetterAccess();
|
TaskAccess<RetryDeadLetter> retryTaskAccess = accessTemplate.getRetryDeadLetterAccess();
|
||||||
retryTaskAccess.one(groupConfig.getGroupName(), namespaceId,
|
retryTaskAccess.one(groupConfig.getGroupName(), namespaceId,
|
||||||
new LambdaQueryWrapper<RetryDeadLetter>().eq(RetryDeadLetter::getId, 1));
|
new LambdaQueryWrapper<RetryDeadLetter>().eq(RetryDeadLetter::getId, 1));
|
||||||
} catch (BadSqlGrammarException e) {
|
} catch (BadSqlGrammarException e) {
|
||||||
Optional.ofNullable(e.getMessage()).ifPresent(s -> {
|
Optional.ofNullable(e.getMessage()).ifPresent(s -> {
|
||||||
if (s.contains("retry_dead_letter_" + groupConfig.getGroupPartition()) && s.contains("doesn't exist")) {
|
if (s.contains("retry_dead_letter_" + groupConfig.getGroupPartition()) && s.contains("doesn't exist")) {
|
||||||
throw new SnailJobServerException("分区:[{}] '未配置表retry_dead_letter_{}', 请联系管理员进行配置",
|
throw new SnailJobServerException("分区:[{}] '未配置表retry_dead_letter_{}', 请联系管理员进行配置",
|
||||||
groupConfig.getGroupPartition(), groupConfig.getGroupPartition());
|
groupConfig.getGroupPartition(), groupConfig.getGroupPartition());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -278,12 +278,12 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
|
|
||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
GroupConfig groupConfig = groupConfigAccess.one(
|
GroupConfig groupConfig = groupConfigAccess.one(
|
||||||
new LambdaQueryWrapper<GroupConfig>()
|
new LambdaQueryWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, UserSessionUtils.currentUserSession().getNamespaceId())
|
.eq(GroupConfig::getNamespaceId, UserSessionUtils.currentUserSession().getNamespaceId())
|
||||||
.eq(GroupConfig::getGroupName, groupName));
|
.eq(GroupConfig::getGroupName, groupName));
|
||||||
|
|
||||||
GroupConfigResponseVO groupConfigResponseVO = GroupConfigResponseVOConverter.INSTANCE.convert(
|
GroupConfigResponseVO groupConfigResponseVO = GroupConfigResponseVOConverter.INSTANCE.convert(
|
||||||
groupConfig);
|
groupConfig);
|
||||||
|
|
||||||
Optional.ofNullable(IdGeneratorModeEnum.modeOf(groupConfig.getIdGeneratorMode())).ifPresent(idGeneratorMode -> {
|
Optional.ofNullable(IdGeneratorModeEnum.modeOf(groupConfig.getIdGeneratorMode())).ifPresent(idGeneratorMode -> {
|
||||||
groupConfigResponseVO.setIdGeneratorModeName(idGeneratorMode.getDesc());
|
groupConfigResponseVO.setIdGeneratorModeName(idGeneratorMode.getDesc());
|
||||||
@ -298,21 +298,21 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
|
|
||||||
List<GroupConfig> groupConfigs = groupConfigAccess.list(
|
List<GroupConfig> groupConfigs = groupConfigAccess.list(
|
||||||
new LambdaQueryWrapper<GroupConfig>()
|
new LambdaQueryWrapper<GroupConfig>()
|
||||||
.select(GroupConfig::getGroupName, GroupConfig::getNamespaceId)
|
.select(GroupConfig::getGroupName, GroupConfig::getNamespaceId)
|
||||||
.in(CollUtil.isNotEmpty(namespaceIds), GroupConfig::getNamespaceId, namespaceIds));
|
.in(CollUtil.isNotEmpty(namespaceIds), GroupConfig::getNamespaceId, namespaceIds));
|
||||||
if (CollUtil.isEmpty(groupConfigs)) {
|
if (CollUtil.isEmpty(groupConfigs)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Namespace> namespaces = namespaceMapper.selectList(
|
List<Namespace> namespaces = namespaceMapper.selectList(
|
||||||
new LambdaQueryWrapper<Namespace>()
|
new LambdaQueryWrapper<Namespace>()
|
||||||
.in(Namespace::getUniqueId, StreamUtils.toSet(groupConfigs, GroupConfig::getNamespaceId)));
|
.in(Namespace::getUniqueId, StreamUtils.toSet(groupConfigs, GroupConfig::getNamespaceId)));
|
||||||
|
|
||||||
Map<String, String> namespaceMap = StreamUtils.toMap(namespaces, Namespace::getUniqueId, Namespace::getName);
|
Map<String, String> namespaceMap = StreamUtils.toMap(namespaces, Namespace::getUniqueId, Namespace::getName);
|
||||||
|
|
||||||
List<GroupConfigResponseVO> groupConfigResponses = GroupConfigResponseVOConverter.INSTANCE.convertList(
|
List<GroupConfigResponseVO> groupConfigResponses = GroupConfigResponseVOConverter.INSTANCE.convertList(
|
||||||
groupConfigs);
|
groupConfigs);
|
||||||
for (final GroupConfigResponseVO groupConfigResponseVO : groupConfigResponses) {
|
for (final GroupConfigResponseVO groupConfigResponseVO : groupConfigResponses) {
|
||||||
groupConfigResponseVO.setNamespaceName(namespaceMap.get(groupConfigResponseVO.getNamespaceId()));
|
groupConfigResponseVO.setNamespaceName(namespaceMap.get(groupConfigResponseVO.getNamespaceId()));
|
||||||
}
|
}
|
||||||
@ -330,8 +330,8 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
|
|
||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
List<GroupConfig> groupConfigs = groupConfigAccess.list(new LambdaQueryWrapper<GroupConfig>()
|
List<GroupConfig> groupConfigs = groupConfigAccess.list(new LambdaQueryWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, userSessionVO.getNamespaceId())
|
.eq(GroupConfig::getNamespaceId, userSessionVO.getNamespaceId())
|
||||||
.select(GroupConfig::getGroupName));
|
.select(GroupConfig::getGroupName));
|
||||||
|
|
||||||
return StreamUtils.toList(groupConfigs, GroupConfig::getGroupName);
|
return StreamUtils.toList(groupConfigs, GroupConfig::getGroupName);
|
||||||
}
|
}
|
||||||
@ -339,9 +339,9 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getOnlinePods(String groupName) {
|
public List<String> getOnlinePods(String groupName) {
|
||||||
List<ServerNode> serverNodes = serverNodeMapper.selectList(
|
List<ServerNode> serverNodes = serverNodeMapper.selectList(
|
||||||
new LambdaQueryWrapper<ServerNode>()
|
new LambdaQueryWrapper<ServerNode>()
|
||||||
.eq(ServerNode::getNamespaceId, UserSessionUtils.currentUserSession().getNamespaceId())
|
.eq(ServerNode::getNamespaceId, UserSessionUtils.currentUserSession().getNamespaceId())
|
||||||
.eq(ServerNode::getGroupName, groupName));
|
.eq(ServerNode::getGroupName, groupName));
|
||||||
return StreamUtils.toList(serverNodes, serverNode -> serverNode.getHostIp() + ":" + serverNode.getHostPort());
|
return StreamUtils.toList(serverNodes, serverNode -> serverNode.getHostIp() + ":" + serverNode.getHostPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,8 +371,8 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return tableList.stream().map(ReUtil::getFirstNumber).filter(i ->
|
return tableList.stream().map(ReUtil::getFirstNumber).filter(i ->
|
||||||
!Objects.isNull(i)).distinct()
|
!Objects.isNull(i)).distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} catch (SQLException ignored) {
|
} catch (SQLException ignored) {
|
||||||
} finally {
|
} finally {
|
||||||
if (Objects.nonNull(connection)) {
|
if (Objects.nonNull(connection)) {
|
||||||
@ -393,10 +393,14 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
|
|
||||||
Set<String> groupSet = StreamUtils.toSet(requestList, GroupConfigRequestVO::getGroupName);
|
Set<String> groupSet = StreamUtils.toSet(requestList, GroupConfigRequestVO::getGroupName);
|
||||||
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
ConfigAccess<GroupConfig> groupConfigAccess = accessTemplate.getGroupConfigAccess();
|
||||||
Assert.isTrue(groupConfigAccess.count(new LambdaQueryWrapper<GroupConfig>()
|
|
||||||
|
List<GroupConfig> configs = groupConfigAccess.list(new LambdaQueryWrapper<GroupConfig>()
|
||||||
|
.select(GroupConfig::getGroupName)
|
||||||
.eq(GroupConfig::getNamespaceId, namespaceId)
|
.eq(GroupConfig::getNamespaceId, namespaceId)
|
||||||
.in(GroupConfig::getGroupName, groupSet)) == 0,
|
.in(GroupConfig::getGroupName, groupSet));
|
||||||
() -> new SnailJobServerException("GroupName已经存在 {}", groupSet));
|
|
||||||
|
Assert.isTrue(CollUtil.isEmpty(configs),
|
||||||
|
() -> new SnailJobServerException("导入失败. 原因: 组{}已存在", StreamUtils.toSet(configs, GroupConfig::getGroupName)));
|
||||||
|
|
||||||
for (final GroupConfigRequestVO groupConfigRequestVO : requestList) {
|
for (final GroupConfigRequestVO groupConfigRequestVO : requestList) {
|
||||||
|
|
||||||
@ -415,9 +419,9 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
String namespaceId = UserSessionUtils.currentUserSession().getNamespaceId();
|
String namespaceId = UserSessionUtils.currentUserSession().getNamespaceId();
|
||||||
|
|
||||||
List<GroupConfig> groupConfigs = accessTemplate.getGroupConfigAccess().list(
|
List<GroupConfig> groupConfigs = accessTemplate.getGroupConfigAccess().list(
|
||||||
new LambdaQueryWrapper<GroupConfig>()
|
new LambdaQueryWrapper<GroupConfig>()
|
||||||
.eq(GroupConfig::getNamespaceId, namespaceId)
|
.eq(GroupConfig::getNamespaceId, namespaceId)
|
||||||
.in(CollUtil.isNotEmpty(groupIds), GroupConfig::getId, groupIds)
|
.in(CollUtil.isNotEmpty(groupIds), GroupConfig::getId, groupIds)
|
||||||
);
|
);
|
||||||
|
|
||||||
return JsonUtil.toJsonString(GroupConfigConverter.INSTANCE.toGroupConfigRequestVOs(groupConfigs));
|
return JsonUtil.toJsonString(GroupConfigConverter.INSTANCE.toGroupConfigRequestVOs(groupConfigs));
|
||||||
|
Loading…
Reference in New Issue
Block a user