Exemplo n.º 1
0
        public static void LoadTask(List <TimingTask> _taskList)
        {
            TaskContent task   = new TaskContent();
            TimingTask  timing = new TimingTask();

            timing.TimingTaskExcuter = task;
            timing.TimingTaskType    = TimingTaskType.PerDay;
            timing.ExcuteTime        = new ShortTime(0, 0, 10);
            _taskList.Add(timing);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加定时任务
        /// </summary>
        /// <param name="taskType"></param>
        /// <param name="taskInfo"></param>
        /// <param name="receiverType"></param>
        /// <param name="receivers"></param>
        /// <param name="websiteOwner"></param>
        /// <returns></returns>
        public bool AddTimingTask(TaskType taskType, string taskInfo, ReceiverType receiverType, string receivers, string websiteOwner)
        {
            TimingTask timingTask = new TimingTask();

            timingTask.TaskType     = (int)taskType;
            timingTask.ReceiverType = (int)receiverType;
            timingTask.Receivers    = receivers;
            timingTask.TaskInfo     = taskInfo;
            timingTask.InsertDate   = DateTime.Now;
            timingTask.WebsiteOwner = websiteOwner;
            return(this.Add(timingTask));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 执行定时任务
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public bool ExecuteTimingTask(TimingTask task)
        {
            switch ((TaskType)task.TaskType)
            {
            case TaskType.SendImageTextMessage:
                return(SendImageTextMessage(task));   //客服接口 群发

            //case TaskType.SendTMUserScoreNotify:
            //    return BLLUserScore.SendTMAllUserScoreDailyAccountBillNotify(task.WebsiteOwner);
            case TaskType.SendMassMessage:
                return(new BLLWeixin("").SendMassMessage(task));

            case TaskType.SynDistributionMember:
                return(new BLLDistribution().SynDistributionCount(task.WebsiteOwner));   //更新上下级人数

            case TaskType.SynDistributionSaleAmount:
                return(new BLLDistribution().SynDistributionSaleAmount(task.WebsiteOwner));   //更新销售额

            case TaskType.FlashChannelData:
                return(new BLLDistribution().FlashChannelData(task.WebsiteOwner));   //更新渠道数据

            case TaskType.CleanUser:
                return(new BLLUser().CleanUser(task.WebsiteOwner) > 0);

            case TaskType.GetDistributionImage:    //分销二维码
                return(new BLLDistribution().GetDistributionImage(task));

            case TaskType.StatisticsOrderProduct:    //统计订单及商品
                return(new BLLMall().StatisticsOrderAndProduct(task));

            case TaskType.SupplierSettlement:    //供应商结算
                return(new BLLMall().SupplierSettlementTask(task));

            case TaskType.SupplierChannelSettlement:    //供应商渠道结算
                return(new BLLMall().SupplierChannelSettlementTask(task));

            case TaskType.ScoreStatis:    //积分统计任务
                return(new BllScore().ExceScoreStatis(task));

            default:
                return(false);
            }
        }
Exemplo n.º 4
0
        public void TestIt()
        {
            var task = new MockTask();

            MockMiscProvider.MockNow = (new DateTime(2004, 3, 5, 10, 5, 10, 0));
            ITiming timing = new TimeSpanTiming(new TimeSpan(0, 5, 0));

            var tt = new TimingTask(task, timing);

            tt.RunIfTimingUp();
            Assert.AreEqual(true, task.DoTaskOk);
            task.DoTaskOk = false;

            MockMiscProvider.Add(new TimeSpan(0, 0, 1));
            tt.RunIfTimingUp();
            Assert.AreEqual(false, task.DoTaskOk);

            MockMiscProvider.Add(new TimeSpan(0, 1, 1));
            tt.RunIfTimingUp();
            Assert.AreEqual(false, task.DoTaskOk);

            MockMiscProvider.Add(new TimeSpan(0, 3, 1));
            tt.RunIfTimingUp();
            Assert.AreEqual(false, task.DoTaskOk);

            MockMiscProvider.Add(new TimeSpan(0, 0, 56));
            tt.RunIfTimingUp();
            Assert.AreEqual(false, task.DoTaskOk);

            MockMiscProvider.Add(new TimeSpan(0, 0, 1));
            tt.RunIfTimingUp();
            Assert.AreEqual(true, task.DoTaskOk);
            task.DoTaskOk = false;

            MockMiscProvider.Add(new TimeSpan(0, 0, 1));
            tt.RunIfTimingUp();
            Assert.AreEqual(false, task.DoTaskOk);

            MockMiscProvider.Add(new TimeSpan(0, 5, 8));
            tt.RunIfTimingUp();
            Assert.AreEqual(true, task.DoTaskOk);
        }
Exemplo n.º 5
0
        /// <summary>
        ///客服接口 群发
        /// </summary>
        /// <param name="timingTask"></param>
        /// <returns></returns>
        public bool SendImageTextMessage(TimingTask timingTask)
        {
            BLLWeixin bllWeixin = new BLLWeixin("");
            List <BLLWeixin.WeiXinArticle> articleList = new List <BLLWeixin.WeiXinArticle>();

            string[] idarray = timingTask.TaskInfo.Split(',');
            foreach (string id in idarray)
            {
                WeixinMsgSourceInfo msg = bllWeixin.Get <WeixinMsgSourceInfo>(string.Format("SourceID={0}", id));
                articleList.Add(new BLLWeixin.WeiXinArticle()
                {
                    Title       = msg.Title,
                    Description = msg.Description,
                    Url         = msg.Url,
                    PicUrl      = msg.PicUrl
                });
            }

            switch ((ReceiverType)timingTask.ReceiverType)
            {
            case ReceiverType.All:
                bllWeixin.BroadcastKeFuMessageImageText(timingTask.WebsiteOwner, articleList, timingTask.TaskInfo);
                return(true);

            case ReceiverType.Group:

                return(false);

            case ReceiverType.List:
                string[] openidArray = timingTask.Receivers.Split(',');
                foreach (string openid in openidArray)
                {
                    bllWeixin.SendKeFuMessageImageText(bllWeixin.GetAccessToken(timingTask.WebsiteOwner), openid, articleList);
                }
                return(openidArray.Length > 0);

            default:
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 积分统计任务
        /// </summary>
        public bool ExceScoreStatis(TimingTask task)
        {
            StringBuilder sbSQL = new StringBuilder();

            sbSQL.AppendFormat(" WebSiteOwner='{0}' ", task.WebsiteOwner);
            if (!string.IsNullOrWhiteSpace(task.DistributionUserId))
            {
                sbSQL.AppendFormat(" And UserID='{0}' ", task.DistributionUserId);
            }
            ;
            //if (!string.IsNullOrWhiteSpace(type)) { sbSQL.AppendFormat(" And ScoreType='{0}' ", type); }
            sbSQL.AppendFormat(" And ScoreType!='AccountAmount' And ScoreType!='TotalAmount' ");

            if (task.FromDate != null)
            {
                sbSQL.AppendFormat(" AND AddTime>='{0}' ", task.FromDate);
            }
            if (task.ToDate != null)
            {
                sbSQL.AppendFormat(" AND AddTime<='{0}' ", task.ToDate);
            }

            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("日期");
            dt.Columns.Add("用户");
            dt.Columns.Add("手机");
            dt.Columns.Add("积分");
            dt.Columns.Add("说明");
            List <UserScoreDetailsInfo> userScores = new List <UserScoreDetailsInfo>();

            int pageIndex = 1;

            do
            {
                userScores = GetLit <UserScoreDetailsInfo>(100, pageIndex, sbSQL.ToString(), " AddTime DESC");
                if (userScores.Count > 0)
                {
                    for (int i = 0; i < userScores.Count; i++)
                    {
                        UserInfo user = bllUser.GetUserInfo(userScores[i].UserID, task.WebsiteOwner);
                        if (user == null)
                        {
                            continue;
                        }
                        System.Data.DataRow newRow = dt.NewRow();
                        newRow["日期"] = userScores[i].AddTime;
                        newRow["用户"] = user.TrueName;
                        newRow["手机"] = user.Phone;
                        newRow["积分"] = userScores[i].Score;
                        newRow["说明"] = userScores[i].AddNote;
                        dt.Rows.Add(newRow);
                    }
                    pageIndex++;
                    System.Threading.Thread.Sleep(100);
                }
            } while (userScores.Count > 0);

            dt.TableName = "积分统计";
            string filePath = string.Format("\\FileUpload\\ScoreStatis\\{0}_{1}积分统计.xls", Guid.NewGuid().ToString(), Convert.ToDateTime(task.InsertDate).ToString("yyyyMMddHHmm"));

            string filePathAbs = string.Format(Common.ConfigHelper.GetConfigString("WebSitePath") + filePath);

            Common.NPOIHelper.DtToXls(dt, filePathAbs);
            task.Url = filePath;

            bool result = Update(task);

            try
            {
                string dir      = "ScoreStatis";
                string fileType = "excel";
                string ossUrl   = AliOss.OssHelper.UploadFile(AliOss.OssHelper.GetBucket(task.WebsiteOwner), dir, AliOss.OssHelper.GetBucket(task.WebsiteOwner), fileType, task.WebsiteOwner, filePathAbs);

                task.Url = ossUrl;
                Update(task);
            }
            catch (Exception ex)
            {
                task.TaskInfo += ex.ToString();
            }

            return(result);
        }