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 9d4d300..bc8d292 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 @@ -1,32 +1,42 @@ package com.nu.mq.directive.listener; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.nu.dto.DirectiveAsyncMQDto; +import com.nu.modules.mediaasyncerrorlog.entity.MediaAsyncErrorLog; +import com.nu.modules.mediaasyncerrorlog.service.IMediaAsyncErrorLogService; import com.nu.modules.servicedirective.entity.ConfigServiceDirective; import com.nu.modules.servicedirective.service.IConfigServiceDirectiveService; +import com.nu.modules.sysconfig.entity.SysConfig; +import com.nu.modules.sysconfig.service.ISysConfigService; +import com.nu.utils.FileDownloader; +import com.nu.utils.SafetyUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.springframework.amqp.core.ExchangeTypes; import org.springframework.amqp.rabbit.annotation.Exchange; import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import java.io.File; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + @Slf4j @Component public class DirectiveMQListener { -// @Value("${jeecg.path.upload}") -// private String upLoadPath; -// @Value("${jeecg.path.directivepath}") -// private String directiveUpLoadPath; -// -// @Autowired + @Value("${jeecg.path.upload}") + private String upLoadPath; + // @Autowired // private IMediaManageApi mediaManageApi; -// @Autowired -// private ISysConfigService sysConfigService; -// @Autowired -// private IMediaAsyncErrorLogService mediaAsyncErrorLogService; + @Autowired + private ISysConfigService sysConfigService; + @Autowired + private IMediaAsyncErrorLogService mediaAsyncErrorLogService; @Autowired private IConfigServiceDirectiveService directiveService; // @Autowired @@ -48,7 +58,7 @@ public class DirectiveMQListener { ), errorHandler = "directiveMQErrorHandler" ) - public void handleMessage(DirectiveAsyncMQDto dto) { + public void handleAuditResult(DirectiveAsyncMQDto dto) { //将字典项更新为已授权 directiveService.auditPass(dto); //更新服务指令状态 @@ -58,6 +68,128 @@ 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); + } + } + } + } + // /** // * if 未到运营开始时间时 全量变更 // * else 增量 diff --git a/nursing-unit-services/nu-services-biz/src/main/java/com/nu/mq/directive/listener/DynamicQueueNameProvider.java b/nursing-unit-services/nu-services-biz/src/main/java/com/nu/mq/directive/listener/DynamicQueueNameProvider.java index 49a3ed1..989b65d 100644 --- a/nursing-unit-services/nu-services-biz/src/main/java/com/nu/mq/directive/listener/DynamicQueueNameProvider.java +++ b/nursing-unit-services/nu-services-biz/src/main/java/com/nu/mq/directive/listener/DynamicQueueNameProvider.java @@ -39,4 +39,18 @@ public class DynamicQueueNameProvider { public String getAuditResultKeyName() { return getAuditResultQueueName(); } + + public String getCreateMediaQueueName() { + JSONObject deptInfo = sysBaseAPI.getDeptInfo(); + String orgCode = deptInfo.getString("code"); + if (StringUtils.isNotBlank(orgCode)) { + return orgCode + ".directive.createmedia"; + } else { + return ""; + } + } + + public String getCreateMediaKeyName() { + return getCreateMediaQueueName(); + } } diff --git a/nursing-unit-system/nu-system-start/src/main/resources/application-uat.yml b/nursing-unit-system/nu-system-start/src/main/resources/application-uat.yml index f30e550..a9df5c4 100644 --- a/nursing-unit-system/nu-system-start/src/main/resources/application-uat.yml +++ b/nursing-unit-system/nu-system-start/src/main/resources/application-uat.yml @@ -254,7 +254,7 @@ jeecg: app: http://localhost:8051 path: #文件上传根目录 设置 - upload: /opt/ope/upFiles + upload: /opt/ope/upFiles101 #webapp文件路径 webapp: /opt/biz101/webapp shiro: diff --git a/nursing-unit-system/nu-system-start/src/main/resources/application-uat102.yml b/nursing-unit-system/nu-system-start/src/main/resources/application-uat102.yml index 61e6363..a9423d3 100644 --- a/nursing-unit-system/nu-system-start/src/main/resources/application-uat102.yml +++ b/nursing-unit-system/nu-system-start/src/main/resources/application-uat102.yml @@ -254,7 +254,7 @@ jeecg: app: http://localhost:8051 path: #文件上传根目录 设置 - upload: /opt/ope/upFiles + upload: /opt/ope/upFiles102 #webapp文件路径 webapp: /opt/biz102/webapp shiro: