|
|
@ -2,10 +2,13 @@ package com.iflytop.digester; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.iflytop.digester.model.MdbDigestionSolution; |
|
|
|
import com.iflytop.digester.model.MdbDigestionTask; |
|
|
|
import com.iflytop.digester.model.MdbOperationLog; |
|
|
|
import com.iflytop.digester.model.MdbRuntimeLog; |
|
|
|
import com.iflytop.digester.underframework.dao.model.UfMdbNotification; |
|
|
|
import com.iflytop.digester.underframework.dao.model.UfMdbOption; |
|
|
|
import com.iflytop.digester.underframework.dao.record.UfActiveRecord; |
|
|
|
import com.iflytop.digester.underframework.util.UfJsonHelper; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import org.eclipse.paho.client.mqttv3.*; |
|
|
@ -91,11 +94,16 @@ public class DigestionTaskTheadManager { |
|
|
|
actionJsonTree = jsonMapper.readTree(content); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
// ignore invalid message |
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
assert actionJsonTree != null; |
|
|
|
String taskId = actionJsonTree.get("taskId").asText(); |
|
|
|
String actionName = actionJsonTree.get("action").asText(); |
|
|
|
if ( "StartNewDigestion".equals(actionName) ) { |
|
|
|
this.startNewDigestion(actionJsonTree.get("params")); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Object> actionParams = new HashMap<>(); |
|
|
|
if ( actionJsonTree.has("params") ) { |
|
|
|
var paramsJsonTree = actionJsonTree.get("params"); |
|
|
@ -104,6 +112,7 @@ public class DigestionTaskTheadManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String taskId = actionJsonTree.get("taskId").asText(); |
|
|
|
DigestionTaskThread task = null; |
|
|
|
for ( var t : this.tasks ) { |
|
|
|
if ( t.getOutTaskId().equals(taskId) ) { |
|
|
@ -118,6 +127,39 @@ public class DigestionTaskTheadManager { |
|
|
|
task.executeAction(actionName, actionParams); |
|
|
|
} |
|
|
|
|
|
|
|
// start new digestion |
|
|
|
private void startNewDigestion( JsonNode params ) { |
|
|
|
String taskId = params.get("taskId").asText(); |
|
|
|
String name = params.get("name").asText(); |
|
|
|
String batchNo = params.get("batchNo").asText(); |
|
|
|
List<Map<String,Object>> tubes = new ArrayList<>(); |
|
|
|
for ( JsonNode node : params.get("tubes") ) { |
|
|
|
Map<String, Object> tube = new HashMap<>(); |
|
|
|
tube.put("no", node.get("no").asText()); |
|
|
|
tubes.add(tube); |
|
|
|
} |
|
|
|
|
|
|
|
var digestion = UfActiveRecord.findOne(MdbDigestionSolution.class, Map.of("name", name)); |
|
|
|
if ( null == digestion ) { |
|
|
|
MdbRuntimeLog.log("DigestionTaskMqttMessage", "无效的消解配方名称 : %s", name); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
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 = ""; |
|
|
|
task.mode = "auto"; |
|
|
|
task.save(); |
|
|
|
|
|
|
|
this.startTask(task); |
|
|
|
} |
|
|
|
|
|
|
|
// Send message to trans bot |
|
|
|
public void sendMessageToTransBot(String action, Map<String, Object> params) { |
|
|
|
String myTopic = UfMdbOption.getString("DigestionTaskMqttMyTopic", ""); |
|
|
|