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

import com.cpop.oam.business.service.DeptService;
import com.cpop.oam.business.vo.DeptVo;
import com.cpop.core.annontation.OperationLog;
import com.cpop.core.base.R;
import com.cpop.core.base.enums.OperationLogEnum;
import com.cpop.oam.business.bo.DeptBo;
import com.cpop.oam.business.bo.DeptListBo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

    @Autowired
    private DeptService deptService;

    /**
     * @Description: 查询部门树列表
     * @param bo 请求参数
     * @return R<List<SysDeptVo>>
     * @Author DB
     * @Date: 2023/5/9 20:45
     */
    @PreAuthorize("@aps.hasPermission('system:dept:list')")
    @ApiOperation("查询部门树列表")
    @GetMapping("/getDeptTreeList")
    public R<List<DeptVo>> getDeptTreeList(DeptListBo bo) {
        List<DeptVo> list = deptService.getDeptTreeList(bo);
        return R.ok(list);
    }

    /**
     * @Description: 新增部门
     * @param bo 请求参数
     * @return R<Void>
     * @Author DB
     * @Date: 2023/5/9 20:47
     */
    @PreAuthorize("@aps.hasPermission('system:dept:insert')")
    @ApiOperation("新增部门")
    @PostMapping("/insertDept")
    public R<Void> insertDept(@Validated @RequestBody DeptBo bo) {
        deptService.insertDept(bo);
        return R.ok();
    }
    
    /**
     * @Description: 修改部门
     * @param bo 请求参数
     * @return R<Void>
     * @Author DB
     * @Date: 2023/5/9 20:47
     */
    @PreAuthorize("@aps.hasPermission('system:dept:update')")
    @ApiOperation("修改部门")
    @PutMapping("/updateDept")
    public R<Void> updateDept(@Validated @RequestBody DeptBo bo) {
        deptService.updateDept(bo);
        return R.ok();
    }

    /**
     * @Description: 删除部门
     * @param id 主键
     * @Author DB
     * @Date: 2023/5/9 20:48
     */
    @PreAuthorize("@aps.hasPermission('system:dept:remove')")
    @ApiOperation("删除部门")
    @DeleteMapping("/removeDept/{id}")
    public R<Void> removeDept(@PathVariable String id) {
        deptService.removeDept(id);
        return R.ok();
    }



}
