package com.zhongzheng.controller.course;

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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zhongzheng.modules.course.bo.CourseChapterAddBo;
import com.zhongzheng.modules.course.bo.CourseChapterEditBo;
import com.zhongzheng.modules.course.bo.CourseChapterQueryBo;
import com.zhongzheng.modules.course.service.ICourseChapterService;
import com.zhongzheng.modules.course.vo.CourseChapterVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 课程大章Controller
 *
 * @author hjl
 * @date 2021-05-19
 */
@Api(value = "课程大章控制器", tags = {"课程大章管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/chapter")
public class CourseChapterController extends BaseController {

    private final ICourseChapterService iCourseChapterService;

    /**
     * 查询课程大章列表
     */
    @ApiOperation("查询课程大章列表")
    @PreAuthorize("@ss.hasPermi('course:chapter:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseChapterVo> list(CourseChapterQueryBo bo) {
        startPage();
        List<CourseChapterVo> list = iCourseChapterService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出课程大章列表
     */
    /*@ApiOperation("导出课程大章列表")
    @PreAuthorize("@ss.hasPermi('course:chapter:export')")
    @Log(title = "课程大章", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CourseChapterVo> export(CourseChapterQueryBo bo) {
        List<CourseChapterVo> list = iCourseChapterService.queryList(bo);
        ExcelUtil<CourseChapterVo> util = new ExcelUtil<CourseChapterVo>(CourseChapterVo.class);
        return util.exportExcel(list, "课程大章");
    }*/

    /**
     * 获取课程大章详细信息
     */
    @ApiOperation("获取课程大章详细信息")
    @PreAuthorize("@ss.hasPermi('course:chapter:query')")
    @GetMapping("/{chapterId}")
    public AjaxResult<CourseChapterVo> getInfo(@PathVariable("chapterId" ) Long chapterId) {
        return AjaxResult.success(iCourseChapterService.queryById(chapterId));
    }

    /**
     * 新增课程大章
     */
    @ApiOperation("新增课程大章")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('course:chapter:add')")
    @Log(title = "课程大章", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody CourseChapterAddBo bo) {
        return toAjax(iCourseChapterService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改课程大章
     */
    @ApiOperation("修改课程大章")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('course:chapter:edit')")
    @Log(title = "课程大章", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@Validated  @RequestBody CourseChapterEditBo bo) {
        return toAjax(iCourseChapterService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除课程大章
     */
    /*@ApiOperation("删除课程大章")
    @PreAuthorize("@ss.hasPermi('course:chapter:remove')")
    @Log(title = "课程大章" , businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult<Void> remove(@RequestBody Long[] chapterIds) {
        return toAjax(iCourseChapterService.deleteWithValidByIds(Arrays.asList(chapterIds), true) ? 1 : 0);
    }*/
}
