...
|
...
|
@@ -73,6 +73,8 @@ public class ChannelGroupServiceImpl implements IChannelGroupService { |
|
|
|
|
|
public static final int BATCH_MESSAGE_NUMBER = 500;
|
|
|
|
|
|
public static final int INSERT_MESSAGE_NUMBER = 500;
|
|
|
|
|
|
public static final short SMS_STATUS_SUCCESS = 1; //短信发送成功状态
|
|
|
|
|
|
public static final short SMS_STATUS_FAIL = 0;
|
...
|
...
|
@@ -159,125 +161,6 @@ public class ChannelGroupServiceImpl implements IChannelGroupService { |
|
|
return pageChannelGroupRspBO;
|
|
|
}
|
|
|
|
|
|
// @Override
|
|
|
// public int sendMessage(ChannelMessageRequestBO channelGroupRequestBO, int sendUserId) {
|
|
|
// logger.info("enter sendMessage. param channelGroupRequestBO{}", channelGroupRequestBO);
|
|
|
// int groupId = channelGroupRequestBO.getGroupId();
|
|
|
// String content = channelGroupRequestBO.getContent();
|
|
|
//
|
|
|
// //1.根据groupId查询条件
|
|
|
// List<ChannelGroupCondition> conditions = channelGroupConditionDAO.selectByGroupId(groupId);
|
|
|
// logger.info("sendMessage:conditions is {}", conditions);
|
|
|
// Map<String, Object> params = conditions.stream().collect(Collectors.toMap(ChannelGroupCondition::getKey, ChannelGroupCondition::getValue));
|
|
|
//
|
|
|
// //2.根据条件分批查询手机号
|
|
|
// int total = channelUserDAO.selectCount(params);
|
|
|
// if (total == 0) {
|
|
|
// logger.info("not find users to send message,param channelGroupRequestBO{}", channelGroupRequestBO);
|
|
|
// return 0;
|
|
|
// }
|
|
|
// Set<String> mobileSet = Sets.newHashSet();
|
|
|
// //2.1分批从数据库中查询,每次1000,使用mobileSet去重
|
|
|
// for (int i = 0; i < total; i += BATCH_MESSAGE_NUMBER) {
|
|
|
// List<ChannelUser> channelUsers = channelUserDAO.selectPage(params, i, i + BATCH_MESSAGE_NUMBER);
|
|
|
// Set<String> channelMobiles = channelUsers.stream().map(ChannelUser::getMobile).collect(Collectors.toSet());
|
|
|
// mobileSet.addAll(channelMobiles);
|
|
|
// }
|
|
|
//
|
|
|
// //2.2查询出来的手机号剔除黑名单数据
|
|
|
// List<String> blackList = channelSmsBlackDAO.selectAll();
|
|
|
// mobileSet.removeAll(blackList);
|
|
|
//
|
|
|
// //2.3添加默认运营的号码
|
|
|
// List<String> businessMobileList = Arrays.asList(businessMobile.split(","));
|
|
|
// mobileSet.addAll(businessMobileList);
|
|
|
//
|
|
|
// //剔除黑名单后,发送手机号为空,返回
|
|
|
//// if (CollectionUtils.isEmpty(mobileSet)) {
|
|
|
//// logger.info("not find users to send message,param channelGroupRequestBO{}", channelGroupRequestBO);
|
|
|
//// return 0;
|
|
|
//// }
|
|
|
//
|
|
|
// //3.记录分组批次表
|
|
|
// int sendTime = DateUtils.getCurrentTimeSecond();
|
|
|
//
|
|
|
// UserInfoBO userInfoBO = null;
|
|
|
//
|
|
|
// try {
|
|
|
// userInfoBO = erpApiServiceHelper.getUserByPid(String.valueOf(sendUserId));
|
|
|
// } catch (Exception e) {
|
|
|
// logger.warn("call erpApiServiceHelper.getUserByPid occurs Exception,e is {}", e.getMessage());
|
|
|
// }
|
|
|
//
|
|
|
// String sendUserName = userInfoBO != null ? userInfoBO.getAccount() : "";
|
|
|
// ChannelGroupBatch channelGroupBatch = new ChannelGroupBatch(groupId, content, sendTime, sendUserId, sendUserName);
|
|
|
// channelGroupBatchDAO.insertSelective(channelGroupBatch);
|
|
|
// logger.info("sendMessage:insert channelGroupBatch,channelGroupBatch ={}", channelGroupBatch);
|
|
|
// int groupBatchId = channelGroupBatch.getId();
|
|
|
//
|
|
|
// List<String> mobileList = Lists.newArrayList(mobileSet);
|
|
|
// List<ChannelSmsDetail> smsDetails = Lists.newArrayList();
|
|
|
// //4.用户去重、黑名单后,分批发送短信
|
|
|
// List<String> mobiles = null;
|
|
|
// int successCount = 0;
|
|
|
// for (int i = 0; i < mobileList.size(); i += BATCH_MESSAGE_NUMBER) {
|
|
|
// if (i + BATCH_MESSAGE_NUMBER > mobileList.size()) {
|
|
|
// mobiles = mobileList.subList(i, mobileList.size());
|
|
|
// } else {
|
|
|
// mobiles = mobileList.subList(i, i + BATCH_MESSAGE_NUMBER);
|
|
|
// }
|
|
|
// String mobile = StringUtils.join(mobiles.toArray(), ",");
|
|
|
// //调用SDK发送短信接口
|
|
|
// SendMessageRspBo sendMessageRspBo = null;
|
|
|
//
|
|
|
// try {
|
|
|
// sendMessageRspBo = sendCrmMessage.generalSceneMsg(mobile, content);
|
|
|
// logger.info("sendMessage:call generalSceneMsg,sendMessageRspBo is {}", sendMessageRspBo);
|
|
|
// } catch (Exception e) {
|
|
|
// logger.warn("sendMessage:call generalSceneMsg occurs Exception,e is {}", e.getMessage());
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// //4.1短信发送成功,记录短信日志表(状态为1)
|
|
|
// if (sendMessageRspBo != null && sendMessageRspBo.getCode() == 200 && sendMessageRspBo.getMessage().equals("SUCCESS")) {
|
|
|
// for (String sms : mobiles) {
|
|
|
// ChannelSmsDetail channelSmsDetail = new ChannelSmsDetail(sms, groupBatchId, SMS_STATUS_SUCCESS, sendTime);
|
|
|
// smsDetails.add(channelSmsDetail);
|
|
|
// successCount++;
|
|
|
// }
|
|
|
// } else {
|
|
|
// //4.2短信发送失败,打印日志,记录短信日志表(状态为0)和分组批次表
|
|
|
// for (String sms : mobiles) {
|
|
|
// ChannelSmsDetail channelSmsDetail = new ChannelSmsDetail(sms, groupBatchId, SMS_STATUS_FAIL, sendTime);
|
|
|
// smsDetails.add(channelSmsDetail);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// //异步记录日志表,以后查询日志方便
|
|
|
// try {
|
|
|
// saveSmsDetail(smsDetails);
|
|
|
// } catch (Exception e) {
|
|
|
// logger.error("", e);
|
|
|
// }
|
|
|
// logger.info("sendMessage:insert channelSmsDetai,smsDetails is {}", smsDetails);
|
|
|
//
|
|
|
// //5.修改分组表的分组人数、发送时间、修改时间、内容、发送人
|
|
|
// ChannelGroup channelGroup = new ChannelGroup();
|
|
|
// channelGroup.setId(groupId);
|
|
|
// channelGroup.setUpdateTime(sendTime);
|
|
|
// channelGroup.setGroupNumber(mobileSet.size());
|
|
|
// channelGroup.setSuccessCount(successCount);
|
|
|
// channelGroup.setSendTime(sendTime);
|
|
|
// channelGroup.setContent(content);
|
|
|
// channelGroup.setSendUserName(sendUserName);
|
|
|
// channelGroup.setSendUser(sendUserId);
|
|
|
// channelGroup.setSmsNumber(groupBatchId);
|
|
|
// channelGroup.setStatus(1);
|
|
|
// int count = channelGroupDAO.updateByPrimaryKeySelective(channelGroup);
|
|
|
// logger.info("sendMessage:update channelGroup,channelGroup is {}", channelGroup);
|
|
|
// return count;
|
|
|
// }
|
|
|
|
|
|
@Override
|
|
|
public int sendMessage(ChannelMessageRequestBO channelGroupRequestBO, int sendUserId) {
|
...
|
...
|
@@ -300,6 +183,7 @@ public class ChannelGroupServiceImpl implements IChannelGroupService { |
|
|
channelGroup.setContent(content);
|
|
|
channelGroup.setSendUserName(sendUserName);
|
|
|
channelGroup.setSendUser(sendUserId);
|
|
|
channelGroup.setSendTime(DateUtils.getCurrentTimeSecond());
|
|
|
channelGroup.setStatus(2); //状态2:发送中
|
|
|
int count = channelGroupDAO.updateByPrimaryKeySelective(channelGroup);
|
|
|
logger.info("sendMessage:sending message,channelGroup is {}", channelGroup);
|
...
|
...
|
@@ -334,7 +218,7 @@ public class ChannelGroupServiceImpl implements IChannelGroupService { |
|
|
}
|
|
|
Set<String> mobileSet = Sets.newHashSet();
|
|
|
//2.1分批从数据库中查询,每次500,使用mobileSet去重
|
|
|
|
|
|
int queryCount = 0; //查询失败手机号
|
|
|
for (int i = 0; i < total; i += BATCH_MESSAGE_NUMBER) {
|
|
|
try{
|
|
|
List<ChannelUser> channelUsers = channelUserDAO.selectPage(params, i, i + BATCH_MESSAGE_NUMBER);
|
...
|
...
|
@@ -342,12 +226,26 @@ public class ChannelGroupServiceImpl implements IChannelGroupService { |
|
|
mobileSet.addAll(channelMobiles);
|
|
|
}catch (Exception e){
|
|
|
//查询超时等异常
|
|
|
if(total-i>BATCH_MESSAGE_NUMBER){
|
|
|
queryCount +=BATCH_MESSAGE_NUMBER;
|
|
|
}else{
|
|
|
//最后一次查询出现异常,失败数不是批量值
|
|
|
queryCount = queryCount+total-i;
|
|
|
}
|
|
|
logger.warn("sendMessage:query users fail.");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//2.2查询出来的手机号剔除黑名单数据
|
|
|
List<String> blackList = channelSmsBlackDAO.selectAll();
|
|
|
//2.2查询出来的手机号剔除黑名单数据,也分批查询黑名单
|
|
|
Integer blackTotal = channelSmsBlackDAO.selectCount();
|
|
|
List<String> blackList = Lists.newArrayList();
|
|
|
if(blackTotal!=null){
|
|
|
for (int i = 0; i < blackTotal; i += BATCH_MESSAGE_NUMBER) {
|
|
|
List<String> temp = channelSmsBlackDAO.selectAll(i,i+BATCH_MESSAGE_NUMBER);
|
|
|
blackList.addAll(temp);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
mobileSet.removeAll(blackList);
|
|
|
|
|
|
//2.3添加默认运营的号码
|
...
|
...
|
@@ -366,8 +264,9 @@ public class ChannelGroupServiceImpl implements IChannelGroupService { |
|
|
|
|
|
//4.用户去重、黑名单后,分批发送短信
|
|
|
List<String> mobiles = null;
|
|
|
int successCount = 0;
|
|
|
int failCount = 0;
|
|
|
int successCount = 0; //发送成功短信数
|
|
|
int failCount = 0; //发送失败短信数
|
|
|
|
|
|
for (int i = 0; i < mobileList.size(); i += BATCH_MESSAGE_NUMBER) {
|
|
|
if (i + BATCH_MESSAGE_NUMBER > mobileList.size()) {
|
|
|
mobiles = mobileList.subList(i, mobileList.size());
|
...
|
...
|
@@ -386,7 +285,7 @@ public class ChannelGroupServiceImpl implements IChannelGroupService { |
|
|
}
|
|
|
|
|
|
|
|
|
//4.1短信发送成功,记录短信日志表(状态为1)
|
|
|
// 4.1短信发送成功,记录短信日志表(状态为1)
|
|
|
if (sendMessageRspBo != null && sendMessageRspBo.getCode() == 200 && sendMessageRspBo.getMessage().equals("SUCCESS")) {
|
|
|
for (String sms : mobiles) {
|
|
|
ChannelSmsDetail channelSmsDetail = new ChannelSmsDetail(sms, groupBatchId, SMS_STATUS_SUCCESS, sendTime);
|
...
|
...
|
@@ -403,22 +302,32 @@ public class ChannelGroupServiceImpl implements IChannelGroupService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
//5.记录短信明细表
|
|
|
channelSmsDetailDAO.batchInsert(smsDetails);
|
|
|
logger.info("sendMessage:end insert channelSmsDetai,smsDetails is {}", smsDetails);
|
|
|
|
|
|
//6.发送成功更新发送人、发送时间、状态等
|
|
|
|
|
|
//5.发送成功更新发送人、发送时间、状态等
|
|
|
ChannelGroup channelGroup = new ChannelGroup();
|
|
|
channelGroup.setId(groupId);
|
|
|
channelGroup.setUpdateTime(sendTime);
|
|
|
channelGroup.setGroupNumber(mobileSet.size());
|
|
|
channelGroup.setSuccessCount(successCount);
|
|
|
channelGroup.setSendTime(sendTime);
|
|
|
channelGroup.setSmsNumber(groupBatchId);
|
|
|
channelGroup.setStatus(1);
|
|
|
channelGroup.setFailCount(failCount);
|
|
|
channelGroup.setQueryCount(queryCount);
|
|
|
channelGroupDAO.updateByPrimaryKeySelective(channelGroup);
|
|
|
|
|
|
//6.最后再更新日志表,批量更新一次1000
|
|
|
List<ChannelSmsDetail> temp = null;
|
|
|
for(int i=0;i<smsDetails.size();i++){
|
|
|
if (i + INSERT_MESSAGE_NUMBER > mobileList.size()) {
|
|
|
temp = smsDetails.subList(i, mobileList.size());
|
|
|
} else {
|
|
|
temp = smsDetails.subList(i, i + INSERT_MESSAGE_NUMBER);
|
|
|
}
|
|
|
channelSmsDetailDAO.batchInsert(temp);
|
|
|
}
|
|
|
logger.info("sendMessage:end insert channelSmsDetai,smsDetails is {}", smsDetails);
|
|
|
|
|
|
logger.info("sendMessage:end sendSmsDetail,groupId={},content={},sendUserId={},sendUserName={}", groupId,content,sendUserId,sendUserName);
|
|
|
}
|
|
|
});
|
...
|
...
|
|