public async Task CreatRecommendFromProject(ProjectCreatedIntegrationEvent @event) { var fromUser = await _userService.GetBaseUserInfoAsync(@event.UserId); var recommend = new ProjectRecommend() { Company = @event.Company, CreateTime = @event.CreateTime, ProjectId = @event.ProjectId, Introduction = @event.Introduction, RecommendTime = DateTime.Now, RecommendType = EnumRecommendType.Friend, UserId = @event.UserId, FromUserAvatar = fromUser.Avatar, FromUserName = fromUser.Name }; _context.ProjectRecommends.Add(recommend); _context.SaveChanges(); }
public async Task CreateRecommendFromProject(ProjectCreatedIntergrationEvent @event) { try { //获取fromuser 信息 使用consul 服务发现 找到User 服务地址,获取用户基本信息 var fromUser = await _userService.GetBaseUserInfoAsync(@event.UserId); if (fromUser == null) { //TBD 记录没有获取到指定userId的用户信息 } //使用通讯录查找所有好友,给这些好友添加 推荐记录 var contacts = await _contactService.GetContactsByUserId(@event.UserId); foreach (var contact in contacts) { //通过 Event传入项目的用户id,及项目其他基本信息 ProjectRecommend recommend = new ProjectRecommend { Company = @event.Company, FinStage = @event.Company, Tags = @event.Tags, RecommendTime = DateTime.Now, CreateTime = @event.CreateTime, FromUserId = @event.UserId, Introduction = @event.Introduction, ProjectAvatar = @event.ProjectAvatar, ProjectId = @event.ProjectId, FromUserAvatar = fromUser.Avatar, FromUserName = fromUser.Name, RecommednType = EnumRecommendType.Friend, UserId = contact.UserId }; _context.ProjectRecommends.Add(recommend); } _context.SaveChanges(); } catch (Exception ex) { } // Task.CompletedTask; }