| | |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | |
| | | @Override |
| | | public Boolean pushMessageList(List<MessageRecord> messageRecordList) { |
| | | // 加入测试人员 |
| | | addSendMsgTest(messageRecordList); |
| | | // addSendMsgTest(messageRecordList); |
| | | List<String> cIdList = new ArrayList<>(); |
| | | AtomicReference<Boolean> push = new AtomicReference<>(false); |
| | | //相同的消息推送给多用户 |
| | | messageRecordList.forEach(messageRecord -> { |
| | | //获取用户cId |
| | | String clientId = getClientIdByUserId(messageRecord.getRecipient()); |
| | | cIdList.add(clientId); |
| | | if (null!=clientId && !clientId.equals("")) { |
| | | cIdList.add(clientId); |
| | | PushVO pushVO = new PushVO(); |
| | | pushVO.setCIds(cIdList); |
| | | pushVO.setTitle(messageRecord.getTheme()); |
| | | pushVO.setContent(messageRecord.getContent()); |
| | | |
| | | HashMap<String, Object> payload = new HashMap<>(); |
| | | payload.put("title",messageRecord.getTheme()); |
| | | payload.put("content", messageRecord.getContent()); |
| | | payload.put("payload", "test"); |
| | | pushVO.setPayload(payload); |
| | | push.set(pushMessage(pushVO)); |
| | | } |
| | | }); |
| | | |
| | | //uni-push 一次推送最多500名用户,所以分批推送 |
| | | List<List<String>> groupList = groupListByQuantity(cIdList, 400); |
| | | Boolean push = false; |
| | | for(List<String> cids :groupList){ |
| | | PushVO pushVO = new PushVO(); |
| | | |
| | | pushVO.setCIds(cids); |
| | | pushVO.setTitle(messageRecordList.get(0).getTheme()); |
| | | pushVO.setContent(messageRecordList.get(0).getContent()); |
| | | |
| | | HashMap<String, Object> payload = new HashMap<>(); |
| | | payload.put("title", messageRecordList.get(0).getTheme()); |
| | | payload.put("content", messageRecordList.get(0).getContent()); |
| | | payload.put("payload", "test"); |
| | | pushVO.setPayload(payload); |
| | | push = pushMessage(pushVO); |
| | | } |
| | | |
| | | return push; |
| | | return push.get(); |
| | | } |
| | | |
| | | /** |