feat(notification): 添加微信订阅消息配置管理及幂等授权功能

- 新增微信订阅消息配置管理控制器,支持模板、场景、事件映射配置
- 实现用户通知授权服务的幂等控制,避免前端重试导致授权次数虚增
- 添加微信订阅消息发送日志记录,用于幂等与排障
- 新增视频生成完成时的订阅消息触发功能
- 实现场景模板查询接口,返回用户授权余额信息
- 添加模板V2相关数据表映射器和实体类
- 集成微信订阅消息触发服务到任务完成流程中
This commit is contained in:
2026-01-01 17:53:59 +08:00
parent 81dc2f1b86
commit f1a2958251
61 changed files with 3655 additions and 9 deletions

View File

@@ -0,0 +1,81 @@
package com.ycwl.basic.service.notify;
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeEventTemplateEntity;
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeSceneTemplateEntity;
import com.ycwl.basic.model.pc.notify.entity.WechatSubscribeTemplateConfigEntity;
import com.ycwl.basic.repository.WechatSubscribeNotifyConfigRepository;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 微信订阅消息配置查询服务(仅负责“配置解析”,不包含授权/发送逻辑)
*
* @Author: System
* @Date: 2025/12/31
*/
@Service
public class WechatSubscribeNotifyConfigService {
private final WechatSubscribeNotifyConfigRepository configRepository;
public WechatSubscribeNotifyConfigService(WechatSubscribeNotifyConfigRepository configRepository) {
this.configRepository = configRepository;
}
public List<WechatSubscribeTemplateConfigEntity> listSceneTemplateConfigs(Long scenicId, String sceneKey) {
List<WechatSubscribeSceneTemplateEntity> mappings =
configRepository.listEffectiveSceneTemplateMappings(scenicId, sceneKey);
if (CollectionUtils.isEmpty(mappings)) {
return new ArrayList<>();
}
Set<String> templateKeys = mappings.stream()
.map(WechatSubscribeSceneTemplateEntity::getTemplateKey)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<String, WechatSubscribeTemplateConfigEntity> configMap =
configRepository.getEffectiveTemplateConfigs(scenicId, templateKeys);
List<WechatSubscribeTemplateConfigEntity> result = new ArrayList<>();
for (WechatSubscribeSceneTemplateEntity mapping : mappings) {
WechatSubscribeTemplateConfigEntity cfg = configMap.get(mapping.getTemplateKey());
if (cfg == null || !Objects.equals(cfg.getEnabled(), 1)) {
continue;
}
result.add(cfg);
}
return result;
}
public List<WechatSubscribeTemplateConfigEntity> listEventTemplateConfigs(Long scenicId, String eventKey) {
List<WechatSubscribeEventTemplateEntity> mappings =
configRepository.listEffectiveEventTemplateMappings(scenicId, eventKey);
if (CollectionUtils.isEmpty(mappings)) {
return new ArrayList<>();
}
Set<String> templateKeys = mappings.stream()
.map(WechatSubscribeEventTemplateEntity::getTemplateKey)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<String, WechatSubscribeTemplateConfigEntity> configMap =
configRepository.getEffectiveTemplateConfigs(scenicId, templateKeys);
List<WechatSubscribeTemplateConfigEntity> result = new ArrayList<>();
for (WechatSubscribeEventTemplateEntity mapping : mappings) {
WechatSubscribeTemplateConfigEntity cfg = configMap.get(mapping.getTemplateKey());
if (cfg == null || !Objects.equals(cfg.getEnabled(), 1)) {
continue;
}
result.add(cfg);
}
return result;
}
}