package com.zksy.data.schedule;

import com.zksy.data.service.IBaseSaveDataInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;

@EnableScheduling
@Component
@Slf4j
public class CollectDataSchedule {
    public HashMap<String,String> serviceMap = new HashMap<>();
    @Autowired
    private ApplicationContext applicationContext;
    @PostConstruct
    public void init() {
        serviceMap.put("xcrCompanyInvestmentServiceImpl", "gateway/api/1/getGdjczxgxxByUniscid");
        serviceMap.put("xcrEquityChangeServiceImpl", "gateway/api/1/getGqczbgxxByUniscid");
        serviceMap.put("xcrSupplementaryForeignInvestmentServiceImpl", "gateway/api/1/getWzbcxxByUniscid");
        serviceMap.put("xcrAppointDelegatesServiceImpl", "gateway/api/1/getWpdbxxByUniscid");
        serviceMap.put("xcrAgriculturalSupplementServiceImpl", "gateway/api/1/getNzbcxxByUniscid");
        serviceMap.put("xcrDomesticCapitalSupplementServiceImpl", "gateway/api/1/getNzbcxxByUniscid1");
        serviceMap.put("xcrInstallmentPaymentServiceImpl", "gateway/api/1/getFqsjxxByUniscid");
        serviceMap.put("xcrInvestorSubscriptionDetailsServiceImpl", "gateway/api/1/getTzrrjxxByUniscid");
        serviceMap.put("xcrNonNaturalPersonContributionServiceImpl", "gateway/api/1/getFzrrczxxByUniscid");
        serviceMap.put("xcrNaturalPersonContributionsServiceImpl", "gateway/api/1/getZrrczxxByUniscid");
        serviceMap.put("xcrHistoryNameServiceImpl", "gateway/api/1/getLsmcxxByUnscid");
        serviceMap.put("xcrHistoricalLegalRepresentativeServiceImpl", "gateway/api/1/getLsfddbrxxByUniscid");
        serviceMap.put("xcrAbnormalHouseholdTerminationServiceImpl", "gateway/api/1/getFzchjcxxByUniscid");
        serviceMap.put("xcrTaxAdministrativePenaltyServiceImpl", "gateway/api/1/getSwxzcfxxByUniscid");
        serviceMap.put("xcrAffiliatedEnterpriseServiceImpl", "gateway/api/1/getLsqyxxByUniscid");
        serviceMap.put("xcrInstallmentSubscriptionServiceImpl", "gateway/api/1/getFqrjxxByUniscid");
        serviceMap.put("xcrAdministrativeLicensingAgriculturalCollegesServiceImpl", "gateway/api/1/getNznbxzxkxxByUniscid");
        serviceMap.put("xcrEnterpriseExceptionListServiceImpl", "gateway/api/1/getQyycmlxxByUniscid1");
        serviceMap.put("xcrInvestorAbnormalRecordServiceImpl", "gateway/api/1/getQyjyycmlgdxxByUnsicd");
        serviceMap.put("xcrEnterprisePublicityLicenseServiceImpl", "gateway/api/1/getQygsxkxxByUniscid");
        serviceMap.put("xcrEnterprisePublicityEquityChangeServiceImpl", "gateway/api/1/getQygsgqbgxxByUniscid");
        serviceMap.put("xcrSimplifiedCancellationAnnouncementServiceImpl", "gateway/api/1/getJyzxggxxByUniscid");
        serviceMap.put("xcrCancelTaxRegistrationServiceImpl", "gateway/api/1/getZxswdjxxByUniscid");
        serviceMap.put("xcrEnterprisePublicityInvestorInformationStatusServiceImpl", "gateway/api/1/getQygsczrxxqkByUniscid");
        serviceMap.put("xcrEnterprisePublicityDetailsContributionsContributorsServiceImpl", "gateway/api/1/getCzrsjmxByUniscid");
        serviceMap.put("xcrEnterprisePublicationSupplySubscribedDetailsInvestorsServiceImpl", "gateway/api/1/getQygsczrrjmxByUniscid");
        serviceMap.put("xcrRevisionInformationAgriculturalCollegeAnnualReportServiceImpl", "gateway/api/1/getNznbxgxxByUniscid");
        serviceMap.put("xcrBasicSupplementAgriculturalCollegeAnnualServiceImpl", "gateway/api/1/getNznbjbxxbcByUniscid");
        serviceMap.put("xcrEnterpriseBasicInformationServiceImpl", "gateway/api/1/getQyjbxxByUniscid");
        serviceMap.put("xcrEnterpriseNameApprovalServiceImpl", "gateway/api/1/getQymcxxByUniscid");
        serviceMap.put("xcrSeriousIllegalDishonestEnterprisesServiceImpl", "gateway/api/1/getYzwfsxqymdBydm");
        serviceMap.put("xcrSeriousIllegalDishonestEnterprisesDetailServiceImpl", "gateway/api/1/getYzwfxxxxByUniscid");
        serviceMap.put("xcrEquityPledgeInfoServiceImpl", "gateway/api/1/getGqczdjxxBydm");
        serviceMap.put("xcrEquityFreezeServiceImpl", "gateway/api/1/getGqdjxxByUniscid");
        serviceMap.put("xcrEquityChangeInfoServiceImpl", "gateway/api/1/getGqbgxxByUniscid");
        serviceMap.put("xcrEquityFreezeExecutionServiceImpl", "gateway/api/1/getGqdjbzxrxxByUniscid");
        serviceMap.put("xcrAbnormalBusinessOperationsServiceImpl", "gateway/api/1/getQyycmlxxxxByUniscid");
        serviceMap.put("xcrCheckWorkInfoServiceImpl", "gateway/api/1/getJcgzxxByUniscid");
        serviceMap.put("xcrTaxRegistrationEstablishmentServiceImpl", "gateway/api/1/getSwdjslxxByUniscid");
        serviceMap.put("xcrStopBusinessInformationServiceImpl", "gateway/api/1/getGtgshtxyxxByUniscid");
        serviceMap.put("xcrAbnormalHouseholdIdentificationServiceImpl", "gateway/api/1/getFzchrdxxByUniscid");
        serviceMap.put("xcrIncomeTaxReturnServiceImpl", "gateway/api/1/getQysdssbxxByUniscid1");
        serviceMap.put("xcrMainFinancialStatementsServiceImpl", "gateway/api/1/getCwbbzbByUniscid");
        serviceMap.put("xcrInvoiceIssuanceServiceImpl", "gateway/api/1/fpkpxxByUniscid");
        serviceMap.put("xcrConfirmationTerminationServiceImpl", "gateway/api/1/getFzchrdjcxxbByUniscid");
        serviceMap.put("xcrTaxpayerCreditRatingServiceImpl", "gateway/api/1/getNsrxydjByUniscid");
        serviceMap.put("xcrInstitutionalClientsServiceImpl", "gateway/api/1/getJgkhxxByUnisicd");
        serviceMap.put("xcrRecordDishonestyServiceImpl", "gateway/api/1/getSxjlmdByQymc");
        serviceMap.put("xcrTechnologyPlanProjectServiceImpl", "gateway/api/1/getKjjhxmapbByQymc");
        serviceMap.put("xcrTechnologyAwardSupplementServiceImpl", "gateway/api/1/getKjjbxmjzjqkByQymc");
        serviceMap.put("xcrMinorEnterprisesServiceImpl", "gateway/api/1/getKjxzxqymdByQymc");
        serviceMap.put("xcrInnovationPlatformServiceImpl", "gateway/api/1/getCxptmd");
        serviceMap.put("xcrHighTechServiceImpl", "gateway/api/1/getGxjsqymdByUniscid");
        serviceMap.put("xcrFoodProductionLicenseDetaliServiceImpl", "gateway/api/1/getSpscxkzpzmxByUniscid");
        serviceMap.put("xcrLegalRepresentativeServiceImpl", "gateway/api/1/getSpscfddbrxxByUniscid");
        serviceMap.put("xcrFoodProductionLicenseServiceImpl", "gateway/api/1/getSpscxkzjbxxByUniscid");
        serviceMap.put("xcrFoodBusinessLicenseServiceImpl", "gateway/api/1/getSpjyxkzjbxxByUniscid");
        serviceMap.put("xcrMsAdministrativeLicenseServiceImpl", "gateway/api/1/getXzxkxxByUniscid");
        serviceMap.put("xcrContactInformationServiceImpl", "gateway/api/1/getLlyxxByUniscid");
        serviceMap.put("xcrFinancialManagerServiceImpl", "gateway/api/1/getCwfzrByUniscid");
        serviceMap.put("xcrPersonalRevokeRecordServiceImpl", "gateway/api/1/getGtdxxxByUniscid");
        serviceMap.put("xcrNoticeRecordServiceImpl", "gateway/api/1/getGsggxxByUniscid");
        serviceMap.put("xcrWebsiteInfoServiceImpl", "gateway/api/1/getGtnbwzhwdxxByUniscid");
        serviceMap.put("xcrSmallAndMicroEnterprisesServiceImpl", "gateway/api/1/getXwqymljbxxByUniscid");
        serviceMap.put("xcrRandomInspectionTaskServiceImpl", "gateway/api/1/getJcgzxxmlByUniscid");
        serviceMap.put("xcrAnnualReportExternalInvestmentServiceImpl", "gateway/api/1/getQynbdwtzxxByUniscid");
        serviceMap.put("xcrExternalGuaranteeServiceImpl", "gateway/api/1/getQynbdwtgbzxxByUniscid");
        serviceMap.put("xcrRevokeInfoServiceImpl", "gateway/api/1/getDxxxByUniscid");
        serviceMap.put("xcrBranchOfficesInfoServiceImpl", "gateway/api/1/getFzjgbaxxByUniscid1");
        serviceMap.put("xcrLicenseInfoServiceImpl", "gateway/api/1/getXkxxByUniscid");
        serviceMap.put("xcrChangeFilingServiceImpl", "gateway/api/1/getBgbaxxByUniscid");
        serviceMap.put("xcrSocialInsuranceDataServiceImpl", "gateway/api/1/getQynbshbxxxByUniscid");
        serviceMap.put("xcrAgriculturalCollegeAnnualReportServiceImpl", "gateway/api/1/getNznbjbxxByUniscid");
        serviceMap.put("xcrEnterprisePollutionPermitInfoServiceImpl", "gateway/api/1/getQypwxkxxByUniscid");
        serviceMap.put("xcrKeyPollutionSourcesServiceImpl", "gateway/api/1/getZdpwdwmlByShxyfwm");
        serviceMap.put("xcrEnvironmentalPenaltyDecisionServiceImpl","gateway/api/1/getHbcfjdqkxxByUniscid");
        serviceMap.put("xcrIndividualBusinessInformationServiceImpl","gateway/api/1/getGtjyzjbxxByUniscid");
        serviceMap.put("xcrIndustryCommerceServiceImpl","gateway/api/1/getGtgshjbxxByUniscid");
        serviceMap.put("xcrAgriculturalSpecializedWebsiteService","gateway/api/1/nznbwzhwdxxByUniscid");
        serviceMap.put("xcrIndividualChangeInformationServiceImpl","gateway/api/1/getGtbgxxByUniscid");
        serviceMap.put("xcrIndividualCancellationServiceImpl","gateway/api/1/getGtzxxxByUniscid");
        serviceMap.put("xcrIndividualBusinessAbnormalityServiceImpl","gateway/api/1/getGtjyycbjxxByUniscid");
        serviceMap.put("xcrMoveOutServiceImpl","gateway/api/1/getQcxxByUniscid");
        serviceMap.put("xcrMoveInServiceImpl","gateway/api/1/getQrxxByUniscid");
        serviceMap.put("xcrDeregistrationServiceImpl","gateway/api/1/getCxdjxxByUniscid");
        serviceMap.put("xcrCancellationServiceImpl","gateway/api/1/getZxxxByUniscid");
        serviceMap.put("xcrLiquidationBasicInfoServiceImpl","gateway/api/1/getQsjbxxByUniscid1");
        serviceMap.put("xcrLiquidationMemberInfoServiceImpl","gateway/api/1/getQscyxxByUniscid");
        serviceMap.put("xcrAbnormalOperationAnnouncementServiceImpl","gateway/api/1/getJyycggplmdxxByUniscid");
        serviceMap.put("xcrFarmSpecialAbnormalDetailServiceImpl","gateway/api/1/getNzycmlxxxxByUniscid");
        serviceMap.put("xcrEnterpriseAnnualReportWebsiteServiceImpl","gateway/api/1/getQynbwzhwdxxByUniscid");
        serviceMap.put("xcrEnterpriseAnnualReportEquityChangeServiceImpl","gateway/api/1/getQynbgqbgxxByUniscid");
        serviceMap.put("xcrIndividualCancellationObjectionServiceImpl","gateway/api/1/getJyzxyyxxByUniscid");
        serviceMap.put("xcrRevokeRegistrationServiceImpl","gateway/api/1/getGtcxdjxxByUniscid");
        serviceMap.put("xcrAgriculturalSpecializedWebsiteServiceImpl","gateway/api/1/nznbwzhwdxxByUniscid");
        serviceMap.put("xcrAnSfcBranchinfoServiceImpl","gateway/api/1/getNznbfzjgxxByUniscid");
        serviceMap.put("xcrMajorMembersServiceImpl","gateway/api/1/zyryxxByUniscid");
        serviceMap.put("xcrOtherInfo36ServiceImpl","interface/v1/datawarehouse/list");
        serviceMap.put("xcrAdministrativeLicensingServiceImpl","interface/v1/doublePublic/findLicensingList");
        serviceMap.put("xcrAdministrativePenaltyServiceImpl","interface/v1/doublePublic/findSanctionList");
        serviceMap.put("xcrOtherInfo37ServiceImpl","interface/v1/datawarehouse/list");
        serviceMap.put("xcrOtherInfo38ServiceImpl","interface/v1/datawarehouse/list");
        serviceMap.put("xcrOtherInfo39ServiceImpl","interface/v1/datawarehouse/list");
        serviceMap.put("xcrTrustworthyIncentive42ServiceImpl","interface/v1/datawarehouse/list");
        serviceMap.put("xcrDishonestyPunishment19ServiceImpl","interface/v1/datawarehouse/list");
    }

    @Scheduled(cron = "0 0 1 1 * ?")
    public void getDataByMonth() {
        List<String> serviceList = List.of(
                "xcrOtherInfo38ServiceImpl",
                "xcrOtherInfo39ServiceImpl"
        );
        commonHandler(serviceList);
    }
    @Scheduled(cron = "0 0 1 * * ?")
    public void getDataByDay1() {
        List<String> serviceList = List.of(
                "xcrEnvironmentalPenaltyDecisionServiceImpl",
                "xcrAdministrativeLicensingServiceImpl",
                "xcrTrustworthyIncentive42ServiceImpl",
                "xcrDishonestyPunishment19ServiceImpl"
        );
        commonHandler(serviceList);
    }

    @Scheduled(cron = "0 0 2 * * ?")
    public void getDataByDay2() {

    }

    @Scheduled(cron = "0 0 3 ? * SUN")
    public void getDataByDay0() {
        List<String> serviceList = List.of(
                "xcrRecordDishonestyServiceImpl",
                "xcrInstitutionalClientsServiceImpl",
                "xcrTaxpayerCreditRatingServiceImpl",
                "xcrMainFinancialStatementsServiceImpl",
                "xcrStopBusinessInformationServiceImpl",
                "xcrAbnormalHouseholdTerminationServiceImpl",
                "xcrTaxAdministrativePenaltyServiceImpl",
                "xcrEnterpriseBasicInformationServiceImpl"
        );
        commonHandler(serviceList);
    }

    @Scheduled(cron = "0 0 4 ? * SUN")
    public void getDataByWeek1() {
        List<String> serviceList = List.of(
                "xcrEnterprisePollutionPermitInfoServiceImpl",
                "xcrKeyPollutionSourcesServiceImpl",
                "xcrAgriculturalSpecializedWebsiteServiceImpl",
                "xcrAnSfcBranchinfoServiceImpl",
                "xcrCompanyInvestmentServiceImpl",
                "xcrEquityChangeServiceImpl",
                "xcrSupplementaryForeignInvestmentServiceImpl",
                "xcrAppointDelegatesServiceImpl",
                "xcrAgriculturalSupplementServiceImpl",
                "xcrDomesticCapitalSupplementServiceImpl",
                "xcrInstallmentPaymentServiceImpl",
                "xcrInvestorSubscriptionDetailsServiceImpl",
                "xcrNonNaturalPersonContributionServiceImpl",
                "xcrNaturalPersonContributionsServiceImpl",
                "xcrHistoryNameServiceImpl",
                "xcrHistoricalLegalRepresentativeServiceImpl",
                "xcrAffiliatedEnterpriseServiceImpl",
                "xcrInstallmentSubscriptionServiceImpl",
                "xcrAdministrativeLicensingAgriculturalCollegesServiceImpl",
                "xcrEnterpriseExceptionListServiceImpl",
                "xcrInvestorAbnormalRecordServiceImpl"
        );
        commonHandler(serviceList);

    }
    @Scheduled(cron = "0 0 5 ? * SUN")
    public void getDataByWeek2() {
        List<String> serviceList = List.of(
                "xcrNoticeRecordServiceImpl",
                "xcrPersonalRevokeRecordServiceImpl",
                "xcrCheckWorkInfoServiceImpl",
                "xcrAbnormalBusinessOperationsServiceImpl",
                "xcrEquityFreezeExecutionServiceImpl",
                "xcrEquityChangeInfoServiceImpl",
                "xcrEquityFreezeServiceImpl",
                "xcrEquityPledgeInfoServiceImpl",
                "xcrSeriousIllegalDishonestEnterprisesDetailServiceImpl",
                "xcrSeriousIllegalDishonestEnterprisesServiceImpl",
                "xcrEnterpriseNameApprovalServiceImpl",
                "xcrBasicSupplementAgriculturalCollegeAnnualServiceImpl",
                "xcrEnterprisePublicityInvestorInformationStatusServiceImpl",
                "xcrEnterprisePublicityDetailsContributionsContributorsServiceImpl",
                "xcrEnterprisePublicationSupplySubscribedDetailsInvestorsServiceImpl",
                "xcrRevisionInformationAgriculturalCollegeAnnualReportServiceImpl"
        );
        commonHandler(serviceList);
    }
    @Scheduled(cron = "0 0 6 ? * SUN")
    public void getDataByWeek3() {
        List<String> serviceList = List.of(
                "xcrCancellationServiceImpl",
                "xcrLiquidationBasicInfoServiceImpl",
                "xcrLiquidationMemberInfoServiceImpl",
                "xcrAbnormalOperationAnnouncementServiceImpl",
                "xcrFarmSpecialAbnormalDetailServiceImpl",
                "xcrEnterpriseAnnualReportWebsiteServiceImpl",
                "xcrEnterpriseAnnualReportEquityChangeServiceImpl",
                "xcrIndividualCancellationObjectionServiceImpl",
                "xcrRevokeRegistrationServiceImpl",
                "xcrAgriculturalCollegeAnnualReportServiceImpl",
                "xcrChangeFilingServiceImpl",
                "xcrLicenseInfoServiceImpl",
                "xcrBranchOfficesInfoServiceImpl",
                "xcrRevokeInfoServiceImpl",
                "xcrExternalGuaranteeServiceImpl",
                "xcrAnnualReportExternalInvestmentServiceImpl",
                "xcrRandomInspectionTaskServiceImpl",
                "xcrSmallAndMicroEnterprisesServiceImpl",
                "xcrWebsiteInfoServiceImpl",
                "xcrOtherInfo36ServiceImpl",
                "interface/v1/datawarehouse/list",
                "xcrOtherInfo37ServiceImpl"
        );
        commonHandler(serviceList);
    }

    @Scheduled(cron = "0 0 7 ? * SUN")
    public void getDataByWeek4() {
        List<String> serviceList = List.of(
                "xcrTechnologyPlanProjectServiceImpl",
                "xcrTechnologyAwardSupplementServiceImpl",
                "xcrMinorEnterprisesServiceImpl",
                "xcrInnovationPlatformServiceImpl",
                "xcrHighTechServiceImpl",
                "xcrFoodProductionLicenseDetaliServiceImpl",
                "xcrLegalRepresentativeServiceImpl",
                "xcrFoodProductionLicenseServiceImpl",
                "xcrFoodBusinessLicenseServiceImpl",
                "xcrMsAdministrativeLicenseServiceImpl",
                "xcrContactInformationServiceImpl",
                "xcrFinancialManagerServiceImpl",
                "xcrIndividualBusinessInformationServiceImpl",
                "xcrIndustryCommerceServiceImpl",
                "xcrIndividualChangeInformationServiceImpl",
                "xcrIndividualCancellationServiceImpl",
                "xcrIndividualBusinessAbnormalityServiceImpl",
                "xcrMoveOutServiceImpl",
                "xcrMoveInServiceImpl",
                "xcrDeregistrationServiceImpl",
                "xcrEnterprisePublicityLicenseServiceImpl",
                "xcrEnterprisePublicityEquityChangeServiceImpl",
                "xcrSimplifiedCancellationAnnouncementServiceImpl"
        );
        commonHandler(serviceList);
    }


    private void commonHandler(List<String> serviceList) {
        serviceList.parallelStream().forEach((q)->{
            try {
                Object bean = applicationContext.getBean(q);
                ((IBaseSaveDataInterface) bean).saveDataByUniCode(serviceMap.get(q));
            } catch (BeansException e) {
                log.error("获取name为:{}的bean失败",q);
                throw new RuntimeException(e);
            }
        });
    }
}
