package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.dto.Result;
import com.crunii.micro.service.sysmgr.dto.post.*;
import com.crunii.micro.service.sysmgr.service.PostService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Tag(name = "管理后台 - 职务")
@RestController
@RequestMapping("/auth/postController")
@Validated
public class PostController {

    @Resource
    private PostService postService;

    @PostMapping("/create")
    @ApiOperation("创建职务")
    public Result createPost(@Valid @RequestBody PostCreateReqVO reqVO) {
        Result<Long> result=new Result<>();
        result.setData(postService.createPost(reqVO));
        return result;
    }

    @PostMapping("/update")
    @ApiOperation("修改职务")
    public Result<Boolean> updatePost(@Valid @RequestBody PostUpdateReqVO reqVO) {
        postService.updatePost(reqVO);
        return new Result<>(true);
    }

    @GetMapping("/delete")
    @ApiOperation("删除职务")
    public Result<Boolean> deletePost(@RequestParam("id") Long id) {
        postService.deletePost(id);
        return new Result<>(true);
    }

    @GetMapping(value = "/get")
    @ApiOperation("获取职务详情")
    public Result<PostRespVO> getPost(@RequestParam("id") Long id) {
        return new Result<>(postService.getPost(id));
    }

    @GetMapping("/list-all-simple")
    @ApiOperation("获取职务精简信息列表")
    public Result<List<PostListRspVo>> getSimplePostList() {
        return new Result<>(postService.getPostList());
    }

    @PostMapping("/page")
    @ApiOperation("获取职务详情")
    @Operation(summary = "获得职务分页列表")
    public Result<PageRsp<PostRespVO>> getPostPage(@RequestBody PageReq<PostPageReqVO> reqVO) {
        return new Result<>(postService.getPostPage(reqVO));
    }

    @PostMapping("/get-by-name")
    @ApiOperation("判断职务名称是否重复")
    public Result<Boolean> getByName(@RequestBody PostReqVO reqVO) {
        return postService.getByName(reqVO);
    }

    @PostMapping("/doCorrelateRole")
    @ApiOperation("关联角色")
    public Result<Boolean> doCorrelateRole(@RequestBody CorrelatePostReq reqVO) {
        return postService.doCorrelateRole(reqVO);
    }
}
