Exemple #1
0
 public PushServer()
 {
     InitializeComponent();
     JobManager.InitializeWithoutStarting(new PushJob());
     JobManager.JobException += info =>
     {
         Util.Logs.Log.GetLog(nameof(PushServer)).Error("An error just happened with a scheduled job: " + info.Exception);
         WxPushNews.SendErrorText($"错误类型:{Util.Helpers.Enum.GetDescription<ExceptionType>(ExceptionType.PushException)},信息:{info.Exception}");
     };
     JobManager.JobEnd += PushJob.OnJobEnd;
 }
Exemple #2
0
        private void PushReport(StatisticType statisticType, int statisticValue, int year)
        {
            var WxNewsUrl         = System.Configuration.ConfigurationManager.AppSettings["WxNewsUrl"];
            var WxNewsPicUrl      = System.Configuration.ConfigurationManager.AppSettings["WxNewsPicUrl"];
            var WxNewssmallPicUrl = System.Configuration.ConfigurationManager.AppSettings["WxNewssmallPicUrl"];

            var redirectUri = string.Format("{0}?date={1}&mode={3}&source={2}", WxNewsUrl, DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), ServerName, statisticType.ToString().ToLower());

            redirectUri = System.Web.HttpUtility.UrlEncode(redirectUri);

            var url         = WxPushNews.CreateWxNewsOAuthUrl(redirectUri);
            var picUrl      = WxNewsPicUrl;
            var smallpicUrl = WxNewssmallPicUrl;

            using (var db = new OMSContext())
            {
                Statistic foo   = new Statistic();
                string    title = string.Empty;

                List <Statistic> lst = new List <Statistic>();
                var nameDesc         = this.ServerDesc;
                switch (statisticType)
                {
                case StatisticType.Day:

                    DateTime dateTime = new DateTime(year, 1, 1).AddDays(statisticValue - 1);
                    lst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.SourceDesc == nameDesc).ToList();
                    if (ServerName == OrderSource.CIBAPP) //CIB,CIBAPP,CIBEVT合并发送
                    {
                        var ciblst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIB).ToList();
                        if (ciblst.Any())
                        {
                            lst.Concat(ciblst);
                        }
                        var cibevtlst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIBEVT).ToList();
                        if (cibevtlst.Any())
                        {
                            lst.Concat(cibevtlst);
                        }
                    }
                    foreach (var s in lst)
                    {
                        foo.TotalAmount             += s.TotalAmount;
                        foo.TotalCustomer           += s.TotalCustomer;
                        foo.TotalCustomerRepurchase += s.TotalCustomerRepurchase;
                        foo.TotalOrderCount         += s.TotalOrderCount;
                        foo.TotalOrderRepurchase    += s.TotalOrderRepurchase;
                        foo.TotalProductCount       += s.TotalProductCount;
                        foo.TotalProductRepurchase  += s.TotalProductRepurchase;
                        foo.TotalWeight             += s.TotalWeight;
                    }
                    if (foo == null || foo.TotalOrderCount <= 0)
                    {
                        title = string.Format("{0} #{1}#{2}(今日无单)", dateTime.ToString("yyyy年MM月dd日"), nameDesc, Environment.NewLine);
                    }
                    else
                    {
                        title = string.Format("{0} #{1}#", dateTime.ToString("yyyy年MM月dd日"), nameDesc);
                    }
                    break;

                case StatisticType.Week:

                    lst = db.StatisticSet.Where(s => s.StatisticType == (int)StatisticType.Week && s.StatisticValue == statisticValue && s.Year == year && s.SourceDesc == nameDesc).ToList();
                    if (ServerName == OrderSource.CIBAPP)    //CIB,CIBAPP,CIBEVT合并发送
                    {
                        var ciblst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIB).ToList();
                        if (ciblst.Any())
                        {
                            lst.Concat(ciblst);
                        }
                        var cibevtlst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIBEVT).ToList();
                        if (cibevtlst.Any())
                        {
                            lst.Concat(cibevtlst);
                        }
                    }
                    foreach (var s in lst)
                    {
                        foo.TotalAmount             += s.TotalAmount;
                        foo.TotalCustomer           += s.TotalCustomer;
                        foo.TotalCustomerRepurchase += s.TotalCustomerRepurchase;
                        foo.TotalOrderCount         += s.TotalOrderCount;
                        foo.TotalOrderRepurchase    += s.TotalOrderRepurchase;
                        foo.TotalProductCount       += s.TotalProductCount;
                        foo.TotalProductRepurchase  += s.TotalProductRepurchase;
                        foo.TotalWeight             += s.TotalWeight;
                    }
                    if (foo == null || foo.TotalOrderCount <= 0)
                    {
                        title = string.Format("{0} #{1}#{2}(本周无单)", $"{year}年{statisticValue}周", nameDesc, Environment.NewLine);
                    }
                    else
                    {
                        title = $"{year}年#{statisticValue}周#{nameDesc}";
                    }
                    break;

                case StatisticType.Month:

                    lst = db.StatisticSet.Where(s => s.StatisticType == (int)StatisticType.Month && s.StatisticValue == statisticValue && s.Year == year && s.SourceDesc == nameDesc).ToList();
                    if (ServerName == OrderSource.CIBAPP)    //CIB,CIBAPP,CIBEVT合并发送
                    {
                        var ciblst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIB).ToList();
                        if (ciblst.Any())
                        {
                            lst.Concat(ciblst);
                        }
                        var cibevtlst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIBEVT).ToList();
                        if (cibevtlst.Any())
                        {
                            lst.Concat(cibevtlst);
                        }
                    }
                    foreach (var s in lst)
                    {
                        foo.TotalAmount             += s.TotalAmount;
                        foo.TotalCustomer           += s.TotalCustomer;
                        foo.TotalCustomerRepurchase += s.TotalCustomerRepurchase;
                        foo.TotalOrderCount         += s.TotalOrderCount;
                        foo.TotalOrderRepurchase    += s.TotalOrderRepurchase;
                        foo.TotalProductCount       += s.TotalProductCount;
                        foo.TotalProductRepurchase  += s.TotalProductRepurchase;
                        foo.TotalWeight             += s.TotalWeight;
                    }
                    if (foo == null || foo.TotalOrderCount <= 0)
                    {
                        title = string.Format("{0} #{1}#{2}(本月无单)", $"{year}年{statisticValue}月", nameDesc, Environment.NewLine);
                    }
                    else
                    {
                        title = $"{year}年#{statisticValue}月份#{nameDesc}";
                    }
                    break;

                case StatisticType.Quarter:

                    lst = db.StatisticSet.Where(s => s.StatisticType == (int)StatisticType.Quarter && s.StatisticValue == statisticValue && s.Year == year && s.SourceDesc == nameDesc).ToList();
                    if (ServerName == OrderSource.CIBAPP)    //CIB,CIBAPP,CIBEVT合并发送
                    {
                        var ciblst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIB).ToList();
                        if (ciblst.Any())
                        {
                            lst.Concat(ciblst);
                        }
                        var cibevtlst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIBEVT).ToList();
                        if (cibevtlst.Any())
                        {
                            lst.Concat(cibevtlst);
                        }
                    }
                    foreach (var s in lst)
                    {
                        foo.TotalAmount             += s.TotalAmount;
                        foo.TotalCustomer           += s.TotalCustomer;
                        foo.TotalCustomerRepurchase += s.TotalCustomerRepurchase;
                        foo.TotalOrderCount         += s.TotalOrderCount;
                        foo.TotalOrderRepurchase    += s.TotalOrderRepurchase;
                        foo.TotalProductCount       += s.TotalProductCount;
                        foo.TotalProductRepurchase  += s.TotalProductRepurchase;
                        foo.TotalWeight             += s.TotalWeight;
                    }
                    if (foo == null || foo.TotalOrderCount <= 0)
                    {
                        title = string.Format("{0} #{1}#{2}(本季无单)", $"{year}年{statisticValue}季", nameDesc, Environment.NewLine);
                    }
                    else
                    {
                        title = $"{year}年#{statisticValue}季度#{nameDesc}";
                    }
                    break;

                case StatisticType.Year:

                    lst = db.StatisticSet.Where(s => s.StatisticType == (int)StatisticType.Year && s.StatisticValue == year && s.SourceDesc == nameDesc).ToList();
                    if (ServerName == OrderSource.CIBAPP)    //CIB,CIBAPP,CIBEVT合并发送
                    {
                        var ciblst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIB).ToList();
                        if (ciblst.Any())
                        {
                            lst.Concat(ciblst);
                        }
                        var cibevtlst = db.StatisticSet.Where(s => s.StatisticType == (int)statisticType && s.StatisticValue == statisticValue && s.Year == year && s.Source == OrderSource.CIBEVT).ToList();
                        if (cibevtlst.Any())
                        {
                            lst.Concat(cibevtlst);
                        }
                    }
                    foreach (var s in lst)
                    {
                        foo.TotalAmount             += s.TotalAmount;
                        foo.TotalCustomer           += s.TotalCustomer;
                        foo.TotalCustomerRepurchase += s.TotalCustomerRepurchase;
                        foo.TotalOrderCount         += s.TotalOrderCount;
                        foo.TotalOrderRepurchase    += s.TotalOrderRepurchase;
                        foo.TotalProductCount       += s.TotalProductCount;
                        foo.TotalProductRepurchase  += s.TotalProductRepurchase;
                        foo.TotalWeight             += s.TotalWeight;
                    }
                    if (foo == null || foo.TotalOrderCount <= 0)
                    {
                        title = string.Format("{0} #{1}#{2}(本年无单)", $"{year}年", nameDesc, Environment.NewLine);
                    }
                    else
                    {
                        title = $"{year}年#{nameDesc}";
                    }
                    break;

                default:
                    break;
                }


                var wxArticles = new List <WxArticle>()
                {
                    new WxArticle(title, url, picUrl, string.Empty)
                };
                int rangvalue = 7;
                switch (statisticType)
                {
                case StatisticType.Week:
                    rangvalue = 7;
                    break;

                case StatisticType.Month:
                    rangvalue = DateTime.DaysInMonth(year, statisticValue);
                    break;

                case StatisticType.Quarter:
                    rangvalue = Util.Helpers.Time.GetDaysInSeason(year, statisticValue);
                    break;

                case StatisticType.Year:
                    rangvalue = Util.Helpers.Time.GetDaysInYear(year);
                    break;

                default:
                    break;
                }
                if (foo != null && foo.TotalOrderCount > 0 && statisticType != StatisticType.Day)
                {
                    wxArticles.AddRange(new List <WxArticle>()
                    {
                        new WxArticle(string.Format("总计单数:{0}", foo.TotalOrderCount), url, smallpicUrl, string.Empty),
                        new WxArticle(string.Format("总计盒数:{0}", foo.TotalProductCount), url, smallpicUrl, string.Empty),


                        new WxArticle(string.Format("总计人数:{0}", foo.TotalCustomer), url, smallpicUrl, string.Empty),
                        new WxArticle(string.Format("日均单数:{0}", Math.Round((double)foo.TotalOrderCount / rangvalue, 2)), url, smallpicUrl, string.Empty),
                        new WxArticle(string.Format("日均盒数:{0}", Math.Round((double)foo.TotalProductCount / rangvalue, 2)), url, smallpicUrl, string.Empty),
                        // new WxArticle(string.Format("总计重量(kg):{0}", foo.TotalWeight/1000),url,smallpicUrl,string.Empty),
                        // new WxArticle(string.Format("总计促销单数:{0}", foo.PromotionalOrderCount),url,string.Empty,string.Empty),
                        //  new WxArticle(string.Format("总计复购人数:{0}", foo.TotalCustomerRepurchase),url,smallpicUrl,string.Empty),

                        new WxArticle(string.Format("总计人数复购率:{0}%", Math.Round((double)foo.TotalCustomerRepurchase * 100 / foo.TotalCustomer, 2)), url, smallpicUrl, string.Empty),
                        new WxArticle(string.Format("总计单数复购率:{0}%", Math.Round((double)foo.TotalOrderRepurchase * 100 / foo.TotalOrderCount, 2)), url, smallpicUrl, string.Empty),
                    });
                }
                else if (foo != null && foo.TotalOrderCount > 0 && statisticType == StatisticType.Day)
                {
                    wxArticles.AddRange(new List <WxArticle>()
                    {
                        new WxArticle(string.Format("总计人数:{0}", foo.TotalCustomer), url, smallpicUrl, string.Empty),
                        new WxArticle(string.Format("总计单数:{0}", foo.TotalOrderCount), url, smallpicUrl, string.Empty),
                        new WxArticle(string.Format("总计盒数:{0}", foo.TotalProductCount), url, smallpicUrl, string.Empty),
                        new WxArticle(string.Format("总计重量(kg):{0}", foo.TotalWeight / 1000), url, smallpicUrl, string.Empty),
                        // new WxArticle(string.Format("总计促销单数:{0}", foo.PromotionalOrderCount),url,string.Empty,string.Empty),
                        new WxArticle(string.Format("总计复购人数:{0}", foo.TotalCustomerRepurchase), url, smallpicUrl, string.Empty),

                        new WxArticle(string.Format("总计人数复购率:{0}%", Math.Round((double)foo.TotalCustomerRepurchase * 100 / foo.TotalCustomer, 2)), url, smallpicUrl, string.Empty),
                        new WxArticle(string.Format("总计单数复购率:{0}%", Math.Round((double)foo.TotalOrderRepurchase * 100 / foo.TotalOrderCount, 2)), url, smallpicUrl, string.Empty),
                    });
                }
                try
                {
                    WxPushNews.OrderStatistic(wxArticles, ServerName);
                    Util.Logs.Log.GetLog(nameof(WxPushNews)).Info($"消息推送成功:{wxArticles[0].Title}");
                }
                catch (Exception ex)
                {
                    Util.Logs.Log.GetLog(nameof(WxPushNews)).Error($"消息推送失败:{wxArticles[0].Title},error:{ex.Message},stackTrace:{ex.StackTrace}");
                }
            }
        }
Exemple #3
0
        public static void OnJobEnd(JobEndInfo obj)
        {
            switch (obj.Name)
            {
            case "CreateDailyReport1":
            case "CreateDailyReport2":
            case "CreateDailyReport3":
            case "CreateDailyReport4":
            case "CreateDailyReport5":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},12点定时任务--生成统计报表完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},12点定时任务--生成统计报表完毕...");
                break;

            case "CreateReport6":
            case "CreateReport7":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},19点定时任务--生成统计报表完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},19点定时任务--生成统计报表完毕...");
                break;

            case "PushDailyReport1":
            case "PushDailyReport2":
            case "PushDailyReport3":
            case "PushDailyReport4":
            case "PushDailyReport5":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},每天14点定时报表推送完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},每天14点定时报表推送完毕...");
                break;

            case "PushDailyReport6":
            case "PushDailyReport7":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},每天20点定时报表推送完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},每天20点定时报表推送完毕...");
                break;

            case "PushWeeklyReport":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},每周一15点定时周报表推送完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},每周一15点定时周报表推送完毕...");
                break;

            case "PushMonthlyReport":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},每月一号16点定时月报表推送完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},每月一号16点定时月报表推送完毕...");
                break;

            case "CreateRepeatReport":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},每天19点定时历史报表生成完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},每天19点定时历史报表生成完毕...");
                break;

            case "ImportErpToOMS":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},每天21点定时ERP订单导入解析完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},每天21点定时ERP订单导入解析完毕...");
                break;

            case "CreateReport2":
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},每天23点定时任务--生成统计报表完毕...");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},每天23点定时任务...");
                break;

            default:
                WxPushNews.SendErrorText($"当前时间:{DateTime.Now},任务名称{obj.Name}执行完毕");
                Util.Logs.Log.GetLog(nameof(PushJob)).Info($"当前时间:{DateTime.Now},任务名称{obj.Name}执行完毕");
                break;
            }
        }