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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.bpm.service.processmapping.ProcessQueryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 管理后台 - 流程数据查询
 *
 * @author 系统
 */
@Tag(name = "管理后台 - 流程数据查询")
@RestController
@RequestMapping("/bpm/process-query")
@Validated
@Slf4j
public class BpmProcessQueryController {

    @Resource
    private ProcessQueryService processQueryService;

    @GetMapping("/data")
    @Operation(summary = "根据流程代码和ID查询数据")
    @Parameter(name = "processCode", description = "流程代码", required = true, example = "ORDER")
    @Parameter(name = "id", description = "数据ID", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('bpm:process-query:data')")
    public CommonResult<Object> getProcessData(@RequestParam("processCode") String processCode,
                                               @RequestParam("id") Serializable id) {
        Object result = processQueryService.queryById(processCode, id);
        return success(result);
    }
}
