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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.businessHospitality.BpmOABusinessHospitalityCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.businessHospitality.BpmOABusinessHospitalityRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOABusinessHospitalityDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOABusinessHospitalityService;
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/business-hospitality")
@Validated
public class BpmOABusinessHospitalityController {

    @Resource
    private BpmOABusinessHospitalityService bpmOABusinessHospitalityService;

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

        return success(bpmOABusinessHospitalityService.createBusinessHospitality(getLoginUserId(), createReqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "获得名片定制申请")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOABusinessHospitalityRespVO> getBusinessHospitality(@RequestParam("id") Long id) {

        BpmOABusinessHospitalityDO bpmOABusinessHospitalityDO = bpmOABusinessHospitalityService.getBusinessHospitality(id);

        return success(BeanUtils.toBean(bpmOABusinessHospitalityDO, BpmOABusinessHospitalityRespVO.class));
    }

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

        BpmOABusinessHospitalityDO bpmOABusinessHospitalityDO = bpmOABusinessHospitalityService.getByProcessInstanceId(processInstanceId);

        return success(BeanUtils.toBean(bpmOABusinessHospitalityDO, BpmOABusinessHospitalityRespVO.class));
    }
}
