import { awaitData } from "../biz/dataInit";
import { OPERATIONALDATATYPE, TABLENAME } from "../config/enum/dbEnum";
import { selectData } from "./operationalData";


// 初始化数据文件结构
async function initDataFile() {
    let enterpriseList = await selectData(OPERATIONALDATATYPE.查询多个, TABLENAME.企业基础信息表, {}, ["eId", "uscc", "enterpriseName"]);
    let currentData = {};
    
    let usccData = await awaitData("91310115MADM8EA654");
    currentData["91310115MADM8EA654"] = usccData;

    for (let i = 0; i < enterpriseList.length; i++) {
        let info = enterpriseList[i];
        console.log("开始同步企查查数据");
        let usccData = await awaitData(info.uscc);
        currentData[info.uscc] = usccData;
        console.log(`${info.enterpriseName} 同步成功, eId：${info.eId}，下标 ${i}`);
    }
    
    console.log("刷新缓存数据结束")
}


/**
 * 接口更新
 * 设置定时器，每天刷新一次数据
 */
 export async function initApiDataStorage() {
    await initDataFile();
    setInterval(async function () {
        await initDataFile();
    }, 3600 * 1000 * 24);
}








