|
@@ -1,13 +1,11 @@
|
|
|
package com.etotem.cfc.service;
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.etotem.cfc.entity.NotificationTemplate;
|
|
|
|
|
import com.etotem.cfc.entity.ProblemDomain;
|
|
import com.etotem.cfc.entity.ProblemDomain;
|
|
|
import com.etotem.cfc.entity.Task;
|
|
import com.etotem.cfc.entity.Task;
|
|
|
import com.etotem.cfc.entity.TaskPlanInstance;
|
|
import com.etotem.cfc.entity.TaskPlanInstance;
|
|
|
import com.etotem.cfc.entity.UserIntent;
|
|
import com.etotem.cfc.entity.UserIntent;
|
|
|
import com.etotem.cfc.entity.UserNotification;
|
|
import com.etotem.cfc.entity.UserNotification;
|
|
|
-import com.etotem.cfc.mapper.NotificationTemplateMapper;
|
|
|
|
|
import com.etotem.cfc.mapper.ProblemDomainMapper;
|
|
import com.etotem.cfc.mapper.ProblemDomainMapper;
|
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.mapper.TaskPlanInstanceMapper;
|
|
import com.etotem.cfc.mapper.TaskPlanInstanceMapper;
|
|
@@ -51,7 +49,7 @@ public class ProblemCompletionService {
|
|
|
private UserNotificationMapper userNotificationMapper;
|
|
private UserNotificationMapper userNotificationMapper;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
- private NotificationTemplateMapper notificationTemplateMapper;
|
|
|
|
|
|
|
+ private NotificationDispatchService notificationDispatchService;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private UserIntentMapper userIntentMapper;
|
|
private UserIntentMapper userIntentMapper;
|
|
@@ -140,24 +138,15 @@ public class ProblemCompletionService {
|
|
|
.eq(UserNotification::getRefId, domain.getId()));
|
|
.eq(UserNotification::getRefId, domain.getId()));
|
|
|
if (notified == null || notified == 0) {
|
|
if (notified == null || notified == 0) {
|
|
|
// 通知发给选择了该问题域的用户
|
|
// 通知发给选择了该问题域的用户
|
|
|
- // W3: 从通知模板表读取文案,支持 {domainName}/{reward} 占位符,回退默认文案
|
|
|
|
|
|
|
+ // W3: 走通知分发服务(模板文案 + {domainName}/{reward} 占位符 + 五通道分发)
|
|
|
Map<String, Object> vars = new HashMap<>();
|
|
Map<String, Object> vars = new HashMap<>();
|
|
|
vars.put("domainName", domain.getName());
|
|
vars.put("domainName", domain.getName());
|
|
|
vars.put("reward", reward);
|
|
vars.put("reward", reward);
|
|
|
- String tplTitle = getTemplateTitle("reward_granted", "问题域完成奖励已到账");
|
|
|
|
|
- String tplContent = getTemplateContent("reward_granted",
|
|
|
|
|
- "恭喜完成「" + domain.getName() + "」全部任务,奖励 " + reward + " CF 已发放至家庭账户。", vars);
|
|
|
|
|
for (UserIntent intent : intents) {
|
|
for (UserIntent intent : intents) {
|
|
|
- UserNotification n = new UserNotification();
|
|
|
|
|
- n.setUserId(intent.getUserId());
|
|
|
|
|
- n.setType("reward_granted");
|
|
|
|
|
- n.setTitle(tplTitle);
|
|
|
|
|
- n.setContent(tplContent);
|
|
|
|
|
- n.setRefType("completion");
|
|
|
|
|
- n.setRefId(domain.getId());
|
|
|
|
|
- n.setIsRead(0);
|
|
|
|
|
- n.setCreatedAt(new Date());
|
|
|
|
|
- userNotificationMapper.insert(n);
|
|
|
|
|
|
|
+ notificationDispatchService.sendByTemplate("reward_granted", intent.getUserId(), vars,
|
|
|
|
|
+ "completion", domain.getId(),
|
|
|
|
|
+ "问题域完成奖励已到账",
|
|
|
|
|
+ "恭喜完成「" + domain.getName() + "」全部任务,奖励 " + reward + " CF 已发放至家庭账户。");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -174,45 +163,4 @@ public class ProblemCompletionService {
|
|
|
log.info("问题域完成奖励已发放: familyId={}, domainCode={}, reward={}",
|
|
log.info("问题域完成奖励已发放: familyId={}, domainCode={}, reward={}",
|
|
|
familyId, domain.getCode(), reward);
|
|
familyId, domain.getCode(), reward);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // ==== W3: 通知模板读取辅助方法(表不存在/停用/无记录时回退默认文案) ====
|
|
|
|
|
-
|
|
|
|
|
- /** 读取通知模板标题,回退默认值 */
|
|
|
|
|
- private String getTemplateTitle(String type, String defaultTitle) {
|
|
|
|
|
- NotificationTemplate tpl = getTemplate(type);
|
|
|
|
|
- if (tpl != null && tpl.getTitle() != null && !tpl.getTitle().isEmpty()) {
|
|
|
|
|
- return tpl.getTitle();
|
|
|
|
|
- }
|
|
|
|
|
- return defaultTitle;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /** 读取通知模板内容,支持 {占位符} 替换,回退默认值 */
|
|
|
|
|
- private String getTemplateContent(String type, String defaultContent, Map<String, Object> vars) {
|
|
|
|
|
- NotificationTemplate tpl = getTemplate(type);
|
|
|
|
|
- String content = defaultContent;
|
|
|
|
|
- if (tpl != null && tpl.getContent() != null && !tpl.getContent().isEmpty()) {
|
|
|
|
|
- content = tpl.getContent();
|
|
|
|
|
- }
|
|
|
|
|
- if (vars != null && !vars.isEmpty()) {
|
|
|
|
|
- for (Map.Entry<String, Object> entry : vars.entrySet()) {
|
|
|
|
|
- content = content.replace("{" + entry.getKey() + "}", String.valueOf(entry.getValue()));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return content;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /** 查询启用的通知模板,异常(如表不存在)时返回 null */
|
|
|
|
|
- private NotificationTemplate getTemplate(String type) {
|
|
|
|
|
- try {
|
|
|
|
|
- List<NotificationTemplate> list = notificationTemplateMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<NotificationTemplate>()
|
|
|
|
|
- .eq(NotificationTemplate::getType, type)
|
|
|
|
|
- .eq(NotificationTemplate::getStatus, 1)
|
|
|
|
|
- .last("LIMIT 1"));
|
|
|
|
|
- return (list != null && !list.isEmpty()) ? list.get(0) : null;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.warn("读取通知模板失败 type={}, error={}", type, e.getMessage());
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|