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.CourseSubjectVo;
import com.zhongzheng.modules.course.bo.CourseSubjectQueryBo;
import com.zhongzheng.modules.course.bo.CourseSubjectAddBo;
import com.zhongzheng.modules.course.bo.CourseSubjectEditBo;
import com.zhongzheng.modules.course.service.ICourseSubjectService;
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/subject")
public class CourseSubjectController extends BaseController {

    private final ICourseSubjectService iCourseSubjectService;

    /**
     * 查询科目列表
     */
    @ApiOperation("查询科目列表")
    @PreAuthorize("@ss.hasPermi('course:subject:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseSubjectVo> list(CourseSubjectQueryBo bo) {
        startPage();
        List<CourseSubjectVo> list = iCourseSubjectService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出科目列表
     */
/*    @ApiOperation("导出科目列表")
    @PreAuthorize("@ss.hasPermi('course:subject:export')")
    @Log(title = "科目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CourseSubjectVo> export(CourseSubjectQueryBo bo) {
        List<CourseSubjectVo> list = iCourseSubjectService.queryList(bo);
        ExcelUtil<CourseSubjectVo> util = new ExcelUtil<CourseSubjectVo>(CourseSubjectVo.class);
        return util.exportExcel(list, "科目");
    }*/

    /**
     * 获取科目详细信息
     */
    @ApiOperation("获取科目详细信息")
    @PreAuthorize("@ss.hasPermi('course:subject:query')")
    @GetMapping("/{id}")
    public AjaxResult<CourseSubjectVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCourseSubjectService.queryById(id));
    }

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

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

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

    /**
     * 查询科目列表
     */
    @ApiOperation("查询科目下拉框")
    @PreAuthorize("@ss.hasPermi('course:subject:list')")
    @GetMapping("/listAll")
    public TableDataInfo<CourseSubjectVo> listAll(CourseSubjectQueryBo bo) {
        startPage();
        List<CourseSubjectVo> list = iCourseSubjectService.queryListAll(bo);
        return getDataTable(list);
    }
}
