Example #1
0
        /// <summary>
        /// 补充获取菜谱列表
        /// </summary>
        /// <param name="reprocessPageIndex"></param>
        /// <returns></returns>
        private async Task <ProcessResult> ReGetCookList(List <string> reprocessPageIndex)
        {
            var processresult = new ProcessResult();

            foreach (var i in reprocessPageIndex)
            {
                CookListEntity data = null;
                try
                {
                    data = await recipeServer.GetCookListByPage(i.ToString());
                }
                catch (Exception e)
                {
                    processresult.Add("补取菜谱列表获取或解析", ProcessResultType.失败, e.Message, new string[] { "当前页" + i });
                    continue;
                }
                if (data != null && data.Status)
                {
                    processresult.Add("补取菜谱列表数据验证", ProcessResultType.成功, data.Tngou.Count().ToString(), new string[] { "当前页" + i });
                }
                else
                {
                    processresult.Add("补取菜谱列表数据验证", ProcessResultType.失败, "返回数据状态为Flase", new string[] { "当前页" + i });

                    continue;
                }
                var datamodel = data.Tngou.Select(c => new cook_show_item()
                {
                    Id    = c.Id,
                    count = c.Count,
                    //description = c.Description,
                    fcount = c.Fcount,
                    food   = GetShortStr(c.Food, 299),
                    img    = c.Img,
                    name   = c.Name,
                    rcount = c.Rcount
                }).ToList();

                foreach (var cookShowItem in datamodel)
                {
                    try
                    {
                        var result = DBHelper.Context.Insert(cookShowItem);
                        processresult.Add("菜谱数据插入", ProcessResultType.成功, result.ToString(), new string[] { "当前页" + i, "当前ID" + cookShowItem.Id });
                    }
                    catch (Exception e)
                    {
                        processresult.Add("菜谱数据插入", ProcessResultType.失败, e.Message, param: new string[] { "当前页" + i, "当前ID" + cookShowItem.Id });
                        continue;
                    }
                }
            }
            return(processresult);
        }
Example #2
0
        public async Task <CookListEntity> GetCookListByPage(string parameter)
        {
            var    result = new CookListEntity();
            string url    = StaticURLHelper.CookList;
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("page", parameter);
            var jsonstr = await GetJSON(url, dic);

            result = JsonConvert.DeserializeObject <CookListEntity>(jsonstr);
            return(result);
        }
        public CookListEntity CookList(int pageIndex, int rowCount)
        {
            CookListEntity result = new CookListEntity();
            var            dbdata = DBHelper.Context.From <cook_show_item>().Page(rowCount, pageIndex);

            if (dbdata != null)
            {
                result.Tngou = dbdata.ToEnumerable().Select(c => new CookListItem()
                {
                    Id     = c.Id,
                    Count  = c.count ?? 0,
                    Fcount = c.fcount ?? 0,
                    Food   = c.food,
                    Img    = c.img,
                    Name   = c.name,
                    Rcount = c.rcount ?? 0
                }).ToList();
                result.Status = true;
            }
            return(result);
        }
        public CookListEntity CookList(string name)
        {
            CookListEntity result = new CookListEntity();
            var            dbdata = DBHelper.Context.From <cook_show_item>().Where(c => c.name.Contains(name));

            if (dbdata != null)
            {
                result.Tngou = dbdata.ToEnumerable().Select(c => new CookListItem()
                {
                    Id     = c.Id,
                    Count  = c.count ?? 0,
                    Fcount = c.fcount ?? 0,
                    Food   = c.food,
                    Img    = c.img,
                    Name   = c.name,
                    Rcount = c.rcount ?? 0
                }).ToList();
                result.Status = true;
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// 获取各个菜谱的分类并更新列表
        /// </summary>
        /// <returns></returns>
        public async Task <ProcessResult> GetShowItemClassify()
        {
            var processresult = new ProcessResult();
            var clearresult   = DBHelper.Context.DeleteAll <cook_2_cook_classify>();

            processresult.Add(ProcessResult.CleanDB, ProcessResultType.成功, clearresult.ToString(), new[] { "show_item_classify" });

            var subClassify = DBHelper.Context.From <cook_classify>().Where(c => c.seq == 1).ToList();

            foreach (var item in subClassify)
            {
                for (int i = 1; i < int.MaxValue; i++)
                {
                    CookListEntity data = null;
                    try
                    {
                        data = await recipeServer.GetCookListById(i.ToString(), item.Id.ToString());
                    }
                    catch (Exception e)
                    {
                        processresult.Add("菜谱列表获取或解析", ProcessResultType.失败, e.Message, new string[] { "当前子类" + item.Id, "当前页" + i });
                        continue;
                    }

                    if (data != null && data.Status)
                    {
                        if (data.Tngou.Count == 0)
                        {
                            processresult.Add("菜谱列表数据验证", ProcessResultType.成功, "无数据表明已经结束", new string[] { "当前子类" + item.Id, "当前页" + i });

                            break;
                        }
                        processresult.Add("菜谱列表数据验证", ProcessResultType.成功, data.Tngou.Count().ToString(), new string[] { "当前子类" + item.Id, "当前页" + i });
                    }
                    else
                    {
                        processresult.Add("菜谱列表数据验证", ProcessResultType.失败, "返回数据状态为Flase", new string[] { "当前子类" + item.Id, "当前页" + i });

                        continue;
                    }
                    var datamodel = data.Tngou.Select(c => new cook_2_cook_classify()
                    {
                        item_id     = c.Id,
                        classify_id = item.Id
                    }).ToList();

                    try
                    {
                        var result = DBHelper.Context.Insert(datamodel);
                        processresult.Add("菜谱类型数据插入", ProcessResultType.成功, result.ToString(), new string[] { "当前子类" + item.Id, "当前页" + i });
                    }
                    catch (Exception e)
                    {
                        processresult.Add("菜谱类型数据插入", ProcessResultType.失败, e.Message, new string[] { "当前子类" + item.Id, "当前页" + i });
                        continue;
                    }
                }
            }

            return(processresult);
        }
Example #6
0
        /// <summary>
        /// 获取菜谱列表
        /// </summary>
        /// <returns></returns>
        public async Task <ProcessResult> GetCookShowItem()
        {
            var processresult = new ProcessResult();


            var clearresult = DBHelper.Context.DeleteAll <cook_show_item>();

            processresult.Add(ProcessResult.CleanDB, ProcessResultType.成功, clearresult.ToString(), new[] { "cook_show_item" });
            int flag = 0;

            for (int i = 1; i < int.MaxValue; i++)
            {
                CookListEntity data = null;
                try
                {
                    data = await recipeServer.GetCookListByPage(i.ToString());
                }
                catch (Exception e)
                {
                    processresult.Add("菜谱列表获取或解析", ProcessResultType.失败, e.Message, new string[] { "当前页" + i });
                    continue;
                }
                if (data != null && data.Status)
                {
                    if (data.Tngou.Count == 0)
                    {
                        processresult.Add("菜谱列表数据验证", ProcessResultType.成功, "无数据表明已经结束", new string[] { "当前页" + i });
                        if (flag > 5)
                        {
                            break;
                        }
                        flag++;
                        continue;
                    }
                    processresult.Add("菜谱列表数据验证", ProcessResultType.成功, data.Tngou.Count().ToString(), new string[] { "当前页" + i });
                }
                else
                {
                    processresult.Add("菜谱列表数据验证", ProcessResultType.失败, "返回数据状态为Flase", new string[] { "当前页" + i });

                    continue;
                }
                var datamodel = data.Tngou.Select(c => new cook_show_item()
                {
                    Id    = c.Id,
                    count = c.Count,
                    //description = c.Description,
                    fcount = c.Fcount,
                    food   = GetShortStr(c.Food, 299),
                    img    = c.Img,
                    name   = c.Name,
                    rcount = c.Rcount
                }).ToList();
                try
                {
                    var result = DBHelper.Context.Insert(datamodel);
                    processresult.Add("菜谱数据插入", ProcessResultType.成功, result.ToString(), new string[] { "当前页" + i });
                }
                catch (Exception e)
                {
                    processresult.Add("菜谱数据插入", ProcessResultType.失败, e.Message, param: new string[] { "当前页" + i });
                    continue;
                }
            }



            return(processresult);
        }