|
@@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.SysMessageDao;
|
|
|
+import com.ym.mec.biz.dal.dao.WaitSendMessageDao;
|
|
|
import com.ym.mec.biz.dal.dto.Mapper;
|
|
|
import com.ym.mec.biz.dal.entity.SysMessage;
|
|
|
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;
|
|
@@ -23,6 +25,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.im.ImFeignService;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext.MessageSender;
|
|
|
+import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.string.MessageFormatter;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -31,10 +34,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
+import static com.ym.mec.biz.dal.enums.MessageTypeEnum.STUDENT_PUSH_VIP_BUY;
|
|
|
+
|
|
|
@Service
|
|
|
public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> implements SysMessageService {
|
|
|
|
|
@@ -53,6 +59,9 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private WaitSendMessageDao waitSendMessageDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private ImFeignService imFeignService;
|
|
|
|
|
|
@Autowired
|
|
@@ -239,57 +248,51 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Async
|
|
|
- public boolean batchSendMessage(MessageSender messageSender, String subject, String content, Map<Integer, String> receivers, Date triggerTime,
|
|
|
- Integer readStatus, String memo, String group,String jpushType) {
|
|
|
-
|
|
|
- if (receivers == null || receivers.size() == 0) {
|
|
|
- throw new BizException("消息接收人不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(content)) {
|
|
|
- throw new BizException("消息内容不能为空");
|
|
|
- }
|
|
|
- String[] tos = receivers.values().toArray(new String[receivers.size()]);
|
|
|
- if (tos != null && tos.length > 0) {
|
|
|
- Date date = new Date();
|
|
|
- SendStatusEnum status = SendStatusEnum.WAIT;
|
|
|
-
|
|
|
- String errorMsg = null;
|
|
|
- try {
|
|
|
- // 立即发送
|
|
|
- if (triggerTime == null || date.after(triggerTime)) {
|
|
|
- status = SendStatusEnum.SENDING;
|
|
|
- if (debugMode == true || messageSenderPluginContext.batchSend(messageSender, subject, content, tos, memo,jpushType)) {
|
|
|
- status = SendStatusEnum.SUCCESSED;
|
|
|
- } else {
|
|
|
- status = SendStatusEnum.FAILED;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- status = SendStatusEnum.FAILED;
|
|
|
- errorMsg = e.getMessage();
|
|
|
- LOGGER.warn("消息发送失败", e);
|
|
|
- }
|
|
|
- MessageSendMode mode = MessageSendMode.SMS;
|
|
|
- if (messageSender.getSendMode().equals("PUSH")) {
|
|
|
- mode = MessageSendMode.PUSH;
|
|
|
- } else if (messageSender.getSendMode().equals("EMAIL")) {
|
|
|
- mode = MessageSendMode.EMAIL;
|
|
|
+ public void pushWaitSendMessageTask() {
|
|
|
+ List<WaitSendMessage> all = waitSendMessageDao.findAll(null);
|
|
|
+ for (WaitSendMessage waitSendMessage : all) {
|
|
|
+ Map<Integer,String> map = (Map<Integer,String>) JSON.parseObject(waitSendMessage.getReceivers(), Map.class);
|
|
|
+ String[] args = null;
|
|
|
+ if(waitSendMessage.getAgrs() != null){
|
|
|
+ List<String> strings = JSON.parseArray(waitSendMessage.getAgrs(), String.class);
|
|
|
+ String[] str = new String[strings.size()];
|
|
|
+ args = strings.toArray(str);
|
|
|
}
|
|
|
- return addMessage(receivers, subject, content, triggerTime, mode, status, errorMsg, readStatus, memo, null) > 0;
|
|
|
+ batchSendMessage(MessageSender.valueOf(waitSendMessage.getMessageSender()),
|
|
|
+ MessageTypeEnum.valueOf(waitSendMessage.getMessageType()),map,null,0,
|
|
|
+ waitSendMessage.getUrl(),waitSendMessage.getJpushType(),args);
|
|
|
+ waitSendMessageDao.delete(waitSendMessage.getId());
|
|
|
}
|
|
|
-
|
|
|
- return false;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Async
|
|
|
public void batchSendMessage(MessageSender messageSender, MessageTypeEnum type, Map<Integer, String> receivers, Date triggerTime, Integer readStatus,
|
|
|
String url,String jpushType, Object... args) {
|
|
|
-
|
|
|
if (receivers == null || receivers.size() == 0) {
|
|
|
throw new BizException("接收地址不能为空");
|
|
|
}
|
|
|
+ if(StringUtils.isNotEmpty(jpushType) && jpushType == "STUDENT"){
|
|
|
+ //如果不是缴费信息
|
|
|
+ if(type != STUDENT_PUSH_VIP_BUY){
|
|
|
+ int hour = DateUtil.getHour(new Date());
|
|
|
+ //如果当前时间在22点之后
|
|
|
+ if(hour > 21){
|
|
|
+ //保存推送信息
|
|
|
+ WaitSendMessage waitSendMessage = new WaitSendMessage();
|
|
|
+ if(args != null){
|
|
|
+ waitSendMessage.setAgrs(JSON.toJSONString(args));
|
|
|
+ }
|
|
|
+ waitSendMessage.setJpushType(jpushType);
|
|
|
+ waitSendMessage.setMessageSender(messageSender.name());
|
|
|
+ waitSendMessage.setMessageType(type.name());
|
|
|
+ waitSendMessage.setReceivers(JSON.toJSONString(receivers));
|
|
|
+ waitSendMessage.setUrl(url);
|
|
|
+ waitSendMessageDao.insert(waitSendMessage);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
String[] tos = receivers.values().toArray(new String[receivers.size()]);
|
|
|
SysMessageConfig messageConfig = sysMessageConfigService.queryByType(type);
|
|
|
if (messageConfig == null) {
|