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.goOut.BpmOAGoOutCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.goOut.BpmOAGoOutRespVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAGoOutConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAGoOutDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAGoOutService;
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/goOut")
@Validated
public class BpmOAGoOutController {

    @Resource
    private BpmOAGoOutService goOutService;



    @PostMapping("/create")
    @Operation(summary = "创建外出申请")
    public CommonResult<Long> createGoOut(@Valid @RequestBody BpmOAGoOutCreateReqVO createReqVO) {

        return success(goOutService.createGoOut(getLoginUserId(), createReqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "获得入职申请")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOAGoOutRespVO> getGoOut(@RequestParam("id") Long id) {

        BpmOAGoOutDO goOut = goOutService.getGoOut(id);

        return success(BpmOAGoOutConvert.INSTANCE.convert(goOut));
    }

    @GetMapping("/getByProcessInstanceId")
    @Operation(summary = "获得外出申请")
    @Parameter(name = "processInstanceId", description = "流程实例编号", required = true, example = "1024")
    public CommonResult<BpmOAGoOutRespVO> getByProcessInstanceId(@RequestParam("processInstanceId") String processInstanceId) {

        BpmOAGoOutDO goOut = goOutService.getByProcessInstanceId(processInstanceId);
        return success(BpmOAGoOutConvert.INSTANCE.convert(goOut));
    }
}
