|
@@ -23,7 +23,7 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PLUGIN_INFO_N
|
|
|
/**
|
|
|
* IoT 插件信息 Service 实现类
|
|
|
*
|
|
|
- * @author 芋道源码
|
|
|
+ * @author haohao
|
|
|
*/
|
|
|
@Service
|
|
|
@Validated
|
|
@@ -37,7 +37,7 @@ public class IotPluginInfoServiceImpl implements IotPluginInfoService {
|
|
|
private IotPluginInstanceService pluginInstanceService;
|
|
|
|
|
|
@Resource
|
|
|
- private SpringPluginManager pluginManager;
|
|
|
+ private SpringPluginManager springPluginManager;
|
|
|
|
|
|
@Override
|
|
|
public Long createPluginInfo(PluginInfoSaveReqVO createReqVO) {
|
|
@@ -60,18 +60,17 @@ public class IotPluginInfoServiceImpl implements IotPluginInfoService {
|
|
|
public void deletePluginInfo(Long id) {
|
|
|
// 1.1 校验存在
|
|
|
IotPluginInfoDO pluginInfoDO = validatePluginInfoExists(id);
|
|
|
- // 1.2 停止插件
|
|
|
+ // 1.2 未开启状态,才允许删除
|
|
|
if (IotPluginStatusEnum.RUNNING.getStatus().equals(pluginInfoDO.getStatus())) {
|
|
|
throw exception(PLUGIN_INFO_DELETE_FAILED_RUNNING);
|
|
|
}
|
|
|
|
|
|
- // 2. 卸载插件
|
|
|
+ // 2.1 卸载插件
|
|
|
pluginInstanceService.stopAndUnloadPlugin(pluginInfoDO.getPluginKey());
|
|
|
-
|
|
|
- // 3. 删除插件文件
|
|
|
+ // 2.2 删除插件文件
|
|
|
pluginInstanceService.deletePluginFile(pluginInfoDO);
|
|
|
|
|
|
- // 4. 删除插件信息
|
|
|
+ // 3. 删除插件信息
|
|
|
pluginInfoMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
@@ -97,17 +96,18 @@ public class IotPluginInfoServiceImpl implements IotPluginInfoService {
|
|
|
public void uploadFile(Long id, MultipartFile file) {
|
|
|
// 1. 校验插件信息是否存在
|
|
|
IotPluginInfoDO pluginInfoDo = validatePluginInfoExists(id);
|
|
|
+ // TODO @haohao:最好校验下 file 相关参数,是否完整,类似:version 之类是不是可以解析到
|
|
|
|
|
|
- // 2. 停止并卸载旧的插件
|
|
|
+ // 2.1 停止并卸载旧的插件
|
|
|
pluginInstanceService.stopAndUnloadPlugin(pluginInfoDo.getPluginKey());
|
|
|
-
|
|
|
- // 3 上传新的插件文件,更新插件启用状态文件
|
|
|
+ // 2.2 上传新的插件文件,更新插件启用状态文件
|
|
|
String pluginKeyNew = pluginInstanceService.uploadAndLoadNewPlugin(file);
|
|
|
|
|
|
- // 4. 更新插件信息
|
|
|
+ // 3. 更新插件信息
|
|
|
updatePluginInfo(pluginInfoDo, pluginKeyNew, file);
|
|
|
}
|
|
|
|
|
|
+ // TODO @haohao:这个方法,要不合并到 uploadFile 里;
|
|
|
/**
|
|
|
* 更新插件信息
|
|
|
*
|
|
@@ -116,18 +116,15 @@ public class IotPluginInfoServiceImpl implements IotPluginInfoService {
|
|
|
* @param file 文件
|
|
|
*/
|
|
|
private void updatePluginInfo(IotPluginInfoDO pluginInfoDo, String pluginKeyNew, MultipartFile file) {
|
|
|
- // 创建新的插件信息对象并链式设置属性
|
|
|
IotPluginInfoDO updatedPluginInfo = new IotPluginInfoDO()
|
|
|
.setId(pluginInfoDo.getId())
|
|
|
.setPluginKey(pluginKeyNew)
|
|
|
- .setStatus(IotPluginStatusEnum.STOPPED.getStatus())
|
|
|
+ .setStatus(IotPluginStatusEnum.STOPPED.getStatus()) // TODO @haohao:这个状态,是不是非 stop 哈?
|
|
|
.setFileName(file.getOriginalFilename())
|
|
|
- .setScript("")
|
|
|
- .setConfigSchema(pluginManager.getPlugin(pluginKeyNew).getDescriptor().getPluginDescription())
|
|
|
- .setVersion(pluginManager.getPlugin(pluginKeyNew).getDescriptor().getVersion())
|
|
|
- .setDescription(pluginManager.getPlugin(pluginKeyNew).getDescriptor().getPluginDescription());
|
|
|
-
|
|
|
- // 执行更新
|
|
|
+ .setScript("") // TODO @haohao:这个设置为 "" 会不会覆盖数据里的哈?应该从插件里读取?未来?
|
|
|
+ .setConfigSchema(springPluginManager.getPlugin(pluginKeyNew).getDescriptor().getPluginDescription())
|
|
|
+ .setVersion(springPluginManager.getPlugin(pluginKeyNew).getDescriptor().getVersion())
|
|
|
+ .setDescription(springPluginManager.getPlugin(pluginKeyNew).getDescriptor().getPluginDescription());
|
|
|
pluginInfoMapper.updateById(updatedPluginInfo);
|
|
|
}
|
|
|
|
|
@@ -140,10 +137,7 @@ public class IotPluginInfoServiceImpl implements IotPluginInfoService {
|
|
|
pluginInstanceService.updatePluginStatus(pluginInfoDo, status);
|
|
|
|
|
|
// 3. 更新数据库中的插件状态
|
|
|
- IotPluginInfoDO updatedPluginInfo = new IotPluginInfoDO();
|
|
|
- updatedPluginInfo.setId(id);
|
|
|
- updatedPluginInfo.setStatus(status);
|
|
|
- pluginInfoMapper.updateById(updatedPluginInfo);
|
|
|
+ pluginInfoMapper.updateById(new IotPluginInfoDO().setId(id).setStatus(status));
|
|
|
}
|
|
|
|
|
|
@Override
|