271 lines
11 KiB
C#
271 lines
11 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.Model.Entity;
|
||
|
||
namespace WX.CRM.CRMServices.ServicesModel
|
||
{
|
||
public class RecordData
|
||
{
|
||
private shjcdrdto dto;
|
||
private List<CSVR_CALLRECORD> callRecordList;
|
||
private List<CSVR_TODAYRECORD> TodayRecordList;
|
||
public RecordData(shjcdrdto _dto)
|
||
{
|
||
this.dto = _dto;
|
||
InsertCallRecord();
|
||
}
|
||
public List<CSVR_CALLRECORD> getCallRecordList()
|
||
{
|
||
return this.callRecordList;
|
||
}
|
||
public List<CSVR_TODAYRECORD> getTodayRecordList()
|
||
{
|
||
return this.TodayRecordList;
|
||
}
|
||
|
||
private void InsertCallRecord()
|
||
{
|
||
List<CSVR_CALLRECORD> calllist = new List<CSVR_CALLRECORD>();
|
||
List<CSVR_TODAYRECORD> todaylist = new List<CSVR_TODAYRECORD>();
|
||
if (this.dto.result != 1)//远程数据失败
|
||
{
|
||
throw new Exception("深海捷获取通话录音远程数据失败:" + this.dto.result + this.dto.data);
|
||
}
|
||
else if (this.dto.data.msg != null && this.dto.data.msg.Count > 0)
|
||
{
|
||
var cdrlist = this.dto.data.msg.Where(obj => obj.Event == "Cdr");
|
||
foreach (var msg in cdrlist)
|
||
{
|
||
if (!string.IsNullOrEmpty(msg.CallType) && msg.Disposition == "ANSWERED")
|
||
{
|
||
string fjh = ""/*座席电话号*/, tel4 = ""/*客户号*/, resId = ""/*客户ID*/;
|
||
DateTime todayDate = DateTime.Today;
|
||
decimal callType;
|
||
decimal out_i = 0;
|
||
if (msg.CallType.ToUpper() == "IN" || msg.CallType == "1")//0:外线呼入,1:内部呼出,2:内部通话
|
||
{
|
||
fjh = msg.Destination;
|
||
tel4 = msg.Source;
|
||
callType = 0;
|
||
}
|
||
else if (msg.CallType.ToUpper() == "OUT" || msg.CallType == "2")
|
||
{
|
||
fjh = msg.Source;
|
||
tel4 = msg.Destination;
|
||
callType = 1;
|
||
}
|
||
else if (msg.CallType.ToUpper() == "INTVAL" || msg.CallType == "3")
|
||
{
|
||
|
||
fjh = msg.Destination;
|
||
tel4 = msg.Source;
|
||
callType = 2;
|
||
}
|
||
else
|
||
{
|
||
fjh = msg.Destination;
|
||
tel4 = msg.Source;
|
||
callType = -1;
|
||
// LogHelper.Error("深海通话类型" + msg.CallType);
|
||
}
|
||
tel4 = NumberSub(tel4);
|
||
if (decimal.TryParse(fjh, out out_i) && decimal.TryParse(tel4, out out_i))
|
||
{
|
||
if (tel4.Length > 5)
|
||
{
|
||
resId = ResUtil.CreateResId(tel4);
|
||
List<ResIdAndPhone> resIdAndNumber = new List<ResIdAndPhone>() {
|
||
new ResIdAndPhone(){
|
||
ResId= resId,
|
||
Number = tel4
|
||
}
|
||
};
|
||
try
|
||
{
|
||
if (resIdAndNumber.Count > 0)
|
||
{
|
||
var reg = new RegPhone(resIdAndNumber);
|
||
reg.RegisterList();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("深海捷CallRecord注册号码:" + ex.ToString());
|
||
}
|
||
}
|
||
if (tel4.Length > 4)
|
||
{
|
||
tel4 = tel4.Substring(tel4.Length - 4);
|
||
}
|
||
|
||
string eid = fjh == "" ? "0" : fjh;
|
||
|
||
CSVR_CALLRECORD call = new CSVR_CALLRECORD()
|
||
{
|
||
RECORDID = Convert.ToDecimal(msg.UniqueID),
|
||
SERVERID = msg.Server,
|
||
FILENAME = msg.UserField,
|
||
RESID = resId,
|
||
SERVICENUMBER = fjh,
|
||
TELNUMBERLAST4 = tel4,
|
||
TIMELENGTH = Convert.ToDecimal(msg.BillableSeconds),
|
||
CALLTYPE = callType,
|
||
SALESEID = Convert.ToDecimal(eid),
|
||
TIMESTART = Convert.ToDateTime(msg.StartTime),
|
||
CTIME = DateTime.Now,
|
||
TIMEEND = Convert.ToDateTime(msg.StartTime).AddSeconds(double.Parse(msg.BillableSeconds))
|
||
};
|
||
calllist.Add(call);
|
||
|
||
CSVR_TODAYRECORD todaymodel = new CSVR_TODAYRECORD()
|
||
{
|
||
RECORDID = decimal.Parse(msg.UniqueID),
|
||
SERVERID = msg.Server,
|
||
FILENAME = msg.UserField,
|
||
RESID = resId,
|
||
SERVICENUMBER = fjh,
|
||
TELNUMBERLAST4 = tel4,
|
||
TIMELENGTH = Convert.ToDecimal(msg.BillableSeconds),
|
||
CALLTYPE = callType,
|
||
SALESEID = Convert.ToDecimal(eid),
|
||
TIMESTART = Convert.ToDateTime(msg.StartTime),
|
||
CTIME = DateTime.Now,
|
||
TIMEEND = Convert.ToDateTime(msg.StartTime).AddSeconds(double.Parse(msg.BillableSeconds))
|
||
};
|
||
todaylist.Add(todaymodel);
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Error("深海捷获取通话录音远程数据为:0");
|
||
}
|
||
this.callRecordList = calllist;
|
||
this.TodayRecordList = todaylist;
|
||
|
||
}
|
||
private string NumberSub(string number)
|
||
{
|
||
string Sub_9 = @"^9\d*$";
|
||
string Sub_0 = @"^(013|015|018|014|017|019)\d*$";
|
||
string Sub_1 = @"^1\d*$";
|
||
Regex reg1 = new Regex(Sub_9);
|
||
Regex reg2 = new Regex(Sub_0);
|
||
Regex reg3 = new Regex(Sub_1);
|
||
if (number.Length > 10 && reg1.IsMatch(number))
|
||
{
|
||
string sub9_number = number.Substring(1);
|
||
if (sub9_number.Length > 11 && reg2.IsMatch(sub9_number))
|
||
{
|
||
string sub0_number = sub9_number.Substring(1);
|
||
return sub0_number;
|
||
}
|
||
else
|
||
{
|
||
return sub9_number;
|
||
}
|
||
}
|
||
else if (number.Length > 11 && reg3.IsMatch(number))
|
||
{
|
||
string sub1_number = number.Substring(1);
|
||
if (sub1_number.Length > 11 && reg2.IsMatch(sub1_number))
|
||
{
|
||
string sub0_number = sub1_number.Substring(1);
|
||
return sub0_number;
|
||
}
|
||
else
|
||
{
|
||
return sub1_number;
|
||
}
|
||
}
|
||
else if (number.Length > 11 && reg2.IsMatch(number))
|
||
{
|
||
string sub0_number = number.Substring(1);
|
||
return sub0_number;
|
||
}
|
||
else
|
||
{
|
||
return number;
|
||
}
|
||
}
|
||
}
|
||
|
||
public class shjcdrdto
|
||
{
|
||
public int result { get; set; }
|
||
public shjcdrdata data { get; set; }
|
||
public shjcdrdto()
|
||
{
|
||
|
||
}
|
||
/// <summary>
|
||
/// 深海捷json 数据转Object
|
||
/// </summary>
|
||
/// <param name="rst"></param>
|
||
/// <returns></returns>
|
||
public shjcdrdto getDto(string rst)
|
||
{
|
||
shjcdrdto dto = Utility.MAXJSONToObject<shjcdrdto>(rst);
|
||
return dto;
|
||
}
|
||
|
||
}
|
||
public class shjcdrdata
|
||
{
|
||
//total为0时表示呼叫中心数据全部被获取完毕
|
||
public int total { get; set; }
|
||
public List<shjcdrmsg> msg { get; set; }
|
||
}
|
||
public class shjcdrmsg
|
||
{
|
||
public string Event { get; set; }
|
||
public string Privilege { get; set; }
|
||
public string AccountCode { get; set; }
|
||
//主叫号码(长度80 字符)
|
||
public string Source { get; set; }
|
||
//被叫号码(长度80 字符)
|
||
public string Destination { get; set; }
|
||
//目的地context(执行的上下文)(长度80 字符)
|
||
public string DestinationContext { get; set; }
|
||
//主叫认息(长度80 字符)
|
||
public string CallerID { get; set; }
|
||
//主叫通道(长度80 字符)
|
||
public string Channel { get; set; }
|
||
//被叫通道(长度80 字符)
|
||
public string DestinationChannel { get; set; }
|
||
//最后执行的应用(长度80 字符)
|
||
public string LastApplication { get; set; }
|
||
//最后执行context(长度80 字符)
|
||
public string LastData { get; set; }
|
||
//呼叫开始的时间(0000-00-00 00:00:00)
|
||
public string StartTime { get; set; }
|
||
public string AnswerTime { get; set; }
|
||
public string EndTime { get; set; }
|
||
//整个呼叫的时间,从呼叫开始到结束,使用秒来计费(数据类型:整数)
|
||
public string Duration { get; set; }
|
||
//整个呼叫通话的时间,从呼叫接通开始到结束,使用秒来计费(数据类型:整数)
|
||
public string BillableSeconds { get; set; }
|
||
//呼叫状态(接通-'ANSWERED',没有接通-'NO ANSWER',忙音-'BUSY',失败-'FAILED')
|
||
public string Disposition { get; set; }
|
||
public string AMAFlags { get; set; }
|
||
//通话记录的唯一标识
|
||
public string UniqueID { get; set; }
|
||
//录音文件名
|
||
public string UserField { get; set; }
|
||
//呼叫类型,0:内部通话,1:外线呼入,2:内部呼出,3:未知
|
||
public string CallType { get; set; }
|
||
//被叫号码,即公司的外线号码,呼入时带此参数
|
||
public string DID { get; set; }
|
||
//挂断方,Caller表示主叫先挂断,Callee表示被叫先挂断
|
||
public string Hangup { get; set; }
|
||
public string Server { get; set; }
|
||
|
||
}
|
||
}
|