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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.module.common.entity.KeyValues;
import com.elephant.framework.galaxy.aroad.module.zhjs.entity.*;
import com.elephant.framework.galaxy.aroad.module.zhjs.mapper.ZhjsGcxmMapper;
import com.elephant.framework.galaxy.aroad.module.zhjs.service.ZhjsGcxmService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * 工程项目信息表

 *
 * @author wangjian
 * @date 2019-04-08 18:14:32
 */
@Service
@AllArgsConstructor
public class ZhjsGcxmServiceImpl extends ServiceImpl<ZhjsGcxmMapper, ZhjsGcxm> implements ZhjsGcxmService {

    final ZhjsGcxmMapper zhjsGcxmMapper;

    private static String[] citys = new String[]{"济南","青岛","淄博","枣庄","东营","烟台","潍坊","济宁","泰安","威海","日照","滨州","德州","聊城"
            ,"临沂","菏泽","莱芜"};

    /**
     * 根据项目ID查询项目情况
     * @param xmid
     * @return
     */
    public ZhjsXmqk getZhjsXmqkByXmid(String xmid) {
        return zhjsGcxmMapper.getZhjsXmqkByXmid(xmid);
    }



    /**
     * 查询综合展示图一数据
     */
    public List<ZhjsZhzsOne> getZhjsZhzsOneDatas() {
        List<ZhjsZhzsOne> zhjsZhzsOnes = new ArrayList<>();

        List<KeyValues> xujxm = zhjsGcxmMapper.getZhjsZhzsThreeAndOne(null, 1);
        List<KeyValues> xijxm = zhjsGcxmMapper.getZhjsZhzsThreeAndOne(null, 2);
        List<KeyValues> wgxm = zhjsGcxmMapper.getZhjsZhzsThreeAndOne(null, 3);

        for(String city : citys) {
            ZhjsZhzsOne zhjsZhzsOne = new ZhjsZhzsOne();
            zhjsZhzsOne.setCity(city);

            for(KeyValues keyValues : xujxm) {
                if(keyValues.getName().indexOf(city)>-1) {
                    zhjsZhzsOne.setXujxm(keyValues.getNumber());
                }
            }
            for(KeyValues keyValues : xijxm) {
                if(keyValues.getName().indexOf(city)>-1) {
                    zhjsZhzsOne.setXijxm(keyValues.getNumber());
                }
            }
            for(KeyValues keyValues : wgxm) {
                if(keyValues.getName().indexOf(city)>-1) {
                    zhjsZhzsOne.setWgxm(keyValues.getNumber());
                }
            }
            zhjsZhzsOnes.add(zhjsZhzsOne);
        }

        return zhjsZhzsOnes;
    }

    /**
     * 查询综合展示图二数据
     */
    public List<KeyValues> getZhjsZhzsTwoDatas(String city) {
        List<KeyValues> keyValues = new ArrayList<>();

        keyValues.add(new KeyValues("瓶颈续建", zhjsGcxmMapper.getZhjsZhzsTwo(city,"瓶颈",1)));
        keyValues.add(new KeyValues("瓶颈新建", zhjsGcxmMapper.getZhjsZhzsTwo(city,"瓶颈",2)));
        keyValues.add(new KeyValues("瓶颈项目", zhjsGcxmMapper.getZhjsZhzsTwo(city,"瓶颈",null)));
        keyValues.add(new KeyValues("穿城续建", zhjsGcxmMapper.getZhjsZhzsTwo(city,"穿城",1)));
        keyValues.add(new KeyValues("穿城新建", zhjsGcxmMapper.getZhjsZhzsTwo(city,"穿城",2)));
        keyValues.add(new KeyValues("穿城项目", zhjsGcxmMapper.getZhjsZhzsTwo(city,"穿城",null)));

        return keyValues;
    }

    /**
     * 查询综合展示图三数据
     */
    public List<ZhjsZhzsThree> getZhjsZhzsThreeDatas() {
        List<ZhjsZhzsThree> zhjsZhzsThrees = new ArrayList<>();

        List<KeyValues> ccxuj = zhjsGcxmMapper.getZhjsZhzsThreeAndOne("穿城项目",1);
        List<KeyValues> ccxij = zhjsGcxmMapper.getZhjsZhzsThreeAndOne("穿城项目",2);
        List<KeyValues> pjxuj = zhjsGcxmMapper.getZhjsZhzsThreeAndOne("瓶颈项目",1);
        List<KeyValues> pjxij = zhjsGcxmMapper.getZhjsZhzsThreeAndOne("瓶颈项目",2);

        for(String city : citys) {
            ZhjsZhzsThree zhjsZhzsThree = new ZhjsZhzsThree();
            zhjsZhzsThree.setCity(city);
            for(KeyValues keyValues : ccxuj) {
                if(keyValues.getName().indexOf(city)>-1) {
                    zhjsZhzsThree.setCcxuj(keyValues.getNumber());
                    break;
                }
            }
            for(KeyValues keyValues : ccxij) {
                if(keyValues.getName().indexOf(city)>-1) {
                    zhjsZhzsThree.setCcxij(keyValues.getNumber());
                    break;
                }
            }
            for(KeyValues keyValues : pjxuj) {
                if(keyValues.getName().indexOf(city)>-1) {
                    zhjsZhzsThree.setPjxuj(keyValues.getNumber());
                    break;
                }
            }
            for(KeyValues keyValues : pjxij) {
                if(keyValues.getName().indexOf(city)>-1) {
                    zhjsZhzsThree.setPjxij(keyValues.getNumber());
                    break;
                }
            }
            zhjsZhzsThrees.add(zhjsZhzsThree);
        }
        return zhjsZhzsThrees;
    }

    /**
     * 根据项目名称分页模糊查询数据
     */
    public IPage<ZhjsGcxm> getZhjsGcxmPageByProName(Page page, String proname) {
        return zhjsGcxmMapper.selectPage(page, Wrappers.<ZhjsGcxm>query().lambda().like(ZhjsGcxm::getProname, proname));
    }
}