package com.rwk.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.rwk.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.rwk.system.domain.RwkMeetingStaff;
import com.rwk.system.mapper.RwkMeetingMapper;
import com.rwk.system.domain.RwkMeeting;
import com.rwk.system.service.IRwkMeetingService;
import com.rwk.common.core.text.Convert;

/**
 * 教育培训Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-05
 */
@Service
public class RwkMeetingServiceImpl implements IRwkMeetingService 
{
    @Autowired
    private RwkMeetingMapper rwkMeetingMapper;

    /**
     * 查询教育培训
     * 
     * @param id 教育培训主键
     * @return 教育培训
     */
    @Override
    public RwkMeeting selectRwkMeetingById(Long id)
    {
        return rwkMeetingMapper.selectRwkMeetingById(id);
    }

    /**
     * 查询教育培训列表
     * 
     * @param rwkMeeting 教育培训
     * @return 教育培训
     */
    @Override
    public List<RwkMeeting> selectRwkMeetingList(RwkMeeting rwkMeeting)
    {
        return rwkMeetingMapper.selectRwkMeetingList(rwkMeeting);
    }

    /**
     * 新增教育培训
     * 
     * @param rwkMeeting 教育培训
     * @return 结果
     */
    @Transactional
    @Override
    public int insertRwkMeeting(RwkMeeting rwkMeeting)
    {
        int rows = rwkMeetingMapper.insertRwkMeeting(rwkMeeting);
        insertRwkMeetingStaff(rwkMeeting);
        return rows;
    }

    /**
     * 修改教育培训
     * 
     * @param rwkMeeting 教育培训
     * @return 结果
     */
    @Transactional
    @Override
    public int updateRwkMeeting(RwkMeeting rwkMeeting)
    {
        rwkMeetingMapper.deleteRwkMeetingStaffByMeetingId(rwkMeeting.getId());
        insertRwkMeetingStaff(rwkMeeting);
        return rwkMeetingMapper.updateRwkMeeting(rwkMeeting);
    }

    /**
     * 批量删除教育培训
     * 
     * @param ids 需要删除的教育培训主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRwkMeetingByIds(String ids)
    {
        rwkMeetingMapper.deleteRwkMeetingStaffByMeetingIds(Convert.toStrArray(ids));
        return rwkMeetingMapper.deleteRwkMeetingByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除教育培训信息
     * 
     * @param id 教育培训主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRwkMeetingById(Long id)
    {
        rwkMeetingMapper.deleteRwkMeetingStaffByMeetingId(id);
        return rwkMeetingMapper.deleteRwkMeetingById(id);
    }

    /**
     * 新增培训人员签到信息
     * 
     * @param rwkMeeting 教育培训对象
     */
    public void insertRwkMeetingStaff(RwkMeeting rwkMeeting)
    {
        List<RwkMeetingStaff> rwkMeetingStaffList = rwkMeeting.getRwkMeetingStaffList();
        Long id = rwkMeeting.getId();
        if (StringUtils.isNotNull(rwkMeetingStaffList)) {
            List<RwkMeetingStaff> list = new ArrayList<>();
            for (RwkMeetingStaff rwkMeetingStaff : rwkMeetingStaffList) {
                rwkMeetingStaff.setMeetingId(id);
                list.add(rwkMeetingStaff);
            }
            if (!list.isEmpty()) {
                rwkMeetingMapper.batchRwkMeetingStaff(list);
            }
        }
    }
}
