jianghaiqing 4 months ago
commit b26bc46a11

@ -48,13 +48,13 @@ public interface ICommonService
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
DataResult<string> ClientUserLogin(UserLoginModel model); Task<DataResult<string>> ClientUserLogin(UserLoginModel model);
/// <summary> /// <summary>
/// 获取用户信息-客户 /// 获取用户信息-客户
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
DataResult<CurrentUserViewModel> GetClientUserInfo(); Task<DataResult<CurrentUserViewModel>> GetClientUserInfo();
/// <summary> /// <summary>
/// 更换机构 /// 更换机构
@ -67,12 +67,12 @@ public interface ICommonService
/// 查询客户用户拥有的菜单权限 /// 查询客户用户拥有的菜单权限
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
DataResult<List<RouteItem>> GetClientUserPermissionByToken(); Task<DataResult<List<RouteItem>>> GetClientUserPermissionByToken();
/// <summary> /// <summary>
/// 获取客户端按钮权限 /// 获取客户端按钮权限
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public DataResult<string[]> GetClientUserPermissionCode(); public Task<DataResult<string[]>> GetClientUserPermissionCode();
/// <summary> /// <summary>
/// 获取角色下拉列表 /// 获取角色下拉列表
/// </summary> /// </summary>

@ -360,18 +360,18 @@ public class CommonService : ICommonService
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
public DataResult<string> ClientUserLogin(UserLoginModel model) public async Task<DataResult<string>> ClientUserLogin(UserLoginModel model)
{ {
var userInfo = db.Queryable<SysUser>().Filter(null, true) var userInfo = await db.Queryable<SysUser>().Filter(null, true)
.First(x => x.UserCode == model.UserName); .FirstAsync(x => x.UserCode == model.UserName);
if (userInfo == null) if (userInfo == null)
{ {
return DataResult<string>.Failed("账号不存在,请检查!"); return await Task.FromResult(DataResult<string>.Failed("账号不存在,请检查!"));
} }
if (userInfo.MD5Password != model.Password) if (userInfo.MD5Password != model.Password)
{ {
return DataResult<string>.Failed("密码错误!"); return await Task.FromResult(DataResult<string>.Failed("密码错误!"));
} }
var tokenModel = new JwtHelper.JwtTokenModel var tokenModel = new JwtHelper.JwtTokenModel
@ -393,20 +393,20 @@ public class CommonService : ICommonService
OpTime = DateTime.Now, OpTime = DateTime.Now,
Message = "登录成功" Message = "登录成功"
}; };
saasService.GetLogDb().Insertable(visLog).ExecuteCommand(); await saasService.GetLogDb().Insertable(visLog).ExecuteCommandAsync();
return DataResult<string>.Success(token); return await Task.FromResult(DataResult<string>.Success(token));
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public DataResult<CurrentUserViewModel> GetClientUserInfo() public async Task<DataResult<CurrentUserViewModel>> GetClientUserInfo()
{ {
var userId = long.Parse(user.UserId); var userId = long.Parse(user.UserId);
var tenantId = user.GetTenantId(); var tenantId = user.GetTenantId();
//取第一个机构 //取第一个机构
var orgRelations = db.Queryable<SysOrgUser>().Filter(null, true) var orgRelations = await db.Queryable<SysOrgUser>().Filter(null, true)
.LeftJoin<SysOrg>((a, b) => a.OrgId == b.Id) .LeftJoin<SysOrg>((a, b) => a.OrgId == b.Id)
.Where(a => a.UserId == userId) .Where(a => a.UserId == userId)
.Select((a, b) => new UserOrgListRes .Select((a, b) => new UserOrgListRes
@ -414,18 +414,21 @@ public class CommonService : ICommonService
OrgId = a.OrgId, OrgId = a.OrgId,
OrgName = b.OrgName OrgName = b.OrgName
}) })
.ToList(); .ToListAsync();
var userInfo = await db.Queryable<SysUser>().Filter(null, true).FirstAsync(x => x.Id == userId);
var tokenModel = new JwtHelper.JwtTokenModel var tokenModel = new JwtHelper.JwtTokenModel
{ {
Uid = user.UserId, Uid = user.UserId,
Name = db.Queryable<SysUser>().Filter(null, true).First(x => x.Id == userId).UserName, Name = userInfo.UserName,
OrgId = user.GetOrgId().ToString(), OrgId = user.GetOrgId().ToString(),
TenantId = tenantId.ToString(), TenantId = tenantId.ToString(),
TenantName = user.TenantName TenantName = user.TenantName
}; };
var refreshToken = JwtHelper.Encrypt(tokenModel, true, true); var refreshToken = JwtHelper.Encrypt(tokenModel, true, true);
var data = db.Queryable<SysUser>().Filter(null, true).Where(x => x.Id == userId) var data = await db.Queryable<SysUser>().Filter(null, true).Where(x => x.Id == userId)
.Select(a => new CurrentUserViewModel .Select(a => new CurrentUserViewModel
{ {
UserId = a.Id, UserId = a.Id,
@ -446,10 +449,10 @@ public class CommonService : ICommonService
//只能写在Select后面 //只能写在Select后面
it.HomePath = "/analysis"; it.HomePath = "/analysis";
}) })
.First(); .FirstAsync();
data.UserOrgs = orgRelations; data.UserOrgs = orgRelations;
return DataResult<CurrentUserViewModel>.Success(data); return await Task.FromResult(DataResult<CurrentUserViewModel>.Success(data));
} }
#region 更换机构 #region 更换机构
@ -498,16 +501,16 @@ public class CommonService : ICommonService
/// 查询客户 用户拥有的菜单权限 /// 查询客户 用户拥有的菜单权限
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public DataResult<List<RouteItem>> GetClientUserPermissionByToken() public async Task<DataResult<List<RouteItem>>> GetClientUserPermissionByToken()
{ {
List<RouteItem> list = new List<RouteItem>(); List<RouteItem> list = new List<RouteItem>();
var userId = long.Parse(user.UserId); var userId = long.Parse(user.UserId);
var userInfo = db.Queryable<SysUser>().Where(x => x.Id == userId).First(); var userInfo = await db.Queryable<SysUser>().Where(x => x.Id == userId).FirstAsync();
//超级管理员 //超级管理员
if (userInfo.UserType == UserTypeEnum.SupperAdmin.ToEnumInt()) if (userInfo.UserType == UserTypeEnum.SupperAdmin.ToEnumInt())
{ {
list = db.Queryable<SysPermission>().Where(x => list = await db.Queryable<SysPermission>().Where(x =>
x.MenuType == 1 && x.IsHidden == false && (x.PermissionType == 1 || x.PermissionType == 0)) x.MenuType == 1 && x.IsHidden == false && (x.PermissionType == 1 || x.PermissionType == 0))
.OrderBy(x => x.SortCode) .OrderBy(x => x.SortCode)
.Select(a => new RouteItem .Select(a => new RouteItem
@ -523,11 +526,11 @@ public class CommonService : ICommonService
Icon = a.Icon, Icon = a.Icon,
} }
}) })
.ToList(); .ToListAsync();
foreach (var item in list) foreach (var item in list)
{ {
var childs = db.Queryable<SysPermission>().Filter(null, true) var childs =await db.Queryable<SysPermission>().Filter(null, true)
.Where(x => (x.MenuType == 1 || x.MenuType == 2) && x.ParentId == item.Id && x.IsHidden == false && .Where(x => (x.MenuType == 1 || x.MenuType == 2) && x.ParentId == item.Id && x.IsHidden == false &&
(x.PermissionType == 1 || x.PermissionType == 0)) (x.PermissionType == 1 || x.PermissionType == 0))
.OrderBy(x => x.SortCode) .OrderBy(x => x.SortCode)
@ -544,19 +547,19 @@ public class CommonService : ICommonService
Title = a.Title, Title = a.Title,
Icon = a.Icon, Icon = a.Icon,
} }
}).ToList(); }).ToListAsync();
item.Children = childs; item.Children = childs;
} }
} }
else if (userInfo.UserType == UserTypeEnum.ApplyUser.ToEnumInt()) //租户申请用户 else if (userInfo.UserType == UserTypeEnum.ApplyUser.ToEnumInt()) //租户申请用户
{ {
var roleIds = db.Queryable<SysRoleUser>().Where(x => x.UserId == userId).Select(x => x.RoleId).ToList(); var roleIds = await db.Queryable<SysRoleUser>().Where(x => x.UserId == userId).Select(x => x.RoleId).ToListAsync();
var permissions = db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId)) var permissions = await db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId))
.Select(x => x.PermissionId).Distinct().ToList(); .Select(x => x.PermissionId).Distinct().ToListAsync();
var perlist = db.Queryable<SysPermission>() var perlist = await db.Queryable<SysPermission>()
.Where(x => x.MenuType == 1 && x.IsHidden == false && permissions.Contains(x.Id) && .Where(x => x.MenuType == 1 && x.IsHidden == false && permissions.Contains(x.Id) &&
(x.PermissionType == 1 || x.PermissionType == 0)) (x.PermissionType == 1 || x.PermissionType == 0))
.OrderBy(x => x.SortCode) .OrderBy(x => x.SortCode)
@ -574,7 +577,7 @@ public class CommonService : ICommonService
Icon = a.Icon, Icon = a.Icon,
} }
}) })
.ToList(); .ToListAsync();
list.AddRange(perlist); list.AddRange(perlist);
//去重 //去重
@ -585,7 +588,7 @@ public class CommonService : ICommonService
foreach (var item in list) foreach (var item in list)
{ {
var childs = db.Queryable<SysPermission>().Where(x => var childs = await db.Queryable<SysPermission>().Where(x =>
x.MenuType == 2 && x.ParentId == item.Id && x.IsHidden == false && permissions.Contains(x.Id) && x.MenuType == 2 && x.ParentId == item.Id && x.IsHidden == false && permissions.Contains(x.Id) &&
(x.PermissionType == 1 || x.PermissionType == 0)) (x.PermissionType == 1 || x.PermissionType == 0))
.OrderBy(x => x.SortCode) .OrderBy(x => x.SortCode)
@ -601,7 +604,7 @@ public class CommonService : ICommonService
Title = a.Title, Title = a.Title,
Icon = a.Icon, Icon = a.Icon,
} }
}).ToList(); }).ToListAsync();
//去重 //去重
childs.Distinct(); childs.Distinct();
@ -612,12 +615,12 @@ public class CommonService : ICommonService
} }
else else
{ {
var roleIds = db.Queryable<SysRoleUser>().Where(x => x.UserId == userId).Select(x => x.RoleId).ToList(); var roleIds = await db.Queryable<SysRoleUser>().Where(x => x.UserId == userId).Select(x => x.RoleId).ToListAsync();
var permissions = db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId)) var permissions = await db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId))
.Select(x => x.PermissionId).Distinct().ToList(); .Select(x => x.PermissionId).Distinct().ToListAsync();
var perlist = db.Queryable<SysPermissionTenant>() var perlist = await db.Queryable<SysPermissionTenant>()
.Where(x => x.MenuType == 1 && x.IsHidden == false && permissions.Contains(x.PermissionId) && .Where(x => x.MenuType == 1 && x.IsHidden == false && permissions.Contains(x.PermissionId) &&
(x.PermissionType == 1 || x.PermissionType == 0)) (x.PermissionType == 1 || x.PermissionType == 0))
.OrderBy(x => x.SortCode) .OrderBy(x => x.SortCode)
@ -637,7 +640,7 @@ public class CommonService : ICommonService
Icon = a.Icon, Icon = a.Icon,
} }
}) })
.ToList(); .ToListAsync();
list.AddRange(perlist); list.AddRange(perlist);
//去重 //去重
@ -648,7 +651,7 @@ public class CommonService : ICommonService
foreach (var item in list) foreach (var item in list)
{ {
var childs = db.Queryable<SysPermissionTenant>().Where(x => var childs = await db.Queryable<SysPermissionTenant>().Where(x =>
(x.MenuType == 1 || x.MenuType == 2) && x.ParentId == item.ParentId && x.IsHidden == false && (x.MenuType == 1 || x.MenuType == 2) && x.ParentId == item.ParentId && x.IsHidden == false &&
permissions.Contains(x.PermissionId) && permissions.Contains(x.PermissionId) &&
(x.PermissionType == 1 || x.PermissionType == 0) && (x.PermissionType == 1 || x.PermissionType == 0) &&
@ -668,7 +671,7 @@ public class CommonService : ICommonService
Title = a.Title, Title = a.Title,
Icon = a.Icon, Icon = a.Icon,
} }
}).ToList(); }).ToListAsync();
//去重 //去重
childs.Distinct(); childs.Distinct();
@ -677,7 +680,7 @@ public class CommonService : ICommonService
foreach (var child in childs) foreach (var child in childs)
{ {
var grandsons = db.Queryable<SysPermissionTenant>().Where(x => var grandsons = await db.Queryable<SysPermissionTenant>().Where(x =>
x.MenuType == 2 && x.ParentId == child.ParentId && x.IsHidden == false && x.MenuType == 2 && x.ParentId == child.ParentId && x.IsHidden == false &&
permissions.Contains(x.PermissionId)) //获取第三层路由 permissions.Contains(x.PermissionId)) //获取第三层路由
.OrderBy(x => x.SortCode) .OrderBy(x => x.SortCode)
@ -695,7 +698,7 @@ public class CommonService : ICommonService
Title = a.Title, Title = a.Title,
Icon = a.Icon, Icon = a.Icon,
} }
}).ToList(); }).ToListAsync();
if (grandsons.Count > 0) if (grandsons.Count > 0)
{ {
//去重 //去重
@ -715,7 +718,7 @@ public class CommonService : ICommonService
} }
// list = list.OrderBy(x => x.Id).ToList(); // list = list.OrderBy(x => x.Id).ToList();
return DataResult<List<RouteItem>>.Success("获取数据成功!", list); return await Task.FromResult(DataResult<List<RouteItem>>.Success("获取数据成功!", list));
} }
@ -723,22 +726,22 @@ public class CommonService : ICommonService
/// 获取客户端按钮权限 /// 获取客户端按钮权限
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public DataResult<string[]> GetClientUserPermissionCode() { public async Task<DataResult<string[]>> GetClientUserPermissionCode() {
var userId = long.Parse(user.UserId); var userId = long.Parse(user.UserId);
var roleList = db.Queryable<SysRoleUser>() var roleList = await db.Queryable<SysRoleUser>()
.Where(x => x.UserId == userId).Select(n => n.RoleId).ToList(); .Where(x => x.UserId == userId).Select(n => n.RoleId).ToListAsync();
roleList.Distinct(); roleList.Distinct();
var list = db.Queryable<SysRolePermission>().Where(a => roleList.Contains(a.RoleId) && a.IsPermission == 1) var list =await db.Queryable<SysRolePermission>().Where(a => roleList.Contains(a.RoleId) && a.IsPermission == 1)
.InnerJoin<SysPermission>((a,b)=>a.PermissionId == b.Id) .InnerJoin<SysPermission>((a,b)=>a.PermissionId == b.Id)
.Where((a, b) => b.MenuType == 3) .Where((a, b) => b.MenuType == 3)
.Select((a, b) => b.PermissionCode .Select((a, b) => b.PermissionCode
).ToArray(); ).ToArrayAsync();
return DataResult<string[]>.Success("获取数据成功!", list); return await Task.FromResult(DataResult<string[]>.Success("获取数据成功!", list));
} }
#endregion #endregion

@ -46,9 +46,9 @@ public class CommonController : ApiController
[HttpPost] [HttpPost]
[AllowAnonymous] [AllowAnonymous]
[Route("ClientUserLogin")] [Route("ClientUserLogin")]
public DataResult<string> ClientUserLogin([FromBody] UserLoginModel model) public async Task<DataResult<string>> ClientUserLogin([FromBody] UserLoginModel model)
{ {
var res = _invokeService.ClientUserLogin(model); var res = await _invokeService.ClientUserLogin(model);
return res; return res;
} }
@ -81,9 +81,9 @@ public class CommonController : ApiController
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("GetClientUserInfo")] [Route("GetClientUserInfo")]
public DataResult<CurrentUserViewModel> GetClientUserInfo() public async Task<DataResult<CurrentUserViewModel>> GetClientUserInfo()
{ {
var res = _invokeService.GetClientUserInfo(); var res = await _invokeService.GetClientUserInfo();
return res; return res;
} }
@ -93,9 +93,9 @@ public class CommonController : ApiController
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("GetClientUserPermissionByToken")] [Route("GetClientUserPermissionByToken")]
public DataResult<List<RouteItem>> GetClientUserPermissionByToken() public async Task<DataResult<List<RouteItem>>> GetClientUserPermissionByToken()
{ {
var res = _invokeService.GetClientUserPermissionByToken(); var res = await _invokeService.GetClientUserPermissionByToken();
return res; return res;
} }
/// <summary> /// <summary>
@ -104,9 +104,9 @@ public class CommonController : ApiController
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("GetClientUserPermissionCode")] [Route("GetClientUserPermissionCode")]
public DataResult<string[]> GetClientUserPermissionCode() public async Task<DataResult<string[]>> GetClientUserPermissionCode()
{ {
var res = _invokeService.GetClientUserPermissionCode(); var res = await _invokeService.GetClientUserPermissionCode();
return res; return res;
} }
/// <summary> /// <summary>

Loading…
Cancel
Save