package com.srs.teacher.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.srs.common.utils.StringUtils;
import com.srs.teacher.domain.SysTeacherBasicmessage;
import com.srs.teacher.domain.SysTeacherTakeclass;
import com.srs.teacher.mapper.SysTeacherBasicmessageMapper;
import com.srs.teacher.service.ISysTeacherBasicmessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * basicMessageService业务层处理
 *
 * @author srs
 * @date 2024-06-07
 */
@Service
public class SysTeacherBasicmessageServiceImpl extends ServiceImpl<SysTeacherBasicmessageMapper,SysTeacherBasicmessage> implements ISysTeacherBasicmessageService {
    @Autowired
    private SysTeacherBasicmessageMapper sysTeacherBasicmessageMapper;

    /**
     * 查询basicMessage
     *
     * @param teacherId basicMessage主键
     * @return basicMessage
     */
    @Override
    public SysTeacherBasicmessage selectSysTeacherBasicmessageByTeacherId(Long teacherId) {
        return sysTeacherBasicmessageMapper.selectSysTeacherBasicmessageByTeacherId(teacherId);
    }

    /**
     * 查询basicMessage列表
     *
     * @param sysTeacherBasicmessage basicMessage
     * @return basicMessage
     */
    @Override
    public List<SysTeacherBasicmessage> selectSysTeacherBasicmessageList(SysTeacherBasicmessage sysTeacherBasicmessage) {
        return sysTeacherBasicmessageMapper.selectSysTeacherBasicmessageList(sysTeacherBasicmessage);
    }

    /**
     * 新增basicMessage
     *
     * @param sysTeacherBasicmessage basicMessage
     * @return 结果
     */
        @Transactional
    @Override
    public int insertSysTeacherBasicmessage(SysTeacherBasicmessage sysTeacherBasicmessage) {
            int rows = sysTeacherBasicmessageMapper.insertSysTeacherBasicmessage(sysTeacherBasicmessage);
            insertSysTeacherTakeclass(sysTeacherBasicmessage);
            return rows;
    }

    /**
     * 修改basicMessage
     *
     * @param sysTeacherBasicmessage basicMessage
     * @return 结果
     */
        @Transactional
    @Override
    public int updateSysTeacherBasicmessage(SysTeacherBasicmessage sysTeacherBasicmessage) {
                sysTeacherBasicmessageMapper.deleteSysTeacherTakeclassByTeacherId(sysTeacherBasicmessage.getTeacherId())
            ;
            insertSysTeacherTakeclass(sysTeacherBasicmessage);
        return sysTeacherBasicmessageMapper.updateSysTeacherBasicmessage(sysTeacherBasicmessage);
    }

    /**
     * 批量删除basicMessage
     *
     * @param teacherIds 需要删除的basicMessage主键
     * @return 结果
     */
        @Transactional
    @Override
    public int deleteSysTeacherBasicmessageByTeacherIds(Long[] teacherIds) {
                sysTeacherBasicmessageMapper.deleteSysTeacherTakeclassByTeacherIds(teacherIds);
        return sysTeacherBasicmessageMapper.deleteSysTeacherBasicmessageByTeacherIds(teacherIds);
    }

    /**
     * 删除basicMessage信息
     *
     * @param teacherId basicMessage主键
     * @return 结果
     */
        @Transactional
    @Override
    public int deleteSysTeacherBasicmessageByTeacherId(Long teacherId) {
                sysTeacherBasicmessageMapper.deleteSysTeacherTakeclassByTeacherId(teacherId);
        return sysTeacherBasicmessageMapper.deleteSysTeacherBasicmessageByTeacherId(teacherId);
    }

        /**
         * 新增takeClass信息
         *
         * @param sysTeacherBasicmessage basicMessage对象
         */
        public void insertSysTeacherTakeclass(SysTeacherBasicmessage sysTeacherBasicmessage) {
            List<SysTeacherTakeclass> sysTeacherTakeclassList = sysTeacherBasicmessage.getSysTeacherTakeclassList();
            Long teacherId = sysTeacherBasicmessage.getTeacherId();
            if (StringUtils.isNotNull(sysTeacherTakeclassList)) {
                List<SysTeacherTakeclass> list = new ArrayList<SysTeacherTakeclass>();
                for (SysTeacherTakeclass sysTeacherTakeclass :sysTeacherTakeclassList)
                {
                    sysTeacherTakeclass.setTeacherId(teacherId);
                    list.add(sysTeacherTakeclass);
                }
                if (list.size() > 0) {
                        sysTeacherBasicmessageMapper.batchSysTeacherTakeclass(list);
                }
            }
        }
}
