private static List <long> beginImportPrivate(ImportState ts) { long id = ts.TemplateId; SpiderImport item = SpiderImport.findById(id); List <SpiderArticle> articles = SpiderArticle .find("SpiderTemplateId in (" + item.DataSourceIds + ") and Id>" + item.LastImportId + " order by Id") .list(); List <ContentSection> sections = ContentSection.find("Id in (" + item.SectionIds + ")").list(); if (sections.Count == 0) { throw new Exception("导入的目标section不存在"); } ContentSection section = null; List <long> results = new List <long>(); for (int i = 0; i < articles.Count; i++) { if (articleExist(articles[i])) { ts.Log.AppendLine("pass..." + articles[i].Title); continue; } section = getNextSection(sections, section); // 均匀分散到各目标section中 ContentApp app = getApp(section); if (item.IsApprove == 1) { importToTemp(articles[i], item, section, app); } else { long newArticleId = importDirect(articles[i], item, section, app); results.Add(newArticleId); } ts.Log.AppendLine("导入:" + articles[i].Title); } if (articles.Count > 0) { item.LastImportId = articles[articles.Count - 1].Id; item.update("LastImportId"); ts.Log.AppendLine("导入完毕(操作结束)"); } else { ts.Log.AppendLine("没有新条目可导入(操作结束)"); } return(results); }
//检查数据库中是否已经存在此数据? private static bool isPageExist(string pageUrl, StringBuilder sb) { bool isExist = false; List <SpiderArticle> list = SpiderArticle.find("Url=:url and IsDelete=0").set("url", pageUrl).list(); if (list.Count > 0) { logger.Info("pass..." + pageUrl); sb.AppendLine("pass..." + pageUrl); isExist = true; } return(isExist); }