package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BomanAnnexMapper;
import com.ruoyi.system.domain.BomanAnnex;
import com.ruoyi.system.service.IBomanAnnexService;

/**
 * 附件Service业务层处理
 * 
 * @author boman
 * @date 2023-11-13
 */
@Service
public class BomanAnnexServiceImpl implements IBomanAnnexService 
{
    @Autowired
    private BomanAnnexMapper bomanAnnexMapper;

    /**
     * 查询附件
     * 
     * @param annexId 附件主键
     * @return 附件
     */
    @Override
    public BomanAnnex selectBomanAnnexByAnnexId(Long annexId)
    {
        return bomanAnnexMapper.selectBomanAnnexByAnnexId(annexId);
    }

    /**
     * 查询附件列表
     * 
     * @param bomanAnnex 附件
     * @return 附件
     */
    @Override
    public List<BomanAnnex> selectBomanAnnexList(BomanAnnex bomanAnnex)
    {
        return bomanAnnexMapper.selectBomanAnnexList(bomanAnnex);
    }

    /**
     * 新增附件
     * 
     * @param bomanAnnex 附件
     * @return 结果
     */
    @Override
    public int insertBomanAnnex(BomanAnnex bomanAnnex)
    {
        List<BomanAnnex> bomanAnnexList = bomanAnnex.getBomanAnnexList();
        int i = 0;
        if (bomanAnnexList != null && bomanAnnexList.size() > 0){
            for (BomanAnnex annex : bomanAnnexList) {
                annex.setReleaseTime(bomanAnnex.getReleaseTime());
                annex.setKeywords(bomanAnnex.getKeywords());
            }
             i = bomanAnnexMapper.batchBomanAnnex(bomanAnnexList);
        }
        return i;
    }

    /**
     * 修改附件
     * 
     * @param bomanAnnex 附件
     * @return 结果
     */
    @Override
    public int updateBomanAnnex(BomanAnnex bomanAnnex)
    {
        List<BomanAnnex> bomanAnnexList = bomanAnnex.getBomanAnnexList();
        if (bomanAnnexList != null && bomanAnnexList.size()>0){
            BomanAnnex bomanAnnexUp = bomanAnnex.getBomanAnnexList().get(0);
            bomanAnnexUp.setAnnexId(bomanAnnex.getAnnexId());
            bomanAnnexUp.setKeywords(bomanAnnex.getKeywords());
            bomanAnnexUp.setReleaseTime(bomanAnnex.getReleaseTime());
            bomanAnnexUp.setUpdateTime(DateUtils.getNowDate());
            return bomanAnnexMapper.updateBomanAnnex(bomanAnnexUp);
        }
        return bomanAnnexMapper.updateBomanAnnex(bomanAnnex);
    }

    /**
     * 批量删除附件
     * 
     * @param annexIds 需要删除的附件主键
     * @return 结果
     */
    @Override
    public int deleteBomanAnnexByAnnexIds(Long[] annexIds)
    {
        return bomanAnnexMapper.deleteBomanAnnexByAnnexIds(annexIds);
    }

    /**
     * 删除附件信息
     * 
     * @param annexId 附件主键
     * @return 结果
     */
    @Override
    public int deleteBomanAnnexByAnnexId(Long annexId)
    {
        return bomanAnnexMapper.deleteBomanAnnexByAnnexId(annexId);
    }
}
