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.seal.BpmOASealCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.seal.BpmOASealRespVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOASealConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASealDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOASealService;
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/seal")
@Validated
public class BpmOASealController {

    @Resource
    private BpmOASealService sealService;

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

        return success(sealService.createSeal(getLoginUserId(), createReqVO));
    }

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

        BpmOASealDO seal = sealService.getSeal(id);

        return success(BpmOASealConvert.INSTANCE.convert(seal));
    }
}
