|
@@ -6,6 +6,11 @@ import com.uas.account.entity.User;
|
|
|
import com.uas.account.entity.UserView;
|
|
import com.uas.account.entity.UserView;
|
|
|
import com.uas.account.util.AccountUtils;
|
|
import com.uas.account.util.AccountUtils;
|
|
|
import com.uas.account.util.FlexJsonUtil;
|
|
import com.uas.account.util.FlexJsonUtil;
|
|
|
|
|
+import com.uas.ps.core.page.PageInfo;
|
|
|
|
|
+import com.uas.ps.core.page.PageParams;
|
|
|
|
|
+import com.uas.ps.core.page.criteria.LogicalExpression;
|
|
|
|
|
+import com.uas.ps.core.page.criteria.PredicateUtils;
|
|
|
|
|
+import com.uas.ps.core.page.criteria.SimpleExpression;
|
|
|
import com.uas.ps.message.dao.AppDao;
|
|
import com.uas.ps.message.dao.AppDao;
|
|
|
import com.uas.ps.message.dao.MessageDao;
|
|
import com.uas.ps.message.dao.MessageDao;
|
|
|
import com.uas.ps.message.domain.App;
|
|
import com.uas.ps.message.domain.App;
|
|
@@ -28,14 +33,19 @@ import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
import org.apache.log4j.Logger;
|
|
import org.apache.log4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by wangyc on 2018/1/13.
|
|
* Created by wangyc on 2018/1/13.
|
|
@@ -51,11 +61,11 @@ public class MessageServiceImpl implements MessageService {
|
|
|
|
|
|
|
|
private static final Logger logger = Logger.getLogger(Logger.class);
|
|
private static final Logger logger = Logger.getLogger(Logger.class);
|
|
|
|
|
|
|
|
- private RestTemplate restTemplate;
|
|
|
|
|
|
|
+// private RestTemplate restTemplate;
|
|
|
|
|
|
|
|
- private static final String EMAIL_REGEX = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
|
|
|
|
|
|
|
+// private static final String EMAIL_REGEX = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
|
|
|
|
|
|
|
|
- private static final String TEL_REGEXP = "^((\\(\\d{3}\\))|(\\d{3}\\-))?(13|15|18|17)\\d{9}$";
|
|
|
|
|
|
|
+// private static final String TEL_REGEXP = "^((\\(\\d{3}\\))|(\\d{3}\\-))?(13|15|18|17)\\d{9}$";
|
|
|
|
|
|
|
|
private static final String PROD_URL = "http://113.105.74.140:8092/tigase/baiduPush";
|
|
private static final String PROD_URL = "http://113.105.74.140:8092/tigase/baiduPush";
|
|
|
/**
|
|
/**
|
|
@@ -84,18 +94,41 @@ public class MessageServiceImpl implements MessageService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<Message> getMessages(String receiverUu, String receiverEnuu, String consumerApp) {
|
|
|
|
|
- List<Message> messages = new ArrayList<>();
|
|
|
|
|
|
|
+ public Page<Message> getMessages(String receiverUu, final String receiverEnuu, String consumerApp,
|
|
|
|
|
+ PageParams pageParams) {
|
|
|
if (StringUtils.isEmpty(receiverUu) || StringUtils.isEmpty(receiverEnuu)) {
|
|
if (StringUtils.isEmpty(receiverUu) || StringUtils.isEmpty(receiverEnuu)) {
|
|
|
throw new ParameterMissingException("接收人信息为空");
|
|
throw new ParameterMissingException("接收人信息为空");
|
|
|
}
|
|
}
|
|
|
- App consumerAppExists = appDao.findByName(consumerApp);
|
|
|
|
|
|
|
+ final App consumerAppExists = appDao.findByName(consumerApp);
|
|
|
if (consumerApp == null) {
|
|
if (consumerApp == null) {
|
|
|
throw new IllegalOperatorException("接收应用不存在");
|
|
throw new IllegalOperatorException("接收应用不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- messages = messageDao.findByReceiverUuAndReceiverEnuuAndConsumerAppId(Long.valueOf(receiverUu),
|
|
|
|
|
- Long.valueOf(receiverEnuu), consumerAppExists.getId());
|
|
|
|
|
|
|
+ // 消息接收人过滤
|
|
|
|
|
+ SimpleExpression receiverUuExp = PredicateUtils.eq("receiverUu", Long.valueOf(receiverUu), true);
|
|
|
|
|
+ // 消息接收企业过滤
|
|
|
|
|
+ final SimpleExpression receiverEnuuExp = PredicateUtils.eq("receiverEnuu", Long.valueOf(receiverEnuu), true);
|
|
|
|
|
+
|
|
|
|
|
+ final SimpleExpression[] simpleExpressions = new SimpleExpression[]{receiverUuExp, receiverEnuuExp};
|
|
|
|
|
+ final LogicalExpression logicalExpression = PredicateUtils.and(simpleExpressions);
|
|
|
|
|
+
|
|
|
|
|
+ final PageInfo pageInfo = new PageInfo(pageParams);
|
|
|
|
|
+ pageInfo.expression(logicalExpression);
|
|
|
|
|
+
|
|
|
|
|
+ Page<Message> messages = messageDao.findAll(new Specification<Message>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Predicate toPredicate(Root<Message> root, CriteriaQuery<?> criteriaQuery,
|
|
|
|
|
+ CriteriaBuilder criteriaBuilder) {
|
|
|
|
|
+ Predicate messagePredicate = criteriaBuilder.and(logicalExpression.toPredicate(root, criteriaQuery,
|
|
|
|
|
+ criteriaBuilder));
|
|
|
|
|
+ // 消费应用过滤
|
|
|
|
|
+ Predicate consumerAppPredicate = criteriaBuilder.equal(root.join("consumerApp").get("id"),
|
|
|
|
|
+ consumerAppExists.getId());
|
|
|
|
|
+ Predicate all = criteriaBuilder.and(messagePredicate, consumerAppPredicate);
|
|
|
|
|
+ criteriaQuery.where(all);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }, pageInfo);
|
|
|
return messages;
|
|
return messages;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -117,8 +150,8 @@ public class MessageServiceImpl implements MessageService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取改应用应接收的未读、未发送的需要推送的消息
|
|
// 获取改应用应接收的未读、未发送的需要推送的消息
|
|
|
- List<Message> messages = messageDao.findByConsumerAppIdAndIsReadAndIsSentNeedToSend(consumerAppExists.getId(),
|
|
|
|
|
- Constant.NO, Constant.NO);
|
|
|
|
|
|
|
+ List<Message> messages = messageDao.findByConsumerAppIdAndIsReadAndIsSentNeedToSend(
|
|
|
|
|
+ consumerAppExists.getId(), Constant.NO, Constant.NO);
|
|
|
logger.info("信息数量:" + messages.size());
|
|
logger.info("信息数量:" + messages.size());
|
|
|
Map<String, Object> resultMap = sendMessageByAPI(messages, consumerApp);
|
|
Map<String, Object> resultMap = sendMessageByAPI(messages, consumerApp);
|
|
|
resultMap.put("success", "success");
|
|
resultMap.put("success", "success");
|
|
@@ -268,7 +301,8 @@ public class MessageServiceImpl implements MessageService {
|
|
|
if (!CollectionUtils.isEmpty(messages)) {
|
|
if (!CollectionUtils.isEmpty(messages)) {
|
|
|
for (Message message : messages) {
|
|
for (Message message : messages) {
|
|
|
try {
|
|
try {
|
|
|
- UserView receiver = AccountUtils.getImUserByUserUU(message.getReceiverUu(), message.getReceiverEnuu());
|
|
|
|
|
|
|
+ UserView receiver = AccountUtils.getImUserByUserUU(message.getReceiverUu(),
|
|
|
|
|
+ message.getReceiverEnuu());
|
|
|
logger.info("接收人:" + receiver.getName());
|
|
logger.info("接收人:" + receiver.getName());
|
|
|
// 发送邮件
|
|
// 发送邮件
|
|
|
// if (message.getSmsType().contains(SMSType.MAIL)) {
|
|
// if (message.getSmsType().contains(SMSType.MAIL)) {
|
|
@@ -286,7 +320,7 @@ public class MessageServiceImpl implements MessageService {
|
|
|
// sendIM(message, receiver, consumerApp);
|
|
// sendIM(message, receiver, consumerApp);
|
|
|
// }
|
|
// }
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- System.err.println(e.getMessage());
|
|
|
|
|
|
|
+ logger.info(e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
messageDao.save(messages);
|
|
messageDao.save(messages);
|
|
@@ -318,6 +352,7 @@ public class MessageServiceImpl implements MessageService {
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|