From 311008cbf2ec074e096fe1e1b08b4bc588c2f6dc Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 14 Oct 2025 19:05:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(message):=20=E9=9B=86=E6=88=90ZT=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=9C=8D=E5=8A=A1=E5=8F=91=E9=80=81=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在TaskTaskServiceImpl中引入ZtMessageProducerService依赖 - 替换原有微信通知逻辑,使用ZT消息服务发送视频生成通知- 在DownloadNotificationTasker中引入ZtMessageProducerService依赖 - 修改视频下载通知发送逻辑,使用ZT消息服务 - 修改视频过期提醒通知逻辑,使用ZT消息服务 - 调整额外通知时间配置获取方式,从scenicConfigManager获取 - 统一构建通知消息参数格式,包含data和page信息 - 添加详细的日志记录,便于追踪消息发送过程 --- .../task/impl/TaskTaskServiceImpl.java | 39 +++--- .../task/DownloadNotificationTasker.java | 114 ++++++++++-------- 2 files changed, 87 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/ycwl/basic/service/task/impl/TaskTaskServiceImpl.java b/src/main/java/com/ycwl/basic/service/task/impl/TaskTaskServiceImpl.java index e422c794..a8ed5f5e 100644 --- a/src/main/java/com/ycwl/basic/service/task/impl/TaskTaskServiceImpl.java +++ b/src/main/java/com/ycwl/basic/service/task/impl/TaskTaskServiceImpl.java @@ -5,6 +5,8 @@ import cn.hutool.crypto.digest.MD5; import com.ycwl.basic.integration.common.manager.DeviceConfigManager; import com.ycwl.basic.integration.common.manager.RenderWorkerConfigManager; import com.ycwl.basic.integration.common.manager.ScenicConfigManager; +import com.ycwl.basic.integration.message.dto.ZtMessage; +import com.ycwl.basic.integration.message.service.ZtMessageProducerService; import com.ycwl.basic.repository.MemberRelationRepository; import com.ycwl.basic.repository.SourceRepository; import com.ycwl.basic.utils.JacksonUtil; @@ -128,6 +130,8 @@ public class TaskTaskServiceImpl implements TaskService { private SourceRepository sourceRepository; @Autowired private MemberRelationRepository memberRelationRepository; + @Autowired + private ZtMessageProducerService ztMessageProducerService; private RenderWorkerEntity getWorker(@NonNull WorkerAuthReqVo req) { String accessKey = req.getAccessKey(); @@ -653,23 +657,26 @@ public class TaskTaskServiceImpl implements TaskService { * 生成时间 {{time4.DATA}} * 备注 {{thing3.DATA}} */ - Map params = new HashMap<>(); Map dataParam = new HashMap<>(); - Map videoMap = new HashMap<>(); - videoMap.put("value", title); - dataParam.put("thing1", videoMap); - Map timeMap2 = new HashMap<>(); - timeMap2.put("value", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm")); - dataParam.put("time4", timeMap2); - Map remarkMap = new HashMap<>(); - remarkMap.put("value", configContent); - dataParam.put("thing3", remarkMap); - params.put("data", dataParam); - params.put("page", page); - params.put("template_id", templateId); - log.info("视频生成通知模板参数:{},用户ID:{}", params, openId); - INotifyAdapter adapter = NotifyFactory.get(NotifyType.WX_MP_SRV, scenicMp.toMap()); - adapter.sendTo(new NotifyContent(title, page, params), openId); + dataParam.put("thing1", title); + dataParam.put("time4", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm")); + dataParam.put("thing3", configContent); + + // 构建extra,只包含data和page + Map extra = new HashMap<>(); + extra.put("data", dataParam); + extra.put("page", page); + + // 使用ZT消息服务发送通知(第一次通知) + ZtMessage msg = new ZtMessage(); + msg.setChannelId(templateId); + msg.setTitle(title); + msg.setContent("【" + item.getFaceId() + "/" + item.getVideoId() + "】"+configContent); + msg.setTarget(openId); + msg.setExtra(extra); + msg.setSendReason("视频生成通知"); + msg.setSendBiz("视频生成"); + ztMessageProducerService.send(msg); } } diff --git a/src/main/java/com/ycwl/basic/task/DownloadNotificationTasker.java b/src/main/java/com/ycwl/basic/task/DownloadNotificationTasker.java index a3a902ac..a81477fb 100644 --- a/src/main/java/com/ycwl/basic/task/DownloadNotificationTasker.java +++ b/src/main/java/com/ycwl/basic/task/DownloadNotificationTasker.java @@ -1,6 +1,8 @@ package com.ycwl.basic.task; import cn.hutool.core.date.DateUtil; +import com.ycwl.basic.integration.message.dto.ZtMessage; +import com.ycwl.basic.integration.message.service.ZtMessageProducerService; import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2DTO; import com.ycwl.basic.mapper.CouponMapper; import com.ycwl.basic.mapper.MemberMapper; @@ -47,6 +49,8 @@ public class DownloadNotificationTasker { private MemberMapper memberMapper; @Autowired private CouponMapper couponMapper; + @Autowired + private ZtMessageProducerService ztMessageProducerService; @Scheduled(cron = "0 0 21 * * *") public void sendDownloadNotification() { @@ -64,7 +68,6 @@ public class DownloadNotificationTasker { log.info("模板消息为空"); return; } - log.info("发送模板消息"); ScenicEntity scenic = scenicRepository.getScenic(item.getScenicId()); ScenicConfigManager configManager = scenicRepository.getScenicConfigManager(item.getScenicId()); String configTitle = configManager.getString("second_notification_title"); @@ -86,20 +89,25 @@ public class DownloadNotificationTasker { * 景区 {{thing1.DATA}} * 备注 {{thing3.DATA}} */ - Map params = new HashMap<>(); Map dataParam = new HashMap<>(); - Map videoMap = new HashMap<>(); - videoMap.put("value", title); - dataParam.put("thing1", videoMap); - Map remarkMap = new HashMap<>(); - remarkMap.put("value", configContent); - dataParam.put("thing3", remarkMap); - params.put("data", dataParam); - params.put("page", page); - params.put("template_id", templateId); - log.info("视频下载通知模板参数:{},用户ID:{}", params, member.getOpenId()); - INotifyAdapter adapter = NotifyFactory.get(NotifyType.WX_MP_SRV, scenicMp.toMap()); - adapter.sendTo(new NotifyContent(title, page, params), member.getOpenId()); + dataParam.put("thing1", title); + dataParam.put("thing3", configContent); + + // 构建extra,只包含data和page + Map extra = new HashMap<>(); + extra.put("data", dataParam); + extra.put("page", page); + + // 使用ZT消息服务发送通知(第二次通知) + ZtMessage msg = new ZtMessage(); + msg.setChannelId(templateId); + msg.setTitle(title); + msg.setContent("【" + item.getFaceId() + "】"+configContent); + msg.setTarget(member.getOpenId()); + msg.setExtra(extra); + msg.setSendReason("第二次通知"); + msg.setSendBiz("定时通知"); + ztMessageProducerService.send(msg); }); } @@ -124,7 +132,6 @@ public class DownloadNotificationTasker { log.info("模板消息为空"); return; } - log.info("发送模板消息"); ScenicEntity scenic = scenicRepository.getScenic(item.getScenicId()); ScenicConfigManager configManager = scenicRepository.getScenicConfigManager(item.getScenicId()); String configTitle = configManager.getString("third_notification_title"); @@ -147,24 +154,27 @@ public class DownloadNotificationTasker { * 过期时间 {{time2.DATA}} * 备注 {{thing3.DATA}} */ - Map params = new HashMap<>(); - Map dataParam = new HashMap<>(); - Map videoMap = new HashMap<>(); - videoMap.put("value", title); - dataParam.put("thing1", videoMap); - Map dateMap = new HashMap<>(); Date expireDate = new Date(item.getCreateTime().getTime() + videoStoreDay * 24 * 60 * 60 * 1000); - dateMap.put("value", DateUtil.format(expireDate, "yyyy-MM-dd HH:mm")); - dataParam.put("time2", dateMap); - Map remarkMap = new HashMap<>(); - remarkMap.put("value", configContent); - dataParam.put("thing3", remarkMap); - params.put("data", dataParam); - params.put("page", page); - params.put("template_id", templateId); - log.info("视频下载通知模板参数:{},用户ID:{}", params, member.getOpenId()); - INotifyAdapter adapter = NotifyFactory.get(NotifyType.WX_MP_SRV, scenicMp.toMap()); - adapter.sendTo(new NotifyContent(title, page, params), member.getOpenId()); + Map dataParam = new HashMap<>(); + dataParam.put("thing1", title); + dataParam.put("time2", DateUtil.format(expireDate, "yyyy-MM-dd HH:mm")); + dataParam.put("thing3", configContent); + + // 构建extra,只包含data和page + Map extra = new HashMap<>(); + extra.put("data", dataParam); + extra.put("page", page); + + // 使用ZT消息服务发送通知(第三次通知 - 过期提醒) + ZtMessage msg = new ZtMessage(); + msg.setChannelId(templateId); + msg.setTitle(title); + msg.setContent("【" + item.getFaceId() + "】"+configContent); + msg.setTarget(member.getOpenId()); + msg.setExtra(extra); + msg.setSendReason("第三次通知"); + msg.setSendBiz("定时通知"); + ztMessageProducerService.send(msg); }); } @@ -183,18 +193,18 @@ public class DownloadNotificationTasker { calendar.clear(); scenicList.parallelStream().forEach(scenic -> { Long scenicId = Long.parseLong(scenic.getId()); - ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId); + ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(scenicId); if (scenicConfig == null) { return; } - if (StringUtils.isEmpty(scenicConfig.getExtraNotificationTime())) { + if (StringUtils.isEmpty(scenicConfig.getString("extra_notification_time"))) { return; } - List timeList = Arrays.asList(StringUtils.split(scenicConfig.getExtraNotificationTime(), ",")); + List timeList = Arrays.asList(StringUtils.split(scenicConfig.getString("extra_notification_time"), ",")); if (!timeList.contains(String.valueOf(currentHour))) { return; } - log.info("当前景区{},配置了{}", scenic.getName(), scenicConfig.getExtraNotificationTime()); + log.info("当前景区{},配置了{}", scenic.getName(), scenicConfig.getString("extra_notification_time")); videoMapper.listRelationByCreateTime(DateUtil.beginOfDay(new Date()), new Date()) .stream() @@ -219,7 +229,6 @@ public class DownloadNotificationTasker { return; } - log.info("发送模板消息"); String title = configTitle.replace("【景区】", scenic.getName()); String page; if (configManager.getBoolean("grouping_enable", false)) { @@ -231,20 +240,25 @@ public class DownloadNotificationTasker { * 景区 {{thing1.DATA}} * 备注 {{thing3.DATA}} */ - Map params = new HashMap<>(); Map dataParam = new HashMap<>(); - Map videoMap = new HashMap<>(); - videoMap.put("value", title); - dataParam.put("thing1", videoMap); - Map remarkMap = new HashMap<>(); - remarkMap.put("value", configContent); - dataParam.put("thing3", remarkMap); - params.put("data", dataParam); - params.put("page", page); - params.put("template_id", templateId); - log.info("视频下载通知模板参数:{},用户ID:{}", params, member.getOpenId()); - INotifyAdapter adapter = NotifyFactory.get(NotifyType.WX_MP_SRV, scenicMp.toMap()); - adapter.sendTo(new NotifyContent(title, page, params), member.getOpenId()); + dataParam.put("thing1", title); + dataParam.put("thing3", configContent); + + // 构建extra,只包含data和page + Map extra = new HashMap<>(); + extra.put("data", dataParam); + extra.put("page", page); + + // 使用ZT消息服务发送通知(额外下载通知) + ZtMessage msg = new ZtMessage(); + msg.setChannelId(templateId); + msg.setTitle(title); + msg.setContent("【" + item.getFaceId() + "】"+configContent); + msg.setTarget(member.getOpenId()); + msg.setExtra(extra); + msg.setSendReason("景区额外配置:" + scenicConfig.getString("extra_notification_time")); + msg.setSendBiz("定时通知"); + ztMessageProducerService.send(msg); }); }); }