package com.ruoyi.bst.agreement.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bst.agreement.mapper.AgreementMapper;
import com.ruoyi.bst.agreement.domain.Agreement;
import com.ruoyi.bst.agreement.domain.AgreementVO;
import com.ruoyi.bst.agreement.domain.AgreementQuery;
import com.ruoyi.bst.agreement.service.AgreementService;
import org.springframework.util.CollectionUtils;

/**
 * 协议列表Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Service
public class AgreementServiceImpl implements AgreementService
{
    @Autowired
    private AgreementMapper agreementMapper;

    /**
     * 查询协议列表
     *
     * @param id 协议列表主键
     * @return 协议列表
     */
    @Override
    public AgreementVO selectAgreementById(Long id)
    {
        return agreementMapper.selectAgreementById(id);
    }

    /**
     * 查询协议列表列表
     *
     * @param agreement 协议列表
     * @return 协议列表
     */
    @Override
    public List<AgreementVO> selectAgreementList(AgreementQuery agreement)
    {
        return agreementMapper.selectAgreementList(agreement);
    }

    /**
     * 新增协议列表
     *
     * @param agreement 协议列表
     * @return 结果
     */
    @Override
    public int insertAgreement(Agreement agreement)
    {
        agreement.setCreateTime(DateUtils.getNowDate());
        return agreementMapper.insertAgreement(agreement);
    }

    /**
     * 修改协议列表
     *
     * @param agreement 协议列表
     * @return 结果
     */
    @Override
    public int updateAgreement(Agreement agreement)
    {
        agreement.setUpdateTime(DateUtils.getNowDate());
        return agreementMapper.updateAgreement(agreement);
    }

    /**
     * 批量删除协议列表
     *
     * @param ids 需要删除的协议列表主键
     * @return 结果
     */
    @Override
    public int deleteAgreementByIds(Long[] ids)
    {
        return agreementMapper.deleteAgreementByIds(ids);
    }

    /**
     * 删除协议列表信息
     *
     * @param id 协议列表主键
     * @return 结果
     */
    @Override
    public int deleteAgreementById(Long id)
    {
        return agreementMapper.deleteAgreementById(id);
    }

    @Override
    public AgreementVO selectOne(AgreementQuery query) {
        PageHelper.startPage(1, 1);
        List<AgreementVO> list = agreementMapper.selectAgreementList(query);
        return CollectionUtils.firstElement(list);
    }
}
