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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.module.roadnet_zhjc.service.roadNetZhjcService;
import com.elephant.framework.galaxy.aroad.module.roadnet_zhjc.entity.ZhyhZhzs;
import com.elephant.framework.galaxy.aroad.module.roadnet_zhjc.entity.ZhyhZhzsData;
import com.elephant.framework.galaxy.aroad.module.roadnet_zhjc.entity.ZhyhZhzsKeyValue;
import com.elephant.framework.galaxy.aroad.module.roadnet_zhjc.mapper.roadNetZhjcMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * 智慧养护_综合展示
 *
 * @author wangjian
 * @date 2019-04-26 11:51:59
 */
@Service
@AllArgsConstructor
public class roadNetZhjcServiceImpl extends ServiceImpl<roadNetZhjcMapper, ZhyhZhzs> implements roadNetZhjcService {

    private final roadNetZhjcMapper zhyhZhzsMapper;

    /**
     * 智慧养护综合展示根据年份进行数据查询
     * @param year 年份
     * @return
     */
    public ZhyhZhzsData getRoadNetZhjcData(String year) {

        ZhyhZhzsData zhyhZhzsData = new ZhyhZhzsData();
        zhyhZhzsData.setZhyhZhzsQlOne(getZhyhZhzsQlListByYear("ql1",year));
        zhyhZhzsData.setZhyhZhzsQlTwo(getZhyhZhzsQlListByYear("ql2",year));
        zhyhZhzsData.setZhyhZhzsQlThree(getZhyhZhzsQlListByYear("ql3",year));

        zhyhZhzsData.setZhyhZhzsSdOne(getZhyhZhzsQlListByYear("sd1",year));
        zhyhZhzsData.setZhyhZhzsSdTwo(getZhyhZhzsQlListByYear("sd2",year));
        zhyhZhzsData.setZhyhZhzsSdThree(getZhyhZhzsQlListByYear("sd3",year));


        zhyhZhzsData.setZhyhZhzsOne(getZhyhZhzsQlListByYear("one",year));

        return zhyhZhzsData;
    }

    public List<ZhyhZhzsKeyValue> getZhyhZhzsQlListByYear(String type, String year) {
        List<ZhyhZhzsKeyValue> zhyhZhzsKeyValues = new ArrayList<ZhyhZhzsKeyValue>();
        List<ZhyhZhzs> zhyhZhzss = zhyhZhzsMapper.selectList(Wrappers.<ZhyhZhzs>query().lambda().eq(ZhyhZhzs::getType,type).eq(ZhyhZhzs::getYear,year));
        for(ZhyhZhzs zhyhZhzs : zhyhZhzss) {
            ZhyhZhzsKeyValue zhyhZhzsKeyValue = new ZhyhZhzsKeyValue();
            zhyhZhzsKeyValue.setKey(zhyhZhzs.getName());
            zhyhZhzsKeyValue.setValue(zhyhZhzs.getValue());
            zhyhZhzsKeyValues.add(zhyhZhzsKeyValue);
        }
        return zhyhZhzsKeyValues;
    }



}
