package com.zcloud.basic.info.web;


import com.zcloud.basic.info.api.PostServiceI;
import com.zcloud.basic.info.dto.*;
import com.zcloud.basic.info.dto.clientobject.PostCO;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * web-adapter
 * 岗位管理
 * @Author SondonYong
 * @Date 2025-10-31 17:24:04
 */
@Api(tags = "岗位表")
@RequestMapping("/${application.gateway}/post")
@RestController
@AllArgsConstructor
public class PostController {
    private final PostServiceI postService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<PostCO> add(@Validated @RequestBody PostAddCmd cmd) {
        return postService.add(cmd);
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody PostUpdateCmd cmd) {
        postService.edit(cmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('gwgl','gwglqyd')")
    public PageResponse<PostCO> page(@Validated @RequestBody PostPageQry qry) {
        return postService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @PostMapping("/listAll")
    public MultiResponse<PostCO> listAll(@Validated @RequestBody PostListQry qry) {
        return postService.list(qry);
    }

    @ApiOperation("详情")
    @GetMapping("/getInfoById")
    public SingleResponse<PostCO> getInfoById(@RequestParam(value = "id") Long id) {
        return postService.getInfoById(id);
    }

    @ApiOperation("删除")
    @PutMapping("/remove")
    public Response remove(@RequestParam(value = "id") Long id) {
        postService.remove(id);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("删除多个")
    @PutMapping("/removeBatch")
    public Response removeBatch(@Validated @RequestBody PostRemoveCmd cmd) {
        postService.removeBatch(cmd.getIds());
        return SingleResponse.buildSuccess();
    }

}

