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.evection.BpmOAEvectionCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.evection.BpmOAEvectionRespVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAEvectionConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAEvectionDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAEvectionService;
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/evection")
@Validated
public class BpmOAEvectionController {

    @Resource
    private BpmOAEvectionService evectionService;

    @PostMapping("/create")
    @Operation(summary = "创建请求申请")
    public CommonResult<Long> createEvection(@Valid @RequestBody BpmOAEvectionCreateReqVO createReqVO) {

        return success(evectionService.createEvection(getLoginUserId(), createReqVO));
    }

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

        BpmOAEvectionDO evection = evectionService.getEvection(id);

        return success(BpmOAEvectionConvert.INSTANCE.convert(evection));
    }
}
