package com.goldenwater.slgc.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.slgc.domain.DocCate;
import com.goldenwater.slgc.service.DocCateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "15. 文档分类管理")
@RestController
@RequestMapping("/slgc/doc-cate")
public class DocCateController extends BaseController {
    @Autowired
    private DocCateService docCateService;

    @Operation(summary = "15.01 查询文档分类列表")
    @GetMapping("/list")
    public TableDataInfo list(DocCate docCate) {
        startPage();
        List<DocCate> list = docCateService.selectDocCateList(docCate);
        return getDataTable(list);
    }

    @Operation(summary = "15.02 获取文档分类详细信息")
    @GetMapping(value = "/{cateId}")
    public AjaxResult getInfo(@PathVariable String cateId) {
        return success(docCateService.selectDocCateById(cateId));
    }

    @Operation(summary = "15.03 新增文档分类")
    @Log(title = "文档分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocCate docCate) {
        return toAjax(docCateService.insertDocCate(docCate));
    }

    @Operation(summary = "15.04 修改文档分类")
    @Log(title = "文档分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocCate docCate) {
        return toAjax(docCateService.updateDocCate(docCate));
    }

    @Operation(summary = "15.05 删除文档分类")
    @Log(title = "文档分类管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cateIds}")
    public AjaxResult remove(@PathVariable String[] cateIds) {
        return toAjax(docCateService.deleteDocCateByIds(cateIds));
    }

    @Operation(summary = "15.06 获取文档分类树")
    @GetMapping("/tree")
    public AjaxResult getTree() {
        return success(docCateService.getTree());
    }

    @Operation(summary = "15.07 查询子分类列表")
    @GetMapping("/subList/{catePid}")
    public AjaxResult getSubList(@PathVariable String catePid) {
        return success(docCateService.findSubList(catePid));
    }
}
