From f23bc049bc89d4ad2704883132e52a179d7a7be0 Mon Sep 17 00:00:00 2001 From: sige Date: Wed, 10 Apr 2024 16:06:04 +0800 Subject: [PATCH] 1 --- .../controller/DigestionTaskController.java | 67 ++++++++++++++++++++++ .../digester/web/DigestionTaskController.java | 67 ---------------------- 2 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 src/main/java/com/iflytop/digester/controller/DigestionTaskController.java delete mode 100644 src/main/java/com/iflytop/digester/web/DigestionTaskController.java diff --git a/src/main/java/com/iflytop/digester/controller/DigestionTaskController.java b/src/main/java/com/iflytop/digester/controller/DigestionTaskController.java new file mode 100644 index 0000000..8d94a18 --- /dev/null +++ b/src/main/java/com/iflytop/digester/controller/DigestionTaskController.java @@ -0,0 +1,67 @@ +package com.iflytop.digester.controller; +import com.iflytop.digester.model.MdbDigestionTask; +import com.iflytop.digester.DigestionTaskTheadManager; +import com.iflytop.digester.model.MdbDigestionSolution; +import com.iflytop.digester.underframework.dao.record.UfActiveRecord; +import com.iflytop.digester.underframework.util.UfJsonHelper; +import com.iflytop.digester.underframework.web.api.UfApiControllerBase; +import com.iflytop.digester.underframework.web.api.UfApiResponse; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseBody; +import java.util.List; +import java.util.Map; +@Controller +public class DigestionTaskController extends UfApiControllerBase { + @Resource + private DigestionTaskTheadManager taskManager; + + @ResponseBody + @PostMapping("/api/digestion-task/start") + public UfApiResponse start(@RequestBody Map params) { + String taskId = (String)params.get("taskId"); + String name = (String)params.get("name"); + String batchNo = (String)params.get("batchNo"); + List> tubes = (List>)params.get("tubes"); + + var digestion = UfActiveRecord.findOne(MdbDigestionSolution.class, Map.of("name", name)); + if ( null == digestion ) { + return this.error("无效的消解配方名称:" + name); + } + + var task = new MdbDigestionTask(); + task.digestionId = digestion.id; + task.outTaskId = taskId; + task.batchNo = batchNo; + task.tubes = UfJsonHelper.objectToJson(tubes); + task.status = "pending"; + task.message = "等待中"; + task.startedAt = (int)(System.currentTimeMillis() / 1000); + task.startedBy = 0; + task.save(); + + this.taskManager.startTask(task); + return this.success(); + } + + @ResponseBody + @PostMapping("/api/digestion-task/exec-action") + public UfApiResponse executeAction( @RequestBody Map params ) { + String taskId = (String)params.get("taskId"); + var task = this.taskManager.getTaskByOutTaskId(taskId); + if ( null == task ) { + return this.error("无效的任务编号:" + taskId); + } + + String action = (String)params.get("action"); + Map actionParams = (Map)params.get("params"); + try { + task.executeAction(action, actionParams); + return this.success(); + } catch ( Exception e ) { + return this.error(e.getMessage()); + } + } +} diff --git a/src/main/java/com/iflytop/digester/web/DigestionTaskController.java b/src/main/java/com/iflytop/digester/web/DigestionTaskController.java deleted file mode 100644 index eaa95ed..0000000 --- a/src/main/java/com/iflytop/digester/web/DigestionTaskController.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.iflytop.digester.web; -import com.iflytop.digester.model.MdbDigestionTask; -import com.iflytop.digester.DigestionTaskTheadManager; -import com.iflytop.digester.model.MdbDigestionSolution; -import com.iflytop.digester.underframework.dao.record.UfActiveRecord; -import com.iflytop.digester.underframework.util.UfJsonHelper; -import com.iflytop.digester.underframework.web.api.UfApiControllerBase; -import com.iflytop.digester.underframework.web.api.UfApiResponse; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.ResponseBody; -import java.util.List; -import java.util.Map; -@Controller -public class DigestionTaskController extends UfApiControllerBase { - @Resource - private DigestionTaskTheadManager taskManager; - - @ResponseBody - @PostMapping("/api/digestion-task/start") - public UfApiResponse start(@RequestBody Map params) { - String taskId = (String)params.get("taskId"); - String name = (String)params.get("name"); - String batchNo = (String)params.get("batchNo"); - List> tubes = (List>)params.get("tubes"); - - var digestion = UfActiveRecord.findOne(MdbDigestionSolution.class, Map.of("name", name)); - if ( null == digestion ) { - return this.error("无效的消解配方名称:" + name); - } - - var task = new MdbDigestionTask(); - task.digestionId = digestion.id; - task.outTaskId = taskId; - task.batchNo = batchNo; - task.tubes = UfJsonHelper.objectToJson(tubes); - task.status = "pending"; - task.message = "等待中"; - task.startedAt = (int)(System.currentTimeMillis() / 1000); - task.startedBy = 0; - task.save(); - - this.taskManager.startTask(task); - return this.success(); - } - - @ResponseBody - @PostMapping("/api/digestion-task/exec-action") - public UfApiResponse executeAction( @RequestBody Map params ) { - String taskId = (String)params.get("taskId"); - var task = this.taskManager.getTaskByOutTaskId(taskId); - if ( null == task ) { - return this.error("无效的任务编号:" + taskId); - } - - String action = (String)params.get("action"); - Map actionParams = (Map)params.get("params"); - try { - task.executeAction(action, actionParams); - return this.success(); - } catch ( Exception e ) { - return this.error(e.getMessage()); - } - } -}