🔨 修改主机自动创建配置.
This commit is contained in:
@@ -37,6 +37,14 @@ import java.util.List;
|
||||
*/
|
||||
public interface HostConfigService {
|
||||
|
||||
/**
|
||||
* 初始化主机配置
|
||||
*
|
||||
* @param hostId hostId
|
||||
* @param types types
|
||||
*/
|
||||
void initHostConfig(Long hostId, List<String> types);
|
||||
|
||||
/**
|
||||
* 更新主机配置
|
||||
*
|
||||
|
||||
@@ -67,6 +67,34 @@ public class HostConfigServiceImpl implements HostConfigService {
|
||||
@Resource
|
||||
private HostConfigDAO hostConfigDAO;
|
||||
|
||||
@Override
|
||||
public void initHostConfig(Long hostId, List<String> types) {
|
||||
// 查询主机配置类型
|
||||
List<String> hostConfigTypes = hostConfigDAO.selectByHostId(hostId)
|
||||
.stream()
|
||||
.map(HostConfigDO::getType)
|
||||
.collect(Collectors.toList());
|
||||
List<HostConfigDO> configs = new ArrayList<>();
|
||||
for (String type : types) {
|
||||
// 配置存在则跳过
|
||||
if (hostConfigTypes.contains(type)) {
|
||||
continue;
|
||||
}
|
||||
// 配置不存在则初始化
|
||||
HostConfigDO config = HostConfigDO.builder()
|
||||
.hostId(hostId)
|
||||
.type(type)
|
||||
.status(EnableStatus.ENABLED.name())
|
||||
.config(HostConfigStrategyEnum.of(type).getDefault().serial())
|
||||
.build();
|
||||
configs.add(config);
|
||||
}
|
||||
// 插入主机配置
|
||||
if (!configs.isEmpty()) {
|
||||
hostConfigDAO.insertBatch(configs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateHostConfig(HostConfigUpdateRequest request) {
|
||||
log.info("HostConfigService-updateHostConfig request: {}", request);
|
||||
|
||||
@@ -128,8 +128,10 @@ public class HostServiceImpl implements HostService {
|
||||
this.checkHostCodePresent(record);
|
||||
// 插入主机
|
||||
int effect = hostDAO.insert(record);
|
||||
log.info("HostService-createHost effect: {}", effect);
|
||||
Long id = record.getId();
|
||||
log.info("HostService-createHost id: {}, effect: {}", id, effect);
|
||||
// 初始化主机配置
|
||||
hostConfigService.initHostConfig(id, request.getTypes());
|
||||
// 插入 tag
|
||||
tagRelApi.addTagRel(TagTypeEnum.HOST, id, request.getTags());
|
||||
// 引用分组
|
||||
@@ -183,6 +185,8 @@ public class HostServiceImpl implements HostService {
|
||||
// 修改 config 状态
|
||||
hostConfigDAO.updateConfigStatus(id, types, EnableStatus.ENABLED.name());
|
||||
hostConfigDAO.updateConfigInvertStatus(id, types, EnableStatus.DISABLED.name());
|
||||
// 初始化主机配置
|
||||
hostConfigService.initHostConfig(id, types);
|
||||
// 删除缓存
|
||||
this.clearCache();
|
||||
return effect;
|
||||
|
||||
@@ -27,8 +27,6 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件操作请求 实体对象
|
||||
*
|
||||
@@ -62,11 +60,6 @@ public class TransferOperatorRequest {
|
||||
*/
|
||||
private Long hostId;
|
||||
|
||||
/**
|
||||
* 被压缩文件路径
|
||||
*/
|
||||
private List<String> paths;
|
||||
|
||||
/**
|
||||
* 错误信息 后端赋值
|
||||
*/
|
||||
|
||||
@@ -133,6 +133,7 @@
|
||||
|
||||
// 更新主机信息
|
||||
const onUpdateHostInfo = (id: number) => {
|
||||
title.value = '修改主机';
|
||||
hostId.value = id;
|
||||
hostViewUpdated.value = true;
|
||||
};
|
||||
|
||||
@@ -194,11 +194,13 @@
|
||||
// 复制
|
||||
const { data } = await copyHost(formModel.value);
|
||||
Message.success('复制成功');
|
||||
formModel.value.id = data;
|
||||
emits('updated', data);
|
||||
} else if (!formModel.value.id) {
|
||||
// 新增
|
||||
const { data } = await createHost(formModel.value);
|
||||
Message.success('创建成功');
|
||||
formModel.value.id = data;
|
||||
emits('updated', data);
|
||||
} else {
|
||||
// 修改
|
||||
|
||||
Reference in New Issue
Block a user