using Dapper; using NetCore.Common; using NetCore.Model.crm; using NetCore.Model.enums; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Linq; namespace NetCore.BLL { public class crm_callrecord_bll { /// /// 获取数据源 /// /// /// /// /// /// /// public List GetList(int clearcount, decimal seq, DateTime checkdate) { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode)) { string sql = string.Format(@"select * from (select pkid,filename,servicenumber,saleseid,timestart,resid,timelength from csvr_callrecord t where t.timestart>:checkdate and t.timestart<:checkdateNext and t.pkid>:seq and exists (select 1 from hg_orderresid a where a.resid=t.resid) ) where rownum<={0} ", clearcount);//过滤掉,只执行订单客服消息 return con.Query(sql, new { seq, checkdate, checkdateNext = checkdate.AddDays(1) }, buffered: false).ToList(); } } private List _ordrecord { get; set; } private string comcode { get; set; } public crm_callrecord_bll(string _comcode) { comcode = _comcode; _ordrecord = new List(); } public void Clear() { _ordrecord = new List(); } /// /// 新增数据 /// /// /// public bool Add(hg_order_record model) { _ordrecord.Add(model); return true; } public void StartInsert() { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode)) { foreach (var model in _ordrecord) { try { hg_order_record getmodel = con.QueryFirstOrDefault("select pkid,filename from HG_ORDER_RECORD where pkid=:pkid", new { model.pkid }); if (getmodel == null || string.IsNullOrEmpty(getmodel.filename))//无数据,需要插入数据 { //无数据 con.Execute(@"insert into hg_order_record (id, pkid, checkdate, ctime, transstatus, ishg, voiceurl, resid, saleseid, filename,timelength) values (pack_base.Seq_smallid_get,:pkid,:checkdate,sysdate, 0, 0,:voiceurl,:resid,:saleseid,:filename,:timelength)", model); } } catch (Exception e) { Console.WriteLine("普通合规消息入库失败:" + JsonConvert.SerializeObject(model)); throw e; } } } } /// /// 获取需要翻译的数据 /// /// public List GetNeedTransList(int clearcount) { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode)) { string sql = string.Format(@"select * from (select * from hg_order_record b where transstatus=0 and ctime>:mintime order by pkid asc)where rownum<={0}", clearcount); return con.Query(sql, new { mintime = Convert.ToDateTime(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")) }, buffered: false).ToList(); } } /// /// 获取需要翻译的数据 /// /// public List GetNeedHegList(int clearcount) { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode)) { string sql = string.Format(@"select * from(select * from hg_order_record b where transstatus=1 and ishg=0 order by pkid asc)where rownum<={0}", clearcount); return con.Query(sql, buffered: false).ToList(); } } public void UpdateHgStatus(List ids) { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode)) { foreach (var item in ids) { con.Execute("update hg_order_record set ishg=1,hgtime=sysdate where id=:id", new { id = item }); } } } /// /// 调用了翻译 /// /// /// /// public bool ToTrans(int id, int transstatus) { bool result = true; try { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode)) { string sql = string.Format(@"update hg_order_record set transstatus=:transstatus,transtime=sysdate where id=:id");//过滤掉,只执行订单客服消息 con.Execute(sql, new { transstatus = transstatus, id = id }); } } catch (Exception e) { LogHelper.Error(e.ToString()); result = false; } return result; } /// /// 翻译数据 /// /// /// /// public bool TransBack(string transcontent, int id, int transstatus) { bool result = true; try { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode)) { DynamicParameters dp = new DynamicParameters(); dp.Add(":transstatus", transstatus); dp.Add(":transcontent", transcontent); dp.Add(":id", id); string sql = string.Format(@"update hg_order_record set transstatus=:transstatus,transtime=sysdate,transcontent=:transcontent where id=:id");//过滤掉,只执行订单客服消息 con.Execute(sql, dp); } } catch (Exception e) { LogHelper.Error(e.ToString()); result = false; } return result; } } }