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.CourseSectionAddBo;
import com.zhongzheng.modules.course.bo.CourseSectionEditBo;
import com.zhongzheng.modules.course.bo.CourseSectionQueryBo;
import com.zhongzheng.modules.course.service.ICourseSectionService;
import com.zhongzheng.modules.course.vo.CourseSectionVo;
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/section")
public class CourseSectionController extends BaseController {

    private final ICourseSectionService iCourseSectionService;

    /**
     * 查询课程小节列表
     */
    @ApiOperation("查询课程小节列表")
    @PreAuthorize("@ss.hasPermi('course:section:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseSectionVo> list(CourseSectionQueryBo bo) {
        startPage();
        List<CourseSectionVo> list = iCourseSectionService.selectList(bo);
        return getDataTable(list);
    }

    /**
     * 导出课程小节列表
     */
   /* @ApiOperation("导出课程小节列表")
    @PreAuthorize("@ss.hasPermi('course:section:export')")
    @Log(title = "课程小节", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CourseSectionVo> export(CourseSectionQueryBo bo) {
        List<CourseSectionVo> list = iCourseSectionService.queryList(bo);
        ExcelUtil<CourseSectionVo> util = new ExcelUtil<CourseSectionVo>(CourseSectionVo.class);
        return util.exportExcel(list, "课程小节");
    }*/

    /**
     * 获取课程小节详细信息
     */
    @ApiOperation("获取课程小节详细信息")
    @PreAuthorize("@ss.hasPermi('course:section:query')")
    @GetMapping("/{sectionId}")
    public AjaxResult<CourseSectionVo> getInfo(@PathVariable("sectionId" ) Long sectionId) {
        return AjaxResult.success(iCourseSectionService.queryById(sectionId));
    }

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

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

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