Commit 628c028c86e5d32fb814ba88d93882e3e738bc29
Merge branch '2023-12-28' into 'master_dev'
fix:任务中心产品类任务未含组织过滤 See merge request yunteng/thingskit!304
Showing
5 changed files
with
24 additions
and
13 deletions
... | ... | @@ -115,7 +115,7 @@ public class RpcCommandTask { |
115 | 115 | } |
116 | 116 | } else { |
117 | 117 | sendRpcCommandByProducts( |
118 | - targetContent, cmdJsonNode, tenantId, securityUser, taskCenterId); | |
118 | + targetContent, cmdJsonNode, tenantId, securityUser, taskCenterId,targetContent.getOrganizationId()); | |
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
... | ... | @@ -132,10 +132,11 @@ public class RpcCommandTask { |
132 | 132 | JsonNode cmdJsonNode, |
133 | 133 | String tenantId, |
134 | 134 | SecurityUser securityUser, |
135 | - String taskCenterId) { | |
135 | + String taskCenterId, | |
136 | + String organizationId) { | |
136 | 137 | for (String deviceProfileId : targetContent.getData()) { |
137 | 138 | Futures.addCallback( |
138 | - tkDeviceService.findDeviceListByDeviceProfileId(deviceProfileId, tenantId), | |
139 | + tkDeviceService.findDeviceListByDeviceProfileId(deviceProfileId, tenantId,organizationId), | |
139 | 140 | new FutureCallback<>() { |
140 | 141 | @Override |
141 | 142 | public void onSuccess(@Nullable List<DeviceDTO> deviceDTOS) { | ... | ... |
... | ... | @@ -777,16 +777,19 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev |
777 | 777 | |
778 | 778 | @Override |
779 | 779 | public ListenableFuture<List<DeviceDTO>> findDeviceListByDeviceProfileId( |
780 | - String deviceProfileId, String tenantId) { | |
780 | + String deviceProfileId, String tenantId,String organizationId) { | |
781 | 781 | if (StringUtils.isEmpty(deviceProfileId) || StringUtils.isEmpty(tenantId)) { |
782 | 782 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
783 | 783 | } |
784 | + | |
785 | + List<String> orgIds = organizationService.organizationAllIds(tenantId, organizationId); | |
784 | 786 | List<DeviceDTO> devices = new ArrayList<>(); |
785 | 787 | List<TkDeviceEntity> entityList = |
786 | 788 | baseMapper.selectList( |
787 | 789 | new LambdaQueryWrapper<TkDeviceEntity>() |
788 | 790 | .eq(TkDeviceEntity::getTenantId, tenantId) |
789 | - .eq(TkDeviceEntity::getDeviceProfileId, deviceProfileId)); | |
791 | + .eq(TkDeviceEntity::getDeviceProfileId, deviceProfileId) | |
792 | + .in(!orgIds.isEmpty(),TkDeviceEntity::getOrganizationId, orgIds)); | |
790 | 793 | return Optional.ofNullable(entityList) |
791 | 794 | .map( |
792 | 795 | list -> |
... | ... | @@ -798,15 +801,20 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev |
798 | 801 | } |
799 | 802 | |
800 | 803 | @Override |
801 | - public List<String> findTbDeviceIdsByDeviceProfileId(String deviceProfileId, String tenantId) { | |
804 | + public List<String>findTbDeviceIdsByDeviceProfileId(String deviceProfileId, String tenantId,String organizationId) { | |
802 | 805 | if (StringUtils.isEmpty(deviceProfileId) || StringUtils.isEmpty(tenantId)) { |
803 | 806 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
804 | 807 | } |
808 | + List<String> orgIds = null; | |
809 | + if(!StringUtils.isEmpty(organizationId)){ | |
810 | + orgIds = organizationService.organizationAllIds(tenantId, organizationId); | |
811 | + } | |
805 | 812 | return Optional.ofNullable( |
806 | 813 | baseMapper.selectList( |
807 | 814 | new LambdaQueryWrapper<TkDeviceEntity>() |
808 | 815 | .eq(TkDeviceEntity::getTenantId, tenantId) |
809 | 816 | .eq(TkDeviceEntity::getDeviceProfileId, deviceProfileId) |
817 | + .in(!orgIds.isEmpty(),TkDeviceEntity::getOrganizationId, orgIds) | |
810 | 818 | .select(TkDeviceEntity::getTbDeviceId))) |
811 | 819 | .map(list -> list.stream().map(TkDeviceEntity::getTbDeviceId).collect(Collectors.toList())) |
812 | 820 | .orElse(null); | ... | ... |
... | ... | @@ -127,7 +127,9 @@ public class TkTaskCenterServiceImpl |
127 | 127 | baseMapper.updateById(entity); |
128 | 128 | updateTaskCenterCache(entity); |
129 | 129 | } |
130 | - saveOrUpdateDeviceTaskCenter(entity, isUpdate); | |
130 | + String organizationId = tkTaskCenterDTO.getExecuteTarget() !=null? | |
131 | + tkTaskCenterDTO.getExecuteTarget().getOrganizationId():null; | |
132 | + saveOrUpdateDeviceTaskCenter(entity, isUpdate,organizationId); | |
131 | 133 | return tkTaskCenterDTO; |
132 | 134 | } |
133 | 135 | |
... | ... | @@ -345,7 +347,7 @@ public class TkTaskCenterServiceImpl |
345 | 347 | } |
346 | 348 | } |
347 | 349 | |
348 | - private void saveOrUpdateDeviceTaskCenter(TkTaskCenterEntity entity, boolean isUpdate) { | |
350 | + private void saveOrUpdateDeviceTaskCenter(TkTaskCenterEntity entity, boolean isUpdate,String organizationId) { | |
349 | 351 | String taskCenterId = entity.getId(); |
350 | 352 | String tenantId = entity.getTenantId(); |
351 | 353 | // 判断是按产品执行还是按设备执行 |
... | ... | @@ -357,7 +359,7 @@ public class TkTaskCenterServiceImpl |
357 | 359 | processDeviceTaskCenterMapping(isUpdate, tenantId, taskCenterId, data); |
358 | 360 | } else { |
359 | 361 | for (String key : data) { |
360 | - List<String> tbDeviceIds = tkDeviceService.findTbDeviceIdsByDeviceProfileId(key, tenantId); | |
362 | + List<String> tbDeviceIds = tkDeviceService.findTbDeviceIdsByDeviceProfileId(key, tenantId,organizationId); | |
361 | 363 | processDeviceTaskCenterMapping(isUpdate, tenantId, taskCenterId, tbDeviceIds); |
362 | 364 | } |
363 | 365 | } | ... | ... |
... | ... | @@ -224,7 +224,7 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> { |
224 | 224 | */ |
225 | 225 | Map<String, List<String>> getDeviceIdsByDeviceProfileId(String tenantId, String tbDeviceProfileId); |
226 | 226 | |
227 | - ListenableFuture<List<DeviceDTO>> findDeviceListByDeviceProfileId(String deviceProfileId,String tenantId); | |
227 | + ListenableFuture<List<DeviceDTO>> findDeviceListByDeviceProfileId(String deviceProfileId,String tenantId,String organizationId); | |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * 通过设备配置ID查询所有的tbDeviceId |
... | ... | @@ -232,7 +232,7 @@ public interface TkDeviceService extends BaseService<TkDeviceEntity> { |
232 | 232 | * @param tenantId 租户ID |
233 | 233 | * @return id集合 |
234 | 234 | */ |
235 | - List<String> findTbDeviceIdsByDeviceProfileId(String deviceProfileId,String tenantId); | |
235 | + List<String> findTbDeviceIdsByDeviceProfileId(String deviceProfileId,String tenantId,String organizationId); | |
236 | 236 | |
237 | 237 | /** |
238 | 238 | * 根据TB设备ID列表获取设备信息 | ... | ... |
... | ... | @@ -187,7 +187,7 @@ class ReactState { |
187 | 187 | if (ScopeEnum.ALL.equals(entityType)) { |
188 | 188 | trifggerDevices = |
189 | 189 | tkDeviceService.findTbDeviceIdsByDeviceProfileId( |
190 | - tkProjectId, trigger.getTenantId()); | |
190 | + tkProjectId, trigger.getTenantId(),null); | |
191 | 191 | } |
192 | 192 | AtomicReference<String> matchKey = new AtomicReference<>(""); |
193 | 193 | AtomicBoolean matched = new AtomicBoolean(false); |
... | ... | @@ -288,7 +288,7 @@ class ReactState { |
288 | 288 | if (ScopeEnum.ALL.equals(entityType)) { |
289 | 289 | conditionDevices = |
290 | 290 | tkDeviceService.findTbDeviceIdsByDeviceProfileId( |
291 | - tkProjectId, condition.getTenantId()); | |
291 | + tkProjectId, condition.getTenantId(),null); | |
292 | 292 | } |
293 | 293 | AtomicBoolean oneConditionResult = new AtomicBoolean(true); |
294 | 294 | conditionDevices.stream() | ... | ... |