package net.vtstar.zhongtong.avi.monitoring.runner;

import lombok.extern.slf4j.Slf4j;
import net.vtstar.user.mybatis.provider.OrderBy;
import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.user.search.service.SearchService;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopArea;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopLane;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cache.Cache;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Order(value = 1)
@Component
public class ReadStationToCacheRunner implements CommandLineRunner {

    @Resource(name = "stationCache")
    private Cache stationCache;
    @Autowired
    private SearchService searchService;
    @Autowired
    private PaintshopStationMapper stationMapper;

    @Override
    public void run(String... args) throws Exception {

        List<PaintshopStation> stations = stationMapper.findList(new WhereFilter() {{
            addJoin(PaintshopStation.class, "area_id", PaintshopArea.class, "id");
            addJoin(PaintshopStation.class, "lane_id", PaintshopLane.class, "id");
            addOrderBy(PaintshopStation.class, "sequence", OrderBy.ASC);
        }}, PaintshopStation.class);

        for (PaintshopStation station : stations) {
            stationCache.put(station.getCode(),station);
        }



    }
}
