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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.module.zhyh.entity.ZhyhZhzs;
import com.elephant.framework.galaxy.aroad.module.zhyh.entity.ZhyhZhzsData;
import com.elephant.framework.galaxy.aroad.module.zhyh.entity.ZhyhZhzsKeyValue;
import com.elephant.framework.galaxy.aroad.module.zhyh.mapper.ZhyhZhzsMapper;
import com.elephant.framework.galaxy.aroad.module.zhyh.service.ZhyhZhzsService;
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 ZhyhZhzsServiceImpl extends ServiceImpl<ZhyhZhzsMapper, ZhyhZhzs> implements ZhyhZhzsService {

    private final ZhyhZhzsMapper zhyhZhzsMapper;

    /**
     * 智慧养护综合展示根据年份进行数据查询
     * @param year 年份
     * @return
     */
    public ZhyhZhzsData getZhyhZhzsData(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;
    }



}
