package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.CphClasstwo;
import com.srs.comprehensive.domain.SrsCeScore;
import com.srs.comprehensive.domain.SrsStudent;
import com.srs.comprehensive.domain.Vo.SrsCeScoreStudent;
import com.srs.comprehensive.domain.Vo.SrsCeScoreStudentStuYear;
import com.srs.comprehensive.domain.Vo.stuYearStudentUser;
import com.srs.comprehensive.service.ISrsCeScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

import static com.srs.common.utils.PageUtils.startPage;

/**
 * 综合评价Controller
 * 
 * @author srs
 * @date 2023-06-28
 */
@Api("综合评价")
@RestController
@RequestMapping("/system/ceScore")
public class SrsCeScoreController extends BaseController
{
    @Autowired
    private ISrsCeScoreService srsCeScoreService;

    /**
     * 查询综合评价列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SrsCeScore srsCeScore)
    {
        startPage();
        List<SrsCeScore> list = srsCeScoreService.selectSrsCeScoreList(srsCeScore);
        return getDataTable(list);
    }

    /**
     * 导出综合评价列表
     */
    @Log(title = "综合评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsCeScore srsCeScore, stuYearStudentUser stuYearStudentUser)
    {
        if (stuYearStudentUser != null) {
            srsCeScore.setStuYearId(stuYearStudentUser.getStuYearId());
            SrsStudent srsStudent = new SrsStudent();
            if (stuYearStudentUser.getClassId() != null){
                srsStudent.setClassId(stuYearStudentUser.getClassId());
            }
            if (stuYearStudentUser.getStuNo() != null){
                srsStudent.setStuNo(stuYearStudentUser.getStuNo());
            }
            if (stuYearStudentUser.getName() != null){
                srsStudent.setName("%" + stuYearStudentUser.getName() + "%");
            }
            srsCeScore.setStudent(srsStudent);
            // 添加学院和专业的查询条件
            srsCeScore.setDeptId(stuYearStudentUser.getDeptId());
            srsCeScore.setMajorId(stuYearStudentUser.getMajorId());
        }
        List<SrsCeScore> list = srsCeScoreService.selectSrsCeScoreList(srsCeScore);
        ExcelUtil<SrsCeScore> util = new ExcelUtil<SrsCeScore>(SrsCeScore.class);
        util.exportExcel(response, list, "综合评价数据");
    }

    /**
     * 获取综合评价详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srsCeScoreService.selectSrsCeScoreById(id));
    }

    /**
     * 新增综合评价
     */
    @Log(title = "综合评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsCeScore srsCeScore)
    {
        return toAjax(srsCeScoreService.insertSrsCeScore(srsCeScore));
    }

    /**
     * 修改综合评价
     */
    @Log(title = "综合评价", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsCeScore srsCeScore)
    {
        return toAjax(srsCeScoreService.updateSrsCeScore(srsCeScore));
    }

    /**
     * 删除综合评价
     */
    @Log(title = "综合评价", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srsCeScoreService.deleteSrsCeScoreByIds(ids));
    }


    /**
     * 综合评价连表查询
     */
    @ApiOperation("综合评价连表查询")
    @PostMapping("/SrsCeScoreStudentStuYear")
    public TableDataInfo SrsCeScoreStudentStuYear(stuYearStudentUser cphIamStudentUser){

        SrsCeScore srsCeScore = new SrsCeScore();
        srsCeScore.setStuYearId(cphIamStudentUser.getStuYearId());
        SrsStudent srsStudent = new SrsStudent();
        if (cphIamStudentUser.getClassId() != null){
            srsStudent.setClassId(cphIamStudentUser.getClassId());
        }
        if (cphIamStudentUser.getStuNo()!= null){
            srsStudent.setStuNo(cphIamStudentUser.getStuNo());
        }
        if (cphIamStudentUser.getName()!= null){
            cphIamStudentUser.setName("%"+cphIamStudentUser.getName()+"%");
            srsStudent.setName(cphIamStudentUser.getName());
        }
        srsCeScore.setStudent(srsStudent);
        // 添加学院和专业的查询条件
        srsCeScore.setDeptId(cphIamStudentUser.getDeptId());
        srsCeScore.setMajorId(cphIamStudentUser.getMajorId());
        startPage();
        List<SrsCeScoreStudentStuYear> srsCeScoreStudentStuYears = srsCeScoreService.SrsCeScoreStudentStuYear(srsCeScore);
        return getDataTable(srsCeScoreStudentStuYears);
    }

    /**
     * 综合评价成绩导入
     */
    @ApiOperation("综合评价成绩导入")
    @PostMapping("/selectSrsCeScoreStudent")
    public AjaxResult selectSrsCeScoreStudent(@RequestBody List<SrsCeScoreStudent> srsCeScores){

        return toAjax(srsCeScoreService.insertSrsCeScoreStudent(srsCeScores));
    }


}
