TG.WXCRM.V4/NetCore.Service/PushThread.cs

287 lines
15 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
{
/// <summary>
/// 推送类
/// </summary>
public class PushThread
{
/// <summary>
/// 随机数
/// </summary>
public string matchstr { get; set; }
public string keyName { get; set; }
public Dictionary<string, string> dic;
public string threadKey { get; set; }
/// <summary>
/// 企业编号
/// </summary>
public string comcode { get; set; }
public void execute()
{
while (true)
{
try
{
dic = new Dictionary<string, string>();
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<PushConfig>(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<hg_message> messgelist = _message_bll.GetHgMessage(nowdate);
// List<sync_push> pushlist = new List<sync_push>();
// 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<hg_wx_message> messgelist = _wxmessage_bll.GetHgMessage(nowdate);
// List<sync_push> pushlist = new List<sync_push>();
// 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<hg_record_message> messgelist = _record_bll.GetHgMessage(nowdate);
List<sync_push> pushlist = new List<sync_push>();
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; }
}
}