Merge remote-tracking branch 'origin/dev-V0.4.5' into dev-V0.4.5
commit
ac087ac9d7
|
@ -0,0 +1,40 @@
|
|||
package cc.iotkit.model.ota;
|
||||
|
||||
import cc.iotkit.model.Id;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: 石恒
|
||||
* @Date: 2023/6/15 22:00
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DeviceOtaDetail implements Id<Long> {
|
||||
|
||||
private Long id;
|
||||
|
||||
private Integer step;
|
||||
|
||||
private String taskId;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String version;
|
||||
|
||||
private String module;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String productKey;
|
||||
|
||||
private String deviceName;
|
||||
|
||||
private Long otaInfoId;
|
||||
}
|
|
@ -17,19 +17,14 @@ public class DeviceOtaInfo implements Id<Long> {
|
|||
|
||||
private Long id;
|
||||
|
||||
private Integer step;
|
||||
|
||||
private String taskId;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String version;
|
||||
|
||||
private String module;
|
||||
|
||||
private String deviceId;
|
||||
private Integer counts;
|
||||
|
||||
private String productKey;
|
||||
|
||||
private String deviceName;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package cc.iotkit.data.manager;
|
||||
|
||||
import cc.iotkit.data.ICommonData;
|
||||
import cc.iotkit.model.ota.DeviceOtaDetail;
|
||||
import cc.iotkit.model.ota.DeviceOtaInfo;
|
||||
|
||||
/**
|
||||
* @Author: 石恒
|
||||
* @Date: 2023/6/15 22:14
|
||||
* @Description:
|
||||
*/
|
||||
public interface IDeviceOtaDetailData extends ICommonData<DeviceOtaDetail, Long> {
|
||||
}
|
|
@ -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 DeviceOtaDetailRepository extends JpaRepository<TbDeviceOtaInfo, String>, QuerydslPredicateExecutor<TbDeviceOtaInfo> {
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package cc.iotkit.data.model;
|
||||
|
||||
import cc.iotkit.model.ota.DeviceOtaDetail;
|
||||
import cc.iotkit.model.ota.DeviceOtaInfo;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* @Author: 石恒
|
||||
* @Date: 2023/6/15 22:22
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "device_ota_detail")
|
||||
@ApiModel(value = "设备升级明细")
|
||||
@AutoMapper(target = DeviceOtaDetail.class)
|
||||
public class TbDeviceOtaDetail {
|
||||
@Id
|
||||
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||
private Long id;
|
||||
|
||||
private Integer step;
|
||||
|
||||
private String taskId;
|
||||
|
||||
@Column(name = "[desc]")
|
||||
private String desc;
|
||||
|
||||
private String version;
|
||||
|
||||
private String module;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String productKey;
|
||||
|
||||
private String deviceName;
|
||||
|
||||
private Long otaInfoId;
|
||||
}
|
|
@ -24,10 +24,6 @@ public class TbDeviceOtaInfo {
|
|||
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||
private Long id;
|
||||
|
||||
private Integer step;
|
||||
|
||||
private String taskId;
|
||||
|
||||
@Column(name = "[desc]")
|
||||
private String desc;
|
||||
|
||||
|
@ -35,9 +31,7 @@ public class TbDeviceOtaInfo {
|
|||
|
||||
private String module;
|
||||
|
||||
private String deviceId;
|
||||
private Integer counts;
|
||||
|
||||
private String productKey;
|
||||
|
||||
private String deviceName;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ public class TbOtaPackage {
|
|||
|
||||
private String module;
|
||||
|
||||
private String productKey;
|
||||
|
||||
private String extData;
|
||||
|
||||
private Long createAt;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package cc.iotkit.data.service;
|
||||
|
||||
import cc.iotkit.data.dao.DeviceOtaInfoRepository;
|
||||
import cc.iotkit.data.dao.IJPACommData;
|
||||
import cc.iotkit.data.manager.IDeviceOtaDetailData;
|
||||
import cc.iotkit.data.manager.IDeviceOtaInfoData;
|
||||
import cc.iotkit.data.model.TbDeviceOtaInfo;
|
||||
import cc.iotkit.model.ota.DeviceOtaDetail;
|
||||
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 DeviceOtaDetailDataImpl implements IDeviceOtaDetailData, IJPACommData<DeviceOtaDetail, Long> {
|
||||
|
||||
private final 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;
|
||||
}
|
||||
}
|
|
@ -17,12 +17,10 @@ import cc.iotkit.common.utils.JsonUtils;
|
|||
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.data.manager.*;
|
||||
import cc.iotkit.model.device.DeviceInfo;
|
||||
import cc.iotkit.model.device.message.ThingModelMessage;
|
||||
import cc.iotkit.model.ota.DeviceOtaDetail;
|
||||
import cc.iotkit.model.ota.DeviceOtaInfo;
|
||||
import cc.iotkit.model.product.Product;
|
||||
import cc.iotkit.model.product.ProductModel;
|
||||
|
@ -45,7 +43,7 @@ public class DeviceBehaviourService {
|
|||
@Autowired
|
||||
private IProductModelData productModelData;
|
||||
@Autowired
|
||||
private IDeviceOtaInfoData deviceOtaInfoData;
|
||||
private IDeviceOtaDetailData deviceOtaDetailData;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("deviceInfoDataCache")
|
||||
|
@ -276,26 +274,26 @@ public class DeviceBehaviourService {
|
|||
}
|
||||
|
||||
public void deviceOta(ThingModelMessage message) {
|
||||
DeviceOtaInfo deviceOtaInfoTemp = JsonUtils.objectToJavaBean(message.getData(), DeviceOtaInfo.class);
|
||||
if (Objects.isNull(deviceOtaInfoTemp)) {
|
||||
DeviceOtaDetail deviceOtaDetailTemp = JsonUtils.objectToJavaBean(message.getData(), DeviceOtaDetail.class);
|
||||
if (Objects.isNull(deviceOtaDetailTemp)) {
|
||||
log.debug("device ota upload data is null deviceId:{}", message.getDeviceId());
|
||||
return;
|
||||
}
|
||||
deviceOtaInfoTemp.setTaskId(message.getMid());
|
||||
deviceOtaInfoTemp.setDeviceId(message.getDeviceId());
|
||||
deviceOtaInfoTemp.setDeviceName(message.getDeviceName());
|
||||
deviceOtaInfoTemp.setProductKey(message.getProductKey());
|
||||
DeviceOtaInfo deviceOtaInfo = deviceOtaInfoData.findOneByCondition(DeviceOtaInfo.builder()
|
||||
deviceOtaDetailTemp.setTaskId(message.getMid());
|
||||
deviceOtaDetailTemp.setDeviceId(message.getDeviceId());
|
||||
deviceOtaDetailTemp.setDeviceName(message.getDeviceName());
|
||||
deviceOtaDetailTemp.setProductKey(message.getProductKey());
|
||||
DeviceOtaDetail deviceOtaDetail = deviceOtaDetailData.findOneByCondition(DeviceOtaDetail.builder()
|
||||
.taskId(message.getMid())
|
||||
.productKey(message.getProductKey())
|
||||
.deviceName(message.getDeviceName())
|
||||
.deviceId(message.getDeviceId()).build());
|
||||
if (Objects.nonNull(deviceOtaInfo)) {
|
||||
deviceOtaInfo.setStep(deviceOtaInfoTemp.getStep());
|
||||
if (Objects.nonNull(deviceOtaDetail)) {
|
||||
deviceOtaDetail.setStep(deviceOtaDetailTemp.getStep());
|
||||
} else {
|
||||
deviceOtaInfo = deviceOtaInfoTemp;
|
||||
deviceOtaDetail = deviceOtaDetailTemp;
|
||||
}
|
||||
deviceOtaInfoData.save(deviceOtaInfo);
|
||||
deviceOtaDetailData.save(deviceOtaDetail);
|
||||
}
|
||||
|
||||
public Product getProductKey(String productKey) {
|
||||
|
|
|
@ -4,9 +4,11 @@ import cc.iotkit.common.api.PageRequest;
|
|||
import cc.iotkit.common.api.Paging;
|
||||
import cc.iotkit.common.api.Request;
|
||||
import cc.iotkit.common.web.core.BaseController;
|
||||
import cc.iotkit.manager.dto.bo.ota.DeviceOtaDetailBo;
|
||||
import cc.iotkit.manager.dto.bo.ota.DeviceOtaInfoBo;
|
||||
import cc.iotkit.manager.dto.bo.ota.DeviceUpgradeBo;
|
||||
import cc.iotkit.manager.dto.bo.ota.OtaPackageBo;
|
||||
import cc.iotkit.manager.dto.vo.ota.DeviceOtaDetailVo;
|
||||
import cc.iotkit.manager.dto.vo.ota.DeviceOtaInfoVo;
|
||||
import cc.iotkit.manager.dto.vo.ota.OtaPackageUploadVo;
|
||||
import cc.iotkit.manager.service.OtaService;
|
||||
|
@ -71,9 +73,15 @@ public class OtaController extends BaseController {
|
|||
}
|
||||
|
||||
@ApiOperation("设备升级结果查询")
|
||||
@PostMapping("/result")
|
||||
public Paging<DeviceOtaInfoVo> otaResult(@RequestBody PageRequest<DeviceOtaInfoBo> request) {
|
||||
return otaService.otaResult(request);
|
||||
@PostMapping("/device/detail")
|
||||
public Paging<DeviceOtaDetailVo> otaDeviceDetail(@RequestBody PageRequest<DeviceOtaDetailBo> request) {
|
||||
return otaService.otaDeviceDetail(request);
|
||||
}
|
||||
|
||||
@ApiOperation("设备升级批次查询")
|
||||
@PostMapping("/device/info")
|
||||
public Paging<DeviceOtaInfoVo> otaDeviceInfo(@RequestBody PageRequest<DeviceOtaInfoBo> request) {
|
||||
return otaService.otaDeviceInfo(request);
|
||||
}
|
||||
|
||||
@ApiOperation("ota升级测试")
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package cc.iotkit.manager.dto.bo.ota;
|
||||
|
||||
import cc.iotkit.common.api.BaseDto;
|
||||
import cc.iotkit.model.ota.DeviceOtaDetail;
|
||||
import cc.iotkit.model.ota.DeviceOtaInfo;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @Author: 石恒
|
||||
* @Date: 2023/6/17 20:45
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "DeviceOtaDetailBo")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = DeviceOtaDetail.class, reverseConvertGenerate = false)
|
||||
public class DeviceOtaDetailBo extends BaseDto {
|
||||
|
||||
private Long otaInfoId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String productKey;
|
||||
|
||||
private String deviceName;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package cc.iotkit.manager.dto.vo.ota;
|
||||
|
||||
import cc.iotkit.model.ota.DeviceOtaDetail;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Author: 石恒
|
||||
* @Date: 2023/6/17 20:49
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@ApiModel(value = "DeviceOtaDetailVo")
|
||||
@AutoMapper(target = DeviceOtaDetail.class)
|
||||
public class DeviceOtaDetailVo implements Serializable {
|
||||
private Long id;
|
||||
|
||||
private Integer step;
|
||||
|
||||
private String taskId;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String version;
|
||||
|
||||
private String module;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String productKey;
|
||||
|
||||
private String deviceName;
|
||||
|
||||
private Long otaInfoId;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package cc.iotkit.manager.dto.vo.ota;
|
||||
|
||||
import cc.iotkit.model.ota.DeviceOtaInfo;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
@ -15,23 +16,18 @@ import java.io.Serializable;
|
|||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@ApiModel(value = "DeviceOtaInfoVo")
|
||||
@AutoMapper(target = DeviceOtaInfoVo.class)
|
||||
@AutoMapper(target = DeviceOtaInfo.class)
|
||||
public class DeviceOtaInfoVo implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private Integer step;
|
||||
|
||||
private String taskId;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String version;
|
||||
|
||||
private String module;
|
||||
|
||||
private String deviceId;
|
||||
private Integer counts;
|
||||
|
||||
private String productKey;
|
||||
|
||||
private String deviceName;
|
||||
}
|
||||
|
|
|
@ -2,17 +2,22 @@ package cc.iotkit.manager.service;
|
|||
|
||||
import cc.iotkit.common.api.PageRequest;
|
||||
import cc.iotkit.common.api.Paging;
|
||||
import cc.iotkit.common.enums.ErrCode;
|
||||
import cc.iotkit.common.exception.BizException;
|
||||
import cc.iotkit.common.oss.core.OssClient;
|
||||
import cc.iotkit.common.oss.factory.OssFactory;
|
||||
import cc.iotkit.common.utils.StringUtils;
|
||||
import cc.iotkit.data.manager.IDeviceOtaDetailData;
|
||||
import cc.iotkit.data.manager.IDeviceOtaInfoData;
|
||||
import cc.iotkit.data.manager.IOtaPackageData;
|
||||
import cc.iotkit.data.system.ISysOssData;
|
||||
import cc.iotkit.manager.dto.bo.ota.DeviceOtaDetailBo;
|
||||
import cc.iotkit.manager.dto.bo.ota.DeviceOtaInfoBo;
|
||||
import cc.iotkit.manager.dto.bo.ota.OtaPackageBo;
|
||||
import cc.iotkit.manager.dto.vo.ota.DeviceOtaDetailVo;
|
||||
import cc.iotkit.manager.dto.vo.ota.DeviceOtaInfoVo;
|
||||
import cc.iotkit.manager.dto.vo.ota.OtaPackageUploadVo;
|
||||
import cc.iotkit.model.ota.DeviceOtaDetail;
|
||||
import cc.iotkit.model.ota.DeviceOtaInfo;
|
||||
import cc.iotkit.model.ota.OtaPackage;
|
||||
import cc.iotkit.model.system.SysOss;
|
||||
|
@ -20,15 +25,19 @@ import lombok.RequiredArgsConstructor;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import cc.iotkit.common.oss.entity.UploadResult;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author: 石恒
|
||||
|
@ -43,11 +52,12 @@ public class OtaService {
|
|||
private final IOtaPackageData iOtaPackageData;
|
||||
private final DeviceService deviceService;
|
||||
private final IDeviceOtaInfoData deviceOtaInfoData;
|
||||
private final IDeviceOtaDetailData deviceOtaDetailData;
|
||||
private final ISysOssData sysOssData;
|
||||
|
||||
public OtaPackageUploadVo uploadFile(MultipartFile file) throws Exception {
|
||||
String originalFileName = file.getOriginalFilename();
|
||||
if(originalFileName ==null){
|
||||
if (originalFileName == null) {
|
||||
throw new BizException("文件名为空,获取失败");
|
||||
}
|
||||
String suffix = StringUtils.substring(originalFileName, originalFileName.lastIndexOf("."), originalFileName.length());
|
||||
|
@ -127,10 +137,37 @@ public class OtaService {
|
|||
*/
|
||||
public void startUpgrade(Long otaId, List<String> deviceIds) {
|
||||
OtaPackage otaPackage = iOtaPackageData.findById(otaId);
|
||||
deviceIds.forEach(deviceId -> deviceService.otaUpgrade(deviceId, true, otaPackage));
|
||||
if(Objects.isNull(otaPackage)){
|
||||
throw new BizException(ErrCode.DATA_NOT_EXIST);
|
||||
}
|
||||
DeviceOtaInfo deviceOtaInfo = deviceOtaInfoData.save(DeviceOtaInfo.builder()
|
||||
.counts(deviceIds.size())
|
||||
.productKey(otaPackage.getProductKey())
|
||||
.module(otaPackage.getModule())
|
||||
.desc(otaPackage.getDesc())
|
||||
.version(otaPackage.getVersion())
|
||||
.build());
|
||||
|
||||
List<DeviceOtaDetail> deviceOtaDetails = new ArrayList<>();
|
||||
deviceIds.forEach(deviceId -> {
|
||||
String taskId = deviceService.otaUpgrade(deviceId, true, otaPackage);
|
||||
deviceOtaDetails.add(DeviceOtaDetail.builder()
|
||||
.taskId(taskId)
|
||||
.otaInfoId(deviceOtaInfo.getId())
|
||||
.module(otaPackage.getModule())
|
||||
.version(otaPackage.getVersion())
|
||||
.step(0)
|
||||
.deviceId(deviceId)
|
||||
.build());
|
||||
});
|
||||
deviceOtaDetailData.batchSave(deviceOtaDetails);
|
||||
}
|
||||
|
||||
public Paging<DeviceOtaInfoVo> otaResult(PageRequest<DeviceOtaInfoBo> request) {
|
||||
public Paging<DeviceOtaDetailVo> otaDeviceDetail(PageRequest<DeviceOtaDetailBo> request) {
|
||||
return deviceOtaDetailData.findAll(request.to(DeviceOtaDetail.class)).to(DeviceOtaDetailVo.class);
|
||||
}
|
||||
|
||||
public Paging<DeviceOtaInfoVo> otaDeviceInfo(PageRequest<DeviceOtaInfoBo> request) {
|
||||
return deviceOtaInfoData.findAll(request.to(DeviceOtaInfo.class)).to(DeviceOtaInfoVo.class);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue