|
|
@@ -1,9 +1,14 @@
|
|
|
package com.dji.sample.manage.service.impl;
|
|
|
|
|
|
+import cn.hutool.extra.mail.MailUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.dji.sample.common.util.EmailUtil;
|
|
|
import com.dji.sample.component.mqtt.model.EventsReceiver;
|
|
|
+import com.dji.sample.component.oss.model.OssConfiguration;
|
|
|
+import com.dji.sample.component.oss.service.IOssService;
|
|
|
+import com.dji.sample.component.oss.service.impl.OssServiceContext;
|
|
|
import com.dji.sample.component.redis.RedisConst;
|
|
|
import com.dji.sample.component.redis.RedisOpsUtils;
|
|
|
import com.dji.sample.component.websocket.model.BizCodeEnum;
|
|
|
@@ -14,11 +19,13 @@ import com.dji.sample.manage.model.entity.DeviceLogsEntity;
|
|
|
import com.dji.sample.manage.model.enums.DeviceLogsStatusEnum;
|
|
|
import com.dji.sample.manage.model.enums.UserTypeEnum;
|
|
|
import com.dji.sample.manage.model.param.DeviceLogsCreateParam;
|
|
|
+import com.dji.sample.manage.model.param.DeviceLogsParam;
|
|
|
import com.dji.sample.manage.model.param.DeviceLogsQueryParam;
|
|
|
-import com.dji.sample.manage.service.IDeviceLogsService;
|
|
|
-import com.dji.sample.manage.service.IDeviceRedisService;
|
|
|
-import com.dji.sample.manage.service.ILogsFileService;
|
|
|
-import com.dji.sample.manage.service.ITopologyService;
|
|
|
+import com.dji.sample.manage.model.param.ManagerLogsQueryParam;
|
|
|
+import com.dji.sample.manage.service.*;
|
|
|
+import com.dji.sample.media.dao.IOssFileMapper;
|
|
|
+import com.dji.sample.media.model.MediaFileEntity;
|
|
|
+import com.dji.sample.media.model.OssFileEntity;
|
|
|
import com.dji.sample.storage.service.IStorageService;
|
|
|
import com.dji.sdk.cloudapi.log.*;
|
|
|
import com.dji.sdk.cloudapi.log.api.AbstractLogService;
|
|
|
@@ -85,6 +92,15 @@ public class DeviceLogsServiceImpl extends AbstractLogService implements IDevice
|
|
|
@Autowired
|
|
|
private AbstractLogService abstractLogService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OssServiceContext ossService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOssFileMapper ossFileMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDeviceService deviceService;
|
|
|
+
|
|
|
@Override
|
|
|
public PaginationData<DeviceLogsDTO> getUploadedLogs(String deviceSn, DeviceLogsQueryParam param) {
|
|
|
LambdaQueryWrapper<DeviceLogsEntity> queryWrapper = new LambdaQueryWrapper<DeviceLogsEntity>()
|
|
|
@@ -148,6 +164,7 @@ public class DeviceLogsServiceImpl extends AbstractLogService implements IDevice
|
|
|
@Override
|
|
|
public HttpResultResponse pushFileUpload(String username, String deviceSn, DeviceLogsCreateParam param) {
|
|
|
StsCredentialsResponse stsCredentials = storageService.getSTSCredentials();
|
|
|
+ stsCredentials.setBucket(OssConfiguration.bucketLogs);
|
|
|
stsCredentials.getCredentials().setExpire(System.currentTimeMillis() + (stsCredentials.getCredentials().getExpire() - 60) * 1000);
|
|
|
LogsUploadCredentialsDTO credentialsDTO = new LogsUploadCredentialsDTO(stsCredentials);
|
|
|
// Set the storage name of the file.
|
|
|
@@ -288,6 +305,137 @@ public class DeviceLogsServiceImpl extends AbstractLogService implements IDevice
|
|
|
return logsFileService.getLogsFileUrl(logsId, fileId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpResultResponse createLogs(String username, String deviceSn, DeviceLogsParam param) {
|
|
|
+
|
|
|
+ String jcUrl = null;
|
|
|
+ String fjUrl = null;
|
|
|
+ String ossUrls = null;
|
|
|
+ DeviceLogsEntity entity = DeviceLogsEntity.builder()
|
|
|
+ .deviceSn(deviceSn)
|
|
|
+ .username(username)
|
|
|
+ .happenTime(param.getHappenTime())
|
|
|
+ .logsInfo(Objects.requireNonNullElse(param.getLogsInfo(), ""))
|
|
|
+ .logsId(UUID.randomUUID().toString())
|
|
|
+ .contactEmail(Objects.requireNonNullElse(param.getContactEmail(), ""))
|
|
|
+ .contactNumber(Objects.requireNonNullElse(param.getContactNumber(), ""))
|
|
|
+ .ossIds(Objects.requireNonNullElse(param.getOssIds(), ""))
|
|
|
+ .status(DeviceLogsStatusEnum.UPLOADING.getVal())
|
|
|
+ .build();
|
|
|
+ mapper.insert(entity);
|
|
|
+ if(param.getList().size() > 0) {
|
|
|
+ StsCredentialsResponse stsCredentials = storageService.getSTSCredentials();
|
|
|
+ stsCredentials.setBucket(OssConfiguration.bucketLogs);
|
|
|
+ stsCredentials.getCredentials().setExpire(System.currentTimeMillis() + (stsCredentials.getCredentials().getExpire() - 60) * 1000);
|
|
|
+ LogsUploadCredentialsDTO credentialsDTO = new LogsUploadCredentialsDTO(stsCredentials);
|
|
|
+ // Set the storage name of the file.
|
|
|
+ List<FileUploadStartFile> files = paramToFiles(param.getList(),deviceSn);
|
|
|
+ files.forEach(file -> file.setObjectKey(credentialsDTO.getObjectKeyPrefix() + "/" + UUID.randomUUID().toString() + LOGS_FILE_SUFFIX));
|
|
|
+
|
|
|
+ credentialsDTO.setParams(new FileUploadStartParam().setFiles(files));
|
|
|
+
|
|
|
+ TopicServicesResponse<ServicesReplyData> response = abstractLogService.fileuploadStart(
|
|
|
+ SDKManager.getDeviceSDK(deviceSn), new FileUploadStartRequest()
|
|
|
+ .setCredentials(stsCredentials.getCredentials())
|
|
|
+ .setBucket(stsCredentials.getBucket())
|
|
|
+ .setEndpoint(stsCredentials.getEndpoint())
|
|
|
+ .setFileStoreDir(stsCredentials.getObjectKeyPrefix())
|
|
|
+ .setProvider(stsCredentials.getProvider())
|
|
|
+ .setRegion(stsCredentials.getRegion())
|
|
|
+ .setParams(new FileUploadStartParam().setFiles(files)));
|
|
|
+
|
|
|
+ if (!response.getData().getResult().isSuccess()) {
|
|
|
+ return HttpResultResponse.error(response.getData().getResult());
|
|
|
+ }
|
|
|
+
|
|
|
+ for (FileUploadStartFile file : files) {
|
|
|
+ String url = ossService.getObjectUrl(OssConfiguration.bucketLogs, file.getObjectKey()).toString();
|
|
|
+ if(file.getModule().getDomain().equals("0")) {
|
|
|
+ if (fjUrl == null) {
|
|
|
+ fjUrl = url;
|
|
|
+ } else {
|
|
|
+ fjUrl = fjUrl + "," + url;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (jcUrl == null) {
|
|
|
+ jcUrl = url;
|
|
|
+ } else {
|
|
|
+ jcUrl = jcUrl + "," + url;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ logsFileService.insertFile(file, entity.getLogsId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // Save the status of the log upload.
|
|
|
+ RedisOpsUtils.hashSet(RedisConst.LOGS_FILE_PREFIX + deviceSn, response.getBid(), LogsOutputProgressDTO.builder().logsId(response.getBid()).build());
|
|
|
+ }
|
|
|
+ if(param.getOssIds() != null) {
|
|
|
+ String[] ids = param.getOssIds().split(",");
|
|
|
+ for(String id : ids) {
|
|
|
+ OssFileEntity ossFileEntity = ossFileMapper.selectById(id);
|
|
|
+ if(ossFileEntity != null) {
|
|
|
+ if( ossUrls == null) {
|
|
|
+ ossUrls = ossFileEntity.getUrl();
|
|
|
+ } else {
|
|
|
+ ossUrls = ossUrls + "," + ossFileEntity.getUrl();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ EmailUtil.sendHtmlDj(ossUrls,fjUrl,jcUrl,entity);
|
|
|
+ return HttpResultResponse.success();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PaginationData<DeviceLogsRespDTO> getLogsList(ManagerLogsQueryParam param) {
|
|
|
+ LambdaQueryWrapper<DeviceLogsEntity> queryWrapper = new LambdaQueryWrapper<DeviceLogsEntity>()
|
|
|
+ .between(Objects.nonNull(param.getBeginTime()) && Objects.nonNull(param.getEndTime()),
|
|
|
+ DeviceLogsEntity::getCreateTime, param.getBeginTime(), param.getEndTime())
|
|
|
+ .eq(Objects.nonNull(param.getStatus()), DeviceLogsEntity::getStatus, param.getStatus())
|
|
|
+ .eq(Objects.nonNull(param.getUsername()), DeviceLogsEntity::getUsername, param.getUsername())
|
|
|
+ .eq(Objects.nonNull(param.getStatus()), DeviceLogsEntity::getStatus, param.getStatus())
|
|
|
+ .and(StringUtils.hasText(param.getSearchInfo()),
|
|
|
+ wrapper -> wrapper.like( DeviceLogsEntity::getDeviceSn, param.getSearchInfo())
|
|
|
+ .or().like( DeviceLogsEntity::getLogsInfo, param.getSearchInfo())
|
|
|
+ )
|
|
|
+ .orderByDesc(DeviceLogsEntity::getCreateTime);
|
|
|
+
|
|
|
+ Page<DeviceLogsEntity> pagination = mapper.selectPage(new Page<>(param.getPage(), param.getPageSize()), queryWrapper);
|
|
|
+
|
|
|
+ List<DeviceLogsRespDTO> deviceLogsList = pagination.getRecords().stream().map(this::entity2RespDto).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new PaginationData<DeviceLogsRespDTO>(deviceLogsList, new Pagination(pagination.getCurrent(), pagination.getSize(), pagination.getTotal()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DeviceLogsDetailRespDTO getLogsDetail(String logsId) {
|
|
|
+ DeviceLogsDetailRespDTO deviceLogsDetailRespDTO = new DeviceLogsDetailRespDTO();
|
|
|
+ LambdaQueryWrapper<DeviceLogsEntity> queryWrapper = new LambdaQueryWrapper<DeviceLogsEntity>();
|
|
|
+ queryWrapper.eq(DeviceLogsEntity::getLogsId,logsId);
|
|
|
+ DeviceLogsEntity deviceLogsEntity = mapper.selectOne(queryWrapper);
|
|
|
+ if(deviceLogsEntity != null) {
|
|
|
+ deviceLogsDetailRespDTO.setLogsInfo(deviceLogsEntity.getLogsInfo());
|
|
|
+ deviceLogsDetailRespDTO.setContactEmail(deviceLogsEntity.getContactEmail());
|
|
|
+ deviceLogsDetailRespDTO.setContactNumber(deviceLogsEntity.getContactNumber());
|
|
|
+ deviceLogsDetailRespDTO.setHappenTime(deviceLogsEntity.getHappenTime());
|
|
|
+ if(deviceLogsEntity.getOssIds() != null) {
|
|
|
+ List<String> urlList = new ArrayList<>();
|
|
|
+ String[] ossIds = deviceLogsEntity.getOssIds().split(",");
|
|
|
+ for (String ossId : ossIds) {
|
|
|
+ OssFileEntity ossFileEntity = ossFileMapper.selectById(ossId);
|
|
|
+ urlList.add(ossFileEntity.getUrl());
|
|
|
+ }
|
|
|
+ deviceLogsDetailRespDTO.setOssUrls(urlList);
|
|
|
+ }
|
|
|
+ List<LogsFileUploadDTO> logFileIndexList = logsFileService.getLogsFileByLogsId(logsId);
|
|
|
+ deviceLogsDetailRespDTO.setList(logFileIndexList);
|
|
|
+
|
|
|
+ }
|
|
|
+ return deviceLogsDetailRespDTO;
|
|
|
+ }
|
|
|
+
|
|
|
private DeviceLogsDTO entity2Dto(DeviceLogsEntity entity) {
|
|
|
if (Objects.isNull(entity)) {
|
|
|
return null;
|
|
|
@@ -311,4 +459,48 @@ public class DeviceLogsServiceImpl extends AbstractLogService implements IDevice
|
|
|
.deviceTopo(topologyService.getDeviceTopologyByGatewaySn(entity.getDeviceSn()).orElse(null))
|
|
|
.build();
|
|
|
}
|
|
|
+
|
|
|
+ private List<FileUploadStartFile> paramToFiles(List<FileUploadFile> list,String deviceSn) {
|
|
|
+ List<FileUploadStartFile> result = new ArrayList<>();
|
|
|
+ for(FileUploadFile fileUploadFile : list) {
|
|
|
+ FileUploadStartFile fileUploadStartFile = new FileUploadStartFile();
|
|
|
+ List<LogFileIndex> fileIndexList = new ArrayList<>();
|
|
|
+ List<LogFileIndexDTO> dtoList = fileUploadFile.getList();
|
|
|
+ fileUploadStartFile.setDeviceSn(deviceSn);
|
|
|
+ fileUploadStartFile.setModule(fileUploadFile.getModule());
|
|
|
+ for (LogFileIndexDTO dto : dtoList) {
|
|
|
+ LogFileIndex logFileIndex = new LogFileIndex();
|
|
|
+ logFileIndex.setBootIndex(dto.getBootIndex());
|
|
|
+ logFileIndex.setSize(dto.getSize());
|
|
|
+ logFileIndex.setEndTime(dto.getEndTime());
|
|
|
+ logFileIndex.setStartTime(dto.getStartTime());
|
|
|
+ fileIndexList.add(logFileIndex);
|
|
|
+ }
|
|
|
+ fileUploadStartFile.setList(fileIndexList);
|
|
|
+ result.add(fileUploadStartFile);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private DeviceLogsRespDTO entity2RespDto(DeviceLogsEntity entity) {
|
|
|
+ if (Objects.isNull(entity)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Optional<DeviceDTO> deviceDTO = deviceService.getDeviceBySn(entity.getDeviceSn());
|
|
|
+
|
|
|
+ return DeviceLogsRespDTO.builder()
|
|
|
+ .logsId(entity.getLogsId())
|
|
|
+ .createTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(entity.getCreateTime()), ZoneId.systemDefault()))
|
|
|
+ .happenTime(Objects.isNull(entity.getHappenTime()) ?
|
|
|
+ null : LocalDateTime.ofInstant(Instant.ofEpochMilli(entity.getHappenTime()), ZoneId.systemDefault()))
|
|
|
+ .status(entity.getStatus())
|
|
|
+ .logsInfo(entity.getLogsInfo())
|
|
|
+ .userName(entity.getUsername())
|
|
|
+ .deviceSn(entity.getDeviceSn())
|
|
|
+ .deviceName(Objects.isNull(deviceDTO.get()) ? null : deviceDTO.get().getDeviceName())
|
|
|
+ .nickName(Objects.isNull(deviceDTO.get()) ? null : deviceDTO.get().getNickname())
|
|
|
+ .firmwareVersion(Objects.isNull(deviceDTO.get()) ? null : deviceDTO.get().getFirmwareVersion())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
}
|