package com.xunmei.core.edu.controller;

import java.util.List;
import com.xunmei.common.core.domain.IdName;
import com.xunmei.common.core.domain.edu.domain.SysKnowledge;
import com.xunmei.core.edu.service.ISysKnowledgeService;
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.xunmei.common.log.annotation.Log;
import com.xunmei.common.log.enums.BusinessType;
import com.xunmei.common.security.annotation.RequiresPermissions;
import com.xunmei.common.core.web.controller.BaseController;
import com.xunmei.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.xunmei.common.core.web.page.TableDataInfo;

/**
 * 知识库标签Controller
 *
 * @author xunmei
 * @date 2023-08-21
 */
@Api(tags = {"SysKnowledge"})
@RestController
@RequestMapping("/knowledge")
public class SysKnowledgeController extends BaseController {
    @Autowired
    private ISysKnowledgeService sysKnowledgeService;

    /**
     * 查询知识库标签列表
     */
    @ApiOperation(value = "查询SysKnowledge列表")
    @RequiresPermissions("core:knowledge:list")
    @GetMapping("/list")
    public TableDataInfo list(SysKnowledge sysKnowledge) {
        return sysKnowledgeService.selectPage(sysKnowledge);
    }


    /**
     * 获取知识库标签详细信息
     */
    @ApiOperation(value = "获取SysKnowledge详细信息")
    @RequiresPermissions("core:knowledge:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysKnowledgeService.selectSysKnowledgeById(id));
    }

    /**
     * 新增知识库标签
     */
    @ApiOperation(value = "新增SysKnowledge")
    @RequiresPermissions("core:knowledge:add")
    @Log(title = "知识库标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysKnowledge sysKnowledge) {
        return toAjax(sysKnowledgeService.insertSysKnowledge(sysKnowledge));
    }

    /**
     * 修改知识库标签
     */
    @ApiOperation(value = "修改SysKnowledge")
    @RequiresPermissions("core:knowledge:edit")
    @Log(title = "知识库标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysKnowledge sysKnowledge) {
        return toAjax(sysKnowledgeService.updateSysKnowledge(sysKnowledge));
    }

    /**
     * 删除知识库标签
     */
    @ApiOperation(value = "删除SysKnowledge")
    @RequiresPermissions("core:knowledge:remove")
    @Log(title = "知识库标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysKnowledgeService.deleteSysKnowledgeByIds(ids));
    }

    /**
     * 查询知识库标签列表
     */
    @ApiOperation(value = "查询SysKnowledge列表")
    @GetMapping("/dataList")
    public List<IdName<String,String>> dataList() {
        return sysKnowledgeService.dataList();
    }
}
