public List <OverdueActivityConfig> GetActivityConfigList(string pageId, string type = "H5") { List <OverdueActivityConfig> activityConfigList = new List <OverdueActivityConfig>(); DateTime nowday = DateTime.Now.Date; string searchkey = "activity/index?id="; string regexstr = @"(.*)activity/index\?id=(\w*)"; if (type.Equals("lightApp", StringComparison.OrdinalIgnoreCase)) { searchkey = "luck/luck2?id="; regexstr = @"(.*)luck/luck2\?id=(\w*)"; } using (var homepageclient = new HomePageClient()) { var response = homepageclient.GetLightAppHomePageModuleInfoByModuleKey(pageId); if (response != null && response.Result != null) { // var homemodels = response.Result.HomePageModels.Where(p => p.Contents.Where(q => q.Uri.IndexOf("activity/index?id=") >= 0).Count()>0).ToList(); foreach (var homeModel in response.Result.HomePageModels.Where(p => p != null)) { var homepageName = homeModel.Title; var typeName = homeModel.TypeName; foreach (var content in homeModel.Contents.Where(p => p != null)) { if (content.Uri?.IndexOf(searchkey) >= 0) { Regex idreg = new Regex(regexstr); Match idMatch = idreg.Match(content.Uri); if (idMatch.Success) { var hashkey = idMatch.Result("$2"); List <ActivePage> promotionItemList = ModuleContentConfigDAL.GetActivePageByHashKey(hashkey); if (promotionItemList != null && promotionItemList.FirstOrDefault() != null) { var promotionItem = promotionItemList.First(); var endDate = promotionItem.EndDate.Date; TimeSpan sp = endDate - nowday; int status = 0; if (sp.Days <= 4 && sp.Days > 0) { status = 1; } else if (sp.Days <= 0) { status = -1; } if (status != 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = homepageName, // HomePageName = promotionModuleItem.HomePageName, HelperModuleName = content.Title, Url = "https://wx.tuhu.cn/staticpage/promotion/activity/?id=" + hashkey, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = status, Type = typeName }; activityConfigList.Add(overdueActivityConfigItem); } } } } } } } } return(activityConfigList); }
public string MonitorAppActivity() { List <OverdueActivityConfig> OverdueActiveConfigList = new List <OverdueActivityConfig>(); IEnumerable <ModuleContentConfig> activityitemlist = ModuleContentConfigDAL.GetActivityModuleContentConfigList(); IEnumerable <ModuleContentConfig> promotionitemlist = ModuleContentConfigDAL.GetPromotionModuleContentConfigList(); IEnumerable <FlowConfig> flowactivityList = ModuleContentConfigDAL.GetFlowConfigActivityList(); IEnumerable <FlowConfig> flowpromotionList = ModuleContentConfigDAL.GetFlowConfigPromotionList(); IEnumerable <FlowConfig> flowconfiglist = ModuleContentConfigDAL.GetFlowConfigList(); DateTime nowday = DateTime.Now.Date; List <ActivityBuild> overdueActivityBuildList = new List <ActivityBuild>(); List <ActivePage> overdueActivePageList = new List <ActivePage>(); List <FlowConfig> overdueFlowConfigList = new List <FlowConfig>(); #region 坑位中老活动过期判断 if (activityitemlist != null && activityitemlist.Any()) { foreach (var activityModuleitem in activityitemlist.Where(p => !string.IsNullOrWhiteSpace(p.LinkUrl) && p.LinkUrl.Contains(@"/staticpage/activity/")).ToList()) { Regex reg = new Regex(@"^\/webView\?url=(.*)$"); Match activityMatch = reg.Match(activityModuleitem.LinkUrl); if (activityMatch.Success) { var encodeactivityUrl = activityMatch.Result("$1"); var decodeactivityUrl = HttpUtility.UrlDecode(encodeactivityUrl); Regex idreg = new Regex(@"(.*)\?id=(\d+)(.*)$"); Match idMatch = idreg.Match(decodeactivityUrl); if (idMatch.Success) { var idstring = idMatch.Result("$2"); List <ActivityBuild> activityBuildItemList = ModuleContentConfigDAL.GetActivityBuildById(Convert.ToInt32(idstring)); if (activityBuildItemList != null && activityBuildItemList.FirstOrDefault() != null) { var activityItem = activityBuildItemList.First(); var endDate = activityItem.EndDate.Date; TimeSpan sp = endDate - nowday; if (sp.Days <= 4 && sp.Days > 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = activityModuleitem.ModuleName, HomePageName = activityModuleitem.HomePageName, HelperModuleName = activityModuleitem.HelperModuleName, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "活动", Status = 1 //yellow color overdue at once }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days == 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = activityModuleitem.ModuleName, HomePageName = activityModuleitem.HomePageName, HelperModuleName = activityModuleitem.HelperModuleName, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "活动", Status = 0 //orange today overdue }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days < 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = activityModuleitem.ModuleName, HomePageName = activityModuleitem.HomePageName, HelperModuleName = activityModuleitem.HelperModuleName, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "活动", Status = -1 //red already overdue }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } } } } } foreach (var activityModuleitem in activityitemlist.Where(p => !string.IsNullOrWhiteSpace(p.MoreUri) && p.MoreUri.Contains(@"/staticpage/activity/")).ToList()) { Regex reg = new Regex(@"^\/webView\?url=(.*)$"); Match activityMatch = reg.Match(activityModuleitem.MoreUri); if (activityMatch.Success) { var encodeactivityUrl = activityMatch.Result("$1"); var decodeactivityUrl = HttpUtility.UrlDecode(encodeactivityUrl); Regex idreg = new Regex(@"(.*)\?id=(\d+)(.*)$"); Match idMatch = idreg.Match(decodeactivityUrl); if (idMatch.Success) { var idstring = idMatch.Result("$2"); List <ActivityBuild> activityBuildItemList = ModuleContentConfigDAL.GetActivityBuildById(Convert.ToInt32(idstring)); if (activityBuildItemList != null && activityBuildItemList.FirstOrDefault() != null) { var activityItem = activityBuildItemList.First(); var endDate = activityItem.EndDate.Date; TimeSpan sp = endDate - nowday; if (sp.Days <= 4 && sp.Days > 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = activityModuleitem.ModuleName, HomePageName = activityModuleitem.HomePageName, HelperModuleName = activityModuleitem.HelperModuleName, ID = activityItem.id, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "活动", Status = 1 //yellow color overdue at once }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days == 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = activityModuleitem.ModuleName, HomePageName = activityModuleitem.HomePageName, HelperModuleName = activityModuleitem.HelperModuleName, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "活动", Status = 0 //orange today overdue }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days < 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = activityModuleitem.ModuleName, HomePageName = activityModuleitem.HomePageName, HelperModuleName = activityModuleitem.HelperModuleName, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "活动", Status = -1 //red already overdue }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } } } } } } #endregion #region 瀑布流中老活动过期判断 if (flowactivityList != null && flowactivityList.Any()) { foreach (var flowactivity in flowactivityList.Where(p => !string.IsNullOrWhiteSpace(p.LinkUrl) && p.LinkUrl.Contains(@"/staticpage/activity/")).ToList()) { //瀑布流没有过期才做后续处理 if (flowactivity.EndDateTime.Date >= nowday) { Regex reg = new Regex(@"^\/webView\?url=(.*)$"); Match activityMatch = reg.Match(flowactivity.LinkUrl); if (activityMatch.Success) { var encodeactivityUrl = activityMatch.Result("$1"); var decodeactivityUrl = HttpUtility.UrlDecode(encodeactivityUrl); Regex idreg = new Regex(@"(.*)\?id=(\d+)(.*)$"); Match idMatch = idreg.Match(decodeactivityUrl); if (idMatch.Success) { var idstring = idMatch.Result("$2"); List <ActivityBuild> activityBuildItemList = ModuleContentConfigDAL.GetActivityBuildById(Convert.ToInt32(idstring)); if (activityBuildItemList != null && activityBuildItemList.FirstOrDefault() != null) { var activityItem = activityBuildItemList.First(); var endDate = activityItem.EndDate.Date; TimeSpan sp = endDate - nowday; if (sp.Days <= 4 && sp.Days > 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = flowactivity.Title, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "瀑布流", Status = 1 //yellow color overdue at once }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days == 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = flowactivity.Title, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "瀑布流", Status = 0 //orange today overdue }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days < 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = flowactivity.Title, Url = decodeactivityUrl, Title = activityItem.Title, EndDate = activityItem.EndDate, Type = "瀑布流", Status = -1 //red already overdue }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } } } } } } } #endregion #region 坑位中新活动过期判断 if (promotionitemlist != null && promotionitemlist.Any()) { // var promotionlinkUrlList = promotionitemlist.Select(p => p.LinkUrl).Where(p => !string.IsNullOrWhiteSpace(p)).ToList(); foreach (var promotionModuleItem in promotionitemlist.Where(p => !string.IsNullOrWhiteSpace(p.LinkUrl) && p.LinkUrl.Contains(@"/staticpage/promotion/activity/")).ToList()) { Regex reg = new Regex(@"^\/webView\?url=(.*)$"); Match promotionMatch = reg.Match(promotionModuleItem.LinkUrl); if (promotionMatch.Success) { var encodepromotionUrl = promotionMatch.Result("$1"); var decodepromotionUrl = HttpUtility.UrlDecode(encodepromotionUrl); Regex idreg = new Regex(@"(.*)\?id=(.*)&tuhu$"); Match idMatch = idreg.Match(decodepromotionUrl); if (idMatch.Success) { var hashkey = idMatch.Result("$2"); List <ActivePage> promotionItemList = ModuleContentConfigDAL.GetActivePageByHashKey(hashkey); if (promotionItemList != null && promotionItemList.FirstOrDefault() != null) { var promotionItem = promotionItemList.First(); var endDate = promotionItem.EndDate.Date; TimeSpan sp = endDate - nowday; if (sp.Days <= 4 && sp.Days > 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = promotionModuleItem.ModuleName, HomePageName = promotionModuleItem.HomePageName, HelperModuleName = promotionModuleItem.HelperModuleName, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = 1, Type = "活动" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days == 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = promotionModuleItem.ModuleName, HomePageName = promotionModuleItem.HomePageName, HelperModuleName = promotionModuleItem.HelperModuleName, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = 0, Type = "活动" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days < 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = promotionModuleItem.ModuleName, HomePageName = promotionModuleItem.HomePageName, HelperModuleName = promotionModuleItem.HelperModuleName, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = -1, Type = "活动" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } } } } } // var promotionMoreUriList = promotionitemlist.Select(p => p.MoreUri).Where(p => !string.IsNullOrWhiteSpace(p)).ToList(); foreach (var promotionMoreUriItem in promotionitemlist.Where(p => !string.IsNullOrWhiteSpace(p.MoreUri) && p.MoreUri.Contains(@"/staticpage/promotion/activity/")).ToList()) { Regex reg = new Regex(@"^\/webView\?url=(.*)$"); Match promotionMatch = reg.Match(promotionMoreUriItem.MoreUri); if (promotionMatch.Success) { var encodepromotionUrl = promotionMatch.Result("$1"); var decodepromotionUrl = HttpUtility.UrlDecode(encodepromotionUrl); Regex idreg = new Regex(@"(.*)\?id=(.*)&tuhu$"); Match idMatch = idreg.Match(decodepromotionUrl); if (idMatch.Success) { var hashkey = idMatch.Result("$2"); List <ActivePage> promotionItemList = ModuleContentConfigDAL.GetActivePageByHashKey(hashkey); if (promotionItemList != null && promotionItemList.FirstOrDefault() != null) { var promotionItem = promotionItemList.First(); var endDate = promotionItem.EndDate.Date; TimeSpan sp = endDate - nowday; if (sp.Days <= 4 && sp.Days > 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = promotionMoreUriItem.ModuleName, HomePageName = promotionMoreUriItem.HomePageName, HelperModuleName = promotionMoreUriItem.HelperModuleName, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = 1, Type = "活动" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days == 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = promotionMoreUriItem.ModuleName, HomePageName = promotionMoreUriItem.HomePageName, HelperModuleName = promotionMoreUriItem.HelperModuleName, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = 0, Type = "活动" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days < 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = promotionMoreUriItem.ModuleName, HomePageName = promotionMoreUriItem.HomePageName, HelperModuleName = promotionMoreUriItem.HelperModuleName, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = -1, Type = "活动" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } } } } } } #endregion #region 瀑布流中新活动过期判断 if (flowpromotionList != null && flowpromotionList.Any()) { foreach (var flowpromotionItem in flowpromotionList.Where(p => !string.IsNullOrWhiteSpace(p.LinkUrl) && p.LinkUrl.Contains(@"/staticpage/promotion/activity/")).ToList()) { if (flowpromotionItem.EndDateTime.Date >= nowday) { Regex reg = new Regex(@"^\/webView\?url=(.*)$"); Match promotionMatch = reg.Match(flowpromotionItem.LinkUrl); if (promotionMatch.Success) { var encodepromotionUrl = promotionMatch.Result("$1"); var decodepromotionUrl = HttpUtility.UrlDecode(encodepromotionUrl); Regex idreg = new Regex(@"(.*)\?id=(.*)&tuhu$"); Match idMatch = idreg.Match(decodepromotionUrl); if (idMatch.Success) { var hashkey = idMatch.Result("$2"); List <ActivePage> promotionItemList = ModuleContentConfigDAL.GetActivePageByHashKey(hashkey); if (promotionItemList != null && promotionItemList.FirstOrDefault() != null) { var promotionItem = promotionItemList.First(); var endDate = promotionItem.EndDate.Date; TimeSpan sp = endDate - nowday; if (sp.Days <= 4 && sp.Days > 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = flowpromotionItem.Title, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = 1, Type = "瀑布流" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days == 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = flowpromotionItem.Title, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = 0, Type = "瀑布流" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } else if (sp.Days < 0) { var overdueActivityConfigItem = new OverdueActivityConfig() { ModuleName = flowpromotionItem.Title, Url = decodepromotionUrl, Title = promotionItem.Title, EndDate = promotionItem.EndDate, Status = -1, Type = "瀑布流" }; OverdueActiveConfigList.Add(overdueActivityConfigItem); } } } } } } } #endregion //通过ModuleName以及URL做判重 OverdueActiveConfigList = OverdueActiveConfigList.Distinct(new OverdueAcitivityConfigComparer()).ToList(); string htmlString = ""; if (OverdueActiveConfigList.Any()) { Logger.Info($"有{OverdueActiveConfigList.Count()}个App首页模块活动页到期提醒需处理"); htmlString = GenerateHtmlString(OverdueActiveConfigList); // MailService.SendMail("App首页模块活动页到期提醒", ConfigurationManager.AppSettings["ActivityMonitorJob:To"], htmlString); } else { Logger.Info("无过期的APP首页活动,故无需邮件发送"); } return(htmlString); }