package com.cpop.oam.business.controller.backstage;

import com.cpop.core.base.entity.R;
import com.cpop.oam.business.bo.DeptBo;
import com.cpop.oam.business.bo.DeptListBo;
import com.cpop.oam.business.service.DeptService;
import com.cpop.oam.business.vo.DeptVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门表 控制层。
 *
 * @author DB
 * @since 2023-09-08
 */
@RestController
@Tag(name = "系统部门模块")
@RequestMapping("/backstage/dept")
public class BackstageDeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 查询部门树列表
     * @param bo 请求参数
     * @return R<List<SysDeptVo>>
     * @author DB
     * @since 2023/5/9 20:45
     */
    @Operation(summary = "查询部门树列表")
    @GetMapping("/getDeptTreeList")
    public R<List<DeptVo>> getDeptTreeList(DeptListBo bo) {
        List<DeptVo> list = deptService.getDeptTreeList(bo);
        return R.ok(list);
    }

    /**
     * 新增部门
     * @param bo 请求参数
     * @return R<Void>
     * @author DB
     * @since 2023/5/9 20:47
     */
    @Operation(summary = "新增部门")
    @PostMapping("/insertDept")
    public R<Void> insertDept(@Validated @RequestBody DeptBo bo) {
        deptService.insertDept(bo);
        return R.ok();
    }
    
    /**
     * 修改部门
     * @param bo 请求参数
     * @return R<Void>
     * @author DB
     * @since 2023/5/9 20:47
     */
    @Operation(summary = "修改部门")
    @PutMapping("/updateDept")
    public R<Void> updateDept(@Validated @RequestBody DeptBo bo) {
        deptService.updateDept(bo);
        return R.ok();
    }

    /**
     * 删除部门
     * @param id 主键
     * @author DB
     * @since 2023/5/9 20:48
     */
    @Operation(summary = "删除部门")
    @DeleteMapping("/removeDept/{id}")
    public R<Void> removeDept(@PathVariable String id) {
        deptService.removeDept(id);
        return R.ok();
    }



}
