ComplianceServer/oldcode/NetCore.BLL/qw/hg_message_bll.cs

167 lines
8.3 KiB
C#

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<hg_message> _messages { get; set; }
private List<hg_message> _groupmessages { get; set; }
private string comcode;
public hg_message_bll(string _comcode)
{
_messages = new List<hg_message>();
_groupmessages = new List<hg_message>();
comcode = _comcode;
}
public void Clear()
{
_messages = new List<hg_message>();
_groupmessages = new List<hg_message>();
}
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<ww_hhuser_eid>(@"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<hg_message>("select seq,msgid from hg_message where msgid=@msgid", new { model.msgid });
string kefuinfo = con.QueryFirstOrDefault<string>("select uname from ww_hhuser where userid=@userid and corpid=@corpid", new { userid = model.fromer, model.corpid });
string customer = con.QueryFirstOrDefault<string>("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<hg_message>("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;
}
}
}
}
}
}
/// <summary>
/// 新增数据
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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<hg_message>("select seq,msgid from hg_message where msgid=@msgid", new { model.msgid });
// string kefuinfo = con.QueryFirstOrDefault<string>("select uname from ww_hhuser where userid=@userid and corpid=@corpid", new { userid = model.fromer, model.corpid });
// string customer = con.QueryFirstOrDefault<string>("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;
}
/// <summary>
/// 新增群消息
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool AddGroupMsg(hg_message model)
{
_groupmessages.Add(model);
return true;
//bool result = false;
//using (IDbConnection con = ConnectionFactory.CreateConnection())
//{
// hg_message getmodel = con.QueryFirstOrDefault<hg_message>("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;
//}
}
/// <summary>
/// check时间的合规数据
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public List<hg_message> GetHgMessage(DateTime time)
{
using (IDbConnection targtcon = ConnectionFactory.CreateConnection(ContextType.qwContext, comcode))
{
return targtcon.Query<hg_message>("select * from hg_message where checkdate=@checkdate", new { checkdate = time }).ToList();
}
}
}
}