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.businessCard.BpmOABusinessCardCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.businessCard.BpmOABusinessCardRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOABusinessCardDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOABusinessCardService;
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-card")
@Validated
public class BpmOABusinessCardController {

    @Resource
    private BpmOABusinessCardService bpmOABusinessCardService;

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

        return success(bpmOABusinessCardService.createBusinessCard(getLoginUserId(), createReqVO));
    }

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

        BpmOABusinessCardDO bpmOABusinessCardDO = bpmOABusinessCardService.getBusinessCard(id);

        return success(BeanUtils.toBean(bpmOABusinessCardDO, BpmOABusinessCardRespVO.class));
    }

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

        BpmOABusinessCardDO bpmOABusinessCardDO = bpmOABusinessCardService.getByProcessInstanceId(processInstanceId);

        return success(BeanUtils.toBean(bpmOABusinessCardDO, BpmOABusinessCardRespVO.class));
    }
}
