package com.muyu.data.util;

import com.muyu.common.core.domain.Result;
import com.muyu.data.remote.RemoteCarService;
import com.muyu.data.remote.RemoteFenceService;
import com.muyu.domain.resp.SysCarVo;
import com.muyu.fence.domain.resp.GroupFenceListresp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

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

@Component
public class InitDataRedis implements ApplicationRunner {


    @Resource
    private RedisTemplate redisTemplate;
    @Autowired
    private RemoteCarService remoteCarService;
    @Autowired
    private RemoteFenceService remoteFenceService;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        //查询数控库中的车辆列表基本信息
        Result<List<SysCarVo>> sysCarVoListResult = remoteCarService.selectSysCarVoList(null);
        List<SysCarVo> sysCarVoList = sysCarVoListResult.getData();
        //将全部信息存入redis中
        for (SysCarVo sysCarVo : sysCarVoList) {
            String carVin = sysCarVo.getCarVin();
            redisTemplate.opsForValue().set("four:car:"+carVin,sysCarVo);
        }

        //查询车辆围栏组列表信息
        Result<List<GroupFenceListresp>> groupListResult = remoteFenceService.selectGroupList(null);
        List<GroupFenceListresp> groupFenceList = groupListResult.getData();
        //将去全部信息存入redis中
        for (GroupFenceListresp groupFenceListresp : groupFenceList) {
            Long id = groupFenceListresp.getId();
            redisTemplate.opsForValue().set("four:fenceGroup:"+id,groupFenceListresp);
        }








    }
}
