...
|
...
|
@@ -13,7 +13,7 @@ import com.yoho.service.model.union.request.ChannelUserRequest; |
|
|
import com.yoho.service.model.union.request.UserInfoBO;
|
|
|
import com.yoho.service.model.union.response.ChannelGroupRspBO;
|
|
|
import com.yoho.service.model.union.response.PageChannelGroupRspBO;
|
|
|
import com.yoho.unions.channel.service.ChannelGroupService;
|
|
|
import com.yoho.unions.channel.service.IChannelGroupService;
|
|
|
import com.yoho.unions.common.utils.DateUtil;
|
|
|
import com.yoho.unions.common.utils.ErpApiServiceHelper;
|
|
|
import com.yoho.unions.dal.*;
|
...
|
...
|
@@ -35,8 +35,8 @@ import java.util.stream.Collectors; |
|
|
* Created by yoho on 2017/2/15.
|
|
|
*/
|
|
|
@Service
|
|
|
public class ChannelGroupServiceImpl implements ChannelGroupService {
|
|
|
static Logger logger = LoggerFactory.getLogger(ChannelGroupService.class);
|
|
|
public class ChannelGroupServiceImpl implements IChannelGroupService {
|
|
|
static Logger logger = LoggerFactory.getLogger(ChannelGroupServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private IChannelGroupDAO channelGroupDAO;
|
...
|
...
|
@@ -88,7 +88,7 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
|
|
|
}};
|
|
|
|
|
|
public final static Map channelSourceMap = new HashedMap(){{
|
|
|
public final static Map channelSourceMap = new HashedMap() {{
|
|
|
put("5", "淘宝B店订单");
|
|
|
put("8", "淘宝C店订单");
|
|
|
put("9", "淘宝LAL店订单");
|
...
|
...
|
@@ -113,6 +113,7 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
}
|
|
|
|
|
|
// (2)查询:总数和列表
|
|
|
channelGroupRequestBO.setStatus(1);
|
|
|
int total = channelGroupDAO.selectListCountByParam(channelGroupRequestBO);
|
|
|
List<ChannelGroupRspBO> channelGroupBOList = channelGroupDAO.selectListByParam(channelGroupRequestBO);
|
|
|
|
...
|
...
|
@@ -126,19 +127,19 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int sendMessage(ChannelMessageRequestBO channelGroupRequestBO,int sendUserId) {
|
|
|
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));
|
|
|
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){
|
|
|
if (total == 0) {
|
|
|
logger.info("not find users to send message,param channelGroupRequestBO{}", channelGroupRequestBO);
|
|
|
return 0;
|
|
|
}
|
...
|
...
|
@@ -146,7 +147,7 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
//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());
|
|
|
Set<String> channelMobiles = channelUsers.stream().map(ChannelUser::getMobile).collect(Collectors.toSet());
|
|
|
mobileSet.addAll(channelMobiles);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -155,7 +156,7 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
mobileSet.removeAll(blackList);
|
|
|
|
|
|
//剔除黑名单后,发送手机号为空,返回
|
|
|
if(CollectionUtils.isEmpty(mobileSet)){
|
|
|
if (CollectionUtils.isEmpty(mobileSet)) {
|
|
|
logger.info("not find users to send message,param channelGroupRequestBO{}", channelGroupRequestBO);
|
|
|
return 0;
|
|
|
}
|
...
|
...
|
@@ -165,43 +166,43 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
|
|
|
UserInfoBO userInfoBO = null;
|
|
|
|
|
|
try{
|
|
|
userInfoBO = erpApiServiceHelper.getUserByPid(String.valueOf(sendUserId));
|
|
|
}catch (Exception e){
|
|
|
logger.warn("call erpApiServiceHelper.getUserByPid occurs Exception,e is {}",e.getMessage());
|
|
|
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);
|
|
|
|
|
|
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);
|
|
|
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 ;
|
|
|
int successCount = 0;
|
|
|
for (int i = 0; i < mobileList.size(); i += BATCH_MESSAGE_NUMBER) {
|
|
|
if(i + BATCH_MESSAGE_NUMBER>mobileList.size()){
|
|
|
if (i + BATCH_MESSAGE_NUMBER > mobileList.size()) {
|
|
|
mobiles = mobileList.subList(i, mobileList.size());
|
|
|
}else{
|
|
|
} else {
|
|
|
mobiles = mobileList.subList(i, i + BATCH_MESSAGE_NUMBER);
|
|
|
}
|
|
|
String mobile = StringUtils.join(mobiles.toArray(), ",");
|
|
|
//调用SDK发送短信接口
|
|
|
SendMessageRspBo sendMessageRspBo = null;
|
|
|
|
|
|
try{
|
|
|
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());
|
|
|
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")) {
|
|
|
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);
|
...
|
...
|
@@ -217,7 +218,7 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
}
|
|
|
|
|
|
channelSmsDetailDAO.batchInsert(smsDetails);
|
|
|
logger.info("sendMessage:insert channelSmsDetai,smsDetails is {}",smsDetails);
|
|
|
logger.info("sendMessage:insert channelSmsDetai,smsDetails is {}", smsDetails);
|
|
|
|
|
|
//5.修改分组表的分组人数、发送时间、修改时间、内容、发送人
|
|
|
ChannelGroup channelGroup = new ChannelGroup();
|
...
|
...
|
@@ -231,83 +232,111 @@ public class ChannelGroupServiceImpl implements ChannelGroupService { |
|
|
// channelGroup.setSmsNumber(groupBatchId);
|
|
|
// channelGroup.setSendUserName(sendUserName);
|
|
|
channelGroupDAO.updateByPrimaryKeySelective(channelGroup);
|
|
|
logger.info("sendMessage:update channelGroup,channelGroup is {}",channelGroup);
|
|
|
logger.info("sendMessage:update channelGroup,channelGroup is {}", channelGroup);
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<Integer,String> getCondition(String ids) {
|
|
|
public Map<Integer, String> getCondition(String ids) {
|
|
|
logger.info("enter getCondition. param ids={}", ids);
|
|
|
List groupIds = Arrays.asList(ids.split(","));
|
|
|
//1.查询出所有分组的条件
|
|
|
List<ChannelGroupCondition> channelGroupConditions = channelGroupConditionDAO.selectByGroupIds(groupIds);
|
|
|
Map<Integer,Map<String,String>> conditionMap = Maps.newHashMap();
|
|
|
Map<Integer, Map<String, String>> conditionMap = Maps.newHashMap();
|
|
|
//2.将查询出的条件按照groupId进行合并
|
|
|
if(!CollectionUtils.isEmpty(channelGroupConditions)){
|
|
|
for(int i=0;i<channelGroupConditions.size();i++){
|
|
|
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);
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
logger.info("getCondition. conditionMap={}", conditionMap);
|
|
|
Map<Integer,String> result = Maps.newHashMap();
|
|
|
Map<Integer, String> result = Maps.newHashMap();
|
|
|
//3.将条件的key、value转为页面显示的名字
|
|
|
for (Map.Entry<Integer,Map<String,String>> entry : conditionMap .entrySet()) {
|
|
|
Map<String,String> map = entry.getValue();
|
|
|
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);
|
|
|
convertTime(map, "beginChannelOrderTime", "endChannelOrderTime", sb);
|
|
|
convertTime(map, "beginYHOrderTime", "endYHOrderTime", sb);
|
|
|
convertTime(map, "beginRegisterTime", "endRegisterTime", sb);
|
|
|
convertTime(map, "beginSmsTime", "endSmsTime", sb);
|
|
|
convertChannelSource(map,"channelSource",sb);
|
|
|
|
|
|
for(Map.Entry<String,String> entry1:map.entrySet()){
|
|
|
for (Map.Entry<String, String> entry1 : map.entrySet()) {
|
|
|
String key = entry1.getKey();
|
|
|
if(key.equals("channelSource")){
|
|
|
String channelSource = entry1.getValue();
|
|
|
sb.append("<div>").append(paramMap.get(key)).append(":").append(channelSourceMap.get(channelSource)).append("</div>");
|
|
|
}else if(key.equals("hasUid")||key.equals("hasYHOrder")){
|
|
|
if (key.equals("hasUid") || key.equals("hasYHOrder")) {
|
|
|
String has = entry1.getValue();
|
|
|
sb.append("<div>").append(paramMap.get(key)).append(":").append(has.equals("1")?"是":"否").append("</div>");
|
|
|
}else{
|
|
|
sb.append("<div>").append(paramMap.get(key)).append(":").append(has.equals("1") ? "是" : "否").append("</div>");
|
|
|
} else {
|
|
|
sb.append("<div>").append(paramMap.get(key)).append(":").append(entry1.getValue()).append("</div>");
|
|
|
}
|
|
|
}
|
|
|
result.put(entry.getKey(),sb.toString());
|
|
|
result.put(entry.getKey(), sb.toString());
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private void convertChannelSource(Map<String, String> map, String channelSource, StringBuffer sb) {
|
|
|
if (map.get(channelSource) != null) {
|
|
|
String source = map.get(channelSource);
|
|
|
String[] sources = source.split(",");
|
|
|
StringBuffer sourceStr = new StringBuffer();
|
|
|
sourceStr.append("<div>").append(paramMap.get(channelSource)).append(":");
|
|
|
for(int i=0;i<sources.length;i++){
|
|
|
sourceStr.append(channelSourceMap.get(sources[i])).append(" ");
|
|
|
}
|
|
|
sb.append(sourceStr).append("</div>");
|
|
|
map.remove(channelSource);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addBlackList(String mobiles) {
|
|
|
logger.info("enter addBlackList. param mobiles={}", mobiles);
|
|
|
int creteTime = DateUtils.getCurrentTimeSecond();
|
|
|
List<String> list = Arrays.asList(mobiles.split(","));
|
|
|
channelSmsBlackDAO.batchInsert(list,creteTime);
|
|
|
channelSmsBlackDAO.batchInsert(list, creteTime);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int deleteGroup(int groupId) {
|
|
|
logger.info("enter deleteGroup. param groupId={}", groupId);
|
|
|
ChannelGroup channelGroup = new ChannelGroup();
|
|
|
channelGroup.setId(groupId);
|
|
|
channelGroup.setStatus(0);
|
|
|
//逻辑删除,status状态置0
|
|
|
int count = channelGroupDAO.updateByPrimaryKeySelective(channelGroup);
|
|
|
if (count > 0) {
|
|
|
logger.info("deleteGroup success. param groupId={}", groupId);
|
|
|
} else {
|
|
|
logger.warn("deleteGroup fail. param groupId={}", groupId);
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
private void convertTime(Map<String, String> map, String beginTimeKey, String endTimeKey, StringBuffer sb) {
|
|
|
if(map.get(beginTimeKey)!=null || map.get(endTimeKey)!=null){
|
|
|
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{
|
|
|
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{
|
|
|
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>");
|
|
|
sb.append("<div>").append(paramMap.get("beginChannelOrderTime")).append(":").append(beginTime).append("----").append(endTime).append("</div>");
|
|
|
map.remove(beginTimeKey);
|
|
|
map.remove(endTimeKey);
|
|
|
}
|
...
|
...
|
|