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

V0.5.x
jay 2023-06-21 11:25:18 +08:00
commit 6c92bc79e6
13 changed files with 48 additions and 111 deletions

View File

@ -15,9 +15,9 @@ import lombok.NoArgsConstructor;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OtaDevice implements Id<String> {
public class OtaDevice implements Id<Long> {
private String id;
private Long id;
private String deviceName;

View File

@ -8,5 +8,5 @@ import cc.iotkit.model.ota.OtaDevice;
* @Date: 2023/5/25 23:40
* @Description:
*/
public interface IOtaDeviceData extends ICommonData<OtaDevice, String> {
public interface IOtaDeviceData extends ICommonData<OtaDevice, Long> {
}

View File

@ -12,6 +12,4 @@ import java.util.List;
*/
public interface IOtaPackageData extends ICommonData<OtaPackage, Long> {
List<OtaPackage> findByVersionGreaterThan(String version);
}

View File

@ -21,7 +21,7 @@ public class TbOtaDevice {
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
private String id;
private Long id;
private String deviceName;

View File

@ -62,7 +62,6 @@ public class TbTaskInfo {
@ApiModelProperty(value = "任务输出")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String actions;
/**

View File

@ -28,7 +28,7 @@ import java.util.stream.Collectors;
*/
@Primary
@Service
public class IOtaDeviceDataImpl implements IOtaDeviceData, IJPACommData<OtaDevice, String> {
public class IOtaDeviceDataImpl implements IOtaDeviceData, IJPACommData<OtaDevice, Long> {
@Resource
private IOtaDeviceRepository iOtaDeviceRepository;
@ -47,45 +47,4 @@ public class IOtaDeviceDataImpl implements IOtaDeviceData, IJPACommData<OtaDevic
public Class getTClass() {
return OtaDevice.class;
}
@Override
public OtaDevice save(OtaDevice data) {
if (StringUtils.isBlank(data.getId())) {
data.setId(UUID.randomUUID().toString());
}
iOtaDeviceRepository.save(MapstructUtils.convert(data, TbOtaDevice.class));
return data;
}
@Override
public OtaDevice findById(String id) {
return MapstructUtils.convert(iOtaDeviceRepository.findById(id).orElse(null), OtaDevice.class);
}
@Override
public void deleteById(String id) {
iOtaDeviceRepository.deleteById(id);
}
@Override
public long count() {
return iOtaDeviceRepository.count();
}
@Override
public List<OtaDevice> findAll() {
return iOtaDeviceRepository.findAll().stream().map(e -> MapstructUtils.convert(e, OtaDevice.class))
.collect(Collectors.toList());
}
@Override
public Paging<OtaDevice> findAll(PageRequest<OtaDevice> pageRequest) {
Page<TbOtaDevice> tbOtaPackages = iOtaDeviceRepository.findAll(Pageable.ofSize(pageRequest.getPageSize()).withPage(pageRequest.getPageNum() - 1));
return new Paging<>(
tbOtaPackages.getTotalElements(),
tbOtaPackages.getContent()
.stream().map(e -> MapstructUtils.convert(e, OtaDevice.class))
.collect(Collectors.toList())
);
}
}

View File

@ -35,11 +35,6 @@ public class IOtaPackageDataImpl implements IOtaPackageData, IJPACommData<OtaPac
private final IOtaPackageRepository iOtaPackageRepository;
@Override
public List<OtaPackage> findByVersionGreaterThan(String version) {
return null;
}
@Override
public JpaRepository getBaseRepository() {
return iOtaPackageRepository;
@ -55,11 +50,6 @@ public class IOtaPackageDataImpl implements IOtaPackageData, IJPACommData<OtaPac
return OtaPackage.class;
}
@Override
public long count() {
return iOtaPackageRepository.count();
}
@Override
public List<OtaPackage> findAll() {
return iOtaPackageRepository.findAll().stream().map(e -> MapstructUtils.convert(e, OtaPackage.class)).collect(Collectors.toList());

View File

@ -9,12 +9,14 @@
*/
package cc.iotkit.data.service;
import cc.iotkit.common.utils.JsonUtils;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.ITaskInfoData;
import cc.iotkit.data.dao.TaskInfoRepository;
import cc.iotkit.data.model.TbTaskInfo;
import cc.iotkit.common.api.Paging;
import cc.iotkit.model.rule.RuleAction;
import cc.iotkit.model.rule.TaskInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
@ -27,6 +29,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Primary
@Service
@ -38,7 +41,8 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData<TaskInfo, S
@Override
public List<TaskInfo> findByUid(String uid) {
return MapstructUtils.convert(taskInfoRepository.findByUid(uid), TaskInfo.class);
return taskInfoRepository.findByUid(uid).stream().map(this::to)
.collect(Collectors.toList());
}
@Override
@ -46,7 +50,9 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData<TaskInfo, S
Page<TbTaskInfo> paged = taskInfoRepository.findByUid(uid,
Pageable.ofSize(size).withPage(page - 1));
return new Paging<>(paged.getTotalElements(),
MapstructUtils.convert(paged.getContent(), TaskInfo.class));
paged.getContent().stream().map(this::to)
.collect(Collectors.toList())
);
}
@Override
@ -71,23 +77,31 @@ public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData<TaskInfo, S
@Override
public TaskInfo findById(String s) {
return MapstructUtils.convert(taskInfoRepository.findById(s).orElse(null), TaskInfo.class);
return to(taskInfoRepository.findById(s).orElse(null));
}
@Override
public TaskInfo save(TaskInfo data) {
if (StringUtils.isBlank(data.getId())) {
data.setId(UUID.randomUUID().toString());
data.setCreateAt(System.currentTimeMillis());
}
taskInfoRepository.save(MapstructUtils.convert(data, TbTaskInfo.class));
taskInfoRepository.save(to(data));
return data;
}
private TaskInfo to(TbTaskInfo tb) {
TaskInfo convert = MapstructUtils.convert(tb, TaskInfo.class);
assert convert != null;
convert.setActions(JsonUtils.parseArray(tb.getActions(), RuleAction.class));
return convert;
}
private TbTaskInfo to(TaskInfo t) {
TbTaskInfo convert = MapstructUtils.convert(t, TbTaskInfo.class);
assert convert != null;
convert.setActions(JsonUtils.toJsonString(t.getActions()));
return convert;
}
}

View File

@ -69,10 +69,10 @@ public class OtaController {
return otaService.getOtaPackagePageList(request);
}
@ApiOperation("设备升级")
@ApiOperation("OTA升级")
@PostMapping("/device/upgrade")
public String deviceUpgrade(@RequestBody Request<DeviceUpgradeBo> request) {
return otaService.startUpgrade(request.getData().getOtaId(), request.getData().getDeviceId());
public void deviceUpgrade(@RequestBody Request<DeviceUpgradeBo> request) {
otaService.startUpgrade(request.getData().getOtaId(), request.getData().getDeviceIds());
}
@ApiOperation("设备升级结果查询")
@ -81,11 +81,4 @@ public class OtaController {
return otaService.otaResult(request);
}
@ApiOperation("OTA升级")
@PostMapping("/down")
public void ota(@RequestBody PageRequest<DeviceOtaInfoBo> request) {
otaService.startUpgrade(1L, "16870054884740abcd123456000000103");
}
}

View File

@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* @Author:
* @Date: 2023/6/16 21:13
@ -17,6 +19,6 @@ import lombok.EqualsAndHashCode;
@AutoMapper(target = DeviceUpgradeBo.class, reverseConvertGenerate = false)
public class DeviceUpgradeBo extends BaseDto {
private static final long serialVersionUID = -1L;
private String deviceId;
private List<String> deviceIds;
private Long otaId;
}

View File

@ -1,29 +1,17 @@
package cc.iotkit.manager.dto.bo.taskinfo;
import cc.iotkit.common.api.BaseDto;
import cc.iotkit.model.rule.RuleAction;
import cc.iotkit.model.rule.TaskInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.annotations.ReverseAutoMapping;
import jakarta.validation.constraints.Size;
import org.springframework.format.annotation.DateTimeFormat;
import io.github.linpeilie.annotations.AutoMapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import java.math.BigDecimal;
import cc.iotkit.common.api.BaseDto;
import cc.iotkit.common.validate.AddGroup;
import cc.iotkit.common.validate.EditGroup;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@ApiModel(value = "TaskInfoBo")
@Data
@ -37,10 +25,7 @@ public class TaskInfoBo extends BaseDto {
private String id;
@ApiModelProperty(value = "任务输出")
@Size(max = 65535, message = "任务输出长度不正确")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String actions;
private List<RuleAction> actions;
@ApiModelProperty(value = "创建时间")
private Long createAt;

View File

@ -1,5 +1,6 @@
package cc.iotkit.manager.dto.vo.taskinfo;
import cc.iotkit.model.rule.RuleAction;
import cc.iotkit.model.rule.TaskInfo;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.annotations.ReverseAutoMapping;
@ -11,6 +12,7 @@ import lombok.ToString;
import java.util.Date;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
@ -22,7 +24,6 @@ import io.github.linpeilie.annotations.AutoMapper;
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = TaskInfo.class)
public class TaskInfoVo implements Serializable {
private static final long serialVersionUID = -1L;
@ -33,9 +34,7 @@ public class TaskInfoVo implements Serializable {
@ApiModelProperty(value = "任务输出")
@ExcelProperty(value = "任务输出")
@AutoMapping(ignore = true)
@ReverseAutoMapping(ignore = true)
private String actions;
private List<RuleAction> actions;
@ApiModelProperty(value = "创建时间")
@ExcelProperty(value = "创建时间")

View File

@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
/**
@ -60,10 +61,6 @@ public class OtaService {
return Boolean.TRUE;
}
public void findByVersionGreaterThan(String version, String deviceId) {
iOtaPackageData.findByVersionGreaterThan(version);
}
public Paging<OtaPackage> getOtaPackagePageList(PageRequest<OtaPackage> request) {
return iOtaPackageData.findAll(request);
}
@ -71,10 +68,11 @@ public class OtaService {
/**
*
*/
public String startUpgrade(Long otaId, String deviceId) {
public void startUpgrade(Long otaId, List<String> deviceIds) {
OtaPackage otaPackage = iOtaPackageData.findById(otaId);
//构建升级包
return deviceService.otaUpgrade(deviceId, true, otaPackage);
deviceIds.forEach(deviceId -> {
deviceService.otaUpgrade(deviceId, true, otaPackage);
});
}
public Paging<DeviceOtaInfoVO> otaResult(PageRequest<DeviceOtaInfoBo> request) {