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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user