...
|
...
|
@@ -3,6 +3,7 @@ package com.yoho.unions.channel.service.impl; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.common.collect.Sets;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.message.sdk.common.model.SendMessageRspBo;
|
...
|
...
|
@@ -23,10 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -117,26 +115,36 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
//1.根据groupId查询条件
|
|
|
List<ChannelGroupCondition> conditions = channelGroupConditionDAO.selectByGroupId(groupId);
|
|
|
logger.info("sendMessage:conditions is {}",conditions);
|
|
|
Map<String, Object> params = Maps.newHashMap();
|
|
|
if (!CollectionUtils.isEmpty(conditions)) {
|
|
|
for (ChannelGroupCondition channelGroupCondition : conditions) {
|
|
|
params.put(channelGroupCondition.getKey(), channelGroupCondition.getValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//2.根据条件分批查询手机号发送短信
|
|
|
int total = channelUserDAO.selectCount(params);
|
|
|
|
|
|
//3.记录分组批次表
|
|
|
Map<String, Object> params = conditions.stream().collect(Collectors.toMap(ChannelGroupCondition::getKey,ChannelGroupCondition::getValue));
|
|
|
// Map<String, Object> params = Maps.newHashMap();
|
|
|
// if (!CollectionUtils.isEmpty(conditions)) {
|
|
|
// for (ChannelGroupCondition channelGroupCondition : conditions) {
|
|
|
// params.put(channelGroupCondition.getKey(), channelGroupCondition.getValue());
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
//2.记录分组批次表
|
|
|
int sendTime = DateUtils.getCurrentTimeSecond();
|
|
|
ChannelGroupBatch channelGroupBatch = new ChannelGroupBatch(groupId, content, sendTime, sendUserId);
|
|
|
channelGroupBatchDAO.insertSelective(channelGroupBatch);
|
|
|
logger.info("sendMessage:insert channelGroupBatch,channelGroupBatch ={}",channelGroupBatch);
|
|
|
int groupBatchId = channelGroupBatch.getId();
|
|
|
|
|
|
//3.根据条件分批查询手机号
|
|
|
int total = channelUserDAO.selectCount(params);
|
|
|
Set<String> mobileSet = Sets.newHashSet();
|
|
|
//分批从数据库中查询,每次1000,使用mobileSet去重
|
|
|
for (int i = 0; i < total; i += BATCH_MESSAGE_NUMBER) {
|
|
|
List<ChannelUser> channelUsers = channelUserDAO.selectPage(params, i, i + BATCH_MESSAGE_NUMBER);
|
|
|
List<String> mobiles = channelUsers.stream().map(ChannelUser::getMobile).collect(Collectors.toList());
|
|
|
Set<String> channelMobiles= channelUsers.stream().map(ChannelUser::getMobile).collect(Collectors.toSet());
|
|
|
mobileSet.addAll(channelMobiles);
|
|
|
}
|
|
|
|
|
|
List<String> mobileList = Lists.newArrayList(mobileSet);
|
|
|
List<ChannelSmsDetail> smsDetails = Lists.newArrayList();
|
|
|
//4.用户去重、黑名单后,分批发送短信
|
|
|
for (int i = 0; i < mobileList.size(); i += BATCH_MESSAGE_NUMBER) {
|
|
|
List<String> mobiles = mobileList.subList(i, i + BATCH_MESSAGE_NUMBER);
|
|
|
String mobile = StringUtils.join(mobiles.toArray(), ",");
|
|
|
//调用SDK发送短信接口
|
|
|
SendMessageRspBo sendMessageRspBo = null;
|
...
|
...
|
@@ -149,7 +157,6 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
}
|
|
|
|
|
|
|
|
|
List<ChannelSmsDetail> smsDetails = Lists.newArrayList();
|
|
|
//4.1短信发送成功,记录短信日志表(状态为1)
|
|
|
if (sendMessageRspBo!=null&&sendMessageRspBo.getCode() == 200 && sendMessageRspBo.getMessage().equals("SUCCESS")) {
|
|
|
for (String sms : mobiles) {
|
...
|
...
|
@@ -163,9 +170,11 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
smsDetails.add(channelSmsDetail);
|
|
|
}
|
|
|
}
|
|
|
channelSmsDetailDAO.batchInsert(smsDetails);
|
|
|
logger.info("sendMessage:insert channelSmsDetai,smsDetails is {}",smsDetails);
|
|
|
}
|
|
|
|
|
|
channelSmsDetailDAO.batchInsert(smsDetails);
|
|
|
logger.info("sendMessage:insert channelSmsDetai,smsDetails is {}",smsDetails);
|
|
|
|
|
|
//5.修改分组表的分组人数、发送时间、修改时间、内容、发送人
|
|
|
ChannelGroup channelGroup = new ChannelGroup();
|
|
|
channelGroup.setId(groupId);
|
...
|
...
|
@@ -224,12 +233,12 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
if(beginTime!=null){
|
|
|
beginTime = DateUtils.int2DateStr(Integer.parseInt(beginTime),"yyyy-MM-dd HH:mm:ss");
|
|
|
}else{
|
|
|
beginTime = "";
|
|
|
beginTime = "未设置";
|
|
|
}
|
|
|
if(endTime!=null){
|
|
|
endTime = DateUtils.int2DateStr(Integer.parseInt(endTime),"yyyy-MM-dd HH:mm:ss");
|
|
|
}else{
|
|
|
endTime = "";
|
|
|
endTime = "未设置";
|
|
|
}
|
|
|
sb.append("<div>").append(paramMap.get("beginChannelOrderTime")).append(":").append( beginTime).append("-").append(endTime).append("</div>");
|
|
|
map.remove(beginTimeKey);
|
...
|
...
|
|