|
|
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;
|
...
|
...
|
@@ -22,9 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -61,6 +61,26 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
|
|
|
public static final short SMS_STATUS_FAIL = 0;
|
|
|
|
|
|
public final static Map paramMap = new HashMap() {{
|
|
|
put("channelSource", "泛渠道来源");
|
|
|
put("channelOrderCode", "泛渠道订单号");
|
|
|
put("uid", "有货uid");
|
|
|
put("hasUid", "是否有货会员");
|
|
|
put("hasYHOrder", "是否存在有货订单");
|
|
|
put("yhOrderCode", "有货订单号");
|
|
|
put("unionCode", "渠道号");
|
|
|
put("userChannel", "渠道注册终端");
|
|
|
put("beginChannelOrderTime", "泛渠道订单时间");
|
|
|
put("endChannelOrderTime", "泛渠道订单时间");
|
|
|
put("beginYHOrderTime", "有货订单时间");
|
|
|
put("endYHOrderTime", "有货订单时间");
|
|
|
put("beginRegisterTime", "注册时间");
|
|
|
put("endRegisterTime", "注册时间");
|
|
|
put("beginSmsTime", "短信发送时间");
|
|
|
put("endSmsTime", "短信发送时间");
|
|
|
|
|
|
}};
|
|
|
|
|
|
@Override
|
|
|
public PageChannelGroupRspBO queryChannelGroupList(ChannelGroupRequestBO channelGroupRequestBO) {
|
|
|
logger.info("enter queryChannelGroupList. param channelGroupRequestBO={}", channelGroupRequestBO);
|
...
|
...
|
@@ -95,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());
|
|
|
}
|
|
|
}
|
|
|
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 total = channelUserDAO.selectCount(params);
|
|
|
|
|
|
//3.记录分组批次表
|
|
|
//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;
|
...
|
...
|
@@ -127,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) {
|
...
|
...
|
@@ -141,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);
|
...
|
...
|
@@ -157,6 +188,64 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
channelGroupDAO.updateByPrimaryKeySelective(channelGroup);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<Integer,String> getCondition(String ids) {
|
|
|
logger.info("enter getCondition. param ids={}", ids);
|
|
|
List groupIds = Arrays.asList(ids.split(","));
|
|
|
List<ChannelGroupCondition> channelGroupConditions = channelGroupConditionDAO.selectByGroupIds(groupIds);
|
|
|
Map<Integer,Map<String,String>> conditionMap = Maps.newHashMap();
|
|
|
if(!CollectionUtils.isEmpty(channelGroupConditions)){
|
|
|
for(int i=0;i<channelGroupConditions.size();i++){
|
|
|
ChannelGroupCondition channelGroupCondition = channelGroupConditions.get(i);
|
|
|
if(conditionMap.get(channelGroupCondition.getGroupId())!=null){
|
|
|
Map<String,String> condition = conditionMap.get(channelGroupCondition.getGroupId());
|
|
|
condition.put(channelGroupCondition.getKey(),channelGroupCondition.getValue());
|
|
|
conditionMap.put(channelGroupCondition.getGroupId(),condition);
|
|
|
}else{
|
|
|
Map<String,String> condition = Maps.newHashMap();
|
|
|
condition.put(channelGroupCondition.getKey(),channelGroupCondition.getValue());
|
|
|
conditionMap.put(channelGroupCondition.getGroupId(),condition);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Map<Integer,String> result = Maps.newHashMap();
|
|
|
for (Map.Entry<Integer,Map<String,String>> entry : conditionMap .entrySet()) {
|
|
|
Map<String,String> map = entry.getValue();
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
convertTime(map,"beginChannelOrderTime","endChannelOrderTime",sb);
|
|
|
convertTime(map,"beginYHOrderTime","endYHOrderTime",sb);
|
|
|
convertTime(map,"beginRegisterTime","endRegisterTime",sb);
|
|
|
convertTime(map,"beginSmsTime","endSmsTime",sb);
|
|
|
|
|
|
for(Map.Entry<String,String> entry1:map.entrySet()){
|
|
|
String key = entry1.getKey();
|
|
|
sb.append("<div>").append(paramMap.get(key)).append(":").append(entry1.getValue()).append("</div>");
|
|
|
}
|
|
|
result.put(entry.getKey(),sb.toString());
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private void convertTime(Map<String, String> map, String beginTimeKey, String endTimeKey, StringBuffer sb) {
|
|
|
if(map.get(beginTimeKey)!=null || map.get(endTimeKey)!=null){
|
|
|
String beginTime = map.get(beginTimeKey);
|
|
|
String endTime = map.get(endTimeKey);
|
|
|
if(beginTime!=null){
|
|
|
beginTime = DateUtils.int2DateStr(Integer.parseInt(beginTime),"yyyy-MM-dd HH:mm:ss");
|
|
|
}else{
|
|
|
beginTime = "未设置";
|
|
|
}
|
|
|
if(endTime!=null){
|
|
|
endTime = DateUtils.int2DateStr(Integer.parseInt(endTime),"yyyy-MM-dd HH:mm:ss");
|
|
|
}else{
|
|
|
endTime = "未设置";
|
|
|
}
|
|
|
sb.append("<div>").append(paramMap.get("beginChannelOrderTime")).append(":").append( beginTime).append("-").append(endTime).append("</div>");
|
|
|
map.remove(beginTimeKey);
|
|
|
map.remove(endTimeKey);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<ChannelGroupRspBO> toRspBOList(List<ChannelGroup> channelGroupList) {
|
|
|
logger.info("enter toRspBOList. param channelGroupList={}", channelGroupList);
|
|
|
List<ChannelGroupRspBO> list = Lists.newArrayList();
|
...
|
...
|
@@ -164,7 +253,6 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
for (int i = 0; i < channelGroupList.size(); i++) {
|
|
|
ChannelGroup channelGroup = channelGroupList.get(i);
|
|
|
ChannelGroupRspBO channelGroupRspBO = new ChannelGroupRspBO();
|
...
|
...
|
|