package com.youchain;


import com.youchain.modules.system.service.dto.ApiDictDetailDto;
import com.youchain.modules.system.service.dto.ApiDictDto;
import com.youchain.modules.system.service.dto.ApiDictQueryCriteria;
import com.youchain.modules.system.service.impl.ApiDictServiceImpl;
import com.youchain.utils.RedisUtils;
import com.youchain.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *
 * @description: ApplicationListener
 * @copyright: @Copyright (c) 2022
 * @company: Aiocloud
 * @author: pany
 * @version: 1.0.0
 * @createTime: 2023-07-06 22:09
 */
@Component
@Slf4j
public class MyApiDictListener implements ApplicationListener<ContextRefreshedEvent> {

    public static boolean isCanRun=true;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        // 在这里处理特定的事件逻辑
        if (event.getApplicationContext().getParent() == null) {
            if(isCanRun){
                isCanRun=false;
                System.out.println("收到应用程序事件：" + event.toString());

                System.out.println("收到应用程序事件2：" + event.toString());
                ApiDictQueryCriteria dict=new ApiDictQueryCriteria();
                ApiDictServiceImpl apiDictServiceImpl = SpringContextHolder.getBean(ApiDictServiceImpl.class);
                // 在这里写入加载数据的逻辑
               apiDictServiceImpl.queryAllToSave();


            }
            // 确保只启动一次
            // 在这里编写你的逻辑代码

        }

    }
}

