Commit c0e2632b354db5b2f19c6521bab8fbb6e6db9895
Committed by
xp.Huang
1 parent
93ae3575
feat:场景联动选择设备后不允许分配给边端
(cherry picked from commit aec4c32520f7c322dcc3e6550f493ceb3242c633)
Showing
3 changed files
with
31 additions
and
16 deletions
... | ... | @@ -19,6 +19,7 @@ import com.google.common.util.concurrent.ListenableFuture; |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
21 | 21 | import org.springframework.data.domain.Page; |
22 | +import org.springframework.data.domain.PageImpl; | |
22 | 23 | import org.springframework.data.domain.Pageable; |
23 | 24 | import org.springframework.data.jpa.repository.JpaRepository; |
24 | 25 | import org.springframework.stereotype.Component; |
... | ... | @@ -40,12 +41,14 @@ import org.thingsboard.server.common.data.page.PageLink; |
40 | 41 | import org.thingsboard.server.dao.DaoUtil; |
41 | 42 | import org.thingsboard.server.dao.device.DeviceDao; |
42 | 43 | import org.thingsboard.server.dao.model.sql.DeviceEntity; |
44 | +import org.thingsboard.server.dao.model.sql.DeviceInfoEntity; | |
43 | 45 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
44 | 46 | import org.thingsboard.server.dao.util.SqlDao; |
47 | +import org.thingsboard.server.dao.yunteng.service.TkDeviceService; | |
45 | 48 | |
46 | -import java.util.List; | |
47 | -import java.util.Optional; | |
48 | -import java.util.UUID; | |
49 | +import java.lang.reflect.InvocationTargetException; | |
50 | +import java.util.*; | |
51 | +import java.util.concurrent.CopyOnWriteArrayList; | |
49 | 52 | |
50 | 53 | import static org.thingsboard.server.dao.DaoUtil.convertTenantEntityInfosToDto; |
51 | 54 | |
... | ... | @@ -65,6 +68,8 @@ public class JpaDeviceDao extends JpaAbstractDao<DeviceEntity, Device> implement |
65 | 68 | |
66 | 69 | @Autowired |
67 | 70 | private DeviceProfileRepository deviceProfileRepository; |
71 | + @Autowired | |
72 | + TkDeviceService tkDeviceService; | |
68 | 73 | |
69 | 74 | @Override |
70 | 75 | protected Class<DeviceEntity> getEntityClass() { |
... | ... | @@ -107,17 +112,25 @@ public class JpaDeviceDao extends JpaAbstractDao<DeviceEntity, Device> implement |
107 | 112 | |
108 | 113 | @Override |
109 | 114 | public PageData<DeviceInfo> findDeviceInfosByFilter(DeviceInfoFilter filter, PageLink pageLink) { |
110 | - return DaoUtil.toPageData( | |
111 | - deviceRepository.findDeviceInfosByFilter( | |
112 | - filter.getTenantId().getId(), | |
113 | - DaoUtil.getStringId(filter.getCustomerId()), | |
114 | - DaoUtil.getStringId(filter.getEdgeId()), | |
115 | - filter.getType(), | |
116 | - DaoUtil.getStringId(filter.getDeviceProfileId()), | |
117 | - filter.getActive() != null, | |
118 | - Boolean.TRUE.equals(filter.getActive()), | |
119 | - pageLink.getTextSearch(), | |
120 | - DaoUtil.toPageable(pageLink))); | |
115 | + Page<DeviceInfoEntity> list = deviceRepository.findDeviceInfosByFilter( | |
116 | + filter.getTenantId().getId(), | |
117 | + DaoUtil.getStringId(filter.getCustomerId()), | |
118 | + DaoUtil.getStringId(filter.getEdgeId()), | |
119 | + filter.getType(), | |
120 | + DaoUtil.getStringId(filter.getDeviceProfileId()), | |
121 | + filter.getActive() != null, | |
122 | + Boolean.TRUE.equals(filter.getActive()), | |
123 | + pageLink.getTextSearch(), | |
124 | + DaoUtil.toPageable(pageLink)); | |
125 | + List<DeviceInfoEntity> listContent = new CopyOnWriteArrayList<>(list.getContent()); | |
126 | + for (DeviceInfoEntity entity:listContent) { | |
127 | + String result = tkDeviceService.usedBySceneLinkage(entity.getTenantId().toString(), entity.getId().toString()); | |
128 | + if(!result.isEmpty()){ | |
129 | + listContent.remove(entity); | |
130 | + } | |
131 | + } | |
132 | + Page<DeviceInfoEntity> newPage = new PageImpl<>(listContent, DaoUtil.toPageable(pageLink), listContent.size()); | |
133 | + return DaoUtil.toPageData(newPage); | |
121 | 134 | } |
122 | 135 | |
123 | 136 | @Override | ... | ... |
... | ... | @@ -603,8 +603,8 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD |
603 | 603 | return usedBySceneLinkage(tenantId, tbDeviceId.toString()); |
604 | 604 | } |
605 | 605 | |
606 | - @Nullable | |
607 | - private String usedBySceneLinkage(String tenantId, String tbDeviceId) { | |
606 | + @Override | |
607 | + public String usedBySceneLinkage(String tenantId, String tbDeviceId) { | |
608 | 608 | LambdaQueryWrapper<TkSceneLinkageEntity> sceneFilter = |
609 | 609 | new QueryWrapper<TkSceneLinkageEntity>() |
610 | 610 | .lambda() | ... | ... |
... | ... | @@ -286,4 +286,6 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> { |
286 | 286 | * @return true成功 false失败 |
287 | 287 | */ |
288 | 288 | boolean updateDeviceProfileByTbDeviceId(UUID tenantId,UUID tbDeviceId,UUID tbDeviceProfileId); |
289 | + | |
290 | + String usedBySceneLinkage(String tenantId, String tbDeviceId); | |
289 | 291 | } | ... | ... |