package com.srs.routine.service.impl;

import java.util.List;

import com.srs.common.exception.ServiceException;
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.RtEnlistmentReserveAttachMapper;
import com.srs.routine.domain.RtEnlistmentReserveAttach;
import com.srs.routine.service.IRtEnlistmentReserveAttachService;

/**
 * 保留学籍申请附件（入伍通知书等）Service业务层处理
 *
 * @author srs
 * @date 2025-10-31
 */
@Service
public class RtEnlistmentReserveAttachServiceImpl extends ServiceImpl<RtEnlistmentReserveAttachMapper,RtEnlistmentReserveAttach> implements IRtEnlistmentReserveAttachService {
    @Autowired
    private RtEnlistmentReserveAttachMapper rtEnlistmentReserveAttachMapper;

    /**
     * 查询保留学籍申请附件（入伍通知书等）
     *
     * @param id 保留学籍申请附件（入伍通知书等）主键
     * @return 保留学籍申请附件（入伍通知书等）
     */
    @Override
    public RtEnlistmentReserveAttach selectRtEnlistmentReserveAttachById(Long id) {
        return rtEnlistmentReserveAttachMapper.selectRtEnlistmentReserveAttachById(id);
    }

    /**
     * 查询保留学籍申请附件（入伍通知书等）列表
     *
     * @param rtEnlistmentReserveAttach 保留学籍申请附件（入伍通知书等）
     * @return 保留学籍申请附件（入伍通知书等）
     */
    @Override
    public List<RtEnlistmentReserveAttach> selectRtEnlistmentReserveAttachList(RtEnlistmentReserveAttach rtEnlistmentReserveAttach) {
        return rtEnlistmentReserveAttachMapper.selectRtEnlistmentReserveAttachList(rtEnlistmentReserveAttach);
    }

    /**
     * 新增保留学籍申请附件（入伍通知书等）
     *
     * @param rtEnlistmentReserveAttach 保留学籍申请附件（入伍通知书等）
     * @return 结果
     */
    @Override
    public int insertRtEnlistmentReserveAttach(RtEnlistmentReserveAttach rtEnlistmentReserveAttach) {
                rtEnlistmentReserveAttach.setCreateTime(DateUtils.getNowDate());
            return rtEnlistmentReserveAttachMapper.insertRtEnlistmentReserveAttach(rtEnlistmentReserveAttach);
    }


    // 批量插入实现
    @Override
    public int batchInsertRtEnlistmentReserveAttach(List<RtEnlistmentReserveAttach> attachList) {
        // 统一设置默认值（如创建时间）
        for (RtEnlistmentReserveAttach attach : attachList) {
            attach.setCreateTime(DateUtils.getNowDate()); // 批量设置创建时间
            // 其他默认值（如状态等）
        }
        // 调用Mapper层批量插入方法
        return rtEnlistmentReserveAttachMapper.batchInsertRtEnlistmentReserveAttach(attachList);
    }

    /**
     * 批量修改附件信息（根据ID）
     */
    @Override
    public int batchUpdateRtEnlistmentReserveAttach(List<RtEnlistmentReserveAttach> attachList) {
        // 1. 校验参数：列表非空且每个元素必须包含ID
        if (attachList == null || attachList.isEmpty()) {
            throw new ServiceException("批量修改失败：附件列表不能为空");
        }
        for (RtEnlistmentReserveAttach attach : attachList) {
            if (attach.getId() == null) {
                throw new ServiceException("批量修改失败：附件ID不能为空");
            }
        }

        // 2. 统一设置更新时间
        for (RtEnlistmentReserveAttach attach : attachList) {
            attach.setUpdateTime(DateUtils.getNowDate()); // 若实体类有updateTime字段
        }

        // 3. 调用Mapper批量修改
        return rtEnlistmentReserveAttachMapper.batchUpdateRtEnlistmentReserveAttach(attachList);
    }

    /**
     * 修改保留学籍申请附件（入伍通知书等）
     *
     * @param rtEnlistmentReserveAttach 保留学籍申请附件（入伍通知书等）
     * @return 结果
     */
    @Override
    public int updateRtEnlistmentReserveAttach(RtEnlistmentReserveAttach rtEnlistmentReserveAttach) {
        return rtEnlistmentReserveAttachMapper.updateRtEnlistmentReserveAttach(rtEnlistmentReserveAttach);
    }

    /**
     * 批量删除保留学籍申请附件（入伍通知书等）
     *
     * @param ids 需要删除的保留学籍申请附件（入伍通知书等）主键
     * @return 结果
     */
    @Override
    public int deleteRtEnlistmentReserveAttachByIds(Long[] ids) {
        return rtEnlistmentReserveAttachMapper.deleteRtEnlistmentReserveAttachByIds(ids);
    }

    /**
     * 删除保留学籍申请附件（入伍通知书等）信息
     *
     * @param id 保留学籍申请附件（入伍通知书等）主键
     * @return 结果
     */
    @Override
    public int deleteRtEnlistmentReserveAttachById(Long id) {
        return rtEnlistmentReserveAttachMapper.deleteRtEnlistmentReserveAttachById(id);
    }

    @Override
    public int deleteRtEnlistmentReserveAttachByFileNameAndStuName(String fileName, String studentName) {
        return rtEnlistmentReserveAttachMapper.deleteRtEnlistmentReserveAttachByFileNameAndStuName(fileName, studentName);
    }
}
