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)
|
||||
@LoginRequired
|
||||
@LoginRequired(role = RoleEnum.ADMIN)
|
||||
public void importScene(@RequestPart("file") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
throw new SnailJobCommonException("Please select a file to upload");
|
||||
@ -119,6 +119,8 @@ public class GroupConfigController {
|
||||
List<GroupConfigRequestVO> requestList = JsonUtil.parseList(JsonUtil.toJsonString(node),
|
||||
GroupConfigRequestVO.class);
|
||||
|
||||
Assert.notEmpty(requestList, () -> new SnailJobServerException("导入数据不能为空"));
|
||||
|
||||
// 校验参数是否合法
|
||||
for (final GroupConfigRequestVO groupConfigRequestVO : requestList) {
|
||||
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
||||
@ -133,10 +135,9 @@ public class GroupConfigController {
|
||||
}
|
||||
|
||||
@PostMapping("/export")
|
||||
@LoginRequired
|
||||
@LoginRequired(role = RoleEnum.ADMIN)
|
||||
@OriginalControllerReturnValue
|
||||
public ResponseEntity<String> exportGroup(@RequestBody Set<Long> groupIds) {
|
||||
Assert.notEmpty(groupIds, () -> new SnailJobServerException("参数错误"));
|
||||
|
||||
String configs = groupConfigService.exportGroup(groupIds);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.aizuda.snailjob.server.web.controller;
|
||||
|
||||
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.exception.SnailJobCommonException;
|
||||
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.web.annotation.LoginRequired;
|
||||
import com.aizuda.snailjob.server.web.model.base.PageResult;
|
||||
@ -97,6 +99,8 @@ public class SceneConfigController {
|
||||
List<SceneConfigRequestVO> requestList = JsonUtil.parseList(JsonUtil.toJsonString(node),
|
||||
SceneConfigRequestVO.class);
|
||||
|
||||
Assert.notEmpty(requestList, () -> new SnailJobServerException("导入数据不能为空"));
|
||||
|
||||
// 校验参数是否合法
|
||||
for (final SceneConfigRequestVO sceneConfigRequestVO : requestList) {
|
||||
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
||||
|
@ -26,6 +26,7 @@ public class GroupConfigRequestVO {
|
||||
/**
|
||||
* 令牌
|
||||
*/
|
||||
@NotBlank(message = "令牌不能为空")
|
||||
private String token;
|
||||
|
||||
/**
|
||||
@ -36,17 +37,20 @@ public class GroupConfigRequestVO {
|
||||
/**
|
||||
* 分区
|
||||
*/
|
||||
@NotNull(message = "分区不能为空")
|
||||
private Integer groupPartition;
|
||||
|
||||
/**
|
||||
* 唯一id生成模式
|
||||
* {@link IdGeneratorModeEnum}
|
||||
*/
|
||||
@NotNull(message = "id生成模式不能为空")
|
||||
private Integer idGeneratorMode;
|
||||
|
||||
/**
|
||||
* 是否初始化场景
|
||||
*/
|
||||
@NotNull(message = "初始化场不能为空")
|
||||
private Integer initScene;
|
||||
|
||||
}
|
||||
|
@ -393,10 +393,14 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
||||
|
||||
Set<String> groupSet = StreamUtils.toSet(requestList, GroupConfigRequestVO::getGroupName);
|
||||
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)
|
||||
.in(GroupConfig::getGroupName, groupSet)) == 0,
|
||||
() -> new SnailJobServerException("GroupName已经存在 {}", groupSet));
|
||||
.in(GroupConfig::getGroupName, groupSet));
|
||||
|
||||
Assert.isTrue(CollUtil.isEmpty(configs),
|
||||
() -> new SnailJobServerException("导入失败. 原因: 组{}已存在", StreamUtils.toSet(configs, GroupConfig::getGroupName)));
|
||||
|
||||
for (final GroupConfigRequestVO groupConfigRequestVO : requestList) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user