package cn.iocoder.yudao.module.bpm.controller.admin.oa;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.second.BpmOASecondCreateReqVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOASecondConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASecondDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOASecondService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * OA 借调申请 Controller
 *
 * @author 符溶馨
 */
@Tag(name = "管理后台 - OA 借调申请")
@RestController
@RequestMapping("/bpm/oa/second")
@Validated
public class BpmOASecondController {

    @Resource
    private BpmOASecondService service;

    @PostMapping("/create")
    @Operation(summary = "创建借调申请")
    public CommonResult<Long> createLeave(@Valid @RequestBody BpmOASecondCreateReqVO createReqVO) {
        return success(service.createSecond(getLoginUserId(), createReqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "获得借调申请")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<?> getLeave(@RequestParam("id") Long id) {
        BpmOASecondDO second = service.getSecond(id);
        return success(BpmOASecondConvert.INSTANCE.convert(second));
    }
}
