package com.srs.web.controller.comprehensive;

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.comprehensive.domain.CphIdeologyScore;
import com.srs.comprehensive.service.ICphIdeologyScoreService;
import com.srs.comprehensive.domain.Vo.stuYearStudentUser;
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 2024-07-01
 */
@RestController
@RequestMapping("/comprehensive/ideologyscore")
@Api(value = "思想品德初始分数管理", tags = "思想品德初始分数管理")
public class CphIdeologyScoreController extends BaseController {
    @Autowired
    private ICphIdeologyScoreService cphIdeologyScoreService;

    @PreAuthorize("@ss.hasPermi('comprehensive:ideologyscore:list')")
    @PostMapping("/doInit")
    @ApiOperation("初始化当前学年分数")
    public AjaxResult doInit(){
        return cphIdeologyScoreService.doInit();
    }



    /**
     * 查询思想品德初始分数列表
     */
@PreAuthorize("@ss.hasPermi('comprehensive:ideologyscore:list')")
@GetMapping("/list")
@ApiOperation("查询思想品德初始分数列表")
    public TableDataInfo list(CphIdeologyScore cphIdeologyScore, stuYearStudentUser stuYearStudentUser)
    {
        if (stuYearStudentUser != null) {
            cphIdeologyScore.setClassId(stuYearStudentUser.getClassId());
            cphIdeologyScore.setDeptId(stuYearStudentUser.getDeptId());
            cphIdeologyScore.setMajorId(stuYearStudentUser.getMajorId());
            cphIdeologyScore.setStuYearId(stuYearStudentUser.getStuYearId());
            cphIdeologyScore.setStuNo(stuYearStudentUser.getStuNo());
            cphIdeologyScore.setName(stuYearStudentUser.getName());
        }
        startPage();
        List<CphIdeologyScore> list = cphIdeologyScoreService.selectCphIdeologyScoreList(cphIdeologyScore);
        return getDataTable(list);
    }

    /**
     * 导出思想品德初始分数列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ideologyscore:export')")
    @Log(title = "思想品德初始分数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出思想品德初始分数列表")
    public void export(HttpServletResponse response, CphIdeologyScore cphIdeologyScore, stuYearStudentUser stuYearStudentUser)
    {
        if (stuYearStudentUser != null) {
            cphIdeologyScore.setClassId(stuYearStudentUser.getClassId());
            cphIdeologyScore.setDeptId(stuYearStudentUser.getDeptId());
            cphIdeologyScore.setMajorId(stuYearStudentUser.getMajorId());
            cphIdeologyScore.setStuYearId(stuYearStudentUser.getStuYearId());
            cphIdeologyScore.setStuNo(stuYearStudentUser.getStuNo());
            cphIdeologyScore.setName(stuYearStudentUser.getName());
        }
        List<CphIdeologyScore> list = cphIdeologyScoreService.selectCphIdeologyScoreList(cphIdeologyScore);
        ExcelUtil<CphIdeologyScore> util = new ExcelUtil<CphIdeologyScore>(CphIdeologyScore.class);
        util.exportExcel(response, list, "思想品德初始分数数据");
    }

    /**
     * 获取思想品德初始分数详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ideologyscore:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取思想品德初始分数详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cphIdeologyScoreService.selectCphIdeologyScoreById(id));
    }

    /**
     * 新增思想品德初始分数
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ideologyscore:add')")
    @Log(title = "思想品德初始分数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增思想品德初始分数")
    public AjaxResult add(@RequestBody CphIdeologyScore cphIdeologyScore)
    {
        return toAjax(cphIdeologyScoreService.insertCphIdeologyScore(cphIdeologyScore));
    }

    /**
     * 修改思想品德初始分数
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ideologyscore:edit')")
    @Log(title = "思想品德初始分数", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改思想品德初始分数")
    public AjaxResult edit(@RequestBody CphIdeologyScore cphIdeologyScore)
    {
        return toAjax(cphIdeologyScoreService.updateCphIdeologyScore(cphIdeologyScore));
    }

    /**
     * 删除思想品德初始分数
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:ideologyscore:remove')")
    @Log(title = "思想品德初始分数", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除思想品德初始分数")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cphIdeologyScoreService.deleteCphIdeologyScoreByIds(ids));
    }
}
