From 8abe663744435869eb03ad4f0901b3f0e3bd1431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E5=B8=A6=E5=A4=A7=E4=BD=AC=E6=B0=94=E5=9C=BA?= <188633308@qq.com> Date: Tue, 1 Jun 2021 09:52:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?update=20=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Ewide.Core/Manager/IUserManager.cs | 9 ++++-- Api/Ewide.Core/Manager/UserManager.cs | 41 ++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Api/Ewide.Core/Manager/IUserManager.cs b/Api/Ewide.Core/Manager/IUserManager.cs index 44dd830..658afd8 100644 --- a/Api/Ewide.Core/Manager/IUserManager.cs +++ b/Api/Ewide.Core/Manager/IUserManager.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Ewide.Core { @@ -10,7 +11,11 @@ namespace Ewide.Core SysUser User { get; } string UserId { get; } - Task CheckUserAsync(string userId, bool tracking = true); + Task CheckUserAsync(); + Task CheckUserAsync(string userId); + Task GetUserEmpInfo(); Task GetUserEmpInfo(string userId); + Task> GetUserRoleIdList(); + Task> GetUserRoleIdList(string userId); } } \ No newline at end of file diff --git a/Api/Ewide.Core/Manager/UserManager.cs b/Api/Ewide.Core/Manager/UserManager.cs index 27ae40c..ee92244 100644 --- a/Api/Ewide.Core/Manager/UserManager.cs +++ b/Api/Ewide.Core/Manager/UserManager.cs @@ -2,7 +2,10 @@ using Furion.DependencyInjection; using Furion.FriendlyException; using Microsoft.AspNetCore.Http; +using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; namespace Ewide.Core { @@ -12,6 +15,8 @@ namespace Ewide.Core public class UserManager : IUserManager, IScoped { private readonly IRepository _sysUserRep; // 用户表仓储 + private readonly IRepository _sysRoleRep; + private readonly IRepository _sysUserRoleRep; private readonly IRepository _sysEmpRep; // 员工表 private readonly IHttpContextAccessor _httpContextAccessor; @@ -40,11 +45,16 @@ namespace Ewide.Core get => _sysUserRep.Find(UserId); } - public UserManager(IRepository sysUserRep, - IRepository sysEmpRep, - IHttpContextAccessor httpContextAccessor) + public UserManager( + IRepository sysUserRep, + IRepository sysRoleRep, + IRepository sysUserRoleRep, + IRepository sysEmpRep, + IHttpContextAccessor httpContextAccessor) { _sysUserRep = sysUserRep; + _sysRoleRep = sysRoleRep; + _sysUserRoleRep = sysUserRoleRep; _sysEmpRep = sysEmpRep; _httpContextAccessor = httpContextAccessor; } @@ -55,12 +65,17 @@ namespace Ewide.Core /// /// /// - public async Task CheckUserAsync(string userId, bool tracking = true) + public async Task CheckUserAsync(string userId) { - var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == userId, tracking); + var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == userId, false); return user ?? throw Oops.Oh(ErrorCode.D1002); } + public async Task CheckUserAsync() + { + return await CheckUserAsync(UserId); + } + /// /// 获取用户员工信息 /// @@ -71,5 +86,21 @@ namespace Ewide.Core var emp = await _sysEmpRep.FirstOrDefaultAsync(u => u.Id == userId, false); return emp ?? throw Oops.Oh(ErrorCode.D1002); } + + public async Task GetUserEmpInfo() + { + return await GetUserEmpInfo(UserId); + } + + public async Task> GetUserRoleIdList(string userId) + { + var roleIds = await _sysUserRoleRep.DetachedEntities.Where(u => u.SysUserId == userId).Select(u => u.SysRoleId).ToListAsync(); + return roleIds; + } + + public async Task> GetUserRoleIdList() + { + return await GetUserRoleIdList(UserId); + } } } \ No newline at end of file From 27c19929cb0db6ebe47c323e60d690090f070bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E5=B8=A6=E5=A4=A7=E4=BD=AC=E6=B0=94=E5=9C=BA?= <188633308@qq.com> Date: Tue, 1 Jun 2021 10:05:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?update=20=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Ewide.Core/Enum/ErrorCode.cs | 2 +- Api/Ewide.Core/Enum/OrgType.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Api/Ewide.Core/Enum/ErrorCode.cs b/Api/Ewide.Core/Enum/ErrorCode.cs index b1d2fbe..d2d5f1e 100644 --- a/Api/Ewide.Core/Enum/ErrorCode.cs +++ b/Api/Ewide.Core/Enum/ErrorCode.cs @@ -137,7 +137,7 @@ namespace Ewide.Core /// /// 已有相同组织机构,编码或名称相同 /// - [ErrorCodeItemMetadata("已有相同编码组织机构")] + [ErrorCodeItemMetadata("已有相同组织机构,编码或名称相同")] D2002, /// diff --git a/Api/Ewide.Core/Enum/OrgType.cs b/Api/Ewide.Core/Enum/OrgType.cs index 8955c0a..f499fa8 100644 --- a/Api/Ewide.Core/Enum/OrgType.cs +++ b/Api/Ewide.Core/Enum/OrgType.cs @@ -10,10 +10,10 @@ namespace Ewide.Core { 市住建部门 = 1, - 区住建部门 = 11, + 区住建部门 = 2, - 乡镇街道办事处 = 21, + 乡镇街道办事处 = 3, - 片区 = 31 + 片区 = 4 } } From 08e4573e195633041cb47e4261f02ffd830ae1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E5=B8=A6=E5=A4=A7=E4=BD=AC=E6=B0=94=E5=9C=BA?= <188633308@qq.com> Date: Tue, 1 Jun 2021 10:21:07 +0800 Subject: [PATCH 3/3] =?UTF-8?q?update=20=E6=89=A9=E5=B1=95userManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Ewide.Core/Manager/IUserManager.cs | 10 ++-- Api/Ewide.Core/Manager/UserManager.cs | 63 +++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/Api/Ewide.Core/Manager/IUserManager.cs b/Api/Ewide.Core/Manager/IUserManager.cs index 658afd8..a9c9f42 100644 --- a/Api/Ewide.Core/Manager/IUserManager.cs +++ b/Api/Ewide.Core/Manager/IUserManager.cs @@ -11,11 +11,15 @@ namespace Ewide.Core SysUser User { get; } string UserId { get; } - Task CheckUserAsync(); Task CheckUserAsync(string userId); - Task GetUserEmpInfo(); + Task CheckUserAsync(); Task GetUserEmpInfo(string userId); - Task> GetUserRoleIdList(); + Task GetUserEmpInfo(); + Task GetUserOrgInfo(string userId); + Task GetUserOrgInfo(); Task> GetUserRoleIdList(string userId); + Task> GetUserRoleIdList(); + Task> GetUserRoleList(string userId); + Task> GetUserRoleList(); } } \ No newline at end of file diff --git a/Api/Ewide.Core/Manager/UserManager.cs b/Api/Ewide.Core/Manager/UserManager.cs index ee92244..6512364 100644 --- a/Api/Ewide.Core/Manager/UserManager.cs +++ b/Api/Ewide.Core/Manager/UserManager.cs @@ -18,6 +18,7 @@ namespace Ewide.Core private readonly IRepository _sysRoleRep; private readonly IRepository _sysUserRoleRep; private readonly IRepository _sysEmpRep; // 员工表 + private readonly IRepository _sysOrgRep; private readonly IHttpContextAccessor _httpContextAccessor; public string UserId @@ -50,12 +51,14 @@ namespace Ewide.Core IRepository sysRoleRep, IRepository sysUserRoleRep, IRepository sysEmpRep, + IRepository sysOrgRep, IHttpContextAccessor httpContextAccessor) { _sysUserRep = sysUserRep; _sysRoleRep = sysRoleRep; _sysUserRoleRep = sysUserRoleRep; _sysEmpRep = sysEmpRep; + _sysOrgRep = sysOrgRep; _httpContextAccessor = httpContextAccessor; } @@ -63,7 +66,6 @@ namespace Ewide.Core /// 获取用户信息 /// /// - /// /// public async Task CheckUserAsync(string userId) { @@ -71,6 +73,10 @@ namespace Ewide.Core return user ?? throw Oops.Oh(ErrorCode.D1002); } + /// + /// 获取用户信息 + /// + /// public async Task CheckUserAsync() { return await CheckUserAsync(UserId); @@ -87,20 +93,75 @@ namespace Ewide.Core return emp ?? throw Oops.Oh(ErrorCode.D1002); } + /// + /// 获取用户员工信息 + /// + /// public async Task GetUserEmpInfo() { return await GetUserEmpInfo(UserId); } + /// + /// 获取用户部门信息 + /// + /// + /// + public async Task GetUserOrgInfo(string userId) + { + var emp = await GetUserEmpInfo(userId); + var org = await _sysOrgRep.FirstOrDefaultAsync(u => u.Id == emp.OrgId, false); + return org ?? throw Oops.Oh(ErrorCode.D1002); + } + + /// + /// 获取用户部门信息 + /// + /// + public async Task GetUserOrgInfo() + { + return await GetUserOrgInfo(UserId); + } + + /// + /// 获取用户角色Id列表 + /// + /// + /// public async Task> GetUserRoleIdList(string userId) { var roleIds = await _sysUserRoleRep.DetachedEntities.Where(u => u.SysUserId == userId).Select(u => u.SysRoleId).ToListAsync(); return roleIds; } + /// + /// 获取用户角色Id列表 + /// + /// public async Task> GetUserRoleIdList() { return await GetUserRoleIdList(UserId); } + + /// + /// 获取用户角色列表 + /// + /// + /// + public async Task> GetUserRoleList(string userId) + { + var roleIds = await GetUserRoleIdList(userId); + var roles = await _sysRoleRep.DetachedEntities.Where(u => roleIds.Contains(u.Id)).ToListAsync(); + return roles; + } + + /// + /// 获取用户角色列表 + /// + /// + public async Task> GetUserRoleList() + { + return await GetUserRoleList(UserId); + } } } \ No newline at end of file