187 lines
7.6 KiB
C#
187 lines
7.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using WX.CRM.CRMServices.SMS.InterfaceModel;
|
||
|
||
namespace WX.CRM.CRMServices.SMS.DataDrive
|
||
{
|
||
internal class BatchMsg
|
||
{
|
||
static BatchMsgWaitModel WaitInfo = new BatchMsgWaitModel();
|
||
|
||
/// <summary>
|
||
/// 当前批次剩余的发送数量
|
||
/// </summary>
|
||
public static decimal NumberCount
|
||
{
|
||
get { return WaitInfo.numberCount; }
|
||
}
|
||
/// <summary>
|
||
/// 清除批次
|
||
/// </summary>
|
||
public static void ClearBatch()
|
||
{
|
||
WaitInfo.batchid = 0;
|
||
WaitInfo.numberCount = 0;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取一组发送数据
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static BatchMsgSendModel GetInfo()
|
||
{
|
||
try
|
||
{
|
||
WX.CRM.IBLL.Sms.ISMS_BATCHMSG_Q dataDriveBiz = new WX.CRM.BLL.Sms.SMS_BATCHMSG_BL();
|
||
if (WaitInfo == null || WaitInfo.batchid <= 0 || WaitInfo.numberCount <= 0)
|
||
{
|
||
var OO = dataDriveBiz.GetTopInfo();
|
||
if (OO == null)
|
||
{
|
||
//Common.LogHelper.Error("【批量短信为空GetTopInfo】:" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"));
|
||
WaitInfo.numberCount = 0;
|
||
WaitInfo.batchid = 0;
|
||
return null;
|
||
}
|
||
WaitInfo.batchid = OO.BATCHID;
|
||
WaitInfo.numberCount = OO.numberCount;
|
||
WaitInfo.smsClientCode = OO.CLIENTCODE;
|
||
WaitInfo.MsgSubTypeId = OO.SUBTYPEID ?? 0;
|
||
WaitInfo.interfactCode = OO.interfaceCode;
|
||
WaitInfo.interfaceAccount = OO.interfaceAccount;
|
||
WaitInfo.interfacePwd = OO.interfacePwd;
|
||
WaitInfo.msgContent = OO.MESSAGE;
|
||
}
|
||
|
||
int step_num = StemNum(WaitInfo.interfactCode); //找出对应的接口每次的发送数量
|
||
|
||
List<WX.CRM.Model.Entity.SMS_BATCHMSGDETAIL> list;
|
||
string hasParaSubTypeId = System.Configuration.ConfigurationManager.AppSettings["hasParaSubTypeId"];
|
||
if (hasParaSubTypeId.Split(',').Contains(WaitInfo.MsgSubTypeId.ToString())) //如果是带参数的自定义群发,则,一次只能发一条,如短信地址推送与返馈
|
||
{
|
||
step_num = 1;
|
||
list = dataDriveBiz.GetPopularDetailList(step_num, WaitInfo.batchid);
|
||
}
|
||
else
|
||
{
|
||
list = dataDriveBiz.GetDetailList(step_num, WaitInfo.batchid);
|
||
}
|
||
WaitInfo.numberCount = WaitInfo.numberCount - step_num;
|
||
|
||
if (list == null)
|
||
{
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
BatchMsgSendModel sendInfo = new BatchMsgSendModel();
|
||
sendInfo.msgContent = WaitInfo.msgContent;
|
||
sendInfo.interfaceAccount = WaitInfo.interfaceAccount;
|
||
sendInfo.interfaceCode = WaitInfo.interfactCode;
|
||
sendInfo.interfacePwd = WaitInfo.interfacePwd;
|
||
sendInfo.clientCode = WaitInfo.smsClientCode;
|
||
sendInfo.batchId = WaitInfo.batchid;
|
||
foreach (var dd in list)
|
||
{
|
||
sendInfo.msgContent = sendInfo.msgContent.Replace("@@code", dd.numEncry); //替换参数
|
||
//Common.LogHelper.Info(sendInfo.msgContent);
|
||
sendInfo.pkids.Add(dd.PKID);
|
||
sendInfo.mobiles.Add(dd.mobile);
|
||
}
|
||
return sendInfo;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
WX.CRM.Common.LogHelper.Error("BatchMsg.GetInfo():" + ex.Message + ex.StackTrace);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public static void ExecLog(List<decimal> detaisIds, WX.CRM.Model.Entity.SMS_SENDLOG logInfo)
|
||
{
|
||
try
|
||
{
|
||
WX.CRM.IBLL.Sms.ISMS_BATCHMSG_Q dataDriveBiz = new WX.CRM.BLL.Sms.SMS_BATCHMSG_BL();
|
||
dataDriveBiz.ExecLog(detaisIds, logInfo);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
WX.CRM.Common.LogHelper.Error("【BatchMsg.ExecLog()】:" + ex.Message + ex.Source + ex.StackTrace);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据接口编码获取步长
|
||
/// </summary>
|
||
/// <param name="step"></param>
|
||
/// <returns></returns>
|
||
static int StemNum(string iterfaceCode)
|
||
{
|
||
JobModel jobm = new JobModel();
|
||
if (string.IsNullOrEmpty(iterfaceCode))
|
||
throw new Exception("StemNum(iterfaceCode)中iterfaceCode参数不能为空!");
|
||
int result = 0;
|
||
var acc = InterfaceFactory.GetInterfaceIdByCode(iterfaceCode);
|
||
switch (acc)
|
||
{
|
||
case InterfaceModel.SmsAccountID.HuiZhi:
|
||
result = jobm.HuiZhiStepNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.RuiXin:
|
||
result = jobm.RuiXinStepNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.QiXinTong:
|
||
result = jobm.QiXinTongStepNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.Ent:
|
||
result = jobm.EntStemNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.Ent2:
|
||
result = jobm.EntStemNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.ENT3:
|
||
result = jobm.EntStemNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.SM360:
|
||
result = jobm.SM360StepNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.CAT:
|
||
result = jobm.UpCatStepNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.LianTong:
|
||
result = jobm.LianTongStepNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.TaoBaoTxt:
|
||
result = jobm.TaoBaoTXTNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.QQSms:
|
||
result = jobm.QQSmsNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.ZJZXSms:
|
||
result = jobm.ZQZXSmsNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.QYXS:
|
||
result = jobm.QYXSStepNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.YZ:
|
||
result = jobm.YZSmsNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.YZ2:
|
||
result = jobm.YZSms2Num;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.TencentSms:
|
||
result = jobm.TencentNum;
|
||
break;
|
||
case InterfaceModel.SmsAccountID.TaoBaoTxtVoice:
|
||
throw new Exception("【淘宝开放平台短信接口】TaoBaoTxtVoice:不能批量发送!");
|
||
//break;
|
||
}
|
||
if (result <= 0)
|
||
throw new Exception(string.Format("短信发送时根据接口编码获取接口【{0}】的发送数量时出现异常!", iterfaceCode));
|
||
return result;
|
||
}
|
||
}
|
||
}
|