diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOtaInfo.java b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOtaInfo.java new file mode 100644 index 00000000..1bb9b630 --- /dev/null +++ b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOtaInfo.java @@ -0,0 +1,23 @@ +package cc.iotkit.model.ota; + +import cc.iotkit.model.Id; +import lombok.*; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:00 + * @Description: + */ + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DeviceOtaInfo implements Id { + private String id; + private Integer step; + private String desc; + private String version; + private String module; + private String deviceId; +} diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaInfo.java b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaInfo.java new file mode 100644 index 00000000..00996e9d --- /dev/null +++ b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaInfo.java @@ -0,0 +1,15 @@ +package cc.iotkit.model.ota; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:54 + * @Description: + */ +@Data +public class OtaInfo implements Serializable { + +} diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaInfoData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaInfoData.java new file mode 100644 index 00000000..2a289180 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaInfoData.java @@ -0,0 +1,12 @@ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.ota.DeviceOtaInfo; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:14 + * @Description: + */ +public interface IDeviceOtaInfoData extends ICommonData { +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaInfoRepository.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaInfoRepository.java new file mode 100644 index 00000000..28d28ebc --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaInfoRepository.java @@ -0,0 +1,13 @@ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceOtaInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:21 + * @Description: + */ +public interface DeviceOtaInfoRepository extends JpaRepository, QuerydslPredicateExecutor { +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaInfo.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaInfo.java new file mode 100644 index 00000000..c8fe7f5f --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaInfo.java @@ -0,0 +1,28 @@ +package cc.iotkit.data.model; + +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:22 + * @Description: + */ +@Data +@Entity +@Table(name = "device_ota_info") +@ApiModel(value = "设备信息") +@AutoMapper(target = TbDeviceOtaInfo.class) +public class TbDeviceOtaInfo { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private String id; +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaInfoDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaInfoDataImpl.java new file mode 100644 index 00000000..8e309984 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaInfoDataImpl.java @@ -0,0 +1,42 @@ +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.DeviceOtaInfoRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IDeviceOtaInfoData; +import cc.iotkit.data.model.TbDeviceOtaInfo; +import cc.iotkit.model.ota.DeviceOtaInfo; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:19 + * @Description: + */ +@Primary +@Service +@RequiredArgsConstructor +public class DeviceOtaInfoDataImpl implements IDeviceOtaInfoData, IJPACommData { + + private DeviceOtaInfoRepository deviceOtaInfoRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return deviceOtaInfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbDeviceOtaInfo.class; + } + + @Override + public Class getTClass() { + return DeviceOtaInfo.class; + } +} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java index 12cae33e..3f651510 100755 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java @@ -189,7 +189,7 @@ public class DeviceMessageHandler implements IMessageHandler { private void doOta(DeviceMessage message) { ThingModelMessage thingModelMessage = converter.decode(message); - deviceBehaviourService.reportMessage(thingModelMessage); + deviceBehaviourService.deviceOta(thingModelMessage); } private void doReport(DeviceMessage message) { diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java index 244e2617..97ac711d 100755 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java @@ -18,10 +18,12 @@ import cc.iotkit.common.utils.UniqueIdUtil; import cc.iotkit.comp.model.DeviceState; import cc.iotkit.comp.model.RegisterInfo; import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IDeviceOtaInfoData; import cc.iotkit.data.manager.IProductData; import cc.iotkit.data.manager.IProductModelData; import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.message.ThingModelMessage; +import cc.iotkit.model.ota.DeviceOtaInfo; import cc.iotkit.model.product.Product; import cc.iotkit.model.product.ProductModel; import cc.iotkit.mq.MqProducer; @@ -41,6 +43,9 @@ public class DeviceBehaviourService { @Autowired private IProductModelData productModelData; + @Autowired + private IDeviceOtaInfoData deviceOtaInfoData; + @Autowired @Qualifier("deviceInfoDataCache") private IDeviceInfoData deviceInfoData; @@ -267,4 +272,10 @@ public class DeviceBehaviourService { ThingModelMessage message = JsonUtils.parseObject(jsonMsg, ThingModelMessage.class); reportMessage(message); } + + public void deviceOta(ThingModelMessage message) { + DeviceOtaInfo otaInfo = (DeviceOtaInfo)message.getData(); + otaInfo.setDeviceId(message.getDeviceId()); + deviceOtaInfoData.save(otaInfo); + } } diff --git a/iot-components/iot-mqtt-component/src/main/resources/component.js b/iot-components/iot-mqtt-component/src/main/resources/component.js index 33487140..4c6c218e 100755 --- a/iot-components/iot-mqtt-component/src/main/resources/component.js +++ b/iot-components/iot-mqtt-component/src/main/resources/component.js @@ -212,6 +212,7 @@ function disconnect(clientId) { } function ota(head, payload) { + payload = JSON.parse(payload); var topic = head.topic; var arr = topic.split('/'); if (arr.length < 6) {