|
@@ -1,6 +1,8 @@
|
|
package com.bosshand.virgo.message.service;
|
|
package com.bosshand.virgo.message.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.bosshand.virgo.core.dao.MgrUserDao;
|
|
|
|
+import com.bosshand.virgo.core.model.MgrUser;
|
|
import com.bosshand.virgo.exception.ServiceException;
|
|
import com.bosshand.virgo.exception.ServiceException;
|
|
import com.bosshand.virgo.message.beetl.FlowMessageGenerator;
|
|
import com.bosshand.virgo.message.beetl.FlowMessageGenerator;
|
|
import com.bosshand.virgo.message.beetl.MessageGenerator;
|
|
import com.bosshand.virgo.message.beetl.MessageGenerator;
|
|
@@ -41,6 +43,17 @@ public class MessageService {
|
|
@Autowired
|
|
@Autowired
|
|
private ApiClient apiClient;
|
|
private ApiClient apiClient;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private MgrUserDao mgrUserDao;
|
|
|
|
+
|
|
|
|
+ private String getUserName(String userId) {
|
|
|
|
+ MgrUser user = mgrUserDao.getById(Long.parseLong(userId));
|
|
|
|
+ if (user != null) {
|
|
|
|
+ return user.getName();
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
public int insert(NotificationMessage notificationMessage) {
|
|
public int insert(NotificationMessage notificationMessage) {
|
|
return notificationMessageDao.insert(notificationMessage);
|
|
return notificationMessageDao.insert(notificationMessage);
|
|
}
|
|
}
|
|
@@ -49,20 +62,46 @@ public class MessageService {
|
|
return notificationMessageDao.updateViewed(id);
|
|
return notificationMessageDao.updateViewed(id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public NotificationMessage get(long id) {
|
|
|
|
+ NotificationMessage notificationMessage = notificationMessageDao.get(id);
|
|
|
|
+ notificationMessage.setSendUserName(this.getUserName(notificationMessage.getSender()));
|
|
|
|
+ return notificationMessage;
|
|
|
|
+ }
|
|
|
|
+
|
|
public List<NotificationMessage> getMessageByUserId(long userId) {
|
|
public List<NotificationMessage> getMessageByUserId(long userId) {
|
|
- return notificationMessageDao.getMessageByUserId(userId);
|
|
|
|
|
|
+ List<NotificationMessage> list = notificationMessageDao.getMessageByUserId(userId);
|
|
|
|
+ for (NotificationMessage message : list) {
|
|
|
|
+ message.setSendUserName(this.getUserName(message.getSender()));
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public List<NotificationMessage> getMessageByUserId(int messageType, long userId) {
|
|
public List<NotificationMessage> getMessageByUserId(int messageType, long userId) {
|
|
- return notificationMessageDao.getMessageByMessageType(messageType, userId);
|
|
|
|
|
|
+ List<NotificationMessage> list = notificationMessageDao.getMessageByMessageType(messageType, userId);
|
|
|
|
+ for (NotificationMessage message : list) {
|
|
|
|
+ message.setSendUserName(this.getUserName(message.getSender()));
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<NotificationMessage> count(int messageType, long userId, boolean viewed) {
|
|
|
|
+ List<NotificationMessage> list = notificationMessageDao.count(messageType, userId, viewed);
|
|
|
|
+ for (NotificationMessage message : list) {
|
|
|
|
+ message.setSendUserName(this.getUserName(message.getSender()));
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
|
|
|
|
public List<NotificationMessage> getMessageByViewed(long userId, boolean viewed) {
|
|
public List<NotificationMessage> getMessageByViewed(long userId, boolean viewed) {
|
|
- return notificationMessageDao.getMessageByViewed(userId, viewed);
|
|
|
|
|
|
+ List<NotificationMessage> list = notificationMessageDao.getMessageByViewed(userId, viewed);
|
|
|
|
+ for (NotificationMessage message : list) {
|
|
|
|
+ message.setSendUserName(this.getUserName(message.getSender()));
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
|
|
|
|
public void pushMessage(List<Long> receiptList, NotificationMessage message) throws ServiceException {
|
|
public void pushMessage(List<Long> receiptList, NotificationMessage message) throws ServiceException {
|
|
- pushMesssage(receiptList, message, false);
|
|
|
|
|
|
+ pushMessage(receiptList, message, false);
|
|
}
|
|
}
|
|
|
|
|
|
public void pushMessage(List<Long> receiptList, MessageGenerator messageGenerator) throws ServiceException {
|
|
public void pushMessage(List<Long> receiptList, MessageGenerator messageGenerator) throws ServiceException {
|
|
@@ -74,7 +113,7 @@ public class MessageService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void pushMesssage(List<Long> receiptList, NotificationMessage message, boolean sendPush) {
|
|
|
|
|
|
+ private void pushMessage(List<Long> receiptList, NotificationMessage message, boolean sendPush) {
|
|
if (receiptList != null && receiptList.size() > 0) {
|
|
if (receiptList != null && receiptList.size() > 0) {
|
|
receiptList.forEach(receipt -> {
|
|
receiptList.forEach(receipt -> {
|
|
message.setUserId(receipt);
|
|
message.setUserId(receipt);
|
|
@@ -92,7 +131,7 @@ public class MessageService {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public void pushMesssage(JSONObject json) {
|
|
|
|
|
|
+ public void pushMessage(JSONObject json) {
|
|
FlowMessageGenerator messageGenerator = new FlowMessageGenerator();
|
|
FlowMessageGenerator messageGenerator = new FlowMessageGenerator();
|
|
messageGenerator.setTemplateName(getTemplateName(json.getString("templateName")));
|
|
messageGenerator.setTemplateName(getTemplateName(json.getString("templateName")));
|
|
messageGenerator.setSender(json.getString("sender"));
|
|
messageGenerator.setSender(json.getString("sender"));
|