|
|
@ -21,31 +21,30 @@ public class UfCmdSnippetExecutor { |
|
|
|
|
|
|
|
/** |
|
|
|
* execute snippet |
|
|
|
* @param snippetName - snippet name |
|
|
|
* @param snippetKey - snippet key |
|
|
|
*/ |
|
|
|
static public void execute(String snippetName) { |
|
|
|
UfCmdSnippetExecutor.execute(snippetName, new HashMap<>()); |
|
|
|
static public void execute(String snippetKey) { |
|
|
|
UfCmdSnippetExecutor.execute(snippetKey, new HashMap<>()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* execute snippet with params |
|
|
|
* @param snippetName - snippet name |
|
|
|
* @param snippetKey - snippet name |
|
|
|
* @param params - params |
|
|
|
*/ |
|
|
|
static public void execute(String snippetName, Map<String, Object> params) { |
|
|
|
static public void execute(String snippetKey, Map<String, Object> params) { |
|
|
|
Boolean logEnabled = UfApplication.getApp().getEnv().getProperty("device.snippet-execute-log-enable", Boolean.class); |
|
|
|
if ( Boolean.TRUE.equals(logEnabled) ) { |
|
|
|
LOG.info("[Snippet Execute] : {} ({})", snippetName, UfJsonHelper.objectToJson(params)); |
|
|
|
LOG.info("[Snippet Execute] : {} ({})", snippetKey, UfJsonHelper.objectToJson(params)); |
|
|
|
} |
|
|
|
|
|
|
|
var snippet = UfActiveRecord.findOne(UfMdbSnippet.class, Map.of("key", snippetKey)); |
|
|
|
if (null == snippet) { |
|
|
|
throw new RuntimeException("无效的片段KEY : " + snippetKey); |
|
|
|
} |
|
|
|
|
|
|
|
// var snippet = UfActiveRecord.findOne(UfMdbSnippet.class, Map.of("key", snippetName)); |
|
|
|
// if (null == snippet) { |
|
|
|
// throw new RuntimeException("无效的片段名称 : " + snippetName); |
|
|
|
// } |
|
|
|
// |
|
|
|
// var executor = new UfCmdSnippetExecutor(snippet, params); |
|
|
|
// executor.run(); |
|
|
|
var executor = new UfCmdSnippetExecutor(snippet, params); |
|
|
|
executor.run(); |
|
|
|
} |
|
|
|
|
|
|
|
// constructor |
|
|
@ -66,13 +65,18 @@ public class UfCmdSnippetExecutor { |
|
|
|
|
|
|
|
for ( JsonNode cmdNode : cmdsJsonTree ) { |
|
|
|
var cmdId = cmdNode.get("cmdId").asText(); |
|
|
|
var cmd = UfActiveRecord.findOne(UfMdbActuatorCmd.class, cmdId); |
|
|
|
if (null == cmd) { |
|
|
|
throw new RuntimeException("无效的指令ID : " + cmdId); |
|
|
|
} |
|
|
|
var cmdParams = cmdNode.get("params").asText(); |
|
|
|
this.executeStep(cmdId, cmdParams); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cmd.parameters = cmdNode.get("params").asText(); |
|
|
|
UfActuatorCmdExecutor.execute(cmd); |
|
|
|
// execute step |
|
|
|
public void executeStep(String cmdId, String cmdParams) { |
|
|
|
var cmd = UfActiveRecord.findOne(UfMdbActuatorCmd.class, cmdId); |
|
|
|
if (null == cmd) { |
|
|
|
throw new RuntimeException("无效的指令ID : " + cmdId); |
|
|
|
} |
|
|
|
cmd.parameters = cmdParams; |
|
|
|
UfActuatorCmdExecutor.execute(cmd); |
|
|
|
} |
|
|
|
} |