package com.lutao.cloud.collect.runner;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lutao.cloud.collect.service.AppInfoService;
import com.lutao.entity.AppInfo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Order(1)
@AllArgsConstructor
@Slf4j
public class InitAppInfo implements CommandLineRunner {

    private final AppInfoService appInfoService;

    private final RedisTemplate redisTemplate;

    @Override
    public void run(String... args) throws Exception {
        List<AppInfo> list = appInfoService.list();

        list.forEach(appInfo -> {
            BoundHashOperations appinfoHash = redisTemplate.boundHashOps("appinfo");
            appinfoHash.put(appInfo.getAppKey(),appInfo);
            log.info("appKey:{}",appInfo.getAppKey());
        });
    }
}
