/// <summary> /// 解锁Host用户 /// </summary> private static void HostUnLock() { lock (lockObj) { using (var db = new ResumeMatchDBEntities()) { db.UsingTransaction(() => { string host; while (hostQueue.TryDequeue(out host)) { var hostUnLock = host; var users = db.User.Where(w => w.Host == hostUnLock && w.IsLocked).ToList(); foreach (var user in users) { user.IsLocked = false; } } foreach (var item in hostList) { if (string.IsNullOrWhiteSpace(item)) { continue; } var users = db.User.Where(w => w.Host == item && w.IsLocked).ToList(); foreach (var user in users) { user.IsLocked = false; } } db.SaveChanges(); hostList.Clear(); }); } } }
public void ChangeResumeStatus(string resumeId, bool isMatchd) { using (var db = new ResumeMatchDBEntities()) { var resume = db.OldResumeSummary.FirstOrDefault(f => f.ResumeId == resumeId); if (resume == null) { return; } resume.Status = 1; resume.MatchTime = DateTime.Now; resume.IsMatched = isMatchd; db.SaveChanges(); } }
/// <summary> /// 解锁简历 /// </summary> private static void ResumeUnLock() { lock (lockObj) { using (var db = new ResumeMatchDBEntities()) { db.UsingTransaction(() => { KeyValuePair <string, List <ResumeComplete> > hostResume; while (resumeQueue.TryDequeue(out hostResume)) { var resumeIdArr = hostResume.Value.Select(s => s.Id).ToArray(); var resumes = db.ResumeComplete.Where(w => resumeIdArr.Any(a => a == w.Id) && w.IsLocked).ToList(); foreach (var resume in resumes) { resume.IsLocked = false; } } foreach (var item in hostResumeList) { var resumeIdArr = item.Value.Select(s => s.Id).ToArray(); var resumes = db.ResumeComplete.Where(w => resumeIdArr.Any(a => a == w.Id) && w.IsLocked).ToList(); foreach (var resume in resumes) { resume.IsLocked = false; } } db.SaveChanges(); }); } } }
private void Download() { lock (lockObj) { var resumes = new List <ResumeComplete>(); using (var db = new ResumeMatchDBEntities()) { db.UsingTransaction(() => { var dateTime = DateTime.UtcNow.AddHours(-1); var today = DateTime.UtcNow.Date.AddHours(-8); var downloadUserArr = db.User .Where(w => w.IsEnable && (string.IsNullOrEmpty(w.Host) || !string.IsNullOrEmpty(w.Host) == Global.IsEnanbleProxy) && (w.DownloadNumber > 0 || w.LastLoginTime < today || w.LastLoginTime == null)) .GroupBy(g => new { g.Host, g.Platform }) .Select(s => s.Key) .Distinct() .ToList(); var query = db.ResumeComplete .Where(w => w.Status == 2 && (!w.IsLocked || w.IsLocked && w.LockedTime < dateTime)); var platformList = downloadUserArr.GroupBy(g => g.Platform).Select(s => s.Key).ToList(); var hostList = downloadUserArr.GroupBy(g => g.Host) /*.Where(w=>!string.IsNullOrEmpty(w.Key))*/.Select(s => s.Key).ToList(); // 排除本地HOST foreach (var item in platformList) { resumes.AddRange(query .Where(w => w.MatchPlatform == item) .OrderByDescending(o => o.Weights) .ThenByDescending(o => o.MatchTime) .Take(20)); } resumes = resumes.Where(w => w.Weights == 1 && w.MatchPlatform == 4) // Todo:当前只优先下载泽林的简历 .OrderByDescending(o => o.Weights) .ThenByDescending(o => o.MatchTime) .Take(20).ToList(); foreach (var resume in resumes) { resume.IsLocked = true; resume.LockedTime = DateTime.UtcNow; } db.SaveChanges(); var count = resumes.Count / hostList.Count + 1; for (var i = 0; i < hostList.Count; i++) { var temp = resumes.Skip(i * count).Take(count).ToList(); if (temp.Any()) { resumeQueue.Enqueue(new KeyValuePair <string, List <ResumeComplete> >(hostList[i], temp)); } } }); } } KeyValuePair <string, List <ResumeComplete> > hostResume; while (resumeQueue.TryDequeue(out hostResume)) { var hostResumeTemp = hostResume; hostResumeList.Add(hostResumeTemp); if (!string.IsNullOrWhiteSpace(hostResumeTemp.Key)) { GetProxy("Download", hostResumeTemp.Key); } Work(hostResumeTemp.Key, hostResumeTemp.Value); ReleaseProxy("Download", hostResumeTemp.Key); if (isEnd) { ResumeUnLock(); } hostResumeList.Remove(hostResumeTemp); } }
/// <summary> /// 匹配 /// </summary> private void Match() { lock (lockObj) { if (!hostQueue.Any() && isFirst) { hostQueue.Enqueue("210.83.225.31:15839"); isFirst = false; } var users = new List <User>(); using (var db = new ResumeMatchDBEntities()) { db.UsingTransaction(() => { var dateTime = DateTime.UtcNow.AddHours(-1); var nowDate = DateTime.UtcNow.Date; users = db.User .Where(w => w.IsEnable && w.Status == 1 && (w.RequestDate.Value == null || w.RequestDate.Value < nowDate || w.RequestDate.Value == nowDate && w.RequestNumber < Global.TodayMaxRequestNumber) && (!w.IsLocked || w.IsLocked && w.LockedTime < dateTime) && (string.IsNullOrEmpty(w.Host) || !string.IsNullOrEmpty(w.Host) == Global.IsEnanbleProxy)) .OrderBy(o => o.RequestNumber) .ThenByDescending(o => o.Host) //.Take(Global.PlatformCount * Global.PlatformHostCount * 2) .ToList(); foreach (var user in users) { user.IsLocked = true; user.LockedTime = DateTime.UtcNow; } db.SaveChanges(); }); } var hosts = users .Where(w => w.IsEnable && w.Host != "210.83.225.31:15839") .GroupBy(g => g.Host) .Select(s => new { Host = s.Key, Count = s.Count() }) .OrderByDescending(o => o.Count) .ToList(); hosts.ForEach(f => { hostQueue.Enqueue(f.Host); }); } string host; while (hostQueue.TryDequeue(out host)) { var hostTemp = host; hostList.Add(hostTemp); if (!string.IsNullOrWhiteSpace(hostTemp)) { GetProxy("Match", hostTemp); } while (true) { List <ResumeSearch> resumes; while (true) { try { resumes = ResumeProducer.PullResumes(); break; } catch (Exception ex) { while (true) { if (ex.InnerException == null) { break; } ex = ex.InnerException; } LogFactory.Error($"拉取待匹配的简历异常!异常信息:{ex.Message},堆栈信息:{ex.StackTrace}"); } } if (resumes != null && resumes.Count > 0) { Console.WriteLine(string.Join(",", resumes.Select(s => s.Name).ToArray())); if (!Work(hostTemp, resumes)) { break; } } } ReleaseProxy("Match", hostTemp); //hostList.Remove(hostTemp); LogFactory.Info("Host 消费记录:" + JsonConvert.SerializeObject(hostQueue)); } HostUnLock(); }
/// <summary> /// 激活 /// </summary> private static void Activation() { var users = new List <User>(); lock (lockObj) { using (var db = new ResumeMatchDBEntities()) { db.UsingTransaction(() => { var time = DateTime.UtcNow.AddHours(-1); users = db.User.Where(w => w.Status == 0 && w.Platform == 3 && (!w.IsLocked || w.IsLocked && w.LockedTime < time)).ToList(); foreach (var user in users) { user.IsLocked = true; user.LockedTime = DateTime.UtcNow; } db.SaveChanges(); }); } } if (users.Count == 0) { return; } #region 获取未读邮件列表 var seenUids = new List <string>(); var messages = EmailFactory.FetchUnseenMessages("pop.exmail.qq.com", 995, true, Global.Email, Global.PassWord, seenUids); using (var db = new ResumeMatchDBEntities()) { var userIdArr = users.Select(s => s.Id).ToArray(); var userList = db.User.Where(w => userIdArr.Any(a => a == w.Id)); foreach (var user in userList) { user.IsLocked = false; var message = messages.FirstOrDefault(f => f.message.Headers.To.FirstOrDefault()?.Address == user.Email); if (message == null) { continue; } var content = Encoding.Default.GetString(message.message.RawMessage); if (!Regex.IsMatch(content, "(?s)token=(.+?)</a>")) { LogFactory.Error($"未匹配到激活码!响应源:{content}", MessageSubjectEnum.JianLiKa); continue; } var activationCode = Regex.Match(content, "(?s)token=(.+?)</a>").Result("$1").Substring(2); var host = string.Empty; //if (Global.IsEnanbleProxy) //{ // if (!string.IsNullOrWhiteSpace(user.Host)) // { // host = user.Host; // GetProxy("JLK_Activation",user.Host); // } //} var dataResult = Activation(activationCode, user.Email, host); //ReleaseProxy("JLK_Activation", host); if (dataResult == null) { continue; } if (!dataResult.IsSuccess) { LogFactory.Error(dataResult.ErrorMsg, MessageSubjectEnum.JianLiKa); continue; } user.Status = 1; LogFactory.Info($"激活成功!邮箱:{user.Email}", MessageSubjectEnum.JianLiKa); if (!EmailFactory.DeleteMessageByMessageId("pop.exmail.qq.com", 995, true, Global.Email, Global.PassWord, message.message.Headers.MessageId)) { LogFactory.Error($"删除激活邮件失败,邮箱地址:{user.Email}", MessageSubjectEnum.JianLiKa); } } db.TransactionSaveChanges(); } #endregion }
public List <SearchResumeModel> GetOldResumes() { var searchResumeList = new List <SearchResumeModel>(); using (var db = new ResumeMatchDBEntities()) { var resumeList = db.OldResumeSummary.Where(w => w.ResumeId.Length == 11 && !w.IsMatched && (w.Status == 0 || w.Status == 99)).Take(500).ToList(); foreach (var resume in resumeList) { resume.Status = 2; } db.SaveChanges(); foreach (var resume in resumeList) { var searchResume = new SearchResumeModel(); var filePath = $@"\\DOLPHIN-PC\Data\智联招聘\{resume.Template}\{resume.ResumeId}.{Path.GetFileNameWithoutExtension(resume.Template)}"; if (!File.Exists(filePath)) { LogFactory.Warn($"指定路径不存在!ResumeNumber=>{resume.ResumeId} Path=>{filePath}"); resume.Status = 1; resume.MatchTime = DateTime.Now; db.SaveChanges(); continue; } var sourceCode = File.ReadAllText(filePath); var genderMatch = Regex.Match(sourceCode, "(男|女)"); if (genderMatch.Success) { searchResume.Gender = genderMatch.Value; } var replaceMatch = Regex.Match(sourceCode, "应聘机构:.+?>(.+?)</strong>"); if (replaceMatch.Success) { sourceCode = sourceCode.Replace(replaceMatch.Result("$1"), ""); } var matchs = Regex.Matches(sourceCode, "([\u4e00-\u9fa5]{4,11}有限公司[\u4e00-\u9fa5]{0,6})"); if (matchs.Count == 0) { Console.WriteLine($"该简历未匹配到公司!ResumeNumber=> {resume.ResumeId}"); resume.Status = 1; resume.MatchTime = DateTime.Now; db.SaveChanges(); continue; } var companys = new List <string>(); for (var i = 0; i < matchs.Count; i++) { if (i == 2) { break; } companys.Add(matchs[i].Result("$1")); } searchResume.Companys = companys; searchResume.Cellphone = resume.Cellphone; searchResume.Email = resume.Email; searchResume.SearchResumeId = resume.ResumeId; searchResumeList.Add(searchResume); } } return(searchResumeList); }
/// <summary> /// 激活 /// </summary> private void Activation() { var users = new List <User>(); lock (lockObj) { using (var db = new ResumeMatchDBEntities()) { db.UsingTransaction(() => { var time = DateTime.UtcNow.AddHours(-1); users = db.User.Where(w => w.Status == 0 && w.Platform == 4 /*&& (!w.IsLocked || w.IsLocked && w.LockedTime < time)*/).ToList(); foreach (var user in users) { user.IsLocked = true; user.LockedTime = DateTime.UtcNow; } db.SaveChanges(); }); } } if (users.Count == 0) { return; } #region 获取未读邮件列表 var seenUids = new List <string>(); var messages = EmailFactory.FetchUnseenMessages("pop.exmail.qq.com", 995, true, Global.Email, Global.PassWord, seenUids); using (var db = new ResumeMatchDBEntities()) { var userIdArr = users.Select(s => s.Id).ToArray(); var userList = db.User.Where(w => userIdArr.Any(a => a == w.Id)); foreach (var user in userList) { user.IsLocked = false; var message = messages.FirstOrDefault(f => f.message.Headers.To.FirstOrDefault()?.Address == user.Email && f.message.Headers.From.Address == "*****@*****.**"); if (message == null) { continue; } var content = Encoding.UTF8.GetString(message.message.FindFirstHtmlVersion().Body); if (!Regex.IsMatch(content, "(?s)完成验证.+?com/track/click/(.+?html)")) { LogFactory.Error($"未匹配到激活码!响应源:{content}", MessageSubjectEnum.ZhaoPinGou); continue; } var url = "http://sctrack.info.zhaopingou.com/track/click/" + Regex.Match(content, "(?s)完成验证.+?com/track/click/(.+?html)\".style").Result("$1"); var host = string.Empty; //if (Global.IsEnanbleProxy) //{ // if (!string.IsNullOrWhiteSpace(user.Host)) // { // host = user.Host; // GetProxy("ZPG_Activation",user.Host); // } //} var dataResult = Activation(url, user.Email, host); //ReleaseProxy("ZPG_Activation", host); if (dataResult == null) { continue; } if (!dataResult.IsSuccess) { LogFactory.Error(dataResult.ErrorMsg, MessageSubjectEnum.ZhaoPinGou); continue; } user.Status = 1; LogFactory.Info($"激活成功!邮箱:{user.Email}", MessageSubjectEnum.ZhaoPinGou); if (!EmailFactory.DeleteMessageByMessageId("pop.exmail.qq.com", 995, true, Global.Email, Global.PassWord, message.message.Headers.MessageId)) { LogFactory.Error($"删除激活邮件失败,邮箱地址:{user.Email}", MessageSubjectEnum.ZhaoPinGou); } } db.TransactionSaveChanges(); } #endregion }
public void MatchZhaopin() { var resumeQueue = new ConcurrentQueue <OldResumeSummary>(); var cookieQueue = new ConcurrentQueue <QueueParam>(); var todayString = DateTime.Today.ToString("yyyy-MM-dd"); using (var db = new MangningXssDBEntities()) { var companyArr = db.ZhaoPinCompany.Where(w => w.Source.Contains("MANUAL")).Select(s => s.Id).ToArray(); var paramArr = db.ZhaopinStaff.Where(w => companyArr.Any(a => a == w.CompanyId) && !string.IsNullOrEmpty(w.Cookie)).Select(s => new { s.CompanyId, s.Cookie }).ToArray(); foreach (var param in paramArr) { var task = db.ZhaopinResumeMatchLimit.FirstOrDefault(f => f.CompanyId == param.CompanyId); if (task == null) { continue; } var todayTask = db.ZhaopinResumeMatchStatistic.FirstOrDefault(f => f.CompanyId == param.CompanyId && f.Date == todayString); if (todayTask == null) { todayTask = new ZhaopinResumeMatchStatistic { Date = todayString, CompanyId = param.CompanyId, MatchedCount = 0, SearchCount = 0, WatchCount = 0 }; db.ZhaopinResumeMatchStatistic.Add(todayTask); db.SaveChanges(); } if (todayTask.SearchCount == task.DailySearchCount || todayTask.WatchCount == task.DailyWatchCount) { continue; } cookieQueue.Enqueue(new QueueParam { CompanyId = param.CompanyId, Cookie = param.Cookie, DailySeachCount = task.DailySearchCount, DailyWatchCount = task.DailyWatchCount, MatchCount = todayTask.MatchedCount, SeachCount = todayTask.SearchCount, WatchCount = todayTask.WatchCount + todayTask.MatchedCount }); } } Task.Run(() => { while (true) { if (resumeQueue.Count < 10) { using (var db = new ResumeMatchDBEntities()) { var resumeList = db.OldResumeSummary.Where(w => w.ResumeId.Length == 10 && !w.IsMatched && w.Status == 0).Take(1000).ToList(); resumeList.ForEach(f => { resumeQueue.Enqueue(f); }); } } Thread.Sleep(TimeSpan.FromSeconds(1)); } }); for (var j = 0; j < 16; j++) { Task.Run(() => { using (var db = new ResumeMatchDBEntities()) { while (true) { #region 匹配 OldResumeSummary resume; if (!resumeQueue.TryDequeue(out resume)) { continue; } var startNum = 0; var resumeTemp = resume; resume = db.OldResumeSummary.FirstOrDefault(f => f.Id == resumeTemp.Id); QueueParam cookie; if (!cookieQueue.TryDequeue(out cookie)) { return; } try { using (var xdb = new MangningXssDBEntities()) { var filePath = $@"E:\Data\智联招聘\{resume.Template}\{resume.ResumeId}.{Path.GetFileNameWithoutExtension(resume.Template)}"; if (!File.Exists(filePath)) { LogFactory.Warn($"指定路径不存在!ResumeNumber=>{resume.ResumeId} Path=>{filePath}"); resume.Status = 1; resume.MatchTime = DateTime.Now; db.SaveChanges(); continue; } var sourceCode = File.ReadAllText(filePath); //var sourceCode = string.Empty; var genderMatch = Regex.Match(sourceCode, "(男|女)"); var gender = string.Empty; if (genderMatch.Success) { gender = genderMatch.Value == "男" ? "1" : "2"; } var matchs = Regex.Matches(sourceCode, "[\u4e00-\u9fa5]{4,11}有限公司[\u4e00-\u9fa5]{0,6}"); var companys = new List <string>(); if (matchs.Count == 0) { if (cookie.SeachCount - cookie.WatchCount < 50) { Console.WriteLine($"该简历未匹配到公司!ResumeNumber=> {resume.ResumeId}"); resume.Status = 1; resume.MatchTime = DateTime.Now; db.SaveChanges(); cookieQueue.Enqueue(cookie); continue; } companys.Add(string.Empty); } for (var i = 0; i < matchs.Count; i++) { if (i == 2) { break; } companys.Add(matchs[i].Value); } var isMatched = true; var age = string.Empty; for (var i = 0; i < companys.Count; i++) { var companyName = companys[i]; var statistic = xdb.ZhaopinResumeMatchStatistic.FirstOrDefault(f => f.Date == todayString && f.CompanyId == cookie.CompanyId); if (statistic == null) { continue; } var cookieContainer = cookie.Cookie.Serialize(".zhaopin.com"); var start = string.IsNullOrEmpty(companyName) ? startNum * 100 : 0; var paramDictionary = new Dictionary <string, string> { { "keywords", "的" }, { "startNum", $"{start}" }, { "rowsCount", "100" }, { "sortColumnName", "sortUpDate" }, { "sortColumn", "sortUpDate desc" }, { "onlyHasImg", "false" }, { "anyKeyWord", "false" }, { "sex", gender }, { "companyName", companyName }, { "onlyLastWork", "false" }, { "ageStart", age }, { "ageEnd", age } }; var requestResult = HttpClientFactory.RequestForString("https://ihr.zhaopin.com/resumesearch/search.do", HttpMethod.Post, paramDictionary, cookieContainer); if (!requestResult.IsSuccess) { isMatched = false; break; } var jObject = JsonConvert.DeserializeObject(requestResult.Data) as JObject; if (jObject["code"] != null) { LogFactory.Warn($"CompanyId => {cookie.CompanyId} 搜索异常 异常信息:{(string)jObject["message"]}"); isMatched = false; return; } statistic.SearchCount += 1; ++cookie.SeachCount; Console.WriteLine($"CompanyId => {cookie.CompanyId} 搜索公司=> {companyName} 性别=> {genderMatch.Value} 今日请求次数:{cookie.SeachCount} "); xdb.SaveChanges(); var matchResumes = (JArray)jObject?["results"]; if (matchResumes == null) { continue; } if (matchResumes.Count == 0) { continue; } var matchResume = matchResumes.FirstOrDefault(a => ((string)a["number"]).Substring(0, 10) == resume.ResumeId); var resumes = matchResumes.Where(w => DateTime.Parse((string)w["modifyDate"]) > DateTime.Today.AddDays(-2)); foreach (var item in resumes) { var wcount = matchResume == null ? cookie.WatchCount : cookie.WatchCount + 1; if (cookie.SeachCount <= wcount) { break; } var number = ((string)item["number"]).Substring(0, 10); if (xdb.ZhaopinResume.Any(a => a.RandomNumber == number)) { continue; } lock (lockObj) { if (xdb.ZhaopinWatchedResume.Any(a => a.ResumeNumber == number)) { continue; } requestResult = HttpClientFactory.RequestForString($"http://ihr.zhaopin.com/resumesearch/getresumedetial.do?resumeNo={(string)item["id"]}_1&resumeSource=1&key=&{(string)item["valResumeTimeStr"]}", HttpMethod.Get, null, cookieContainer); if (requestResult.IsSuccess) { var resumeData = JsonConvert.DeserializeObject <dynamic>(requestResult.Data).data; var resumeDetail = JsonConvert.DeserializeObject(resumeData.detialJSonStr.ToString()); var resumeid = resumeData.resumeId != null ? (int)resumeData.resumeId : resumeDetail.ResumeId != null ? (int)resumeDetail.ResumeId : 0; statistic.WatchCount += 1; Console.WriteLine($"CompanyId => {cookie.CompanyId} 查看简历成功!查看简历份数:{++cookie.WatchCount} ResumeNumber => {number}"); xdb.ZhaopinWatchedResume.Add(new ZhaopinWatchedResume { Id = resumeid, ResumeNumber = number, CompanyId = cookie.CompanyId, WatchTime = DateTime.UtcNow }); xdb.SaveChanges(); } } } if (cookie.SeachCount - cookie.WatchCount > 50 && string.IsNullOrEmpty(companyName) && matchResume == null) { i--; if (startNum == 40) { if (string.IsNullOrEmpty(age)) { age = "18"; } else { age = (Convert.ToInt32(age) + 1).ToString(); } startNum = 0; } else { startNum++; } continue; } if (matchResume == null) { continue; } var resumeNo = (string)matchResume["id"] + "_1"; var resumeNumber = ((string)matchResume["number"]).Substring(0, 10); if (xdb.ZhaopinResume.Any(a => a.RandomNumber == resumeNumber)) { continue; } var valResumeTimeStr = (string)matchResume["valResumeTimeStr"]; requestResult = HttpClientFactory.RequestForString($"http://ihr.zhaopin.com/resumesearch/getresumedetial.do?resumeNo={resumeNo}&resumeSource=1&key=&{valResumeTimeStr}", HttpMethod.Get, null, cookieContainer); if (!requestResult.IsSuccess) { continue; } ++cookie.WatchCount; var resumeJson = JsonConvert.DeserializeObject <dynamic>(requestResult.Data).data; var detail = JsonConvert.DeserializeObject(resumeJson.detialJSonStr.ToString()); var resumeId = resumeJson.resumeId != null ? (int)resumeJson.resumeId : detail.ResumeId != null ? (int)detail.ResumeId : 0; if (xdb.ZhaopinMatchedResume.Any(a => a.Id == resumeId)) { statistic.MatchedCount += 1; LogFactory.Warn($"匹配到重复简历!ResumeId=>{resumeId} ResumeNumber=>{resumeNumber}"); continue; } if (resumeId == 0) { LogFactory.Warn($"CompanyId => {cookie.CompanyId} 解析异常!ResumeId 为空, ResumeNumber:{resumeNumber}"); continue; } var userId = (int)resumeJson.userDetials.userMasterId; var user = xdb.ZhaopinUser.FirstOrDefault(f => f.Id == userId); if (user != null) { if (!user.Source.Contains("MANUAL")) { user.Id = userId; user.Source = "XSS"; user.ModifyTime = BaseFanctory.GetTime((string)detail.DateModified).ToUniversalTime(); user.CreateTime = BaseFanctory.GetTime((string)detail.DateCreated).ToUniversalTime(); user.Cellphone = resume.Cellphone; user.Email = resume.Email; user.Name = resumeJson.userDetials.userName.ToString(); user.UpdateTime = DateTime.UtcNow; user.Username = resumeJson.userDetials.email.ToString(); } } else { xdb.ZhaopinUser.Add(new ZhaopinUser { Id = userId, Source = "XSS", ModifyTime = BaseFanctory.GetTime((string)detail.DateModified).ToUniversalTime(), CreateTime = BaseFanctory.GetTime((string)detail.DateCreated).ToUniversalTime(), Cellphone = resume.Cellphone, Email = resume.Email, Name = resumeJson.userDetials.userName.ToString(), UpdateTime = DateTime.UtcNow }); } var resumeEntity = xdb.ZhaopinResume.FirstOrDefault(f => f.Id == resumeId); if (resumeEntity == null) { xdb.ZhaopinResume.Add(new ZhaopinResume { Id = resumeId, RandomNumber = resumeNumber, UserId = userId, RefreshTime = BaseFanctory.GetTime((string)detail.DateModified).ToUniversalTime(), UpdateTime = DateTime.UtcNow, UserExtId = detail.UserMasterExtId.ToString(), DeliveryNumber = resumeEntity?.DeliveryNumber, Source = resumeEntity == null ? "XSS" : resumeEntity.Source }); } else { resumeEntity.RandomNumber = resumeNumber; resumeEntity.UserId = userId; resumeEntity.RefreshTime = BaseFanctory.GetTime((string)detail.DateModified).ToUniversalTime(); resumeEntity.UpdateTime = DateTime.UtcNow; resumeEntity.UserExtId = detail.UserMasterExtId.ToString(); resumeEntity.DeliveryNumber = resumeEntity?.DeliveryNumber; resumeEntity.Source = resumeEntity == null ? "XSS" : resumeEntity.Source; } var path = $"{ConfigurationManager.AppSettings["Resume.SavePath"]}{DateTime.Now:yyyyMMdd}"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var resumePath = $@"{path}\{resumeId}.json"; resumeJson.userDetials.email = resume.Email; resumeJson.userDetials.mobilePhone = resume.Cellphone; File.WriteAllText(resumePath, JsonConvert.SerializeObject(resumeJson)); uploadOssActionBlock.Post(resumePath); statistic.MatchedCount += 1; Console.WriteLine($"CompanyId => {cookie.CompanyId} 搜索简历成功!匹配成功 {++cookie.MatchCount} 份, ResumeNumner=>{resumeNumber},ResumeId=>{resumeId}"); xdb.ZhaopinMatchedResume.Add(new ZhaopinMatchedResume { Id = resumeId, CompanyId = cookie.CompanyId, MatchTime = DateTime.UtcNow }); xdb.SaveChanges(); resume.IsMatched = true; break; } if (cookie.SeachCount < cookie.DailySeachCount) { cookieQueue.Enqueue(cookie); } if (isMatched) { resume.Status = 99; resume.MatchTime = DateTime.Now; } db.SaveChanges(); } } catch (Exception ex) { //while (true) //{ // if(ex.InnerException == null) break; // ex = ex.InnerException; //} if (cookie.SeachCount < cookie.DailySeachCount) { cookieQueue.Enqueue(cookie); } LogFactory.Warn($"程序异常, 异常信息:{ex.Message} 堆栈:{ex.StackTrace}"); } #endregion } } }); } }
/// <summary> /// 注册 /// </summary> private void Register() { var proxyId = 0; var host = string.Empty; var isAddProxy = false; lock (lockObj) { using (var db = new ResumeMatchDBEntities()) { var data = db.UsingTransaction(() => { var result = new DataResult(); if (!Global.IsEnanbleProxy) { return(result); } var ipArr = db.Proxy.AsNoTracking() .GroupBy(g => g.Host) .Select(s => new { Host = s.Key, Count = s.Count() }) .Where(w => w.Count < Global.PlatformCount * Global.PlatformHostCount) .Select(s => s.Host).ToArray(); if (ipArr.Length > 0) { var proxy = db.Proxy.FirstOrDefault(f => ipArr.Any(a => a == f.Host) && f.Platform == 4 && !string.IsNullOrEmpty(f.Host) && f.Count < Global.PlatformHostCount); if (proxy != null) { proxyId = proxy.Id; host = proxy.Host; proxy.Count++; var user = db.User.Where(w => w.Host == host && w.Platform == 4).OrderBy(o => o.DownloadNumber).FirstOrDefault(); if (user == null) { LogFactory.Error($"找不到用户,Host = {host}", MessageSubjectEnum.ZhaoPinGou); result.IsSuccess = false; return(result); } db.SaveChanges(); return(result); } } var proxyEntity = new Proxy { Count = 1, Platform = 4 }; db.Proxy.Add(proxyEntity); db.SaveChanges(); isAddProxy = true; proxyId = proxyEntity.Id; return(result); }); if (!data.IsSuccess) { return; } } } if (Global.IsEnanbleProxy) { if (string.IsNullOrWhiteSpace(host)) { host = GetProxy("ZPG_Register", true); } else { GetProxy("ZPG_Register", host); } } var dataResult = Register(host); ReleaseProxy("ZPG_Register", host); using (var db = new ResumeMatchDBEntities()) { var proxy = db.Proxy.FirstOrDefault(f => f.Id == proxyId); if (dataResult == null || !dataResult.IsSuccess) { if (proxy != null) { if (isAddProxy) { db.Proxy.Remove(proxy); } else { proxy.Count--; } } } else { db.User.Add(new User { Email = dataResult.Data.Email, Password = dataResult.Data.Password, InviteCode = dataResult.Data.InviteCode, CreateTime = DateTime.UtcNow, IsEnable = true, DownloadNumber = 10, Host = host, Platform = 4, Status = 0, IsLocked = false, LockedTime = new DateTime(1900, 1, 1), RequestNumber = 0 }); if (proxy != null) { proxy.Host = host; } } db.TransactionSaveChanges(); } }