package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.model.MsgsAttachment;
import com.hc.business.mapper.MsgsAttachmentMapper;
import com.hc.business.service.MsgsAttachmentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (MsgsAttachment)表服务实现类
 *
 * @author makejava
 * @since 2024-02-29 18:06:59
 */

@Service
public class MsgsAttachmentServiceImpl implements MsgsAttachmentService {

    private final MsgsAttachmentMapper msgsAttachmentMapper;

    public MsgsAttachmentServiceImpl(MsgsAttachmentMapper msgsAttachmentMapper) {
        this.msgsAttachmentMapper = msgsAttachmentMapper;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param attachmentId 主键
     * @return 实例对象
     */
    @Override
    public MsgsAttachment queryById(Integer attachmentId) {
        return this.msgsAttachmentMapper.selectByPrimaryKey(attachmentId);
    }

    /**
     * 新增数据
     *
     * @param msgsAttachment 实例对象
     * @return 实例对象
     */
    @Override
    public MsgsAttachment insert(MsgsAttachment msgsAttachment) {
        this.msgsAttachmentMapper.insert(msgsAttachment);
        return msgsAttachment;
    }

    /**
     * 修改数据
     *
     * @param msgsAttachment 实例对象
     * @return 实例对象
     */
    @Override
    public MsgsAttachment update(MsgsAttachment msgsAttachment) {
        this.msgsAttachmentMapper.updateByPrimaryKeySelective(msgsAttachment);
        return this.queryById(msgsAttachment.getAttachmentId());
    }

    /**
     * 通过主键删除数据
     *
     * @param attachmentId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer attachmentId) {
        return this.msgsAttachmentMapper.deleteByPrimaryKey(attachmentId) > 0;
    }

    /**
     * 分页查询多条数据
     *
     * @param page 页码
     * @param size 查询条数
     * @return 对象列表
     */
    @Override
    public PageInfo queryAllByLimit(int page, int size) {
        return PageHelper.startPage(page, size).doSelectPageInfo(this.msgsAttachmentMapper::selectAll);
    }


    /**
     * 通过直播查询她关联的培训班
     * */
    @Override
    public List<MsgsAttachment> queryByMsgId(Integer msgId) {
        List<MsgsAttachment> list = this.msgsAttachmentMapper.queryByMsgId(msgId);
        return list;
    }
}
