fix: 单独执行时,scriptEngine为null的bug

V0.5.x
gaoyoulong 2024-03-01 16:06:29 +08:00
parent b412eec2a8
commit 53b13b0b3a
1 changed files with 6 additions and 0 deletions

View File

@ -130,6 +130,12 @@ public class VirtualManager {
.build();
try {
IScriptEngine scriptEngine = virtualScripts.get(virtualDevice.getId());
if ( null == scriptEngine ) {
//添加新的脚本对象
scriptEngine = ScriptEngineFactory.getScriptEngine("js");
scriptEngine.setScript(virtualDevice.getScript());
virtualScripts.put(virtualDevice.getId(), scriptEngine);
}
for (String deviceId : devices) {
DeviceInfo device = deviceInfoData.findByDeviceId(deviceId);
processReport(scriptEngine.invokeMethod(new TypeReference<>() {