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.cash.BpmOACashCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.cash.BpmOACashRespVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOACashConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOACashDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOACashService;
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/cash")
@Validated
public class BpmOACashController {

    @Resource
    private BpmOACashService cashService;

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

        return success(cashService.createCash(getLoginUserId(), createReqVO));
    }

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

        BpmOACashDO cash = cashService.getCash(id);

        return success(BpmOACashConvert.INSTANCE.convert(cash));
    }
}
