package com.srs.web.controller.comprehensive;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.srs.common.core.domain.entity.SysUser;
import com.srs.comprehensive.domain.CphProRank;
import com.srs.comprehensive.domain.Dto.CphProRankingDto;
import com.srs.comprehensive.domain.Vo.CphProRankingVo;
import com.srs.comprehensive.domain.Vo.stuYearStudentUser;
import com.srs.dormitory.domain.Dto.DormitoryModelDto;
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.comprehensive.domain.CphProRanking;
import com.srs.comprehensive.service.ICphProRankingService;
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;
import org.springframework.web.multipart.MultipartFile;

/**
 * 平均学分绩总排名Controller
 *
 * @author srs
 * @date 2024-02-19
 */
@RestController
@RequestMapping("/comprehensive/ranking")
@Api(value = "平均学分绩总排名管理", tags = "平均学分绩总排名管理")
public class CphProRankingController extends BaseController {
    @Autowired
    private ICphProRankingService cphProRankingService;

    @PostMapping("/doImport")
    public AjaxResult doImport(@RequestBody List<CphProRanking> param) {
        return cphProRankingService.doImport(param);
    }


    /**
     * 查询平均学分绩总排名列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ranking:list')")
    @GetMapping("/list")
    @ApiOperation("查询平均学分绩总排名列表")
    public TableDataInfo list(CphProRank cphProRanking, stuYearStudentUser stuYearStudentUser) {
        if(stuYearStudentUser != null) {
            cphProRanking.setDeptId(stuYearStudentUser.getDeptId());
            cphProRanking.setMajorId(stuYearStudentUser.getMajorId());
        }
        startPage();
        List<CphProRank> rank = cphProRankingService.getRankList(cphProRanking);
        return getDataTable(rank);
    }

    /**
     * 导入科学文化素质
     */
    @Log(title = "导入科学文化素质", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('comprehensive:ranking:import')")
    @PostMapping("/importData")
    public AjaxResult importData(@RequestBody List<CphProRankingDto> rankListDto) {
        Long operName = getUserId();
        String message = cphProRankingService.importUser(rankListDto, operName);
        return success(message);
    }

    /**
     * 导出科学文化素质模板
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ranking:exportmodel')")
    @Log(title = "导出科学文化素质模板", businessType = BusinessType.EXPORT)
    @PostMapping("/exportmodel")
    @ApiOperation("导出平均学分绩总排名列表")
    public void exportmodel(HttpServletResponse response, CphProRankingDto cphProRankingDto) {
        List<CphProRankingDto> list = new ArrayList<>();
        CphProRankingDto rankingDto = new CphProRankingDto();
        rankingDto.setStuNo("202400000001");
        rankingDto.setXsxm("张三");
        rankingDto.setClassName("模板1班");
        rankingDto.setCourseCredit(BigDecimal.valueOf(100));
        rankingDto.setTotalCredit(BigDecimal.valueOf(99));
        rankingDto.setTotalScore(BigDecimal.valueOf(8800));
        rankingDto.setCourseNum(50L);
        rankingDto.setAvgScore(BigDecimal.valueOf(99));
        rankingDto.setAvgCredit(BigDecimal.valueOf(99));
        rankingDto.setRanking(1L);
        rankingDto.setNopass(1L);
        list.add(rankingDto);
        ExcelUtil<CphProRankingDto> util = new ExcelUtil<CphProRankingDto>(CphProRankingDto.class);
        util.exportExcel(response, list, "平均学分绩总排名数据");
    }

    /**
     * 导出平均学分绩总排名列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ranking:export')")
    @Log(title = "平均学分绩总排名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出平均学分绩总排名列表")
    public void export(HttpServletResponse response, CphProRank cphProRanking, stuYearStudentUser stuYearStudentUser) {
        if (stuYearStudentUser != null) {
            cphProRanking.setStuYearId(stuYearStudentUser.getStuYearId());
            if (stuYearStudentUser.getClassId() != null){
                cphProRanking.setClassId(stuYearStudentUser.getClassId());
            }
            if (stuYearStudentUser.getStuNo() != null){
                cphProRanking.setStuNo(stuYearStudentUser.getStuNo());
            }
            if (stuYearStudentUser.getName() != null){
                cphProRanking.setXsxm(stuYearStudentUser.getName());
            }
            // 添加学院和专业的查询条件
            cphProRanking.setDeptId(stuYearStudentUser.getDeptId());
            cphProRanking.setMajorId(stuYearStudentUser.getMajorId());
        }
        List<CphProRank> list = cphProRankingService.getRankList(cphProRanking);
        ExcelUtil<CphProRank> util = new ExcelUtil<CphProRank>(CphProRank.class);
        util.exportExcel(response, list, "平均学分绩总排名数据");
    }

    /**
     * 获取平均学分绩总排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ranking:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取平均学分绩总排名详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cphProRankingService.selectCphProRankingById(id));
    }

    /**
     * 新增平均学分绩总排名
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ranking:add')")
    @Log(title = "平均学分绩总排名", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增平均学分绩总排名")
    public AjaxResult add(@RequestBody CphProRanking cphProRanking) {
        return toAjax(cphProRankingService.insertCphProRanking(cphProRanking));
    }

    /**
     * 修改平均学分绩总排名
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ranking:edit')")
    @Log(title = "平均学分绩总排名", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改平均学分绩总排名")
    public AjaxResult edit(@RequestBody CphProRanking cphProRanking) {
        return toAjax(cphProRankingService.updateCphProRanking(cphProRanking));
    }

    /**
     * 删除平均学分绩总排名
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ranking:remove')")
    @Log(title = "平均学分绩总排名", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除平均学分绩总排名")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cphProRankingService.deleteCphProRankingByIds(ids));
    }




}
