diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOta.java b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOta.java new file mode 100644 index 00000000..5d83ae4a --- /dev/null +++ b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOta.java @@ -0,0 +1,14 @@ +package cc.iotkit.model.ota; + +import lombok.Data; + +/** + * @Author: 石恒 + * @Date: 2023/6/10 14:36 + * @Description: + */ +@Data +public class DeviceOta { + private String currentVersion; + private String deviceId; +} \ No newline at end of file diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaDevice.java b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaDevice.java new file mode 100644 index 00000000..873b88fc --- /dev/null +++ b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaDevice.java @@ -0,0 +1,32 @@ +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/10 14:36 + * @Description: + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class OtaDevice implements Id { + + private String id; + + private String deviceName; + + private String deviceId; + + private String version; + + private Integer status; + + private Long createAt; +} + diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java new file mode 100644 index 00000000..64aa5e81 --- /dev/null +++ b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java @@ -0,0 +1,35 @@ +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/10 14:35 + * @Description: + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class OtaPackage implements Id { + + private String id; + + private Long size; + + private String sign; + + private String name; + + private String desc; + + private String version; + + private String url; + + private Long createAt; +} diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaDeviceData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaDeviceData.java new file mode 100644 index 00000000..2da1a298 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaDeviceData.java @@ -0,0 +1,12 @@ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.ota.OtaDevice; + +/** + * @Author: 石恒 + * @Date: 2023/5/25 23:40 + * @Description: + */ +public interface IOtaDeviceData extends ICommonData { +} diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java new file mode 100644 index 00000000..520e308a --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java @@ -0,0 +1,17 @@ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.ota.OtaPackage; + +import java.util.List; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 21:46 + * @Description: + */ +public interface IOtaPackageData extends ICommonData { + + List findByVersionGreaterThan(String version); + +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaDeviceRepository.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaDeviceRepository.java new file mode 100644 index 00000000..a1598ef7 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaDeviceRepository.java @@ -0,0 +1,12 @@ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbOtaDevice; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Author: 石恒 + * @Date: 2023/5/25 23:43 + * @Description: + */ +public interface IOtaDeviceRepository extends JpaRepository { +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaPackageRepository.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaPackageRepository.java new file mode 100644 index 00000000..bcd48d87 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaPackageRepository.java @@ -0,0 +1,16 @@ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbOtaPackage; +import cc.iotkit.model.ota.OtaPackage; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 21:54 + * @Description: + */ +public interface IOtaPackageRepository extends JpaRepository { + List findByVersionGreaterThan(String version); +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaDevice.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaDevice.java new file mode 100644 index 00000000..82febd74 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaDevice.java @@ -0,0 +1,31 @@ +package cc.iotkit.data.model; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * @Author: 石恒 + * @Date: 2023/5/25 23:26 + * @Description: + */ +@Data +@Entity +@Table(name = "ota_device") +public class TbOtaDevice { + + @Id + private String id; + + private String deviceName; + + private String deviceId; + + private String version; + + private Integer status; + + private Long createAt; +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java new file mode 100644 index 00000000..54ca0459 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java @@ -0,0 +1,35 @@ +package cc.iotkit.data.model; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 21:25 + * @Description: + */ +@Data +@Entity +@Table(name = "ota_package") +public class TbOtaPackage { + + @Id + private String id; + + private Long size; + + private String sign; + + private String name; + + private String desc; + + private String version; + + private String url; + + private Long createAt; +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaDeviceDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaDeviceDataImpl.java new file mode 100644 index 00000000..6dfba6f9 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaDeviceDataImpl.java @@ -0,0 +1,91 @@ +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.IOtaDeviceRepository; +import cc.iotkit.data.manager.IOtaDeviceData; +import cc.iotkit.data.model.TbOtaDevice; +import cc.iotkit.model.ota.OtaDevice; +import cc.iotkit.model.space.Home; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * @Author: 石恒 + * @Date: 2023/5/25 23:41 + * @Description: + */ +@Primary +@Service +public class IOtaDeviceDataImpl implements IOtaDeviceData, IJPACommData { + + @Resource + private IOtaDeviceRepository iOtaDeviceRepository; + + @Override + public JpaRepository getBaseRepository() { + return iOtaDeviceRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbOtaDevice.class; + } + + @Override + 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 findAll() { + return iOtaDeviceRepository.findAll().stream().map(e -> MapstructUtils.convert(e, OtaDevice.class)) + .collect(Collectors.toList()); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + Page 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()) + ); + } +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java new file mode 100644 index 00000000..08aff388 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java @@ -0,0 +1,91 @@ +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.IOtaPackageRepository; +import cc.iotkit.data.manager.IOtaPackageData; +import cc.iotkit.data.model.TbOtaDevice; +import cc.iotkit.data.model.TbOtaPackage; +import cc.iotkit.model.ota.OtaDevice; +import cc.iotkit.model.ota.OtaPackage; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 21:53 + * @Description: + */ +@Primary +@Service +public class IOtaPackageDataImpl implements IOtaPackageData, IJPACommData { + + @Resource + private IOtaPackageRepository iOtaPackageRepository; + + @Override + public List findByVersionGreaterThan(String version) { + return null; + } + + @Override + public JpaRepository getBaseRepository() { + return iOtaPackageRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbOtaPackage.class; + } + + @Override + public Class getTClass() { + 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 + public long count() { + return iOtaPackageRepository.count(); + } + + @Override + public List findAll() { + return iOtaPackageRepository.findAll().stream().map(e -> MapstructUtils.convert(e, OtaPackage.class)).collect(Collectors.toList()); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + Page tbOtaPackages = iOtaPackageRepository.findAll(Pageable.ofSize(pageRequest.getPageSize()).withPage(pageRequest.getPageNum() - 1)); + return new Paging<>(tbOtaPackages.getTotalElements(), tbOtaPackages.getContent().stream().map(e -> MapstructUtils.convert(e, OtaPackage.class)).collect(Collectors.toList())); + } +} diff --git a/iot-module/iot-manager/pom.xml b/iot-module/iot-manager/pom.xml index 58d16560..4927ecf0 100644 --- a/iot-module/iot-manager/pom.xml +++ b/iot-module/iot-manager/pom.xml @@ -59,6 +59,12 @@ iot-rule-engine + + cc.iotkit + iot-component-oss + ${revision} + + cc.iotkit iot-component-server diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java index a2f42892..9e300c64 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java @@ -1,12 +1,24 @@ package cc.iotkit.manager.controller; +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; import cc.iotkit.manager.service.OtaService; +import cc.iotkit.model.ota.DeviceOta; +import cc.iotkit.model.ota.OtaPackage; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.validation.Valid; +import java.io.InputStream; /** * @Author: 石恒 @@ -22,7 +34,7 @@ public class OtaController { @Resource private OtaService otaService; - /*@ApiOperation("升级包上传") + @ApiOperation("升级包上传") @PostMapping("/package/upload") public String packageUpload(MultipartFile file) throws Exception { if (!file.isEmpty()) { @@ -49,7 +61,7 @@ public class OtaController { @ApiOperation("升级包列表") @PostMapping("/package/getList") public Paging packageList(@RequestBody @Valid PageRequest request) { - return otaService.getOtaPackagePageList(request.getPageNo(), request.getPageSize()); + return null; } @ApiOperation("设备获取升级包") @@ -57,5 +69,5 @@ public class OtaController { public void deviceUpgrade(@RequestBody Request deviceOtaRequest) { DeviceOta deviceOta = deviceOtaRequest.getData(); otaService.findByVersionGreaterThan(deviceOta.getCurrentVersion(), deviceOta.getDeviceId()); - }*/ + } } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java index 0aea8f7a..99dd6acf 100644 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java @@ -1,9 +1,16 @@ package cc.iotkit.manager.service; +import cc.iotkit.data.manager.IOtaDeviceData; +import cc.iotkit.data.manager.IOtaPackageData; +import cc.iotkit.model.ota.OtaPackage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.io.InputStream; +import java.util.UUID; + /** * @Author: 石恒 * @Date: 2023/5/19 20:49 @@ -14,5 +21,34 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class OtaService { + private final IOtaPackageData iOtaPackageData; + private final IOtaDeviceData iOtaDeviceData; + + + @Value("${oss.region}") + private String region; + @Value("${oss.buckName}") + private String buckName; + + public String uploadFile(InputStream inputStream, String suffix) throws Exception { + String objectName = UUID.randomUUID().toString().replaceAll("-", "") + suffix; + return "https://" + region + "/" + objectName; + } + + public OtaPackage addOtaPackage(OtaPackage otaPackage) { + return iOtaPackageData.save(otaPackage); + } + + public Boolean delOtaPackageById(String id) { + iOtaPackageData.deleteById(id); + return Boolean.TRUE; + } + + public void findByVersionGreaterThan(String version, String deviceId) { + iOtaPackageData.findByVersionGreaterThan(version); + } + + public void batchOta() { + } } diff --git a/iot-starter/src/main/resources/application-dev.yml b/iot-starter/src/main/resources/application-dev.yml index c268d301..bccf5b9c 100644 --- a/iot-starter/src/main/resources/application-dev.yml +++ b/iot-starter/src/main/resources/application-dev.yml @@ -117,3 +117,10 @@ sa-token: #认证中心地址 oauth2: auth-server-url: http://127.0.0.1:8086 + +oss: + region: xxxxx + endpoint: xxxxx + accessKey: xxxxx + secretKey: xxxxx + buckName: xxxx \ No newline at end of file diff --git a/iot-starter/src/main/resources/application-mysql.yml b/iot-starter/src/main/resources/application-mysql.yml index b21b8363..abc47774 100644 --- a/iot-starter/src/main/resources/application-mysql.yml +++ b/iot-starter/src/main/resources/application-mysql.yml @@ -91,3 +91,10 @@ sa-token: #认证中心地址 oauth2: auth-server-url: http://127.0.0.1:8086 + +oss: + region: xxxxx + endpoint: xxxxx + accessKey: xxxxx + secretKey: xxxxx + buckName: xxxx \ No newline at end of file diff --git a/iot-starter/src/main/resources/application.yml b/iot-starter/src/main/resources/application.yml index 01e99ef5..c483c106 100644 --- a/iot-starter/src/main/resources/application.yml +++ b/iot-starter/src/main/resources/application.yml @@ -153,3 +153,10 @@ user: maxRetryCount: 5 # 密码锁定时间(默认10分钟) lockTime: 10 + +oss: + region: xxxxx + endpoint: xxxxx + accessKey: xxxxx + secretKey: xxxxx + buckName: xxxx \ No newline at end of file