
package com.lideeyunji.core.framework.config.listener;

import com.lideeyunji.core.framework.mapper.LideeYunJiSqlMapper;
import com.lideeyunji.core.framework.service.IFormService;
import com.lideeyunji.core.framework.service.IFrameSqlService;
import com.lideeyunji.tool.framework.yunji.component.redis.lideeYunjiRedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


@Slf4j
@Order(value = 999)
@Component
public class LideeYunJiListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    lideeYunjiRedisUtils redisUtil;

    @Autowired
    private IFormService dbFormService;

    @Autowired
    private LideeYunJiSqlMapper sqlMapper;


    @Autowired
    private IFrameSqlService sqlService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        dbFormService.cleanCache();
        log.info("1.清除框架缓存--->完成");
        dbFormService.initDataAuthTable();
        log.info("2.处理那些表需要做数据权限--->完成");
        dbFormService.initOtherDataSource();
        log.info("3.初始化动态数据源--->完成");

        /*String sql1="insert into tbl_studentlin(name,age) value(#{ew[0].name},#{ew[0].age});";
        String sql2="insert into tbl_studentlin(name,age) value(#{ew[1].name},#{ew[1].age})";

       List<String> sqlListStr=new ArrayList<>();
       sqlListStr.add(sql1);
       sqlListStr.add(sql2);

        Map<String,Object> dataMap1=new HashMap<>();
        dataMap1.put("name","张三");
        dataMap1.put("age",18);

        Map<String,Object> dataMap2=new HashMap<>();
        dataMap2.put("name","李四");
        dataMap2.put("age",19);


        sqlService.insertDataByPlus("tbl_studentlin",dataMap1);*/

   /*     long time1 = System.currentTimeMillis();
        List<Map<String,Object>> dataMapList=new ArrayList<>();
        for (int i = 0; i < 100 * 10000; i++) {
            Map<String,Object> dataMap1=new HashMap<>();
            dataMap1.put("age",i);
            dataMap1.put("name","姓名"+i);

            dataMapList.add(dataMap1);
        }

        Set<String> fieldNameList=new HashSet<>();
        fieldNameList.add("name");
        fieldNameList.add("age");
        sqlService.insertDataListByPlus("tbl_studentlin",fieldNameList,dataMapList);

        long time2 = System.currentTimeMillis();

        log.info("批量插入耗时：{}",time2-time1);*/
    }


    
}