package com.yeejoin.equip.eqmx;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.equip.entity.EquipmentIndexVO;
import com.yeejoin.equip.entity.EquipmentSpecificIndex;
import com.yeejoin.equip.mapper.mysql.EquipmentSpecificIndexMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

@Component("SystemInit")
public class SystemInit {

    public static  Map<String, Map<String,String>> map = new HashMap<>();

    public static  Map<String, Map<String,String>> fanmap = new HashMap<>();

    @Autowired
    private EquipmentSpecificIndexMapper  equipmentSpecificIndexMapper;

    @PostConstruct
    public void point()
    {
        EquipmentIndexVO equipmentIndexVO = new EquipmentIndexVO();
        equipmentIndexVO.setDType("null");
        equipmentIndexVO.setNewAddress("notnull");
        List<EquipmentIndexVO> list = equipmentSpecificIndexMapper.getEquipSpecificIndexList(equipmentIndexVO);
        Map<String,List<EquipmentIndexVO>> glist = list.stream()
                .collect(Collectors.groupingBy(
                        EquipmentIndexVO::getGatewayId
                ));
        for(String key :glist.keySet())
        {
            Map<String,String> map1  = new HashMap<>();
            for(EquipmentIndexVO v : glist.get(key))
            {
                map1.put(v.getNewAddress(),v.getIndexAddress());
            }
            map.put(key,map1);
        }

        equipmentIndexVO.setDType("notnull");
        List<EquipmentIndexVO> list2 = equipmentSpecificIndexMapper.getEquipSpecificIndexList(equipmentIndexVO);
        Map<String,List<EquipmentIndexVO>> list3 = list2.stream()
                .collect(Collectors.groupingBy(
                        EquipmentIndexVO::getDType
                ));
        for(String key :list3.keySet())
        {
            Map<String,String> map1  = new HashMap<>();
            for(EquipmentIndexVO v : list3.get(key))
            {
                map1.put(v.getNewAddress(),v.getIndexAddress());
            }
            fanmap.put(key,map1);
        }
    }
}
