using WX.CRM.BLL.Base; using WX.CRM.BLL.Csvr; using WX.CRM.BLL.Ord; using WX.CRM.Common; using WX.CRM.Model.Entity; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Web; namespace WX.CRM.CRMServices.PkgSms { public class HGRecordDownload { public void HGSetRecord() { int hg_count = 0, nofile_count = 0, nodown_count = 0; ORD_HEGUIMEMO_BL heguiMemo = new ORD_HEGUIMEMO_BL(); CSVR_CALLRECORD_BL callrecord = new CSVR_CALLRECORD_BL(); ORD_SERVICEMEMO_BL servicMemo = new ORD_SERVICEMEMO_BL(); BAS_PARAMETER_BL paramerter = new BAS_PARAMETER_BL(); decimal memosubtypeid = Convert.ToDecimal(paramerter.GetModel_Patameter("HGMeMoSubTypeId").PARAVALUE); decimal lastMemo = heguiMemo.getLastMemoid(memosubtypeid); List list = servicMemo.GetHgServiceMemo(lastMemo, memosubtypeid); hg_count = list.Count(); List listHgMemo = new List(); foreach (ORD_SERVICEMEMO model in list) { ORD_HEGUIMEMO hgMemo = this.setHeguiMemo(model); CSVR_TODAYRECORD record = callrecord.GetNewestCallRecord(model.RESID, model.INNERUSERID.Value, model.CTIME.Value); if (null == record) { nofile_count++; hgMemo.ISDOWNED = -1; } else { hgMemo.FILENAME = record.FILENAME; bool isDownLoad = this.download(record.FILENAME, record.SERVERID); if (!isDownLoad) { hgMemo.ISDOWNED = 0; nodown_count++; } else { hgMemo.ISDOWNED = 1; } } //LogHelper.Error(hg_count + "合规"); listHgMemo.Add(hgMemo); } heguiMemo.CreateListMemo(listHgMemo); string msg = Utility.GetSettingByKey("UpReportCode") + ",合规工单数量:" + hg_count + ";未找到录音:" + nofile_count + ";下载不成功:" + nodown_count + ";" + DateTime.Now.ToString(); sendEmail(msg); } private void sendEmail(string emailMsg) { string title = "合规工单录音下载"; string smtpserver = Utility.GetSettingByKey("smtpserver"); string[] email_server = smtpserver.Split('#'); string sendto = Utility.GetSettingByKey("receiveEmail"); string[] receiveEmail = sendto.Split(','); foreach (string strTo in receiveEmail) { EMail.Send(email_server[0], email_server[1], email_server[2], email_server[3], email_server[4], strTo, title, emailMsg); } } private bool download(string file, string serverID) { string cti = Utility.GetSettingByKey("CTI"); string server = string.Empty; try { if (cti == "shj") { server = Utility.GetSettingByKey("SHJREC"); } else { server = Utility.GetSettingByKey(serverID.ToUpper()); if (null == server) { LogHelper.Error("CallRecord.GetCallFile错误,录音服务器:" + server + "不存在"); return false; } } string _localurl = "HQRecordFile//" + DateTime.Now.ToString("yyyyMMdd") + "//"; string localurl = FileUnit.GetBaseDirectory() + _localurl + file; string remoteUri = server + file; string d = localurl.Substring(0, localurl.LastIndexOf("\\", System.StringComparison.Ordinal)); if (!Directory.Exists(d)) { Directory.CreateDirectory(d); } Uri downUri = new Uri(remoteUri); HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(downUri); using (Stream inputStream = hwr.GetResponse().GetResponseStream()) { using (FileStream flieStream = new FileStream(localurl, FileMode.Create)) { inputStream.CopyTo(flieStream); } } return true; } catch (Exception ex) { LogHelper.Error(ex); return false; } } private ORD_HEGUIMEMO setHeguiMemo(ORD_SERVICEMEMO model) { ORD_HEGUIMEMO Memo = new ORD_HEGUIMEMO(); Memo.MEMOID = model.MEMOID; Memo.INNERUSERID = model.INNERUSERID; Memo.MEMOCONTENTID = model.MEMOCONTENTID; Memo.RESID = model.RESID; Memo.MEMOSTYLEID = model.MEMOSTYLEID; Memo.MEMOTYPEID = model.MEMOTYPEID; Memo.MEMOSUBTYPEID = model.MEMOSUBTYPEID; Memo.BUSINESSID = model.BUSINESSID; Memo.CTIME = model.CTIME; Memo.CALLTIME = model.CALLTIME; Memo.CALLTIMEEND = model.CALLTIMEEND; Memo.ISCHECKED = model.ISCHECKED; return Memo; } } }