diff --git a/nursing-unit-common/src/main/java/com/nu/dto/DirectiveAsyncMQDto.java b/nursing-unit-common/src/main/java/com/nu/dto/DirectiveAsyncMQDto.java index 088652c..d79eb23 100644 --- a/nursing-unit-common/src/main/java/com/nu/dto/DirectiveAsyncMQDto.java +++ b/nursing-unit-common/src/main/java/com/nu/dto/DirectiveAsyncMQDto.java @@ -150,4 +150,6 @@ public class DirectiveAsyncMQDto implements Serializable { private String bodyTagsObj; //情绪标签json字符串(有id、label) private String emotionTagsObj; + //资源请求接口域名+项目上下文路径 + private String api; } diff --git a/nursing-unit-common/src/main/java/com/nu/dto/DirectiveMQDto.java b/nursing-unit-common/src/main/java/com/nu/dto/DirectiveMQDto.java index 5116c58..d934bef 100644 --- a/nursing-unit-common/src/main/java/com/nu/dto/DirectiveMQDto.java +++ b/nursing-unit-common/src/main/java/com/nu/dto/DirectiveMQDto.java @@ -28,4 +28,6 @@ public class DirectiveMQDto { private List bodyTagList; //情绪标签字典项 private List emotionTagList; + //是否同步指令资源 + private boolean izSyncMedia; } diff --git a/nursing-unit-services/nu-services-biz/src/main/java/com/nu/mq/directive/listener/DirectiveMQListener.java b/nursing-unit-services/nu-services-biz/src/main/java/com/nu/mq/directive/listener/DirectiveMQListener.java index d256b84..1a418ce 100644 --- a/nursing-unit-services/nu-services-biz/src/main/java/com/nu/mq/directive/listener/DirectiveMQListener.java +++ b/nursing-unit-services/nu-services-biz/src/main/java/com/nu/mq/directive/listener/DirectiveMQListener.java @@ -86,6 +86,142 @@ public class DirectiveMQListener { dto.setIdStr(dto.getDirectiveList().stream().map(d -> d.getId()).collect(Collectors.joining(","))); //增量处理 handleIncremental(dto); + handleCreateMedia(dto); + } + + /** + * 拉取指令资源 + * + * @param mqDto + */ + @RabbitListener( + bindings = @QueueBinding( + value = @Queue(name = "#{directiveAsyncDQNP.getCreateMediaQueueName()}"), + exchange = @Exchange(name = "hldy.directive", type = ExchangeTypes.DIRECT), + key = "#{directiveAsyncDQNP.getCreateMediaKeyName()}" + ), + errorHandler = "directiveMQErrorHandler" + ) + public void handleCreateMedia(DirectiveMQDto mqDto) { + mqDto.getDirectiveList().stream().forEach(dto -> { + //查询现有服务指令 + QueryWrapper qw = new QueryWrapper<>(); + qw.eq("id", dto.getId()); + ConfigServiceDirective currentDirective = directiveService.getOne(qw); + + //更新服务指令媒体资源字段 + ConfigServiceDirective configServiceDirective = new ConfigServiceDirective(); + configServiceDirective.setId(dto.getId()); + configServiceDirective.setServiceContent(dto.getServiceContent());//服务指令说明 + + //拉取媒体资源至本地目录 + { + //接口协议域名+上下文访问路径 + String baseUrl = dto.getApi(); + + //处理服务指令图片 + if (!dto.getPreviewFileMd5().equals(currentDirective.getPreviewFileMd5())) { + String previewFile = dto.getPreviewFile(); + if (StringUtils.isNotBlank(previewFile)) { + String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(previewFile, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); + if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { + upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); + } + String filePath = previewFile.substring(0, previewFile.lastIndexOf("/")); + String fileName = previewFile.substring(previewFile.lastIndexOf("/") + 1); + if (filePath.startsWith("/") || filePath.startsWith("\\")) { + filePath = filePath.substring(1); + } + try { + FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); + configServiceDirective.setPreviewFile(dto.getPreviewFile());//服务指令图片 + configServiceDirective.setPreviewFileMd5(dto.getPreviewFileMd5()); + } catch (Exception e) { + e.printStackTrace(); + MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); + mediaAsyncErrorLog.setMediaid(previewFile); + mediaAsyncErrorLogService.save(mediaAsyncErrorLog); + } + } + } + //处理即时指令图标 + if (!dto.getImmediateFileMd5().equals(currentDirective.getImmediateFileMd5())) { + String immediateFile = dto.getImmediateFile(); + if (StringUtils.isNotBlank(immediateFile)) { + String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(immediateFile, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); + if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { + upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); + } + String filePath = immediateFile.substring(0, immediateFile.lastIndexOf("/")); + String fileName = immediateFile.substring(immediateFile.lastIndexOf("/") + 1); + if (filePath.startsWith("/") || filePath.startsWith("\\")) { + filePath = filePath.substring(1); + } + try { + FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); + configServiceDirective.setImmediateFile(dto.getImmediateFile());//即时指令图标 + configServiceDirective.setImmediateFileMd5(dto.getImmediateFileMd5()); + } catch (Exception e) { + MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); + mediaAsyncErrorLog.setMediaid(immediateFile); + mediaAsyncErrorLogService.save(mediaAsyncErrorLog); + e.printStackTrace(); + } + } + } + //处理指令音频文件 + if (!dto.getMp3FileMd5().equals(currentDirective.getMp3FileMd5())) { + String mp3File = dto.getMp3File(); + if (StringUtils.isNotBlank(mp3File)) { + String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(mp3File, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); + if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { + upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); + } + String filePath = mp3File.substring(0, mp3File.lastIndexOf("/")); + String fileName = mp3File.substring(mp3File.lastIndexOf("/") + 1); + if (filePath.startsWith("/") || filePath.startsWith("\\")) { + filePath = filePath.substring(1); + } + try { + FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); + configServiceDirective.setMp3File(dto.getMp3File());//指令音频文件 + configServiceDirective.setMp3FileMd5(dto.getMp3FileMd5()); + } catch (Exception e) { + MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); + mediaAsyncErrorLog.setMediaid(mp3File); + mediaAsyncErrorLogService.save(mediaAsyncErrorLog); + e.printStackTrace(); + } + } + } + //处理指令视频文件 + if (!dto.getMp4FileMd5().equals(currentDirective.getMp4FileMd5())) { + String mp4File = dto.getMp4File(); + if (StringUtils.isNotBlank(mp4File)) { + String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(mp4File, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); + if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { + upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); + } + String filePath = mp4File.substring(0, mp4File.lastIndexOf("/")); + String fileName = mp4File.substring(mp4File.lastIndexOf("/") + 1); + if (filePath.startsWith("/") || filePath.startsWith("\\")) { + filePath = filePath.substring(1); + } + try { + FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); + configServiceDirective.setMp4File(dto.getMp4File());//指令视频文件 + configServiceDirective.setMp4FileMd5(dto.getMp4FileMd5()); + } catch (Exception e) { + MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); + mediaAsyncErrorLog.setMediaid(mp4File); + mediaAsyncErrorLogService.save(mediaAsyncErrorLog); + e.printStackTrace(); + } + } + } + directiveService.updateById(configServiceDirective); + } + }); } // @RabbitListener( // bindings = @QueueBinding( @@ -105,127 +241,127 @@ public class DirectiveMQListener { // directiveService.updateById(configServiceDirective); // } // - @RabbitListener( - bindings = @QueueBinding( - value = @Queue(name = "#{directiveAsyncDQNP.getCreateMediaQueueName()}"), - exchange = @Exchange(name = "hldy.directive", type = ExchangeTypes.DIRECT), - key = "#{directiveAsyncDQNP.getCreateMediaKeyName()}" - ), - errorHandler = "directiveMQErrorHandler" - ) - public void handleCreateMedia(DirectiveAsyncMQDto dto) { - //更新服务指令媒体资源字段 - ConfigServiceDirective configServiceDirective = new ConfigServiceDirective(); - configServiceDirective.setId(dto.getId()); - configServiceDirective.setPreviewFile(dto.getPreviewFile());//服务指令图片 - configServiceDirective.setServiceContent(dto.getServiceContent());//服务指令说明 - configServiceDirective.setImmediateFile(dto.getImmediateFile());//即时指令图标 - configServiceDirective.setMp3File(dto.getMp3File());//指令音频文件 - configServiceDirective.setMp4File(dto.getMp4File());//指令视频文件 - directiveService.updateById(configServiceDirective); - - //拉取媒体资源至本地目录 - { - LambdaQueryWrapper qw = new LambdaQueryWrapper<>(); - qw.eq(SysConfig::getDelFlag, "0"); - qw.eq(SysConfig::getConfigKey, "ope_open_url"); - SysConfig urlObj = sysConfigService.getOne(qw); - //试验田协议+域名(/ip+端口) - String baseUrl = urlObj.getConfigValue(); - if (baseUrl.endsWith("/")) { - baseUrl = baseUrl.substring(0, baseUrl.length() - 1); // 移除末尾斜杠 - } - - //处理服务指令图片 - String previewFile = dto.getPreviewFile(); - if (StringUtils.isNotBlank(previewFile)) { - String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(previewFile, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); - if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { - upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); - } - String filePath = previewFile.substring(0, previewFile.lastIndexOf("/")); - String fileName = previewFile.substring(previewFile.lastIndexOf("/") + 1); - if (filePath.startsWith("/") || filePath.startsWith("\\")) { - filePath = filePath.substring(1); - } - try { - FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); - } catch (Exception e) { - MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); - mediaAsyncErrorLog.setMediaid(previewFile); - mediaAsyncErrorLogService.save(mediaAsyncErrorLog); - e.printStackTrace(); - throw new RuntimeException(e); - } - } - //处理即时指令图标 - String immediateFile = dto.getImmediateFile(); - if (StringUtils.isNotBlank(immediateFile)) { - String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(immediateFile, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); - if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { - upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); - } - String filePath = immediateFile.substring(0, immediateFile.lastIndexOf("/")); - String fileName = immediateFile.substring(immediateFile.lastIndexOf("/") + 1); - if (filePath.startsWith("/") || filePath.startsWith("\\")) { - filePath = filePath.substring(1); - } - try { - FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); - } catch (Exception e) { - MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); - mediaAsyncErrorLog.setMediaid(immediateFile); - mediaAsyncErrorLogService.save(mediaAsyncErrorLog); - e.printStackTrace(); - throw new RuntimeException(e); - } - } - //处理指令音频文件 - String mp3File = dto.getMp3File(); - if (StringUtils.isNotBlank(mp3File)) { - String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(mp3File, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); - if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { - upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); - } - String filePath = mp3File.substring(0, mp3File.lastIndexOf("/")); - String fileName = mp3File.substring(mp3File.lastIndexOf("/") + 1); - if (filePath.startsWith("/") || filePath.startsWith("\\")) { - filePath = filePath.substring(1); - } - try { - FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); - } catch (Exception e) { - MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); - mediaAsyncErrorLog.setMediaid(mp3File); - mediaAsyncErrorLogService.save(mediaAsyncErrorLog); - e.printStackTrace(); - throw new RuntimeException(e); - } - } - //处理指令视频文件 - String mp4File = dto.getMp4File(); - if (StringUtils.isNotBlank(mp4File)) { - String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(mp4File, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); - if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { - upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); - } - String filePath = mp4File.substring(0, mp4File.lastIndexOf("/")); - String fileName = mp4File.substring(mp4File.lastIndexOf("/") + 1); - if (filePath.startsWith("/") || filePath.startsWith("\\")) { - filePath = filePath.substring(1); - } - try { - FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); - } catch (Exception e) { - MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); - mediaAsyncErrorLog.setMediaid(mp4File); - mediaAsyncErrorLogService.save(mediaAsyncErrorLog); - e.printStackTrace(); - throw new RuntimeException(e); - } - } - } - } +// @RabbitListener( +// bindings = @QueueBinding( +// value = @Queue(name = "#{directiveAsyncDQNP.getCreateMediaQueueName()}"), +// exchange = @Exchange(name = "hldy.directive", type = ExchangeTypes.DIRECT), +// key = "#{directiveAsyncDQNP.getCreateMediaKeyName()}" +// ), +// errorHandler = "directiveMQErrorHandler" +// ) +// public void handleCreateMedia(DirectiveAsyncMQDto dto) { +// //更新服务指令媒体资源字段 +// ConfigServiceDirective configServiceDirective = new ConfigServiceDirective(); +// configServiceDirective.setId(dto.getId()); +// configServiceDirective.setPreviewFile(dto.getPreviewFile());//服务指令图片 +// configServiceDirective.setServiceContent(dto.getServiceContent());//服务指令说明 +// configServiceDirective.setImmediateFile(dto.getImmediateFile());//即时指令图标 +// configServiceDirective.setMp3File(dto.getMp3File());//指令音频文件 +// configServiceDirective.setMp4File(dto.getMp4File());//指令视频文件 +// directiveService.updateById(configServiceDirective); +// +// //拉取媒体资源至本地目录 +// { +// LambdaQueryWrapper qw = new LambdaQueryWrapper<>(); +// qw.eq(SysConfig::getDelFlag, "0"); +// qw.eq(SysConfig::getConfigKey, "ope_open_url"); +// SysConfig urlObj = sysConfigService.getOne(qw); +// //试验田协议+域名(/ip+端口) +// String baseUrl = urlObj.getConfigValue(); +// if (baseUrl.endsWith("/")) { +// baseUrl = baseUrl.substring(0, baseUrl.length() - 1); // 移除末尾斜杠 +// } +// +// //处理服务指令图片 +// String previewFile = dto.getPreviewFile(); +// if (StringUtils.isNotBlank(previewFile)) { +// String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(previewFile, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); +// if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { +// upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); +// } +// String filePath = previewFile.substring(0, previewFile.lastIndexOf("/")); +// String fileName = previewFile.substring(previewFile.lastIndexOf("/") + 1); +// if (filePath.startsWith("/") || filePath.startsWith("\\")) { +// filePath = filePath.substring(1); +// } +// try { +// FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); +// } catch (Exception e) { +// MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); +// mediaAsyncErrorLog.setMediaid(previewFile); +// mediaAsyncErrorLogService.save(mediaAsyncErrorLog); +// e.printStackTrace(); +// throw new RuntimeException(e); +// } +// } +// //处理即时指令图标 +// String immediateFile = dto.getImmediateFile(); +// if (StringUtils.isNotBlank(immediateFile)) { +// String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(immediateFile, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); +// if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { +// upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); +// } +// String filePath = immediateFile.substring(0, immediateFile.lastIndexOf("/")); +// String fileName = immediateFile.substring(immediateFile.lastIndexOf("/") + 1); +// if (filePath.startsWith("/") || filePath.startsWith("\\")) { +// filePath = filePath.substring(1); +// } +// try { +// FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); +// } catch (Exception e) { +// MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); +// mediaAsyncErrorLog.setMediaid(immediateFile); +// mediaAsyncErrorLogService.save(mediaAsyncErrorLog); +// e.printStackTrace(); +// throw new RuntimeException(e); +// } +// } +// //处理指令音频文件 +// String mp3File = dto.getMp3File(); +// if (StringUtils.isNotBlank(mp3File)) { +// String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(mp3File, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); +// if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { +// upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); +// } +// String filePath = mp3File.substring(0, mp3File.lastIndexOf("/")); +// String fileName = mp3File.substring(mp3File.lastIndexOf("/") + 1); +// if (filePath.startsWith("/") || filePath.startsWith("\\")) { +// filePath = filePath.substring(1); +// } +// try { +// FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); +// } catch (Exception e) { +// MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); +// mediaAsyncErrorLog.setMediaid(mp3File); +// mediaAsyncErrorLogService.save(mediaAsyncErrorLog); +// e.printStackTrace(); +// throw new RuntimeException(e); +// } +// } +// //处理指令视频文件 +// String mp4File = dto.getMp4File(); +// if (StringUtils.isNotBlank(mp4File)) { +// String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(mp4File, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey(); +// if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) { +// upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1); +// } +// String filePath = mp4File.substring(0, mp4File.lastIndexOf("/")); +// String fileName = mp4File.substring(mp4File.lastIndexOf("/") + 1); +// if (filePath.startsWith("/") || filePath.startsWith("\\")) { +// filePath = filePath.substring(1); +// } +// try { +// FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName); +// } catch (Exception e) { +// MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog(); +// mediaAsyncErrorLog.setMediaid(mp4File); +// mediaAsyncErrorLogService.save(mediaAsyncErrorLog); +// e.printStackTrace(); +// throw new RuntimeException(e); +// } +// } +// } +// } // /** // * if 未到运营开始时间时 全量变更 @@ -371,6 +507,16 @@ public class DirectiveMQListener { //获取到需要新增的指令集合 for (ConfigServiceDirective directive : allData) { if (needAddIds.contains(directive.getId())) { + //这里都是新增的指令 不存储指令资源字段 在指令资源mq中会存储这个值 + directive.setPreviewFile(null); + directive.setImmediateFile(null); + directive.setMp3File(null); + directive.setMp4File(null); + directive.setServiceContent(null); + directive.setPreviewFileMd5(null); + directive.setImmediateFileMd5(null); + directive.setMp3FileMd5(null); + directive.setMp4FileMd5(null); needAddDirectiveList.add(directive); } }