package com.zhongzheng.controller.course;

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

import com.zhongzheng.modules.course.bo.CourseMenuAddBo;
import com.zhongzheng.modules.course.bo.CourseMenuEditBo;
import com.zhongzheng.modules.course.bo.CourseMenuListAddBo;
import com.zhongzheng.modules.course.bo.CourseMenuQueryBo;
import com.zhongzheng.modules.course.service.ICourseMenuService;
import com.zhongzheng.modules.course.vo.CourseMenuVo;
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-12
 */
@Api(value = "课程目录结构控制器", tags = {"课程目录结构管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/menu")
public class CourseMenuController extends BaseController {

    private final ICourseMenuService iCourseMenuService;

    /**
     * 查询课程目录结构列表
     */
    @ApiOperation("查询课程目录结构列表")
    @PreAuthorize("@ss.hasPermi('system:menu:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseMenuVo> list(CourseMenuQueryBo bo) {
        startPage();
        List<CourseMenuVo> list = iCourseMenuService.selectList(bo);
        return getDataTable(list);
    }

    /**
     * 导出课程目录结构列表
     */
   /* @ApiOperation("导出课程目录结构列表")
    @PreAuthorize("@ss.hasPermi('system:menu:export')")
    @Log(title = "课程目录结构", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CourseMenuVo> export(CourseMenuQueryBo bo) {
        List<CourseMenuVo> list = iCourseMenuService.queryList(bo);
        ExcelUtil<CourseMenuVo> util = new ExcelUtil<CourseMenuVo>(CourseMenuVo.class);
        return util.exportExcel(list, "课程目录结构");
    }*/

    /**
     * 获取课程目录结构详细信息
     */
    @ApiOperation("获取课程目录结构详细信息")
    @PreAuthorize("@ss.hasPermi('system:menu:query')")
    @GetMapping("/{id}")
    public AjaxResult<CourseMenuVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCourseMenuService.queryById(id));
    }

    /**
     * 新增课程目录结构
     */
    @ApiOperation("新增课程目录结构")
    @PreAuthorize("@ss.hasPermi('system:menu:add')")
    @Log(title = "课程目录结构", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CourseMenuListAddBo bo) {
        return toAjax(iCourseMenuService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改课程目录结构
     */
    @ApiOperation("修改课程目录结构")
    @PreAuthorize("@ss.hasPermi('system:menu:edit')")
    @Log(title = "课程目录结构", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody CourseMenuListAddBo bo) {
        return toAjax(iCourseMenuService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除课程目录结构
     */
/*    @ApiOperation("删除课程目录结构")
    @PreAuthorize("@ss.hasPermi('system:menu:remove')")
    @Log(title = "课程目录结构" , businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iCourseMenuService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }*/
}
