|
|
@@ -1,9 +1,11 @@ |
|
|
package com.iformall.service.impl; |
|
|
package com.iformall.service.impl; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
import com.iformall.common.ErrorCode; |
|
|
import com.iformall.common.ErrorCode; |
|
|
import com.iformall.common.IdWorker; |
|
|
import com.iformall.common.IdWorker; |
|
|
import com.iformall.common.Result; |
|
|
import com.iformall.common.Result; |
|
|
@@ -11,15 +13,13 @@ import com.iformall.common.ResultData; |
|
|
import com.iformall.domain.dto.WxCUserBasicInfoFilterListDto; |
|
|
import com.iformall.domain.dto.WxCUserBasicInfoFilterListDto; |
|
|
import com.iformall.domain.po.*; |
|
|
import com.iformall.domain.po.*; |
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
|
|
|
import com.iformall.domain.po.msg.SmartAppMsg; |
|
|
import com.iformall.domain.po.msg.WxMsg; |
|
|
import com.iformall.domain.po.msg.WxMsg; |
|
|
import com.iformall.enums.*; |
|
|
import com.iformall.enums.*; |
|
|
import com.iformall.exception.MallinkException; |
|
|
import com.iformall.exception.MallinkException; |
|
|
import com.iformall.mapper.*; |
|
|
import com.iformall.mapper.*; |
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
import com.iformall.service.PushLimitService; |
|
|
|
|
|
import com.iformall.service.WxCUserBasicInfoService; |
|
|
|
|
|
import com.iformall.service.WxCUserTagsService; |
|
|
|
|
|
import com.iformall.service.WxMsgService; |
|
|
|
|
|
|
|
|
import com.iformall.service.*; |
|
|
import com.iformall.utils.DateUtils; |
|
|
import com.iformall.utils.DateUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
@@ -56,6 +56,8 @@ public class WxMsgServiceImpl implements WxMsgService { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
WxMsgModelMapper wxMsgModelMapper; |
|
|
WxMsgModelMapper wxMsgModelMapper; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxTemplateMsgMapper wxTemplateMsgMapper; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
MqBaseProducer mqBaseProducer; |
|
|
MqBaseProducer mqBaseProducer; |
|
|
@@ -66,6 +68,9 @@ public class WxMsgServiceImpl implements WxMsgService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
PushLimitService pushLimitService; |
|
|
PushLimitService pushLimitService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxAppinfoService wxAppinfoService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { |
|
|
public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { |
|
|
PageHelper.startPage(pageIndex, pageSize); |
|
|
PageHelper.startPage(pageIndex, pageSize); |
|
|
@@ -120,17 +125,28 @@ public class WxMsgServiceImpl implements WxMsgService { |
|
|
//是否立即发送 |
|
|
//是否立即发送 |
|
|
if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { |
|
|
if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { |
|
|
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); |
|
|
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); |
|
|
if (wxMsg.getExpectSendNumber().intValue() > 1000) { |
|
|
|
|
|
batchSendMsg(wxMsg, wxMsgConfig, null); |
|
|
|
|
|
} else { |
|
|
|
|
|
//sendmsg(wxMsg, wxMsgConfig, null); |
|
|
|
|
|
wxMsg.setWxMsgConfig(wxMsgConfig); |
|
|
|
|
|
wxMsg.setCouponInject(null); |
|
|
|
|
|
wxMsg.setMsgType(EnumMsgRecordType.SMS_CALLBACK.getCode()); |
|
|
|
|
|
wxMsg.setReceiver(wxMsg.getPhones()); |
|
|
|
|
|
mqBaseProducer.sendMessage(wxMsg, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),null); |
|
|
|
|
|
|
|
|
if(wxMsg.getWay() == EnumSendWay.TAG.getCode()){ |
|
|
|
|
|
if (wxMsg.getExpectSendNumber().intValue() > 1000) { |
|
|
|
|
|
batchSendMsg(wxMsg, wxMsgConfig, null); |
|
|
|
|
|
} else { |
|
|
|
|
|
//sendmsg(wxMsg, wxMsgConfig, null); |
|
|
|
|
|
wxMsg.setWxMsgConfig(wxMsgConfig); |
|
|
|
|
|
wxMsg.setCouponInject(null); |
|
|
|
|
|
wxMsg.setMsgType(EnumMsgRecordType.SMS_CALLBACK.getCode()); |
|
|
|
|
|
wxMsg.setReceiver(wxMsg.getPhones()); |
|
|
|
|
|
mqBaseProducer.sendMessage(wxMsg, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),null); |
|
|
|
|
|
} |
|
|
|
|
|
}else if(wxMsg.getWay() == EnumSendWay.APPINFOR.getCode()){ |
|
|
|
|
|
batchSendAppinfo(wxMsg); |
|
|
|
|
|
}else{ |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_REQUEST_PARAMS_ERROR); |
|
|
} |
|
|
} |
|
|
return new ResultData(Result.SUCCESS, "短信已发送"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
|
|
wxMsg.setId(idWorker.nextId()); |
|
|
|
|
|
wxMsg.setCreatetime(new Date()); |
|
|
|
|
|
wxMsgMapper.insert(wxMsg); |
|
|
|
|
|
return new ResultData(Result.SUCCESS, "消息已发送"); |
|
|
} else { |
|
|
} else { |
|
|
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_NOT_SEND.getCode()); |
|
|
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_NOT_SEND.getCode()); |
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
@@ -138,7 +154,7 @@ public class WxMsgServiceImpl implements WxMsgService { |
|
|
wxMsg.setId(id); |
|
|
wxMsg.setId(id); |
|
|
wxMsg.setCreatetime(new Date()); |
|
|
wxMsg.setCreatetime(new Date()); |
|
|
wxMsgMapper.insert(wxMsg); |
|
|
wxMsgMapper.insert(wxMsg); |
|
|
return new ResultData(Result.SUCCESS, "短信会在预设时间发送", id); |
|
|
|
|
|
|
|
|
return new ResultData(Result.SUCCESS, "消息会在预设时间发送", id); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
@@ -151,21 +167,31 @@ public class WxMsgServiceImpl implements WxMsgService { |
|
|
//是否立即发送 |
|
|
//是否立即发送 |
|
|
if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { |
|
|
if (wxMsg.getIsright().equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) { |
|
|
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); |
|
|
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); |
|
|
if (wxMsg.getExpectSendNumber().intValue() > 1000) { |
|
|
|
|
|
batchSendMsg(wxMsg, wxMsgConfig, null); |
|
|
|
|
|
} else { |
|
|
|
|
|
//sendmsg(wxMsg, wxMsgConfig, null); |
|
|
|
|
|
wxMsg.setWxMsgConfig(wxMsgConfig); |
|
|
|
|
|
wxMsg.setMsgType(EnumMsgRecordType.SMS_CALLBACK.getCode()); |
|
|
|
|
|
wxMsg.setReceiver(wxMsg.getPhones()); |
|
|
|
|
|
mqBaseProducer.sendMessage(wxMsg, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); |
|
|
|
|
|
|
|
|
if(wxMsg.getWay() == EnumSendWay.TAG.getCode()){ |
|
|
|
|
|
if (wxMsg.getExpectSendNumber().intValue() > 1000) { |
|
|
|
|
|
batchSendMsg(wxMsg, wxMsgConfig, null); |
|
|
|
|
|
} else { |
|
|
|
|
|
//sendmsg(wxMsg, wxMsgConfig, null); |
|
|
|
|
|
wxMsg.setWxMsgConfig(wxMsgConfig); |
|
|
|
|
|
wxMsg.setMsgType(EnumMsgRecordType.SMS_CALLBACK.getCode()); |
|
|
|
|
|
wxMsg.setReceiver(wxMsg.getPhones()); |
|
|
|
|
|
mqBaseProducer.sendMessage(wxMsg, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
}else if(wxMsg.getWay() == EnumSendWay.APPINFOR.getCode()){ |
|
|
|
|
|
batchSendAppinfo(wxMsg); |
|
|
|
|
|
}else{ |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_REQUEST_PARAMS_ERROR); |
|
|
} |
|
|
} |
|
|
return new ResultData(Result.SUCCESS, "短信已发送"); |
|
|
|
|
|
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
|
|
wxMsg.setId(idWorker.nextId()); |
|
|
|
|
|
wxMsg.setCreatetime(new Date()); |
|
|
|
|
|
wxMsgMapper.insert(wxMsg); |
|
|
|
|
|
return new ResultData(Result.SUCCESS, "消息已发送"); |
|
|
} else { |
|
|
} else { |
|
|
//定时 |
|
|
//定时 |
|
|
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_NOT_SEND.getCode()); |
|
|
wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_NOT_SEND.getCode()); |
|
|
wxMsgMapper.updateById(wxMsg); |
|
|
wxMsgMapper.updateById(wxMsg); |
|
|
return new ResultData(Result.SUCCESS, "短信会在预设时间发送"); |
|
|
|
|
|
|
|
|
return new ResultData(Result.SUCCESS, "消息会在预设时间发送"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
@@ -226,14 +252,27 @@ public class WxMsgServiceImpl implements WxMsgService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (phones.isEmpty()) {//没有手工输入手机号时解析标签,有,继续流转 |
|
|
if (phones.isEmpty()) {//没有手工输入手机号时解析标签,有,继续流转 |
|
|
List<WxCUserBasicInfo> list = |
|
|
|
|
|
wxCUserBasicInfoService.listByFilterList(tenantEntity,wxMsg.getFilterList()); |
|
|
|
|
|
wxMsg.setExpectSendNumber(list.size());//预计发送数量 |
|
|
|
|
|
phones = list.stream().map(u -> u.getPhone()).collect(Collectors.joining(",")); |
|
|
|
|
|
if (phones==null || phones.isEmpty()) {//解析之后手机号依然不存在时返回 |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_NO_VALID_PHONE); |
|
|
|
|
|
|
|
|
if(wxMsg.getWay() == EnumSendWay.TAG.getCode()){ |
|
|
|
|
|
List<WxCUserBasicInfo> list = |
|
|
|
|
|
wxCUserBasicInfoService.listByFilterList(tenantEntity,wxMsg.getFilterList()); |
|
|
|
|
|
wxMsg.setExpectSendNumber(list.size());//预计发送数量 |
|
|
|
|
|
phones = list.stream().map(u -> u.getPhone()).collect(Collectors.joining(",")); |
|
|
|
|
|
if (phones==null || phones.isEmpty()) {//解析之后手机号依然不存在时返回 |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_NO_VALID_PHONE); |
|
|
|
|
|
} |
|
|
|
|
|
wxMsg.setPhones(StringUtils.join(phones)); |
|
|
|
|
|
}else if(wxMsg.getWay() == EnumSendWay.APPINFOR.getCode()){ |
|
|
|
|
|
List<String> list = wxCUserBasicInfoService.listOpenIdByFilter(tenantEntity,wxMsg.getFilterList()); |
|
|
|
|
|
wxMsg.setExpectSendNumber(list.size());//预计发送数量 |
|
|
|
|
|
String opens = StringUtils.join(list, ","); |
|
|
|
|
|
if (opens==null || opens.isEmpty()) {//解析之后手机号依然不存在时返回 |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_NO_VALID_PHONE); |
|
|
|
|
|
} |
|
|
|
|
|
wxMsg.setPhones(opens); |
|
|
|
|
|
}else{ |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_REQUEST_PARAMS_ERROR); |
|
|
} |
|
|
} |
|
|
wxMsg.setPhones(StringUtils.join(phones)); |
|
|
|
|
|
|
|
|
|
|
|
wxMsg.setTags(JSON.toJSONString(wxMsg.getFilterList())); |
|
|
wxMsg.setTags(JSON.toJSONString(wxMsg.getFilterList())); |
|
|
} else { |
|
|
} else { |
|
|
String[] phoneSplit = phones.split(","); |
|
|
String[] phoneSplit = phones.split(","); |
|
|
@@ -242,24 +281,32 @@ public class WxMsgServiceImpl implements WxMsgService { |
|
|
wxMsg.setPhones(StringUtils.join(phoneSet,",")); |
|
|
wxMsg.setPhones(StringUtils.join(phoneSet,",")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//从短信配置中查询密钥 bid 等信息 |
|
|
|
|
|
WxMsgConfig wxMsgConfig = new WxMsgConfig(); |
|
|
|
|
|
wxMsgConfig.setTenantId(wxMsg.getTenantId()); |
|
|
|
|
|
List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); |
|
|
|
|
|
if (wxMsgConfigs.size() == 0) return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND, "您还未接入短信运营商,请联系平台管理员"); |
|
|
|
|
|
wxMsgConfig = wxMsgConfigs.get(0); |
|
|
|
|
|
|
|
|
|
|
|
if (wxMsgConfig.getRemains() == 0) { |
|
|
|
|
|
logger.info("短信数量为0"); |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_SUM_ZERO); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(wxMsg.getWay() == EnumSendWay.TAG.getCode()){ |
|
|
|
|
|
//从短信配置中查询密钥 bid 等信息 |
|
|
|
|
|
WxMsgConfig wxMsgConfig = new WxMsgConfig(); |
|
|
|
|
|
wxMsgConfig.setTenantId(wxMsg.getTenantId()); |
|
|
|
|
|
List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); |
|
|
|
|
|
if (wxMsgConfigs.size() == 0) return new ResultData(ErrorCode.MSG_SERVER_NOT_FIND, "您还未接入短信运营商,请联系平台管理员"); |
|
|
|
|
|
wxMsgConfig = wxMsgConfigs.get(0); |
|
|
|
|
|
|
|
|
|
|
|
if (wxMsgConfig.getRemains() == 0) { |
|
|
|
|
|
logger.info("短信数量为0"); |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_SUM_ZERO); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { |
|
|
|
|
|
logger.info("短信数量不足"); |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_SUM_INSUFFICENT); |
|
|
|
|
|
|
|
|
if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { |
|
|
|
|
|
logger.info("短信数量不足"); |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_SUM_INSUFFICENT); |
|
|
|
|
|
} |
|
|
|
|
|
saveOrUpdate(wxMsg, wxMsgConfig); |
|
|
|
|
|
return new ResultData(); |
|
|
|
|
|
}else if(wxMsg.getWay() == EnumSendWay.APPINFOR.getCode()){ |
|
|
|
|
|
|
|
|
|
|
|
saveOrUpdate(wxMsg,null); |
|
|
|
|
|
return new ResultData(); |
|
|
|
|
|
}else{ |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_REQUEST_PARAMS_ERROR); |
|
|
} |
|
|
} |
|
|
saveOrUpdate(wxMsg, wxMsgConfig); |
|
|
|
|
|
return new ResultData(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -302,6 +349,60 @@ public class WxMsgServiceImpl implements WxMsgService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void batchSendAppinfo(WxMsg wxMsg) { |
|
|
|
|
|
TenantEntity tenantEntity = new TenantEntity(); |
|
|
|
|
|
tenantEntity.setTenantId(wxMsg.getTenantId()); |
|
|
|
|
|
tenantEntity.setParentTenantId(wxMsg.getParentTenantId()); |
|
|
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity, EnumPayWay.PAY_WAY_WECHAT); |
|
|
|
|
|
SmartAppMsg smartAppMsg = new SmartAppMsg(); |
|
|
|
|
|
smartAppMsg.updateTenantInfo(tenantEntity); |
|
|
|
|
|
smartAppMsg.setMsgType(EnumMsgRecordType.SMART_APP_TO.getCode()); |
|
|
|
|
|
smartAppMsg.setAppId(cAppInfo.getAppId()); |
|
|
|
|
|
|
|
|
|
|
|
WxTemplateMsg wxTemplateMsg = wxTemplateMsgMapper.selectById(wxMsg.getModelId()); |
|
|
|
|
|
|
|
|
|
|
|
smartAppMsg.setTemplateType(wxTemplateMsg.getType()); |
|
|
|
|
|
JSONObject customParam = JSON.parseObject(wxMsg.getMsg()); |
|
|
|
|
|
if(wxTemplateMsg.getType() == EnumTemplateType.ACTIVITY_REMIND.getCode()){ |
|
|
|
|
|
/** |
|
|
|
|
|
* 活动名称:{{thing13.DATA}} |
|
|
|
|
|
* 活动时间:{{date5.DATA}} |
|
|
|
|
|
* 商户名称:{{thing12.DATA}} |
|
|
|
|
|
* 活动内容:{{thing1.DATA}} |
|
|
|
|
|
* 温馨提示:{{thing11.DATA}}" |
|
|
|
|
|
*/ |
|
|
|
|
|
smartAppMsg.setDataList(Lists.newArrayList( |
|
|
|
|
|
customParam.getString("thing13"), |
|
|
|
|
|
customParam.getString("date5"), |
|
|
|
|
|
customParam.getString("thing12"), |
|
|
|
|
|
customParam.getString("thing1"), |
|
|
|
|
|
customParam.getString("thing11") |
|
|
|
|
|
)); |
|
|
|
|
|
}else if(wxTemplateMsg.getType() == EnumTemplateType.LIVE_REMIND.getCode()){ |
|
|
|
|
|
/** |
|
|
|
|
|
* 直播标题:{{thing1.DATA}} |
|
|
|
|
|
* 开播时间:{{date3.DATA}} |
|
|
|
|
|
* 主播昵称:{{thing4.DATA}} |
|
|
|
|
|
* 温馨提示:{{thing5.DATA}} |
|
|
|
|
|
*/ |
|
|
|
|
|
smartAppMsg.setDataList(Lists.newArrayList( |
|
|
|
|
|
customParam.getString("thing1"), |
|
|
|
|
|
customParam.getString("date3"), |
|
|
|
|
|
customParam.getString("thing4"), |
|
|
|
|
|
customParam.getString("thing5") |
|
|
|
|
|
)); |
|
|
|
|
|
}else{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
String[] split = wxMsg.getPhones().split(","); |
|
|
|
|
|
for (String s:split) { |
|
|
|
|
|
smartAppMsg.setTo(s); |
|
|
|
|
|
mqBaseProducer.sendMessage(smartAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void addMsgCallback(WxMsg wxmsg, String batchNo) { |
|
|
public void addMsgCallback(WxMsg wxmsg, String batchNo) { |
|
|
|