using Dapper; using NetCore.Common; using NetCore.Model.enums; using NetCore.Model.qw; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Linq; namespace NetCore.BLL { public class hg_ordervoice_bll { private List _ordrvoic { get; set; } private string comcode; public hg_ordervoice_bll(string _comcode) { _ordrvoic = new List(); comcode = _comcode; } public void Clear() { _ordrvoic = new List(); } /// /// 新增数据 /// /// /// public bool Add(hg_ordervoice model) { _ordrvoic.Add(model); return true; } public void StartInsert() { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode)) { foreach (var model in _ordrvoic) { try { hg_ordervoice getmodel = con.QueryFirstOrDefault("select corpid,seq,msgid from hg_ordervoice where msgid=@msgid", new { model.msgid }); if (getmodel == null || string.IsNullOrEmpty(getmodel.msgid))//无数据,需要插入数据 { //无数据 con.Execute("insert into hg_ordervoice(corpid,tablename,seq,msgid,msgtype,md5sum,nfile,checkdate,ctime,msgctime,voiceUrl,fromer,tolist)" + "values(@corpid,@tablename,@seq,@msgid,@msgtype,@md5sum,@nfile,@checkdate,now(),@msgctime,@voiceUrl,@fromer,@tolist)", model); } } catch (Exception e) { Console.WriteLine("普通合规消息入库失败:" + JsonConvert.SerializeObject(model)); throw e; } } } } /// /// 获取需要翻译的数据 /// /// public List GetNeedTransList(int clearcount) { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode)) { string sql = string.Format(@"select * from hg_ordervoice b where transstatus=0 and ctime>@mintime and msgctime(sql, new { mintime = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") }, buffered: false).ToList(); } } /// /// 获取需要翻译的数据 /// /// public List GetNeedHegList(int clearcount) { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode)) { string sql = string.Format(@"select * from hg_ordervoice b where transstatus=1 and ishg=0 order by seq asc limit {0}", clearcount); return con.Query(sql, new { mintime = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") }, buffered: false).ToList(); } } public void UpdateHgStatus(List ids) { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode)) { foreach (var item in ids) { con.Execute("update hg_ordervoice set ishg=1,hgtime=now() where id=@id ", new { id = item }); } } } /// /// 调用了翻译 /// /// /// /// public bool ToTrans(int id, int transstatus) { bool result = true; try { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode)) { string sql = string.Format(@"update hg_ordervoice set transstatus=@transstatus,transtime=now() 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.qwContext, comcode)) { string sql = string.Format(@"update hg_ordervoice set transstatus=@transstatus,transtime=now(),transcontent=@transcontent where id=@id");//过滤掉,只执行订单客服消息 con.Execute(sql, new { transstatus = transstatus, transcontent = transcontent, id = id }); } } catch (Exception e) { LogHelper.Error(e.ToString()); result = false; } return result; } } }