Sfoglia il codice sorgente

fix:物模型保存

xiwa 2 anni fa
parent
commit
d4e5c824a6

+ 16 - 16
data/init/thingModel.json

@@ -1,6 +1,6 @@
 [
   {
-    "id": "0",
+    "id": 1,
     "productKey": "xpsYHExTKPFaQMS7",
     "model": {
       "properties": [
@@ -34,7 +34,7 @@
     }
   },
   {
-    "id": "1",
+    "id": 2,
     "productKey": "hdX3PCMcFrCYpesJ",
     "model": {
       "properties": [
@@ -82,7 +82,7 @@
     }
   },
   {
-    "id": "2",
+    "id": 3,
     "productKey": "hbtgIA0SuVw9lxjB",
     "model": {
       "properties": [],
@@ -178,7 +178,7 @@
     }
   },
   {
-    "id": "3",
+    "id": 4,
     "productKey": "eDhXKwEzwFybM5R7",
     "model": {
       "properties": [
@@ -274,7 +274,7 @@
     }
   },
   {
-    "id": "4",
+    "id": 5,
     "productKey": "cGCrkK7Ex4FESAwe",
     "model": {
       "properties": [
@@ -344,7 +344,7 @@
     }
   },
   {
-    "id": "5",
+    "id": 6,
     "productKey": "Rf4QSjbm65X45753",
     "model": {
       "properties": [
@@ -436,7 +436,7 @@
     "_class": "cc.iotkit.model.ThingModel"
   },
   {
-    "id": "6",
+    "id": 7,
     "productKey": "PN3EDmkBZDD8whDd",
     "model": {
       "properties": [
@@ -496,7 +496,7 @@
     }
   },
   {
-    "id": "7",
+    "id": 8,
     "productKey": "N523nWsCiG3CAn6X",
     "model": {
       "properties": [
@@ -658,7 +658,7 @@
     }
   },
   {
-    "id": "8",
+    "id": 9,
     "productKey": "KdJYpTp5ywNhmrmC",
     "model": {
       "properties": [],
@@ -684,7 +684,7 @@
     }
   },
   {
-    "id": "9",
+    "id": 10,
     "productKey": "Eit3kmGJtxSHfCKT",
     "model": {
       "properties": [
@@ -718,7 +718,7 @@
     }
   },
   {
-    "id": "10",
+    "id": 11,
     "productKey": "D8c5pXFmt2KJDxNm",
     "model": {
       "properties": [
@@ -814,7 +814,7 @@
     }
   },
   {
-    "id": "11",
+    "id": 12,
     "productKey": "AWcJnf7ymGSkaz5M",
     "model": {
       "properties": [
@@ -944,7 +944,7 @@
     }
   },
   {
-    "id": "12",
+    "id": 13,
     "productKey": "6kYp6jszrDns2yh4",
     "model": {
       "properties": [
@@ -984,7 +984,7 @@
     }
   },
   {
-    "id": "13",
+    "id": 14,
     "productKey": "bGdZt8ffBETtsirm",
     "model": {
       "properties": [
@@ -1047,7 +1047,7 @@
     }
   },
   {
-    "id": "14",
+    "id": 15,
     "productKey": "BRD3x4fkKxkaxXFt",
     "model": {
       "properties": [],
@@ -1115,7 +1115,7 @@
     }
   },
   {
-    "id": "15",
+    "id": 16,
     "productKey": "PwMfpXmp4ZWkGahn",
     "model": {
       "properties": [

+ 4 - 0
iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ThingModelCacheEvict.java

@@ -11,4 +11,8 @@ public class ThingModelCacheEvict {
     public void findById(Long s) {
     }
 
+    @CacheEvict(value = Constants.CACHE_THING_MODEL, key = "#root.method.name+#productKey")
+    public void findByProductKey(String productKey){
+    }
+
 }

+ 2 - 1
iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ThingModelDataCache.java

@@ -38,6 +38,7 @@ public class ThingModelDataCache implements IThingModelData {
     public ThingModel save(ThingModel data) {
         data = thingModelData.save(data);
         thingModelCacheEvict.findById(data.getId());
+        thingModelCacheEvict.findByProductKey(data.getProductKey());
         return data;
     }
 
@@ -83,7 +84,7 @@ public class ThingModelDataCache implements IThingModelData {
     }
 
     @Override
-    @Cacheable(value = Constants.CACHE_THING_MODEL, key = "#root.method.name+#s", unless = "#result == null")
+    @Cacheable(value = Constants.CACHE_THING_MODEL, key = "#root.method.name+#productKey", unless = "#result == null")
     public ThingModel findByProductKey(String productKey) {
         return thingModelData.findByProductKey(productKey);
     }

+ 1 - 1
iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/ProductServiceImpl.java

@@ -111,7 +111,7 @@ public class ProductServiceImpl implements IProductService {
     public boolean saveThingModel(ThingModelBo data) {
         String productKey = data.getProductKey();
         String model = data.getModel();
-        ThingModel oldData = thingModelData.findOneByCondition(ThingModel.builder().productKey(productKey).build());
+        ThingModel oldData = thingModelData.findByProductKey(productKey);
         ThingModel thingModel = new ThingModel(YitIdHelper.nextId(), productKey, JsonUtils.parseObject(model, ThingModel.Model.class));
 
         if (oldData == null) {