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.ZhyhZhzsQl;
import com.elephant.framework.galaxy.aroad.module.zhyh.entity.ZhyhZhzsQlData;
import com.elephant.framework.galaxy.aroad.module.zhyh.mapper.ZhyhZhzsQlMapper;
import com.elephant.framework.galaxy.aroad.module.zhyh.service.ZhyhZhzsQlService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * 智慧养护_综合展示_桥梁
 *
 * @author wangjian
 * @date 2019-04-26 15:34:59
 */
@Service
@AllArgsConstructor
public class ZhyhZhzsQlServiceImpl extends ServiceImpl<ZhyhZhzsQlMapper, ZhyhZhzsQl> implements ZhyhZhzsQlService {

    private final ZhyhZhzsQlMapper zhyhZhzsQlMapper;

    /**
     * 获取综合展示桥梁信息
     * @param year
     * @return
     */
    public ZhyhZhzsQlData getZhyhZhzsQlDataByYear(String year) {
        ZhyhZhzsQlData zhyhZhzsQlData = new ZhyhZhzsQlData();

        zhyhZhzsQlData.setZhyhZhzsQl(getZhyhZhzsQlByYearTotle(year));
        zhyhZhzsQlData.setZhyhZhzsQls(getZhyhZhzsQlByYear(year));

        return zhyhZhzsQlData;
    }

    /**
     * 获取饼状图
     * @param year
     * @return
     */
    public List<ZhyhZhzsQl> getZhyhZhzsQlByYear(String year) {
        List<ZhyhZhzsQl> zhyhZhzsQls = new ArrayList<>();
        zhyhZhzsQls = zhyhZhzsQlMapper.selectList(Wrappers.<ZhyhZhzsQl>query().lambda().ne(ZhyhZhzsQl::getSs,"总计").eq(ZhyhZhzsQl::getYear,year));
        return zhyhZhzsQls;
    }

    /**
     * 获取柱状图
     * @param year
     * @return
     */
    public ZhyhZhzsQl getZhyhZhzsQlByYearTotle(String year) {
        ZhyhZhzsQl zhyhZhzsQl = new ZhyhZhzsQl();
        zhyhZhzsQl = zhyhZhzsQlMapper.selectOne(Wrappers.<ZhyhZhzsQl>query().lambda().eq(ZhyhZhzsQl::getYear,year).eq(ZhyhZhzsQl::getSs,"总计"));
        return zhyhZhzsQl;
    }
}
