using CRM.Core.DTO; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using WX.CRM.Common; using WX.CRM.DAL; namespace WX.CRM.CRMServices.WeiXin { public static class SummaryMessagePush { private static string host = Utility.GetSettingOrNullByKey("DataSyncApiUrl"); private static string url = host + "/api/DataSync"; private static MySqlDbHelper mySqlhelper = new MySqlDbHelper("MysqlQWConn");//读取 private static string _deptCode = Utility.GetSettingByKey("DataClientCode"); public static void Push() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var msgs = mySqlhelper.QueryEntitys("select * from ww_message_summary where ispush=0 and pushcount!=0 and getcount != 0 order by ctime limit 100"); List ids = new List(); foreach (var msg in msgs) { if (PushOne(msg)) { ids.Add(msg.id);//记录推送成功的id //Thread.Sleep(300); } } //更新已经推送数据 if (ids.Any()) { mySqlhelper.ExecuteNonQuery($"update ww_message_summary set ispush=1 where id in ({string.Join(",", ids)})"); } stopWatch.Stop(); //记录费时 LogHelper.Info(string.Concat("WX.CRM.CRMServices.CRMJobs.SummaryMessagePushJob:", stopWatch.ElapsedMilliseconds, "ms")); stopWatch = null; } public static bool PushOne(ww_MessageSummary model) { try { var para = new SYNC_PUSH_DTO() { bidatatype = "Server_push_wwmessagesummary", deptcode = _deptCode, jsontext = model.ToJson() }; var rep = Utility.PostAjaxData(url, para.ToJson(), Encoding.UTF8); var ret = Utility.JSONToObject(rep); return ret.result; } catch (Exception ex) { LogHelper.Error(string.Concat("WX.CRM.CRMServices.CRMJobs.SummaryMessagePushJob.Execute ", ex.Message, ex.StackTrace)); } return false; } } public class ww_MessageSummary { public int id { get; set; } public string appid { get; set; } public string userid { get; set; } public string externaluserid { get; set; } public int pushcount { get; set; } public int getcount { get; set; } public DateTime ctime { get; set; } public DateTime msgdate { get; set; } public int ispush { get; set; } } }