mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
用户增加parentid,组织增加负责人
This commit is contained in:
parent
099ea55a3d
commit
457458541b
@ -47,6 +47,11 @@ namespace OpenAuth.App.Request
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 直接上级
|
||||
/// </summary>
|
||||
public string ParentId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -44,6 +44,11 @@ namespace OpenAuth.App.Response
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 直接上级
|
||||
/// </summary>
|
||||
public string ParentId { get; set; }
|
||||
|
||||
|
||||
|
||||
|
@ -12,27 +12,22 @@ using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class UserManagerApp : BaseStringApp<User,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
private OrgManagerApp _orgManagerApp;
|
||||
|
||||
public UserManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<User,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app,IAuth auth, OrgManagerApp orgManagerApp) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
_orgManagerApp = orgManagerApp;
|
||||
}
|
||||
|
||||
public User GetByAccount(string account)
|
||||
{
|
||||
return Repository.FirstOrDefault(u => u.Account == account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载当前登录用户可访问的一个部门及子部门全部用户
|
||||
/// 如果请求的request.OrgId为空,则可以获取到已被删除机构的用户(即:没有分配任何机构的用户)
|
||||
@ -40,13 +35,11 @@ namespace OpenAuth.App
|
||||
public async Task<TableData> Load(QueryUserListReq request)
|
||||
{
|
||||
var loginUser = _auth.GetCurrentUser();
|
||||
|
||||
IQueryable<User> query = UnitWork.Find<User>(null);
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
query = UnitWork.Find<User>(u => u.Name.Contains(request.key) || u.Account.Contains(request.key));
|
||||
}
|
||||
|
||||
var userOrgs = from user in query
|
||||
join relevance in UnitWork.Find<Relevance>(u => u.Key == "UserOrg")
|
||||
on user.Id equals relevance.FirstId into temp
|
||||
@ -66,33 +59,27 @@ namespace OpenAuth.App
|
||||
user.CreateTime,
|
||||
user.TypeId,
|
||||
user.TypeName,
|
||||
user.ParentId,
|
||||
r.Key,
|
||||
r.SecondId,
|
||||
OrgId = o.Id,
|
||||
OrgName = o.Name
|
||||
};
|
||||
|
||||
//如果请求的orgId不为空
|
||||
if (!string.IsNullOrEmpty(request.orgId))
|
||||
{
|
||||
var org = loginUser.Orgs.SingleOrDefault(u => u.Id == request.orgId);
|
||||
var cascadeId = org.CascadeId;
|
||||
|
||||
var orgIds = loginUser.Orgs.Where(u => u.CascadeId.Contains(cascadeId)).Select(u => u.Id).ToArray();
|
||||
|
||||
//只获取机构里面的用户
|
||||
userOrgs = userOrgs.Where(u => u.Key == Define.USERORG && orgIds.Contains(u.OrgId));
|
||||
}
|
||||
else //todo:如果请求的orgId为空,即为跟节点,这时可以额外获取到机构已经被删除的用户,从而进行机构分配。可以根据自己需求进行调整
|
||||
{
|
||||
var orgIds = loginUser.Orgs.Select(u => u.Id).ToArray();
|
||||
|
||||
//获取用户可以访问的机构的用户和没有任何机构关联的用户(机构被删除后,没有删除这里面的关联关系)
|
||||
userOrgs = userOrgs.Where(u => (u.Key == Define.USERORG && orgIds.Contains(u.OrgId)) || (u.OrgId == null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
var userViews = (await userOrgs.ToListAsync()).GroupBy(b => b.Account)
|
||||
.Select(u =>new UserView
|
||||
{
|
||||
@ -101,13 +88,12 @@ namespace OpenAuth.App
|
||||
Name = u.First().Name,
|
||||
Sex = u.First().Sex,
|
||||
Status = u.First().Status,
|
||||
ParentId = u.First().ParentId,
|
||||
CreateTime = u.First().CreateTime,
|
||||
CreateUser = u.First().CreateId,
|
||||
OrganizationIds = string.Join(",", u.Select(x=>x.OrgId))
|
||||
,Organizations = string.Join(",", u.Select(x=>x.OrgName))
|
||||
|
||||
});
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count =userViews.Count(),
|
||||
@ -116,7 +102,6 @@ namespace OpenAuth.App
|
||||
.Take(request.limit),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的用户
|
||||
/// 为了控制权限,通常只用于流程实例选择执行角色,其他地方请使用Load
|
||||
@ -128,7 +113,6 @@ namespace OpenAuth.App
|
||||
{
|
||||
query = UnitWork.Find<User>(u => u.Name.Contains(request.key) || u.Account.Contains(request.key));
|
||||
}
|
||||
|
||||
var userOrgs = from user in query
|
||||
join relevance in UnitWork.Find<Relevance>(u => u.Key == "UserOrg")
|
||||
on user.Id equals relevance.FirstId into temp
|
||||
@ -153,13 +137,11 @@ namespace OpenAuth.App
|
||||
OrgId = o.Id,
|
||||
OrgName = o.Name
|
||||
};
|
||||
|
||||
//如果请求的orgId不为空
|
||||
if (!string.IsNullOrEmpty(request.orgId))
|
||||
{
|
||||
userOrgs = userOrgs.Where(u => u.Key == Define.USERORG && u.OrgId == request.orgId);
|
||||
}
|
||||
|
||||
var userViews = (await userOrgs.ToListAsync()).GroupBy(b => b.Account).Select(u =>new UserView
|
||||
{
|
||||
Id = u.First().Id,
|
||||
@ -171,9 +153,7 @@ namespace OpenAuth.App
|
||||
CreateUser = u.First().CreateId,
|
||||
OrganizationIds = string.Join(",", u.Select(x=>x.OrgId))
|
||||
,Organizations = string.Join(",", u.Select(x=>x.OrgName))
|
||||
|
||||
});
|
||||
|
||||
return new TableResp<UserView>()
|
||||
{
|
||||
count = userViews.Count(),
|
||||
@ -182,16 +162,13 @@ namespace OpenAuth.App
|
||||
.Take(request.limit).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void AddOrUpdate(UpdateUserReq request)
|
||||
{
|
||||
request.ValidationEntity(u => new {u.Account,u.Name, u.OrganizationIds});
|
||||
|
||||
if (string.IsNullOrEmpty(request.OrganizationIds))
|
||||
throw new Exception("请为用户分配机构");
|
||||
User requser = request;
|
||||
requser.CreateId = _auth.GetCurrentUser().User.Id;
|
||||
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.Id))
|
||||
@ -200,14 +177,11 @@ namespace OpenAuth.App
|
||||
{
|
||||
throw new Exception("用户账号已存在");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(requser.Password))
|
||||
{
|
||||
requser.Password = requser.Account; //如果客户端没提供密码,默认密码同账号
|
||||
}
|
||||
|
||||
requser.CreateTime = DateTime.Now;
|
||||
|
||||
UnitWork.Add(requser);
|
||||
request.Id = requser.Id; //要把保存后的ID存入view
|
||||
}
|
||||
@ -219,7 +193,8 @@ namespace OpenAuth.App
|
||||
BizCode = requser.BizCode,
|
||||
Name = requser.Name,
|
||||
Sex = requser.Sex,
|
||||
Status = requser.Status
|
||||
Status = requser.Status,
|
||||
ParentId = request.ParentId
|
||||
});
|
||||
if (!string.IsNullOrEmpty(requser.Password)) //密码为空的时候,不做修改
|
||||
{
|
||||
@ -229,16 +204,12 @@ namespace OpenAuth.App
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
UnitWork.Save();
|
||||
string[] orgIds = request.OrganizationIds.Split(',').ToArray();
|
||||
|
||||
_revelanceApp.DeleteBy(Define.USERORG, requser.Id);
|
||||
_revelanceApp.Assign(Define.USERORG, orgIds.ToLookup(u => requser.Id));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户,包含用户与组织关系、用户与角色关系
|
||||
/// </summary>
|
||||
@ -252,10 +223,7 @@ namespace OpenAuth.App
|
||||
UnitWork.Delete<User>(u => ids.Contains(u.Id));
|
||||
UnitWork.Save();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 修改密码
|
||||
/// </summary>
|
||||
@ -267,8 +235,6 @@ namespace OpenAuth.App
|
||||
Password = request.Password
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定角色包含的用户列表
|
||||
/// </summary>
|
||||
@ -281,14 +247,12 @@ namespace OpenAuth.App
|
||||
join user in UnitWork.Find<User>(null) on userRole.FirstId equals user.Id into temp
|
||||
from c in temp.Where(u =>u.Id != null)
|
||||
select c;
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count =await users.CountAsync(),
|
||||
data =await users.Skip((request.page - 1) * request.limit).Take(request.limit).ToListAsync()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定机构包含的用户列表
|
||||
/// </summary>
|
||||
@ -301,14 +265,12 @@ namespace OpenAuth.App
|
||||
join user in UnitWork.Find<User>(null) on userOrg.FirstId equals user.Id into temp
|
||||
from c in temp.Where(u =>u.Id != null)
|
||||
select c;
|
||||
|
||||
return new TableData
|
||||
{
|
||||
count =await users.CountAsync(),
|
||||
data =await users.Skip((request.page - 1) * request.limit).Take(request.limit).ToListAsync()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户资料
|
||||
/// </summary>
|
||||
@ -319,7 +281,6 @@ namespace OpenAuth.App
|
||||
{
|
||||
throw new Exception("不能修改超级管理员信息");
|
||||
}
|
||||
|
||||
Repository.Update(u => u.Account == request.Account, user => new User
|
||||
{
|
||||
Name = request.Name,
|
||||
|
@ -99,6 +99,12 @@ namespace OpenAuth.Repository.Domain
|
||||
/// </summary>
|
||||
[Description("分类ID")]
|
||||
public string TypeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 负责人ID
|
||||
/// </summary>
|
||||
[Description("负责人ID")]
|
||||
public string ChairmanId { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -84,6 +84,12 @@ namespace OpenAuth.Repository.Domain
|
||||
/// </summary>
|
||||
[Description("分类ID")]
|
||||
public string TypeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 直接上级
|
||||
/// </summary>
|
||||
[Description("直接上级")]
|
||||
public string ParentId { get; set; }
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user