ソースを参照

fix jetlinks/jetlinks-pro#63

zhou-hao 5 年 前
コミット
aae6966a60

+ 3 - 2
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/excel/DeviceExcelInfo.java

@@ -33,7 +33,7 @@ public class DeviceExcelInfo {
     private long rowNumber;
 
 
-    public void tag(String key, String name, Object value) {
+    public void tag(String key, String name, Object value,String type) {
         if (value == null) {
             return;
         }
@@ -41,10 +41,11 @@ public class DeviceExcelInfo {
         entity.setKey(key);
         entity.setValue(String.valueOf(value));
         entity.setName(name);
+        entity.setDeviceId(id);
+        entity.setType(type);
         entity.setId(String.valueOf(id).concat(":").concat(key));
         tags.add(entity);
     }
-
     public void setId(String id) {
         this.id = id;
         for (DeviceTagEntity tag : tags) {

+ 5 - 5
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/excel/DeviceWrapper.java

@@ -18,14 +18,14 @@ import java.util.Map;
  */
 public class DeviceWrapper extends RowWrapper<DeviceExcelInfo> {
 
-    Map<String, String> tagMapping = new HashMap<>();
+    Map<String, PropertyMetadata> tagMapping = new HashMap<>();
     static Map<String, String> headerMapping = DeviceExcelInfo.getImportHeaderMapping();
 
     public static DeviceWrapper empty = new DeviceWrapper(Collections.emptyList());
 
     public DeviceWrapper(List<PropertyMetadata> tags) {
         for (PropertyMetadata tag : tags) {
-            tagMapping.put(tag.getName(), tag.getId());
+            tagMapping.put(tag.getName(), tag);
         }
     }
 
@@ -38,9 +38,9 @@ public class DeviceWrapper extends RowWrapper<DeviceExcelInfo> {
     protected DeviceExcelInfo wrap(DeviceExcelInfo deviceExcelInfo, Cell header, Cell cell) {
         String headerText = header.valueAsText().orElse("null");
 
-        String maybeTag = tagMapping.get(headerText);
-        if (StringUtils.hasText(maybeTag)) {
-            deviceExcelInfo.tag(maybeTag, headerText, cell.value().orElse(null));
+        PropertyMetadata maybeTag = tagMapping.get(headerText);
+        if (maybeTag != null) {
+            deviceExcelInfo.tag(maybeTag.getId(), headerText, cell.value().orElse(null), maybeTag.getValueType().getId());
         } else {
             deviceExcelInfo.with(headerMapping.getOrDefault(headerText, headerText), cell.value().orElse(null));
         }