protected override void NoTask()
        {
            var first = ORMHelper.GetModel <Tmall_Skechers_Detail>(" where LastUpdate > '2017-03-19 5:51:33' and LastUpdate < '2017-03-19 23:59:34'");
            Dictionary <Int64, Tmall_Skechers_Detail> dic_First = first.ToDictionary(key => key.Id, Tmall_Skechers_Detail => Tmall_Skechers_Detail);

            var last = ORMHelper.GetModel <Tmall_Skechers_Detail>(" where LastUpdate > '2017-03-27 0:00:00' and LastUpdate < '2017-03-28 23:59:34'");
            Dictionary <Int64, Tmall_Skechers_Detail> dic_Last = last.ToDictionary(key => key.Id, Tmall_Skechers_Detail => Tmall_Skechers_Detail);

            List <Tmall_Skechers_Detail> putAway  = new List <Tmall_Skechers_Detail>();
            List <Tmall_Skechers_Detail> saleOut  = new List <Tmall_Skechers_Detail>();
            List <Tmall_Skechers_Detail> onSaling = new List <Tmall_Skechers_Detail>();

            #region  架
            using (StreamWriter sw = new StreamWriter("新品.csv", false, Encoding.Default))
            {
                sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", "商品ID", "首页价格", "本日月销量", "总销量", "库存", "月评价", "总评价");
                foreach (var it in last)
                {
                    if (!dic_First.ContainsKey(it.Id))
                    {
                        sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", "=\"" + it.Id + "\"", it.indexPrice, it.Sales_Mon, it.Sales_Total, it.Repertory, it.Comments_Mon, it.Comments_Total);
                    }
                }
                sw.Close();
                ShowMsg("新上架写入完成");
            }
            #endregion

            #region  架
            using (StreamWriter sw = new StreamWriter("下架.csv", false, Encoding.Default))
            {
                sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", "商品ID", "首页价格", "本日月销量", "总销量", "库存", "月评价", "总评价");
                foreach (var it in first)
                {
                    if (!dic_Last.ContainsKey(it.Id))
                    {
                        sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", "=\"" + it.Id + "\"", it.indexPrice, it.Sales_Mon, it.Sales_Total, it.Repertory, it.Comments_Mon, it.Comments_Total);
                    }
                }
                sw.Close();
                ShowMsg("下架写入完成");
            }
            #endregion

            #region 热卖
            using (StreamWriter sw = new StreamWriter("热卖.csv", false, Encoding.Default))
            {
                sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", "商品ID", "首页价格(前)", "首页价格(本)", "上期月销量", "本日月销量", "上期总销量", "总销量", "上期库存", "库存", "月评价", "总评价");
                foreach (var it in last)
                {
                    if (dic_First.ContainsKey(it.Id))
                    {
                        sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", "=\"" + it.Id + "\"", dic_First[it.Id].indexPrice, it.indexPrice, dic_First[it.Id].Sales_Mon, it.Sales_Mon, dic_First[it.Id].Sales_Total, it.Sales_Total, dic_First[it.Id].Repertory, it.Repertory, it.Comments_Mon, it.Comments_Total);
                    }
                }
                sw.Close();
                ShowMsg("热卖商品写入完成");
            }
            #endregion
        }
        protected override void Fun(List <urlInfo> task)
        {
            System.Threading.Thread.Sleep(10 * 1000);
            string date    = DateTime.Now.Date.AddDays(-1).ToShortDateString() + " 0:00:00";
            var    gotList = ORMHelper.GetModel <Tmall_Skechers_Name>(" where State =" + Program.UpdateTimes);
            Dictionary <Int64, Tmall_Skechers_Name> dic_Got = new Dictionary <long, Tmall_Skechers_Name>();

            foreach (var dg in gotList)
            {
                if (!dic_Got.ContainsKey(dg.Id))
                {
                    dic_Got.Add(dg.Id, dg);
                }
            }

            List <Tmall_Skechers_Name>   nsList = new List <Tmall_Skechers_Name>();
            List <Tmall_Skechers_Detail> dsList = new List <Tmall_Skechers_Detail>();
            int a = 0;

            foreach (var t in task)
            {
                ShowMsg(t.dataId.ToString());
                if (dic_Got.ContainsKey((long)t.dataId))
                {
                    continue;
                }
                //if (++a == 20)
                //{
                //    System.Threading.Thread.Sleep(60 * 1000);
                //    a = 0;
                //}
                var result = PageDataHelper.GotDetailData(t);
                Tmall_Skechers_Detail td = new Tmall_Skechers_Detail();
                Tmall_Skechers_Name   tn = new Tmall_Skechers_Name();
                td.Id             = tn.Id = (Int64)result.Id;
                tn.Name           = result.Name;
                td.LastUpdate     = tn.LastUpdate = result.LastUpdate;
                td.indexPrice     = result.IndexPrice;
                td.AvePrice       = result.AvePrice;
                td.Comments_Mon   = result.IndexComment;
                td.Comments_Total = result.TotalComment;
                td.Repertory      = (int)result.Repertory;
                td.Sales_Mon      = result.MonSales;
                tn.State          = td.State = sbyte.Parse(Program.UpdateTimes);
                td.Sales_Total    = result.TotalSales;
                ShowMsg(t.dataId + "  " + t.name + " " + td.AvePrice + " " + td.Sales_Mon + " " + td.Comments_Mon + td.LastUpdate);
                nsList.Add(tn);
                dsList.Add(td);
                Random random   = new Random();
                int    interval = random.Next(35, 80);
                ShowMsg(interval.ToString());
                System.Threading.Thread.Sleep(interval * 100);
            }
            DataToBase.SaveData(nsList);
            DataToBase.SaveData(dsList);
            //更新配置文件
            CC.Utility.iniHelper ini = new CC.Utility.iniHelper(Program.FilePath);
            ini.Write("state", "times", (sbyte.Parse(Program.UpdateTimes) + 1).ToString());
        }
        protected override void Fun(List <urlInfo> task)
        {
            string date    = DateTime.Now.Date.ToShortDateString() + " 0:00:00";
            var    gotList = ORMHelper.GetModel <Tmall_Name_Anta>(" where State = '" + (Program.UpdateTimes + 1) + "' ");
            Dictionary <UInt64, Tmall_Name_Anta> dic_Got = new Dictionary <ulong, Tmall_Name_Anta>();

            foreach (var dg in gotList)
            {
                if (!dic_Got.ContainsKey(dg.Id))
                {
                    dic_Got.Add(dg.Id, dg);
                }
            }
            int a = 0;
            List <Tmall_Detail_Anta> dsList = new List <Tmall_Detail_Anta>();
            List <Tmall_Name_Anta>   nsList = new List <Tmall_Name_Anta>();

            foreach (var t in task)
            {
                a++;
                ShowMsg(t.dataId.ToString());
                if (dic_Got.ContainsKey(t.dataId))
                {
                    continue;
                }

                var result           = PageDataHelper.GotDetailData(t);
                Tmall_Detail_Anta td = new Tmall_Detail_Anta();
                Tmall_Name_Anta   tn = new Tmall_Name_Anta();
                td.Id             = tn.Id = (UInt64)result.Id;
                tn.Name           = result.Name;
                td.LastUpdate     = tn.LastUpdate = result.LastUpdate;
                td.IndexPrice     = result.IndexPrice;
                td.AvePrice       = result.AvePrice;
                td.Comments_Mon   = result.IndexComment;
                td.Comments_Total = result.TotalComment;
                td.Repertory      = (uint)result.Repertory;
                td.Sales_Mon      = result.MonSales;
                td.Sales_Total    = result.TotalSales;
                tn.State          = td.State = byte.Parse(Program.UpdateTimes);
                ShowMsg(t.dataId + "  " + t.name + " " + td.AvePrice + " " + td.Sales_Mon + " " + td.Comments_Mon + td.LastUpdate);
                nsList.Add(tn);
                dsList.Add(td);
                Random random   = new Random();
                int    interval = random.Next(25, 76);
                ShowMsg(interval.ToString());
                System.Threading.Thread.Sleep(interval * 100);
                if (a == 50)
                {
                    ShowMsg("<加入50条数据>");
                    DataToBase.SaveData(nsList);
                    DataToBase.SaveData(dsList);
                }
            }
            //更新配置文件
            CC.Utility.iniHelper ini = new CC.Utility.iniHelper(Program.FilePath);
            ini.Write("state", "times", (byte.Parse(Program.UpdateTimes) + 1).ToString());
            driver.Close();
        }
Example #4
0
        public static void GotResultCsv(string excelPath, string tableName, string excelName)
        {
            var dic_Excel = ExcelToDs(excelPath, tableName, excelName);
            List <Tmall_Detail_Anta> orm_List = ORMHelper.GetModel <Tmall_Detail_Anta>("where  LastUpdate > '2017-04-09 00:00:00'");
            var orm_Dic      = orm_List.ToDictionary(key => key.Id, Tmall_Detail_Anta => Tmall_Detail_Anta);
            var dic_Xiajia   = new Dictionary <ulong, string[]>();
            var dic_Shangjia = new Dictionary <ulong, Tmall_Detail_Anta>();
            var dic_SjNo     = new Dictionary <ulong, Tmall_Detail_Anta>();//上期没有数据但是以前有的

            #region 本次没有 上次-本次
            foreach (var del in dic_Excel)
            {
                if (!orm_Dic.ContainsKey((UInt64)del.Key))
                {
                    dic_Xiajia.Add((UInt64)del.Key, del.Value);
                }
            }
            #endregion

            #region 本次新上
            foreach (var od in orm_Dic)
            {
                if (!dic_Excel.ContainsKey((Int64)od.Key))
                {
                    dic_Shangjia.Add(od.Key, od.Value);
                }
            }
            #endregion
            string date = DateTime.Now.Date.ToShortDateString();
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter("result_Anta.csv", false, Encoding.UTF8))
            {
                sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18}", "商品ID", "首页价格(周)", "", "", "首页价格(月)", "期末月销量", "", "", "期末总销量", "", "", "库存", "", "", "月评论", "总评论", "期末月销售额", "期间销售量", "期间销售额");
                sw.WriteLine("{0}", "新品");
                List <long> have = new List <long>();
                foreach (var dsj in dic_Shangjia)
                {
                    if (IsNew((long)dsj.Key, dsj.Value.LastUpdate, "tmall_detail_anta"))
                    {
                        have.Add((long)dsj.Key);
                        sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}", "=" + "\"" + dsj.Key + "\"", 0, 0, dsj.Value.IndexPrice, 0, 0, 0, dsj.Value.Sales_Mon, 0, 0, dsj.Value.Sales_Total, 0, 0, dsj.Value.Repertory, dsj.Value.Comments_Mon, dsj.Value.Comments_Total);
                    }
                    else
                    {
                        dic_SjNo.Add(dsj.Key, dsj.Value);
                    }
                }
                sw.WriteLine("{0}", "旧款");
                foreach (var dx in dic_Xiajia)
                {
                    have.Add((long)dx.Key);
                    sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}", "=" + "\"" + dx.Key + "\"", dx.Value[1], dx.Value[2], 0, dx.Value[3], dx.Value[4], dx.Value[5], 0, dx.Value[6], dx.Value[7], 0, dx.Value[8], dx.Value[9], 0, 0, 0, 0, 0);
                }
                sw.WriteLine("{0}", "热卖");
                foreach (var die in dic_Excel)
                {
                    if (!have.Contains((long)die.Key))
                    {
                        sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}", "=" + "\"" + die.Key + "\"", die.Value[1], die.Value[2], orm_Dic[(ulong)die.Key].IndexPrice, die.Value[3], die.Value[4], die.Value[5], orm_Dic[(ulong)die.Key].Sales_Mon, die.Value[6], die.Value[7], orm_Dic[(ulong)die.Key].Sales_Total, die.Value[8], die.Value[9], orm_Dic[(ulong)die.Key].Repertory, orm_Dic[(ulong)die.Key].Comments_Mon, orm_Dic[(ulong)die.Key].Comments_Total, 0, 0);
                    }
                }
                sw.WriteLine("{0}", "总计:");

                sw.Close();
            }
            Console.WriteLine("---------输出Csv----------");
        }