private void ImportPageEvaluate(RemunerationEntities entity) { var datas = from editor in entity.art_verOfPage_evaluate.Where(p => p.ymd == 0) join page in entity.sys_paper_verOfPage on editor.vid equals page.vid select new { editor, page.publishDate }; int total = datas.Count(); int count = 0; foreach (var data in datas.ToArray()) { data.editor.ymd = int.Parse(data.publishDate.ToString("yyyyMM")); data.editor.paperId = 1; entity.SaveChanges(); Console.Write("\r版面数据导入...............{0}%", (++count * 100) / total); System.Threading.Thread.Sleep(50); } Console.WriteLine("\r版面数据转换完成"); }
private void ImportDeclareAuthor(RemunerationEntities entity) { var datas = from author in entity.rpt_declareAuthor.Where(p => p.ymd == 0) join declare in entity.rpt_declareArt on author.articleId equals declare.id join article in entity.art_article on declare.sourceArticleId equals article.id select new { author, article.publishDate }; int total = datas.Count(); int count = 0; foreach (var data in datas.ToArray()) { data.author.ymd = int.Parse(data.publishDate.ToString("yyyyMM")); data.author.paperId = 1; entity.SaveChanges(); Console.Write("\r特约申报数据导入...............{0}%", (++count * 100) / total); System.Threading.Thread.Sleep(50); } Console.WriteLine("\r特约申报数据转换完成"); }
private void ImportArticle(RemunerationEntities entity) { try { DateTime start = new DateTime(2017, 1, 1); DateTime end = new DateTime(2017, 12, 31); var query = entity.art_article.Where(p => p.newsId == 0 && p.publishDate >= start && p.publishDate < end && p.publishType == 0).OrderBy(p => p.id); int total = query.Count(); for (int count = 0; count < total;) { foreach (var a in query.Take(20).ToArray()) { using (var tran = new TransactionScope()) { var news = entity.cb_news.Add(new cb_news { cbNewsId = a.matchFromCB ?? 0, fromType = a.stat == 404 ? 1 : 0, title = a.title, publishDate = a.publishDate, setDate = a.setdate, hasEvaluate = false, evaluateUserId = 0, evaluateUserName = "", paperId = a.paperId, baseScore = a.baseScore, otherPlaceScale = a.otherPlaceScore, isHolidy = a.holidy > 0, specialScore = 0, transmissionScore = 0, score = a.score, flowRecord = a.flowRecord, evaluateContent = a.evaluateContent ?? "", affiliatedScore = "" }); entity.SaveChanges(); a.newsId = news.id; foreach (var au in entity.art_author.Where(p => p.articleId == a.id).ToArray()) { entity.cb_author.Add(new cb_author { newsId = a.newsId, authorId = au.authorId, typeSign = au.typeSign, authorName = au.authorName, coefficient = (decimal)au.coefficient, scoreScale = au.scoreScale, score = au.score, salary = au.salary, ymd = int.Parse(a.publishDate.ToString("yyyyMM")), paperId = a.paperId, affiliatedScore = "" }); } entity.SaveChanges(); tran.Complete(); Console.Write("\r稿件数据导入...............{0}%", (++count * 100) / total); System.Threading.Thread.Sleep(50); } } } Console.WriteLine("\r稿件数据转换完成"); } catch (Exception ex) { throw ex; } }
public override void process() { List <EvaluateArticle> list = new List <EvaluateArticle>(); var cbEntity = WebCBEntitiesFactory.CreateWebEntitie(); var datas = (from pne in cbEntity.pub_newsofweibo.Where(p => !p.synch && p.commitDate.HasValue) select new { Id = pne.id, userId = pne.userid, cbNewsId = pne.sourceId, strAuthorId = "", pne.content, txtContent = pne.content, title = pne.content, pageview = 0, evaluateCategoryId = 0, articleType = 4, publishDate = pne.commitDate.Value, fromWhere = pne.fromwhere, pne.fabulousNumber, pne.forwardsNumber, pne.commentsNumber, pne.disseminationNumber, ReprintChannelNumber = 0, ReprintChannelTime = 0, ReprintMediaNumber = 0, ReprintNumber = 0, ReadingNumber = 0 }).Union( from pn in cbEntity.pub_newsofweixin.Where(p => !p.synch && p.commitDate.HasValue && p.txtContent != null) select new { Id = pn.id, userId = pn.userid, cbNewsId = pn.fromNewsId, strAuthorId = pn.strAuthorId, pn.content, pn.txtContent, pn.title, pageview = 0, evaluateCategoryId = pn.evaluateCategoryId, articleType = 3, publishDate = pn.commitDate.Value, fromWhere = pn.strAuthor, fabulousNumber = 0, forwardsNumber = 0, commentsNumber = 0, disseminationNumber = pn.DisseminationNumber, pn.ReprintChannelNumber, pn.ReprintChannelTime, pn.ReprintMediaNumber, pn.ReprintNumber, pn.ReadingNumber }).Union(from pne in cbEntity.pub_newsofwebsite.Where(p => !p.synch && p.commitDate.HasValue) select new { Id = pne.id, userId = pne.userid, cbNewsId = pne.sourceId, strAuthorId = "", pne.content, txtContent = pne.txtContent, title = pne.title, pageview = 0, evaluateCategoryId = 0, articleType = 1, publishDate = pne.commitDate.Value, fromWhere = pne.fromwhere, fabulousNumber = 0, forwardsNumber = 0, commentsNumber = 0, disseminationNumber = pne.DisseminationNumber, pne.ReprintChannelNumber, pne.ReprintChannelTime, pne.ReprintMediaNumber, pne.ReprintNumber, pne.ReadingNumber }); foreach (var data in datas) { var authorIds = data.strAuthorId.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)); var authors = cbEntity.v_user_info.Where(p => authorIds.Contains(p.userid) && p.typeId == 0).Select(p => new Author { authorId = p.userid, authorName = p.realname, departmentId = p.departmentId ?? 0, departmentName = p.departmentName }).ToArray(); var kv = cbEntity.sys_dictionary.SingleOrDefault(p => p.id == data.evaluateCategoryId); var evaluateCategoryName = ""; if (kv == null) { NLog.LogManager.GetCurrentClassLogger().Error(string.Format("稿件分类未在字典中找到值,字典Id:{0},稿件Id:{1}", data.evaluateCategoryId, data.Id)); } else { evaluateCategoryName = kv.keyValue; } var art = new EvaluateArticle { id = data.Id, cbNewsId = data.cbNewsId, txtContent = data.txtContent, title = data.title, pageView = data.pageview, evaluateCategoryId = data.evaluateCategoryId, evaluateCategoryName = evaluateCategoryName, articleType = data.articleType, authors = authors, hasPic = regImg.Matches(data.content).Count > 0, hasAudio = regAudio.Matches(data.content).Count > 0, hasVedio = regVideo.Matches(data.content).Count > 0, publishDate = new DateTime(data.publishDate.Year, data.publishDate.Month, data.publishDate.Day), paperId = GetPaperId(data.fromWhere), fromWhere = data.fromWhere, disseminationNumber = data.disseminationNumber, commentsNumber = data.commentsNumber, fabulousNumber = data.fabulousNumber, forwardsNumber = data.forwardsNumber, ReadingNumber = data.ReadingNumber, ReprintChannelNumber = data.ReprintChannelNumber, ReprintChannelTime = data.ReprintChannelTime, ReprintMediaNumber = data.ReprintMediaNumber, ReprintNumber = data.ReprintNumber }; art.baseScore = 0; list.Add(art); } cbEntity.Dispose(); List <Tuple <int, int> > synchIds = new List <Tuple <int, int> >(); using (RemunerationEntities entity = RemunerationEntities.Create()) { foreach (var a in list) { synchIds.Add(new Tuple <int, int>(a.id, a.articleType)); if (entity.art_article.Count(p => p.matchFromCB == a.id && p.publishType == a.articleType) > 0) { continue; } using (var tran = new TransactionScope()) { //var fromType = fromWhere[a.fromWhere]; var fromType = 0; Remuneration.Dal.cb_news news = null; if (a.cbNewsId > 0) { news = (from n in entity.cb_news.Where(p => p.cbNewsId == a.cbNewsId && p.fromType == fromType) join art in entity.art_article.Where(p => p.picCount == 0) on n.id equals art.newsId select n).FirstOrDefault(); } var strtitle = a.title; if (strtitle.Length > 30) { strtitle = strtitle.Substring(0, 30); } if (news == null) { news = new Remuneration.Dal.cb_news() { cbNewsId = a.cbNewsId, fromType = fromType, title = strtitle, publishDate = a.publishDate, setDate = DateTime.Now, hasEvaluate = false, paperId = a.paperId, baseScore = 0, otherPlaceScale = 0, isHolidy = false, specialScore = 0, transmissionScore = 0, score = 0, flowRecord = "", evaluateContent = "", affiliatedScore = "" }; entity.cb_news.Add(news); entity.SaveChanges(); } else { news.hasEvaluate = false; } #region 保存art_article entity.art_article.Add(new art_article { leadTitle = "", title = strtitle, subTitle = "", txtContent = a.txtContent, wordCount = a.txtContent.Length, author = string.Join(",", a.authors.Select(p => p.authorName)), authorIds = string.Join(",", a.authors.Select(p => p.authorId)), departmentIds = string.Join(",", a.authors.Select(p => p.departmentId)), departmentNames = string.Join(",", a.authors.Select(p => p.departmentName)), picCount = 0, publishDate = a.publishDate, coordinate = "", verOfPagePicWidth = 0, verOfPagePicHeight = 0, verOfPagePicPath = "", picPath = "", setdate = DateTime.Now, paperId = a.paperId, paperName = "", verOfPageId = 0, verOfPageName = "", orderOfPageId = 0, orderOfPageName = "", stat = 0, auditUserId = 0, auditUserName = "", auditDate = null, categoryId = a.evaluateCategoryId, categoryName = a.evaluateCategoryName, editer = "", setLevelUserId = 0, setLevelUserName = "", levelId = 0, levelName = "", sendType = "", unit = "", salary = 0, remark = a.fromWhere, flowRecord = "", isBackToUpdate = 0, patchNewsTypeId = 0, baseScore = a.baseScore, score = 0, otherPlace = 0, otherPlaceScore = 0, holidy = 0, holidyScore = 0, other = 0, otherScore = 0, specialScore = 0, transmissionQuantity = a.pageView, transmissionScore = 0, evaluateContent = "", matchFromCB = a.id, publishType = a.articleType, hasPic = a.hasPic, hasAudio = a.hasAudio, hasVedio = a.hasVedio, @abstract = "", newsId = news.id, levelScore = 0, forwardsNumber = a.forwardsNumber, fabulousNumber = a.fabulousNumber, commentsNumber = a.commentsNumber, disseminationNumber = a.disseminationNumber, ReprintNumber = a.ReprintNumber, ReprintMediaNumber = a.ReprintMediaNumber, ReadingNumber = a.ReadingNumber, ReprintChannelNumber = a.ReprintChannelNumber, ReprintChannelTime = a.ReprintChannelTime }); #endregion foreach (var author in a.authors) { if (entity.cb_author.Count(p => p.newsId == news.id && p.authorId == author.authorId && p.typeSign == 0) > 0) { continue; } entity.cb_author.Add(new cb_author { newsId = news.id, authorId = author.authorId, typeSign = 0, authorName = author.authorName, coefficient = 0, scoreScale = 0, score = 0, salary = 0, ymd = int.Parse(a.publishDate.ToString("yyyyMM")), paperId = a.paperId, affiliatedScore = "" }); } entity.SaveChanges(); tran.Complete(); System.Threading.Thread.Sleep(50); } } } using (cbEntity = WebCBEntitiesFactory.CreateWebEntitie()) { foreach (var data in synchIds) { switch (data.Item2) { case 1: { var pne = cbEntity.pub_newsofwebsite.SingleOrDefault(p => p.id == data.Item1); if (pne != null) { pne.synch = true; } break; } case 2: { var pne = cbEntity.pub_newsofapp_evaluate.SingleOrDefault(p => p.Id == data.Item1); if (pne != null) { pne.synch = true; } break; } case 3: { var pne = cbEntity.pub_newsofweixin.SingleOrDefault(p => p.id == data.Item1); if (pne != null) { pne.synch = true; } break; } case 4: { var pne = cbEntity.pub_newsofweibo.SingleOrDefault(p => p.id == data.Item1); if (pne != null) { pne.synch = true; } break; } default: break; } } cbEntity.SaveChanges(); } Console.WriteLine("Finish"); }
public override void process() { using (RemunerationEntities entity = RemunerationEntities.Create()) { var depts = entity.sys_assessmentDepartment.GroupBy(p => p.paperId).Select(p => new { paperId = p.Key, departmentIds = p.Select(d => d.departmentId) }).ToArray(); var postions = entity.sys_user_position.ToArray(); foreach (var dept in depts) { var cbEntity = WebCBEntitiesFactory.CreateWebEntitie(); var users = (from u in cbEntity.v_user_info.Where(p => dept.departmentIds.Contains(p.departmentId.Value) && p.deleted == 0).ToArray() join p in postions on u.userid equals p.userId into Postions from p in Postions.DefaultIfEmpty() select new { user = u, positionId = p == null ? 0 : p.positionId, postionName = p == null ? "" : p.positionName }).ToArray(); cbEntity.Dispose(); int ymd = int.Parse(DateTime.Now.ToString("yyyyMM")); foreach (var user in users) { var item = entity.rpt_authorEvaluateScoreList.SingleOrDefault(p => p.authorId == user.user.userid && p.ymd == ymd && p.paperId == dept.paperId); if (item == null) { entity.rpt_authorEvaluateScoreList.Add(new rpt_authorEvaluateScoreList { authorId = user.user.userid, authorName = user.user.realname, departmentId = user.user.departmentId.Value, departmentName = user.user.departmentName, positionId = user.positionId, positionName = user.postionName, ymd = ymd, score = 0, achievementsSalary = 0, circumstancesScore = 0, levelId = 0, levelName = "", finishVerOfPageNum = 0, finishVerOfPageSalary = 0, finishVerOfPageScore = 0, departmentTotalSalary = 0, departmentSalary = 0, departmentPeopleNum = 0, paperId = dept.paperId, assessmentSalary = 0, addSalary = 0, vacationSalary = 0, workSalary = 0, totalAmount = 0, addRemark = "", fixedAmount = 0, noJoinAssessment = 0 }); entity.SaveChanges(); } if (user.positionId == DirectorPositionId && entity.sys_user_noJoinAssessment.Count(p => p.userId == user.user.userid && p.ymd == ymd) == 0) { entity.sys_user_noJoinAssessment.Add(new sys_user_noJoinAssessment { userId = user.user.userid, ymd = ymd }); entity.SaveChanges(); } } } } }