package com.elephant.framework.galaxy.aroad.module.zhjc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.bigdata.Basehighwayalldata;
import com.elephant.framework.galaxy.aroad.bigdata.EsUtil_fanshe;
import com.elephant.framework.galaxy.aroad.module.zhjc.entity.ZhjcPtgsdLwzs;
import com.elephant.framework.galaxy.aroad.module.zhjc.mapper.ZhjcPtgsdLwzsMapper;
import com.elephant.framework.galaxy.aroad.module.zhjc.service.ZhjcPtgsdLwzsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 普通国道路线平均行程车速
 *
 * @author zyw
 * @date 2019-05-06 14:29:11
 */
@Service
@AllArgsConstructor
public class ZhjcPtgsdLwzsServiceImpl extends ServiceImpl<ZhjcPtgsdLwzsMapper, com.elephant.framework.galaxy.aroad.module.zhjc.entity.ZhjcPtgsdLwzs> implements ZhjcPtgsdLwzsService {

    private final  ZhjcPtgsdLwzsMapper zhjcPtgsdLwzsMapper;

    @Override
    public Map<String, List<ZhjcPtgsdLwzs>> selectLwzs(ZhjcPtgsdLwzs lwzs) {

        Map<String,List<ZhjcPtgsdLwzs>> map = new HashMap<>();

        List<ZhjcPtgsdLwzs> GdList = zhjcPtgsdLwzsMapper.selectGdlwzs(lwzs.getYear());
        List<ZhjcPtgsdLwzs> SdList = zhjcPtgsdLwzsMapper.selectSdlwzs(lwzs.getYear());
        List<ZhjcPtgsdLwzs> GSdList = new ArrayList<>();
        GSdList.addAll(GdList);
        GSdList.addAll(SdList);

        // 定义一个比较器，用于排序
        Comparator<ZhjcPtgsdLwzs> comparator = Comparator.comparingDouble(ZhjcPtgsdLwzs::getYjd);

        GSdList.sort(comparator.reversed());
        map.put("gdList",GdList);
        map.put("sdList",SdList);
        map.put("gsdList",GSdList);


        return map;
    }

    /**
     * 根据路线编号查询所有路段
     * @param lxbh
     * @return
     */
    @Override
    public List<Basehighwayalldata> getLinesByLxbh(String lxbh) {
        List<Basehighwayalldata> lukehighways =null;
        try {
           lukehighways = EsUtil_fanshe.queryHighWayLXBH(lxbh, "basehighwayalldata", "2018", 0, 2000000000);



        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(Arrays.toString(lukehighways.toArray()));
        return lukehighways;
    }


    /**
     * 路网监测--综合监测路网指数top6
     * @author : Xingyuyang
     * @date : 2019/05/29 16:08
     */
    public Map<String, List<ZhjcPtgsdLwzs>> roadNetZhjcTop(ZhjcPtgsdLwzs lwzs) {

        Map<String,List<ZhjcPtgsdLwzs>> map = new HashMap<>();

        List<ZhjcPtgsdLwzs> GdList = zhjcPtgsdLwzsMapper.selectGdlwzs(lwzs.getYear());
        List<ZhjcPtgsdLwzs> SdList = zhjcPtgsdLwzsMapper.selectSdlwzs(lwzs.getYear());
        List<ZhjcPtgsdLwzs> GSdList = new ArrayList<>();
        GSdList.addAll(GdList);
        GSdList.addAll(SdList);

        // 定义一个比较器，用于排序
        Comparator<ZhjcPtgsdLwzs> comparator = Comparator.comparingDouble(ZhjcPtgsdLwzs::getYjd);

        GSdList.sort(comparator.reversed());
        GSdList = GSdList.subList(0,5);
//        map.put("gdList",GdList);
//        map.put("sdList",SdList);
        map.put("gsdList",GSdList);

        return map;
    }
}
