Example #1
0
        /// <summary>
        ///检查是否有要运行的秒杀商品
        /// </summary>
        /// <param name="bizLogFile">业务日志文件全名</param>
        public static void CheckCountDownSecKill(string bizLogFile)
        {
            BizLogFile = bizLogFile;
            WriteLog("\r\n------------------- Begin-------------------------");
            WriteConsoleInfo("\r\n------------------- Begin-------------------------");

            WriteLog("\r\n设置没有库存的正在运行的售完即止活动结束时间为当前时间");
            WriteConsoleInfo("\r\n设置没有库存的正在运行的售完即止活动结束时间为当前时间");
            int intEndCount = SecKillDA.CountDownSetEndTimeForNoQty();

            WriteLog(string.Format("\r\n{0}", intEndCount));
            WriteConsoleInfo(string.Format("\r\n{0}", intEndCount));

            // 获取限时抢购中秒杀商品的记录
            List <SecKillEntity> CountDownSecKillList = SecKillDA.GetCountDownItem4SecKill();
            string startmsg = "获取到限时抢购中就绪和运行态的记录,共" + CountDownSecKillList.Count + "条.";

            WriteLog(startmsg);
            WriteConsoleInfo(startmsg);

            if (CountDownSecKillList.Count == 0)
            {
                return;
            }
            StringBuilder startNum   = new StringBuilder();
            StringBuilder finishNum  = new StringBuilder();
            StringBuilder abandonNum = new StringBuilder();

            foreach (SecKillEntity oCountdown in CountDownSecKillList)
            {
                string info = string.Format("限时抢购SysNo|产品SysNo|状态-->{0}|{1}|{2}\r\n",
                                            oCountdown.SysNo, oCountdown.ProductSysNo, oCountdown.Status);
                if (oCountdown.Status == 0 &&
                    (oCountdown.StartTime <= DateTime.Now &&
                     oCountdown.EndTime > DateTime.Now))
                {
                    try
                    {
                        if (!SetRunning(oCountdown.SysNo))
                        {
                            SetAbandon(oCountdown.SysNo);
                            abandonNum.AppendLine(info);
                        }
                        else
                        {
                            startNum.AppendLine(info);
                        }
                    }
                    catch (Exception exp)
                    {
                        SendExceptionInfoEmail(exp.Message.ToString());
                        WriteLog(string.Format("{0}就绪->运行 出错了!异常:{1}", info, exp.Message.ToString()));
                        continue;
                    }
                }
                if (oCountdown.Status == 1 && (oCountdown.EndTime < DateTime.Now))
                {
                    try
                    {
                        SetFinish(oCountdown.SysNo);
                        finishNum.AppendLine(info);
                    }
                    catch (Exception ex)
                    {
                        SendExceptionInfoEmail(ex.Message.ToString());
                        WriteLog("运行->结束 出错了![" + info + "]" + "异常:" + ex.ToString());
                        continue;
                    }
                }
            }

            string endMsg = "本轮运行结果:\r\n就绪->运行:\r\n" + startNum.ToString() + "\r\n就绪->作废:\r\n"
                            + abandonNum.ToString() + "\r\n运行->完成:\r\n" + finishNum.ToString();

            WriteLog(endMsg);
            WriteLog("------------------- End-----------------------------\r\n");
            WriteConsoleInfo(endMsg);
        }