package com.srs.web.controller.routine;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.routine.domain.RtEnlistmentReserveAttach;
import com.srs.routine.service.IRtEnlistmentReserveAttachService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * 保留学籍申请附件（入伍通知书等）Controller
 *
 * @author srs
 * @date 2025-10-31
 */
@RestController
@RequestMapping("/routine/enlistmentReserveAttach")
@Api(value = "保留学籍申请附件（入伍通知书等）管理", tags = "保留学籍申请附件（入伍通知书等）管理")
public class RtEnlistmentReserveAttachController extends BaseController {
    @Autowired
    private IRtEnlistmentReserveAttachService rtEnlistmentReserveAttachService;

    /**
     * 查询保留学籍申请附件（入伍通知书等）列表
     */
    @PreAuthorize("@ss.hasPermi('routine:enlistmentReserveAttach:list')")
    @GetMapping("/list")
    @ApiOperation("查询保留学籍申请附件（入伍通知书等）列表")
    public TableDataInfo list(RtEnlistmentReserveAttach rtEnlistmentReserveAttach) {
        startPage();
        List<RtEnlistmentReserveAttach> list = rtEnlistmentReserveAttachService.selectRtEnlistmentReserveAttachList(rtEnlistmentReserveAttach);
        return getDataTable(list);
    }

    /**
     * 导出保留学籍申请附件（入伍通知书等）列表
     */
    @PreAuthorize("@ss.hasPermi('routine:enlistmentReserveAttach:export')")
    @Log(title = "保留学籍申请附件（入伍通知书等）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出保留学籍申请附件（入伍通知书等）列表")
    public void export(HttpServletResponse response, RtEnlistmentReserveAttach rtEnlistmentReserveAttach) {
        List<RtEnlistmentReserveAttach> list = rtEnlistmentReserveAttachService.selectRtEnlistmentReserveAttachList(rtEnlistmentReserveAttach);
        ExcelUtil<RtEnlistmentReserveAttach> util = new ExcelUtil<RtEnlistmentReserveAttach>(RtEnlistmentReserveAttach.class);
        util.exportExcel(response, list, "保留学籍申请附件（入伍通知书等）数据");
    }

    /**
     * 获取保留学籍申请附件（入伍通知书等）详细信息
     */
    @PreAuthorize("@ss.hasPermi('routine:enlistmentReserveAttach:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取保留学籍申请附件（入伍通知书等）详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rtEnlistmentReserveAttachService.selectRtEnlistmentReserveAttachById(id));
    }

    /**
     * 新增保留学籍申请附件（入伍通知书等）
     */
    @PreAuthorize("@ss.hasPermi('routine:enlistmentReserveAttach:add')")
    @Log(title = "保留学籍申请附件（入伍通知书等）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增保留学籍申请附件（入伍通知书等）")
    public AjaxResult add(@RequestBody RtEnlistmentReserveAttach rtEnlistmentReserveAttach) {
        return toAjax(rtEnlistmentReserveAttachService.insertRtEnlistmentReserveAttach(rtEnlistmentReserveAttach));
    }

    /**
     * 批量新增保留学籍申请附件（入伍通知书等）
     */
    @PreAuthorize("@ss.hasPermi('routine:enlistmentReserveAttach:add')")
    @Log(title = "保留学籍申请附件（入伍通知书等）", businessType = BusinessType.INSERT)
    @PostMapping("/batchAdd") // 注意：修改接口路径避免与原单条接口冲突
    @ApiOperation("批量新增保留学籍申请附件（入伍通知书等）")
    public AjaxResult batchAdd(@RequestBody List<RtEnlistmentReserveAttach> attachList) {
        // 1. 校验参数合法性
        if (attachList == null || attachList.isEmpty()) {
            return AjaxResult.error("批量插入失败：附件列表不能为空");
        }

        // 2. 调用Service层批量插入方法
        int rows = rtEnlistmentReserveAttachService.batchInsertRtEnlistmentReserveAttach(attachList);

        // 3. 返回结果（rows为成功插入的条数）
        return rows > 0 ? AjaxResult.success("批量插入成功，共插入 " + rows + " 条记录")
                : AjaxResult.error("批量插入失败");
    }

    /**
     * 批量修改保留学籍申请附件
     */
    @PreAuthorize("@ss.hasPermi('routine:enlistmentReserveAttach:edit')")
    @Log(title = "保留学籍申请附件", businessType = BusinessType.UPDATE)
    @PostMapping("/batchUpdate")
    @ApiOperation("批量修改保留学籍申请附件")
    public AjaxResult batchUpdate(@RequestBody List<RtEnlistmentReserveAttach> attachList) {

        int rows = rtEnlistmentReserveAttachService.batchUpdateRtEnlistmentReserveAttach(attachList);
        return rows > 0 ? AjaxResult.success("批量修改成功，共更新 " + rows + " 条记录")
                : AjaxResult.error("批量修改失败，未找到匹配的记录");

    }

    /**
     * 删除保留学籍申请附件（入伍通知书等）
     */
    @PreAuthorize("@ss.hasPermi('routine:enlistmentReserveAttach:remove')")
    @Log(title = "保留学籍申请附件（入伍通知书等）", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除保留学籍申请附件（入伍通知书等）")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rtEnlistmentReserveAttachService.deleteRtEnlistmentReserveAttachByIds(ids));
    }

    /**
     * 删除保留学籍申请附件（入伍通知书等）
     */
    @PreAuthorize("@ss.hasPermi('routine:enlistmentReserveAttach:remove')")
    @Log(title = "保留学籍申请附件（入伍通知书等）", businessType = BusinessType.DELETE)
    @PostMapping("/deleteRtEnlistmentReserve")
    @ApiOperation("删除保留学籍申请附件（入伍通知书等）")
    public AjaxResult deleteRtEnlistmentReserveAttachByFileNameAndStuName(String fileName, String studentName) {
        return toAjax(rtEnlistmentReserveAttachService.deleteRtEnlistmentReserveAttachByFileNameAndStuName(fileName, studentName));
    }
}
