package com.zhongzheng.controller.course;

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

import com.zhongzheng.modules.course.bo.CourseChapterBusinessAddBo;
import com.zhongzheng.modules.course.bo.CourseChapterBusinessEditBo;
import com.zhongzheng.modules.course.bo.CourseChapterBusinessQueryBo;
import com.zhongzheng.modules.course.service.ICourseChapterBusinessService;
import com.zhongzheng.modules.course.vo.CourseChapterBusinessVo;
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/chapter/business")
public class CourseChapterBusinessController extends BaseController {

    private final ICourseChapterBusinessService iCourseChapterBusinessService;

    /**
     * 查询课程大章适用业务关系列表
     */
    @ApiOperation("查询课程大章适用业务关系列表")
    @PreAuthorize("@ss.hasPermi('system:business:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseChapterBusinessVo> list(CourseChapterBusinessQueryBo bo) {
        startPage();
        List<CourseChapterBusinessVo> list = iCourseChapterBusinessService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出课程大章适用业务关系列表
     */
    /*@ApiOperation("导出课程大章适用业务关系列表")
    @PreAuthorize("@ss.hasPermi('system:business:export')")
    @Log(title = "课程大章适用业务关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CourseChapterBusinessVo> export(CourseChapterBusinessQueryBo bo) {
        List<CourseChapterBusinessVo> list = iCourseChapterBusinessService.queryList(bo);
        ExcelUtil<CourseChapterBusinessVo> util = new ExcelUtil<CourseChapterBusinessVo>(CourseChapterBusinessVo.class);
        return util.exportExcel(list, "课程大章适用业务关系");
    }*/

    /**
     * 获取课程大章适用业务关系详细信息
     */
    @ApiOperation("获取课程大章适用业务关系详细信息")
    @PreAuthorize("@ss.hasPermi('system:business:query')")
    @GetMapping("/{id}")
    public AjaxResult<CourseChapterBusinessVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCourseChapterBusinessService.queryById(id));
    }

    /**
     * 新增课程大章适用业务关系
     */
    @ApiOperation("新增课程大章适用业务关系")
    @PreAuthorize("@ss.hasPermi('system:business:add')")
    @Log(title = "课程大章适用业务关系", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CourseChapterBusinessAddBo bo) {
        return toAjax(iCourseChapterBusinessService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改课程大章适用业务关系
     */
    @ApiOperation("修改课程大章适用业务关系")
    @PreAuthorize("@ss.hasPermi('system:business:edit')")
    @Log(title = "课程大章适用业务关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody CourseChapterBusinessEditBo bo) {
        return toAjax(iCourseChapterBusinessService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除课程大章适用业务关系
     */
    @ApiOperation("删除课程大章适用业务关系")
    @PreAuthorize("@ss.hasPermi('system:business:remove')")
    @Log(title = "课程大章适用业务关系" , businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iCourseChapterBusinessService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
