package com.xiang.xservice.application.script.domain.schedule;

import com.xiang.xservice.basic.utils.IpUtils;
import com.xiang.xservice.application.script.domain.service.IDomainService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: xiang
 * @Date: 2025-06-10 17:21
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class DynamicDomainSchedule {

    private final IDomainService IDomainService;

    @Scheduled(cron = "0 0/30 * * * ? ")
    public void dynamicDomainSchedule() {
        String publicIp = "";
        try {
            publicIp = IpUtils.getPublicIp();
        } catch (Exception e) {
            log.error("获取公网ip失败，", e);
        }
       if (StringUtils.isNotBlank(publicIp)) {
           try {
               IDomainService.dynamicDomainAnalysis(publicIp);
           } catch (Exception e) {
               log.error("动态解析公网ip失败, ip:{}", publicIp, e);
           }
       }
    }
}
