Эх сурвалжийг харах

Merge remote-tracking branch 'origin/dev-V0.4.5' into dev-V0.4.5

jay 2 жил өмнө
parent
commit
d746490c57

+ 16 - 16
data/init/thingModel.json

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

+ 2 - 0
iot-common/iot-common-core/src/main/java/cc/iotkit/common/thing/ThingService.java

@@ -23,6 +23,8 @@ public class ThingService<T> {
     public static final String TYPE_PROPERTY = "property";
     public static final String TYPE_PROPERTY = "property";
     public static final String TYPE_SERVICE = "service";
     public static final String TYPE_SERVICE = "service";
 
 
+    public static final String TYPE_OTA = "ota";
+
     private String mid;
     private String mid;
 
 
     private String productKey;
     private String productKey;

+ 8 - 2
iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java

@@ -15,9 +15,9 @@ import lombok.NoArgsConstructor;
 @Builder
 @Builder
 @NoArgsConstructor
 @NoArgsConstructor
 @AllArgsConstructor
 @AllArgsConstructor
-public class OtaPackage implements Id<String> {
+public class OtaPackage implements Id<Long> {
 
 
-    private String id;
+    private Long id;
 
 
     private Long size;
     private Long size;
 
 
@@ -35,5 +35,11 @@ public class OtaPackage implements Id<String> {
 
 
     private String url;
     private String url;
 
 
+    private String signMethod;
+
+    private String module;
+
+    private String extData;
+
     private Long createAt;
     private Long createAt;
 }
 }

+ 1 - 1
iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java

@@ -10,7 +10,7 @@ import java.util.List;
  * @Date: 2023/5/19 21:46
  * @Date: 2023/5/19 21:46
  * @Description:
  * @Description:
  */
  */
-public interface IOtaPackageData extends ICommonData<OtaPackage, String> {
+public interface IOtaPackageData extends ICommonData<OtaPackage, Long> {
 
 
     List<OtaPackage> findByVersionGreaterThan(String version);
     List<OtaPackage> findByVersionGreaterThan(String version);
 
 

+ 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) {
     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) {
     public ThingModel save(ThingModel data) {
         data = thingModelData.save(data);
         data = thingModelData.save(data);
         thingModelCacheEvict.findById(data.getId());
         thingModelCacheEvict.findById(data.getId());
+        thingModelCacheEvict.findByProductKey(data.getProductKey());
         return data;
         return data;
     }
     }
 
 
@@ -83,7 +84,7 @@ public class ThingModelDataCache implements IThingModelData {
     }
     }
 
 
     @Override
     @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) {
     public ThingModel findByProductKey(String productKey) {
         return thingModelData.findByProductKey(productKey);
         return thingModelData.findByProductKey(productKey);
     }
     }

+ 10 - 1
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java

@@ -1,5 +1,7 @@
 package cc.iotkit.data.model;
 package cc.iotkit.data.model;
 
 
+import cc.iotkit.model.ota.OtaPackage;
+import io.github.linpeilie.annotations.AutoMapper;
 import lombok.Data;
 import lombok.Data;
 import org.hibernate.annotations.GenericGenerator;
 import org.hibernate.annotations.GenericGenerator;
 
 
@@ -16,12 +18,13 @@ import javax.persistence.Table;
 @Data
 @Data
 @Entity
 @Entity
 @Table(name = "ota_package")
 @Table(name = "ota_package")
+@AutoMapper(target = OtaPackage.class)
 public class TbOtaPackage {
 public class TbOtaPackage {
 
 
     @Id
     @Id
     @GeneratedValue(generator = "SnowflakeIdGenerator")
     @GeneratedValue(generator = "SnowflakeIdGenerator")
     @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
     @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
-    private String id;
+    private Long id;
 
 
     private Long size;
     private Long size;
 
 
@@ -39,5 +42,11 @@ public class TbOtaPackage {
 
 
     private String url;
     private String url;
 
 
+    private String signMethod;
+
+    private String module;
+
+    private String extData;
+
     private Long createAt;
     private Long createAt;
 }
 }

+ 4 - 22
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java

@@ -10,6 +10,7 @@ import cc.iotkit.data.model.TbOtaDevice;
 import cc.iotkit.data.model.TbOtaPackage;
 import cc.iotkit.data.model.TbOtaPackage;
 import cc.iotkit.model.ota.OtaDevice;
 import cc.iotkit.model.ota.OtaDevice;
 import cc.iotkit.model.ota.OtaPackage;
 import cc.iotkit.model.ota.OtaPackage;
+import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.annotation.Primary;
 import org.springframework.context.annotation.Primary;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
@@ -29,10 +30,10 @@ import java.util.stream.Collectors;
  */
  */
 @Primary
 @Primary
 @Service
 @Service
-public class IOtaPackageDataImpl implements IOtaPackageData, IJPACommData<OtaPackage, String> {
+@RequiredArgsConstructor
+public class IOtaPackageDataImpl implements IOtaPackageData, IJPACommData<OtaPackage, Long> {
 
 
-    @Resource
-    private IOtaPackageRepository iOtaPackageRepository;
+    private final IOtaPackageRepository iOtaPackageRepository;
 
 
     @Override
     @Override
     public List<OtaPackage> findByVersionGreaterThan(String version) {
     public List<OtaPackage> findByVersionGreaterThan(String version) {
@@ -54,25 +55,6 @@ public class IOtaPackageDataImpl implements IOtaPackageData, IJPACommData<OtaPac
         return OtaPackage.class;
         return OtaPackage.class;
     }
     }
 
 
-    @Override
-    public OtaPackage save(OtaPackage data) {
-        if (StringUtils.isBlank(data.getId())) {
-            data.setId(UUID.randomUUID().toString());
-        }
-        iOtaPackageRepository.save(MapstructUtils.convert(data, TbOtaPackage.class));
-        return data;
-    }
-
-    @Override
-    public OtaPackage findById(String id) {
-        return MapstructUtils.convert(iOtaPackageRepository.findById(id).orElse(null), OtaPackage.class);
-    }
-
-    @Override
-    public void deleteById(String id) {
-        iOtaPackageRepository.deleteById(id);
-    }
-
     @Override
     @Override
     public long count() {
     public long count() {
         return iOtaPackageRepository.count();
         return iOtaPackageRepository.count();

+ 8 - 2
iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java

@@ -71,8 +71,8 @@ public class OtaController {
 
 
     @ApiOperation("设备升级")
     @ApiOperation("设备升级")
     @PostMapping("/device/upgrade")
     @PostMapping("/device/upgrade")
-    public void deviceUpgrade(@RequestBody Request<DeviceUpgradeBo> request) {
-        otaService.startUpgrade(request.getData().getOtaId(), request.getData().getDeviceId());
+    public String deviceUpgrade(@RequestBody Request<DeviceUpgradeBo> request) {
+        return otaService.startUpgrade(request.getData().getOtaId(), request.getData().getDeviceId());
     }
     }
 
 
     @ApiOperation("设备升级结果查询")
     @ApiOperation("设备升级结果查询")
@@ -81,5 +81,11 @@ public class OtaController {
         return otaService.otaResult(request);
         return otaService.otaResult(request);
     }
     }
 
 
+    @ApiOperation("OTA升级")
+    @PostMapping("/down")
+    public void ota(@RequestBody PageRequest<DeviceOtaInfoBo> request) {
+        otaService.startUpgrade("0417d633-2806-4a0f-ab2a-afe35e2b2dc6", "16870054884740abcd123456000000103");
+    }
+
 
 
 }
 }

+ 2 - 1
iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceService.java

@@ -188,8 +188,9 @@ public class DeviceService {
                 .build();
                 .build();
         if (!ThingModelMessage.TYPE_CONFIG.equals(type)
         if (!ThingModelMessage.TYPE_CONFIG.equals(type)
                 && !ThingModelMessage.TYPE_LIFETIME.equals(type)
                 && !ThingModelMessage.TYPE_LIFETIME.equals(type)
+                && !ThingModelMessage.TYPE_OTA.equals(type)
         ) {
         ) {
-            //非配置且非生命周期下发需要做物模型转换
+            //非配置非OTA且非生命周期下发需要做物模型转换
             thingModelService.parseParams(thingService);
             thingModelService.parseParams(thingService);
         }
         }
 
 

+ 2 - 22
iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java

@@ -68,33 +68,13 @@ public class OtaService {
         return iOtaPackageData.findAll(request);
         return iOtaPackageData.findAll(request);
     }
     }
 
 
-    public void batchOta() {
-    }
-
     /**
     /**
      * 开始升级
      * 开始升级
      */
      */
-    public void startUpgrade(String otaId, String deviceId) {
+    public String startUpgrade(String otaId, String deviceId) {
         OtaPackage otaPackage = iOtaPackageData.findById(otaId);
         OtaPackage otaPackage = iOtaPackageData.findById(otaId);
         //构建升级包
         //构建升级包
-        JsonObject buildOtaPackage = buildOtaPackage(otaPackage);
-        String id = deviceService.otaUpgrade(deviceId, true, buildOtaPackage);
-    }
-
-    private JsonObject buildOtaPackage(OtaPackage otaPackage) {
-        JsonObject ota = new JsonObject();
-        JsonObject extData = new JsonObject();
-        extData.addProperty("key1", "测试1");
-        extData.addProperty("key2", "测试2");
-        ota.addProperty("size", otaPackage.getSize());
-        ota.addProperty("sign", otaPackage.getSign());
-        ota.addProperty("version", otaPackage.getVersion());
-        ota.addProperty("isDiff", Boolean.toString(otaPackage.getIsDiff()));
-        ota.addProperty("url", otaPackage.getUrl());
-        ota.addProperty("signMethod", "MD5");
-        ota.addProperty("module", "MCU");
-        ota.add("extData", extData);
-        return ota;
+        return deviceService.otaUpgrade(deviceId, true, otaPackage);
     }
     }
 
 
     public Paging<DeviceOtaInfoVO> otaResult(PageRequest<DeviceOtaInfoBo> request) {
     public Paging<DeviceOtaInfoVO> otaResult(PageRequest<DeviceOtaInfoBo> request) {

+ 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) {
     public boolean saveThingModel(ThingModelBo data) {
         String productKey = data.getProductKey();
         String productKey = data.getProductKey();
         String model = data.getModel();
         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));
         ThingModel thingModel = new ThingModel(YitIdHelper.nextId(), productKey, JsonUtils.parseObject(model, ThingModel.Model.class));
 
 
         if (oldData == null) {
         if (oldData == null) {