Commit 795e06bc8fc1ae36d93e8e2e9dd41be7f4c019e7
1 parent
8fac009d
【功能修复】IoT:插件还是考虑支持多租户,因此需要忽略部分场景下的租户,避免报错
Showing
4 changed files
with
15 additions
and
9 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginConfigDO.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.dal.dataobject.plugin; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; | |
| 5 | 5 | import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginDeployTypeEnum; |
| 6 | -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; | |
| 7 | 6 | import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginTypeEnum; |
| 8 | 7 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 9 | 8 | import com.baomidou.mybatisplus.annotation.TableId; |
| ... | ... | @@ -23,7 +22,7 @@ import lombok.*; |
| 23 | 22 | @Builder |
| 24 | 23 | @NoArgsConstructor |
| 25 | 24 | @AllArgsConstructor |
| 26 | -public class IotPluginConfigDO extends BaseDO { | |
| 25 | +public class IotPluginConfigDO extends TenantBaseDO { | |
| 27 | 26 | |
| 28 | 27 | /** |
| 29 | 28 | * 主键 ID | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginInstanceDO.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.dal.dataobject.plugin; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 3 | +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; | |
| 4 | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| ... | ... | @@ -21,7 +21,7 @@ import java.time.LocalDateTime; |
| 21 | 21 | @Builder |
| 22 | 22 | @NoArgsConstructor |
| 23 | 23 | @AllArgsConstructor |
| 24 | -public class IotPluginInstanceDO extends BaseDO { | |
| 24 | +public class IotPluginInstanceDO extends TenantBaseDO { | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * 主键 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/plugin/IotPluginInstancesJob.java
| ... | ... | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.iot.job.plugin; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; |
| 5 | +import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; | |
| 5 | 6 | import cn.iocoder.yudao.module.iot.service.plugin.IotPluginInstanceService; |
| 6 | 7 | import org.springframework.stereotype.Component; |
| 7 | 8 | |
| ... | ... | @@ -28,6 +29,7 @@ public class IotPluginInstancesJob implements JobHandler { |
| 28 | 29 | private IotPluginInstanceService pluginInstanceService; |
| 29 | 30 | |
| 30 | 31 | @Override |
| 32 | + @TenantJob | |
| 31 | 33 | public String execute(String param) { |
| 32 | 34 | int count = pluginInstanceService.offlineTimeoutPluginInstance( |
| 33 | 35 | LocalDateTime.now().minus(OFFLINE_TIMEOUT)); | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.iot.service.plugin; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.io.FileUtil; |
| 5 | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | +import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | |
| 6 | 7 | import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotPluginInstanceHeartbeatReqDTO; |
| 7 | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginConfigDO; |
| 8 | 9 | import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginInstanceDO; |
| ... | ... | @@ -62,7 +63,8 @@ public class IotPluginInstanceServiceImpl implements IotPluginInstanceService { |
| 62 | 63 | @Override |
| 63 | 64 | public void heartbeatPluginInstance(IotPluginInstanceHeartbeatReqDTO heartbeatReqDTO) { |
| 64 | 65 | // 情况一:已存在,则进行更新 |
| 65 | - IotPluginInstanceDO instance = pluginInstanceMapper.selectByProcessId(heartbeatReqDTO.getProcessId()); | |
| 66 | + IotPluginInstanceDO instance = TenantUtils.executeIgnore( | |
| 67 | + () -> pluginInstanceMapper.selectByProcessId(heartbeatReqDTO.getProcessId())); | |
| 66 | 68 | if (instance != null) { |
| 67 | 69 | IotPluginInstanceDO.IotPluginInstanceDOBuilder updateObj = IotPluginInstanceDO.builder().id(instance.getId()) |
| 68 | 70 | .hostIp(heartbeatReqDTO.getHostIp()).downstreamPort(heartbeatReqDTO.getDownstreamPort()) |
| ... | ... | @@ -74,12 +76,14 @@ public class IotPluginInstanceServiceImpl implements IotPluginInstanceService { |
| 74 | 76 | } else { |
| 75 | 77 | updateObj.offlineTime(LocalDateTime.now()); |
| 76 | 78 | } |
| 77 | - pluginInstanceMapper.updateById(updateObj.build()); | |
| 79 | + TenantUtils.execute(instance.getTenantId(), | |
| 80 | + () -> pluginInstanceMapper.updateById(updateObj.build())); | |
| 78 | 81 | return; |
| 79 | 82 | } |
| 80 | 83 | |
| 81 | 84 | // 情况二:不存在,则创建 |
| 82 | - IotPluginConfigDO info = pluginConfigService.getPluginConfigByPluginKey(heartbeatReqDTO.getPluginKey()); | |
| 85 | + IotPluginConfigDO info = TenantUtils.executeIgnore( | |
| 86 | + () -> pluginConfigService.getPluginConfigByPluginKey(heartbeatReqDTO.getPluginKey())); | |
| 83 | 87 | if (info == null) { |
| 84 | 88 | log.error("[heartbeatPluginInstance][心跳({}) 对应的插件不存在]", heartbeatReqDTO); |
| 85 | 89 | return; |
| ... | ... | @@ -93,7 +97,8 @@ public class IotPluginInstanceServiceImpl implements IotPluginInstanceService { |
| 93 | 97 | } else { |
| 94 | 98 | insertObj.offlineTime(LocalDateTime.now()); |
| 95 | 99 | } |
| 96 | - pluginInstanceMapper.insert(insertObj.build()); | |
| 100 | + TenantUtils.execute(info.getTenantId(), | |
| 101 | + () -> pluginInstanceMapper.insert(insertObj.build())); | |
| 97 | 102 | } |
| 98 | 103 | |
| 99 | 104 | @Override | ... | ... |