Skip to content

Commit

Permalink
无法保证钉钉只返回一个错误部门,排除所有ID不合法的部门
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer-zheng committed Apr 3, 2024
1 parent 6ef9714 commit 1958753
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ public async Task SyncContactsAsync()
var depts = DingdingAppService.GetDepartmentList();
Logger.Debug($"钉钉返回部门信息:{JsonConvert.SerializeObject(depts)}");
//部分企业或组织在使用钉钉某些功能后,将在顶级id=1的部门下生成id为负数的部门,理应筛选掉并做日志提醒
var deptWithNegativeId = depts.Find(dept => dept.Id < 0);
var deptWithNegativeId = depts.FindAll(dept => dept.Id < 1);
if (deptWithNegativeId != null)
{
Logger.Debug($"找到了id为负数的部门,id: {deptWithNegativeId.Id}, name: {deptWithNegativeId.Name},现在将其删除");
depts.Remove(deptWithNegativeId);
foreach (var item in deptWithNegativeId)
{

Logger.Debug($"找到了id为负数的部门,id: {item.Id}, name: {item.Name},现在将其删除");
depts.Remove(item);
}
}

//获取当前数据库中的部门
Expand Down Expand Up @@ -72,7 +76,7 @@ public async Task SyncContactsAsync()
if (!relaList.Any(t => t.UserId == user.Userid && t.DeptId == item.Id))
{
newRelaList.Add(new UserDepartmentsRelationEntity
{ Id = Guid.NewGuid().ToString(), UserId = user.Userid, DeptId = item.Id });
{ Id = Guid.NewGuid().ToString(), UserId = user.Userid, DeptId = item.Id });
}
}
}
Expand Down

0 comments on commit 1958753

Please sign in to comment.