|
|
@@ -1,11 +1,13 @@
|
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
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.Task;
|
|
|
import com.etotem.cfc.entity.TaskPlanInstance;
|
|
|
import com.etotem.cfc.entity.UserIntent;
|
|
|
import com.etotem.cfc.entity.UserNotification;
|
|
|
+import com.etotem.cfc.mapper.NotificationTemplateMapper;
|
|
|
import com.etotem.cfc.mapper.ProblemDomainMapper;
|
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.mapper.TaskPlanInstanceMapper;
|
|
|
@@ -18,7 +20,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 问题域完成奖励 — 改版v1(B17)
|
|
|
@@ -46,6 +50,9 @@ public class ProblemCompletionService {
|
|
|
@Resource
|
|
|
private UserNotificationMapper userNotificationMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private NotificationTemplateMapper notificationTemplateMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private UserIntentMapper userIntentMapper;
|
|
|
|
|
|
@@ -133,13 +140,19 @@ public class ProblemCompletionService {
|
|
|
.eq(UserNotification::getRefId, domain.getId()));
|
|
|
if (notified == null || notified == 0) {
|
|
|
// 通知发给选择了该问题域的用户
|
|
|
+ // W3: 从通知模板表读取文案,支持 {domainName}/{reward} 占位符,回退默认文案
|
|
|
+ Map<String, Object> vars = new HashMap<>();
|
|
|
+ vars.put("domainName", domain.getName());
|
|
|
+ vars.put("reward", reward);
|
|
|
+ String tplTitle = getTemplateTitle("reward_granted", "问题域完成奖励已到账");
|
|
|
+ String tplContent = getTemplateContent("reward_granted",
|
|
|
+ "恭喜完成「" + domain.getName() + "」全部任务,奖励 " + reward + " CF 已发放至家庭账户。", vars);
|
|
|
for (UserIntent intent : intents) {
|
|
|
UserNotification n = new UserNotification();
|
|
|
n.setUserId(intent.getUserId());
|
|
|
n.setType("reward_granted");
|
|
|
- n.setTitle("问题域完成奖励已到账");
|
|
|
- n.setContent("恭喜完成「" + domain.getName() + "」全部任务,奖励 "
|
|
|
- + reward + " CF 已发放至家庭账户。");
|
|
|
+ n.setTitle(tplTitle);
|
|
|
+ n.setContent(tplContent);
|
|
|
n.setRefType("completion");
|
|
|
n.setRefId(domain.getId());
|
|
|
n.setIsRead(0);
|
|
|
@@ -161,4 +174,45 @@ public class ProblemCompletionService {
|
|
|
log.info("问题域完成奖励已发放: familyId={}, domainCode={}, 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|