🔨 模板主机后端服务.
This commit is contained in:
@@ -35,11 +35,12 @@ services:
|
|||||||
- /data/orion-ops-pro-space/docker-volumes/mysql/etc-mysql:/etc/mysql
|
- /data/orion-ops-pro-space/docker-volumes/mysql/etc-mysql:/etc/mysql
|
||||||
orion-ops-pro-redis:
|
orion-ops-pro-redis:
|
||||||
image: redis:6.0.16-alpine
|
image: redis:6.0.16-alpine
|
||||||
command: redis-server --requirepass Data@123456
|
command: redis-server --appendonly yes --requirepass Data@123456
|
||||||
ports:
|
ports:
|
||||||
- 6380:6379
|
- 6380:6379
|
||||||
volumes:
|
volumes:
|
||||||
- /data/orion-ops-pro-space/docker-volumes/redis/data:/data
|
- /data/orion-ops-pro-space/docker-volumes/redis/data:/data
|
||||||
|
- /data/orion-ops-pro-space/docker-volumes/redis/redis.conf:/usr/local/etc/redis/redis.conf
|
||||||
orion-ops-pro-adminer:
|
orion-ops-pro-adminer:
|
||||||
image: adminer
|
image: adminer
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.orion.ops.module.asset.dao;
|
||||||
|
|
||||||
|
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||||
|
import com.orion.ops.module.asset.entity.domain.ExecTemplateHostDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行模板主机 Mapper 接口
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.6
|
||||||
|
* @since 2024-4-22 12:13
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ExecTemplateHostDAO extends IMapper<ExecTemplateHostDO> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.orion.ops.module.asset.entity.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行模板主机 实体对象
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.6
|
||||||
|
* @since 2024-4-22 12:13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName(value = "exec_template_host", autoResultMap = true)
|
||||||
|
@Schema(name = "ExecTemplateHostDO", description = "执行模板主机 实体对象")
|
||||||
|
public class ExecTemplateHostDO extends BaseDO {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "id")
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "模板id")
|
||||||
|
@TableField("template_id")
|
||||||
|
private Long templateId;
|
||||||
|
|
||||||
|
@Schema(description = "主机id")
|
||||||
|
@TableField("host_id")
|
||||||
|
private Long hostId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import javax.validation.constraints.NotBlank;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行模板 创建请求对象
|
* 执行模板 创建请求对象
|
||||||
@@ -51,4 +52,7 @@ public class ExecTemplateCreateRequest implements Serializable {
|
|||||||
@Schema(description = "参数定义")
|
@Schema(description = "参数定义")
|
||||||
private String parameterSchema;
|
private String parameterSchema;
|
||||||
|
|
||||||
|
@Schema(description = "模板主机")
|
||||||
|
private List<Long> hostIdList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,4 +31,7 @@ public class ExecTemplateQueryRequest extends PageRequest {
|
|||||||
@Schema(description = "命令")
|
@Schema(description = "命令")
|
||||||
private String command;
|
private String command;
|
||||||
|
|
||||||
|
@Schema(description = "是否查询模板主机")
|
||||||
|
private Boolean queryHost;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import javax.validation.constraints.NotBlank;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行模板 更新请求对象
|
* 执行模板 更新请求对象
|
||||||
@@ -55,4 +56,7 @@ public class ExecTemplateUpdateRequest implements Serializable {
|
|||||||
@Schema(description = "参数定义")
|
@Schema(description = "参数定义")
|
||||||
private String parameterSchema;
|
private String parameterSchema;
|
||||||
|
|
||||||
|
@Schema(description = "模板主机")
|
||||||
|
private List<Long> hostIdList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行模板 视图响应对象
|
* 执行模板 视图响应对象
|
||||||
@@ -55,4 +56,7 @@ public class ExecTemplateVO implements Serializable {
|
|||||||
@Schema(description = "修改人")
|
@Schema(description = "修改人")
|
||||||
private String updater;
|
private String updater;
|
||||||
|
|
||||||
|
@Schema(description = "模板主机")
|
||||||
|
private Set<Long> hostIdList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.orion.ops.module.asset.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行模板主机 服务类
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.6
|
||||||
|
* @since 2024-4-22 12:13
|
||||||
|
*/
|
||||||
|
public interface ExecTemplateHostService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询模板主机
|
||||||
|
*
|
||||||
|
* @param templateId templateId
|
||||||
|
* @return hostId
|
||||||
|
*/
|
||||||
|
Set<Long> getHostByTemplateId(Long templateId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询模板主机
|
||||||
|
*
|
||||||
|
* @param templateIdList templateIdList
|
||||||
|
* @return hostIdMap
|
||||||
|
*/
|
||||||
|
Map<Long, Set<Long>> getHostByTemplateIdList(List<Long> templateIdList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置模板主机
|
||||||
|
*
|
||||||
|
* @param templateId templateId
|
||||||
|
* @param hostList hostList
|
||||||
|
*/
|
||||||
|
void setTemplateHost(Long templateId, List<Long> hostList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 templateId 删除
|
||||||
|
*
|
||||||
|
* @param templateId templateId
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer deleteByTemplateId(Long templateId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 hostId 删除
|
||||||
|
*
|
||||||
|
* @param hostId hostId
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer deleteByHostId(Long hostId);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package com.orion.ops.module.asset.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.orion.lang.function.Functions;
|
||||||
|
import com.orion.lang.utils.collect.Lists;
|
||||||
|
import com.orion.ops.module.asset.dao.ExecTemplateHostDAO;
|
||||||
|
import com.orion.ops.module.asset.entity.domain.ExecTemplateHostDO;
|
||||||
|
import com.orion.ops.module.asset.service.ExecTemplateHostService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行模板主机 服务实现类
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.6
|
||||||
|
* @since 2024-4-22 12:13
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ExecTemplateHostServiceImpl implements ExecTemplateHostService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ExecTemplateHostDAO execTemplateHostDAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Long> getHostByTemplateId(Long templateId) {
|
||||||
|
return execTemplateHostDAO.of()
|
||||||
|
.createWrapper()
|
||||||
|
.select(ExecTemplateHostDO::getHostId)
|
||||||
|
.eq(ExecTemplateHostDO::getTemplateId, templateId)
|
||||||
|
.then()
|
||||||
|
.stream()
|
||||||
|
.map(ExecTemplateHostDO::getHostId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Long, Set<Long>> getHostByTemplateIdList(List<Long> templateIdList) {
|
||||||
|
return execTemplateHostDAO.of()
|
||||||
|
.createWrapper()
|
||||||
|
.select(ExecTemplateHostDO::getTemplateId, ExecTemplateHostDO::getHostId)
|
||||||
|
.in(ExecTemplateHostDO::getTemplateId, templateIdList)
|
||||||
|
.then()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
ExecTemplateHostDO::getTemplateId,
|
||||||
|
Collectors.mapping(ExecTemplateHostDO::getHostId, Collectors.toSet())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTemplateHost(Long templateId, List<Long> hostList) {
|
||||||
|
LambdaQueryWrapper<ExecTemplateHostDO> wrapper = execTemplateHostDAO.wrapper()
|
||||||
|
.eq(ExecTemplateHostDO::getTemplateId, templateId);
|
||||||
|
if (Lists.isEmpty(hostList)) {
|
||||||
|
// 为空移除
|
||||||
|
execTemplateHostDAO.delete(wrapper);
|
||||||
|
} else {
|
||||||
|
// 查询主机
|
||||||
|
wrapper.select(ExecTemplateHostDO::getId, ExecTemplateHostDO::getHostId);
|
||||||
|
Map<Long, Long> hostMap = execTemplateHostDAO.of(wrapper)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(ExecTemplateHostDO::getHostId,
|
||||||
|
ExecTemplateHostDO::getId,
|
||||||
|
Functions.right()));
|
||||||
|
// 插入主机
|
||||||
|
List<ExecTemplateHostDO> insertRecords = hostList.stream()
|
||||||
|
.filter(s -> !hostMap.containsKey(s))
|
||||||
|
.map(s -> ExecTemplateHostDO.builder()
|
||||||
|
.templateId(templateId)
|
||||||
|
.hostId(s)
|
||||||
|
.build())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (!insertRecords.isEmpty()) {
|
||||||
|
execTemplateHostDAO.insertBatch(insertRecords);
|
||||||
|
}
|
||||||
|
// 删除主机
|
||||||
|
List<Long> deleteIdList = hostMap.keySet()
|
||||||
|
.stream()
|
||||||
|
.filter(s -> !hostList.contains(s))
|
||||||
|
.map(hostMap::get)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (!deleteIdList.isEmpty()) {
|
||||||
|
execTemplateHostDAO.deleteBatchIds(deleteIdList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deleteByTemplateId(Long templateId) {
|
||||||
|
LambdaQueryWrapper<ExecTemplateHostDO> wrapper = execTemplateHostDAO.lambda()
|
||||||
|
.eq(ExecTemplateHostDO::getTemplateId, templateId);
|
||||||
|
log.info("ExecTemplateHostService-deleteByTemplateId idList: {}", templateId);
|
||||||
|
int effect = execTemplateHostDAO.delete(wrapper);
|
||||||
|
log.info("ExecTemplateHostService-deleteByTemplateId effect: {}", effect);
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deleteByHostId(Long hostId) {
|
||||||
|
LambdaQueryWrapper<ExecTemplateHostDO> wrapper = execTemplateHostDAO.lambda()
|
||||||
|
.eq(ExecTemplateHostDO::getHostId, hostId);
|
||||||
|
log.info("ExecTemplateHostService-deleteByHostId idList: {}", hostId);
|
||||||
|
int effect = execTemplateHostDAO.delete(wrapper);
|
||||||
|
log.info("ExecTemplateHostService-deleteByHostId effect: {}", effect);
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.orion.ops.module.asset.service.impl;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.orion.lang.define.wrapper.DataGrid;
|
import com.orion.lang.define.wrapper.DataGrid;
|
||||||
|
import com.orion.lang.utils.Booleans;
|
||||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||||
import com.orion.ops.framework.common.utils.Valid;
|
import com.orion.ops.framework.common.utils.Valid;
|
||||||
import com.orion.ops.module.asset.convert.ExecTemplateConvert;
|
import com.orion.ops.module.asset.convert.ExecTemplateConvert;
|
||||||
@@ -13,11 +14,16 @@ import com.orion.ops.module.asset.entity.request.exec.ExecTemplateQueryRequest;
|
|||||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateUpdateRequest;
|
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateUpdateRequest;
|
||||||
import com.orion.ops.module.asset.entity.vo.ExecTemplateVO;
|
import com.orion.ops.module.asset.entity.vo.ExecTemplateVO;
|
||||||
import com.orion.ops.module.asset.enums.ScriptExecEnum;
|
import com.orion.ops.module.asset.enums.ScriptExecEnum;
|
||||||
|
import com.orion.ops.module.asset.service.ExecTemplateHostService;
|
||||||
import com.orion.ops.module.asset.service.ExecTemplateService;
|
import com.orion.ops.module.asset.service.ExecTemplateService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行模板 服务实现类
|
* 执行模板 服务实现类
|
||||||
@@ -33,6 +39,9 @@ public class ExecTemplateServiceImpl implements ExecTemplateService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ExecTemplateDAO execTemplateDAO;
|
private ExecTemplateDAO execTemplateDAO;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ExecTemplateHostService execTemplateHostService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createExecTemplate(ExecTemplateCreateRequest request) {
|
public Long createExecTemplate(ExecTemplateCreateRequest request) {
|
||||||
log.info("ExecTemplateService-createExecTemplate request: {}", JSON.toJSONString(request));
|
log.info("ExecTemplateService-createExecTemplate request: {}", JSON.toJSONString(request));
|
||||||
@@ -41,9 +50,11 @@ public class ExecTemplateServiceImpl implements ExecTemplateService {
|
|||||||
ExecTemplateDO record = ExecTemplateConvert.MAPPER.to(request);
|
ExecTemplateDO record = ExecTemplateConvert.MAPPER.to(request);
|
||||||
// 查询数据是否冲突
|
// 查询数据是否冲突
|
||||||
this.checkExecTemplatePresent(record);
|
this.checkExecTemplatePresent(record);
|
||||||
// 插入
|
// 插入模板
|
||||||
int effect = execTemplateDAO.insert(record);
|
int effect = execTemplateDAO.insert(record);
|
||||||
Long id = record.getId();
|
Long id = record.getId();
|
||||||
|
// 修改模板主机
|
||||||
|
execTemplateHostService.setTemplateHost(id, request.getHostIdList());
|
||||||
log.info("ExecTemplateService-createExecTemplate id: {}, effect: {}", id, effect);
|
log.info("ExecTemplateService-createExecTemplate id: {}, effect: {}", id, effect);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -60,29 +71,49 @@ public class ExecTemplateServiceImpl implements ExecTemplateService {
|
|||||||
ExecTemplateDO updateRecord = ExecTemplateConvert.MAPPER.to(request);
|
ExecTemplateDO updateRecord = ExecTemplateConvert.MAPPER.to(request);
|
||||||
// 查询数据是否冲突
|
// 查询数据是否冲突
|
||||||
this.checkExecTemplatePresent(updateRecord);
|
this.checkExecTemplatePresent(updateRecord);
|
||||||
// 更新
|
// 更新模板
|
||||||
int effect = execTemplateDAO.updateById(updateRecord);
|
int effect = execTemplateDAO.updateById(updateRecord);
|
||||||
|
// 修改模板主机
|
||||||
|
execTemplateHostService.setTemplateHost(id, request.getHostIdList());
|
||||||
log.info("ExecTemplateService-updateExecTemplateById effect: {}", effect);
|
log.info("ExecTemplateService-updateExecTemplateById effect: {}", effect);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExecTemplateVO getExecTemplateById(Long id) {
|
public ExecTemplateVO getExecTemplateById(Long id) {
|
||||||
// 查询
|
// 查询模板
|
||||||
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
||||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||||
// 转换
|
// 转换
|
||||||
return ExecTemplateConvert.MAPPER.to(record);
|
ExecTemplateVO template = ExecTemplateConvert.MAPPER.to(record);
|
||||||
|
// 查询模板主机
|
||||||
|
Set<Long> hosts = execTemplateHostService.getHostByTemplateId(id);
|
||||||
|
template.setHostIdList(hosts);
|
||||||
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataGrid<ExecTemplateVO> getExecTemplatePage(ExecTemplateQueryRequest request) {
|
public DataGrid<ExecTemplateVO> getExecTemplatePage(ExecTemplateQueryRequest request) {
|
||||||
// 条件
|
// 条件
|
||||||
LambdaQueryWrapper<ExecTemplateDO> wrapper = this.buildQueryWrapper(request);
|
LambdaQueryWrapper<ExecTemplateDO> wrapper = this.buildQueryWrapper(request);
|
||||||
// 查询
|
// 查询模板
|
||||||
return execTemplateDAO.of(wrapper)
|
DataGrid<ExecTemplateVO> templates = execTemplateDAO.of(wrapper)
|
||||||
.page(request)
|
.page(request)
|
||||||
.dataGrid(ExecTemplateConvert.MAPPER::to);
|
.dataGrid(ExecTemplateConvert.MAPPER::to);
|
||||||
|
if (templates.isEmpty()) {
|
||||||
|
return templates;
|
||||||
|
}
|
||||||
|
// 查询模板主机
|
||||||
|
if (Booleans.isTrue(request.getQueryHost())) {
|
||||||
|
List<Long> idList = templates.stream()
|
||||||
|
.map(ExecTemplateVO::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Map<Long, Set<Long>> templateHosts = execTemplateHostService.getHostByTemplateIdList(idList);
|
||||||
|
for (ExecTemplateVO template : templates) {
|
||||||
|
template.setHostIdList(templateHosts.get(template.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,9 +122,11 @@ public class ExecTemplateServiceImpl implements ExecTemplateService {
|
|||||||
// 检查数据是否存在
|
// 检查数据是否存在
|
||||||
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
||||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||||
// 删除
|
// 删除模板
|
||||||
int effect = execTemplateDAO.deleteById(id);
|
int effect = execTemplateDAO.deleteById(id);
|
||||||
log.info("ExecTemplateService-deleteExecTemplateById id: {}, effect: {}", id, effect);
|
log.info("ExecTemplateService-deleteExecTemplateById id: {}, effect: {}", id, effect);
|
||||||
|
// 删除模板主机
|
||||||
|
effect += execTemplateHostService.deleteByTemplateId(id);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.orion.ops.module.asset.entity.request.host.HostQueryRequest;
|
|||||||
import com.orion.ops.module.asset.entity.request.host.HostUpdateRequest;
|
import com.orion.ops.module.asset.entity.request.host.HostUpdateRequest;
|
||||||
import com.orion.ops.module.asset.entity.vo.HostVO;
|
import com.orion.ops.module.asset.entity.vo.HostVO;
|
||||||
import com.orion.ops.module.asset.service.ExecJobHostService;
|
import com.orion.ops.module.asset.service.ExecJobHostService;
|
||||||
|
import com.orion.ops.module.asset.service.ExecTemplateHostService;
|
||||||
import com.orion.ops.module.asset.service.HostConfigService;
|
import com.orion.ops.module.asset.service.HostConfigService;
|
||||||
import com.orion.ops.module.asset.service.HostService;
|
import com.orion.ops.module.asset.service.HostService;
|
||||||
import com.orion.ops.module.infra.api.DataExtraApi;
|
import com.orion.ops.module.infra.api.DataExtraApi;
|
||||||
@@ -70,6 +71,9 @@ public class HostServiceImpl implements HostService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ExecJobHostService execJobHostService;
|
private ExecJobHostService execJobHostService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ExecTemplateHostService execTemplateHostService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TagRelApi tagRelApi;
|
private TagRelApi tagRelApi;
|
||||||
|
|
||||||
@@ -219,6 +223,8 @@ public class HostServiceImpl implements HostService {
|
|||||||
hostConfigDAO.deleteByHostId(id);
|
hostConfigDAO.deleteByHostId(id);
|
||||||
// 删除计划任务主机
|
// 删除计划任务主机
|
||||||
execJobHostService.deleteByHostId(id);
|
execJobHostService.deleteByHostId(id);
|
||||||
|
// 删除执行模板主机
|
||||||
|
execTemplateHostService.deleteByHostId(id);
|
||||||
// 删除分组
|
// 删除分组
|
||||||
dataGroupRelApi.deleteByRelId(DataGroupTypeEnum.HOST, id);
|
dataGroupRelApi.deleteByRelId(DataGroupTypeEnum.HOST, id);
|
||||||
// 删除 tag 引用
|
// 删除 tag 引用
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.orion.ops.module.asset.dao.ExecTemplateHostDAO">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="BaseResultMap" type="com.orion.ops.module.asset.entity.domain.ExecTemplateHostDO">
|
||||||
|
<id column="id" property="id"/>
|
||||||
|
<result column="template_id" property="templateId"/>
|
||||||
|
<result column="host_id" property="hostId"/>
|
||||||
|
<result column="create_time" property="createTime"/>
|
||||||
|
<result column="update_time" property="updateTime"/>
|
||||||
|
<result column="creator" property="creator"/>
|
||||||
|
<result column="updater" property="updater"/>
|
||||||
|
<result column="deleted" property="deleted"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 通用查询结果列 -->
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id, template_id, host_id, create_time, update_time, creator, updater, deleted
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user