Commit cf8b65a32775655304b173da8b9901f8dfbb49c3

Authored by 云中非
1 parent 85cba202

fix: 设备配置

1.设备配置保存bug修复
@@ -19,6 +19,7 @@ import org.thingsboard.server.common.data.device.profile.*; @@ -19,6 +19,7 @@ import org.thingsboard.server.common.data.device.profile.*;
19 import org.thingsboard.server.common.data.edge.EdgeEventActionType; 19 import org.thingsboard.server.common.data.edge.EdgeEventActionType;
20 import org.thingsboard.server.common.data.exception.ThingsboardException; 20 import org.thingsboard.server.common.data.exception.ThingsboardException;
21 import org.thingsboard.server.common.data.id.DeviceProfileId; 21 import org.thingsboard.server.common.data.id.DeviceProfileId;
  22 +import org.thingsboard.server.common.data.id.RuleChainId;
22 import org.thingsboard.server.common.data.id.TenantId; 23 import org.thingsboard.server.common.data.id.TenantId;
23 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; 24 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
24 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; 25 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
@@ -68,7 +69,7 @@ public class YtDeviceProfileController extends BaseController { @@ -68,7 +69,7 @@ public class YtDeviceProfileController extends BaseController {
68 69
69 //TODO 3/3.处理业务平台的业务逻辑 70 //TODO 3/3.处理业务平台的业务逻辑
70 71
71 - DeviceProfileDTO newDeviceProfileDTO = ytDeviceProfileService.insertOrUpdate(getCurrentUser().getCurrentTenantId(), deviceProfileDTO); 72 + DeviceProfileDTO newDeviceProfileDTO = ytDeviceProfileService.insertOrUpdate(savedDeviceProfile.getId().getId().toString(), deviceProfileDTO);
72 return Optional.ofNullable(newDeviceProfileDTO) 73 return Optional.ofNullable(newDeviceProfileDTO)
73 .map( 74 .map(
74 dto -> { 75 dto -> {
@@ -191,21 +192,27 @@ public class YtDeviceProfileController extends BaseController { @@ -191,21 +192,27 @@ public class YtDeviceProfileController extends BaseController {
191 // 传输类型默认都是Default 192 // 传输类型默认都是Default
192 tbDeviceProfile.setTransportType(DeviceTransportType.DEFAULT); 193 tbDeviceProfile.setTransportType(DeviceTransportType.DEFAULT);
193 // 获取当前租户的默认规则链 194 // 获取当前租户的默认规则链
194 -// tbDeviceProfile.setDefaultRuleChainId(new RuleChainId(getCurrentUserDefaultRuleChains())); 195 + if(StringUtils.isNotBlank(deviceProfileDTO.getDefaultRuleChainId())){
  196 + UUID chainId = UUID.fromString(deviceProfileDTO.getDefaultRuleChainId());
  197 + tbDeviceProfile.setDefaultRuleChainId(new RuleChainId(chainId));
  198 + }
  199 +
195 tbDeviceProfile.setDefaultQueueName(ServiceQueue.MAIN); 200 tbDeviceProfile.setDefaultQueueName(ServiceQueue.MAIN);
196 tbDeviceProfile.setProvisionType(DeviceProfileProvisionType.DISABLED); 201 tbDeviceProfile.setProvisionType(DeviceProfileProvisionType.DISABLED);
197 tbDeviceProfile.setCreatedTime(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli()); 202 tbDeviceProfile.setCreatedTime(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
  203 +
198 DeviceProfileData deviceProfileData = new DeviceProfileData(); 204 DeviceProfileData deviceProfileData = new DeviceProfileData();
199 deviceProfileData.setConfiguration(new DefaultDeviceProfileConfiguration()); 205 deviceProfileData.setConfiguration(new DefaultDeviceProfileConfiguration());
200 deviceProfileData.setProvisionConfiguration(new DisabledDeviceProfileProvisionConfiguration(null)); 206 deviceProfileData.setProvisionConfiguration(new DisabledDeviceProfileProvisionConfiguration(null));
201 deviceProfileData.setTransportConfiguration(new DefaultDeviceProfileTransportConfiguration()); 207 deviceProfileData.setTransportConfiguration(new DefaultDeviceProfileTransportConfiguration());
202 - if (null != deviceProfileDTO.getAlarms()) {  
203 - List<DeviceProfileAlarm> list = new ArrayList<>();  
204 - DeviceProfileAlarm deviceProfileAlarm = JacksonUtil.convertValue(deviceProfileDTO.getAlarms(),DeviceProfileAlarm.class);  
205 - list.add(deviceProfileAlarm);  
206 - deviceProfileData.setAlarms(list);  
207 - } 208 + deviceProfileData.setAlarms(deviceProfileDTO.getProfileData().getAlarms());
  209 +// if (null != deviceProfileDTO.getAlarms()) {
  210 +// List<DeviceProfileAlarm> list = new ArrayList<>();
  211 +// DeviceProfileAlarm deviceProfileAlarm = JacksonUtil.convertValue(deviceProfileDTO.getAlarms(),DeviceProfileAlarm.class);
  212 +// list.add(deviceProfileAlarm);
  213 +// }
208 tbDeviceProfile.setProfileData(deviceProfileData); 214 tbDeviceProfile.setProfileData(deviceProfileData);
  215 +
209 return tbDeviceProfile; 216 return tbDeviceProfile;
210 } 217 }
211 } 218 }
@@ -5,8 +5,11 @@ import io.swagger.annotations.ApiModelProperty; @@ -5,8 +5,11 @@ import io.swagger.annotations.ApiModelProperty;
5 import lombok.Data; 5 import lombok.Data;
6 import lombok.EqualsAndHashCode; 6 import lombok.EqualsAndHashCode;
7 import org.thingsboard.server.common.data.DeviceTransportType; 7 import org.thingsboard.server.common.data.DeviceTransportType;
  8 +import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
  9 +import org.thingsboard.server.common.data.id.RuleChainId;
8 import org.thingsboard.server.common.data.yunteng.common.AddGroup; 10 import org.thingsboard.server.common.data.yunteng.common.AddGroup;
9 11
  12 +import javax.validation.Valid;
10 import javax.validation.constraints.NotEmpty; 13 import javax.validation.constraints.NotEmpty;
11 14
12 @EqualsAndHashCode(callSuper = true) 15 @EqualsAndHashCode(callSuper = true)
@@ -28,7 +31,10 @@ public class DeviceProfileDTO extends TenantDTO { @@ -28,7 +31,10 @@ public class DeviceProfileDTO extends TenantDTO {
28 @Deprecated 31 @Deprecated
29 private String tbProfileId; 32 private String tbProfileId;
30 33
31 - private JsonNode alarms;  
32 - /** 告警配置 */ 34 + @Valid
  35 + private transient DeviceProfileData profileData;
  36 + @ApiModelProperty(value = "关联规则链,默认关联根规则链", required = false)
  37 + private String defaultRuleChainId;
  38 + /** 告警通知配置 */
33 private AlarmProfileDTO alarmProfile; 39 private AlarmProfileDTO alarmProfile;
34 } 40 }
@@ -48,15 +48,15 @@ public class YtDeviceProfileServiceImpl @@ -48,15 +48,15 @@ public class YtDeviceProfileServiceImpl
48 48
49 @Override 49 @Override
50 @Transactional 50 @Transactional
51 - public DeviceProfileDTO insertOrUpdate(String tenantId,DeviceProfileDTO deviceProfileDTO) { 51 + public DeviceProfileDTO insertOrUpdate(String deviceProfileId,DeviceProfileDTO deviceProfileDTO) {
52 if (StringUtils.isBlank(deviceProfileDTO.getId())) { 52 if (StringUtils.isBlank(deviceProfileDTO.getId())) {
53 - return insert(tenantId,deviceProfileDTO); 53 + return insert(deviceProfileId,deviceProfileDTO);
54 } else { 54 } else {
55 - return update(tenantId,deviceProfileDTO); 55 + return update(deviceProfileDTO);
56 } 56 }
57 } 57 }
58 58
59 - private DeviceProfileDTO update(String tenantId,DeviceProfileDTO deviceProfileDTO) { 59 + private DeviceProfileDTO update(DeviceProfileDTO deviceProfileDTO) {
60 60
61 // 如果原来不是TCP或者更新也不是TCP 那就需要check 61 // 如果原来不是TCP或者更新也不是TCP 那就需要check
62 // if (!deviceProfile.getTransportType().equals(TransportTypeEnum.TCP) 62 // if (!deviceProfile.getTransportType().equals(TransportTypeEnum.TCP)
@@ -10,7 +10,7 @@ import java.util.Optional; @@ -10,7 +10,7 @@ import java.util.Optional;
10 import java.util.Set; 10 import java.util.Set;
11 11
12 public interface YtDeviceProfileService { 12 public interface YtDeviceProfileService {
13 - DeviceProfileDTO insertOrUpdate(String tenantId,DeviceProfileDTO deviceProfileDTO); 13 + DeviceProfileDTO insertOrUpdate(String deviceProfileId,DeviceProfileDTO deviceProfileDTO);
14 14
15 void deleteDeviceProfiles(String tenantId,Set<String> ids); 15 void deleteDeviceProfiles(String tenantId,Set<String> ids);
16 16