Commit aa103add1744598bd60771689c0db22a3edc7217
1 parent
98270395
fix: 设备配置相关接口
1.设备配置列表下拉选项数据缺失 2、设备配置列表按租户过滤
Showing
4 changed files
with
26 additions
and
8 deletions
... | ... | @@ -2,13 +2,12 @@ package org.thingsboard.server.common.data.yunteng.utils; |
2 | 2 | |
3 | 3 | import lombok.extern.slf4j.Slf4j; |
4 | 4 | import org.springframework.beans.BeanUtils; |
5 | +import org.thingsboard.server.common.data.DeviceProfile; | |
6 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | |
5 | 7 | |
6 | 8 | import java.lang.reflect.Constructor; |
7 | 9 | import java.lang.reflect.Field; |
8 | -import java.util.ArrayList; | |
9 | -import java.util.Arrays; | |
10 | -import java.util.Collection; | |
11 | -import java.util.List; | |
10 | +import java.util.*; | |
12 | 11 | |
13 | 12 | @Slf4j |
14 | 13 | public class ReflectUtils { |
... | ... | @@ -48,6 +47,15 @@ public class ReflectUtils { |
48 | 47 | return targetList; |
49 | 48 | } |
50 | 49 | |
50 | + public static DeviceProfileDTO getDeviceProfileDTO(DeviceProfile entity) { | |
51 | + DeviceProfileDTO result = new DeviceProfileDTO(); | |
52 | + BeanUtils.copyProperties(entity, result); | |
53 | + result.setId(entity.getId().getId().toString()); | |
54 | + result.setTenantId(entity.getTenantId().getId().toString()); | |
55 | + result.setDefaultRuleChainId(Optional.ofNullable(entity.getDefaultRuleChainId()).map(uuid ->uuid.getId().toString()).orElse(null)); | |
56 | + return result; | |
57 | + } | |
58 | + | |
51 | 59 | |
52 | 60 | /** |
53 | 61 | * 获取类的所有属性,包含父类的【public private protected】 | ... | ... |
... | ... | @@ -28,6 +28,7 @@ import org.thingsboard.server.dao.DaoUtil; |
28 | 28 | import org.thingsboard.server.dao.sql.device.JpaDeviceProfileDao; |
29 | 29 | import org.thingsboard.server.dao.yunteng.repository.YtDeviceProfileRepository; |
30 | 30 | |
31 | +import java.util.List; | |
31 | 32 | import java.util.Objects; |
32 | 33 | |
33 | 34 | @Component |
... | ... | @@ -55,5 +56,10 @@ public class YtJpaDeviceProfileDao extends JpaDeviceProfileDao { |
55 | 56 | } |
56 | 57 | } |
57 | 58 | |
59 | + public List<DeviceProfileDTO> findDeviceProfileByTenantId(TenantId tenantId) { | |
60 | + return ytDeviceProfileRepository.findDeviceProfileByTenantId(tenantId.getId()); | |
61 | + | |
62 | + } | |
63 | + | |
58 | 64 | |
59 | 65 | } | ... | ... |
... | ... | @@ -158,8 +158,7 @@ public class YtDeviceProfileServiceImpl |
158 | 158 | TenantId tenant = new TenantId(UUID.fromString(tenantId)); |
159 | 159 | DeviceProfile profile = deviceProfileDao.findById(tenant, UUID.fromString(id)); |
160 | 160 | return Optional.ofNullable(profile).map(entity -> { |
161 | - DeviceProfileDTO result = new DeviceProfileDTO(); | |
162 | - BeanUtils.copyProperties(entity, result); | |
161 | + DeviceProfileDTO result = ReflectUtils.getDeviceProfileDTO(entity); | |
163 | 162 | return result; |
164 | 163 | }); |
165 | 164 | } |
... | ... | @@ -180,7 +179,7 @@ public class YtDeviceProfileServiceImpl |
180 | 179 | @Override |
181 | 180 | public List<DeviceProfileDTO> findDeviceProfile(String tenantId) { |
182 | 181 | UUID profileId = UUID.fromString(tenantId); |
183 | - List<DeviceProfile> profile = deviceProfileDao.find(new TenantId(profileId)); | |
184 | - return ReflectUtils.sourceToTarget(profile, DeviceProfileDTO.class); | |
182 | + List<DeviceProfileDTO> results = deviceProfileDao.findDeviceProfileByTenantId(new TenantId(profileId)); | |
183 | + return results; | |
185 | 184 | } |
186 | 185 | } | ... | ... |
... | ... | @@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; |
24 | 24 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
25 | 25 | import org.thingsboard.server.dao.model.sql.DeviceProfileEntity; |
26 | 26 | |
27 | +import java.util.List; | |
27 | 28 | import java.util.UUID; |
28 | 29 | |
29 | 30 | public interface YtDeviceProfileRepository extends JpaRepository<DeviceProfileEntity, UUID> { |
... | ... | @@ -45,4 +46,8 @@ public interface YtDeviceProfileRepository extends JpaRepository<DeviceProfileEn |
45 | 46 | Pageable pageable); |
46 | 47 | |
47 | 48 | |
49 | + @Query("SELECT new org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO(d.id, d.name, d.createdTime,d.description, d.transportType, d.defaultRuleChainId) " + | |
50 | + "FROM DeviceProfileEntity d WHERE d.tenantId = :tenantId ") | |
51 | + List<DeviceProfileDTO> findDeviceProfileByTenantId(@Param("tenantId") UUID tenantId); | |
52 | + | |
48 | 53 | } | ... | ... |