Commit 7a9825807fb36c20112653dfb2b1023fb179b90d
Merge branch 'ljl1207' into 'master'
fix: 设备配置相关接口 See merge request huang/thingsboard3.3.2!10
Showing
8 changed files
with
35 additions
and
10 deletions
@@ -45,7 +45,7 @@ public class DeviceDTO extends TenantDTO { | @@ -45,7 +45,7 @@ public class DeviceDTO extends TenantDTO { | ||
45 | @ApiModelProperty(value = "设备唯一编号", required = true) | 45 | @ApiModelProperty(value = "设备唯一编号", required = true) |
46 | private String deviceToken; | 46 | private String deviceToken; |
47 | // 不用序列化给前端 | 47 | // 不用序列化给前端 |
48 | - @JsonIgnore private String tbDeviceId; | 48 | + private String tbDeviceId; |
49 | private String deviceTypeId; | 49 | private String deviceTypeId; |
50 | 50 | ||
51 | @NotEmpty( | 51 | @NotEmpty( |
@@ -5,8 +5,11 @@ import com.fasterxml.jackson.annotation.JsonFormat; | @@ -5,8 +5,11 @@ import com.fasterxml.jackson.annotation.JsonFormat; | ||
5 | import com.fasterxml.jackson.annotation.JsonInclude; | 5 | import com.fasterxml.jackson.annotation.JsonInclude; |
6 | import lombok.Data; | 6 | import lombok.Data; |
7 | import lombok.EqualsAndHashCode; | 7 | import lombok.EqualsAndHashCode; |
8 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | ||
9 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | ||
8 | import org.thingsboard.server.common.data.yunteng.enums.TenantStatusEnum; | 10 | import org.thingsboard.server.common.data.yunteng.enums.TenantStatusEnum; |
9 | 11 | ||
12 | +import javax.validation.constraints.NotEmpty; | ||
10 | import java.time.LocalDateTime; | 13 | import java.time.LocalDateTime; |
11 | 14 | ||
12 | @EqualsAndHashCode(callSuper = false) | 15 | @EqualsAndHashCode(callSuper = false) |
@@ -18,6 +21,9 @@ public class TenantDTO extends BaseDTO { | @@ -18,6 +21,9 @@ public class TenantDTO extends BaseDTO { | ||
18 | private String description; | 21 | private String description; |
19 | private String defaultConfig; | 22 | private String defaultConfig; |
20 | /** TB的租户ID */ | 23 | /** TB的租户ID */ |
24 | + @NotEmpty( | ||
25 | + message = "租户ID不能为空或者空字符串", | ||
26 | + groups = {UpdateGroup.class}) | ||
21 | private String tenantId; | 27 | private String tenantId; |
22 | /** 租户角色 */ | 28 | /** 租户角色 */ |
23 | private String[] roleIds; | 29 | private String[] roleIds; |
@@ -2,13 +2,12 @@ package org.thingsboard.server.common.data.yunteng.utils; | @@ -2,13 +2,12 @@ package org.thingsboard.server.common.data.yunteng.utils; | ||
2 | 2 | ||
3 | import lombok.extern.slf4j.Slf4j; | 3 | import lombok.extern.slf4j.Slf4j; |
4 | import org.springframework.beans.BeanUtils; | 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 | import java.lang.reflect.Constructor; | 8 | import java.lang.reflect.Constructor; |
7 | import java.lang.reflect.Field; | 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 | @Slf4j | 12 | @Slf4j |
14 | public class ReflectUtils { | 13 | public class ReflectUtils { |
@@ -48,6 +47,15 @@ public class ReflectUtils { | @@ -48,6 +47,15 @@ public class ReflectUtils { | ||
48 | return targetList; | 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 | * 获取类的所有属性,包含父类的【public private protected】 | 61 | * 获取类的所有属性,包含父类的【public private protected】 |
@@ -28,6 +28,7 @@ import org.thingsboard.server.dao.DaoUtil; | @@ -28,6 +28,7 @@ import org.thingsboard.server.dao.DaoUtil; | ||
28 | import org.thingsboard.server.dao.sql.device.JpaDeviceProfileDao; | 28 | import org.thingsboard.server.dao.sql.device.JpaDeviceProfileDao; |
29 | import org.thingsboard.server.dao.yunteng.repository.YtDeviceProfileRepository; | 29 | import org.thingsboard.server.dao.yunteng.repository.YtDeviceProfileRepository; |
30 | 30 | ||
31 | +import java.util.List; | ||
31 | import java.util.Objects; | 32 | import java.util.Objects; |
32 | 33 | ||
33 | @Component | 34 | @Component |
@@ -55,5 +56,10 @@ public class YtJpaDeviceProfileDao extends JpaDeviceProfileDao { | @@ -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,8 +158,7 @@ public class YtDeviceProfileServiceImpl | ||
158 | TenantId tenant = new TenantId(UUID.fromString(tenantId)); | 158 | TenantId tenant = new TenantId(UUID.fromString(tenantId)); |
159 | DeviceProfile profile = deviceProfileDao.findById(tenant, UUID.fromString(id)); | 159 | DeviceProfile profile = deviceProfileDao.findById(tenant, UUID.fromString(id)); |
160 | return Optional.ofNullable(profile).map(entity -> { | 160 | return Optional.ofNullable(profile).map(entity -> { |
161 | - DeviceProfileDTO result = new DeviceProfileDTO(); | ||
162 | - BeanUtils.copyProperties(entity, result); | 161 | + DeviceProfileDTO result = ReflectUtils.getDeviceProfileDTO(entity); |
163 | return result; | 162 | return result; |
164 | }); | 163 | }); |
165 | } | 164 | } |
@@ -180,7 +179,7 @@ public class YtDeviceProfileServiceImpl | @@ -180,7 +179,7 @@ public class YtDeviceProfileServiceImpl | ||
180 | @Override | 179 | @Override |
181 | public List<DeviceProfileDTO> findDeviceProfile(String tenantId) { | 180 | public List<DeviceProfileDTO> findDeviceProfile(String tenantId) { |
182 | UUID profileId = UUID.fromString(tenantId); | 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 | } |
@@ -162,6 +162,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -162,6 +162,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
162 | deviceTenantId = currentTenantId; | 162 | deviceTenantId = currentTenantId; |
163 | deviceDTO.setTenantId(currentTenantId); | 163 | deviceDTO.setTenantId(currentTenantId); |
164 | }else{ | 164 | }else{ |
165 | + deviceTenantId = deviceDTO.getTenantId(); | ||
165 | YtDevice device = baseMapper.selectById(deviceDTO.getId()); | 166 | YtDevice device = baseMapper.selectById(deviceDTO.getId()); |
166 | if(device == null){ | 167 | if(device == null){ |
167 | throw new YtDataValidationException("设备不存在!"); | 168 | throw new YtDataValidationException("设备不存在!"); |
@@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; | @@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.DeviceTransportType; | ||
24 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | 24 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
25 | import org.thingsboard.server.dao.model.sql.DeviceProfileEntity; | 25 | import org.thingsboard.server.dao.model.sql.DeviceProfileEntity; |
26 | 26 | ||
27 | +import java.util.List; | ||
27 | import java.util.UUID; | 28 | import java.util.UUID; |
28 | 29 | ||
29 | public interface YtDeviceProfileRepository extends JpaRepository<DeviceProfileEntity, UUID> { | 30 | public interface YtDeviceProfileRepository extends JpaRepository<DeviceProfileEntity, UUID> { |
@@ -45,4 +46,8 @@ public interface YtDeviceProfileRepository extends JpaRepository<DeviceProfileEn | @@ -45,4 +46,8 @@ public interface YtDeviceProfileRepository extends JpaRepository<DeviceProfileEn | ||
45 | Pageable pageable); | 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 | } |
@@ -38,7 +38,7 @@ | @@ -38,7 +38,7 @@ | ||
38 | SELECT | 38 | SELECT |
39 | <include refid="columns"/>,ifdp.name AS profile_name,io.name AS organization_name | 39 | <include refid="columns"/>,ifdp.name AS profile_name,io.name AS organization_name |
40 | FROM iotfs_device ifd | 40 | FROM iotfs_device ifd |
41 | - LEFT JOIN iotfs_device_profile ifdp ON ifd.profile_id = ifdp.id | 41 | + LEFT JOIN device_profile ifdp ON ifd.profile_id = CAST (ifdp.id AS VARCHAR) |
42 | LEFT JOIN iotfs_organization io ON io.id = ifd.organization_id | 42 | LEFT JOIN iotfs_organization io ON io.id = ifd.organization_id |
43 | <where> | 43 | <where> |
44 | <if test="queryMap.tenantId !=null and queryMap.tenantId !=''"> | 44 | <if test="queryMap.tenantId !=null and queryMap.tenantId !=''"> |