Merge remote-tracking branch 'origin/master'

This commit is contained in:
zhouhao 2023-08-04 18:42:42 +08:00
commit 66eee1bf26
3 changed files with 35 additions and 3 deletions

View File

@ -1 +1 @@
distributionUrl=https://downloads.apache.org/maven/maven-3/3.9.3/binaries/apache-maven-3.9.3-bin.zip
distributionUrl=https://archive.apache.org/dist/maven/maven-3/3.9.3/binaries/apache-maven-3.9.3-bin.zip

View File

@ -1,6 +1,7 @@
package org.jetlinks.community.device.entity;
import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
@ -14,6 +15,8 @@ import org.hswebframework.web.validator.CreateGroup;
import org.jetlinks.core.metadata.Converter;
import org.jetlinks.core.metadata.DataType;
import org.jetlinks.core.metadata.PropertyMetadata;
import org.jetlinks.core.metadata.types.ArrayType;
import org.jetlinks.core.metadata.types.ObjectType;
import javax.persistence.Column;
import javax.persistence.Index;
@ -78,6 +81,17 @@ public class DeviceTagEntity extends GenericEntity<String> {
return entity;
}
//以物模型标签基础数据为准重构数据库保存的可能已过时的标签数据
public DeviceTagEntity restructure(DeviceTagEntity tag) {
this.setDataType(tag.getDataType());
this.setName(tag.getName());
this.setType(tag.getType());
this.setKey(tag.getKey());
this.setDescription(tag.getDescription());
return this;
}
public static DeviceTagEntity of(PropertyMetadata property, Object value) {
DeviceTagEntity tag = of(property);
@ -88,7 +102,19 @@ public class DeviceTagEntity extends GenericEntity<String> {
value = newValue;
}
}
tag.setValue(String.valueOf(value));
String stringValue;
switch (type.getId()) {
//结构体和数组类型转为json字符串
case ObjectType.ID:
case ArrayType.ID:
stringValue = JSON.toJSONString(value);
break;
default:
stringValue = String.valueOf(value);
}
tag.setValue(stringValue);
return tag;
}

View File

@ -252,7 +252,12 @@ public class DeviceDetail {
Collectors.toMap(
DeviceTagEntity::getKey,
Function.identity(),
(_1, _2) -> StringUtils.hasText(_1.getValue()) ? _1 : _2));
(_1, _2) -> {
if (StringUtils.hasText(_1.getValue())) {
return _1.restructure(_2);
}
return _2.restructure(_1);
}));
this.tags = new ArrayList<>(map.values());
@ -269,6 +274,7 @@ public class DeviceDetail {
this.tags.sort(Comparator.comparing(DeviceTagEntity::getCreateTime));
}
if (StringUtils.hasText(id)) {
for (DeviceTagEntity tag : getTags()) {
tag.setId(DeviceTagEntity.createTagId(id, tag.getKey()));