|
@@ -1,19 +1,25 @@
|
|
|
package com.qxgmat.service.extend;
|
|
|
|
|
|
+import com.alipay.api.domain.TransOrderDetail;
|
|
|
+import com.nuliji.tools.Transform;
|
|
|
import com.nuliji.tools.exception.ParameterException;
|
|
|
-import com.qxgmat.data.constants.enums.MessageCategory;
|
|
|
-import com.qxgmat.data.constants.enums.MessageMethod;
|
|
|
-import com.qxgmat.data.constants.enums.MessageType;
|
|
|
+import com.qxgmat.data.constants.enums.*;
|
|
|
+import com.qxgmat.data.constants.enums.module.FeedbackModule;
|
|
|
+import com.qxgmat.data.constants.enums.module.ProductType;
|
|
|
import com.qxgmat.data.constants.enums.status.AnswerStatus;
|
|
|
+import com.qxgmat.data.constants.enums.trade.RecordSource;
|
|
|
+import com.qxgmat.data.constants.enums.user.AskTarget;
|
|
|
+import com.qxgmat.data.constants.enums.user.DataType;
|
|
|
+import com.qxgmat.data.constants.enums.user.FeedbackTarget;
|
|
|
import com.qxgmat.data.dao.entity.*;
|
|
|
import com.qxgmat.help.MailHelp;
|
|
|
import com.qxgmat.help.SmsHelp;
|
|
|
import com.qxgmat.help.WechatHelp;
|
|
|
-import com.qxgmat.service.inline.MessageTemplateService;
|
|
|
-import com.qxgmat.service.inline.UserMessageService;
|
|
|
+import com.qxgmat.service.inline.*;
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import sun.plugin2.message.Message;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -39,6 +45,21 @@ public class MessageExtendService {
|
|
|
private MessageTemplateService messageTemplateService;
|
|
|
|
|
|
@Resource
|
|
|
+ private CourseService courseService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CourseNoService courseNoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CoursePackageService coursePackageService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private QuestionNoService questionNoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CourseDataService courseDataService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
private ToolsService toolsService;
|
|
|
|
|
|
@Value("${url.pc}")
|
|
@@ -47,7 +68,10 @@ public class MessageExtendService {
|
|
|
@Value("${url.h5}")
|
|
|
private String h5Url;
|
|
|
|
|
|
- private void send(User user, MessageCategory category, Map<String, String>params){
|
|
|
+ @Value("${info.wechat}")
|
|
|
+ private String wechat;
|
|
|
+
|
|
|
+ private void send(User user, MessageCategory category, Map<String, String>params, Integer relationId){
|
|
|
List<MessageTemplate> templateList = messageTemplateService.listByCategory(category);
|
|
|
for(MessageTemplate template : templateList){
|
|
|
MessageMethod messageMethod = MessageMethod.ValueOf(template.getMessageMethod());
|
|
@@ -55,10 +79,21 @@ public class MessageExtendService {
|
|
|
String content = replaceBody(template.getContent(), params);
|
|
|
switch(messageMethod){
|
|
|
case EMAIL:
|
|
|
- sendEmail(params.getOrDefault("emails", user.getEmail()), title, content);
|
|
|
+ if(params.containsKey("link")){
|
|
|
+ params.put("linkHtml", makeLink(params.get("link"), params.getOrDefault("linkTitle", category.linkTitle), relationId));
|
|
|
+ }else if(category.link != null ){
|
|
|
+ params.put("linkHtml", makeLink(category.link, category.linkTitle, relationId));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (params.containsKey("linkSecond")){
|
|
|
+ params.put("linkSecondHtml", makeLink(params.get("linkSecond"), params.getOrDefault("linkTitle", category.linkSecondTitle), relationId));
|
|
|
+ }else if(category.linkSecond != null){
|
|
|
+ params.put("linkSecondHtml", makeLink(category.linkSecond, category.linkSecondTitle, relationId));
|
|
|
+ }
|
|
|
+ sendEmail(params.getOrDefault("emails", user.getEmail()), title, content, params.get("attachment"), params.get("attachments"));
|
|
|
break;
|
|
|
case INSIDE:
|
|
|
- sendInside(user.getId(), title, content, template.getLink(), category);
|
|
|
+ sendInside(user.getId(), title, content, relationId, params.getOrDefault("link", template.getLink()), params.getOrDefault("linkTitle", null), category);
|
|
|
break;
|
|
|
case WECHAT:
|
|
|
sendWechat(user.getWechatOpenidWechat(), category, params);
|
|
@@ -73,19 +108,26 @@ public class MessageExtendService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private UserMessage sendInside(Integer userId, String title, String content, String link, MessageCategory category){
|
|
|
+ private UserMessage sendInside(Integer userId, String title, String content, Integer relationId, String link, String linkTitle, MessageCategory category){
|
|
|
// 根据模版创建
|
|
|
return userMessageService.add(UserMessage.builder()
|
|
|
.userId(userId)
|
|
|
.title(title)
|
|
|
.content(content)
|
|
|
+ .relationId(relationId)
|
|
|
.link(link)
|
|
|
+ .linkTitle(linkTitle)
|
|
|
.type(MessageType.FromCategory(category).key)
|
|
|
.isRead(0)
|
|
|
.build());
|
|
|
}
|
|
|
|
|
|
- private void sendEmail(String emails, String title, String body){
|
|
|
+ private void sendEmail(String emails, String title, String body, String attachment, String attachments){
|
|
|
+ if (attachment != null){
|
|
|
+ mailHelp.sendAttachMail(emails, title, body, attachment);
|
|
|
+ }else if(attachments != null){
|
|
|
+ mailHelp.sendAttachMail(emails, title, body, Arrays.stream(attachments.split(";")).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
mailHelp.sendBaseMail(emails, title, body);
|
|
|
}
|
|
|
|
|
@@ -96,14 +138,11 @@ public class MessageExtendService {
|
|
|
private void sendSms(String area, String mobile, MessageCategory category, Map<String, String> params){
|
|
|
String[] template;
|
|
|
Map<String, String> smsParams = new HashMap<>();
|
|
|
- SimpleDateFormat sdf;
|
|
|
- String time;
|
|
|
switch(category){
|
|
|
case LOGIN_ABNORMAL:
|
|
|
template = smsHelp.ABNORMAL_TEMPLATE;
|
|
|
// time: yyyy年MM月dd日hh:mm:ss
|
|
|
- sdf = new SimpleDateFormat("yyyy年MM月dd hh:mm:ss");
|
|
|
- smsParams.put("time", sdf.format(params.get("time")));
|
|
|
+ smsParams.put("time", params.get("time"));
|
|
|
break;
|
|
|
case TEXTBOOK_LIBRARY:
|
|
|
template = smsHelp.LIBRARY_TEMPLATE;
|
|
@@ -112,7 +151,11 @@ public class MessageExtendService {
|
|
|
// 间隔%jgts%天,库长%kcts%天
|
|
|
// 获取机经: %jjdz%
|
|
|
// 也可搜索微信订阅号“%dyh%”查阅机经。
|
|
|
- smsParams.put("dyh", "");
|
|
|
+ smsParams.put("zx_date", params.get("date"));
|
|
|
+ smsParams.put("sc_date", params.get("prevDate"));
|
|
|
+ smsParams.put("jgts", params.get("period"));
|
|
|
+ smsParams.put("kcts", params.get("days"));
|
|
|
+ smsParams.put("dyh", wechat);
|
|
|
smsParams.put("jjdz", pcUrl+"/textbook");
|
|
|
break;
|
|
|
case COURSE_USE_EXPIRE:
|
|
@@ -120,20 +163,18 @@ public class MessageExtendService {
|
|
|
// yhnc: 用户昵称
|
|
|
// %kcmc%: 课程名称
|
|
|
// %date%: 格式为:yyyy年MM月dd日
|
|
|
- sdf = new SimpleDateFormat("yyyy年MM月dd");
|
|
|
- smsParams.put("date", sdf.format(params.get("time")));
|
|
|
+ smsParams.put("date", params.get("expireDate"));
|
|
|
smsParams.put("yhnc", params.get("nickname"));
|
|
|
smsParams.put("kcmc", params.get("title"));
|
|
|
break;
|
|
|
- case COURSE_EXPIRE:
|
|
|
- case TEXTBOOK_EXPIRE:
|
|
|
- case QX_CAT_EXPIRE:
|
|
|
+ case COURSE_OPEN_EXPIRE:
|
|
|
+ case TEXTBOOK_OPEN_EXPIRE:
|
|
|
+ case QX_CAT_OPEN_EXPIRE:
|
|
|
template = smsHelp.EXPIRE_TEMPLATE;
|
|
|
// yhnc: 用户昵称
|
|
|
// %date%: 格式为:yyyy年MM月dd日
|
|
|
// wktfw: 未开通的服务名称
|
|
|
- sdf = new SimpleDateFormat("yyyy年MM月dd");
|
|
|
- smsParams.put("date", sdf.format(params.get("time")));
|
|
|
+ smsParams.put("date", params.get("expireDate"));
|
|
|
smsParams.put("yhnc", params.get("nickname"));
|
|
|
smsParams.put("wktfw", params.get("title"));
|
|
|
break;
|
|
@@ -145,7 +186,19 @@ public class MessageExtendService {
|
|
|
}
|
|
|
|
|
|
public void refreshMessage(List<UserMessage> messageList){
|
|
|
-
|
|
|
+ for(UserMessage message : messageList){
|
|
|
+ if (message.getLink() != null && message.getLink() != null) continue;
|
|
|
+ MessageCategory category = MessageCategory.ValueOf(message.getMessageCategory());
|
|
|
+ if(category.emailLink) continue;
|
|
|
+ if (category.link != null){
|
|
|
+ message.setLink(replaceLink(category.link, "id", message.getRelationId()));
|
|
|
+ message.setLinkTitle(category.linkTitle);
|
|
|
+ }
|
|
|
+ if (category.linkSecond != null){
|
|
|
+ message.setLinkSecond(replaceLink(category.linkSecond, "id", message.getRelationId()));
|
|
|
+ message.setLinkSecondTitle(category.linkSecondTitle);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void sendCustom(User user, MessageTemplate template, Map<String, String>params){
|
|
@@ -155,10 +208,10 @@ public class MessageExtendService {
|
|
|
String content = replaceBody(template.getContent(), params);
|
|
|
switch(messageMethod){
|
|
|
case EMAIL:
|
|
|
- sendEmail(user.getEmail(), title, content);
|
|
|
+ sendEmail(user.getEmail(), title, content, null, null);
|
|
|
break;
|
|
|
case INSIDE:
|
|
|
- sendInside(user.getId(), title, content, template.getLink(), MessageCategory.CUSTOM);
|
|
|
+ sendInside(user.getId(), title, content, 0, template.getLink(), null, MessageCategory.CUSTOM);
|
|
|
break;
|
|
|
default:
|
|
|
throw new ParameterException("消息发送方式错误");
|
|
@@ -175,15 +228,85 @@ public class MessageExtendService {
|
|
|
map.put("code", code);
|
|
|
map.put("nickname", user.getNickname());
|
|
|
map.put("url", pcUrl+"/id/"+code);
|
|
|
- send(user, MessageCategory.INVITED, map);
|
|
|
+ send(user, MessageCategory.INVITED, map, user.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 邀请成功通知
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ public void sendInviteSuccess(User user, UserOrderRecord record){
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("nickname", user.getNickname());
|
|
|
+ map.put("number", String.valueOf(user.getInviteNumber()));
|
|
|
+ map.put("useExpireDays", String.valueOf(record.getUseExpireDays()));
|
|
|
+ map.put("expireTime", getTime(record.getUseEndTime()));
|
|
|
+ send(user, MessageCategory.INVITED_SUCCESS, map, record.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实名认证
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ public void sendReal(User user, UserOrderRecord record){
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("nickname", user.getNickname());
|
|
|
+ map.put("useExpireDays", String.valueOf(record.getUseExpireDays()));
|
|
|
+ map.put("expireTime", getTime(record.getUseEndTime()));
|
|
|
+ send(user, MessageCategory.REAL, map, record.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 完善备考
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ public void sendPrepare(User user, UserOrderRecord record){
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("nickname", user.getNickname());
|
|
|
+ map.put("useExpireDays", String.valueOf(record.getUseExpireDays()));
|
|
|
+ map.put("expireTime", getTime(record.getUseEndTime()));
|
|
|
+ send(user, MessageCategory.PREPARE, map, record.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送机经换库
|
|
|
+ */
|
|
|
+ public void sendTextbookLibrary(User user, TextbookLibrary latest, TextbookLibrary second){
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ int days =(int)(latest.getStartDate().getTime() - second.getStartDate().getTime()) / 86400000;
|
|
|
+ map.put("date", getDate(latest.getStartDate()));
|
|
|
+ map.put("prevDate", getDate(second.getStartDate()));
|
|
|
+ map.put("period", String.valueOf(days-1));
|
|
|
+ map.put("days", String.valueOf(days));
|
|
|
+ send(user, MessageCategory.TEXTBOOK_LIBRARY, map, 0);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送机经更新
|
|
|
*/
|
|
|
- public void sendTextbookUpdate(User user, TextbookLibrary textbookLibrary){
|
|
|
+ public void sendTextbookUpdate(User user, TextbookLibrary textbookLibrary, Boolean subscribe){
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
- send(user, MessageCategory.TEXTBOOK_LIBRARY, map);
|
|
|
+ Integer version = textbookLibrary.getQuantVersion();
|
|
|
+ if (textbookLibrary.getIrVersion() > version){
|
|
|
+ version = textbookLibrary.getIrVersion();
|
|
|
+ }
|
|
|
+ if (textbookLibrary.getRcVersion() >version){
|
|
|
+ version = textbookLibrary.getRcVersion();
|
|
|
+ }
|
|
|
+ map.put("email", user.getEmail());
|
|
|
+ map.put("version", String.valueOf(version));
|
|
|
+ map.put("quantVersion", String.valueOf(textbookLibrary.getQuantVersion()));
|
|
|
+ map.put("quantDescription", String.valueOf(textbookLibrary.getQuantDescription()));
|
|
|
+ map.put("irVersion", String.valueOf(textbookLibrary.getIrVersion()));
|
|
|
+ map.put("irDescription", String.valueOf(textbookLibrary.getIrDescription()));
|
|
|
+ map.put("rcVersion", String.valueOf(textbookLibrary.getRcVersion()));
|
|
|
+ map.put("rcDescription", String.valueOf(textbookLibrary.getRcDescription()));
|
|
|
+ if (subscribe){
|
|
|
+ map.put("attachments", String.format("%s;%s;%s", textbookLibrary.getQuant(), textbookLibrary.getIr(), textbookLibrary.getRc()));
|
|
|
+ send(user, MessageCategory.TEXTBOOK_UPDATE_SUBSCRIBE, map, 0);
|
|
|
+ }else{
|
|
|
+ send(user, MessageCategory.TEXTBOOK_UPDATE, map, 0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -194,7 +317,8 @@ public class MessageExtendService {
|
|
|
map.put("nickname", user.getNickname());
|
|
|
map.put("ip", userAbnormal.getLoginIp());
|
|
|
map.put("city", userAbnormal.getLoginCity());
|
|
|
- send(user, MessageCategory.LOGIN_ABNORMAL, map);
|
|
|
+ map.put("time", getTime(userAbnormal.getCreateTime()));
|
|
|
+ send(user, MessageCategory.LOGIN_ABNORMAL, map, userAbnormal.getId());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -206,7 +330,7 @@ public class MessageExtendService {
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("courseTitle", course.getTitle());
|
|
|
map.put("title", previewAssign.getTitle());
|
|
|
- send(user, MessageCategory.PREVIEW_NOTICE, map);
|
|
|
+ send(user, MessageCategory.PREVIEW_NOTICE, map, previewAssign.getId());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -215,10 +339,235 @@ public class MessageExtendService {
|
|
|
* 支付金额:{money}
|
|
|
* 开通有效期:{expireTime}
|
|
|
*/
|
|
|
- public void sendPayed(User user, UserOrder userOrder){
|
|
|
+ public void sendPayed(User user, UserOrder userOrder, List<UserOrderRecord> recordList){
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
- map.put("money", userOrder.getMoney().toString());
|
|
|
- send(user, MessageCategory.PAYED, map);
|
|
|
+ List<UserOrderRecord> pList = recordList.stream().filter((checkout)-> checkout.getParentId() == 0).collect(Collectors.toList());
|
|
|
+
|
|
|
+ map.put("number", String.valueOf(pList.size()));
|
|
|
+ if(userOrder.getProductTypes().size() == 1){
|
|
|
+ String productType = userOrder.getProductTypes().getString(1);
|
|
|
+ UserOrderRecord one = pList.get(0);
|
|
|
+ switch(ProductType.ValueOf(productType)){
|
|
|
+ case SERVICE:
|
|
|
+ ServiceKey key = ServiceKey.ValueOf(one.getService());
|
|
|
+ map.put("title", key.title);
|
|
|
+ map.put("expireDays", String.valueOf(one.getExpireDays()));
|
|
|
+ map.put("useExpireDays", String.valueOf(one.getUseExpireDays()));
|
|
|
+ switch(key){
|
|
|
+ case VIP:
|
|
|
+ send(user, MessageCategory.VIP_PAY, map, one.getId());
|
|
|
+ break;
|
|
|
+ case TEXTBOOK:
|
|
|
+ send(user, MessageCategory.TEXTBOOK_PAY, map, one.getId());
|
|
|
+ break;
|
|
|
+ case QX_CAT:
|
|
|
+ send(user, MessageCategory.QX_CAT_PAY, map, one.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case DATA:
|
|
|
+ CourseData data = courseDataService.get(one.getProductId());
|
|
|
+ map.put("title", data.getTitle());
|
|
|
+ if (pList.size() > 1){
|
|
|
+ Collection dataIds = Transform.getIds(pList, UserOrderRecord.class, "productId");
|
|
|
+ List<CourseData> courseDataList = courseDataService.select(dataIds);
|
|
|
+ List<String> dataTitle = new ArrayList<>();
|
|
|
+ for(CourseData c: courseDataList){
|
|
|
+ dataTitle.add(c.getTitle());
|
|
|
+ }
|
|
|
+ map.put("titleJoin", String.join("”,“", dataTitle));
|
|
|
+ send(user, MessageCategory.DATA_PAY_MULTI, map, userOrder.getId());
|
|
|
+ }else{
|
|
|
+ send(user, MessageCategory.DATA_PAY, map, userOrder.getId());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case COURSE:
|
|
|
+ Course course = courseService.get(one.getProductId());
|
|
|
+ map.put("title", course.getTitle());
|
|
|
+ if (pList.size() > 1){
|
|
|
+ Collection courseIds = Transform.getIds(pList, UserOrderRecord.class, "productId");
|
|
|
+ List<Course> courseList = courseService.select(courseIds);
|
|
|
+ List<String> courseTitle = new ArrayList<>();
|
|
|
+ for(Course c: courseList){
|
|
|
+ courseTitle.add(c.getTitle());
|
|
|
+ }
|
|
|
+ map.put("titleJoin", String.join("”,“", courseTitle));
|
|
|
+ send(user, MessageCategory.COURSE_PAY_MULTI, map, userOrder.getId());
|
|
|
+ }else{
|
|
|
+ map.put("expireDays", String.valueOf(one.getExpireDays()));
|
|
|
+ map.put("useExpireDays", String.valueOf(one.getUseExpireDays()));
|
|
|
+ send(user, MessageCategory.COURSE_PAY, map, userOrder.getId());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case COURSE_PACKAGE:
|
|
|
+ CoursePackage coursePackage = coursePackageService.get(one.getProductId());
|
|
|
+ List<Course> courseList = courseService.select(coursePackage.getCourseIds());
|
|
|
+ List<String> courseTitle = new ArrayList<>();
|
|
|
+ for(Course c: courseList){
|
|
|
+ courseTitle.add(c.getTitle());
|
|
|
+ }
|
|
|
+ map.put("titleJoin", String.join("”,“", courseTitle));
|
|
|
+ map.put("number", String.valueOf(courseList.size()));
|
|
|
+ map.put("title", courseList.get(0).getTitle());
|
|
|
+ send(user, MessageCategory.COURSE_PAY_MULTI, map, userOrder.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ List<String> titles = new ArrayList<>();
|
|
|
+
|
|
|
+ List<UserOrderRecord> prService = recordList.stream().filter((row)-> row.getProductType().equals(ProductType.SERVICE.key)).collect(Collectors.toList());
|
|
|
+ for(UserOrderRecord r : prService){
|
|
|
+ ServiceKey key = ServiceKey.ValueOf(r.getService());
|
|
|
+ titles.add(key.title);
|
|
|
+ }
|
|
|
+ // 绑定套餐
|
|
|
+ List<UserOrderRecord> prPackage = recordList.stream().filter((row)-> row.getProductType().equals(ProductType.COURSE_PACKAGE.key)).collect(Collectors.toList());
|
|
|
+ Collection packageIds = Transform.getIds(prPackage, UserOrderRecord.class, "productId");
|
|
|
+ List<CoursePackage> coursePackageList = coursePackageService.select(packageIds);
|
|
|
+ List<Integer> courseExtendIds = new ArrayList<>();
|
|
|
+ Map coursePackageMap = Transform.getMap(coursePackageList, CoursePackage.class, "id");
|
|
|
+ for(UserOrderRecord r : prPackage){
|
|
|
+ if (!coursePackageMap.containsKey(r.getProductId())) continue;
|
|
|
+ CoursePackage coursePackage = (CoursePackage) coursePackageMap.get(r.getProductId());
|
|
|
+ courseExtendIds.addAll(Arrays.stream(coursePackage.getCourseIds()).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ List<Course> courseExtendList = courseService.select(courseExtendIds);
|
|
|
+ Map courseExtendMap = Transform.getMap(courseExtendList, Course.class, "id");
|
|
|
+ for(UserOrderRecord r: prPackage){
|
|
|
+ if (!coursePackageMap.containsKey(r.getProductId())) continue;
|
|
|
+ CoursePackage coursePackage = (CoursePackage) coursePackageMap.get(r.getProductId());
|
|
|
+ for(Integer courseId : coursePackage.getCourseIds()){
|
|
|
+ if (!courseExtendMap.containsKey(courseId)) continue;
|
|
|
+ Course course = (Course) courseExtendMap.get(courseId);
|
|
|
+ titles.add(course.getTitle());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定资料
|
|
|
+ List<UserOrderRecord> prData = recordList.stream().filter((row)-> row.getProductType().equals(ProductType.DATA.key)).collect(Collectors.toList());
|
|
|
+ Collection dataIds = Transform.getIds(prData, UserOrderRecord.class, "productId");
|
|
|
+ List<CourseData> courseDataList = courseDataService.select(dataIds);
|
|
|
+ Map courseDataMap = Transform.getMap(courseDataList, CourseData.class, "id");
|
|
|
+ for(UserOrderRecord r: prData){
|
|
|
+ if (courseDataMap.containsKey(r.getProductId())) continue;
|
|
|
+ CourseData courseData = (CourseData) courseDataMap.get(r.getProductId());
|
|
|
+ titles.add(courseData.getTitle());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定课程
|
|
|
+ List<UserOrderRecord> prCourse = recordList.stream().filter((row)-> row.getProductType().equals(ProductType.COURSE.key)).collect(Collectors.toList());
|
|
|
+ Collection courseIds = Transform.getIds(prCourse, UserOrderRecord.class, "productId");
|
|
|
+ List<Course> courseList = courseService.select(courseIds);
|
|
|
+ Map courseMap = Transform.getMap(courseList, Course.class, "id");
|
|
|
+ for(UserOrderRecord r: prCourse){
|
|
|
+ if (courseMap.containsKey(r.getProductId())) continue;
|
|
|
+ Course course = (Course) courseMap.get(r.getProductId());
|
|
|
+ titles.add(course.getTitle());
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("number", String.valueOf(titles.size()));
|
|
|
+ map.put("title", titles.get(0));
|
|
|
+ map.put("titleJoin", String.join("”,“", titles));
|
|
|
+ send(user, MessageCategory.PAY_MULTI, map, userOrder.getId());
|
|
|
+ }
|
|
|
+ // 赠品
|
|
|
+ List<UserOrderRecord> gifts = recordList.stream().filter((checkout)-> checkout.getSource().equals(RecordSource.GIFT_COURSE.key)).collect(Collectors.toList());
|
|
|
+ for(UserOrderRecord gift: gifts){
|
|
|
+ Map<String, String> giftMap = new HashMap<>();
|
|
|
+ ServiceKey key = ServiceKey.ValueOf(gift.getService());
|
|
|
+ map.put("title", key.title);
|
|
|
+ // 获取赠品链接
|
|
|
+ switch(key){
|
|
|
+ case QX_CAT:
|
|
|
+ map.put("link", MessageCategory.QX_CAT_PAY.link);
|
|
|
+ map.put("linkTitle", MessageCategory.QX_CAT_PAY.linkTitle);
|
|
|
+ break;
|
|
|
+ case TEXTBOOK:
|
|
|
+ map.put("link", MessageCategory.TEXTBOOK_PAY.link);
|
|
|
+ map.put("linkTitle", MessageCategory.TEXTBOOK_PAY.linkTitle);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ send(user, MessageCategory.COURSE_GIFT, giftMap, gift.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开通到期提醒
|
|
|
+ * @param user
|
|
|
+ * @param record
|
|
|
+ * @param days
|
|
|
+ */
|
|
|
+ public void sendOpenExpire(User user, UserOrderRecord record, Integer days){
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("days", String.valueOf(days));
|
|
|
+ map.put("expireDate", getDate(record.getEndTime()));
|
|
|
+ map.put("nickname", user.getNickname());
|
|
|
+ switch(ProductType.ValueOf(record.getProductType())){
|
|
|
+ case SERVICE:
|
|
|
+ ServiceKey key = ServiceKey.ValueOf(record.getService());
|
|
|
+ map.put("title", key.title);
|
|
|
+ switch(key){
|
|
|
+ case TEXTBOOK:
|
|
|
+ send(user, MessageCategory.TEXTBOOK_OPEN_EXPIRE, map, record.getId());
|
|
|
+ break;
|
|
|
+ case QX_CAT:
|
|
|
+ send(user, MessageCategory.QX_CAT_OPEN_EXPIRE, map, record.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case COURSE:
|
|
|
+ Course course = courseService.get(record.getProductId());
|
|
|
+ map.put("title", course.getTitle());
|
|
|
+ send(user, MessageCategory.COURSE_OPEN_EXPIRE, map, record.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用到期提醒
|
|
|
+ * @param user
|
|
|
+ * @param record
|
|
|
+ * @param days
|
|
|
+ */
|
|
|
+ public void sendUseExpire(User user, UserOrderRecord record, Integer days){
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("days", String.valueOf(days));
|
|
|
+ map.put("expireDate", getDate(record.getUseEndTime()));
|
|
|
+ map.put("nickname", user.getNickname());
|
|
|
+ switch(ProductType.ValueOf(record.getProductType())){
|
|
|
+ case SERVICE:
|
|
|
+ ServiceKey key = ServiceKey.ValueOf(record.getService());
|
|
|
+ map.put("title", key.title);
|
|
|
+ switch(key){
|
|
|
+ case VIP:
|
|
|
+ send(user, MessageCategory.VIP_USE_EXPIRE, map, record.getId());
|
|
|
+ break;
|
|
|
+ case TEXTBOOK:
|
|
|
+ send(user, MessageCategory.TEXTBOOK_USE_EXPIRE, map, record.getId());
|
|
|
+ break;
|
|
|
+ case QX_CAT:
|
|
|
+ send(user, MessageCategory.QX_CAT_USE_EXPIRE, map, record.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case COURSE:
|
|
|
+ Course course = courseService.get(record.getProductId());
|
|
|
+ map.put("title", course.getTitle());
|
|
|
+ send(user, MessageCategory.COURSE_USE_EXPIRE, map, record.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -226,13 +575,26 @@ public class MessageExtendService {
|
|
|
* 资料名称:{title}
|
|
|
* 更新时间:{updateTime}
|
|
|
*/
|
|
|
- public void sendDataUpdate(User user, CourseData data, CourseDataHistory history){
|
|
|
+ public void sendDataUpdate(User user, CourseData data, CourseDataHistory history, Boolean subscribe){
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("title", data.getTitle());
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- String time = sdf.format(history.getTime());
|
|
|
- map.put("time", time);
|
|
|
- send(user, MessageCategory.DATA_UPDATE, map);
|
|
|
+ map.put("nickname", user.getNickname());
|
|
|
+ map.put("email", user.getEmail());
|
|
|
+ map.put("version", history.getVersion());
|
|
|
+ map.put("description", String.format("位置:%s, 原内容:%s, 更改为:%s", history.getPosition(), history.getOriginContent(), history.getContent()));
|
|
|
+ switch(DataType.ValueOf(data.getDataType())){
|
|
|
+ case PAPER:
|
|
|
+ send(user, MessageCategory.DATA_UPDATE_PAPER, map, data.getId());
|
|
|
+ break;
|
|
|
+ case ELECTRON:
|
|
|
+ if (subscribe){
|
|
|
+ map.put("attachment", data.getResource());
|
|
|
+ send(user, MessageCategory.DATA_UPDATE_SUBSCRIBE, map, data.getId());
|
|
|
+ }else{
|
|
|
+ send(user, MessageCategory.DATA_UPDATE_BASE, map, data.getId());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -242,21 +604,32 @@ public class MessageExtendService {
|
|
|
* 提问状态:{status}, 精选、隐藏
|
|
|
*/
|
|
|
public void sendAskQuestion(User user,UserAskQuestion userAskQuestion){
|
|
|
+ // 非学员
|
|
|
+ if (user.getIsCourse() == 0) return;
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("content", userAskQuestion.getContent());
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- String time = sdf.format(new Date());
|
|
|
- map.put("time", time);
|
|
|
- AnswerStatus status = AnswerStatus.ValueOf(userAskQuestion.getAnswerStatus());
|
|
|
- if (status == AnswerStatus.ANSWER){
|
|
|
- map.put("status", "已回答");
|
|
|
- }else if (status == AnswerStatus.IGNORE){
|
|
|
- map.put("status", "已隐藏");
|
|
|
- }
|
|
|
- if(userAskQuestion.getShowStatus() > 0){
|
|
|
- map.put("status", "精选");
|
|
|
+ map.put("date", getDate(userAskQuestion.getCreateTime()));
|
|
|
+ QuestionNo questionNo = questionNoService.get(userAskQuestion.getQuestionNoId());
|
|
|
+ map.put("title", questionNo.getTitle());
|
|
|
+
|
|
|
+ switch(AnswerStatus.ValueOf(userAskQuestion.getAnswerStatus())){
|
|
|
+ case ANSWER:
|
|
|
+ if(userAskQuestion.getShowStatus() > 0){
|
|
|
+ // 替换内容较多
|
|
|
+ String link = replaceLink(MessageCategory.ASK_QUESTION_SPECIAL.link, "id", userAskQuestion.getId());
|
|
|
+ link = replaceLink(link, "questionNoId", userAskQuestion.getQuestionNoId());
|
|
|
+ map.put("link", link);
|
|
|
+ map.put("linkTitle", MessageCategory.ASK_QUESTION_SPECIAL.linkTitle);
|
|
|
+ send(user, MessageCategory.ASK_QUESTION_SPECIAL, map, userAskQuestion.getId());
|
|
|
+ }else{
|
|
|
+ send(user, MessageCategory.ASK_QUESTION_HANDLE, map, userAskQuestion.getId());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case IGNORE:
|
|
|
+ send(user, MessageCategory.ASK_QUESTION_IGNORE, map, userAskQuestion.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
}
|
|
|
- send(user, MessageCategory.ASK_QUESTION, map);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -266,21 +639,34 @@ public class MessageExtendService {
|
|
|
* 提问状态:{status}, 精选、隐藏
|
|
|
*/
|
|
|
public void sendAskCourse(User user, UserAskCourse userAskCourse){
|
|
|
+ // 非学员
|
|
|
+ if (user.getIsCourse() == 0) return;
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("content", userAskCourse.getContent());
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- String time = sdf.format(new Date());
|
|
|
- map.put("time", time);
|
|
|
- AnswerStatus status = AnswerStatus.ValueOf(userAskCourse.getAnswerStatus());
|
|
|
- if (status == AnswerStatus.ANSWER){
|
|
|
- map.put("status", "已回答");
|
|
|
- }else if (status == AnswerStatus.IGNORE){
|
|
|
- map.put("status", "已隐藏");
|
|
|
- }
|
|
|
- if(userAskCourse.getShowStatus() > 0){
|
|
|
- map.put("status", "精选");
|
|
|
+ map.put("date", getDate(userAskCourse.getCreateTime()));
|
|
|
+ Course course = courseService.get(userAskCourse.getCourseId());
|
|
|
+ map.put("title", course.getTitle());
|
|
|
+ CourseNo courseNo = courseNoService.get(userAskCourse.getCourseNoId());
|
|
|
+ map.put("no", String.valueOf(courseNo.getNo()));
|
|
|
+ switch(AnswerStatus.ValueOf(userAskCourse.getAnswerStatus())){
|
|
|
+ case ANSWER:
|
|
|
+ if(userAskCourse.getShowStatus() > 0){
|
|
|
+ // 替换内容较多
|
|
|
+ String link = replaceLink(MessageCategory.ASK_COURSE_SPECIAL.link, "id", userAskCourse.getId());
|
|
|
+ link = replaceLink(link, "courseId", userAskCourse.getCourseId());
|
|
|
+ link = replaceLink(link, "courseNoId", userAskCourse.getCourseNoId());
|
|
|
+ map.put("link", link);
|
|
|
+ map.put("linkTitle", MessageCategory.ASK_COURSE_SPECIAL.linkTitle);
|
|
|
+ send(user, MessageCategory.ASK_COURSE_SPECIAL, map, userAskCourse.getId());
|
|
|
+ }else{
|
|
|
+ send(user, MessageCategory.ASK_COURSE_HANDLE, map, userAskCourse.getId());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case IGNORE:
|
|
|
+ send(user, MessageCategory.ASK_COURSE_IGNORE, map, userAskCourse.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
}
|
|
|
- send(user, MessageCategory.ASK_COURSE, map);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -335,7 +721,15 @@ public class MessageExtendService {
|
|
|
break;
|
|
|
}
|
|
|
map.put("channel", channel);
|
|
|
- send(user, MessageCategory.FAQ_CALLBACK, map);
|
|
|
+ switch(AnswerStatus.ValueOf(faq.getAnswerStatus())){
|
|
|
+ case ANSWER:
|
|
|
+ send(user, MessageCategory.FAQ_HANDLE, map, faq.getId());
|
|
|
+ break;
|
|
|
+ case IGNORE:
|
|
|
+ send(user, MessageCategory.FAQ_IGNORE, map, faq.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -344,57 +738,97 @@ public class MessageExtendService {
|
|
|
* 应更正:{correct}
|
|
|
* 处理结果:{status}
|
|
|
*/
|
|
|
- public void sendFeedbackAnswer(User user, UserFeedbackError feedbackError){
|
|
|
+ public void sendFeedbackError(User user, UserFeedbackError feedbackError, UserOrderRecord record){
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
- map.put("content", feedbackError.getOriginContent());
|
|
|
- AnswerStatus status = AnswerStatus.ValueOf(feedbackError.getStatus());
|
|
|
- if (status == AnswerStatus.ANSWER){
|
|
|
- map.put("status", "已采纳");
|
|
|
- }else if (status == AnswerStatus.IGNORE){
|
|
|
- map.put("status", "已忽略");
|
|
|
- }else if (status == AnswerStatus.NOHANDLE){
|
|
|
- map.put("status", "无需处理");
|
|
|
+ map.put("time", getTime(feedbackError.getCreateTime()));
|
|
|
+ map.put("content", feedbackError.getContent());
|
|
|
+ map.put("title", feedbackError.getTitle());
|
|
|
+ if (feedbackError.getModule().equals(FeedbackModule.DATA.key)){
|
|
|
+ String[] p = feedbackError.getPosition().split(",");
|
|
|
+ map.put("position", String.format("第%s页第%s行", p[0], p[1]));
|
|
|
+ }else{
|
|
|
+ map.put("position", AskTarget.ValueOf(feedbackError.getPosition()).title);
|
|
|
+ }
|
|
|
+ map.put("originContent", feedbackError.getOriginContent());
|
|
|
+ if (record != null){
|
|
|
+ map.put("useExpireDays", String.valueOf(record.getUseExpireDays()));
|
|
|
+ }
|
|
|
+ switch(AnswerStatus.ValueOf(feedbackError.getStatus())){
|
|
|
+ case ANSWER:
|
|
|
+ send(user, MessageCategory.FEEDBACK_ERROR_HANDLE, map, feedbackError.getId());
|
|
|
+ break;
|
|
|
+ case IGNORE:
|
|
|
+ send(user, MessageCategory.FEEDBACK_ERROR_IGNORE, map, feedbackError.getId());
|
|
|
+ break;
|
|
|
+ case NOHANDLE:
|
|
|
+ send(user, MessageCategory.FEEDBACK_ERROR_NOHANDLE, map, feedbackError.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
}
|
|
|
- map.put("correct", feedbackError.getContent());
|
|
|
- map.put("object", feedbackError.getTitle());
|
|
|
- send(user, MessageCategory.FEEDBACK_CALLBACK, map);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 注册成功通知
|
|
|
- * @param user
|
|
|
+ * 纠错对象:{object}
|
|
|
+ * 错误内容:{content}
|
|
|
+ * 应更正:{correct}
|
|
|
+ * 处理结果:{status}
|
|
|
*/
|
|
|
- public void sendRegister(User user){
|
|
|
+ public void sendTextbookFeedback(User user, UserTextbookFeedback textbookFeedback, UserOrderRecord record){
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
- map.put("mobile", user.getMobile());
|
|
|
- send(user, MessageCategory.REGISTER, map);
|
|
|
+ map.put("time", getTime(textbookFeedback.getCreateTime()));
|
|
|
+ map.put("content", textbookFeedback.getContent());
|
|
|
+ map.put("subject", QuestionSubject.ValueOf(textbookFeedback.getQuestionSubject()).title);
|
|
|
+ map.put("no", String.valueOf(textbookFeedback.getNo()));
|
|
|
+ FeedbackTarget target = FeedbackTarget.ValueOf(textbookFeedback.getTarget());
|
|
|
+ map.put("target", target.title);
|
|
|
+ map.put("result", target.result);
|
|
|
+ map.put("handle", target.handle);
|
|
|
+ if (record != null){
|
|
|
+ map.put("useExpireDays", String.valueOf(record.getUseExpireDays()));
|
|
|
+ }
|
|
|
+ switch(AnswerStatus.ValueOf(textbookFeedback.getStatus())){
|
|
|
+ case ANSWER:
|
|
|
+ send(user, MessageCategory.TEXTBOOK_FEEDBACK_HANDLE, map, textbookFeedback.getId());
|
|
|
+ break;
|
|
|
+ case IGNORE:
|
|
|
+ send(user, MessageCategory.TEXTBOOK_FEEDBACK_IGNORE, map, textbookFeedback.getId());
|
|
|
+ break;
|
|
|
+ case NOHANDLE:
|
|
|
+ send(user, MessageCategory.TEXTBOOK_FEEDBACK_NOHANDLE, map, textbookFeedback.getId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 邮箱绑定
|
|
|
+ * 注册成功通知
|
|
|
* @param user
|
|
|
*/
|
|
|
- public void sendEmailBind(User user){
|
|
|
+ public void sendRegister(User user){
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
- map.put("nickname", user.getNickname());
|
|
|
+ map.put("mobile", user.getMobile());
|
|
|
map.put("email", user.getEmail());
|
|
|
- send(user, MessageCategory.EMAIL_CHANGE, map);
|
|
|
+ send(user, MessageCategory.REGISTER, map, 0);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 邮箱变更
|
|
|
* @param user
|
|
|
*/
|
|
|
- public void sendEmailChange(User user, String email){
|
|
|
- if(email != null && !email.isEmpty()){
|
|
|
+ public void sendEmailChange(User user, String newEmail){
|
|
|
+ if(user.getEmail() != null && !user.getEmail().isEmpty()){
|
|
|
Map<String, String> unbindMap = new HashMap<>();
|
|
|
unbindMap.put("nickname", user.getNickname());
|
|
|
- unbindMap.put("emails", email);
|
|
|
- send(user, MessageCategory.EMAIL_UNNBIND, unbindMap);
|
|
|
+ unbindMap.put("emails", user.getEmail());
|
|
|
+ String[] emails = newEmail.split("@");
|
|
|
+ emails[0] = "****"+emails[0].substring(emails[0].length() - 3);
|
|
|
+ unbindMap.put("email", String.join("@", emails));
|
|
|
+ send(user, MessageCategory.EMAIL_UNNBIND, unbindMap, 0);
|
|
|
}
|
|
|
Map<String, String> changeMap = new HashMap<>();
|
|
|
changeMap.put("nickname", user.getNickname());
|
|
|
- send(user, MessageCategory.EMAIL_CHANGE, changeMap);
|
|
|
+ changeMap.put("emails", newEmail);
|
|
|
+ send(user, MessageCategory.EMAIL_CHANGE, changeMap, 0);
|
|
|
}
|
|
|
|
|
|
private String replaceBody(String body, Map<String, String> params){
|
|
@@ -404,4 +838,22 @@ public class MessageExtendService {
|
|
|
}
|
|
|
return body;
|
|
|
}
|
|
|
+
|
|
|
+ private String replaceLink(String link, String p, Integer relationId){
|
|
|
+ return link.replace("\\{"+p+"}", String.valueOf(relationId));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String makeLink(String link, String linkTitle, Integer relationId){
|
|
|
+ return String.format("<a href=\"%s\" target=\"_blank\">%s</a>", pcUrl + replaceLink(link, "id",relationId), linkTitle);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getDate(Date date){
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
|
|
|
+ return sdf.format(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTime(Date time){
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
+ return sdf.format(time);
|
|
|
+ }
|
|
|
}
|