TG.WXCRM.V4/NetCore.BLL/wx/wx_hg_message_bll.cs

126 lines
5.2 KiB
C#

using Dapper;
using NetCore.Model.enums;
using NetCore.Model.wx;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace NetCore.BLL.wx
{
public class wx_hg_message_bll
{
private List<hg_wx_message> _messages { get; set; }
private List<hg_wx_message> _groupmessages { get; set; }
private string comcode;
public wx_hg_message_bll(string _comcode)
{
_messages = new List<hg_wx_message>();
_groupmessages = new List<hg_wx_message>();
comcode = _comcode;
}
public void Clear()
{
_messages = new List<hg_wx_message>();
_groupmessages = new List<hg_wx_message>();
}
public void StartInsert()
{
using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.wxContext, comcode))
{
foreach (var model in _messages)
{
try
{
hg_wx_message getmodel = con.QueryFirstOrDefault<hg_wx_message>("select msgsvrid from hg_message where msgsvrid=@msgsvrid", new { model.msgsvrid });
if (getmodel == null || string.IsNullOrEmpty(getmodel.msgsvrid))//无数据,需要插入数据
{
wx_work work = GetKeFuName(model.username);
if (work != null)
{
model.kefuname = work.nickname;
model.eid = work.eid;
model.eidname = work.uname;
}
con.Execute(@"INSERT INTO hg_message
(pkid, msgsvrid, msgtype, issend, talker, username, nickname, msgcontent, imgpath, voiceUrl, ctime, hgstatus, kefuname, word, eid,checkdate,eidname) VALUES
(@pkid, @msgsvrid, @msgtype, @issend, @talker, @username, @nickname, @msgcontent, @imgpath, @voiceUrl, getdate(), 0, @kefuname, @word, @eid,@checkdate,@eidname)", model);
}
}
catch (Exception e)
{
Console.WriteLine("普通合规消息入库失败:" + JsonConvert.SerializeObject(model));
throw e;
}
}
}
}
public wx_work GetKeFuName(string jobusername)
{
using (IDbConnection con = ConnectionFactory.CreateConnection(ContextType.crmContext, comcode))
{
return con.QueryFirstOrDefault<wx_work>(@"
select t.nickname, a.eid,a.uname from wx_workaccount t
join bas_inneruser a on t.inneruserid = a.pkid
where t.username = :jobusername ", new { jobusername });
}
}
/// <summary>
/// 新增数据
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool Add(hg_wx_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>
/// check时间的合规数据
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public List<hg_wx_message> GetHgMessage(DateTime time)
{
using (IDbConnection targtcon = ConnectionFactory.CreateConnection(ContextType.wxContext, comcode))
{
return targtcon.Query<hg_wx_message>("select * from hg_message where checkdate=@checkdate", new { checkdate = time }).ToList();
}
}
}
}