add:添加ota上报入库

V0.5.x
荭琪枫 2023-06-16 00:02:44 +08:00
parent 7fe2c4b337
commit 1f34bb5aed
9 changed files with 146 additions and 1 deletions

View File

@ -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<String> {
private String id;
private Integer step;
private String desc;
private String version;
private String module;
private String deviceId;
}

View File

@ -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 {
}

View File

@ -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<DeviceOtaInfo, String> {
}

View File

@ -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<TbDeviceOtaInfo, String>, QuerydslPredicateExecutor<TbDeviceOtaInfo> {
}

View File

@ -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;
}

View File

@ -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<DeviceOtaInfo, String> {
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;
}
}

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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) {