diff --git a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowiseController.java b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowiseController.java index c2700a2..871492f 100644 --- a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowiseController.java +++ b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowiseController.java @@ -1,14 +1,22 @@ package com.cmvr.web.controller.test; +import com.alibaba.fastjson2.JSONObject; import com.cmvr.common.core.controller.BaseController; import com.cmvr.common.core.domain.AjaxResult; +import com.cmvr.test.flow.control.FlowControlService; +import com.cmvr.test.flow.runtime.engine.FlowTaskRuntimeService; +import com.cmvr.test.flow.runtime.operator.edge.ti.TiTouchOperateService; import com.cmvr.test.model.vo.FlowiseActionRequestVO; import com.cmvr.test.model.vo.FlowiseChatRequestVO; import com.cmvr.test.model.vo.FlowiseStartRequestVO; +import com.cmvr.test.model.vo.TeTaskExecuteNormalVO; +import com.cmvr.test.service.FlowActionExecutorService; import com.cmvr.test.service.FlowiseActionService; +import com.google.gson.JsonObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -16,6 +24,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; +import java.util.List; + @Api(tags = "测试--flowise服务") @RestController @RequestMapping("/flowise") @@ -23,11 +34,37 @@ import org.springframework.web.bind.annotation.RestController; public class TeFlowiseController extends BaseController { private final FlowiseActionService flowiseActionService; + private final FlowTaskRuntimeService flowTaskRuntimeService; + private final FlowControlService flowControlService; + private final FlowActionExecutorService flowActionExecutorService; + private final TiTouchOperateService tiTouchOperateService; + private final List taskInstIdList = new ArrayList<>(); @ApiOperation("调用flowise") @PostMapping("/start") public AjaxResult start(@RequestBody FlowiseStartRequestVO request) { - return AjaxResult.ok(flowiseActionService.start(request)); + TeTaskExecuteNormalVO taskExecuteNormalVO = new TeTaskExecuteNormalVO(); + + JSONObject runParams = new JSONObject(); + runParams.put("5bb26d52e1861c6936f3c3149eaf17e8", new JsonObject()); + runParams.getJSONObject("5bb26d52e1861c6936f3c3149eaf17e8").put("test", request.getQuestion()); + + taskExecuteNormalVO.builder() + .taskId("b6ab5ffff783d9b25d0dc34f13be222d") + .terminalId("18749f257ff902643bc1ea6ab33f8b04") + .runParams(JSONObject.from(runParams)); + if (!taskInstIdList.isEmpty()) { + try { + taskInstIdList.forEach(flowControlService::stop); + } catch (Exception e) { + // 忽略 + } + taskInstIdList.clear(); + } + String insId = flowTaskRuntimeService.executeTask(taskExecuteNormalVO); + taskInstIdList.add(insId); + return AjaxResult.success(); +// return AjaxResult.ok(flowiseActionService.start(request)); } @ApiOperation("根据chatId查询执行结果") @@ -39,7 +76,16 @@ public class TeFlowiseController extends BaseController { @ApiOperation("终止flowise") @GetMapping("/abort") public AjaxResult abort() { - return AjaxResult.ok(flowiseActionService.abort()); + if (!taskInstIdList.isEmpty()) { + try { + taskInstIdList.forEach(flowControlService::stop); + } catch (Exception e) { + // 忽略 + } + taskInstIdList.clear(); + } + return AjaxResult.success(); +// return AjaxResult.ok(flowiseActionService.abort()); } @ApiOperation("执行指令") diff --git a/cmvr-iot-inspection/src/main/java/com/cmvr/inspection/domain/dto/InspectionTaskInstanceQuery.java b/cmvr-iot-inspection/src/main/java/com/cmvr/inspection/domain/dto/InspectionTaskInstanceQuery.java index 36807f4..0ddd38e 100644 --- a/cmvr-iot-inspection/src/main/java/com/cmvr/inspection/domain/dto/InspectionTaskInstanceQuery.java +++ b/cmvr-iot-inspection/src/main/java/com/cmvr/inspection/domain/dto/InspectionTaskInstanceQuery.java @@ -25,4 +25,7 @@ public class InspectionTaskInstanceQuery { @ApiModelProperty("多状态集合,in查询用:0待执行 1执行中 2已完成 3已取消 4执行失败 5已暂停") private List statusList; + @ApiModelProperty("任务类型") + private String taskType; + } \ No newline at end of file diff --git a/cmvr-iot-inspection/src/main/resources/mapper/inspection/InspectionRobotMapper.xml b/cmvr-iot-inspection/src/main/resources/mapper/inspection/InspectionRobotMapper.xml index 6808884..552a937 100644 --- a/cmvr-iot-inspection/src/main/resources/mapper/inspection/InspectionRobotMapper.xml +++ b/cmvr-iot-inspection/src/main/resources/mapper/inspection/InspectionRobotMapper.xml @@ -39,6 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -150,7 +151,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" r.ip_address, r.port, r.current_map_id, m.map_name as current_map_name, r.status, r.battery_level, r.current_position, r.terminal_id, - u1.nick_name as create_by_name, u2.nick_name as update_by_name + u1.nick_name as create_by_name, u2.nick_name as update_by_name, m.map_source_name as robot_map_name from inspection_robot r left join inspection_map m on r.current_map_id = m.id left join sys_user u1 on r.create_by = u1.user_name diff --git a/cmvr-iot-inspection/src/main/resources/mapper/inspection/InspectionTaskInstanceMapper.xml b/cmvr-iot-inspection/src/main/resources/mapper/inspection/InspectionTaskInstanceMapper.xml index 2e43e2f..8b2aad8 100644 --- a/cmvr-iot-inspection/src/main/resources/mapper/inspection/InspectionTaskInstanceMapper.xml +++ b/cmvr-iot-inspection/src/main/resources/mapper/inspection/InspectionTaskInstanceMapper.xml @@ -157,6 +157,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and ti.status = #{status} + + + and t.task_type = #{taskType} + order by ti.create_time desc