package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.CphTerm;
import com.srs.comprehensive.service.ICphTermService;
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.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 学期Controller
 * 
 * @author srs
 * @date 2023-08-22
 */
@RestController
@RequestMapping("/comprehensive/term")
public class CphTermController extends BaseController
{
    @Autowired
    private ICphTermService cphTermService;

    /**
     * 查询学期列表
     */
    //RequiresPermissions("comprehensive:term:list")
    @GetMapping("/list")
    @ApiOperation("查询学期列表")
    public TableDataInfo list(CphTerm cphTerm)
    {
        startPage();
        List<CphTerm> list = cphTermService.selectCphTermList(cphTerm);
        return getDataTable(list);
    }

    /**
     * 导出学期列表
     */
    //@RequiresPermissions("comprehensive:term:export")
    @Log(title = "学期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出学期列表")
    public void export(HttpServletResponse response, CphTerm cphTerm)
    {
        List<CphTerm> list = cphTermService.selectCphTermList(cphTerm);
        ExcelUtil<CphTerm> util = new ExcelUtil<CphTerm>(CphTerm.class);
        util.exportExcel(response, list, "学期数据");
    }

    /**
     * 获取学期详细信息
     */
    //@RequiresPermissions("comprehensive:term:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取学期详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cphTermService.selectCphTermById(id));
    }

    /**
     * 新增学期
     */
    //@RequiresPermissions("comprehensive:term:add")
    @Log(title = "学期", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增学期")
    public AjaxResult add(@RequestBody CphTerm cphTerm)
    {
        return toAjax(cphTermService.insertCphTerm(cphTerm));
    }

    /**
     * 修改学期
     */
    //@RequiresPermissions("comprehensive:term:edit")
    @Log(title = "学期", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改学期")
    public AjaxResult edit(@RequestBody CphTerm cphTerm)
    {
        return toAjax(cphTermService.updateCphTerm(cphTerm));
    }

    /**
     * 删除学期
     */
    //@RequiresPermissions("comprehensive:term:remove")
    @Log(title = "学期", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除学期")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cphTermService.deleteCphTermByIds(ids));
    }

    /// 查询下拉框
    @GetMapping("/xlkterm_name")
    @ApiOperation("查询下拉框")
    public AjaxResult xlkterm_name()
    {
        return success(cphTermService.xlkterm_name());
    }
}
