⚡ 批量删除后端服务.
This commit is contained in:
@@ -98,6 +98,15 @@ public class ExecJobController {
|
||||
return execJobService.deleteExecJobById(id);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecJobOperatorType.DELETE)
|
||||
@DeleteMapping("/batch-delete")
|
||||
@Operation(summary = "批量删除计划任务")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job:delete')")
|
||||
public Integer batchDeleteExecJob(@RequestParam("idList") List<Long> idList) {
|
||||
return execJobService.deleteExecJobByIdList(idList);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecJobOperatorType.TRIGGER)
|
||||
@PostMapping("/trigger")
|
||||
@Operation(summary = "手动触发计划任务")
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 执行模板 api
|
||||
@@ -92,5 +93,14 @@ public class ExecTemplateController {
|
||||
return execTemplateService.deleteExecTemplateById(id);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecTemplateOperatorType.DELETE)
|
||||
@DeleteMapping("/batch-delete")
|
||||
@Operation(summary = "批量删除执行模板")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-template:delete')")
|
||||
public Integer batchDeleteExecTemplate(@RequestParam("idList") List<Long> idList) {
|
||||
return execTemplateService.deleteExecTemplateByIdList(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -96,5 +96,15 @@ public class HostController {
|
||||
return hostService.deleteHostById(id);
|
||||
}
|
||||
|
||||
@DemoDisableApi
|
||||
@OperatorLog(HostOperatorType.DELETE)
|
||||
@DeleteMapping("/batch-delete")
|
||||
@Operation(summary = "批量删除主机")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:delete')")
|
||||
public Integer batchDeleteHost(@RequestParam("idList") List<Long> idList) {
|
||||
return hostService.deleteHostByIdList(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -97,5 +97,15 @@ public class HostIdentityController {
|
||||
return hostIdentityService.deleteHostIdentityById(id);
|
||||
}
|
||||
|
||||
@DemoDisableApi
|
||||
@OperatorLog(HostIdentityOperatorType.DELETE)
|
||||
@DeleteMapping("/batch-delete")
|
||||
@Operation(summary = "批量删除主机身份")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-identity:delete')")
|
||||
public Integer batchDeleteHostIdentity(@RequestParam("idList") List<Long> idList) {
|
||||
return hostIdentityService.deleteHostIdentityByIdList(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -96,5 +96,15 @@ public class HostKeyController {
|
||||
return hostKeyService.deleteHostKeyById(id);
|
||||
}
|
||||
|
||||
@DemoDisableApi
|
||||
@OperatorLog(HostKeyOperatorType.DELETE)
|
||||
@DeleteMapping("/batch-delete")
|
||||
@Operation(summary = "批量删除主机密钥")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-key:delete')")
|
||||
public Integer batchDeleteHostKey(@RequestParam("idList") List<Long> idList) {
|
||||
return hostKeyService.deleteHostKeyByIdList(idList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,18 @@ public interface ExecJobHostDAO extends IMapper<ExecJobHostDO> {
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 jobId 删除
|
||||
*
|
||||
* @param jobIdList jobIdList
|
||||
* @return effect
|
||||
*/
|
||||
default Integer deleteByJobIdList(List<Long> jobIdList) {
|
||||
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.wrapper()
|
||||
.in(ExecJobHostDO::getJobId, jobIdList);
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 hostId 删除
|
||||
*
|
||||
@@ -56,4 +68,16 @@ public interface ExecJobHostDAO extends IMapper<ExecJobHostDO> {
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 hostId 删除
|
||||
*
|
||||
* @param hostIdList hostIdList
|
||||
* @return effect
|
||||
*/
|
||||
default Integer deleteByHostIdList(List<Long> hostIdList) {
|
||||
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.wrapper()
|
||||
.in(ExecJobHostDO::getHostId, hostIdList);
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,17 +95,17 @@ public interface HostConfigDAO extends IMapper<HostConfigDO> {
|
||||
/**
|
||||
* 设置 keyId 为 NULL
|
||||
*
|
||||
* @param keyId keyId
|
||||
* @param keyIdList keyIdList
|
||||
* @return effect
|
||||
*/
|
||||
int setKeyIdWithNull(@Param("keyId") Long keyId);
|
||||
int setKeyIdWithNull(@Param("keyIdList") List<Long> keyIdList);
|
||||
|
||||
/**
|
||||
* 设置 identityId 为 NULL
|
||||
*
|
||||
* @param identityId identityId
|
||||
* @param identityIdList identityIdList
|
||||
* @return effect
|
||||
*/
|
||||
int setIdentityIdWithNull(@Param("identityId") Long identityId);
|
||||
int setIdentityIdWithNull(@Param("identityIdList") List<Long> identityIdList);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.orion.visor.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.visor.module.asset.entity.domain.HostIdentityDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机身份 Mapper 接口
|
||||
@@ -20,13 +21,13 @@ public interface HostIdentityDAO extends IMapper<HostIdentityDO> {
|
||||
/**
|
||||
* 设置 keyId 为 null
|
||||
*
|
||||
* @param keyId keyId
|
||||
* @param keyIdList keyIdList
|
||||
* @return effect
|
||||
*/
|
||||
default int setKeyWithNull(@Param("keyId") Long keyId) {
|
||||
default int setKeyWithNull(List<Long> keyIdList) {
|
||||
LambdaUpdateWrapper<HostIdentityDO> updateWrapper = Wrappers.<HostIdentityDO>lambdaUpdate()
|
||||
.set(HostIdentityDO::getKeyId, null)
|
||||
.eq(HostIdentityDO::getKeyId, keyId);
|
||||
.in(HostIdentityDO::getKeyId, keyIdList);
|
||||
return this.update(null, updateWrapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,14 @@ public interface ExecJobHostService {
|
||||
*/
|
||||
Integer deleteByJobId(Long jobId);
|
||||
|
||||
/**
|
||||
* 通过 jobId 删除
|
||||
*
|
||||
* @param jobIdList jobIdList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByJobIdList(List<Long> jobIdList);
|
||||
|
||||
/**
|
||||
* 通过 hostId 删除
|
||||
*
|
||||
@@ -43,4 +51,12 @@ public interface ExecJobHostService {
|
||||
*/
|
||||
Integer deleteByHostId(Long hostId);
|
||||
|
||||
/**
|
||||
* 通过 hostId 删除
|
||||
*
|
||||
* @param hostIdList hostIdList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByHostIdList(List<Long> hostIdList);
|
||||
|
||||
}
|
||||
|
||||
@@ -78,6 +78,14 @@ public interface ExecJobService {
|
||||
*/
|
||||
Integer deleteExecJobById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除计划任务
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteExecJobByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 手动触发任务
|
||||
*
|
||||
|
||||
@@ -45,6 +45,14 @@ public interface ExecTemplateHostService {
|
||||
*/
|
||||
Integer deleteByTemplateId(Long templateId);
|
||||
|
||||
/**
|
||||
* 通过 templateId 删除
|
||||
*
|
||||
* @param templateIdList templateIdList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByTemplateIdList(List<Long> templateIdList);
|
||||
|
||||
/**
|
||||
* 通过 hostId 删除
|
||||
*
|
||||
@@ -53,4 +61,12 @@ public interface ExecTemplateHostService {
|
||||
*/
|
||||
Integer deleteByHostId(Long hostId);
|
||||
|
||||
/**
|
||||
* 通过 hostId 删除
|
||||
*
|
||||
* @param hostIdList hostIdList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByHostIdList(List<Long> hostIdList);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.orion.visor.module.asset.entity.request.exec.ExecTemplateQueryRequest
|
||||
import com.orion.visor.module.asset.entity.request.exec.ExecTemplateUpdateRequest;
|
||||
import com.orion.visor.module.asset.entity.vo.ExecTemplateVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 执行模板 服务类
|
||||
*
|
||||
@@ -63,4 +65,12 @@ public interface ExecTemplateService {
|
||||
*/
|
||||
Integer deleteExecTemplateById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除执行模板
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteExecTemplateByIdList(List<Long> idList);
|
||||
|
||||
}
|
||||
|
||||
@@ -64,4 +64,12 @@ public interface HostIdentityService {
|
||||
*/
|
||||
Integer deleteHostIdentityById(Long id);
|
||||
|
||||
/**
|
||||
* 通过 id 批量删除主机身份
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteHostIdentityByIdList(List<Long> idList);
|
||||
|
||||
}
|
||||
|
||||
@@ -66,11 +66,19 @@ public interface HostKeyService {
|
||||
DataGrid<HostKeyVO> getHostKeyPage(HostKeyQueryRequest request);
|
||||
|
||||
/**
|
||||
* 通过 id 删除主机密钥
|
||||
* 通过 id 批量删除主机密钥
|
||||
*
|
||||
* @param id id
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteHostKeyById(Long id);
|
||||
|
||||
/**
|
||||
* 通过 id 删除主机密钥
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteHostKeyByIdList(List<Long> idList);
|
||||
|
||||
}
|
||||
|
||||
@@ -64,11 +64,19 @@ public interface HostService {
|
||||
*/
|
||||
Integer deleteHostById(Long id);
|
||||
|
||||
/**
|
||||
* 通过 id 批量删除主机
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteHostByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 通过 id 删除主机引用
|
||||
*
|
||||
* @param id id
|
||||
* @param idList idList
|
||||
*/
|
||||
void deleteHostRelByIdAsync(Long id);
|
||||
void deleteHostRelByIdListAsync(List<Long> idList);
|
||||
|
||||
}
|
||||
|
||||
@@ -49,9 +49,19 @@ public class ExecJobHostServiceImpl implements ExecJobHostService {
|
||||
return execJobHostDAO.deleteByJobId(jobId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByJobIdList(List<Long> jobIdList) {
|
||||
return execJobHostDAO.deleteByJobIdList(jobIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByHostId(Long hostId) {
|
||||
return execJobHostDAO.deleteByHostId(hostId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByHostIdList(List<Long> hostIdList) {
|
||||
return execJobHostDAO.deleteByHostIdList(hostIdList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.time.cron.Cron;
|
||||
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.visor.framework.common.constant.Const;
|
||||
import com.orion.visor.framework.common.constant.ErrorMessage;
|
||||
import com.orion.visor.framework.common.utils.Valid;
|
||||
import com.orion.visor.framework.job.core.utils.QuartzUtils;
|
||||
@@ -235,19 +236,30 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteExecJobById(Long id) {
|
||||
log.info("ExecJobService-deleteExecJobById id: {}", id);
|
||||
return this.deleteExecJobByIdList(Lists.singleton(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteExecJobByIdList(List<Long> idList) {
|
||||
log.info("ExecJobService-deleteExecJobByIdList idList: {}", idList);
|
||||
// 检查数据是否存在
|
||||
ExecJobDO record = execJobDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
List<ExecJobDO> jobList = execJobDAO.selectBatchIds(idList);
|
||||
Valid.notEmpty(jobList, ErrorMessage.DATA_ABSENT);
|
||||
// 删除任务
|
||||
int effect = execJobDAO.deleteById(id);
|
||||
int effect = execJobDAO.deleteBatchIds(idList);
|
||||
// 删除任务主机
|
||||
effect += execJobHostService.deleteByJobId(id);
|
||||
effect += execJobHostService.deleteByJobIdList(idList);
|
||||
// 设置日志参数
|
||||
OperatorLogs.add(OperatorLogs.NAME, record.getName());
|
||||
String name = jobList.stream()
|
||||
.map(ExecJobDO::getName)
|
||||
.collect(Collectors.joining(Const.COMMA));
|
||||
OperatorLogs.add(OperatorLogs.NAME, name);
|
||||
// 设置 quartz 状态
|
||||
this.setQuartzJobStatus(record, true, false);
|
||||
log.info("ExecJobService-deleteExecJobById id: {}, effect: {}", id, effect);
|
||||
for (ExecJobDO job : jobList) {
|
||||
this.setQuartzJobStatus(job, true, false);
|
||||
}
|
||||
log.info("ExecJobService-deleteExecJobByIdList idList: {}, effect: {}", idList, effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,20 +97,40 @@ public class ExecTemplateHostServiceImpl implements ExecTemplateHostService {
|
||||
public Integer deleteByTemplateId(Long templateId) {
|
||||
LambdaQueryWrapper<ExecTemplateHostDO> wrapper = execTemplateHostDAO.lambda()
|
||||
.eq(ExecTemplateHostDO::getTemplateId, templateId);
|
||||
log.info("ExecTemplateHostService-deleteByTemplateId idList: {}", templateId);
|
||||
log.info("ExecTemplateHostService-deleteByTemplateId id: {}", templateId);
|
||||
int effect = execTemplateHostDAO.delete(wrapper);
|
||||
log.info("ExecTemplateHostService-deleteByTemplateId effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByTemplateIdList(List<Long> templateIdList) {
|
||||
LambdaQueryWrapper<ExecTemplateHostDO> wrapper = execTemplateHostDAO.lambda()
|
||||
.in(ExecTemplateHostDO::getTemplateId, templateIdList);
|
||||
log.info("ExecTemplateHostService-deleteByTemplateIdList idList: {}", templateIdList);
|
||||
int effect = execTemplateHostDAO.delete(wrapper);
|
||||
log.info("ExecTemplateHostService-deleteByTemplateIdList 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);
|
||||
log.info("ExecTemplateHostService-deleteByHostId id: {}", hostId);
|
||||
int effect = execTemplateHostDAO.delete(wrapper);
|
||||
log.info("ExecTemplateHostService-deleteByHostId effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByHostIdList(List<Long> hostIdList) {
|
||||
LambdaQueryWrapper<ExecTemplateHostDO> wrapper = execTemplateHostDAO.lambda()
|
||||
.in(ExecTemplateHostDO::getHostId, hostIdList);
|
||||
log.info("ExecTemplateHostService-deleteByHostIdList id: {}", hostIdList);
|
||||
int effect = execTemplateHostDAO.delete(wrapper);
|
||||
log.info("ExecTemplateHostService-deleteByHostIdList effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.visor.framework.common.constant.Const;
|
||||
import com.orion.visor.framework.common.constant.ErrorMessage;
|
||||
import com.orion.visor.framework.common.utils.Valid;
|
||||
import com.orion.visor.framework.security.core.utils.SecurityUtils;
|
||||
@@ -21,10 +23,12 @@ import com.orion.visor.module.asset.service.ExecTemplateHostService;
|
||||
import com.orion.visor.module.asset.service.ExecTemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 执行模板 服务实现类
|
||||
@@ -126,16 +130,28 @@ public class ExecTemplateServiceImpl implements ExecTemplateService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteExecTemplateById(Long id) {
|
||||
log.info("ExecTemplateService-deleteExecTemplateById id: {}", id);
|
||||
return this.deleteExecTemplateByIdList(Lists.singleton(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteExecTemplateByIdList(List<Long> idList) {
|
||||
log.info("ExecTemplateService-deleteExecTemplateByIdList idList: {}", idList);
|
||||
// 检查数据是否存在
|
||||
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
List<ExecTemplateDO> recordList = execTemplateDAO.selectBatchIds(idList);
|
||||
Valid.notEmpty(recordList, ErrorMessage.DATA_ABSENT);
|
||||
// 设置日志参数
|
||||
String name = recordList.stream()
|
||||
.map(ExecTemplateDO::getName)
|
||||
.collect(Collectors.joining(Const.COMMA));
|
||||
OperatorLogs.add(OperatorLogs.NAME, name);
|
||||
// 删除模板
|
||||
int effect = execTemplateDAO.deleteById(id);
|
||||
log.info("ExecTemplateService-deleteExecTemplateById id: {}, effect: {}", id, effect);
|
||||
int effect = execTemplateDAO.deleteBatchIds(idList);
|
||||
log.info("ExecTemplateService-deleteExecTemplateByIdList idList: {}, effect: {}", idList, effect);
|
||||
// 删除模板主机
|
||||
effect += execTemplateHostService.deleteByTemplateId(id);
|
||||
effect += execTemplateHostService.deleteByTemplateIdList(idList);
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,15 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.visor.framework.common.constant.Const;
|
||||
import com.orion.visor.framework.common.constant.ErrorMessage;
|
||||
import com.orion.visor.framework.common.security.PasswordModifier;
|
||||
import com.orion.visor.framework.common.utils.CryptoUtils;
|
||||
import com.orion.visor.framework.common.utils.Valid;
|
||||
import com.orion.visor.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.visor.framework.redis.core.utils.RedisUtils;
|
||||
import com.orion.visor.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.visor.module.asset.convert.HostIdentityConvert;
|
||||
import com.orion.visor.module.asset.dao.HostConfigDAO;
|
||||
@@ -32,6 +35,7 @@ import com.orion.visor.module.infra.api.DataPermissionApi;
|
||||
import com.orion.visor.module.infra.enums.DataPermissionTypeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
@@ -185,24 +189,34 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteHostIdentityById(Long id) {
|
||||
log.info("HostIdentityService-deleteHostIdentityById id: {}", id);
|
||||
return this.deleteHostIdentityByIdList(Lists.singleton(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteHostIdentityByIdList(List<Long> idList) {
|
||||
log.info("HostIdentityService-deleteHostIdentityByIdList idList: {}", idList);
|
||||
// 检查数据是否存在
|
||||
HostIdentityDO record = hostIdentityDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
List<HostIdentityDO> list = hostIdentityDAO.selectBatchIds(idList);
|
||||
Valid.notEmpty(list, ErrorMessage.DATA_ABSENT);
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.NAME, record.getName());
|
||||
String name = list.stream()
|
||||
.map(HostIdentityDO::getName)
|
||||
.collect(Collectors.joining(Const.COMMA));
|
||||
OperatorLogs.add(OperatorLogs.NAME, name);
|
||||
// 删除数据库
|
||||
int effect = hostIdentityDAO.deleteById(id);
|
||||
int effect = hostIdentityDAO.deleteBatchIds(idList);
|
||||
// 删除主机配置
|
||||
hostConfigDAO.setIdentityIdWithNull(id);
|
||||
hostConfigDAO.setIdentityIdWithNull(idList);
|
||||
// 删除主机身份额外配置
|
||||
dataExtraApi.deleteHostIdentityExtra(id);
|
||||
dataExtraApi.deleteHostIdentityExtra(idList);
|
||||
// 删除数据权限
|
||||
dataPermissionApi.deleteByRelId(DataPermissionTypeEnum.HOST_IDENTITY, id);
|
||||
dataPermissionApi.deleteByRelIdList(DataPermissionTypeEnum.HOST_IDENTITY, idList);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_IDENTITY.getKey(), record.getId());
|
||||
log.info("HostIdentityService-deleteHostIdentityById effect: {}", effect);
|
||||
RedisUtils.delete(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
log.info("HostIdentityService-deleteHostIdentityByIdList effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.visor.framework.common.constant.Const;
|
||||
import com.orion.visor.framework.common.constant.ErrorMessage;
|
||||
import com.orion.visor.framework.common.security.PasswordModifier;
|
||||
import com.orion.visor.framework.common.utils.CryptoUtils;
|
||||
import com.orion.visor.framework.common.utils.Valid;
|
||||
import com.orion.visor.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.visor.framework.redis.core.utils.RedisUtils;
|
||||
import com.orion.visor.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.visor.module.asset.convert.HostKeyConvert;
|
||||
import com.orion.visor.module.asset.dao.HostConfigDAO;
|
||||
@@ -170,24 +173,33 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteHostKeyById(Long id) {
|
||||
log.info("HostKeyService-deleteHostKeyById id: {}", id);
|
||||
return this.deleteHostKeyByIdList(Lists.singleton(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer deleteHostKeyByIdList(List<Long> idList) {
|
||||
log.info("HostKeyService-deleteHostKeyById idList: {}", idList);
|
||||
// 检查数据是否存在
|
||||
HostKeyDO record = hostKeyDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
List<HostKeyDO> list = hostKeyDAO.selectBatchIds(idList);
|
||||
Valid.notEmpty(list, ErrorMessage.DATA_ABSENT);
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.NAME, record.getName());
|
||||
String name = list.stream()
|
||||
.map(HostKeyDO::getName)
|
||||
.collect(Collectors.joining(Const.COMMA));
|
||||
OperatorLogs.add(OperatorLogs.NAME, name);
|
||||
// 删除数据库
|
||||
int effect = hostKeyDAO.deleteById(id);
|
||||
int effect = hostKeyDAO.deleteBatchIds(idList);
|
||||
// 删除关联
|
||||
hostIdentityDAO.setKeyWithNull(id);
|
||||
hostIdentityDAO.setKeyWithNull(idList);
|
||||
// 删除主机配置
|
||||
hostConfigDAO.setKeyIdWithNull(id);
|
||||
hostConfigDAO.setKeyIdWithNull(idList);
|
||||
// 删除主机密钥额外配置
|
||||
dataExtraApi.deleteHostKeyExtra(id);
|
||||
dataExtraApi.deleteHostKeyExtra(idList);
|
||||
// 删除数据权限
|
||||
dataPermissionApi.deleteByRelId(DataPermissionTypeEnum.HOST_KEY, id);
|
||||
dataPermissionApi.deleteByRelIdList(DataPermissionTypeEnum.HOST_KEY, idList);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_KEY.getKey(), record.getId());
|
||||
RedisUtils.delete(HostCacheKeyDefine.HOST_KEY);
|
||||
log.info("HostKeyService-deleteHostKeyById effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.spring.SpringHolder;
|
||||
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.visor.framework.common.constant.Const;
|
||||
import com.orion.visor.framework.common.constant.ErrorMessage;
|
||||
import com.orion.visor.framework.common.utils.Valid;
|
||||
import com.orion.visor.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.visor.framework.redis.core.utils.RedisUtils;
|
||||
import com.orion.visor.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.visor.module.asset.convert.HostConvert;
|
||||
import com.orion.visor.module.asset.dao.HostConfigDAO;
|
||||
@@ -191,41 +193,49 @@ public class HostServiceImpl implements HostService {
|
||||
|
||||
@Override
|
||||
public Integer deleteHostById(Long id) {
|
||||
log.info("HostService-deleteHostById id: {}", id);
|
||||
return this.deleteHostByIdList(Lists.singleton(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteHostByIdList(List<Long> idList) {
|
||||
log.info("HostService-deleteHostByIdList idList: {}", idList);
|
||||
// 查询
|
||||
HostDO record = hostDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.HOST_ABSENT);
|
||||
List<HostDO> hosts = hostDAO.selectBatchIds(idList);
|
||||
Valid.notEmpty(hosts, ErrorMessage.HOST_ABSENT);
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.NAME, record.getName());
|
||||
String name = hosts.stream()
|
||||
.map(HostDO::getName)
|
||||
.collect(Collectors.joining(Const.COMMA));
|
||||
OperatorLogs.add(OperatorLogs.NAME, name);
|
||||
// 删除
|
||||
int effect = hostDAO.deleteById(id);
|
||||
log.info("HostService-deleteHostById effect: {}", effect);
|
||||
int effect = hostDAO.deleteBatchIds(hosts);
|
||||
log.info("HostService-deleteHostByIdList effect: {}", effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_INFO, id);
|
||||
RedisUtils.delete(HostCacheKeyDefine.HOST_INFO);
|
||||
// 删除主机引用
|
||||
SpringHolder.getBean(HostService.class)
|
||||
.deleteHostRelByIdAsync(id);
|
||||
.deleteHostRelByIdListAsync(idList);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void deleteHostRelByIdAsync(Long id) {
|
||||
log.info("HostService-deleteHostRelByIdAsync id: {}", id);
|
||||
public void deleteHostRelByIdListAsync(List<Long> idList) {
|
||||
log.info("HostService-deleteHostRelByIdListAsync idList: {}", idList);
|
||||
// 删除主机配置
|
||||
hostConfigDAO.deleteByHostId(id);
|
||||
hostConfigDAO.deleteByHostIdList(idList);
|
||||
// 删除计划任务主机
|
||||
execJobHostService.deleteByHostId(id);
|
||||
execJobHostService.deleteByHostIdList(idList);
|
||||
// 删除执行模板主机
|
||||
execTemplateHostService.deleteByHostId(id);
|
||||
execTemplateHostService.deleteByHostIdList(idList);
|
||||
// 删除分组
|
||||
dataGroupRelApi.deleteByRelId(DataGroupTypeEnum.HOST, id);
|
||||
dataGroupRelApi.deleteByRelIdList(DataGroupTypeEnum.HOST, idList);
|
||||
// 删除 tag 引用
|
||||
tagRelApi.deleteRelId(TagTypeEnum.HOST, id);
|
||||
tagRelApi.deleteRelIdList(TagTypeEnum.HOST, idList);
|
||||
// 删除收藏引用
|
||||
favoriteApi.deleteByRelId(FavoriteTypeEnum.HOST, id);
|
||||
favoriteApi.deleteByRelIdList(FavoriteTypeEnum.HOST, idList);
|
||||
// 删除额外配置
|
||||
dataExtraApi.deleteByRelId(DataExtraTypeEnum.HOST, id);
|
||||
dataExtraApi.deleteByRelIdList(DataExtraTypeEnum.HOST, idList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,11 +151,13 @@ public class HostTerminalServiceImpl implements HostTerminalService {
|
||||
HostExtraSshAuthTypeEnum extraAuthType = HostExtraSshAuthTypeEnum.of(extra.getAuthType());
|
||||
if (HostExtraSshAuthTypeEnum.CUSTOM_KEY.equals(extraAuthType)) {
|
||||
// 验证主机密钥是否有权限
|
||||
Valid.notNull(extra.getKeyId(), ErrorMessage.KEY_ABSENT);
|
||||
Valid.isTrue(dataPermissionApi.hasPermission(DataPermissionTypeEnum.HOST_KEY, userId, extra.getKeyId()),
|
||||
ErrorMessage.ANY_NO_PERMISSION,
|
||||
DataPermissionTypeEnum.HOST_KEY.getPermissionName());
|
||||
} else if (HostExtraSshAuthTypeEnum.CUSTOM_IDENTITY.equals(extraAuthType)) {
|
||||
// 验证主机身份是否有权限
|
||||
Valid.notNull(extra.getIdentityId(), ErrorMessage.IDENTITY_ABSENT);
|
||||
Valid.isTrue(dataPermissionApi.hasPermission(DataPermissionTypeEnum.HOST_IDENTITY, userId, extra.getIdentityId()),
|
||||
ErrorMessage.ANY_NO_PERMISSION,
|
||||
DataPermissionTypeEnum.HOST_IDENTITY.getPermissionName());
|
||||
@@ -270,6 +272,7 @@ public class HostTerminalServiceImpl implements HostTerminalService {
|
||||
HostSshAuthTypeEnum authType = HostSshAuthTypeEnum.of(config.getAuthType());
|
||||
if (HostSshAuthTypeEnum.IDENTITY.equals(authType)) {
|
||||
// 身份认证
|
||||
Valid.notNull(config.getIdentityId(), ErrorMessage.IDENTITY_ABSENT);
|
||||
HostIdentityDO identity = hostIdentityDAO.selectById(config.getIdentityId());
|
||||
Valid.notNull(identity, ErrorMessage.IDENTITY_ABSENT);
|
||||
config.setUsername(identity.getUsername());
|
||||
@@ -293,6 +296,7 @@ public class HostTerminalServiceImpl implements HostTerminalService {
|
||||
} else if (HostSshAuthTypeEnum.KEY.equals(authType)) {
|
||||
// 密钥认证
|
||||
Long keyId = config.getKeyId();
|
||||
Valid.notNull(keyId, ErrorMessage.KEY_ABSENT);
|
||||
HostKeyDO key = hostKeyDAO.selectById(keyId);
|
||||
Valid.notNull(key, ErrorMessage.KEY_ABSENT);
|
||||
conn.setKeyId(keyId);
|
||||
|
||||
@@ -25,17 +25,21 @@
|
||||
<update id="setKeyIdWithNull">
|
||||
UPDATE host_config
|
||||
SET version = version + 1,
|
||||
config = JSON_REMOVE(config, '$.keyId')
|
||||
config = JSON_REMOVE(config, '$.keyId')
|
||||
WHERE deleted = 0
|
||||
AND JSON_CONTAINS(config, JSON_OBJECT('keyId', #{keyId}))
|
||||
<foreach collection="keyIdList" item="item" separator="OR" open="AND (" close=")">
|
||||
JSON_CONTAINS(config, JSON_OBJECT('keyId', #{item}))
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="setIdentityIdWithNull">
|
||||
UPDATE host_config
|
||||
SET version = version + 1,
|
||||
config = JSON_REMOVE(config, '$.identityId')
|
||||
config = JSON_REMOVE(config, '$.identityId')
|
||||
WHERE deleted = 0
|
||||
AND JSON_CONTAINS(config, JSON_OBJECT('identityId', #{identityId}))
|
||||
<foreach collection="identityIdList" item="item" separator="OR" open="AND (" close=")">
|
||||
JSON_CONTAINS(config, JSON_OBJECT('identityId', #{item}))
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user