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<BmDeptPlanVo> selectUnitList() {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectUnitList();
        return bmDeptPlanVos;
    }

    /**
     * 首页-单位榜单资金
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectUnitAmountList() {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectUnitAmountList();
        return bmDeptPlanVos;
    }

    /**
     * 统计分析-合同金额
     * @return
     */
    @Override
    public List<BmDeptPlanVo> selectTotAmtList() {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectTotAmtList();
        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;
    }

    /**
     * 统计分析-入归榜单
     * @return
     */

    @Override
    public List<BmDeptPlanVo> selectInvestmentList() {
        List<BmDeptPlanVo> bmDeptPlanVos = bmDeptPlanMapper.selectInvestmentList();
        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;
    }
}
