|
|
@@ -1,8 +1,8 @@
|
|
|
package com.uas.ps.message.service.impl;
|
|
|
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.message.mail.domain.MailLog;
|
|
|
-import com.uas.message.mail.service.MailService;
|
|
|
import com.uas.ps.message.dao.AppDao;
|
|
|
import com.uas.ps.message.dao.MessageDao;
|
|
|
import com.uas.ps.message.domain.App;
|
|
|
@@ -83,18 +83,18 @@ public class MessageServiceImpl implements MessageService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Message> getMessages(String receiver, String consumerApp) {
|
|
|
+ public List<Message> getMessages(String receiverUu, String receiverEnuu, String consumerApp) {
|
|
|
List<Message> messages = new ArrayList<>();
|
|
|
- User user = FastjsonUtils.fromJson(receiver, User.class);
|
|
|
+ if (StringUtils.isEmpty(receiverUu) || StringUtils.isEmpty(receiverEnuu)) {
|
|
|
+ throw new ParameterMissingException("接收人信息为空");
|
|
|
+ }
|
|
|
App consumerAppExists = appDao.findByName(consumerApp);
|
|
|
if (consumerApp == null) {
|
|
|
throw new IllegalOperatorException("接收应用不存在");
|
|
|
}
|
|
|
|
|
|
- if (user.getUserUU() != null && user.getEnterprise() != null && user.getEnterprise().getUu() != null) {
|
|
|
- messages = messageDao.findByReceiverUuAndReceiverEnuuAndConsumerAppId(user.getUserUU(),
|
|
|
- user.getEnterprise().getUu(), consumerAppExists.getId());
|
|
|
- }
|
|
|
+ messages = messageDao.findByReceiverUuAndReceiverEnuuAndConsumerAppId(Long.valueOf(receiverUu),
|
|
|
+ Long.valueOf(receiverEnuu), consumerAppExists.getId());
|
|
|
return messages;
|
|
|
}
|
|
|
|
|
|
@@ -113,7 +113,8 @@ public class MessageServiceImpl implements MessageService {
|
|
|
}
|
|
|
|
|
|
// 获取改应用应接收的未读、未发送消息
|
|
|
- List<Message> messages = messageDao.findByConsumerAppIdAndIsReadAndIsSent(consumerAppExists.getId(), Constant.NO, Constant.NO);
|
|
|
+ List<Message> messages = messageDao.findByConsumerAppIdAndIsReadAndIsSent(consumerAppExists.getId(),
|
|
|
+ Constant.NO, Constant.NO);
|
|
|
|
|
|
Map<String, Object> resultMap = sendMessageByAPI(messages, consumerApp);
|
|
|
return resultMap;
|
|
|
@@ -164,7 +165,7 @@ public class MessageServiceImpl implements MessageService {
|
|
|
} else {
|
|
|
App app = appDao.findByName(String.valueOf(produceApp));
|
|
|
if (app == null) {
|
|
|
- throw new ParameterMissingException("发送应用不存在");
|
|
|
+ throw new IllegalOperatorException("发送应用不存在");
|
|
|
}
|
|
|
message.setProducerApp(app.getId());
|
|
|
}
|
|
|
@@ -195,7 +196,7 @@ public class MessageServiceImpl implements MessageService {
|
|
|
for (String consumer : consumers) {
|
|
|
App app = appDao.findByName(consumer);
|
|
|
if (app == null) {
|
|
|
- throw new ParameterMissingException("接收应用不存在");
|
|
|
+ throw new IllegalOperatorException("接收应用不存在");
|
|
|
}
|
|
|
consumerApps.add(app);
|
|
|
}
|
|
|
@@ -239,7 +240,7 @@ public class MessageServiceImpl implements MessageService {
|
|
|
* 推送消息(调用邮件、短信、IM接口)
|
|
|
* @param messages 消息
|
|
|
* @param consumerApp 消费app
|
|
|
- * @return
|
|
|
+ * @return resultMap
|
|
|
*/
|
|
|
private Map<String, Object> sendMessageByAPI(List<Message> messages, String consumerApp) {
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
@@ -260,7 +261,9 @@ public class MessageServiceImpl implements MessageService {
|
|
|
if (message.getSmsType().contains(SMSType.IM)) {
|
|
|
sendIM(message, consumerApp);
|
|
|
}
|
|
|
+ message.setIsSent(Constant.YES);
|
|
|
}
|
|
|
+ messageDao.save(messages);
|
|
|
}
|
|
|
return resultMap;
|
|
|
}
|
|
|
@@ -281,7 +284,8 @@ public class MessageServiceImpl implements MessageService {
|
|
|
object.put("params", message.getContent());
|
|
|
|
|
|
HttpEntity<String> formEntity = new HttpEntity<String>(object.toJSONString(), headers);
|
|
|
- ResponseEntity<MailLog> responseEntity = restTemplate.postForEntity(MAIL_CONSOLE_HOST + MAIL_SEND_URL, formEntity, MailLog.class);
|
|
|
+ ResponseEntity<MailLog> responseEntity = restTemplate.postForEntity(MAIL_CONSOLE_HOST + MAIL_SEND_URL,
|
|
|
+ formEntity, MailLog.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -290,18 +294,20 @@ public class MessageServiceImpl implements MessageService {
|
|
|
*/
|
|
|
private void sendSM(Message message) {
|
|
|
// TODO 账户中心获取用户手机号
|
|
|
- String templetId = "";
|
|
|
- User user = FastjsonUtils.fromJson(message.getReceiver(), User.class);
|
|
|
- if (user.getUserTel() != null) {
|
|
|
- try {
|
|
|
- SmsMessage sms = new SmsMessage();
|
|
|
- List<Object> obj = new ArrayList<Object>();
|
|
|
- sms.setParams(obj);
|
|
|
- sms.setReceiver(user.getUserTel());
|
|
|
- sms.setTemplateId(templetId);
|
|
|
- com.uas.ps.message.util.HttpUtil.sendPost(messageUrl, FastjsonUtils.toJson(sms));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ if (message.getSmTemplate() != null) {
|
|
|
+ String templetId = message.getSmTemplate();
|
|
|
+ User user = FastjsonUtils.fromJson(message.getReceiver(), User.class);
|
|
|
+ if (user.getUserTel() != null) {
|
|
|
+ try {
|
|
|
+ SmsMessage sms = new SmsMessage();
|
|
|
+ List<Object> obj = new ArrayList<Object>();
|
|
|
+ sms.setParams(obj);
|
|
|
+ sms.setReceiver(user.getUserTel());
|
|
|
+ sms.setTemplateId(templetId);
|
|
|
+ com.uas.ps.message.util.HttpUtil.sendPost(messageUrl, FastjsonUtils.toJson(sms));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -309,6 +315,7 @@ public class MessageServiceImpl implements MessageService {
|
|
|
/**
|
|
|
* 发送IM
|
|
|
* @param message 消息
|
|
|
+ * @param consumerApp 消费app
|
|
|
*/
|
|
|
private void sendIM(Message message, String consumerApp) {
|
|
|
Map<String, Object> params = new HashMap<>();
|