package com.njcn.influx.config;

import com.njcn.influx.bo.po.PqDeviceBak;
import com.njcn.influx.bo.po.PqLineBak;
import com.njcn.influx.service.IPqDeviceBakService;
import com.njcn.influx.service.PqLineBakService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:
 * Date: 2024/1/17  14:36【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Component
public class IdMappingCache {

    @Autowired
    private PqLineBakService pqLineBakService;
    @Autowired
    private  IPqDeviceBakService pqDeviceBakService;

    @Autowired
    private RedisUtil redisUtil;

    public static   List<Integer> oracleIds = new ArrayList<>();
    @PostConstruct
    public void init() {
        Map<String, String> DevIdMapping = new HashMap<>();
        Map<String, String> LineIdMapping = new HashMap<>();
        List<PqLineBak> resultList = pqLineBakService.list();
        for (PqLineBak row : resultList) {
            String id = row.getId();
            String lineId = row.getLineId();
            oracleIds.add(Integer.valueOf(lineId));
            LineIdMapping.put(lineId,id );
        }
        redisUtil.saveByKey("LineIdMapping",LineIdMapping);

        List<PqDeviceBak> list = pqDeviceBakService.list();

        for (PqDeviceBak row : list) {
            String id = row.getId();
            String devId = row.getDevId()+"";
            DevIdMapping.put(devId,id );
        }
        redisUtil.saveByKey("DevIdMapping",DevIdMapping);

    }

}
