[Fix]修复“删除有掉线提醒的实例时会导致所有提醒都无法显示”的Bug

This commit is contained in:
2023-03-21 23:16:33 +08:00
parent 44511e9547
commit e1b0603648
2 changed files with 33 additions and 6 deletions
@@ -11,12 +11,14 @@ import com.mzaxd.noodles.domain.entity.Container;
import com.mzaxd.noodles.domain.vo.*;
import com.mzaxd.noodles.enums.AppHttpCodeEnum;
import com.mzaxd.noodles.mapper.HostMachineMapper;
import com.mzaxd.noodles.mapper.NotificationMapper;
import com.mzaxd.noodles.service.ContainerService;
import com.mzaxd.noodles.mapper.ContainerMapper;
import com.mzaxd.noodles.service.HostMachineService;
import com.mzaxd.noodles.service.SshLinkService;
import com.mzaxd.noodles.util.BeanCopyUtils;
import com.mzaxd.noodles.util.SshLinkUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -32,6 +34,7 @@ import java.util.Objects;
* @createDate 2023-02-02 06:26:00
*/
@Service
@Slf4j
public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container>
implements ContainerService {
@@ -47,6 +50,9 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container
@Resource
private SshLinkService sshLinkService;
@Resource
private NotificationMapper notificationMapper;
@Override
public ResponseResult containerListSummaryStatistics() {
//设置查询所有在线vm的条件
@@ -109,6 +115,12 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container
@Override
public ResponseResult deleteContainerById(Integer id) {
if (removeById(id)) {
//删除掉线提醒
LambdaQueryWrapper<Notification> notificationLambdaQueryWrapper = new LambdaQueryWrapper<>();
notificationLambdaQueryWrapper.eq(Notification::getInstanceId, id);
notificationLambdaQueryWrapper.eq(Notification::getInstanceType, SystemConstant.INSTANCETYPE_CONTAINER);
notificationMapper.delete(notificationLambdaQueryWrapper);
log.info("删除id为{}的虚拟机的所有掉线提醒", id);
return ResponseResult.okResult("删除成功");
}
return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR);
@@ -13,10 +13,7 @@ import com.mzaxd.noodles.domain.message.Server;
import com.mzaxd.noodles.domain.vo.*;
import com.mzaxd.noodles.enums.AppHttpCodeEnum;
import com.mzaxd.noodles.exception.SystemException;
import com.mzaxd.noodles.mapper.HostDetectorMapper;
import com.mzaxd.noodles.mapper.HostMachineMapper;
import com.mzaxd.noodles.mapper.OsMapper;
import com.mzaxd.noodles.mapper.SshLinkMapper;
import com.mzaxd.noodles.mapper.*;
import com.mzaxd.noodles.service.*;
import com.mzaxd.noodles.util.BeanCopyUtils;
import com.mzaxd.noodles.util.SshLinkUtil;
@@ -74,6 +71,9 @@ public class HostMachineServiceImpl extends ServiceImpl<HostMachineMapper, HostM
@Resource
private SshLinkMapper sshLinkMapper;
@Resource
private NotificationMapper notificationMapper;
@Override
public ResponseResult getHostDrawer() {
LambdaQueryWrapper<HostMachine> wrapper = new LambdaQueryWrapper<>();
@@ -340,8 +340,16 @@ public class HostMachineServiceImpl extends ServiceImpl<HostMachineMapper, HostM
log.info("删除hostId为{}的host信息", id);
osMapper.deleteById(hostMachine.getOsId());
}
log.info("删除id为{}的host", id);
//删除掉线提醒
LambdaQueryWrapper<Notification> notificationLambdaQueryWrapper = new LambdaQueryWrapper<>();
notificationLambdaQueryWrapper.eq(Notification::getInstanceId, id);
notificationLambdaQueryWrapper.eq(Notification::getInstanceType, SystemConstant.INSTANCETYPE_HOST);
notificationMapper.delete(notificationLambdaQueryWrapper);
log.info("删除id为{}的物理机的所有掉线提醒", id);
//删除物理机
hostMachineMapper.deleteById(id);
log.info("删除id为{}的host", id);
return ResponseResult.okResult(SystemConstant.SUCCESS_CODE, "删除成功");
}
@@ -453,8 +461,15 @@ public class HostMachineServiceImpl extends ServiceImpl<HostMachineMapper, HostM
if (Objects.nonNull(getById(id).getSshId())) {
sshLinkMapper.deleteById(getById(id).getSshId());
}
log.info("删除id为{}的vm", id);
//删除掉线提醒
LambdaQueryWrapper<Notification> notificationLambdaQueryWrapper = new LambdaQueryWrapper<>();
notificationLambdaQueryWrapper.eq(Notification::getInstanceId, id);
notificationLambdaQueryWrapper.eq(Notification::getInstanceType, SystemConstant.INSTANCETYPE_VM);
notificationMapper.delete(notificationLambdaQueryWrapper);
log.info("删除id为{}的虚拟机的所有掉线提醒", id);
hostMachineMapper.deleteById(id);
log.info("删除id为{}的vm", id);
return ResponseResult.okResult(SystemConstant.SUCCESS_CODE, "删除成功");
}