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

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.project.BmConstructionPayInfo;
import com.ruoyi.system.domain.project.BmProjectConstruction;
import com.ruoyi.system.mapper.project.BmConstructionPayInfoMapper;
import com.ruoyi.system.service.project.IBmConstructionPayInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.ruoyi.system.service.impl.project.BmProjectConstructionServiceImpl.templateSetTime;


/**
 * 项目入统Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-08
 */
@Service
public class BmConstructionPayInfoServiceImpl implements IBmConstructionPayInfoService
{
    @Autowired
    private BmConstructionPayInfoMapper bmConstructionPayInfoMapper;

    /**
     * 查询项目入统
     * 
     * @param id 项目入统ID
     * @return 项目入统
     */
    @Override
    public BmConstructionPayInfo selectBmConstructionPayInfoById(Long id)
    {
        return bmConstructionPayInfoMapper.selectBmConstructionPayInfoById(id);
    }

    /**
     * 查询项目入统列表
     * 
     * @param bmConstructionPayInfo 项目入统
     * @return 项目入统
     */
    @Override
    public List<BmConstructionPayInfo> selectBmConstructionPayInfoList(BmConstructionPayInfo bmConstructionPayInfo)
    {
        return bmConstructionPayInfoMapper.selectBmConstructionPayInfoList(bmConstructionPayInfo);
    }

    /**
     * 新增项目入统
     * 
     * @param bmConstructionPayInfo 项目入统
     * @return 结果
     */
    @Override
    public AjaxResult insertBmConstructionPayInfo(BmConstructionPayInfo bmConstructionPayInfo)
    {
        bmConstructionPayInfo.setCreateTime(DateUtils.getNowDate());
        bmConstructionPayInfo.setCreateBy(SecurityUtils.getUsername());
        //提取出合同约定开工时间/竣工时间
        Long bmProjectId = bmConstructionPayInfo.getBmProjectId();
        if (bmProjectId == null) {
            return AjaxResult.error("缺少项目id");
        }
        templateSetTime(BmConstructionPayInfo.class,bmConstructionPayInfo);
        int i = bmConstructionPayInfoMapper.insertBmConstructionPayInfo(bmConstructionPayInfo);
        if (i != 1) {
            return AjaxResult.error("新增失败");
        }
        return AjaxResult.success();
    }

    /**
     * 修改项目入统
     * 
     * @param bmConstructionPayInfo 项目入统
     * @return 结果
     */
    @Override
    public AjaxResult updateBmConstructionPayInfo(BmConstructionPayInfo bmConstructionPayInfo)
    {
        bmConstructionPayInfo.setUpdateTime(DateUtils.getNowDate());
        bmConstructionPayInfo.setUpdateBy(SecurityUtils.getUsername());
        //提取出合同约定开工时间/竣工时间
        Long bmProjectId = bmConstructionPayInfo.getBmProjectId();
        if (bmProjectId == null) {
            return AjaxResult.error("缺少项目id");
        }
        templateSetTime(BmConstructionPayInfo.class,bmConstructionPayInfo);
        int i = bmConstructionPayInfoMapper.updateBmConstructionPayInfo(bmConstructionPayInfo);
        if (i != 1) {
            return AjaxResult.error("新增失败");
        }
        return AjaxResult.success();
    }

    /**
     * 批量删除项目入统
     * 
     * @param ids 需要删除的项目入统ID
     * @return 结果
     */
    @Override
    public int deleteBmConstructionPayInfoByIds(Long[] ids)
    {
        return bmConstructionPayInfoMapper.deleteBmConstructionPayInfoByIds(ids);
    }

    /**
     * 删除项目入统信息
     * 
     * @param id 项目入统ID
     * @return 结果
     */
    @Override
    public int deleteBmConstructionPayInfoById(Long id)
    {
        return bmConstructionPayInfoMapper.deleteBmConstructionPayInfoById(id);
    }
}
