package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.SrsStuYear;
import com.srs.comprehensive.service.ISrsStuYearService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;

/**
 * 【学年表】Controller
 * 
 * @author srs
 * @date 2023-06-28
 */
@Api("年级表")
@RestController
@RequestMapping("/system/year")
public class SrsStuYearController extends BaseController
{
    @Autowired
    private ISrsStuYearService srsStuYearService;


    @GetMapping("/listAllYear")
    public AjaxResult listAllYear(){
        return srsStuYearService.listAllYear();
    }


    @GetMapping("/listEnableYear")
    public TableDataInfo listEnableYear(){
        startPage();
        List<SrsStuYear> list = srsStuYearService.listEnableYear();
        return getDataTable(list);
    }

    /**
     * 所有激活学年
     */
    @GetMapping("/listAllEnableYear")
    public AjaxResult listAllEnableYear(){

        List<SrsStuYear> list = srsStuYearService.listEnableYear();
        return AjaxResult.success(list);
    }
    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:year:list')")
    @ApiOperation("查询年级表")
    @GetMapping("/list")
    public TableDataInfo list(SrsStuYear srsStuYear)
    {
        startPage();
        List<SrsStuYear> list = srsStuYearService.selectSrsStuYearList(srsStuYear);
        return getDataTable(list);
    }

    /**
     * 所有数据
     * @param
     * @return
     */
//    @PreAuthorize("@ss.hasPermi('system:year:list')")
    @GetMapping("/lists")
    public AjaxResult lists()
    {
        List<SrsStuYear> list = srsStuYearService.selectSrsStuYearLists();
        return success(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:year:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsStuYear srsStuYear)
    {
        List<SrsStuYear> list = srsStuYearService.selectSrsStuYearList(srsStuYear);
        ExcelUtil<SrsStuYear> util = new ExcelUtil<SrsStuYear>(SrsStuYear.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:year:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srsStuYearService.selectSrsStuYearById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:year:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsStuYear srsStuYear)
    {
        return toAjax(srsStuYearService.insertSrsStuYear(srsStuYear));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:year:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsStuYear srsStuYear)
    {
        return toAjax(srsStuYearService.updateSrsStuYear(srsStuYear));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:year:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srsStuYearService.deleteSrsStuYearByIds(ids));
    }

    /**
     *中间表导入数据
     * @return 结果
     */
    @PutMapping("/addStuYear")
    public AjaxResult addStuYear()
    {
        return success("解析成功").put("导入失败的数据",srsStuYearService.addStuYear());
    }

}
