mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-14 04:13:39 +00:00
feat: 流程编排init
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
package org.ruoyi.workflow.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.workflow.base.ThreadContext;
|
||||
import org.ruoyi.workflow.dto.workflow.*;
|
||||
import org.ruoyi.workflow.entity.WorkflowComponent;
|
||||
import org.ruoyi.workflow.service.WorkflowComponentService;
|
||||
import org.ruoyi.workflow.service.WorkflowService;
|
||||
import org.ruoyi.workflow.workflow.WorkflowStarter;
|
||||
import org.ruoyi.workflow.workflow.node.switcher.OperatorEnum;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/workflow")
|
||||
@Validated
|
||||
public class WorkflowController {
|
||||
|
||||
@Resource
|
||||
private WorkflowStarter workflowStarter;
|
||||
|
||||
@Resource
|
||||
private WorkflowService workflowService;
|
||||
|
||||
@Resource
|
||||
private WorkflowComponentService workflowComponentService;
|
||||
|
||||
@PostMapping("/add")
|
||||
public R<WorkflowResp> add(@RequestBody @Validated WfAddReq addReq) {
|
||||
return R.ok(workflowService.add(addReq.getTitle(), addReq.getRemark(), addReq.getIsPublic()));
|
||||
}
|
||||
|
||||
@PostMapping("/set-public/{wfUuid}")
|
||||
public R setPublic(@PathVariable String wfUuid, @RequestParam(defaultValue = "true") Boolean isPublic) {
|
||||
workflowService.setPublic(wfUuid, isPublic);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public R<WorkflowResp> update(@RequestBody @Validated WorkflowUpdateReq req) {
|
||||
return R.ok(workflowService.update(req));
|
||||
}
|
||||
|
||||
@PostMapping("/del/{uuid}")
|
||||
public R delete(@PathVariable String uuid) {
|
||||
workflowService.softDelete(uuid);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/enable/{uuid}")
|
||||
public R enable(@PathVariable String uuid, @RequestParam Boolean enable) {
|
||||
workflowService.enable(uuid, enable);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/base-info/update")
|
||||
public R<WorkflowResp> updateBaseInfo(@RequestBody @Validated WfBaseInfoUpdateReq req) {
|
||||
return R.ok(workflowService.updateBaseInfo(req.getUuid(), req.getTitle(), req.getRemark(), req.getIsPublic()));
|
||||
}
|
||||
|
||||
@Operation(summary = "流式响应")
|
||||
@PostMapping(value = "/run", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public SseEmitter sseAsk(@RequestBody WorkflowRunReq runReq) {
|
||||
return workflowStarter.streaming(ThreadContext.getCurrentUser(), runReq.getUuid(), runReq.getInputs());
|
||||
}
|
||||
|
||||
@GetMapping("/mine/search")
|
||||
public R<Page<WorkflowResp>> searchMine(@RequestParam(defaultValue = "") String keyword,
|
||||
@RequestParam(required = false) Boolean isPublic,
|
||||
@NotNull @Min(1) Integer currentPage,
|
||||
@NotNull @Min(10) Integer pageSize) {
|
||||
return R.ok(workflowService.search(keyword, isPublic, null, currentPage, pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索公开工作流
|
||||
*
|
||||
* @param keyword 搜索关键词
|
||||
* @param currentPage 当前页数
|
||||
* @param pageSize 每页数量
|
||||
* @return 工作流列表
|
||||
*/
|
||||
@GetMapping("/public/search")
|
||||
public R<Page<WorkflowResp>> searchPublic(@RequestParam(defaultValue = "") String keyword,
|
||||
@NotNull @Min(1) Integer currentPage,
|
||||
@NotNull @Min(10) Integer pageSize) {
|
||||
return R.ok(workflowService.searchPublic(keyword, currentPage, pageSize));
|
||||
}
|
||||
|
||||
@GetMapping("/public/operators")
|
||||
public R<List<Map<String, String>>> searchPublic() {
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
for (OperatorEnum operator : OperatorEnum.values()) {
|
||||
result.add(Map.of("name", operator.getName(), "desc", operator.getDesc()));
|
||||
}
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@GetMapping("/public/component/list")
|
||||
public R<List<WorkflowComponent>> component() {
|
||||
return R.ok(workflowComponentService.getAllEnable());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.ruoyi.workflow.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.workflow.dto.workflow.WfRuntimeNodeDto;
|
||||
import org.ruoyi.workflow.dto.workflow.WfRuntimeResp;
|
||||
import org.ruoyi.workflow.dto.workflow.WorkflowResumeReq;
|
||||
import org.ruoyi.workflow.service.WorkflowRuntimeService;
|
||||
import org.ruoyi.workflow.workflow.WorkflowStarter;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/workflow/runtime")
|
||||
@Validated
|
||||
public class WorkflowRuntimeController {
|
||||
|
||||
@Resource
|
||||
private WorkflowRuntimeService workflowRuntimeService;
|
||||
|
||||
@Resource
|
||||
private WorkflowStarter workflowStarter;
|
||||
|
||||
@Operation(summary = "接收用户输入以继续执行剩余流程")
|
||||
@PostMapping(value = "/resume/{runtimeUuid}")
|
||||
public R resume(@PathVariable String runtimeUuid, @RequestBody WorkflowResumeReq resumeReq) {
|
||||
workflowStarter.resumeFlow(runtimeUuid, resumeReq.getFeedbackContent());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
public R<Page<WfRuntimeResp>> search(@RequestParam String wfUuid,
|
||||
@NotNull @Min(1) Integer currentPage,
|
||||
@NotNull @Min(10) Integer pageSize) {
|
||||
return R.ok(workflowRuntimeService.page(wfUuid, currentPage, pageSize));
|
||||
}
|
||||
|
||||
@GetMapping("/nodes/{runtimeUuid}")
|
||||
public R<List<WfRuntimeNodeDto>> listByRuntimeId(@PathVariable String runtimeUuid) {
|
||||
return R.ok(workflowRuntimeService.listByRuntimeUuid(runtimeUuid));
|
||||
}
|
||||
|
||||
@PostMapping("/clear")
|
||||
public R<Boolean> clear(@RequestParam(defaultValue = "") String wfUuid) {
|
||||
return R.ok(workflowRuntimeService.deleteAll(wfUuid));
|
||||
}
|
||||
|
||||
@PostMapping("/del/{wfRuntimeUuid}")
|
||||
public R<Boolean> delete(@PathVariable String wfRuntimeUuid) {
|
||||
return R.ok(workflowRuntimeService.softDelete(wfRuntimeUuid));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.ruoyi.workflow.controller.admin;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.workflow.dto.workflow.WfComponentReq;
|
||||
import org.ruoyi.workflow.dto.workflow.WfComponentSearchReq;
|
||||
import org.ruoyi.workflow.entity.WorkflowComponent;
|
||||
import org.ruoyi.workflow.service.WorkflowComponentService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/workflow/component")
|
||||
@Validated
|
||||
public class AdminWorkflowComponentController {
|
||||
@Resource
|
||||
private WorkflowComponentService workflowComponentService;
|
||||
|
||||
@PostMapping("/search")
|
||||
public R<Page<WorkflowComponent>> search(@RequestBody WfComponentSearchReq searchReq, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) {
|
||||
return R.ok(workflowComponentService.search(searchReq, currentPage, pageSize));
|
||||
}
|
||||
|
||||
@PostMapping("/enable")
|
||||
public R enable(@RequestParam String uuid, @RequestParam Boolean isEnable) {
|
||||
workflowComponentService.enable(uuid, isEnable);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/del/{uuid}")
|
||||
public R del(@PathVariable String uuid) {
|
||||
workflowComponentService.deleteByUuid(uuid);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/addOrUpdate")
|
||||
public R<WorkflowComponent> addOrUpdate(@Validated @RequestBody WfComponentReq req) {
|
||||
return R.ok(workflowComponentService.addOrUpdate(req));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.ruoyi.workflow.controller.admin;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.workflow.dto.workflow.WfSearchReq;
|
||||
import org.ruoyi.workflow.dto.workflow.WorkflowResp;
|
||||
import org.ruoyi.workflow.service.WorkflowService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/workflow")
|
||||
@Validated
|
||||
public class AdminWorkflowController {
|
||||
|
||||
@Resource
|
||||
private WorkflowService workflowService;
|
||||
|
||||
@PostMapping("/search")
|
||||
public R<Page<WorkflowResp>> search(@RequestBody WfSearchReq req,
|
||||
@RequestParam @NotNull @Min(1) Integer currentPage,
|
||||
@RequestParam @NotNull @Min(10) Integer pageSize) {
|
||||
return R.ok(workflowService.search(req.getTitle(), req.getIsPublic(),
|
||||
req.getIsEnable(), currentPage, pageSize));
|
||||
}
|
||||
|
||||
@PostMapping("/enable")
|
||||
public R enable(@RequestParam String uuid, @RequestParam Boolean isEnable) {
|
||||
workflowService.enable(uuid, isEnable);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user