122 lines
4.6 KiB
C#
122 lines
4.6 KiB
C#
using CRM.Core.BLL.Util;
|
||
using CRM.Core.Model.Entity;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using WX.CRM.Common;
|
||
|
||
namespace CRM.Core.BLL.Sms
|
||
{
|
||
public class SMS_MESSAGE_BL : DbContextRepository<SMS_MESSAGE>
|
||
{
|
||
string clientid = Utility.GetSettingByKey("CRMClientKey");
|
||
SecurityHelper sHelper = new SecurityHelper();
|
||
public List<SMS_MESSAGE> GetList(int topNum)
|
||
{
|
||
|
||
using (var db = new zxdContext())
|
||
{
|
||
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();
|
||
string newResid = "";
|
||
string[] resids = resid.Split(',');
|
||
foreach (var item in resids)
|
||
{
|
||
if (string.IsNullOrEmpty(item))
|
||
continue;
|
||
if (item.Length > 11)
|
||
{
|
||
//如果是resid做解密处理,批量一定是手机号码
|
||
var m = db.RES_RESOURCEMOBILE.Where(p => p.RESID == item).FirstOrDefault();
|
||
if (m != null)
|
||
{
|
||
var mobile = string.Empty;
|
||
try
|
||
{
|
||
mobile = sHelper.decyptData(clientid, m.MOBILE);
|
||
}
|
||
catch
|
||
{
|
||
LogHelper.Info("手机号码解密问题1" + clientid);
|
||
try
|
||
{
|
||
mobile = sHelper.decyptData("gd_crm", m.MOBILE);
|
||
}
|
||
catch
|
||
{
|
||
LogHelper.Info("手机号码解密问题gd_crm");
|
||
}
|
||
}
|
||
newResid += mobile + ",";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
newResid += item + ",";
|
||
}
|
||
}
|
||
o.mobile = newResid;
|
||
if (o.mobile.EndsWith(","))
|
||
{
|
||
o.mobile = o.mobile.Substring(0, o.mobile.Length - 1);
|
||
}
|
||
|
||
|
||
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;
|
||
}
|
||
}
|
||
return q;
|
||
}
|
||
}
|
||
|
||
public void ExecLog(decimal messageId, SMS_SENDLOG logInfo)
|
||
{
|
||
//if (db.Database.Connection.State != System.Data.ConnectionState.Open)
|
||
// db.Database.Connection.Open();
|
||
//var dbtrans = db.Database.Connection.BeginTransaction();
|
||
try
|
||
{
|
||
using (var db = new zxdContext())
|
||
{
|
||
db.SMS_SENDLOG.Add(logInfo);
|
||
var msg = db.SMS_MESSAGE.Where(p => p.MESSAGEID == messageId).FirstOrDefault();
|
||
db.SMS_MESSAGE_HIS.Add(new 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();
|
||
//}
|
||
}
|
||
|
||
}
|
||
}
|