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.MajorLabelVo;
import com.zhongzheng.modules.course.bo.MajorLabelQueryBo;
import com.zhongzheng.modules.course.bo.MajorLabelAddBo;
import com.zhongzheng.modules.course.bo.MajorLabelEditBo;
import com.zhongzheng.modules.course.service.IMajorLabelService;
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/label")
public class MajorLabelController extends BaseController {

    private final IMajorLabelService iMajorLabelService;

    /**
     * 查询标签列表
     */
    @ApiOperation("查询标签列表")
    @PreAuthorize("@ss.hasPermi('course:label:list')")
    @GetMapping("/list")
    public TableDataInfo<MajorLabelVo> list(MajorLabelQueryBo bo) {
        startPage();
        List<MajorLabelVo> list = iMajorLabelService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 查询标签关联专业列表
     */
    @ApiOperation("查询标签关联专业列表")
    @PreAuthorize("@ss.hasPermi('course:label:list')")
    @GetMapping("/listMajor")
    public TableDataInfo<MajorLabelVo> listMajor(MajorLabelQueryBo bo) {
        startPage();
        List<MajorLabelVo> list = iMajorLabelService.listMajor(bo);
        return getDataTable(list);
    }

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

    /**
     * 获取标签详细信息
     */
    @ApiOperation("获取标签详细信息")
    @PreAuthorize("@ss.hasPermi('course:label:query')")
    @GetMapping("/{id}")
    public AjaxResult<MajorLabelVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMajorLabelService.queryById(id));
    }

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

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

    /**
     * 删除关联标签
     */
    @ApiOperation("删除关联标签")
    @PreAuthorize("@ss.hasPermi('course:label:edit')")
    @Log(title = "删除关联标签", businessType = BusinessType.UPDATE)
    @PostMapping("/editMajor")
    public AjaxResult<Void> editMajor(@RequestBody MajorLabelEditBo bo) {
        return toAjax(iMajorLabelService.editMajor(bo) ? 1 : 0);
    }

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