package com.srs.web.controller.comprehensive;

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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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 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.comprehensive.domain.SrsGrade;
import com.srs.comprehensive.service.ISrsGradeService;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 年级
Controller
 * 
 * @author srs
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/cph/grade")
public class SrsGradeController extends BaseController
{
    @Autowired
    private ISrsGradeService srsGradeService;


    @ApiOperation("列出在校生年级")
    @GetMapping("/listEnableGrade")
    public AjaxResult listEnableGrade(){
        List<SrsGrade> list = srsGradeService.list(
                new QueryWrapper<SrsGrade>()
                        .in("grade_status", "1","3")
                        .orderByDesc("grade_code")
        );
        return AjaxResult.success(list);
    }


    @ApiOperation("列出新生年级")
    @GetMapping("/listNowGrade")
    public AjaxResult listNowGrade(){
        return srsGradeService.listNowGrade();
    }

    @ApiOperation("列出所有年级")
    @GetMapping("/listAllGrade")
    public AjaxResult listAllGrade(){
        List<SrsGrade> list = srsGradeService.selectSrsGradeList(null);
        return AjaxResult.success(list);
    }



    /**
     * 分页查询年级列表
     */
//    @PreAuthorize("@ss.hasPermi('cph:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrsGrade srsGrade)
    {
        startPage();
        List<SrsGrade> list = srsGradeService.selectSrsGradeList(srsGrade);
        return getDataTable(list);
    }

    /**
     * 查询所有年级列表
     * @param srsGrade
     * @return
     */
    @GetMapping("/name")
    public AjaxResult name(SrsGrade srsGrade)
    {
        List<SrsGrade> list = srsGradeService.selectSrsGradeList(srsGrade);
        return AjaxResult.success(list);
    }


    /**
     * 导出年级列表
     */
//    @PreAuthorize("@ss.hasPermi('cph:grade:export')")
    @Log(title = "年级 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsGrade srsGrade)
    {
        List<SrsGrade> list = srsGradeService.selectSrsGradeList(srsGrade);
        ExcelUtil<SrsGrade> util = new ExcelUtil<SrsGrade>(SrsGrade.class);
        util.exportExcel(response, list, "年级数据");
    }

    /**
     * 获取年级详细信息
     */
//    @PreAuthorize("@ss.hasPermi('cph:grade:query')")
    @GetMapping(value = "/{gradeId}")
    public AjaxResult getInfo(@PathVariable("gradeId") Long gradeId)
    {
        return success(srsGradeService.selectSrsGradeByGradeId(gradeId));
    }

    /**
     * 新增年级

     */
//    @PreAuthorize("@ss.hasPermi('cph:grade:add')")
    @Log(title = "年级 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsGrade srsGrade)
    {
        return toAjax(srsGradeService.insertSrsGrade(srsGrade));
    }

    /**
     * 修改年级

     */
//    @PreAuthorize("@ss.hasPermi('cph:grade:edit')")
    @Log(title = "年级 ", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsGrade srsGrade)
    {
        return toAjax(srsGradeService.updateSrsGrade(srsGrade));
    }

    /**
     * 删除年级

     */
//    @PreAuthorize("@ss.hasPermi('cph:grade:remove')")
    @Log(title = "年级 ", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{gradeIds}")
    public AjaxResult remove(@PathVariable Long[] gradeIds)
    {
        return toAjax(srsGradeService.deleteSrsGradeByGradeIds(gradeIds));
    }
}
