fix:插件脚本引擎获取修改

V0.5.x
xiwa 2023-10-30 08:39:59 +08:00
parent baea6416f4
commit 723585f47c
3 changed files with 8 additions and 9 deletions

View File

@ -92,7 +92,10 @@ public class PluginServiceImpl implements IPluginService {
log.info("script:{}", script);
}
plugin.setState(PluginInfo.STATE_STOPPED);
PluginState pluginState = pluginInfo.getPluginState();
if (pluginState == PluginState.STARTED) {
plugin.setState(PluginInfo.STATE_RUNNING);
}
plugin.setPluginId(pluginInfo.getPluginId());
plugin.setFile(file.getOriginalFilename());
plugin.setConfigSchema(configJson);
@ -102,9 +105,6 @@ public class PluginServiceImpl implements IPluginService {
plugin.setVersion(pluginDescriptor.getPluginVersion());
plugin.setDescription(pluginDescriptor.getDescription());
pluginInfoData.save(plugin);
//默认停止
pluginOperator.stop(pluginId);
} catch (Exception e) {
throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED, e);
}

View File

@ -67,17 +67,13 @@ public class PluginMainImpl implements IPluginMain, DeviceService {
@Autowired
private MqProducer<ThingModelMessage> producer;
private static final Map<String, IScriptEngine> SCRIPT_ENGINE_MAP = new HashMap<>();
public IScriptEngine initScriptEngine(String pluginId) {
PluginInfo pluginInfo = pluginInfoData.findByPluginId(pluginId);
if (pluginInfo == null) {
SCRIPT_ENGINE_MAP.put(pluginId, null);
return null;
}
String script = pluginInfo.getScript();
if (StringUtils.isBlank(script)) {
SCRIPT_ENGINE_MAP.put(pluginId, null);
return null;
}
@ -88,7 +84,7 @@ public class PluginMainImpl implements IPluginMain, DeviceService {
@Override
public IScriptEngine getScriptEngine(String pluginId) {
return SCRIPT_ENGINE_MAP.put(pluginId, initScriptEngine(pluginId));
return initScriptEngine(pluginId);
}
@Override

View File

@ -155,6 +155,9 @@ public class ThingServiceImpl implements IThingService {
if (device != null) {
log.info("device already registered");
device.setModel(register.getModel());
device.setProductKey(register.getProductKey());
device.setSecret(RandomStringUtils.randomAlphabetic(16));
deviceInfoData.save(device);
} else {
//不存在,注册新设备
device = new DeviceInfo();