package com.srs.routine.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.srs.routine.mapper.RtClassMettingHeldMapper;
import com.srs.routine.domain.RtClassMettingHeld;
import com.srs.routine.service.IRtClassMettingHeldService;

/**
 * 辅导员班会Service业务层处理
 *
 * @author LSD
 * @date 2025-03-02
 */
@Service
public class RtClassMettingHeldServiceImpl extends ServiceImpl<RtClassMettingHeldMapper,RtClassMettingHeld> implements IRtClassMettingHeldService {
    @Autowired
    private RtClassMettingHeldMapper rtClassMettingHeldMapper;

    @Override
    public AjaxResult fdyAdd(RtClassMettingHeld param){
        try{

            List<String> classIds = param.getClassIds();
            List<RtClassMettingHeld> addList = new ArrayList<>();
            for(String classId : classIds){
                RtClassMettingHeld add = new RtClassMettingHeld();
                add.setMettingFile(param.getMettingFile());
                add.setMettingTheme(param.getMettingTheme());
                add.setCmhClassNo(classId);
                add.setCmhTeacherNo(param.getCmhTeacherNo());
                add.setCmhContent(param.getCmhContent());
                add.setCmhTime(param.getCmhTime());
                add.setCmhAddr(param.getCmhAddr());
                add.setStatus("1");
                addList.add(add);
            }
            boolean res = this.saveBatch(addList);
            if(!res){
                return AjaxResult.error("添加失败");
            }

            return AjaxResult.success();
        }catch(Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 查询辅导员班会
     *
     * @param cmhId 辅导员班会主键
     * @return 辅导员班会
     */
    @Override
    public RtClassMettingHeld selectRtClassMettingHeldByCmhId(Long cmhId) {
        return rtClassMettingHeldMapper.selectRtClassMettingHeldByCmhId(cmhId);
    }

    @Override
    public List<RtClassMettingHeld> listView(RtClassMettingHeld rtClassMettingHeld){
        return rtClassMettingHeldMapper.listView(rtClassMettingHeld);
    }

    /**
     * 查询辅导员班会列表
     *
     * @param rtClassMettingHeld 辅导员班会
     * @return 辅导员班会
     */
    @Override
    public List<RtClassMettingHeld> selectRtClassMettingHeldList(RtClassMettingHeld rtClassMettingHeld) {
        return rtClassMettingHeldMapper.selectRtClassMettingHeldList(rtClassMettingHeld);
    }

    /**
     * 新增辅导员班会
     *
     * @param rtClassMettingHeld 辅导员班会
     * @return 结果
     */
    @Override
    public int insertRtClassMettingHeld(RtClassMettingHeld rtClassMettingHeld) {
        rtClassMettingHeld.setCreateTime(DateUtils.getNowDate());
        return rtClassMettingHeldMapper.insertRtClassMettingHeld(rtClassMettingHeld);
    }

    /**
     * 修改辅导员班会
     *
     * @param rtClassMettingHeld 辅导员班会
     * @return 结果
     */
    @Override
    public int updateRtClassMettingHeld(RtClassMettingHeld rtClassMettingHeld) {
        rtClassMettingHeld.setUpdateTime(DateUtils.getNowDate());
        return rtClassMettingHeldMapper.updateRtClassMettingHeld(rtClassMettingHeld);
    }

    /**
     * 批量删除辅导员班会
     *
     * @param cmhIds 需要删除的辅导员班会主键
     * @return 结果
     */
    @Override
    public int deleteRtClassMettingHeldByCmhIds(Long[] cmhIds) {
        return rtClassMettingHeldMapper.deleteRtClassMettingHeldByCmhIds(cmhIds);
    }

    /**
     * 删除辅导员班会信息
     *
     * @param cmhId 辅导员班会主键
     * @return 结果
     */
    @Override
    public int deleteRtClassMettingHeldByCmhId(Long cmhId) {
        return rtClassMettingHeldMapper.deleteRtClassMettingHeldByCmhId(cmhId);
    }
}
