🎨 优化策略定义逻辑.
This commit is contained in:
@@ -24,7 +24,7 @@ package org.dromara.visor.module.asset.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.dromara.visor.framework.common.handler.data.GenericsDataDefinition;
|
||||
import org.dromara.visor.framework.common.handler.data.GenericsStrategyDefinition;
|
||||
import org.dromara.visor.framework.common.handler.data.model.GenericsDataModel;
|
||||
import org.dromara.visor.framework.common.handler.data.strategy.GenericsDataStrategy;
|
||||
import org.dromara.visor.module.asset.handler.host.extra.strategy.HostLabelExtraStrategy;
|
||||
@@ -39,7 +39,7 @@ import org.dromara.visor.module.asset.handler.host.extra.strategy.HostSshExtraSt
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum HostExtraItemEnum implements GenericsDataDefinition {
|
||||
public enum HostExtraItemEnum implements GenericsStrategyDefinition {
|
||||
|
||||
/**
|
||||
* SSH 额外配置
|
||||
|
||||
@@ -24,7 +24,7 @@ package org.dromara.visor.module.asset.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.dromara.visor.framework.common.handler.data.GenericsDataDefinition;
|
||||
import org.dromara.visor.framework.common.handler.data.GenericsStrategyDefinition;
|
||||
import org.dromara.visor.framework.common.handler.data.model.GenericsDataModel;
|
||||
import org.dromara.visor.framework.common.handler.data.strategy.GenericsDataStrategy;
|
||||
import org.dromara.visor.module.asset.handler.host.config.strategy.HostSshConfigStrategy;
|
||||
@@ -38,7 +38,7 @@ import org.dromara.visor.module.asset.handler.host.config.strategy.HostSshConfig
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum HostTypeEnum implements GenericsDataDefinition {
|
||||
public enum HostTypeEnum implements GenericsStrategyDefinition {
|
||||
|
||||
/**
|
||||
* SSH
|
||||
|
||||
@@ -25,7 +25,6 @@ package org.dromara.visor.module.asset.service.impl;
|
||||
import cn.orionsec.kit.lang.function.Functions;
|
||||
import cn.orionsec.kit.lang.utils.collect.Maps;
|
||||
import org.dromara.visor.framework.common.handler.data.model.GenericsDataModel;
|
||||
import org.dromara.visor.framework.common.handler.data.strategy.GenericsDataStrategy;
|
||||
import org.dromara.visor.framework.common.utils.Valid;
|
||||
import org.dromara.visor.framework.security.core.utils.SecurityUtils;
|
||||
import org.dromara.visor.module.asset.entity.request.host.HostExtraQueryRequest;
|
||||
@@ -120,7 +119,6 @@ public class HostExtraServiceImpl implements HostExtraService {
|
||||
Long hostId = request.getHostId();
|
||||
Long userId = SecurityUtils.getLoginUserId();
|
||||
HostExtraItemEnum item = Valid.valid(HostExtraItemEnum::of, request.getItem());
|
||||
GenericsDataStrategy<GenericsDataModel> strategy = item.getStrategy();
|
||||
// 查询原始配置
|
||||
DataExtraQueryDTO query = DataExtraQueryDTO.builder()
|
||||
.userId(userId)
|
||||
@@ -136,7 +134,7 @@ public class HostExtraServiceImpl implements HostExtraService {
|
||||
GenericsDataModel newExtra = item.parse(request.getExtra());
|
||||
GenericsDataModel beforeExtra = item.parse(beforeExtraItem.getValue());
|
||||
// 更新验证
|
||||
strategy.doValid(beforeExtra, newExtra);
|
||||
item.doValid(beforeExtra, newExtra);
|
||||
// 更新配置
|
||||
return dataExtraApi.updateExtraValue(beforeExtraItem.getId(), newExtra.serial());
|
||||
}
|
||||
@@ -167,9 +165,8 @@ public class HostExtraServiceImpl implements HostExtraService {
|
||||
* @return defaultValue
|
||||
*/
|
||||
private String checkInitItem(HostExtraItemEnum item, Long userId, Long hostId) {
|
||||
GenericsDataStrategy<GenericsDataModel> strategy = item.getStrategy();
|
||||
// 初始化默认数据
|
||||
String extraValue = strategy.getDefault().serial();
|
||||
String extraValue = item.getDefault().serial();
|
||||
// 插入默认值
|
||||
DataExtraSetDTO set = DataExtraSetDTO.builder()
|
||||
.userId(userId)
|
||||
|
||||
@@ -116,7 +116,7 @@ public class HostServiceImpl implements HostService {
|
||||
this.checkHostNamePresent(record);
|
||||
this.checkHostCodePresent(record);
|
||||
// 设置主机配置
|
||||
record.setConfig(type.getStrategy().getDefault().serial());
|
||||
record.setConfig(type.getDefault().serial());
|
||||
// 插入主机
|
||||
int effect = hostDAO.insert(record);
|
||||
log.info("HostService-createHost effect: {}", effect);
|
||||
@@ -193,7 +193,7 @@ public class HostServiceImpl implements HostService {
|
||||
OperatorLogs.add(OperatorLogs.ID, id);
|
||||
OperatorLogs.add(OperatorLogs.NAME, host.getName());
|
||||
// 更新前校验
|
||||
type.getStrategy().doValid(beforeConfig, newConfig);
|
||||
type.doValid(beforeConfig, newConfig);
|
||||
// 修改配置
|
||||
HostDO updateHost = HostDO.builder()
|
||||
.id(id)
|
||||
|
||||
Reference in New Issue
Block a user