package com.xueyi.job.task;

import com.xueyi.common.cache.utils.SourceUtil;
import com.xueyi.common.core.utils.core.StrUtil;
import com.xueyi.common.core.web.result.R;
import com.xueyi.message.api.transfer.feign.RemoteTransferService;
import com.xueyi.system.api.digitalmans.feign.RemoteManDeviceService;
import com.xueyi.system.api.model.Source;
import com.xueyi.tenant.api.tenant.domain.dto.TeTenantDto;
import com.xueyi.tenant.api.tenant.feign.RemoteTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时任务调度测试
 *
 * @author xueyi
 */
@Component("dgmanTask")
public class DgmanTask {

    @Autowired
    RemoteTenantService tenantService;

    @Autowired
    RemoteManDeviceService remoteManDeviceService;

    public void ryParams(String params) {
        System.out.println(StrUtil.format("执行有参方法：参数{}", params));
    }

    public void dgmanMonitor() {
        R<List<TeTenantDto>> listR = tenantService.tenantList();
        if (listR.isFail()) {
            System.out.println("租户列表获取失败");
            return;
        }
        listR.getData().forEach(item->{
            // 获取数据源
            Source source = SourceUtil.getSourceCache(item.getStrategyId());
            // 更新租户内数字人信息
            remoteManDeviceService.manDeviceListInnerSync(item.getId());
        });
        System.out.println("监控心跳执行完成");
    }

    /**
     * 触发条件：0 0 10 * * *
     * 每日十点触发，收集当前在线数
     */
    public void dgmanDeviceOnlineState() {
        remoteManDeviceService.syncNumbersOfOnline();
    }
}
