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.MajorVo;
import com.zhongzheng.modules.course.bo.MajorQueryBo;
import com.zhongzheng.modules.course.bo.MajorAddBo;
import com.zhongzheng.modules.course.bo.MajorEditBo;
import com.zhongzheng.modules.course.service.IMajorService;
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-09
 */
@Api(value = "专业控制器", tags = {"专业管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course/major")
public class MajorController extends BaseController {

    private final IMajorService iMajorService;

    /**
     * 查询专业列表
     */
    @ApiOperation("查询专业列表")
    @PreAuthorize("@ss.hasPermi('course:major:list')")
    @GetMapping("/list")
    public TableDataInfo<MajorVo> list(MajorQueryBo bo) {
        startPage();
        List<MajorVo> list = iMajorService.queryList(bo);
        return getDataTable(list);
    }

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

    /**
     * 获取专业详细信息
     */
    @ApiOperation("获取专业详细信息")
    @PreAuthorize("@ss.hasPermi('course:major:query')")
    @GetMapping("/{id}")
    public AjaxResult<MajorVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMajorService.queryById(id));
    }

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

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

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