using Dapper; using NetCore.Model.crm; 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_message_bll { private List _messages { get; set; } private List _groupmessages { get; set; } private string comcode; public hg_message_bll(string _comcode) { _messages = new List(); _groupmessages = new List(); comcode = _comcode; } public void Clear() { _messages = new List(); _groupmessages = new List(); } public void StartInsert() { using (IDbConnection wxcon = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode)) { using (IDbConnection targtcon = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode)) { using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode, false)) { foreach (var model in _messages) { try { var hhuser_eid = wxcon.QueryFirstOrDefault(@"select a.eid,x.uname from ww_hhuser_eid a join bas_inneruser x on a.eid = x.eid where a.userid =:userid and a.corpid =:corpid ", new { userid = model.fromer, corpid = model.corpid }); hg_message getmodel = targtcon.QueryFirstOrDefault("select seq,msgid from hg_message where msgid=@msgid", new { model.msgid }); string kefuinfo = con.QueryFirstOrDefault("select uname from ww_hhuser where userid=@userid and corpid=@corpid", new { userid = model.fromer, model.corpid }); string customer = con.QueryFirstOrDefault("select name from ww_extuser where userid=@userid and corpid=@corpid", new { userid = model.tolist, model.corpid }); model.kehuname = kefuinfo; model.cusname = customer; if (hhuser_eid != null) { model.eid = hhuser_eid.eid; model.eidname = hhuser_eid.uname; } if (getmodel == null || string.IsNullOrEmpty(getmodel.msgid))//无数据,需要插入数据 { //无数据 targtcon.Execute("insert into hg_message(seq,msgid,msgtype,action,fromer,tolist,roomid,ext,content,nfile,msgtime,ctime,hgstatus,hgtime,issend,kehuname,cusname,corpid,word,voiceUrl,checkdate,eid,eidname)" + "values(@seq,@msgid,@msgtype,@action,@fromer,@tolist,@roomid,@ext,@content,@nfile,@msgtime,@ctime,@hgstatus,@hgtime,@issend,@kehuname,@cusname,@corpid,@word,@voiceUrl,@checkdate,@eid,@eidname)", model); } } catch (Exception e) { Console.WriteLine("普通合规消息入库失败:" + JsonConvert.SerializeObject(model)); throw e; } } foreach (var model in _groupmessages) { try { hg_message getmodel = targtcon.QueryFirstOrDefault("select seq,msgid from hg_message_group where msgid=@msgid", new { model.msgid }); if (getmodel == null || string.IsNullOrEmpty(getmodel.msgid))//无数据,需要插入数据 { //无数据 targtcon.Execute("insert into hg_message_group(seq,msgid,msgtype,action,fromer,tolist,roomid,ext,content,nfile,msgtime,hgstatus,hgtime)" + "values(@seq,@msgid,@msgtype,@action,@fromer,@tolist,@roomid,@ext,@content,@nfile,@msgtime,@hgstatus,@hgtime)", model); } } catch (Exception e) { Console.WriteLine("群合规消息入库失败:" + JsonConvert.SerializeObject(model)); throw e; } } } } } } /// /// 新增数据 /// /// /// public bool Add(hg_message model) { _messages.Add(model); return true; //bool result = false; //try //{ // using (IDbConnection con = ConnectionFactory.CreateConnection()) // { // hg_message getmodel = con.QueryFirstOrDefault("select seq,msgid from hg_message where msgid=@msgid", new { model.msgid }); // string kefuinfo = con.QueryFirstOrDefault("select uname from ww_hhuser where userid=@userid and corpid=@corpid", new { userid = model.fromer, model.corpid }); // string customer = con.QueryFirstOrDefault("select name from ww_extuser where userid=@userid and corpid=@corpid", new { userid = model.tolist, model.corpid }); // model.kehuname = kefuinfo; // model.cusname = customer; // if (getmodel == null || string.IsNullOrEmpty(getmodel.msgid))//无数据,需要插入数据 // { // //无数据 // result = con.Execute("insert into hg_message(seq,msgid,msgtype,action,fromer,tolist,roomid,ext,content,nfile,msgtime,hgstatus,hgtime,issend,kehuname,cusname,corpid)" + // "values(@seq,@msgid,@msgtype,@action,@fromer,@tolist,@roomid,@ext,@content,@nfile,@msgtime,@hgstatus,@hgtime,@issend,@kehuname,@cusname,@corpid)", model) > 0; // } // } //} //catch (Exception e) //{ // Console.WriteLine("错误消息:" + JsonConvert.SerializeObject(model)); // throw e; //} //return result; } /// /// 新增群消息 /// /// /// public bool AddGroupMsg(hg_message model) { _groupmessages.Add(model); return true; //bool result = false; //using (IDbConnection con = ConnectionFactory.CreateConnection()) //{ // hg_message getmodel = con.QueryFirstOrDefault("select seq,msgid from hg_message_group where msgid=@msgid", new { model.msgid }); // if (getmodel == null || string.IsNullOrEmpty(getmodel.msgid))//无数据,需要插入数据 // { // //无数据 // result = con.Execute("insert into hg_message_group(seq,msgid,msgtype,action,fromer,tolist,roomid,ext,content,nfile,msgtime,hgstatus,hgtime)" + // "values(@seq,@msgid,@msgtype,@action,@fromer,@tolist,@roomid,@ext,@content,@nfile,@msgtime,@hgstatus,@hgtime)", model) > 0; // } // return result; //} } /// /// check时间的合规数据 /// /// /// public List GetHgMessage(DateTime time) { using (IDbConnection targtcon = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode)) { return targtcon.Query("select * from hg_message where checkdate=@checkdate", new { checkdate = time }).ToList(); } } } }