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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.*;
import java.util.stream.Collectors;

/**
 * 普通国道路线平均行程车速
 *
 * @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;
    }
}
