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.TeacherAddBo;
import com.zhongzheng.modules.course.bo.TeacherEditBo;
import com.zhongzheng.modules.course.bo.TeacherQueryBo;
import com.zhongzheng.modules.course.service.ITeacherService;
import com.zhongzheng.modules.course.vo.TeacherVo;
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/teacher")
public class TeacherController extends BaseController {

    private final ITeacherService iTeacherService;

    /**
     * 查询名师列表
     */
    @ApiOperation("查询名师列表")
    @PreAuthorize("@ss.hasPermi('course:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo<TeacherVo> list(TeacherQueryBo bo) {
        startPage();
        List<TeacherVo> list = iTeacherService.queryList(bo);
        return getDataTable(list);
    }

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

    /**
     * 获取名师详细信息
     */
    @ApiOperation("获取名师详细信息")
    @PreAuthorize("@ss.hasPermi('course:teacher:query')")
    @GetMapping("/{teacherId}")
    public AjaxResult<TeacherVo> getInfo(@PathVariable("teacherId" ) Long teacherId) {
        return AjaxResult.success(iTeacherService.queryById(teacherId));
    }

    /**
     * 新增名师
     */
    @ApiOperation("新增名师")
    @ApiOperationSupport(ignoreParameters = {"updateTime","createTime"})
    @PreAuthorize("@ss.hasPermi('course:teacher:add')")
    @Log(title = "名师", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated  @RequestBody TeacherAddBo bo) {
        return toAjax(iTeacherService.insertByAddBo(bo) ? 1 : 0);
    }

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

    /**
     * 删除名师
     */
    /*@ApiOperation("删除名师")
    @PreAuthorize("@ss.hasPermi('course:teacher:remove')")
    @Log(title = "名师" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{teacherIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] teacherIds) {
        return toAjax(iTeacherService.deleteWithValidByIds(Arrays.asList(teacherIds), true) ? 1 : 0);
    }*/
}
