using Quartz; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Runtime.Caching; using WX.CRM.BLL.Csvr; using WX.CRM.BLL.IPSC; using WX.CRM.Model.Entity; namespace WX.CRM.CRMServices.CRMJobs { /// /// 获取L2满意度数据 /// public class GetIvrSatisfaction : IJob { static bool isRuning = false; public void Execute(JobExecutionContext context) { if (isRuning) return; isRuning = true; try { DateTime dt = GetLstInsertionTime(); var data = new IPSC_BL().SetCallRecordSatisfaction(dt); List details = new List(); foreach (DataRow item in data.Tables[0].Rows) { details.Add(new CSVR_CALLSTATISDETAIL() { PKID = item["id"].ToString(), SALESEID = Convert.ToDecimal(item["agent"]), INSERTTIME = Convert.ToDateTime(item["inserttime"]), SATISFACTION = Convert.ToDecimal(item["satisfaction"]), SESSIONID = item["sessionid"].ToString() }); } new CSVR_CALLSTATIS_BL().AddDetails(details); if (details.Count > 0) { SetLstInsertionTime(details.Max(item => item.INSERTTIME));//设置最近一次的最大时间 } } catch (Exception e) { WX.CRM.Common.LogHelper.Error(e); } finally { isRuning = false; } } protected void SetLstInsertionTime(DateTime dt) { string cacheKey = "WX.CRM.CRMServices.CRMJobs.GetIvrSatisfaction.LstInsertionTime"; ObjectCache cache = MemoryCache.Default; CacheItemPolicy policy = new CacheItemPolicy(); policy.SlidingExpiration = TimeSpan.FromMinutes(60); cache.Set(cacheKey, dt, policy); } protected DateTime GetLstInsertionTime() { string cacheKey = "WX.CRM.CRMServices.CRMJobs.GetIvrSatisfaction.LstInsertionTime"; ObjectCache cache = MemoryCache.Default; DateTime lsttime = DateTime.Parse("2000-01-01"); if (cache[cacheKey] != null) { lsttime = (DateTime)cache[cacheKey]; } else { lsttime = new CSVR_CALLSTATIS_BL().GetLstInsertionTime(); CacheItemPolicy policy = new CacheItemPolicy(); policy.SlidingExpiration = TimeSpan.FromMinutes(60); cache.Set(cacheKey, lsttime, policy); } return lsttime; } } }