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.BmConstructionPay;
import com.ruoyi.system.domain.vo.BmDeptPlanVo;
import com.ruoyi.system.mapper.project.BmConstructionPayMapper;
import com.ruoyi.system.service.project.IBmConstructionPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 项目到资
(最少一条记录、合计、回写项目单)Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-08
 */
@Service
public class BmConstructionPayServiceImpl implements IBmConstructionPayService
{
    @Autowired
    private BmConstructionPayMapper bmConstructionPayMapper;

    /**
     * 查询项目到资
(最少一条记录、合计、回写项目单)
     * 
     * @param id 项目到资
(最少一条记录、合计、回写项目单)ID
     * @return 项目到资
(最少一条记录、合计、回写项目单)
     */
    @Override
    public BmConstructionPay selectBmConstructionPayById(Long id)
    {
        return bmConstructionPayMapper.selectBmConstructionPayById(id);
    }

    /**
     * 查询项目到资
(最少一条记录、合计、回写项目单)列表
     * 
     * @param bmConstructionPay 项目到资
(最少一条记录、合计、回写项目单)
     * @return 项目到资
(最少一条记录、合计、回写项目单)
     */
    @Override
    public List<BmConstructionPay> selectBmConstructionPayList(BmConstructionPay bmConstructionPay)
    {
        return bmConstructionPayMapper.selectBmConstructionPayList(bmConstructionPay);
    }

    /**
     * 新增项目到资
(最少一条记录、合计、回写项目单)
     * 
     * @param bmConstructionPay 项目到资
(最少一条记录、合计、回写项目单)
     * @return 结果
     */
    @Override
    public int insertBmConstructionPay(BmConstructionPay bmConstructionPay)
    {
        bmConstructionPay.setCreateTime(DateUtils.getNowDate());
        bmConstructionPay.setCreateBy(SecurityUtils.getUsername());
        return bmConstructionPayMapper.insertBmConstructionPay(bmConstructionPay);
    }

    /**
     * 修改项目到资
(最少一条记录、合计、回写项目单)
     * 
     * @param bmConstructionPay 项目到资
(最少一条记录、合计、回写项目单)
     * @return 结果
     */
    @Override
    public int updateBmConstructionPay(BmConstructionPay bmConstructionPay)
    {
        bmConstructionPay.setUpdateTime(DateUtils.getNowDate());
        bmConstructionPay.setUpdateBy(SecurityUtils.getUsername());
        return bmConstructionPayMapper.updateBmConstructionPay(bmConstructionPay);
    }

    /**
     * 批量删除项目到资
(最少一条记录、合计、回写项目单)
     * 
     * @param ids 需要删除的项目到资
(最少一条记录、合计、回写项目单)ID
     * @return 结果
     */
    @Override
    public int deleteBmConstructionPayByIds(Long[] ids)
    {
        return bmConstructionPayMapper.deleteBmConstructionPayByIds(ids);
    }

    /**
     * 删除项目到资
(最少一条记录、合计、回写项目单)信息
     * 
     * @param id 项目到资
(最少一条记录、合计、回写项目单)ID
     * @return 结果
     */
    @Override
    public int deleteBmConstructionPayById(Long id)
    {
        return bmConstructionPayMapper.deleteBmConstructionPayById(id);
    }


    /**
     * 首页柱状图
     * @param year
     * @return
     */
    @Override
    public Map<String, Object> selectIndexEharts(String year) {
        List<BmDeptPlanVo> bmDeptPlanVos = bmConstructionPayMapper.selectIndexEharts(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;
    }
}
