package com.zcloud.modules.oa.controller;

import com.zcloud.common.annotation.SysLog;
import com.zcloud.common.utils.CamelCaseUtil;
import com.zcloud.common.utils.PageUtils;
import com.zcloud.common.utils.R;
import com.zcloud.modules.oa.entity.OaPostEntity;
import com.zcloud.modules.oa.service.OaPostService;
import com.zcloud.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author fangjiakai
 * @Desc 岗位(OaPost)表控制层
 * @Date 2023-10-17 16:31:25
 */
@Api(tags = "岗位")
@RestController
@RequestMapping("/oa/post")
public class OaPostController extends AbstractController {
    @Autowired
    private OaPostService oaPostService;

    @ApiOperation("岗位-新增数据")
    @SysLog("岗位-新增数据")
	//@RequiresPermission("oaPost:save")
    @PostMapping("/save")
    public R insert(@RequestBody OaPostEntity param) {
        param.setCreateor(getUserId());
		param.setOperator(getUserId());
        boolean result = oaPostService.savePost(param);
        if (!result)
            return R.error(200,"岗位名重复!");
        return R.ok();
    }

    @ApiOperation("岗位-编辑数据")
    @SysLog("岗位-编辑数据")
//    //@RequiresPermission("oaPost:update")
    @PostMapping("/update")
    public R update(@RequestBody OaPostEntity param) {
        param.setOperator(getUserId());
        oaPostService.updateById(param);

        return R.ok();
    }


    @ApiOperation("岗位-删除数据")
    @SysLog("岗位-删除数据")
//    //@RequiresPermission("oaPost:delete")
    @PostMapping("/delete")
    public R delete(@RequestBody OaPostEntity param) {
        oaPostService.delete(param.getPostId(),getUserId());
        return R.ok();
    }

    @ApiOperation("岗位-分页查询")
    @SysLog("岗位-分页查询")
//    //@RequiresPermission("oaPost:list")
    @PostMapping("/listPage")
    public R listPage(@RequestBody Map<String, Object> params) {
        PageUtils page = oaPostService.listPage(params);

		return R.ok().put("page", page);
    }

    @ApiOperation("岗位-查询全部")
    @SysLog("岗位-查询全部")
//    //@RequiresPermission("oaPost:list")
    @PostMapping("/listAll")
    public R listAll(@RequestBody Map<String, Object> params) {
        params.remove("userId");
        List<OaPostEntity> list = oaPostService.listByMap(CamelCaseUtil.camelToUnderline(params));

        return R.ok().put("postList", list);
    }


    @ApiOperation("岗位-根据ID查详情")
    @SysLog("岗位-根据ID查详情")
//    //@RequiresPermission("oaPost:info")
    @PostMapping("/info")
    public R info(@RequestBody OaPostEntity param) {
        OaPostEntity oaPost = oaPostService.getById(param.getPostId());
        return R.ok().put("oaPost", oaPost);
    }

}
