2025-04-24 18:31:27 +08:00

871 lines
44 KiB
C#
Raw 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 Microsoft.Practices.Unity;
using MyCode.Project.Domain.Config;
using MyCode.Project.Domain.Message.Request.Report40;
using MyCode.Project.Domain.Message.Request.WebSocket;
using MyCode.Project.Domain.Message.Response.User;
using MyCode.Project.Domain.Message.Response.WebSocket;
using MyCode.Project.Infrastructure.Cache;
using MyCode.Project.Infrastructure.Common;
using MyCode.Project.Infrastructure.Constant;
using MyCode.Project.Infrastructure.Enumeration;
using MyCode.Project.Infrastructure.UnityExtensions;
using MyCode.Project.Infrastructure.WebPost;
using MyCode.Project.Repositories.Common;
using MyCode.Project.Services;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Fleck.Samples.ConsoleApp
{
public class Server
{
static int procc = 0; //线程池空闲线程数
static int maxPoolnum = 10;
static int AddPoolStatus = 0;
static void Main()
{
/// <summary>
/// WebSocketIpAddress
/// </summary>
IUnityContainer container = UnityHelper.GetUnityContainer();
container.RegisterType<MyCodeSqlSugarClient>(new PerThreadLifetimeManager());
new DingDingHelper(SystemConfig.DingDingApiUrl, "websocket");
//注册缓存对象
container.RegisterType<IMyCodeCacheService, RedisCache>(new InjectionConstructor(SystemConfig.RedisAddress, SystemConfig.CachePrefix));
string webSocketIpAddress = WebConfigUtils.GetAppSettingsInfo("WebSocketIpAddress");
//var _webSocketService = UnityHelper.GetService<IWebSocketService>();
var _myCodeCacheService = UnityHelper.GetService<IMyCodeCacheService>();
SystemCache systemCache = new SystemCache();
FleckLog.Level = LogLevel.Debug;
var allSockets = new List<IWebSocketConnection>();
WebSocketMessgeResp<HomeMessgeResp> webSocketMessgeResp = new WebSocketMessgeResp<HomeMessgeResp>();
webSocketMessgeResp.ContentTxt = new HomeMessgeResp();
webSocketMessgeResp.ContentTxt.HeadImgUrl = "";
webSocketMemberIdKey = new Dictionary<string, string>();
//2021-12-29 本次版本运营要求取消消息页面停止掉websocket消息
while (1 == 0 && true)
{
try
{
var server = new WebSocketServer(webSocketIpAddress);
server.Start(socket =>
{
socket.OnOpen = () =>
{
string name = "";
//解析授权token
if (socket.ConnectionInfo.Headers.Keys.Contains("Authorization"))
{
var authHeader = socket.ConnectionInfo.Headers["Authorization"];
if (!string.IsNullOrWhiteSpace(authHeader))
{
try
{
var obj = TokenHelper.Get(authHeader.Trim(),
SystemConfig.JwtKey,
Const.LoginInfoKey);
var loginInfo = ((JObject)obj).ToObject<MemberLoginInfo>();
systemCache.Set(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort, loginInfo, new TimeSpan(365, 0, 0, 0));
systemCache.Set("IP" + loginInfo.UserId.ToString(), socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort, new TimeSpan(365, 0, 0, 0));
name = loginInfo.Name;
LogHelper.Info(loginInfo.Name + "绑定IP:" + socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
allSockets.Add(socket);
}
catch (Exception ex)
{
socket.Send("-2");
Console.WriteLine(ex.Message);
//socket.Close();
}
}
Console.WriteLine(name + ":Open!");
}
else
{
Console.WriteLine("Open没有传授权参数");
LogHelper.Info("绑定IP:" + socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
socket.Send("-2");
Console.WriteLine("-2");
//socket.Close();
}
//socket.Send("链接成功");
};
socket.OnClose = () =>
{
allSockets.Remove(socket);
try
{
var loginInfo = systemCache.Get<MemberLoginInfo>(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
if (loginInfo != null)
{
LogHelper.Info(loginInfo.Name + "删除IP:" + socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
systemCache.Delete("IP" + loginInfo.UserId.ToString());
}
systemCache.Delete(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
systemCache.Delete("ShopId:" + loginInfo.UserId);
Console.WriteLine(loginInfo.Name + "Close!");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
//socket.Close();
}
};
socket.OnMessage = message =>
{
var _webSocketService = UnityHelper.GetService<IWebSocketService>();
Console.WriteLine(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort + "--- " + message);
if (message == "ping") //心跳
{
socket.Send("pong");
Console.WriteLine("pong");
return;
}
LogHelper.Info("ip:" + socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
var loginInfo = systemCache.Get<MemberLoginInfo>(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
Console.WriteLine(message);
if (loginInfo != null)
{
var requst = JsonHelper.ToObject<MessgeRequst>(message);
string key = CacheKey.WebSocketQueueCacheKey + requst.Id + loginInfo.UserId;
if (requst.Message == "1")
{
_myCodeCacheService.Delete(key + CacheKey.WebSocketMemberQueueCacheKey);
_myCodeCacheService.Delete(key);
if (!webSocketMemberIdKey.ContainsKey(loginInfo.UserId.ToString()))
{
webSocketMemberIdKey.Add(loginInfo.UserId.ToString(), key);
}
else
{
webSocketMemberIdKey[loginInfo.UserId.ToString()] = key;
}
LogHelper.Info(loginInfo.Name + " " + loginInfo.UserId + " 被增加了一个详情页的KEY:" + key);
}
if (webSocketMemberIdKey.ContainsKey(loginInfo.UserId.ToString()) && requst.Message == "0")
{
int i = 0;
//webSocketMemberIdKey[loginInfo.UserId.ToString()] = "";
webSocketMemberIdKey.Remove(loginInfo.UserId.ToString());
LogHelper.Info(loginInfo.Name + " " + loginInfo.UserId + " 被删了一个详情页的KEY:" + key);
_myCodeCacheService.Delete(key); //会员详情页消息
_myCodeCacheService.Delete(key + CacheKey.WebSocketMemberQueueCacheKey); //进店消息详情页通知
}
var result = _webSocketService.MessageProcessing(message, loginInfo);
if (!string.IsNullOrWhiteSpace(result))
{
socket.Send(result);
//Console.WriteLine(loginInfo.Name + result);
LogHelper.Info(loginInfo.Name + $"接收消息后推送首页列表消息: " + result);
}
systemCache.Set("ShopId:" + loginInfo.UserId, requst.ShopId, new TimeSpan(1, 0, 0, 0));
}
else
{
}
};
socket.OnError = message =>
{
var loginInfo = systemCache.Get<MemberLoginInfo>(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
Console.WriteLine(message);
systemCache.Delete(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
if (loginInfo != null)
{
LogHelper.Error(loginInfo.Name + "出错啦!(148)");
Console.WriteLine(loginInfo.Name + "出错啦!");
DingDingSendMsg(loginInfo.Name + $"出错啦:" + message);
systemCache.Delete("IP" + loginInfo.UserId.ToString());
}
else
{
Console.WriteLine("出错啦!");
LogHelper.Error("(158)出错啦!");
}
LogHelper.Error(message);
//allSockets.Remove(socket);
//socket.Close();
//container.RegisterType<MyCodeSqlSugarClient>(new PerThreadLifetimeManager());
//Thread.Sleep(3000);
};
});
//监听消息队列里是否有新消息要推送
//详情消息
Task task1 = new Task(() =>
{
while (1 == 1)
{
try
{
var keys = webSocketMemberIdKey.Keys.ToList();
if (keys != null)
{
foreach (var key in keys)
{
var keyValue = webSocketMemberIdKey[key];
//LogHelper.Info($"keyValue:" + key);
if (string.IsNullOrWhiteSpace(keyValue))
{
//LogHelper.Info($"消失的主动推详情消息KEY:" + key);
continue;
}
var msg = (RedisMessge)_myCodeCacheService.Popup(keyValue);
if (msg != null)
{
var clientIpInfo = systemCache.Get<string>("IP" + msg.UserId.ToString());
if (clientIpInfo != null)
{
var socket = allSockets.FirstOrDefault(t => t.ConnectionInfo.ClientIpAddress + ":" + t.ConnectionInfo.ClientPort == clientIpInfo);
if (socket != null)
{
var loginInfo = systemCache.Get<MemberLoginInfo>(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
if (loginInfo != null)
{
var _webSocketService = UnityHelper.GetService<IWebSocketService>();
string result = _webSocketService.SendMsg(msg, loginInfo);
socket.Send(result);
LogHelper.Info(loginInfo.Name + $"主动推详情消息:" + result);
Console.WriteLine(loginInfo.Name + "主动推详情消息:" + result);
//LogHelper.Info("主动推详情消息:" + result);
}
}
}
else
{
LogHelper.Info($"主动推详情消息没有IP:" + msg.UserId.ToString());
Console.WriteLine("主动推详情消息没有IP:" + msg.UserId.ToString());
}
}
};
}
}
catch (Exception ex1)
{
LogHelper.Info($"详情消息出错:" + ex1.Message);
LogHelper.Info(ex1);
}
Thread.Sleep(300);
}
});
task1.Start();
//首页消息
Task task2 = new Task(() =>
{
while (1 == 1)
{
try
{
var IndexMsg = (RedisMessge)_myCodeCacheService.Popup(CacheKey.WebSocketQueueCacheKey);
while (IndexMsg != null)
{
var clientIpInfo = systemCache.Get<string>("IP" + IndexMsg.UserId.ToString());
if (clientIpInfo != null)
{
var socket = allSockets.FirstOrDefault(t => t.ConnectionInfo.ClientIpAddress + ":" + t.ConnectionInfo.ClientPort == clientIpInfo);
if (socket != null)
{
var _webSocketService = UnityHelper.GetService<IWebSocketService>();
var loginInfo = systemCache.Get<MemberLoginInfo>(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
IndexMsg.PositionType = 1;
Guid? shopId = systemCache.Get<Guid?>("ShopId:" + loginInfo.UserId);
if (shopId == null || (IndexMsg.ShopId != null && shopId == IndexMsg.ShopId) || IndexMsg.TemplateType == (int)ChatMessagType.MaterialsStore)
{
string result = _webSocketService.SendMsg(IndexMsg, loginInfo);
shopId = systemCache.Get<Guid?>("ShopId:" + loginInfo.UserId);
if (shopId == null || (IndexMsg.ShopId != null && shopId == IndexMsg.ShopId) || IndexMsg.TemplateType == (int)ChatMessagType.MaterialsStore)
{
socket.Send(result);
LogHelper.Info(loginInfo.Name + $"主动推首页列表消息: " + result);
Console.WriteLine(loginInfo.Name + "主动推首页列表消息:" + result);
}
else
{
LogHelper.Info(shopId);
LogHelper.Info(IndexMsg);
LogHelper.Info(loginInfo.Name + "2主动推首页列表消息:不是当前店铺,不推此消息");
Console.WriteLine(loginInfo.Name + "2主动推首页列表消息:不是当前店铺,不推此消息");
}
}
else
{
LogHelper.Info(shopId);
LogHelper.Info(IndexMsg);
LogHelper.Info(loginInfo.Name + "主动推首页列表消息:不是当前店铺,不推此消息");
Console.WriteLine(loginInfo.Name + "主动推首页列表消息:不是当前店铺,不推此消息");
}
}
}
else
{
LogHelper.Info($"主页列表消息:该用户没有在线: " + IndexMsg.UserId.ToString());
Console.WriteLine("主页列表消息:该用户没有在线: " + IndexMsg.UserId.ToString());
}
IndexMsg = (RedisMessge)_myCodeCacheService.Popup(CacheKey.WebSocketQueueCacheKey);
}
//DingDingSendMsg($"这是一个轮回:" + DateTime.Now);
//Console.WriteLine("这是一个轮回:" + DateTime.Now);
}
catch (Exception ex2)
{
LogHelper.Info($"首页消息出错:" + ex2.Message);
LogHelper.Info(ex2);
}
Thread.Sleep(300);
}
});
task2.Start();
////会员进店提醒
//Task task3 = new Task(() =>
//{
// while (1 == 1)
// {
// try
// {
// var keys = webSocketMemberIdKey.Keys.ToList();
// if (keys != null)
// {
// foreach (var key in keys)
// {
// var keyValue = webSocketMemberIdKey[key];
// if (string.IsNullOrWhiteSpace(keyValue))
// continue;
// var msg = (RedisMessge)_myCodeCacheService.Popup(keyValue + CacheKey.WebSocketMemberQueueCacheKey);
// if (msg != null)
// {
// var clientIpInfo = systemCache.Get<string>("IP" + msg.UserId.ToString());
// if (clientIpInfo != null)
// {
// var socket = allSockets.FirstOrDefault(t => t.ConnectionInfo.ClientIpAddress + ":" + t.ConnectionInfo.ClientPort == clientIpInfo);
// if (socket != null)
// {
// var loginInfo = systemCache.Get<MemberLoginInfo>(socket.ConnectionInfo.ClientIpAddress + ":" + socket.ConnectionInfo.ClientPort);
// if (loginInfo != null)
// {
// var _webSocketService = UnityHelper.GetService<IWebSocketService>();
// string result = _webSocketService.SendMsg(msg, loginInfo);
// socket.Send(result);
// LogHelper.Info(loginInfo.Name + $"主动推会员进店详情消息:" + result);
// Console.WriteLine(loginInfo.Name + "主动推会员进店详情消息:" + result);
// //LogHelper.Info("主动推详情消息:" + result);
// }
// }
// }
// else
// {
// LogHelper.Info($"主动推会员进店详情消息没有IP:" + msg.UserId.ToString());
// Console.WriteLine("主动推会员进店详情消息没有IP:" + msg.UserId.ToString());
// }
// }
// };
// }
// }
// catch (Exception ex3)
// {
// LogHelper.Info($"会员进店提醒出错:" + ex3.Message);
// LogHelper.Info(ex3);
// }
// Thread.Sleep(1000);
// }
//});
//task3.Start();
////每秒轮询调用会员进店提醒方法
//Task task4 = new Task(() =>
//{
// while (1 == 1)
// {
// DateTime time = DateTime.Now;
// var _webSocketService = UnityHelper.GetService<IWebSocketService>();
// try
// {
// searchTime = _webSocketService.SendMessageByFace(searchTime);
// }
// catch(Exception ex4)
// {
// LogHelper.Info($"每秒轮询调用会员进店提醒方法出错:" + ex4.Message);
// LogHelper.Info(ex4);
// }
// var span = DateTime.Now - time;
// if (1000d - span.TotalMilliseconds > 0)
// {
// var sss =(int)( 1000 - span.TotalMilliseconds);
// Thread.Sleep(sss);
// }
// }
//});
//task4.Start();
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex);
LogHelper.Error("(238)出错:" + ex.Message);
LogHelper.Error(ex);
DingDingSendMsg($"(240)出错啦:" + ex.Message);
allSockets.Clear();
allSockets = new List<IWebSocketConnection>();
Thread.Sleep(300);
}
}
int send = 1;
int hour = 0;
DateTime runTime = DateTime.Now;
//把门店的使用数据储存到数据库
while (true)
{
try
{
if (procc < 0)
procc = 0;
ThreadPool.SetMinThreads(1, 1);
ThreadPool.SetMaxThreads(maxPoolnum, maxPoolnum);
int ii = 0;
ThreadPool.GetAvailableThreads(out procc, out ii);
if (DateTime.Now.Hour == hour && send == 1)
{
send = 0;
DingDingSendMsg("正常运行中: " + DateTime.Now);
}
else if (DateTime.Now.Hour != hour)
{
hour = DateTime.Now.Hour;
send = 1;
}
Console.WriteLine((10-procc)+"个线程在运行,憨鸠鸠又一日 " + DateTime.Now);
var abc = ThreadPool.QueueUserWorkItem(new WaitCallback(rpShopUseAppletDataServiceSaveData), 1);
//var _rpShopUseAppletDataService = UnityHelper.GetService<IRpShopUseAppletDataService>();
//var temp1 = _myCodeCacheService.Popup(CacheKey.RpShopUseAppletDataKey2);
//if (temp1 != null)
//{
// var something = _myCodeCacheService.Popup(CacheKey.RpShopUseAppletDataKey);
// if (something != null)
// {
// string json = JsonHelper.ToJson(something);
// Console.WriteLine("获取到的参数 :" + json);
// if (!string.IsNullOrWhiteSpace(json))
// _rpShopUseAppletDataService.SaveData(json);
// }
// var req1 = JsonHelper.ToObject<RpShopUseAppletDataAct>(temp1.ToString());
// _rpShopUseAppletDataService.SelectSetData(req1.ApiUrl, req1.RequestDataStr, req1.Token);
//}
}
catch (Exception ex)
{
Console.WriteLine(ex);
LogHelper.Error("(452)出错:" + ex.Message);
LogHelper.Error(ex);
DingDingSendMsg($"(454)出错啦:" + ex.Message);
}
Thread.Sleep(1000);
try
{
var _HuLiHuShao40Service = UnityHelper.GetService<IHuLiHuShao40Service>();
var something = _myCodeCacheService.Popup(CacheKey.RpHuLiHuShao);
//if (something != null) //已经不要了
//{
// string json = JsonHelper.ToJson(something);
// Console.WriteLine("年报月报获取到的参数 :" + json);
// if (!string.IsNullOrWhiteSpace(json))
// _HuLiHuShao40Service.AutoSetReport();
//}
}
catch (Exception ex)
{
Console.WriteLine(ex);
//LogHelper.Error("(471)年报月报出错:" + ex.Message);
//LogHelper.Error(ex);
//DingDingSendMsg($"(473)年报月报出错:" + ex.Message);
}
try
{
if (AddPoolStatus == 0 && _myCodeCacheService.Exists("Auto:GetShopFenXiReport2207"))
{
DateTime now = DateTime.Now;
var tempJson = _myCodeCacheService.Get<string>("Auto:GetShopFenXiReport2207");
var templist = JsonHelper.ToObject<List<GetShopFenXiReport2207>>(tempJson);
_myCodeCacheService.Delete("Auto:GetShopFenXiReport2207");
var abc = ThreadPool.QueueUserWorkItem(new WaitCallback(AddPool), templist);
//templist.ForEach(t =>
//{
// var abc = ThreadPool.QueueUserWorkItem(new WaitCallback(TaskFenXiReportToCache), t);
//});
Console.WriteLine("执行提前查询方法Auto:GetShopFenXiReport2207");
}
else
{
_myCodeCacheService.Delete("Auto:GetShopFenXiReport2207");
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
try
{
if (_myCodeCacheService.Exists("Auto:PoolTaskSave2308TodayData"))
{
var tempJson = _myCodeCacheService.Popup("Auto:PoolTaskSave2308TodayData");
var abc = ThreadPool.QueueUserWorkItem(new WaitCallback(PoolTaskSave2308TodayData), tempJson);
Console.WriteLine("执行提前查询方法Auto:PoolTaskSave2308TodayData");
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
try
{
DateTime now = DateTime.Now;
if ((now- runTime).TotalMinutes>=4)
{
runTime = now;
//PoolTaskReport2308LargeScreen(1);
var abc = ThreadPool.QueueUserWorkItem(new WaitCallback(PoolTaskReport2308LargeScreen), 1);
Console.WriteLine("执行提前查询方法刷202308的大投屏缓存");
}
//PoolTaskReport2308LargeScreen
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
GC.Collect();
}
}
//private static ConcurrentBag<string> webSocketMemberIdKey;
private static Dictionary<string, string> webSocketMemberIdKey;
private static DateTime searchTime = DateTime.Now;
#region SendMsg()
private static Task DingDingSendMsg(string content)
{
string url = WebConfigUtils.GetAppSettingsInfo("DingDingApiUrl");
string _txt = "websocket" + WebConfigUtils.GetAppSettingsInfo("DingDingTxt");
WebUtils webUtils = new WebUtils();
var jsonObject = new { msgtype = "text", text = new { content = _txt + content } };
var jsonStr = JsonHelper.ToJson(jsonObject);
try
{
var result = webUtils.DoPostJson(url, jsonStr);
}
catch
{ }
return Task.CompletedTask;
}
#endregion
public static string TaskFenXiReportToCache(object i)
{
string md5key = "";
try
{
int ii = 10;
ThreadPool.GetAvailableThreads(out procc, out ii);
int tempprocc = procc;
Stopwatch sw = new Stopwatch();
GetShopFenXiReport2207 act = (GetShopFenXiReport2207)i;
Console.WriteLine($@"{10- tempprocc}线程池执行方法TaskFenXiReportToCache 开始" + act.UserId + " " + act.DuiBi + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
var _report2207Service = UnityHelper.GetService<IReport2207Service>();
sw.Start();
md5key = _report2207Service.SetFenXiReportToCache(act.UserId, act.DuiBi);
sw.Stop();
Console.WriteLine($@"{10- tempprocc}线程池执行方法TaskFenXiReportToCache 结束,耗时" + sw.Elapsed.TotalSeconds + "秒" + act.UserId + " " + act.DuiBi + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
}
catch (Exception ex)
{
md5key = "-1";
Console.WriteLine(ex);
}
return md5key;
}
public static void rpShopUseAppletDataServiceSaveData(object i)
{
try
{
int ii = 10;
ThreadPool.GetAvailableThreads(out procc, out ii);
int tempprocc = procc;
Console.WriteLine((10- tempprocc) + "线程池执行方法rpShopUseAppletDataServiceSaveData 开始" + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
Stopwatch sw = new Stopwatch();
sw.Start();
var _myCodeCacheService = UnityHelper.GetService<IMyCodeCacheService>();
var _rpShopUseAppletDataService = UnityHelper.GetService<IRpShopUseAppletDataService>();
var temp1 = _myCodeCacheService.Popup(CacheKey.RpShopUseAppletDataKey2);
if (temp1 != null)
{
var something = _myCodeCacheService.Popup(CacheKey.RpShopUseAppletDataKey);
if (something != null)
{
string json = JsonHelper.ToJson(something);
Console.WriteLine("获取到的参数 :" + json);
if (!string.IsNullOrWhiteSpace(json))
_rpShopUseAppletDataService.SaveData(json);
}
var req1 = JsonHelper.ToObject<RpShopUseAppletDataAct>(temp1.ToString());
_rpShopUseAppletDataService.SelectSetData(req1.ApiUrl, req1.RequestDataStr, req1.Token);
}
sw.Stop();
Console.WriteLine((10- tempprocc) + "线程池执行方法rpShopUseAppletDataServiceSaveData 结束,耗时" + sw.Elapsed.TotalSeconds + "秒" + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public static void AddPool(object act)
{
if (AddPoolStatus == 1)
{
return;
}
AddPoolStatus = 1;
try
{
List<string> md5Key = new List<string>();
Stopwatch sw = new Stopwatch();
sw.Start();
List<GetShopFenXiReport2207> templist = (List<GetShopFenXiReport2207>)act;
var _report2207Service = UnityHelper.GetService<IReport2207Service>();
templist.ForEach(t =>
{
int ii = 0;
ThreadPool.GetAvailableThreads(out procc, out ii);
//temKey= TaskFenXiReportToCache(t);
int tempprocc = procc;
GetShopFenXiReport2207 act2 = (GetShopFenXiReport2207)t;
Console.WriteLine($@"{10 - tempprocc}线程池执行方法TaskFenXiReportToCache 开始" + act2.UserId + " " + act2.DuiBi + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
Stopwatch sw2 = new Stopwatch();
sw2.Start();
_report2207Service.SetFenXiReportToCache(act2.UserId, act2.DuiBi);
sw2.Stop();
Console.WriteLine($@"{10 - tempprocc}线程池执行方法TaskFenXiReportToCache 结束,耗时" + sw2.Elapsed.TotalSeconds + "秒" + act2.UserId + " " + act2.DuiBi + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(2000);
});
AddPoolStatus = 0;
sw.Stop();
Console.WriteLine((10 - procc) + "线程池执行方法:商品分析对比计算 结束,耗时" + sw.Elapsed.TotalSeconds + "秒" + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
templist.Clear();
templist = null;
GC.Collect();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public static void PoolTaskSave2308TodayData(object i)
{
try
{
int ii = 10;
ThreadPool.GetAvailableThreads(out procc, out ii);
int tempprocc = procc;
Console.WriteLine((10- tempprocc) + "线程池执行方法PoolTaskSave2308TodayData 开始" + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
Stopwatch sw = new Stopwatch();
sw.Start();
var _report2308Service = UnityHelper.GetService<IReport2308Service>();
_report2308Service.TaskSave2308TodayData(Guid.Parse(i.ToString()));
sw.Stop();
Console.WriteLine((10- tempprocc) + "线程池执行方法PoolTaskSave2308TodayData 结束,耗时" + sw.Elapsed.TotalSeconds + "秒" + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public static void PoolTaskReport2308LargeScreen(object i)
{
try
{
int ii = 10;
ThreadPool.GetAvailableThreads(out procc, out ii);
int tempprocc = procc;
Console.WriteLine((10- tempprocc) + "线程池执行方法2023年8月份的大投屏缓存 开始" + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
Stopwatch sw = new Stopwatch();
sw.Start();
string url = WebConfigUtils.GetAppSettingsInfo("LxmAdminApiUrl");
WebUtils webUtils = new WebUtils();
var _myCodeCacheService = UnityHelper.GetService<IMyCodeCacheService>();
var searchstring = _myCodeCacheService.Get("timeSearch2308");
string search1 = "";
TimeSearchAct2308 search = null;
if (searchstring !=null && !string.IsNullOrWhiteSpace(searchstring.ToString()))
{
search1 = searchstring.ToString(); //楚恩的框架存的缓存,值直接转字符串再序列号即可
search = JsonHelper.ToObject<TimeSearchAct2308>(search1);
}
if (search == null)
{
DateTime now = DateTime.Now;
search = new TimeSearchAct2308();
search.BeginYearMonth =now.Year + "-01";
search.EndYearMonth = now.Year + "-" + now.Month;
}
search.Key = "0CB1C571-EADB-4C14-9F3E-664738078574";
var jsonStr = JsonHelper.ToJson(search);
try
{
//计算主推品项系列销量分析存到redis 1
string apiUrl = url + "/api/Admin/Report2308LargeScreen/GetZhuTuiFenXiToRedis";
var result = webUtils.DoPostJson(apiUrl, jsonStr);
}
catch(Exception ex)
{
int dasd = 0;
}
try
{
//计算新品上市销售量分析分析存到redis 2
string apiUrl = url + "/api/Admin/Report2308LargeScreen/GetXinPinFenXiToRedis";
var result = webUtils.DoPostJson(apiUrl, jsonStr);
}
catch
{ }
try
{
//计算家居产品销售量排行榜存到redis 3
string apiUrl = url + "/api/Admin/Report2308LargeScreen/GetJiaJuXiaoLiangToRedis";
var result = webUtils.DoPostJson(apiUrl, jsonStr);
}
catch
{ }
try
{
//产品销售总额分析到redis 4
string apiUrl = url + "/api/Admin/Report2308LargeScreen/GetShangPinXiaoShouFenXiToRedis";
var result = webUtils.DoPostJson(apiUrl, jsonStr);
}
catch
{ }
try
{
//计算叠加品项销售量排行榜存到redis 5
string apiUrl = url + "/api/Admin/Report2308LargeScreen/GetDieJiaPinXiaoLiangToRedis";
var result = webUtils.DoPostJson(apiUrl, jsonStr);
}
catch
{ }
try
{
//彩妆销售top10到redis 6
string apiUrl = url + "/api/Admin/Report2308LargeScreen/GetCaiZhuangTop10ToRedis";
var result = webUtils.DoPostJson(apiUrl, jsonStr);
}
catch
{ }
try
{
//计算主推品全国门店覆盖率存到redis 7
string apiUrl = url + "/api/Admin/Report2308LargeScreen/GetMenDianFuGaiLvToRedis";
var result = webUtils.DoPostJson(apiUrl, jsonStr);
}
catch
{ }
try
{
//计算叠加品项全国门店覆盖率存到redis 8
string apiUrl = url + "/api/Admin/Report2308LargeScreen/GetDieJiaPinPinFuGaiLvToRedis";
var result = webUtils.DoPostJson(apiUrl, jsonStr);
}
catch
{ }
sw.Stop();
Console.WriteLine((10- tempprocc) + "线程池执行方法2023年8月份的大投屏缓存 结束,耗时" + sw.Elapsed.TotalSeconds + "秒" + " 线程ID" + Thread.CurrentThread.ManagedThreadId);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}