TG.WXCRM.V4/CRMServices/PkgSms/CtiGetCdr.cs

183 lines
8.3 KiB
C#

using WX.CRM.BLL.Base;
using WX.CRM.BLL.Csvr;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.Model.Entity;
using WX.CRM.Model.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WX.CRM.CRMServices.ServicesModel;
namespace WX.CRM.CRMServices.PkgSms
{
public class CtiGetCdr
{
public void DowSHJData()
{
GetSHJCallRecold();
}
public void DisposeRecoldFile()
{
try
{
DeleteTwoMonthFile();
}
catch (Exception ex)
{
LogHelper.Error("删除深海捷录音两月前数据文件:" + ex.ToString());
}
try
{
DisposeErrorRecord();
}
catch (Exception ex)
{
LogHelper.Error("处理深海捷录音出错文件:" + ex.ToString());
}
}
private void GetSHJCallRecold()
{
try
{
IBAS_PARAMETER_Q BAS_PARAMETER_BL = new BAS_PARAMETER_BL();
var deptcode = BAS_PARAMETER_BL.GetModel_Patameter("Sys_Environment_DeptCode").PARAVALUE;
bool isNJ = deptcode == Sys_Environment_DeptCode.NJDM01.ToString();
LogHelper.Info("isNJ:" + isNJ);
string shjapi = Utility.GetSettingByKey("shj");
string url = shjapi + "?action=getmsg&count=" + Utility.GetSettingByKey("shjcount");
var rst = Utility.PostData(url, Encoding.Default);
//var rst = "{\"result\":\"1\",\"data\":{\"total\":16,\"msg\":[{\"Event\":\"Cdr\",\"Privilege\":\"cdr,all\",\"AccountCode\":\"\",\"Source\":\"8015\",\"Destination\":\"15011893348\",\"DestinationContext\":\"from-internal\",\"CallerID\":\"6002\",\"Channel\":\"SIP8015-00000105\",\"DestinationChannel\":\"SIPsip6-00000106\",\"LastApplication\":\"Dial\",\"LastData\":\"SIPsip615011893348,300,tTwW\",\"StartTime\":\"2015-05-11 08:48:55\",\"AnswerTime\":\"2015-05-11 08:48:55\",\"EndTime\":\"2015-05-11 08:49:13\",\"Duration\":\"18\",\"BillableSeconds\":0,\"Disposition\":\"NO ANSWER\",\"AMAFlags\":\"DOCUMENTATION\",\"UniqueID\":\"1431305335.3456\",\"UserField\":\"20150511-084855-8015-15011893348-1431305335.3456.WAV\",\"CallType\":\"OUT\",\"Server\":\"localhost\",\"CID\":\"83670688\",\"Hangup\":\"Caller\"}]},\"error\":0}";
// var rst = "{\"result\":\"1\",\"data\":{\"total\":0,\"msg\":null},\"error\":0}";
try
{
AddRecord(rst, isNJ);
}
catch (Exception ex)//转换失败
{
LogHelper.Error("深海捷数据处理:" + ex);
try
{
string filepath = FileUnit.GetBaseDirectory() + "/ShjCtiCallRecord/";
FileUnit.WriteWithDirectory(filepath, "", rst);
}
catch (Exception ex2)
{
LogHelper.Info("深海捷文件保存:" + ex2 + rst);
}
}
}
catch (Exception e)//获取远程录音数据失败
{
WX.CRM.Common.LogHelper.Error("深海捷接口数据抓取: " + e);
}
}
private void DisposeErrorRecord()
{
string directorypath = FileUnit.GetBaseDirectory() + "/ShjCtiCallRecord/";
List<string> listPath = FileUnit.GetAllFiles(directorypath);
foreach (string path in listPath)
{
string rst = "";
try
{
rst = FileUnit.Read(path);
var deptcode = new BAS_PARAMETER_BL().GetModel_Patameter("Sys_Environment_DeptCode").PARAVALUE;
bool isNJ = deptcode == Sys_Environment_DeptCode.NJDM01.ToString();
AddRecord(rst, isNJ);
FileUnit.Delete(path);
}
catch (Exception ex)//转换失败
{
LogHelper.Error("处理深海捷错误录音文件:" + path + ex);
}
}
}
private void DeleteTwoMonthFile()
{
string directorypath = FileUnit.GetBaseDirectory() + "/ShjCtiOriginal/";
List<string> listPath = FileUnit.GetAllDirectory(directorypath);
int deletetime = Convert.ToInt32(string.Format("{0:yyMMdd}", DateTime.Now.AddDays(-60)));
List<string> _listPath = new List<string>();
foreach (string path in listPath)
{
string pathtime = path.Substring(path.LastIndexOf("/") + 1);
if (Convert.ToInt32(pathtime) < deletetime)
{
_listPath.Add(path);
}
}
FileUnit.DeleteDirectory(_listPath);
}
public void AddRecord(string rst, bool isNJ)
{
SaveOriginalValue(rst);//保存原始数据
shjcdrdto dto = new shjcdrdto();
dto = dto.getDto(rst);
RecordData recordData = new RecordData(dto);
List<CSVR_CALLRECORD> callRecordList = recordData.getCallRecordList();
List<CSVR_TODAYRECORD> todayRecordList = recordData.getTodayRecordList();
CSVR_CALLRECORD_BL callrecord = new CSVR_CALLRECORD_BL();
CSVR_TODAYRECORD_BL todayrecord = new CSVR_TODAYRECORD_BL();
if (isNJ)
{
var loginloglist = new BAS_LOGINLOG_BL().GetTodayLoginLogLst();
if (null != loginloglist)
{
foreach (var item in callRecordList)
{
var loginlog = loginloglist.Where(obj => obj.TELNUM == item.SALESEID);
if (null != loginlog && loginlog.Count() > 0)
{
item.SALESEID = loginlog.OrderByDescending(obj => obj.LOGINTIME).FirstOrDefault().LOGINEID;
}
}
foreach (var item in todayRecordList)
{
var loginlog = loginloglist.Where(obj => obj.TELNUM == item.SALESEID);
if (null != loginlog && loginlog.Count() > 0)
{
item.SALESEID = loginlog.OrderByDescending(obj => obj.LOGINTIME).FirstOrDefault().LOGINEID;
}
}
}
}
new CreateRecord().AddRecordList(callRecordList);
// callrecord.AddListRecord(callRecordList);
todayrecord.AddListRecord(todayRecordList);
}
private void SaveOriginalValue(string rst)
{
//shjcdrdto _dto = new shjcdrdto();
//_dto = _dto.getDto(rst);
//if (_dto != null && _dto.data != null)
//{
// if (_dto.data.msg != null && _dto.data.msg.Count > 0)
// {
// var cdrlist = _dto.data.msg.Where(obj => obj.Event == "Cdr");
// foreach (var model in cdrlist)
// {
// model.Source = (!string.IsNullOrEmpty(model.Source) && model.Source.Length > 4) ? model.Source.Substring(model.Source.Length - 4) : model.Source;
// model.Destination = (!string.IsNullOrEmpty(model.Destination) && model.Destination.Length > 4) ? model.Destination.Substring(model.Destination.Length - 4) : model.Destination;
// }
// if (cdrlist != null && cdrlist.Count() > 0)
// {
// string saveDTO = Utility.ObjectToJson<shjcdrdto>(_dto);
// //保存原始数据
// string saveDTOpath = FileUnit.GetBaseDirectory() + "/ShjCtiOriginal/" + string.Format("{0:yyMMdd}", DateTime.Now) + "/";
// FileUnit.WriteWithDirectory(saveDTOpath, "", saveDTO);
// }
// }
//}
string saveDTOpath = FileUnit.GetBaseDirectory() + "/ShjCtiOriginal/" + string.Format("{0:yyMMdd}", DateTime.Now) + "/";
FileUnit.WriteWithDirectory(saveDTOpath, "", rst);
}
}
}