107 lines
3.9 KiB
C#
107 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
|
|
namespace WX.CRM.BLL.Sms
|
|
{
|
|
public class SMS_MESSAGE_BL : WX.CRM.IBLL.Sms.ISMS_MESSAGE_Q
|
|
{
|
|
string clientid = Utility.GetSettingByKey("CRMClientKey");
|
|
WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper();
|
|
|
|
private WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext();
|
|
|
|
public List<WX.CRM.Model.Entity.SMS_MESSAGE> GetList(int topNum)
|
|
{
|
|
var q = db.SMS_MESSAGE.OrderBy(p => p.MESSAGEID).Skip(0).Take(topNum).ToList();
|
|
foreach (var o in q)
|
|
{
|
|
string resid = o.RESID.ToString().Trim();
|
|
var m = db.RES_RESOURCEMOBILE.Where(p => p.RESID == resid).FirstOrDefault();
|
|
if (m != null)
|
|
{
|
|
var mobile = string.Empty;
|
|
try
|
|
{
|
|
mobile = sHelper.decyptData(clientid, m.MOBILE);
|
|
}
|
|
catch
|
|
{
|
|
try
|
|
{
|
|
mobile = sHelper.decyptData("gd_crm", m.MOBILE);
|
|
}
|
|
catch
|
|
{
|
|
LogHelper.Error("手机号码解密错误:" + resid);
|
|
}
|
|
}
|
|
o.mobile = mobile;
|
|
}
|
|
var c = db.SMS_ACCOUNT.Where(p => p.CLIENTCODE == o.CLIENTCODE).FirstOrDefault();
|
|
if (c != null)
|
|
{
|
|
o.interfaceAccount = c.SMSACCOUNT;
|
|
o.interfaceCode = c.SMSSP_CODE;
|
|
o.interfacePwd = c.SMSPASSWORD;
|
|
}
|
|
else
|
|
{
|
|
LogHelper.Info("未能获取到配置信息:" + o.CLIENTCODE + "--");
|
|
}
|
|
}
|
|
return q;
|
|
}
|
|
|
|
public void ExecLog(decimal messageId, WX.CRM.Model.Entity.SMS_SENDLOG logInfo)
|
|
{
|
|
//if (db.Database.Connection.State != System.Data.ConnectionState.Open)
|
|
// db.Database.Connection.Open();
|
|
//var dbtrans = db.Database.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
logInfo.SENDID = new BLL.Base.SEQUENCES_BL().Seq_base_get(WX.CRM.Model.Enum.PKIDType.LargeTable);
|
|
db.SMS_SENDLOG.Add(logInfo);
|
|
var msg = db.SMS_MESSAGE.Where(p => p.MESSAGEID == messageId).FirstOrDefault();
|
|
db.SMS_MESSAGE_HIS.Add(new WX.CRM.Model.Entity.SMS_MESSAGE_HIS()
|
|
{
|
|
MESSAGEID = msg.MESSAGEID,
|
|
MESSAGE = msg.MESSAGE,
|
|
TYPECODE = msg.TYPECODE,
|
|
SUBTYPECODE = msg.SUBTYPECODE,
|
|
RESID = msg.RESID,
|
|
CLIENTCODE = msg.CLIENTCODE,
|
|
CTIME = msg.CTIME,
|
|
CREATEUSER = msg.CREATEUSER,
|
|
SENDID = logInfo.SENDID,
|
|
SENDSUCCESS = logInfo.SENDSUCCESS,
|
|
SENDTIME = logInfo.SENDTIME
|
|
});
|
|
db.SMS_MESSAGE.Remove(msg);
|
|
db.SaveChanges();
|
|
//dbtrans.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//dbtrans.Rollback();
|
|
throw ex;
|
|
}
|
|
//finally
|
|
//{
|
|
// db.Database.Connection.Close();
|
|
//}
|
|
}
|
|
|
|
public void Add(WX.CRM.Model.Entity.SMS_MESSAGE model)
|
|
{
|
|
model.MESSAGEID = new BLL.Base.SEQUENCES_BL().Seq_base_get(WX.CRM.Model.Enum.PKIDType.LargeTable);
|
|
model.CTIME = DateTime.Now;
|
|
model.CREATEUSER = 1;
|
|
db.SMS_MESSAGE.Add(model);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
}
|