package com.friday.custody.quartz;

import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.friday.custody.service.basicService.CdsProductInfoService;
import com.friday.custody.service.tenantService.CustodyTenantMappingService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Set;

@Slf4j
@DisallowConcurrentExecution
public class SyncZXDataJob extends QuartzJobBean {

    @Autowired
    private CdsProductInfoService cdsProductInfoService;
    @Autowired
    private CustodyTenantMappingService custodyTenantMappingService;

    @Value("${custody.quartz.syncZXDataJob.switch}")
    private Boolean syncOverviewOfPrivateFundSwitch;

    @Override
    protected void executeInternal(JobExecutionContext context) {
        if (!syncOverviewOfPrivateFundSwitch) {
            log.warn("定时拉取资讯数据开关:未开启!");
            return;
        }
        Set<String> privatePlatformAdminSet = custodyTenantMappingService.queryAdminList();
        if (CollectionUtils.isNotEmpty(privatePlatformAdminSet)) {
            for (String admin : privatePlatformAdminSet) {
                log.info("定时拉取资讯数据开始，租户：{}", admin);
                cdsProductInfoService.syncFundInfoFromHtscCds(admin);
            }
        }

    }
}
