|
@@ -0,0 +1,75 @@
|
|
|
|
|
+package cn.iocoder.byzs.module.bpm.controller.admin.courseAuto;
|
|
|
|
|
+
|
|
|
|
|
+import cn.iocoder.byzs.module.bpm.controller.admin.courseAuto.vo.CompleteEditRequest;
|
|
|
|
|
+import cn.iocoder.byzs.module.bpm.controller.admin.courseAuto.vo.CourseFlowRequest;
|
|
|
|
|
+import org.flowable.engine.RuntimeService;
|
|
|
|
|
+import org.flowable.engine.TaskService;
|
|
|
|
|
+import org.flowable.engine.runtime.Execution;
|
|
|
|
|
+import org.flowable.engine.runtime.ProcessInstance;
|
|
|
|
|
+import org.flowable.task.api.Task;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/api/flow")
|
|
|
|
|
+public class CourseFlowController {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RuntimeService runtimeService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TaskService taskService;
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 启动流程(用户输入触发语+选择数字人)
|
|
|
|
|
+ @PostMapping("/start")
|
|
|
|
|
+ public String startProcess(@RequestBody CourseFlowRequest request) {
|
|
|
|
|
+ Map<String, Object> variables = new HashMap<>();
|
|
|
|
|
+ variables.put("triggerText", request.getTriggerText());
|
|
|
|
|
+ variables.put("mainSpeaker", request.getMainSpeaker());
|
|
|
|
|
+ variables.put("sideSpeakers", request.getSideSpeakers());
|
|
|
|
|
+ variables.put("userId", request.getCurrentUserId()); // 当前用户ID
|
|
|
|
|
+
|
|
|
|
|
+ // 启动流程(流程标识为 courseAuto,与截图中一致)
|
|
|
|
|
+ ProcessInstance pi = runtimeService.startProcessInstanceByKey("courseAuto", variables);
|
|
|
|
|
+ return pi.getId(); // 返回流程实例ID,供前端查询状态
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 查询待办任务(前端编辑脚本)
|
|
|
|
|
+ @GetMapping("/todo-tasks")
|
|
|
|
|
+ public List<Task> getTodoTasks(@RequestParam String userId) {
|
|
|
|
|
+ return taskService.createTaskQuery()
|
|
|
|
|
+ .taskAssignee(userId)
|
|
|
|
|
+ .processDefinitionKey("courseAuto")
|
|
|
|
|
+ .list();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 完成编辑任务(提交编辑后的脚本)
|
|
|
|
|
+ @PostMapping("/complete-edit")
|
|
|
|
|
+ public void completeEditTask(@RequestBody CompleteEditRequest request) {
|
|
|
|
|
+ Map<String, Object> variables = new HashMap<>();
|
|
|
|
|
+ variables.put("editedScriptJson", request.getEditedScriptJson());
|
|
|
|
|
+ taskService.complete(request.getTaskId(), variables);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 查询流程状态
|
|
|
|
|
+ @GetMapping("/status/{processInstanceId}")
|
|
|
|
|
+ public String getProcessStatus(@PathVariable String processInstanceId) {
|
|
|
|
|
+ Execution execution = runtimeService.createExecutionQuery()
|
|
|
|
|
+ .processInstanceId(processInstanceId)
|
|
|
|
|
+ .singleResult();
|
|
|
|
|
+ if (execution == null) return "流程已结束";
|
|
|
|
|
+
|
|
|
|
|
+ String activityId = execution.getActivityId();
|
|
|
|
|
+ // 映射活动ID到阶段名称
|
|
|
|
|
+ return switch (activityId) {
|
|
|
|
|
+ case "generateScriptTask" -> "生成脚本中";
|
|
|
|
|
+ case "editScriptTask" -> "待编辑脚本";
|
|
|
|
|
+ case "generateImageMusicTask" -> "生成背景图/音乐中";
|
|
|
|
|
+ case "generateVoiceTask" -> "生成语音中";
|
|
|
|
|
+ case "saveToDbTask" -> "保存入库中";
|
|
|
|
|
+ default -> "处理中";
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+}
|