package com.ruoyi.system.service.impl.project;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.project.BmDeptPlan;
import com.ruoyi.system.domain.vo.BmDeptPlanVo;
import com.ruoyi.system.mapper.project.BmDeptPlanMapper;
import com.ruoyi.system.service.project.IBmDeptPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 *  部门招商计划Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-09
 */
@Service
public class BmDeptPlanServiceImpl implements IBmDeptPlanService
{
    @Autowired
    private BmDeptPlanMapper bmDeptPlanMapper;

    /**
     * 查询 部门招商计划
     * 
     * @param id  部门招商计划ID
     * @return  部门招商计划
     */
    @Override
    public BmDeptPlan selectBmDeptPlanById(Long id)
    {
        return bmDeptPlanMapper.selectBmDeptPlanById(id);
    }

    /**
     * 查询 部门招商计划列表
     * 
     * @param bmDeptPlan  部门招商计划
     * @return  部门招商计划
     */
    @Override
    public List<BmDeptPlan> selectBmDeptPlanList(BmDeptPlan bmDeptPlan)
    {
        return bmDeptPlanMapper.selectBmDeptPlanList(bmDeptPlan);
    }

    /**
     * 新增 部门招商计划
     * 
     * @param bmDeptPlan  部门招商计划
     * @return 结果
     */
    @Override
    public int insertBmDeptPlan(BmDeptPlan bmDeptPlan)
    {
        bmDeptPlan.setCreateTime(DateUtils.getNowDate());
        bmDeptPlan.setCreateBy(SecurityUtils.getUsername());
        return bmDeptPlanMapper.insertBmDeptPlan(bmDeptPlan);
    }

    /**
     * 修改 部门招商计划
     * 
     * @param bmDeptPlan  部门招商计划
     * @return 结果
     */
    @Override
    public int updateBmDeptPlan(BmDeptPlan bmDeptPlan)
    {
        bmDeptPlan.setUpdateTime(DateUtils.getNowDate());
        bmDeptPlan.setUpdateBy(SecurityUtils.getUsername());
        return bmDeptPlanMapper.updateBmDeptPlan(bmDeptPlan);
    }

    /**
     * 批量删除 部门招商计划
     * 
     * @param ids 需要删除的 部门招商计划ID
     * @return 结果
     */
    @Override
    public int deleteBmDeptPlanByIds(Long[] ids)
    {
        return bmDeptPlanMapper.deleteBmDeptPlanByIds(ids);
    }

    /**
     * 删除 部门招商计划信息
     * 
     * @param id  部门招商计划ID
     * @return 结果
     */
    @Override
    public int deleteBmDeptPlanById(Long id)
    {
        return bmDeptPlanMapper.deleteBmDeptPlanById(id);
    }

    /**
     * 首页-市直榜单
     * @return
     */
    @Override
    public List<BmDeptPlan> selectUnitList(String year) {
        List<BmDeptPlan> bmDeptPlanList = bmDeptPlanMapper.selectUnitList(year);
        return bmDeptPlanList;
    }



    /**
     * 统计分析-再谈线索-两区及乡镇
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectUnitClueList(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectUnitClueList(year);
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-在谈线索-市直
     * @param year
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectUnitClueCityList(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectUnitClueCityList(year);
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-签约项目-两区及乡镇榜单
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectTargetSigningList(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectTargetSigningList(year);
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-签约项目-市直榜单
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectTotAmtList(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectTotAmtList(year);
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-在建项目-柱状图
     * @param year
     * @return
     */
    @Override
    public Map<String, Object> selectProjectUnitAmountEharts(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectProjectUnitAmountEharts(year);
        Map<String, Object> map  = new HashMap<>(2);
        List<String> deptName = new ArrayList<>();
        List<BigDecimal> payForMoney = new ArrayList<>();
        if (bmDeptPlanVos.size() > 0){
            for (BmDeptPlanVo bmDeptPlanVo : bmDeptPlanVos) {
                deptName.add(bmDeptPlanVo.getDeptName());
                payForMoney.add(bmDeptPlanVo.getPayForMoney());
            }
        }
        map.put("x",deptName);
        map.put("y",payForMoney);
        return map;
    }

    /**
     * 统计分析-在建项目-市直榜单
     * @param year
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectProjectUnitAmountUnit(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectProjectUnitAmountUnit(year);
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-在建项目-两区及乡镇
     * @param year
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectProjectAreaAmountUnit(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectProjectAreaAmountUnit(year);
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-投产项目-两区及乡镇入归榜单
     * @return
     */

    @Override
    public List<BmDeptPlanVo> selectInvestmentList(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectInvestmentList(year);
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-投产项目-市直榜单
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectInvestmentCityList(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectInvestmentCityList(year);
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-投产项目-柱状图
     * @param year
     * @return
     */
    @Override
    public Map<String, Object> selectProjectInvestmentEharts(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectProjectInvestmentEharts(year);
        Map<String, Object> map  = new HashMap<>(2);
        List<String> deptName = new ArrayList<>();
        List<Integer> successMission = new ArrayList<>();
        if (bmDeptPlanVos.size() > 0){
            for (BmDeptPlanVo bmDeptPlanVo : bmDeptPlanVos) {
                deptName.add(bmDeptPlanVo.getDeptName());
                successMission.add(bmDeptPlanVo.getSuccessMission());
            }
        }
        map.put("x",deptName);
        map.put("y",successMission);
        return map;
    }
}
