package com.zhongzheng.controller.course;

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

import com.zhongzheng.modules.course.bo.CourseModuleAddBo;
import com.zhongzheng.modules.course.bo.CourseModuleEditBo;
import com.zhongzheng.modules.course.bo.CourseModuleQueryBo;
import com.zhongzheng.modules.course.domain.CourseChapterBusiness;
import com.zhongzheng.modules.course.domain.CourseModuleBusiness;
import com.zhongzheng.modules.course.service.ICourseModuleBusinessService;
import com.zhongzheng.modules.course.service.ICourseModuleService;
import com.zhongzheng.modules.course.vo.CourseModuleVo;
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.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-10-09
 */
@Api(value = "课程模块控制器", tags = {"课程模块管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/module")
public class CourseModuleController extends BaseController {

    private final ICourseModuleService iCourseModuleService;

    private final ICourseModuleBusinessService iCourseModuleBusinessService;

    /**
     * 查询课程模块列表
     */
    @ApiOperation("查询课程模块列表")
    @PreAuthorize("@ss.hasPermi('system:module:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseModuleVo> list(CourseModuleQueryBo bo) {
        startPage();
        List<CourseModuleVo> list = iCourseModuleService.selectList(bo);
        return getDataTable(list);
    }

    /**
     * 导出课程模块列表
     */
   /* @ApiOperation("导出课程模块列表")
    @PreAuthorize("@ss.hasPermi('system:module:export')")
    @Log(title = "课程模块", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CourseModuleVo> export(CourseModuleQueryBo bo) {
        List<CourseModuleVo> list = iCourseModuleService.queryList(bo);
        ExcelUtil<CourseModuleVo> util = new ExcelUtil<CourseModuleVo>(CourseModuleVo.class);
        return util.exportExcel(list, "课程模块");
    }*/

    /**
     * 获取课程模块详细信息
     */
    @ApiOperation("获取课程模块详细信息")
    @PreAuthorize("@ss.hasPermi('system:module:query')")
    @GetMapping("/{moduleId}")
    public AjaxResult<CourseModuleVo> getInfo(@PathVariable("moduleId" ) Long moduleId) {
        return AjaxResult.success(iCourseModuleService.queryById(moduleId));
    }

    /**
     * 新增课程模块
     */
    @ApiOperation("新增课程模块")
    @PreAuthorize("@ss.hasPermi('system:module:add')")
    @Log(title = "课程模块", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CourseModuleAddBo bo) {
        return toAjax(iCourseModuleService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改课程模块
     */
    @ApiOperation("修改课程模块")
    @PreAuthorize("@ss.hasPermi('system:module:edit')")
    @Log(title = "课程模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody CourseModuleEditBo bo) {
        return toAjax(iCourseModuleService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除课程模块
     */
   /* @ApiOperation("删除课程模块")
    @PreAuthorize("@ss.hasPermi('system:module:remove')")
    @Log(title = "课程模块" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{moduleIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] moduleIds) {
        return toAjax(iCourseModuleService.deleteWithValidByIds(Arrays.asList(moduleIds), true) ? 1 : 0);
    }*/

    /**
     * 获取课程小节业务层次列表
     */
    @ApiOperation("获取课程模块业务层次列表")
    @PreAuthorize("@ss.hasPermi('system:section:query')")
    @GetMapping("/business/{moduleId}")
    public AjaxResult<List<CourseModuleBusiness>> getBusinessList(@PathVariable("moduleId" ) Long moduleId) {
        List<CourseModuleBusiness> list = iCourseModuleBusinessService.getListById(moduleId);
        return AjaxResult.success(list);
    }
}
