package com.yanzhu.jh.project.service.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;


import com.ruoyi.common.utils.DateUtils;
import com.yanzhu.jh.project.domain.SurProjectCostOutput;
import com.yanzhu.jh.project.mapper.SurProjectCostOutputMapper;
import com.yanzhu.jh.project.service.ISurProjectCostOutputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.SecurityUtils;
/**
 * 项目成本产值Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-27
 */
@Service
public class SurProjectCostOutputServiceImpl implements ISurProjectCostOutputService
{
    @Autowired
    private SurProjectCostOutputMapper surProjectCostOutputMapper;

    /**
     * 查询项目成本产值
     * 
     * @param id 项目成本产值主键
     * @return 项目成本产值
     */
    @Override
    public SurProjectCostOutput selectSurProjectCostOutputById(Long id)
    {
        return surProjectCostOutputMapper.selectSurProjectCostOutputById(id);
    }

    /**
     * 查询项目成本产值列表
     * 
     * @param surProjectCostOutput 项目成本产值
     * @return 项目成本产值
     */
    @Override
    public List<SurProjectCostOutput> selectSurProjectCostOutputList(SurProjectCostOutput surProjectCostOutput)
    {
        return surProjectCostOutputMapper.selectSurProjectCostOutputList(surProjectCostOutput);
    }

    /**
     * 新增项目成本产值
     * 
     * @param surProjectCostOutput 项目成本产值
     * @return 结果
     */
    @Override
    public int insertSurProjectCostOutput(SurProjectCostOutput surProjectCostOutput)
    {
        surProjectCostOutput.setCreateBy(SecurityUtils.getUsername());
        surProjectCostOutput.setCreateTime(DateUtils.getNowDate());
        return surProjectCostOutputMapper.insertSurProjectCostOutput(surProjectCostOutput);
    }

    /**
     * 修改项目成本产值
     * 
     * @param surProjectCostOutput 项目成本产值
     * @return 结果
     */
    @Override
    public int updateSurProjectCostOutput(SurProjectCostOutput surProjectCostOutput)
    {
        surProjectCostOutput.setUpdateBy(SecurityUtils.getUsername());
        surProjectCostOutput.setUpdateTime(DateUtils.getNowDate());
        return surProjectCostOutputMapper.updateSurProjectCostOutput(surProjectCostOutput);
    }

    /**
     * 批量删除项目成本产值
     * 
     * @param ids 需要删除的项目成本产值主键
     * @return 结果
     */
    @Override
    public int deleteSurProjectCostOutputByIds(Long[] ids)
    {
        return surProjectCostOutputMapper.deleteSurProjectCostOutputByIds(ids);
    }

    /**
     * 删除项目成本产值信息
     * 
     * @param id 项目成本产值主键
     * @return 结果
     */
    @Override
    public int deleteSurProjectCostOutputById(Long id)
    {
        return surProjectCostOutputMapper.deleteSurProjectCostOutputById(id);
    }

    @Override
    public void initProject(long projectId) {
        Calendar calendar=Calendar.getInstance();
        int year=calendar.get(Calendar.YEAR);
        SurProjectCostOutput it=new SurProjectCostOutput();
        it.setProjectId(projectId);
        it.setMoney(0l);
        it.setRemark("");
        it.setIsDel(0l);
        it.setCostType(1l);//总投资
        insertSurProjectCostOutput(it);
        it.setCostType(2l);//年度投资
        it.setYear(year*1l);
        insertSurProjectCostOutput(it);
        it.setYear(null);
        it.setCostType(3l);//合同金额
        insertSurProjectCostOutput(it);
        it.setCostType(4l);//合同支付金额
        insertSurProjectCostOutput(it);
        it.setCostType(5l);//合同挂账金额
        insertSurProjectCostOutput(it);
        it.setCostType(6l);//安措金额
        insertSurProjectCostOutput(it);
        it.setCostType(7l);//安措支付金额
        insertSurProjectCostOutput(it);
        it.setCostType(8l);//安措挂账金额
        insertSurProjectCostOutput(it);
        it.setCostType(9l);//月度投资
        it.setYear(year*1l);
        for(int i=1;i<=12;i++){
            it.setMonth(i*1l);
            insertSurProjectCostOutput(it);
        }

    }

    @Override
    public void addYearInvestment(SurProjectCostOutput it) {
        it.setMoney(0l);
        it.setRemark("");
        it.setIsDel(0l);
        it.setCostType(2l);//年度投资
        insertSurProjectCostOutput(it);
    }

    @Override
    public void addMonthInvestment(SurProjectCostOutput it) {
        it.setMoney(0l);
        it.setRemark("");
        it.setIsDel(0l);
        it.setCostType(9l);//月度投资
        for(int i=1;i<=12;i++){
            it.setMonth(i*1l);
            insertSurProjectCostOutput(it);
        }
    }

    @Override
    public List<SurProjectCostOutput> selectYearAndMonth(SurProjectCostOutput where) {
        return surProjectCostOutputMapper.selectYearAndMonth(where);
    }

    @Override
    public List<SurProjectCostOutput> sumByDeptId(SurProjectCostOutput where) {
        return surProjectCostOutputMapper.sumByDeptId(where);
    }
}

