From fc6b7c9852f18e42fb9bccaf0cc22fbe5389d179 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期三, 12 四月 2023 14:43:46 +0800 Subject: [PATCH] 优化 --- Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs | 64 +++++++++++++++++++++++-------- 1 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs b/Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs index 52186cc..6940c5f 100644 --- a/Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs +++ b/Application/IStation.Application.OpenApi/test/report/Report_ShysController.cs @@ -19,7 +19,9 @@ [ApiDescriptionSettings("OpenApi", Name = "娴嬭瘯鎶ヨ〃", Order = 1001)] public class Report_ShysController : IDynamicApiController { - + /// <summary> + /// + /// </summary> public readonly static Dictionary<string, string> ProvinceCodeDic = new Dictionary<string, string> { { "鍥涘窛鐪�", "510000" }, { "鍖椾含甯�", "110000" }, { "澶╂触甯�", "120000" }, { "娌冲寳鐪�", "130000" }, { "灞辫タ鐪�", "140000" }, { "鍐呰挋鍙よ嚜娌诲尯", "150000" }, { "杈藉畞鐪�", "210000" }, { "鍚夋灄鐪�", "220000" }, { "榛戦緳姹熺渷", "230000" }, { "涓婃捣甯�", "310000" }, { "姹熻嫃鐪�", "320000" }, { "娴欐睙鐪�", "330000" }, { "瀹夊窘鐪�", "340000" }, { "绂忓缓鐪�", "350000" }, { "姹熻タ鐪�", "360000" }, { "灞变笢鐪�", "370000" }, { "娌冲崡鐪�", "410000" }, { "婀栧寳鐪�", "420000" }, { "婀栧崡鐪�", "430000" }, { "骞夸笢鐪�", "440000" }, { "骞胯タ鑷不鍖�", "450000" }, { "娴峰崡鐪�", "460000" }, { "閲嶅簡甯�", "500000" }, { "璐靛窞鐪�", "520000" }, { "浜戝崡鐪�", "530000" }, { "瑗胯棌鑷不鍖�", "540000" }, { "闄曡タ鐪�", "610000" }, { "鐢樿們鐪�", "620000" }, { "闈掓捣鐪�", "630000" }, { "瀹佸鑷不鍖�", "640000" }, { "鏂扮枂鑷不鍖�", "650000" }, { "鍙版咕鐪�", "710000" }, { "棣欐腐鐗瑰埆琛屾斂鍖�", "810000" }, { "婢抽棬鐗瑰埆琛屾斂鍖�", "820000" } }; /// <summary> @@ -44,17 +46,18 @@ return default; var dto = new UserLoginLogReportDto(); - dto.LoginLogList = new List<UserLoginLogItem>(); - dto.LogSummaryList = logs.GroupBy(x => x.LoginTime.Date).Select(x => new LogSummary() { DateTime = x.Key, Visitors = x.Count() }).ToList(); + dto.LoginLogList = new List<LoginLogItem>(); + dto.LoginStatisticsList = new List<LoginStatistics>(); dto.TotalUsers = users.Count; - - var uniqueVisitorList = logs.DistinctBy(x => x.UserID).ToList(); - var today = DateTime.Today; - var last7Days = today.AddDays(-7); - var last30Days = today.AddDays(-30); + dto.LogSummaryList = logs.GroupBy(x => x.LoginTime.Date).Select(x => new LogSummary() {Date = x.Key.ToString("d"), Visitors = x.Count() }).ToList(); + + var uniqueVisitorList = logs.DistinctBy(x => x.UserID).ToList(); + var yesterday = DateTime.Today.AddDays(-1); + var last7Days = yesterday.AddDays(-7); + var last30Days = yesterday.AddDays(-30); if (uniqueVisitorList != null && uniqueVisitorList.Count > 0) { - dto.TodayUV = uniqueVisitorList.Where(x => x.LoginTime >= today).Count(); + dto.YesterdayUV = uniqueVisitorList.Where(x => x.LoginTime >= yesterday).Count(); dto.Last7DaysUV = uniqueVisitorList.Where(x => x.LoginTime >= last7Days).Count(); dto.Last30DaysUV = uniqueVisitorList.Where(x => x.LoginTime >= last30Days).Count(); } @@ -67,26 +70,53 @@ foreach (var logGroup in logGroups) { var corp = corps.Find(x => x.ID == logGroup.Key); + var corpName = corp?.ShortName; + var list = new List<LoginLogItem>(); foreach (var log in logGroup) { var area = RandomValues(ProvinceCodeDic, 1).First().Key; - var item = new UserLoginLogItem(log, corp.ShortName, area); - dto.LoginLogList.Add(item); + var softName = string.Empty; + switch (log.SoftType) + { + case IStation.SoftType.CS_瀹㈡埛绔�: + softName = "瀹㈡埛绔�"; + break; + case IStation.SoftType.BS_缃戦〉绔�: + softName = "缃戦〉绔�"; + break; + case IStation.SoftType.Wechat_寰俊灏忕▼搴�: + softName = "灏忕▼搴�"; + break; + case IStation.SoftType.App_绉诲姩绔�: + softName = "APP"; + break; + default: + softName = "鏈煡"; + break; + } + var item = new LoginLogItem(log, corpName, area, softName); + list.Add(item); } + var statistics = list.GroupBy(x => x.SoftName).Select(x => new LoginStatistics() { CorpName = corpName, Software = x.Key, Visitors = x.Count() }); + dto.LoginStatisticsList.AddRange(statistics); + dto.LoginLogList.AddRange(list); } + + LogHelper.Info("鐢熸垚鏂囦欢!"); var ReportPath = Path.Combine(Settings.File.FileStorageFolder, @"UserLoginLogReport"); if (!Directory.Exists(ReportPath)) Directory.CreateDirectory(ReportPath); - var yyMM = DateTime.Today.ToString("yyyy-MM"); - var filePath = Path.Combine(ReportPath, yyMM + ".xml"); - filePath = filePath.Replace(@"\\", @"/"); - - LogHelper.Info("淇濆瓨鏂囦欢!"); + //var filePath = Path.Combine(ReportPath, "UserLoginLogReport" + ".xml"); + var filePath = "C:\\FineReport\\tomcat-win64\\webapps\\webroot\\WEB-INF\\reportlets\\file\\UserLoginLogReport.xml"; + if (File.Exists(filePath)) + { + File.Delete(filePath); + } XmlHelper<UserLoginLogReportDto>.SaveObjectXmlFile(filePath, dto); - + LogHelper.Info("淇濆瓨鏂囦欢!"); } catch (Exception ex) { -- Gitblit v1.9.3