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.reimbursement.BpmOAReimbursementCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.reimbursement.BpmOAReimbursementRespVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAReimbursementConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAReimbursementDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAReimbursementService;
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/reimbursement")
@Validated
public class BpmOAReimbursementController {

    @Resource
    private BpmOAReimbursementService service;

    @PostMapping("/create")
//    @PreAuthorize("@ss.hasPermission('bpm:oa-reimbursement:create')")
    @Operation(summary = "创建请求申请")
    public CommonResult<Long> createReimbursement(@Valid @RequestBody BpmOAReimbursementCreateReqVO createReqVO) {
        return success(service.createReimbursement(getLoginUserId(), createReqVO));
    }

    @GetMapping("/get")
//    @PreAuthorize("@ss.hasPermission('bpm:oa-reimbursement:query')")
    @Operation(summary = "获得报销申请")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOAReimbursementRespVO> getReimbursement(@RequestParam("id") Long id) {

        BpmOAReimbursementDO reimbursement = service.getReimbursement(id);
        return success(service.convert(reimbursement));
    }

//    @GetMapping("/page")
//    @PreAuthorize("@ss.hasPermission('bpm:oa-reimbursement:query')")
//    @Operation(summary = "获得请假申请分页")
//    public CommonResult<PageResult<BpmOALeaveRespVO>> getLeavePage(@Valid BpmOALeavePageReqVO pageVO) {
//        PageResult<BpmOALeaveDO> pageResult = leaveService.getLeavePage(getLoginUserId(), pageVO);
//        return success(BpmOALeaveConvert.INSTANCE.convertPage(pageResult));
//    }

}
