package com.srs.web.controller.dormitory;

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.dormitory.domain.DmsSemester;
import com.srs.dormitory.service.IDmsSemesterService;
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 2023-11-09
 */
@RestController
@RequestMapping("/dormitory/semester")
@Api(value = "学期管理", tags = "学期管理")
public class DmsSemesterController extends BaseController {
    @Autowired
    private IDmsSemesterService dmsSemesterService;

    /**
     * 查询学期列表
     */
//@PreAuthorize("@ss.hasPermi('system:semester:list')")
@GetMapping("/list")
@ApiOperation("查询学期列表")
    public TableDataInfo list(DmsSemester dmsSemester)
    {
        startPage();
        List<DmsSemester> list = dmsSemesterService.selectDmsSemesterList(dmsSemester);
        return getDataTable(list);
    }

    /**
     * 导出学期列表
     */
//    @PreAuthorize("@ss.hasPermi('system:semester:export')")
    @Log(title = "学期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出学期列表")
    public void export(HttpServletResponse response, DmsSemester dmsSemester)
    {
        List<DmsSemester> list = dmsSemesterService.selectDmsSemesterList(dmsSemester);
        ExcelUtil<DmsSemester> util = new ExcelUtil<DmsSemester>(DmsSemester.class);
        util.exportExcel(response, list, "学期数据");
    }

    /**
     * 获取学期详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:semester:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取学期详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsSemesterService.selectDmsSemesterById(id));
    }

    /**
     * 新增学期
     */
//    @PreAuthorize("@ss.hasPermi('system:semester:add')")
    @Log(title = "学期", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增学期")
    public AjaxResult add(@RequestBody DmsSemester dmsSemester)
    {
        return dmsSemesterService.add(dmsSemester);
    }

    /**
     * 修改学期
     */
//    @PreAuthorize("@ss.hasPermi('system:semester:edit')")
    @Log(title = "学期", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改学期")
    public AjaxResult edit(@RequestBody DmsSemester dmsSemester)
    {
        return toAjax(dmsSemesterService.updateDmsSemester(dmsSemester));
    }

    /**
     * 删除学期
     */
//    @PreAuthorize("@ss.hasPermi('system:semester:remove')")
    @Log(title = "学期", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除学期")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsSemesterService.deleteDmsSemesterByIds(ids));
    }

    /**
     * 结束当前学期
     */
    @GetMapping("/over")
    @ApiOperation("结束当前学期")
    public AjaxResult over(){
        return dmsSemesterService.over();
    }
}
