package com.ruoyi.hezhi.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.hezhi.domain.TbConferenceNotice;
import com.ruoyi.hezhi.mapper.TbConferenceNoticeMapper;
import com.ruoyi.hezhi.mapper.TbConferencePeopleMapper;
import com.ruoyi.hezhi.service.ITbConferenceNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 数字教育大会通知Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@Service
public class TbConferenceNoticeServiceImpl implements ITbConferenceNoticeService
{
    @Autowired
    private TbConferenceNoticeMapper tbConferenceNoticeMapper;
    @Autowired
    private TbConferencePeopleMapper tbConferencePeopleMapper;

    /**
     * 查询数字教育大会通知
     *
     * @param conferenceNoticeId 数字教育大会通知主键
     * @return 数字教育大会通知
     */
    @Override
    public TbConferenceNotice selectTbConferenceNoticeByConferenceNoticeId(Long conferenceNoticeId)
    {
        return tbConferenceNoticeMapper.selectTbConferenceNoticeByConferenceNoticeId(conferenceNoticeId);
    }

    /**
     * 查询数字教育大会通知列表
     *
     * @param tbConferenceNotice 数字教育大会通知
     * @return 数字教育大会通知
     */
    @Override
    public List<TbConferenceNotice> selectTbConferenceNoticeList(TbConferenceNotice tbConferenceNotice)
    {
        return tbConferenceNoticeMapper.selectTbConferenceNoticeList(tbConferenceNotice);
    }

    /**
     * 新增数字教育大会通知
     *
     * @param tbConferenceNotice 数字教育大会通知
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertTbConferenceNotice(TbConferenceNotice tbConferenceNotice)
    {
        //先校验是否有时间重合的
        List<TbConferenceNotice> conferenceNotice = tbConferenceNoticeMapper.selectTbConferenceNoticeBy(tbConferenceNotice.getConferenceStartTime(), tbConferenceNotice.getConferenceEndTime());
        if (!conferenceNotice.isEmpty()) {
            throw new ServiceException("新增失败，存在重合的会议时间");
        }
        tbConferenceNotice.setCreateTime(DateUtils.getNowDate());
        return tbConferenceNoticeMapper.insertTbConferenceNotice(tbConferenceNotice);
    }

    /**
     * 修改数字教育大会通知
     *
     * @param tbConferenceNotice 数字教育大会通知
     * @return 结果
     */
    @Override
    public int updateTbConferenceNotice(TbConferenceNotice tbConferenceNotice)
    {
        tbConferenceNotice.setUpdateTime(DateUtils.getNowDate());
        return tbConferenceNoticeMapper.updateTbConferenceNotice(tbConferenceNotice);
    }

    /**
     * 批量删除数字教育大会通知
     *
     * @param conferenceNoticeIds 需要删除的数字教育大会通知主键
     * @return 结果
     */
    @Override
    public int deleteTbConferenceNoticeByConferenceNoticeIds(Long[] conferenceNoticeIds)
    {
        int flag = tbConferenceNoticeMapper.deleteTbConferenceNoticeByConferenceNoticeIds(conferenceNoticeIds);
        if (flag > 0) {
            tbConferencePeopleMapper.deleteTbConferencePeopleByConferenceNoticeIds(conferenceNoticeIds);
        }
        return flag;
    }

    /**
     * 删除数字教育大会通知信息
     *
     * @param conferenceNoticeId 数字教育大会通知主键
     * @return 结果
     */
    @Override
    public int deleteTbConferenceNoticeByConferenceNoticeId(Long conferenceNoticeId)
    {
        return tbConferenceNoticeMapper.deleteTbConferenceNoticeByConferenceNoticeId(conferenceNoticeId);
    }

    /**
     * 数字教育大会通知列表
     *
     * @param params 参数
     * @return 数字教育大会通知列表
     */
    @Override
    public List<Map<String, Object>> getCourseTeacherList(Map<String, Object> params) {
        return tbConferenceNoticeMapper.getCourseTeacherList(params);
    }

    /**
     * 数字教育大会通知详情
     *
     * @param params 参数
     * @return 数字教育大会通知详情
     */
    @Override
    public Map<String, Object> getConferenceNoticeInfo(Map<String, Object> params) {
        return tbConferenceNoticeMapper.getConferenceNoticeInfo(params);
    }

    /**
     * 查询最新数字教育大会会议通知（会议开始时间未开始）
     *
     * @return 数字教育大会通知
     */
    @Override
    public TbConferenceNotice selectTbConferenceNoticeByNew() {
        return tbConferenceNoticeMapper.selectTbConferenceNoticeByNew();
    }

    /**
     * 查询开始报名的数字教育大会会议通知
     *
     * @return 数字教育大会通知
     */
    @Override
    public TbConferenceNotice selectTbConferenceNoticeByEnroll() {
        return tbConferenceNoticeMapper.selectTbConferenceNoticeByEnroll();
    }
}
