|
|
@@ -1,6 +1,7 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.dayaedu.cbs.common.enums.EAppKey;
|
|
|
import com.dayaedu.cbs.common.enums.EClientType;
|
|
|
import com.dayaedu.cbs.common.enums.message.EMessageSendMode;
|
|
|
@@ -20,7 +21,9 @@ import com.ym.mec.biz.dal.entity.SysMessageConfig;
|
|
|
import com.ym.mec.biz.dal.entity.WaitSendMessage;
|
|
|
import com.ym.mec.biz.dal.enums.MessageSendMode;
|
|
|
import com.ym.mec.biz.dal.enums.MessageTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.SendStatusEnum;
|
|
|
import com.ym.mec.biz.dal.page.SysMessageQueryInfo;
|
|
|
+import com.ym.mec.biz.dal.wrapper.SysMessageWrapper;
|
|
|
import com.ym.mec.biz.service.SysMessageConfigService;
|
|
|
import com.ym.mec.biz.service.SysMessageService;
|
|
|
import com.ym.mec.biz.service.SysUserService;
|
|
|
@@ -30,6 +33,7 @@ import com.ym.mec.common.entity.ImPrivateMessage;
|
|
|
import com.ym.mec.common.entity.ImSendMessageUserInfo;
|
|
|
import com.ym.mec.common.entity.ImTxtMessage;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
+import com.ym.mec.common.page.PageInfo;
|
|
|
import com.ym.mec.common.redis.service.RedisCache;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
@@ -54,6 +58,8 @@ import java.io.IOException;
|
|
|
import java.net.URL;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.ym.mec.biz.dal.enums.MessageTypeEnum.STUDENT_PUSH_VIP_BUY;
|
|
|
|
|
|
@@ -85,7 +91,7 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
// 发送验证码的间隔时间
|
|
|
public static final int CODE_INTERVAL_TIME = 60;
|
|
|
|
|
|
- private final int DEFAULT_CODE = 888888;
|
|
|
+ private final int DEFAULT_CODE = 666666;
|
|
|
|
|
|
@Value("${message.debugMode}")
|
|
|
private boolean debugMode;
|
|
|
@@ -95,6 +101,105 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
return sysMessageDao;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ * @param page IPage<SysMessageWrapper.SysMessageList>
|
|
|
+ * @param query SysMessageWrapper.SysMessageQuery
|
|
|
+ * @return IPage<SysMessageWrapper.SysMessage>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageInfo<SysMessageWrapper.Message> queryPage(SysMessageQueryInfo query){
|
|
|
+
|
|
|
+ CbsMessageWrapper.SysMessageQuery cbsQuery = getSysMessageQuery(query);
|
|
|
+
|
|
|
+ PageInfo<SysMessageWrapper.Message> pageInfo = new PageInfo<>(query.getPage(), query.getRows());
|
|
|
+
|
|
|
+ cbsQuery.setPage(query.getPage());
|
|
|
+ cbsQuery.setRows(query.getRows());
|
|
|
+ com.microsvc.toolkit.common.response.paging.PageInfo<CbsMessageWrapper.SysMessage> sysMessagePageInfo = messageFeignClientService
|
|
|
+ .sysMessagePage(cbsQuery).feignData();
|
|
|
+ List<CbsMessageWrapper.SysMessage> rows = sysMessagePageInfo.getRows();
|
|
|
+ if (CollectionUtils.isEmpty(rows)) {
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+ List<SysMessage> sysMessages = rows.stream().map(this::convert).collect(Collectors.toList());
|
|
|
+ pageInfo.setRows(JSON.parseArray(JSON.toJSONString(sysMessages), SysMessageWrapper.Message.class));
|
|
|
+ pageInfo.setTotal(sysMessagePageInfo.getTotal());
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysMessage convert(CbsMessageWrapper.SysMessage sysMessage) {
|
|
|
+ SysMessage message = new SysMessage();
|
|
|
+ message.setId(sysMessage.getId().toString());
|
|
|
+ if (sysMessage.getUserId() != null) {
|
|
|
+ message.setUserId(sysMessage.getUserId().intValue());
|
|
|
+ }
|
|
|
+ if (sysMessage.getMessageConfigId() != null) {
|
|
|
+ message.setMessageConfigId(sysMessage.getMessageConfigId().intValue());
|
|
|
+ }
|
|
|
+ message.setTitle(sysMessage.getTitle());
|
|
|
+ message.setContent(sysMessage.getContent());
|
|
|
+ message.setType(MessageSendMode.valueOf(sysMessage.getSendMode() !=null?sysMessage.getSendMode().name():"PUSH"));
|
|
|
+ message.setStatus(SendStatusEnum.valueOf(Optional.ofNullable(sysMessage.getStatus()).map(o->o.name()).orElse(SendStatusEnum.FAILED.name())));
|
|
|
+ message.setReceiver(sysMessage.getReceiver());
|
|
|
+ message.setSendTime(sysMessage.getSendTime());
|
|
|
+ message.setErrorMsg(sysMessage.getErrorMsg());
|
|
|
+ message.setMemo(sysMessage.getMemo());
|
|
|
+ message.setReadStatus(sysMessage.getReadStatus()?1:0);
|
|
|
+ message.setGroup(sysMessage.getGroup());
|
|
|
+ message.setCreateOn(sysMessage.getCreateTime());
|
|
|
+ message.setModifyOn(sysMessage.getUpdateTime());
|
|
|
+ message.setJpushType(sysMessage.getSendMode().name());
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ private CbsMessageWrapper.SysMessageQuery getSysMessageQuery(SysMessageQueryInfo query) {
|
|
|
+ CbsMessageWrapper.SysMessageQuery cbsQuery = new CbsMessageWrapper.SysMessageQuery();
|
|
|
+ if (query.getUserId() != null) {
|
|
|
+ cbsQuery.setUserId(query.getUserId().longValue());
|
|
|
+ }
|
|
|
+ cbsQuery.setAppKey(EAppKey.GYM);
|
|
|
+ if (query.getJpushType() !=null) {
|
|
|
+ cbsQuery.setClientType(getClientType(query.getJpushType()));
|
|
|
+ }
|
|
|
+ if (query.getStatus() !=null) {
|
|
|
+ switch (query.getStatus()) {
|
|
|
+ case 0:
|
|
|
+ cbsQuery.setStatus(ESendStatus.WAIT);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ cbsQuery.setStatus(ESendStatus.SENDING);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ cbsQuery.setStatus(ESendStatus.SUCCESSED);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cbsQuery.setTitle(query.getTitle());
|
|
|
+ if (query.getType() != null) {
|
|
|
+ switch (query.getType()) {
|
|
|
+ case 1:
|
|
|
+ cbsQuery.setSendMode(EMessageSendMode.SMS);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ cbsQuery.setSendMode(EMessageSendMode.EMAIL);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ cbsQuery.setSendMode(EMessageSendMode.PUSH);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(query.getGroup())) {
|
|
|
+ cbsQuery.setGroup(query.getGroup());
|
|
|
+ }
|
|
|
+ if (query.getReadStatus() != null) {
|
|
|
+ cbsQuery.setReadStatus(query.getReadStatus() == 1);
|
|
|
+ }
|
|
|
+ return cbsQuery;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public R<com.microsvc.toolkit.common.response.paging.PageInfo<CbsMessageWrapper.SysMessage>> queryListPage(SysMessageQueryInfo queryInfo) {
|
|
|
CbsMessageWrapper.SysMessageQuery query = new CbsMessageWrapper.SysMessageQuery();
|
|
|
@@ -103,6 +208,7 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
query.setUserId(queryInfo.getUserId().longValue());
|
|
|
// query.setStatus(ESendStatus.SUCCESSED);
|
|
|
query.setAppKey(EAppKey.GYM);
|
|
|
+ query.setGroup(queryInfo.getGroup());
|
|
|
query.setSendMode(getMessageSendMode(queryInfo.getType()));
|
|
|
query.setTitle(queryInfo.getTitle());
|
|
|
query.setClientType(getClientType(queryInfo.getJpushType()));
|
|
|
@@ -160,6 +266,7 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
params.put(user.getUserId().longValue(), user.getPhone());
|
|
|
messageParam.setReceivers(params);
|
|
|
messageParam.setRealSend(!debugMode);
|
|
|
+ messageParam.setUrl(memo);
|
|
|
if(args != null && args.length > 0){
|
|
|
String[] argsStr = new String[args.length];
|
|
|
for (int i = 0; i < args.length; i++) {
|
|
|
@@ -446,18 +553,27 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
if(StringUtils.isEmpty(jpushType)){
|
|
|
jpushType = "STUDENT";
|
|
|
}
|
|
|
- List<SimpleUserDto> userDtoList = teacherDao.getUsersSimpleInfo(new ArrayList<>(receivers.keySet()));
|
|
|
+ // 处理注册验证码,没有用户ID的情况导致没有发送短息
|
|
|
List<CbsMessageWrapper.MessageParam> messageParams = new ArrayList<>();
|
|
|
- for (SimpleUserDto user : userDtoList) {
|
|
|
+ List<SimpleUserDto> userDtoList = teacherDao.getUsersSimpleInfo(new ArrayList<>(receivers.keySet()));
|
|
|
+ Map<Integer, SimpleUserDto> userMap = userDtoList.stream().collect(Collectors.toMap(SimpleUserDto::getUserId, Function.identity()));
|
|
|
+ for (Map.Entry<Integer, String> receive : receivers.entrySet()) {
|
|
|
+ Long userId = Long.valueOf(Optional.ofNullable(receive.getKey()).orElse(-1));
|
|
|
+ SimpleUserDto user = userMap.getOrDefault(userId.intValue(), new SimpleUserDto());
|
|
|
CbsMessageWrapper.MessageParam messageParam = new CbsMessageWrapper.MessageParam();
|
|
|
- messageParam.setUserId(user.getUserId().longValue());
|
|
|
+ messageParam.setUserId(userId);
|
|
|
messageParam.setAppKey(EAppKey.GYM);
|
|
|
messageParam.setClientType(getClientType(jpushType));
|
|
|
- messageParam.setClientId(messageParam.getClientType());
|
|
|
+ messageParam.setClientId(getClientType(jpushType));
|
|
|
messageParam.setType(type.getCode());
|
|
|
messageParam.setUrl(url);
|
|
|
Map<Long, String> params = new HashMap<>();
|
|
|
- params.put(user.getUserId().longValue(), user.getPhone());
|
|
|
+ if(messageSender == MessageSender.EMAIL){
|
|
|
+ //如果是极光推送,没有用户ID的情况下,使用手机号
|
|
|
+ params.put(userId, Optional.ofNullable(receive.getValue()).orElse(user.getPhone()));
|
|
|
+ }else {
|
|
|
+ params.put(userId, Optional.ofNullable(user.getPhone()).orElse(receive.getValue()));
|
|
|
+ }
|
|
|
messageParam.setReceivers(params);
|
|
|
messageParam.setRealSend(!debugMode);
|
|
|
if(args != null && args.length > 0){
|
|
|
@@ -524,7 +640,7 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
CbsMessageWrapper.MessageParam messageParam = new CbsMessageWrapper.MessageParam();
|
|
|
messageParam.setUserId(user.getUserId().longValue());
|
|
|
messageParam.setAppKey(EAppKey.GYM);
|
|
|
- messageParam.setClientType(EClientType.STUDENT);
|
|
|
+ messageParam.setClientType(EClientType.valueOf(jpushType));
|
|
|
messageParam.setClientId(messageParam.getClientType());
|
|
|
messageParam.setType(type.getCode());
|
|
|
messageParam.setUrl(url);
|
|
|
@@ -579,13 +695,6 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
return object == null ? null : object.toString();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void delSendedVerificationCode(MessageTypeEnum type, String mobileNOOrEmailAddr) {
|
|
|
- String key = getVerificationCodeCacheKey(type, mobileNOOrEmailAddr);
|
|
|
- if (StringUtils.isNotBlank(key)) {
|
|
|
- redisCache.delete(key);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Integer> queryCountOfUnread(MessageSendMode type, Integer userId, String jpushType, Integer tenantId) {
|