using NetCore.BLL; using NetCore.BLL.crm; using NetCore.BLL.qw; using NetCore.BLL.wx; using NetCore.Common; using NetCore.Model; using NetCore.Model.crm; using NetCore.Model.enums; using NetCore.Model.qw; using System; using System.Collections.Generic; using System.Threading; namespace NetCore.Service { /// /// 推送类 /// public class PushThread { /// /// 随机数 /// public string matchstr { get; set; } public string keyName { get; set; } public Dictionary dic; public string threadKey { get; set; } /// /// 企业编号 /// public string comcode { get; set; } public void execute() { while (true) { try { dic = new Dictionary(); bas_config_bll _config_bll = new bas_config_bll(comcode); bas_pushcmd_bll _pushcmd_bll = new bas_pushcmd_bll(comcode); hg_message_bll _message_bll = new hg_message_bll(comcode); wx_hg_message_bll _wxmessage_bll = new wx_hg_message_bll(comcode); hg_record_message_bll _record_bll = new hg_record_message_bll(comcode); sync_push_bll bll = new sync_push_bll(); var entry = _config_bll.GetConfig(BasConfigEnum.PushTimeConfig); if (entry == null || string.IsNullOrEmpty(entry.value)) { } else { string ssxx = entry.value; string datestr = DateTime.Now.ToString("yyyy-MM-dd"); PushConfig config = Newtonsoft.Json.JsonConvert.DeserializeObject(ssxx); if (!string.IsNullOrEmpty(config.qw)) { #region 企业微信推送 //foreach (var item in config.qw.Split('|')) //{ // string title = $"qw{datestr} {item}"; // Console.WriteLine("合规推送:" + title); // if (!dic.ContainsKey(title))//有数据了,不必再进行推送 // { // bas_pushcmd cmd = _pushcmd_bll.GetConfig(title); // if (cmd != null && cmd.id != 0)//表明已经推送过,不必再推送 // { // dic.Add(title, title); // } // else // { // //判断一下,是否到点了 // DateTime configtime = Convert.ToDateTime(title.Replace("qw", "")); // if (DateTime.Now > configtime)//超过时间点了,可以进行推送了哦 // { // //推送一下数据 // try // { // DateTime stime = DateTime.Now; // DateTime nowdate = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));//上传昨天的数据 // List messgelist = _message_bll.GetHgMessage(nowdate); // List pushlist = new List(); // foreach (hg_message hgmsg in messgelist) // { // hgmsg.hgstatus = 0; // hgmsg.detpcode = comcode; // pushlist.Add(new sync_push() // { // bidatatype = "Server_Hg_Qw_Message", // ctime = DateTime.Now, // deptcode = comcode, // isbatch = 0, // jsontext = Newtonsoft.Json.JsonConvert.SerializeObject(hgmsg) // }); // } // bll.InserPush(pushlist); // Console.WriteLine("合规推送:" + title + ",count:" + pushlist.Count); // pushlist = null;//入库完毕,销毁list // _pushcmd_bll.InsertPushCmd(new bas_pushcmd() // { // ctime = stime, // endtime = DateTime.Now, // iscomplete = 1, // mevent = "qwpush", // title = title, // type = "sys" // }); // dic.Add(title, title); // } // catch (Exception a) // { // LogHelper.Error(a.ToString()); // } // } // } // } //} #endregion } if (!string.IsNullOrEmpty(config.wx)) { #region 微信推送 //foreach (var item in config.wx.Split('|')) //{ // string title = $"wx{datestr} {item}"; // Console.WriteLine("合规推送:" + title); // if (!dic.ContainsKey(title))//有数据了,不必再进行推送 // { // bas_pushcmd cmd = _pushcmd_bll.GetConfig(title); // if (cmd != null && cmd.id != 0)//表明已经推送过,不必再推送 // { // dic.Add(title, title); // } // else // { // //判断一下,是否到点了 // DateTime configtime = Convert.ToDateTime(title.Replace("wx", "")); // if (DateTime.Now > configtime)//超过时间点了,可以进行推送了哦 // { // //推送一下数据 // try // { // DateTime stime = DateTime.Now; // DateTime nowdate = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));//上传昨天的数据 // List messgelist = _wxmessage_bll.GetHgMessage(nowdate); // List pushlist = new List(); // foreach (hg_wx_message hgmsg in messgelist) // { // hgmsg.hgstatus = 0; // hgmsg.detpcode = comcode; // pushlist.Add(new sync_push() // { // bidatatype = "Server_Hg_Wx_Message", // ctime = DateTime.Now, // deptcode = comcode, // isbatch = 0, // jsontext = Newtonsoft.Json.JsonConvert.SerializeObject(hgmsg) // }); // } // bll.InserPush(pushlist); // Console.WriteLine("合规推送:" + title + ",count:" + pushlist.Count); // pushlist = null;//入库完毕,销毁list // _pushcmd_bll.InsertPushCmd(new bas_pushcmd() // { // ctime = stime, // endtime = DateTime.Now, // iscomplete = 1, // mevent = "wxpush", // title = title, // type = "sys" // }); // dic.Add(title, title); // } // catch (Exception a) // { // LogHelper.Error(a.ToString()); // } // } // } // } //} #endregion } if (!string.IsNullOrEmpty(config.record)) { #region 语音推送 foreach (var item in config.wx.Split('|')) { string title = $"record{datestr} {item}"; Console.WriteLine("合规推送:" + title); if (!dic.ContainsKey(title))//有数据了,不必再进行推送 { bas_pushcmd cmd = _pushcmd_bll.GetConfig(title); if (cmd != null && cmd.id != 0)//表明已经推送过,不必再推送 { dic.Add(title, title); } else { //判断一下,是否到点了 DateTime configtime = Convert.ToDateTime(title.Replace("record", "")); if (DateTime.Now > configtime)//超过时间点了,可以进行推送了哦 { //推送一下数据 try { DateTime stime = DateTime.Now; DateTime nowdate = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));//上传昨天的数据 List messgelist = _record_bll.GetHgMessage(nowdate); List pushlist = new List(); foreach (hg_record_message hgmsg in messgelist) { hgmsg.hgstatus = 0; hgmsg.detpcode = comcode; pushlist.Add(new sync_push() { bidatatype = "Server_Hg_ReCord_Message", ctime = DateTime.Now, deptcode = comcode, isbatch = 0, jsontext = Newtonsoft.Json.JsonConvert.SerializeObject(hgmsg) }); } bll.InserPush(pushlist); Console.WriteLine("合规推送:" + title + ",count:" + pushlist.Count); pushlist = null;//入库完毕,销毁list _pushcmd_bll.InsertPushCmd(new bas_pushcmd() { ctime = stime, endtime = DateTime.Now, iscomplete = 1, mevent = "recordpush", title = title, type = "sys" }); dic.Add(title, title); } catch (Exception a) { LogHelper.Error(a.ToString()); } } } } } #endregion } } } catch (Exception e) { LogHelper.Error(e.ToString()); Program.ToFinishMan(threadKey); } finally { Thread.Sleep(5 * 60 * 1000);//5分钟执行一次 Console.WriteLine("合规推送休息5分钟"); } } } } public class PushConfig { public string qw { get; set; } public string wx { get; set; } public string record { get; set; } } }