public async Task <int> SyncGroups(string userid, string token) { // 先到clockify获取数据 var ls = await _clockifyService.GetUserGroups(userid, token); var list = new List <Group>(); var userGroups = new List <UserGroup>(); foreach (var l in ls) { list.Add(new Group() { Gid = l.id, Name = l.name, CompanyId = "", WorkspaceId = l.workspaceId, CreatedDate = DateTime.Now, CreatedUserID = userid, CreatedUserName = userid, IsDeleted = false, UpdatedDate = DateTime.Now, UpdatedUserID = userid, UpdatedUserName = userid }); foreach (var uid in l.userIds) { userGroups.Add(new UserGroup() { GroupId = l.id, UserId = uid, CreatedDate = DateTime.Now, CreatedUserID = userid, CreatedUserName = userid, IsDeleted = false, UpdatedDate = DateTime.Now, UpdatedUserID = userid, UpdatedUserName = userid }); } } // 然后在本地插入或者同步数据 await _groupService.Clear(); var affectedRecordCount = await _groupService.AddManyAsync(list); await _userGroupService.Clear(); var affectedRecordCount1 = await _userGroupService.AddManyAsync(userGroups); return(affectedRecordCount1); }