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.CourseHandoutsVo;
import com.zhongzheng.modules.course.bo.CourseHandoutsQueryBo;
import com.zhongzheng.modules.course.bo.CourseHandoutsAddBo;
import com.zhongzheng.modules.course.bo.CourseHandoutsEditBo;
import com.zhongzheng.modules.course.service.ICourseHandoutsService;
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-11-02
 */
@Api(value = "讲义列控制器", tags = {"讲义列管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/handouts")
public class CourseHandoutsController extends BaseController {

    private final ICourseHandoutsService iCourseHandoutsService;

    /**
     * 查询讲义列列表
     */
    @ApiOperation("查询讲义列列表")
    @PreAuthorize("@ss.hasPermi('course:handouts:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseHandoutsVo> list(CourseHandoutsQueryBo bo) {
        startPage();
        List<CourseHandoutsVo> list = iCourseHandoutsService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出讲义列列表
     */
/*    @ApiOperation("导出讲义列列表")
    @PreAuthorize("@ss.hasPermi('course:handouts:export')")
    @Log(title = "讲义列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CourseHandoutsVo> export(CourseHandoutsQueryBo bo) {
        List<CourseHandoutsVo> list = iCourseHandoutsService.queryList(bo);
        ExcelUtil<CourseHandoutsVo> util = new ExcelUtil<CourseHandoutsVo>(CourseHandoutsVo.class);
        return util.exportExcel(list, "讲义列");
    }*/

    /**
     * 获取讲义列详细信息
     */
    @ApiOperation("获取讲义列详细信息")
    @PreAuthorize("@ss.hasPermi('course:handouts:query')")
    @GetMapping("/{handoutsId}")
    public AjaxResult<CourseHandoutsVo> getInfo(@PathVariable("handoutsId" ) Long handoutsId) {
        return AjaxResult.success(iCourseHandoutsService.queryById(handoutsId));
    }

    /**
     * 新增讲义列
     */
    @ApiOperation("新增讲义列")
    @PreAuthorize("@ss.hasPermi('course:handouts:add')")
    @Log(title = "讲义列", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CourseHandoutsAddBo bo) {
        return toAjax(iCourseHandoutsService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改讲义列
     */
    @ApiOperation("修改讲义列")
    @PreAuthorize("@ss.hasPermi('course:handouts:edit')")
    @Log(title = "讲义列", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult<Void> edit(@RequestBody CourseHandoutsEditBo bo) {
        return toAjax(iCourseHandoutsService.updateByEditBo(bo) ? 1 : 0);
    }

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