package com.gyee.wisdom.alarm.sharding.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.wisdom.alarm.sharding.entity.StopType;
import com.gyee.wisdom.alarm.sharding.mapper.StopTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;


@Service
public class StopTypeService extends ServiceImpl<StopTypeMapper, StopType> {


    @Autowired
    private StopTypeMapper stopTypeMapper;

    public List<StopType> queryStopTypeList() {
        List<StopType> treeType = stopTypeMapper.queryStopTypeList("gz");
        return treeType;
    }

    List<Object> list = new ArrayList<Object>();
    private List<Object> typeList(List<StopType> types) {
        for (StopType t : types) {
            Map<String, Object> mapArr = new LinkedHashMap<String, Object>();
            mapArr.put("lable", t.getId());
            mapArr.put("value", t.getName());
            mapArr.put("children", typeChild(t.getId()));
            list.add(mapArr);
        }
        return list;
    }


    private List<?> typeChild(String parentid) {
        List<Object> lists = new ArrayList<Object>();
        List<Map> typeChild = stopTypeMapper.queryStopTypeParent(parentid);
        for (Map c : typeChild) {
            Map<String, Object> childArray = new LinkedHashMap<String, Object>();
            childArray.put("lable", c.get("lable"));
            childArray.put("value", c.get("value"));
            childArray.put("children", typeChild(c.get("lable").toString()));
            lists.add(childArray);
        }
        return lists;
    }


}
