package com.xhpc.system.service.impl;

import com.xhpc.system.api.domain.SysUser;
import com.xhpc.system.domain.SysMenu;
import com.xhpc.system.domain.XhpcDataDimension;
import com.xhpc.system.domain.vo.TreeSelect;
import com.xhpc.system.mapper.XhpcDataDimensionMapper;
import com.xhpc.system.service.IXhpcDataDimensionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author yuyang
 * @date 2021/10/26 14:16
 * @Version 1.0
 */
@Service
public class XhpcDataDimensionServiceImpl implements IXhpcDataDimensionService {


    @Autowired
    private XhpcDataDimensionMapper xhpcDataDimensionMapper;

    @Override
    public List<Integer> selectByUserId(Long userId) {

        return xhpcDataDimensionMapper.selectByUserId(userId);
    }

    @Override
    public List<TreeSelect> buildMenuTreeSelect() {
        List<TreeSelect> treeSelectList =new ArrayList<TreeSelect>();
        //拼接树
        //获取所有运营商和场站
        List<Map<String, Object>> list = xhpcDataDimensionMapper.buildMenuTreeSelect();

        if(list !=null && list.size()>0){
            for (int i = 0; i <list.size() ; i++) {
                TreeSelect treeSelect =new TreeSelect();
                Map<String, Object> map = list.get(i);
                treeSelect.setId(Long.valueOf(map.get("operatorId").toString()));
                treeSelect.setLabel(map.get("operatorName").toString());
                if(map.get("chargingStationId") !=null){
                    String[] ids = map.get("chargingStationId").toString().split(",");
                    String[] names = map.get("chargingStationName").toString().split(",");
                    List<TreeSelect> treeSelectList1 =new ArrayList<TreeSelect>();
                    for (int j = 0; j <ids.length ; j++) {
                        TreeSelect ts =new TreeSelect();
                        ts.setId(Long.valueOf(ids[j]));
                        ts.setLabel(names[j]);
                        treeSelectList1.add(ts);
                    }
                    treeSelect.setChildren(treeSelectList1);
                }
                treeSelectList.add(treeSelect);
            }
        }
        return treeSelectList;
    }


}
