package com.zhongzheng.controller.course;

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

import cn.hutool.http.HttpStatus;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zhongzheng.modules.course.bo.CourseAddBo;
import com.zhongzheng.modules.course.bo.CourseEditBo;
import com.zhongzheng.modules.course.bo.CourseQueryBo;
import com.zhongzheng.modules.course.service.ICourseService;
import com.zhongzheng.modules.course.vo.CourseVo;
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")
public class CourseController extends BaseController {

    private final ICourseService iCourseService;

    /**
     * 查询课程列表
     */
    @ApiOperation("查询课程列表")
    @PreAuthorize("@ss.hasPermi('course:course:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseVo> list(CourseQueryBo bo) {
        startPage();
        List<CourseVo> list = iCourseService.selectCourseList(bo);
        return getDataTable(list);
    }

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

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

    /**
     * 新增课程
     */
    @ApiOperation("新增课程")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('course:course:add')")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@Validated @RequestBody CourseAddBo bo) {
        Long id = iCourseService.insertByAddBo(bo);
        String content = "新增课程:"+bo.getCourseName();
        return AjaxResult.success_log(id,content);
    }

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

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