diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java index 353db6a..93fb744 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java @@ -27,7 +27,7 @@ import com.hnac.hzinfo.inspect.plan.vo.PlanOfflineVO; import com.hnac.hzinfo.inspect.task.entity.*; import com.hnac.hzinfo.inspect.task.service.*; import com.hnac.hzinfo.inspect.task.vo.TaskObjectOfflineVO; -import com.hnac.hzinfo.inspect.areamonthly.vo.TaskObjectProjectOfflineVO; +import com.hnac.hzinfo.inspect.task.vo.TaskObjectProjectOfflineVO; import com.hnac.hzinfo.inspect.task.vo.TaskOfflineVO; import com.hnac.hzinfo.inspect.utils.JsonFileUtil; import lombok.RequiredArgsConstructor; @@ -430,7 +430,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { eq(ContentEntity::getTenantId, tenantId); }}); // 返回数据 - return contents.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return contents.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } /** @@ -447,7 +447,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { eq(ObjectDangerEntity::getTenantId, tenantId); }}); // 返回数据 - return dangers.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return dangers.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } @@ -466,7 +466,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { eq(OfflineTaskEntity::getId, taskId); }}); // 返回数据 - return tasks.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return tasks.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } @@ -482,7 +482,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { List taskUsers = this.taskUserService.getOfflineTaskUser(taskIds); // 返回数据 - return taskUsers.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return taskUsers.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } /** @@ -496,7 +496,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { // 查询巡检任务 List tasks = taskService.getTaskData(taskId,currentDate); // 返回数据 - return tasks.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return tasks.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } /** @@ -510,7 +510,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { } List tasks = planService.getPlans(planIds); // 返回数据 - return tasks.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return tasks.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } @@ -527,7 +527,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { List events = eventService.list(new LambdaQueryWrapper() {{ in(EventEntity::getTaskId, taskIds); }}); - return events.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return events.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } /** @@ -543,7 +543,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { List eventAttachments = eventAttachmentService.list(new LambdaQueryWrapper() {{ in(EventAttachmentEntity::getEventId, eventIds); }}); - return eventAttachments.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return eventAttachments.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } /** @@ -559,7 +559,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { in(EventRecordEntity::getEventId, eventIds); }}); // 返回数据 - return eventRecords.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return eventRecords.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } /** @@ -574,7 +574,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { // 查询巡检任务对象 List taskObjects = taskObjectService.getExObjectData(taskIds); // 返回数据 - return taskObjects.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); + return taskObjects.stream().map(item -> this.convertFileOrVideo(item)).collect(Collectors.toList()); } /** @@ -603,9 +603,9 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { } // 查询巡检任务内容 List contents = taskObjectProjectContentService.list( - new LambdaQueryWrapper() {{ - in(TaskObjectProjectContentEntity::getTaskId, taskIds); - }}); + new LambdaQueryWrapper() {{ + in(TaskObjectProjectContentEntity::getTaskId, taskIds); + }}); // 返回数据 return contents.stream().map(this::convertFileOrVideo).collect(Collectors.toList()); } @@ -687,12 +687,12 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { } - /** - * 下载文件 - * @param fileUrl - * @param downloadFileDir - * @return - */ + /** + * 下载文件 + * @param fileUrl + * @param downloadFileDir + * @return + */ private String downloadFileByUrl(String fileUrl, String downloadFileDir){ URL url = null; String fileName = null; @@ -832,6 +832,9 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { List taskObjects = JsonFileUtil.readJsonFile(upload + "/HZ_ST_EX_OBJECT.json", TaskObjectSyncBO.class); List projectContents = JsonFileUtil.readJsonFile(upload + "/HZ_ST_EX_OBJECT_PROJECT_CONTENT.json", TaskObjectProjectContentBO.class); + // 内容图片 + this.batchCurrentImg(upload, eventRecords); + // 文件上传 this.batchUploadImg(upload, eventRecords); this.batchUploadImg(upload, eventAttachments); @@ -873,6 +876,49 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { } /** + * 上传内容文件 + * + * @param sourceDir + * @param data + */ + private void batchCurrentImg(String sourceDir, List data) { + if (CollectionUtil.isEmpty(data)) { + return; + } + + data.forEach(bo -> { + if (CollectionUtil.isEmpty(bo.getCurrentValues())) { + return; + } + List urls = bo.getCurrentValues().stream().map(o -> { + if (StringUtils.isBlank(o) || !o.contains("file:")) { + return null; + } + /**wxq begin**/ + String fileName = o.substring(o.lastIndexOf("/") >= 0 ? o.lastIndexOf("/") + 1 : 0); + File file = new File(sourceDir + "/" + fileName); + if (!file.exists()) { + throw new RuntimeException("文件名称为:" + fileName + "不存在,上传失败!"); + } + R r = null; + try { + MultipartFile multipartFile = this.getMultipartFile(file); + r = ossClient.putFile(multipartFile); + if (!r.isSuccess()) { + throw new RuntimeException("上传文件["+fileName+"]失败,bladex-resource报错:" + r.toString()); + } + BladeFile bladeFile = r.getData(); + return bladeFile != null ? bladeFile.getLink() : null; + } catch (Exception ex) { + throw new RuntimeException("上传文件["+fileName+"]失败,bladex-resource报错:" + r.toString(), ex); + } + }).filter(StringUtils::isNotBlank).collect(Collectors.toList()); + bo.setCurrentValues(urls); + }); + + } + + /** * 上传文件 * * @param sourceDir @@ -909,10 +955,9 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { } catch (Exception ex) { throw new RuntimeException("上传文件["+fileName+"]失败,bladex-resource报错:" + r.toString(), ex); } - }).filter(o -> StringUtils.isNotBlank(o)).collect(Collectors.toList()); + }).filter(StringUtils::isNotBlank).collect(Collectors.toList()); bo.setFiles(urls); }); - } private MultipartFile getMultipartFile(File file) { @@ -926,7 +971,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { FileItemFactory factory = new DiskFileItemFactory(16, null); String textFieldName = "file"; FileItem item = factory.createItem(textFieldName, "text/plain", false, - file.getName()); + file.getName()); int bytesRead = 0; byte[] buffer = new byte[1024]; FileInputStream fis = null; @@ -958,3 +1003,4 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { } } + diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/sync/EventRecordSyncBO.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/sync/EventRecordSyncBO.java index c90b919..1cc9c64 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/sync/EventRecordSyncBO.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/sync/EventRecordSyncBO.java @@ -40,4 +40,20 @@ public class EventRecordSyncBO extends EventRecordEntity implements SyncBO { super.setFileUrl(urls.get(0)); } } + + @Override + public List getCurrentValues() { + return new ArrayList() {{ + if (StringUtil.isNotBlank(getCurrentValue())) { + add(getCurrentValue()); + } + }}; + } + + @Override + public void setCurrentValues(List urls) { + if (CollectionUtil.isNotEmpty(urls)) { + super.setCurrentValue(urls.get(0)); + } + } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/sync/SyncBO.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/sync/SyncBO.java index 628053e..02fce35 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/sync/SyncBO.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/sync/SyncBO.java @@ -15,6 +15,15 @@ public interface SyncBO { default void setFiles(List urls) { } + + default List getCurrentValues() { + return null; + } + + default void setCurrentValues(List urls) { + + } + Object getPrimaryKey(); Integer getOfflineFlag(); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java index 554173d..151beb8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java @@ -213,7 +213,7 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl