|
@@ -1,14 +1,23 @@
|
|
|
package org.lym.pom.scheduled;
|
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
import org.lym.pom.constant.NewVersionNotifyStrategyEnum;
|
|
|
import org.lym.pom.dto.business.NotifyEmailBO;
|
|
|
import org.lym.pom.dto.business.NotifyProjectBO;
|
|
|
import org.lym.pom.dto.business.NotifyRecordBO;
|
|
|
-import org.lym.pom.entity.*;
|
|
|
+import org.lym.pom.entity.DependencyIndex;
|
|
|
+import org.lym.pom.entity.NotifyRecordEntity;
|
|
|
+import org.lym.pom.entity.ProjectEntity;
|
|
|
+import org.lym.pom.entity.ThirdProjectEntity;
|
|
|
+import org.lym.pom.entity.UserEntity;
|
|
|
import org.lym.pom.notify.event.SendNotifyEvent;
|
|
|
-import org.lym.pom.service.*;
|
|
|
+import org.lym.pom.service.INotifyRecordService;
|
|
|
+import org.lym.pom.service.INotifySendService;
|
|
|
+import org.lym.pom.service.IProjectService;
|
|
|
+import org.lym.pom.service.IThirdProjectService;
|
|
|
+import org.lym.pom.service.IUserService;
|
|
|
import org.shoulder.core.exception.CommonErrorCodeEnum;
|
|
|
+import org.shoulder.core.log.AppLoggers;
|
|
|
+import org.shoulder.core.log.Logger;
|
|
|
import org.shoulder.core.util.AssertUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.event.EventListener;
|
|
@@ -18,7 +27,12 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -27,10 +41,11 @@ import java.util.stream.Collectors;
|
|
|
*
|
|
|
* @author lym
|
|
|
*/
|
|
|
-@Slf4j
|
|
|
@Service
|
|
|
public class SendNotifyTask {
|
|
|
|
|
|
+ private final Logger log = AppLoggers.APP_SERVICE;
|
|
|
+
|
|
|
@Autowired
|
|
|
private INotifyRecordService notifyRecordService;
|
|
|
|
|
@@ -111,7 +126,8 @@ public class SendNotifyTask {
|
|
|
notifiedRecordIds.add(record.getId());
|
|
|
ProjectEntity project = projectMap.get(record.getProjectId());
|
|
|
UserEntity user = userMap.get(project.getUserId());
|
|
|
- NotifyProjectBO notifyProjectBO = projectIdToBoMap.computeIfAbsent(project.getId(), id -> new NotifyProjectBO(project, user));
|
|
|
+ NotifyProjectBO notifyProjectBO = projectIdToBoMap.computeIfAbsent(project.getId(),
|
|
|
+ id -> new NotifyProjectBO(project, user));
|
|
|
notifyProjectBO.addNotifyRecordBO(record, thirdProjectMap.get(record.getDependencyIndex()));
|
|
|
notifyProjectBO.setNotifyReason(notifyReason);
|
|
|
}
|
|
@@ -130,7 +146,6 @@ public class SendNotifyTask {
|
|
|
log.info("finished sending notify TASK!");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private NotifyEmailBO generateNotifyEmailBO(NotifyProjectBO notifyProjectBO) {
|
|
|
NotifyEmailBO emailBO = new NotifyEmailBO();
|
|
|
emailBO.setEmail(notifyProjectBO.getUser().getEmail());
|
|
@@ -167,25 +182,31 @@ public class SendNotifyTask {
|
|
|
String splitLine = "</br><hr></br>";
|
|
|
|
|
|
String headTemplate = "Deer {USER_NAME}</br>" +
|
|
|
- " Your project <b>{PROJECT_NAME}</b> may need update.";
|
|
|
+ " Your project <b>{PROJECT_NAME}</b> may need update.";
|
|
|
String header = headTemplate
|
|
|
.replace("{PROJECT_NAME}", PROJECT_NAME)
|
|
|
.replace("{USER_NAME}", USER_NAME);
|
|
|
|
|
|
StringBuilder result = new StringBuilder(header);
|
|
|
// -------------------------------------------------------------
|
|
|
-// result.append(splitLine);
|
|
|
+ // result.append(splitLine);
|
|
|
String eachDependencyTemplate = "* The dependency({DEPENDENCY_ID}) has published a new stable version " +
|
|
|
- "({NEW_VERSION}) Your version is {YOUR_VERSION}.</br>";
|
|
|
+ "({NEW_VERSION}) Your version is {YOUR_VERSION}.</br>";
|
|
|
if (from_style) {
|
|
|
String tableHeader = "<style type=\"text/css\">" +
|
|
|
- " table.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}" +
|
|
|
- " table.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}" +
|
|
|
- " table.tftable tr {background-color:#ffffff;}" +
|
|
|
- " table.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}" +
|
|
|
- "</style>" +
|
|
|
- "<table id=\"tfhover\" class=\"tftable\" border=\"1\">" +
|
|
|
- "<tr><th>Dependency</th><th>Your<br>Version</th><th>New<br>Version</th>";
|
|
|
+ " table.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: "
|
|
|
+ + "#729ea5;border-collapse: collapse;}"
|
|
|
+ +
|
|
|
+ " table.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;"
|
|
|
+ + "border-style: solid;border-color: #729ea5;text-align:left;}"
|
|
|
+ +
|
|
|
+ " table.tftable tr {background-color:#ffffff;}" +
|
|
|
+ " table.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: "
|
|
|
+ + "#729ea5;}"
|
|
|
+ +
|
|
|
+ "</style>" +
|
|
|
+ "<table id=\"tfhover\" class=\"tftable\" border=\"1\">" +
|
|
|
+ "<tr><th>Dependency</th><th>Your<br>Version</th><th>New<br>Version</th>";
|
|
|
result.append(tableHeader);
|
|
|
eachDependencyTemplate = "<tr><td>{DEPENDENCY_ID}</td><td>{YOUR_VERSION}</td><td>{NEW_VERSION}</td>";
|
|
|
}
|
|
@@ -200,15 +221,18 @@ public class SendNotifyTask {
|
|
|
// -------------------------------------------------------
|
|
|
result.append(splitLine);
|
|
|
|
|
|
- String unsubscribeUrl = "http://autoPom.itlym.cn/dependencies/updateNotifyStrategy?projectId={PROJECT_ID}&email&={USER_EMAIL}¬ifyStrategy=" + NewVersionNotifyStrategyEnum.IGNORE.getValue()
|
|
|
- .replace("{PROJECT_ID}", String.valueOf(notifyProjectBO.getProjectId()))
|
|
|
- .replace("{USER_EMAIL}", notifyProjectBO.getUser().getEmail());
|
|
|
- String LINK_POM_UPDATE_PROJECT = convertHtmlLink("View on PomUpdate", "http://autoPom.itlym.cn/projects?email=" + notifyProjectBO.getUser().getEmail());
|
|
|
+ String unsubscribeUrl =
|
|
|
+ "http://autoPom.itlym.cn/dependencies/updateNotifyStrategy?projectId={PROJECT_ID}&email&={USER_EMAIL}¬ifyStrategy="
|
|
|
+ + NewVersionNotifyStrategyEnum.IGNORE.getValue()
|
|
|
+ .replace("{PROJECT_ID}", String.valueOf(notifyProjectBO.getProjectId()))
|
|
|
+ .replace("{USER_EMAIL}", notifyProjectBO.getUser().getEmail());
|
|
|
+ String LINK_POM_UPDATE_PROJECT = convertHtmlLink("View on PomUpdate",
|
|
|
+ "http://autoPom.itlym.cn/projects?email=" + notifyProjectBO.getUser().getEmail());
|
|
|
String LINK_POM_UPDATE_UNSUBSCRIBE = convertHtmlLink("Unsubscribe", unsubscribeUrl, "gray", false);
|
|
|
|
|
|
String tailTemplate = " Notify Reason: {NOTIFY_REASON}.<br>" +
|
|
|
- "{LINK_POM_UPDATE_PROJECT}<br>" +
|
|
|
- "<br> {LINK_POM_UPDATE_UNSUBSCRIBE}";
|
|
|
+ "{LINK_POM_UPDATE_PROJECT}<br>" +
|
|
|
+ "<br> {LINK_POM_UPDATE_UNSUBSCRIBE}";
|
|
|
String tail = tailTemplate
|
|
|
.replace("{LINK_POM_UPDATE_PROJECT}", LINK_POM_UPDATE_PROJECT)
|
|
|
.replace("{LINK_POM_UPDATE_UNSUBSCRIBE}", LINK_POM_UPDATE_UNSUBSCRIBE)
|
|
@@ -246,10 +270,11 @@ public class SendNotifyTask {
|
|
|
private static String convertHtmlLink(String text, String url) {
|
|
|
return convertHtmlLink(text, url, "blue", true);
|
|
|
}
|
|
|
+
|
|
|
private static String convertHtmlLink(String text, String url, String color, boolean blod) {
|
|
|
if (StringUtils.hasText(url)) {
|
|
|
String style = " style=\"color:" + color + ";";
|
|
|
- if(blod) {
|
|
|
+ if (blod) {
|
|
|
style += "font-weight:bold;";
|
|
|
}
|
|
|
style += "\" ";
|