package com.zhongzheng.controller.course;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
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.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.modules.course.vo.MajorExamineVo;
import com.zhongzheng.modules.course.bo.MajorExamineQueryBo;
import com.zhongzheng.modules.course.bo.MajorExamineAddBo;
import com.zhongzheng.modules.course.bo.MajorExamineEditBo;
import com.zhongzheng.modules.course.service.IMajorExamineService;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 考期Controller
 * 
 * @author ruoyi
 * @date 2021-10-09
 */
@Api(value = "考期控制器", tags = {"考期管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/examine")
public class MajorExamineController extends BaseController {

    private final IMajorExamineService iMajorExamineService;

    /**
     * 查询考期列表
     */
    @ApiOperation("查询考期列表")
    @PreAuthorize("@ss.hasPermi('course:examine:list')")
    @GetMapping("/list")
    public TableDataInfo<MajorExamineVo> list(MajorExamineQueryBo bo) {
        startPage();
        List<MajorExamineVo> list = iMajorExamineService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出考期列表
     */
/*    @ApiOperation("导出考期列表")
    @PreAuthorize("@ss.hasPermi('course:examine:export')")
    @Log(title = "考期", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MajorExamineVo> export(MajorExamineQueryBo bo) {
        List<MajorExamineVo> list = iMajorExamineService.queryList(bo);
        ExcelUtil<MajorExamineVo> util = new ExcelUtil<MajorExamineVo>(MajorExamineVo.class);
        return util.exportExcel(list, "考期");
    }*/

    /**
     * 获取考期详细信息
     */
    @ApiOperation("获取考期详细信息")
    @PreAuthorize("@ss.hasPermi('course:examine:query')")
    @GetMapping("/{id}")
    public AjaxResult<MajorExamineVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMajorExamineService.queryById(id));
    }

    /**
     * 新增考期
     */
    @ApiOperation("新增考期")
    @PreAuthorize("@ss.hasPermi('course:examine:add')")
    @Log(title = "考期", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody MajorExamineAddBo bo) {
        return toAjax(iMajorExamineService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改考期
     */
    @ApiOperation("修改考期")
    @PreAuthorize("@ss.hasPermi('course:examine:edit')")
    @Log(title = "考期", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody MajorExamineEditBo bo) {
        return toAjax(iMajorExamineService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除考期
     */
 /*   @ApiOperation("删除考期")
    @PreAuthorize("@ss.hasPermi('course:examine:remove')")
    @Log(title = "考期" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iMajorExamineService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }*/
}
