package com.srs.web.controller.graduatetext;

import com.srs.common.core.controller.BaseController;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.comprehensive.domain.*;
import com.srs.comprehensive.service.GraduateTextService;
import com.srs.comprehensive.util.FileUploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
import com.srs.common.utils.file.FileUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.srs.common.utils.PageUtils.startPage;
import static com.srs.dormitory.utils.PageUtil.getDataTable;


@RestController
@RequestMapping("/comprehensive/rankingModel")
/**
 * 毕业生信息管理
 * 邵政文
 * 2025-07-01
 */
public class GraduateTextController extends BaseController {

    @Autowired
    private GraduateTextService graduateTextService;

    @Autowired
    private FileUploadUtil fileUploadUtil;

    private static final Logger log = LoggerFactory.getLogger(GraduateTextController.class);

    /**
     * 批量下载所对应的所有模板
     * 邵政文
     * 2025-07-01
     */
    @PostMapping("/downloadAllTemplates")
    public void downloadAllTemplates(HttpServletResponse response) throws IOException {
        // 创建 ZIP 文件
        String zipFileName = "allTemplates";
        List<Class<?>> entityClasses = Arrays.asList(JianDingtable.class, PingYutable.class);
        fileUploadUtil.downloadTemplates(response, entityClasses, zipFileName);
    }

    /**
     * 查询毕业生列表信息
     * @param graduateStudent
     * @return 结果
     * 邵政文
     * 2025-07-01
     */
    //@PreAuthorize("@ss.hasPermi('graduate:basedata:list')")
    @GetMapping("/graduatelist")
    public TableDataInfo getGraduateList(GraduateStudentNews graduateStudent) {
        if(graduateStudent.getClassId() != null) {
            String className = graduateTextService.selectGraduateClassData(graduateStudent.getClassId());
            graduateStudent.setStudentClass(className);
        }
        startPage();
        List<GraduateStudentNews> list = graduateTextService.getGraduateList(graduateStudent);
        return getDataTable(list);
    }

    /**
     * 添加毕业生信息
     * @param graduateStudent
     * @return 结果
     * 邵政文
     * 2025-07-03
     */
    //@PreAuthorize("@ss.hasPermi('graduate:basedata:add')")
    @PostMapping("/addGraduate")
    public AjaxResult addGraduate(@RequestBody List<GraduateStudentNews> graduateStudent) {
        String tNo = getUsername();
        for (GraduateStudentNews fruit : graduateStudent) {
            fruit.setEmployeeId(tNo);
        }
        int cout = graduateTextService.addGraduateList(graduateStudent);
        if(cout == 0) {
            return AjaxResult.error("添加失败");
        }
        return AjaxResult.success("添加成功");
    }

    /**
     * 根据id查询毕业生信息
     * @param id
     * @return 结果
     * 邵政文
     * 2025-07-03
     */
    //@PreAuthorize("@ss.hasPermi('graduate:basedata:dayin')")
    @GetMapping("/getStuInfo/{id}")
    public AjaxResult selectGraduateById(@PathVariable Long id) {
        SaveStudent saveStudent = graduateTextService.selectGraduateExclById(id);
        if(saveStudent == null) {
            return AjaxResult.error("查询失败");
        }
        return AjaxResult.success(saveStudent);
    }

    /**
     * 根据ids批量查询毕业生信息
     * @param ids
     * @return 结果
     * 邵政文
     * 2025-07-03
     */
    //@PreAuthorize("@ss.hasPermi('graduate:basedata:dayin')")
    @PostMapping("/print/{ids}")
    public TableDataInfo selectGraduateByIds(@PathVariable Long[] ids) {
        List<SaveStudent> saveStudents = graduateTextService.graduateByIdsList(ids);
        if(saveStudents == null) {
            return getDataTable(new ArrayList<>());
        }
        return getDataTable(saveStudents);
    }

}
