コード例 #1
0
ファイル: MovieTypeService.cs プロジェクト: guipie/Api
        public async Task <IList <MovieWebsiteTypeRelation> > GetTypesRelationAsync(SysMovieWebsite website)
        {
            List <string> types = await MovieCrawlerCore.Instance(website).GetMovieTypes();

            if (types.Count == 0)
            {
                types = await MovieCrawlerCore.Instance(website).GetMovieTypes();
            }
            if (types.Count == 0)
            {
                throw new BusinessException($"未抓取到{website.GetRemark()}类别");
            }
            int    siteId       = website.GetEnumValue <SysMovieWebsite>();
            string querySql     = "SELECT a.Id,TypeId,a.Name SiteTypeName,b.Name TypeName from movie_website_type a left JOIN movie_type b on a.TypeId=b.Id where a.SiteId=@SiteId";
            var    typeRelation = repository.DapperContext.QueryList <MovieWebsiteTypeRelation>(querySql, new { SiteId = siteId }).ToList();
            var    list         = from t1 in types
                                  join t2 in typeRelation on t1 equals t2.SiteTypeName into temp
                                  from tt in temp.DefaultIfEmpty()
                                  select new MovieWebsiteTypeRelation
            {
                Id           = tt == null ? 0 : tt.Id,
                TypeId       = tt == null ? 0 : tt.TypeId,
                TypeName     = tt == null ? "" : tt.TypeName,
                SiteTypeName = t1,
                SiteId       = siteId
            };

            return(list.ToList());
        }
コード例 #2
0
ファイル: MovieWebsiteServiceHub.cs プロジェクト: guipie/Api
        /// <summary>
        /// 爬取任务
        /// </summary>
        /// <param name="movieWebsite"></param>
        /// <returns></returns>
        public async Task <WebResponseContent> CrawlingMonitor(SysMovieWebsite movieWebsite, string type = "all")
        {
            if (IMovieCrawlerFactory.taskStatus != 3 && IMovieCrawlerFactory.taskStatus != -1)
            {
                return(WebResponseContent.Instance.Error("有正在进行的采集任务,请清空后再试.."));
            }
            CrawlingReset();
            IMovieCrawler factory   = MovieCrawlerCore.Instance(movieWebsite);
            int           pageCount = await factory.GetPageCount();

            IMovieCrawlerFactory.CrawlingType = type;

            if (pageCount > 0)
            {
                factory.Crawling(pageCount); return(WebResponseContent.Instance.OK("任务初始化成功,请查看监控日志", pageCount));
            }
            return(WebResponseContent.Instance.Error("任务初始化失败,请重试"));
        }