using WX.CRM.BLL.Csvr; using WX.CRM.Common; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using WX.CRM.BLL.Base; using System.Text.RegularExpressions; using WX.CRM.BLL.Res; using WX.CRM.Model.Entity; using System.Xml.Serialization; using System.IO; using WX.CRM.CRMServices.ServicesModel; using WX.CRM.CRMServices.SqlHelper; namespace WX.CRM.CRMServices.PkgSms { public class DowCallRecold { #region 录音 /// /// 录音抓取 /// public void DowData() { GetCallRecold(); } private void GetCallRecold() { CSVR_CALLRECORD_BL callrecord = new CSVR_CALLRECORD_BL(); CSVR_TODAYRECORD_BL rodayrecord = new CSVR_TODAYRECORD_BL(); decimal? recordId = callrecord.GetLastCallRecord(); DataSet ds = new CallRecord().GetCallRecord(recordId); if (ds != null && ds.Tables[0].Rows.Count > 0) { List lists = new List(); List todaylists = new List(); // SEQUENCES_BL pkid = new SEQUENCES_BL(); DateTime todayDate = DateTime.Today; List resIdAndNumber = new List(); foreach (DataRow row in ds.Tables[0].Rows) { string _number = (row["Number"] ?? "").ToString(); if (_number.Length >= 5) { string number = NumberSub(_number); string resId = ResUtil.CreateResId(number); resIdAndNumber.Add(new ResIdAndPhone() { ResId = resId, Number = number }); decimal _second = 0, _calleype = -1, _userid = 0; DateTime _begintime = DateTime.MinValue; decimal.TryParse((row["FileLength"] ?? "").ToString(), out _second); decimal.TryParse((row["CallType"] ?? "").ToString(), out _calleype); decimal.TryParse((row["EmployeeID"] ?? "").ToString(), out _userid); DateTime.TryParse((row["CreateTime"] ?? "").ToString(), out _begintime); WX.CRM.Model.Entity.CSVR_CALLRECORD model = new WX.CRM.Model.Entity.CSVR_CALLRECORD(); // model.PKID = pkid.Seq_base_get(); model.RECORDID = row["RecordId"] == null ? (decimal?)null : Convert.ToDecimal(row["RecordId"]); model.SERVERID = (row["ServerID"] ?? "").ToString(); model.FILENAME = (row["FileName"] ?? "").ToString(); model.RESID = resId; model.SERVICENUMBER = (row["ExtensionNumber"] ?? "").ToString(); model.TELNUMBERLAST4 = number.Length > 4 ? number.Substring(number.Length - 4) : number; model.TIMELENGTH = _second; model.CALLTYPE = _calleype; model.SALESEID = _userid; model.TIMESTART = _begintime; model.TIMEEND = _begintime.AddSeconds(Convert.ToDouble(_second)); model.CTIME = DateTime.Now; lists.Add(model); WX.CRM.Model.Entity.CSVR_TODAYRECORD todaymodel = new WX.CRM.Model.Entity.CSVR_TODAYRECORD(); // todaymodel.PKID = pkid.Seq_base_get(); todaymodel.RECORDID = model.RECORDID; todaymodel.SERVERID = model.SERVERID; todaymodel.FILENAME = model.FILENAME; todaymodel.RESID = model.RESID; todaymodel.SERVICENUMBER = model.SERVICENUMBER; todaymodel.TELNUMBERLAST4 = model.TELNUMBERLAST4; todaymodel.TIMELENGTH = model.TIMELENGTH; todaymodel.CALLTYPE = model.CALLTYPE; todaymodel.SALESEID = model.SALESEID; todaymodel.TIMESTART = model.TIMESTART; todaymodel.TIMEEND = model.TIMEEND; todaymodel.CTIME = DateTime.Now; todaylists.Add(todaymodel); } } //没注册的号码加入注册 try { if (resIdAndNumber.Count > 0) { var reg = new RegPhone(resIdAndNumber); reg.RegisterList(); } } catch (Exception ex) { LogHelper.Error("CallRecord注册号码:" + ex.ToString()); } if (lists.Count > 0) { new CreateRecord().AddRecordList(lists); // callrecord.AddListRecord(lists); } if (todaylists.Count > 0) { rodayrecord.AddListRecord(todaylists); } } } #endregion #region Level2录音 public void DowLevel2Record() { Level2CallRecord(); } private void Level2CallRecord() { CSVR_CALLRECORD_BL callrecord = new CSVR_CALLRECORD_BL(); CSVR_TODAYRECORD_BL rodayrecord = new CSVR_TODAYRECORD_BL(); CallRecord callRecord = new CallRecord(); DateTime timestart = callrecord.GetLastStartTime(); timestart = timestart.AddHours(-2); //ulong coidInt = Convert.ToUInt64(coid); string serverId = ""; var Server = callRecord.GetServerID(); if (Server != null && Server.Tables[0] != null && Server.Tables[0].Rows.Count > 0) serverId = Server.Tables[0].Rows[0]["configvalue"].ToString(); List existRecord = callrecord.getCallRecordByTimestart(timestart); DataSet ds = callRecord.GetLevel2CallRecord(timestart); if (ds != null && ds.Tables[0].Rows.Count > 0) { List lists = new List(); List todaylists = new List(); //SEQUENCES_BL pkid = new SEQUENCES_BL(); DateTime todayDate = DateTime.Today; List resIdAndNumber = new List(); foreach (DataRow row in ds.Tables[0].Rows) { try { string _number = (row["number"] ?? "").ToString(); if (_number.Length >= 5) { string number = NumberSub(_number); string resId = ResUtil.CreateResId(number); resIdAndNumber.Add(new ResIdAndPhone() { ResId = resId, Number = number }); decimal _second = 0, _calleype = -1, _userid = 0; DateTime _begintime = DateTime.MinValue; decimal.TryParse((row["second"] ?? "").ToString(), out _second); decimal.TryParse((row["calltype"] ?? "").ToString(), out _calleype); decimal.TryParse((row["userid"] ?? "").ToString(), out _userid); DateTime.TryParse((row["begintime"] ?? "").ToString(), out _begintime); WX.CRM.Model.Entity.CSVR_CALLRECORD model = new WX.CRM.Model.Entity.CSVR_CALLRECORD(); // model.PKID = pkid.Seq_base_get(); model.RECORDID = model.PKID; model.COID = (row["agentsessionid"] ?? "").ToString(); model.SERVERID = serverId; model.FILENAME = (row["recordfile"] ?? "").ToString(); model.RESID = resId; model.SERVICENUMBER = ""; model.TELNUMBERLAST4 = number.Length > 4 ? number.Substring(number.Length - 4) : number; model.TIMELENGTH = _second; model.CALLTYPE = _calleype; model.SALESEID = _userid; model.TIMESTART = _begintime; model.TIMEEND = _begintime.AddSeconds(Convert.ToDouble(_second)); model.CTIME = DateTime.Now; lists.Add(model); } } catch (Exception ex) { LogHelper.Error("录音抓取错误:" + (row["agentsessionid"] ?? "").ToString()); throw ex; } } //没注册的号码加入注册 try { if (resIdAndNumber.Count > 0) { var reg = new RegPhone(resIdAndNumber); reg.RegisterList(); } } catch (Exception ex) { LogHelper.Error("level2CallRecord注册号码:" + ex.ToString()); } if (lists.Count > 0) { string[] coids = existRecord.Select(p => p.COID).ToArray(); lists = lists.Where(p => !coids.Contains(p.COID)).ToList(); if (lists.Count > 0) { new CreateRecord().AddRecordList(lists); //callrecord.AddListRecord(lists); } // var _todayList = lists.Where(p => p.TIMESTART > todayDate); foreach (var model in lists) { WX.CRM.Model.Entity.CSVR_TODAYRECORD todaymodel = new WX.CRM.Model.Entity.CSVR_TODAYRECORD(); //todaymodel.PKID = pkid.Seq_base_get(); todaymodel.RECORDID = todaymodel.PKID; todaymodel.COID = model.COID; todaymodel.SERVERID = model.SERVERID; todaymodel.FILENAME = model.FILENAME; todaymodel.RESID = model.RESID; todaymodel.SERVICENUMBER = model.SERVICENUMBER; todaymodel.TELNUMBERLAST4 = model.TELNUMBERLAST4; todaymodel.TIMELENGTH = model.TIMELENGTH; todaymodel.CALLTYPE = model.CALLTYPE; todaymodel.SALESEID = model.SALESEID; todaymodel.TIMESTART = model.TIMESTART; todaymodel.TIMEEND = model.TIMEEND; todaymodel.CTIME = DateTime.Now; todaylists.Add(todaymodel); } if (todaylists.Count > 0) { rodayrecord.AddListRecord(todaylists); } } } } #endregion 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; } } } }