package com.zhongzheng.controller.course;

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

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.modules.course.vo.CourseBusinessVo;
import com.zhongzheng.modules.course.bo.CourseBusinessQueryBo;
import com.zhongzheng.modules.course.bo.CourseBusinessAddBo;
import com.zhongzheng.modules.course.bo.CourseBusinessEditBo;
import com.zhongzheng.modules.course.service.ICourseBusinessService;
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 ruoyi
 * @date 2021-10-08
 */
@Api(value = "业务层次控制器", tags = {"业务层次管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/business")
public class CourseBusinessController extends BaseController {

    private final ICourseBusinessService iCourseBusinessService;

    /**
     * 查询业务层次列表
     */
    @ApiOperation("查询业务层次列表")
    @PreAuthorize("@ss.hasPermi('course:business:list')")
    @GetMapping("/list")
    public TableDataInfo<CourseBusinessVo> list(CourseBusinessQueryBo bo) {
        startPage();
        List<CourseBusinessVo> list = iCourseBusinessService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出业务层次列表
     */
 /*   @ApiOperation("导出业务层次列表")
    @PreAuthorize("@ss.hasPermi('modules.course:business:export')")
    @Log(title = "业务层次", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CourseBusinessVo> export(CourseBusinessQueryBo bo) {
        List<CourseBusinessVo> list = iCourseBusinessService.queryList(bo);
        ExcelUtil<CourseBusinessVo> util = new ExcelUtil<CourseBusinessVo>(CourseBusinessVo.class);
        return util.exportExcel(list, "业务层次");
    }*/

    /**
     * 获取业务层次详细信息
     */
    @ApiOperation("获取业务层次详细信息")
    @PreAuthorize("@ss.hasPermi('course:business:query')")
    @GetMapping("/{id}")
    public AjaxResult<CourseBusinessVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCourseBusinessService.queryById(id));
    }

    /**
     * 新增业务层次
     */
    @ApiOperation("新增业务层次")
    @PreAuthorize("@ss.hasPermi('course:business:add')")
    @Log(title = "业务层次", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CourseBusinessAddBo bo) {
        return toAjax(iCourseBusinessService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改业务层次
     */
    @ApiOperation("修改业务层次")
    @PreAuthorize("@ss.hasPermi('course:business:edit')")
    @Log(title = "业务层次", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody CourseBusinessEditBo bo) {
        return toAjax(iCourseBusinessService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 修改业务层次
     */
    @ApiOperation("批量更改业务层次得模板")
    @PreAuthorize("@ss.hasPermi('course:business:edit')")
    @Log(title = "业务层次", businessType = BusinessType.UPDATE)
    @PostMapping("/editModel")
    public AjaxResult<Void> editModel(@RequestBody CourseBusinessEditBo bo) {
        return toAjax(iCourseBusinessService.editModel(bo) ? 1 : 0);
    }


    /**
     * 删除业务层次
     */
/*    @ApiOperation("删除业务层次")
    @PreAuthorize("@ss.hasPermi('modules.course:business:remove')")
    @Log(title = "业务层次" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iCourseBusinessService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }*/
}
