diff --git a/ds-wms-service/DS.WMS.Core/Sys/Interface/ICommonService.cs b/ds-wms-service/DS.WMS.Core/Sys/Interface/ICommonService.cs index 48597fc9..ada3acdb 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Interface/ICommonService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Interface/ICommonService.cs @@ -48,13 +48,13 @@ public interface ICommonService /// /// /// - DataResult ClientUserLogin(UserLoginModel model); + Task> ClientUserLogin(UserLoginModel model); /// /// 获取用户信息-客户 /// /// - DataResult GetClientUserInfo(); + Task> GetClientUserInfo(); /// /// 更换机构 @@ -67,12 +67,12 @@ public interface ICommonService /// 查询客户用户拥有的菜单权限 /// /// - DataResult> GetClientUserPermissionByToken(); + Task>> GetClientUserPermissionByToken(); /// /// 获取客户端按钮权限 /// /// - public DataResult GetClientUserPermissionCode(); + public Task> GetClientUserPermissionCode(); /// /// 获取角色下拉列表 /// diff --git a/ds-wms-service/DS.WMS.Core/Sys/Method/CommonService.cs b/ds-wms-service/DS.WMS.Core/Sys/Method/CommonService.cs index 3534a8d2..9c076d20 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Method/CommonService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Method/CommonService.cs @@ -360,18 +360,18 @@ public class CommonService : ICommonService /// /// /// - public DataResult ClientUserLogin(UserLoginModel model) + public async Task> ClientUserLogin(UserLoginModel model) { - var userInfo = db.Queryable().Filter(null, true) - .First(x => x.UserCode == model.UserName); + var userInfo = await db.Queryable().Filter(null, true) + .FirstAsync(x => x.UserCode == model.UserName); if (userInfo == null) { - return DataResult.Failed("账号不存在,请检查!"); + return await Task.FromResult(DataResult.Failed("账号不存在,请检查!")); } if (userInfo.MD5Password != model.Password) { - return DataResult.Failed("密码错误!"); + return await Task.FromResult(DataResult.Failed("密码错误!")); } var tokenModel = new JwtHelper.JwtTokenModel @@ -393,20 +393,20 @@ public class CommonService : ICommonService OpTime = DateTime.Now, Message = "登录成功" }; - saasService.GetLogDb().Insertable(visLog).ExecuteCommand(); - return DataResult.Success(token); + await saasService.GetLogDb().Insertable(visLog).ExecuteCommandAsync(); + return await Task.FromResult(DataResult.Success(token)); } /// /// /// /// - public DataResult GetClientUserInfo() + public async Task> GetClientUserInfo() { var userId = long.Parse(user.UserId); var tenantId = user.GetTenantId(); //取第一个机构 - var orgRelations = db.Queryable().Filter(null, true) + var orgRelations = await db.Queryable().Filter(null, true) .LeftJoin((a, b) => a.OrgId == b.Id) .Where(a => a.UserId == userId) .Select((a, b) => new UserOrgListRes @@ -414,18 +414,21 @@ public class CommonService : ICommonService OrgId = a.OrgId, OrgName = b.OrgName }) - .ToList(); + .ToListAsync(); + + var userInfo = await db.Queryable().Filter(null, true).FirstAsync(x => x.Id == userId); + var tokenModel = new JwtHelper.JwtTokenModel { Uid = user.UserId, - Name = db.Queryable().Filter(null, true).First(x => x.Id == userId).UserName, + Name = userInfo.UserName, OrgId = user.GetOrgId().ToString(), TenantId = tenantId.ToString(), TenantName = user.TenantName }; var refreshToken = JwtHelper.Encrypt(tokenModel, true, true); - var data = db.Queryable().Filter(null, true).Where(x => x.Id == userId) + var data = await db.Queryable().Filter(null, true).Where(x => x.Id == userId) .Select(a => new CurrentUserViewModel { UserId = a.Id, @@ -446,10 +449,10 @@ public class CommonService : ICommonService //只能写在Select后面 it.HomePath = "/analysis"; }) - .First(); + .FirstAsync(); data.UserOrgs = orgRelations; - return DataResult.Success(data); + return await Task.FromResult(DataResult.Success(data)); } #region 更换机构 @@ -498,16 +501,16 @@ public class CommonService : ICommonService /// 查询客户 用户拥有的菜单权限 /// /// - public DataResult> GetClientUserPermissionByToken() + public async Task>> GetClientUserPermissionByToken() { List list = new List(); var userId = long.Parse(user.UserId); - var userInfo = db.Queryable().Where(x => x.Id == userId).First(); + var userInfo = await db.Queryable().Where(x => x.Id == userId).FirstAsync(); //超级管理员 if (userInfo.UserType == UserTypeEnum.SupperAdmin.ToEnumInt()) { - list = db.Queryable().Where(x => + list = await db.Queryable().Where(x => x.MenuType == 1 && x.IsHidden == false && (x.PermissionType == 1 || x.PermissionType == 0)) .OrderBy(x => x.SortCode) .Select(a => new RouteItem @@ -523,11 +526,11 @@ public class CommonService : ICommonService Icon = a.Icon, } }) - .ToList(); + .ToListAsync(); foreach (var item in list) { - var childs = db.Queryable().Filter(null, true) + var childs =await db.Queryable().Filter(null, true) .Where(x => (x.MenuType == 1 || x.MenuType == 2) && x.ParentId == item.Id && x.IsHidden == false && (x.PermissionType == 1 || x.PermissionType == 0)) .OrderBy(x => x.SortCode) @@ -544,19 +547,19 @@ public class CommonService : ICommonService Title = a.Title, Icon = a.Icon, } - }).ToList(); + }).ToListAsync(); item.Children = childs; } } else if (userInfo.UserType == UserTypeEnum.ApplyUser.ToEnumInt()) //租户申请用户 { - var roleIds = db.Queryable().Where(x => x.UserId == userId).Select(x => x.RoleId).ToList(); + var roleIds = await db.Queryable().Where(x => x.UserId == userId).Select(x => x.RoleId).ToListAsync(); - var permissions = db.Queryable().Where(x => roleIds.Contains(x.RoleId)) - .Select(x => x.PermissionId).Distinct().ToList(); + var permissions = await db.Queryable().Where(x => roleIds.Contains(x.RoleId)) + .Select(x => x.PermissionId).Distinct().ToListAsync(); - var perlist = db.Queryable() + var perlist = await db.Queryable() .Where(x => x.MenuType == 1 && x.IsHidden == false && permissions.Contains(x.Id) && (x.PermissionType == 1 || x.PermissionType == 0)) .OrderBy(x => x.SortCode) @@ -574,7 +577,7 @@ public class CommonService : ICommonService Icon = a.Icon, } }) - .ToList(); + .ToListAsync(); list.AddRange(perlist); //去重 @@ -585,7 +588,7 @@ public class CommonService : ICommonService foreach (var item in list) { - var childs = db.Queryable().Where(x => + var childs = await db.Queryable().Where(x => x.MenuType == 2 && x.ParentId == item.Id && x.IsHidden == false && permissions.Contains(x.Id) && (x.PermissionType == 1 || x.PermissionType == 0)) .OrderBy(x => x.SortCode) @@ -601,7 +604,7 @@ public class CommonService : ICommonService Title = a.Title, Icon = a.Icon, } - }).ToList(); + }).ToListAsync(); //去重 childs.Distinct(); @@ -612,12 +615,12 @@ public class CommonService : ICommonService } else { - var roleIds = db.Queryable().Where(x => x.UserId == userId).Select(x => x.RoleId).ToList(); + var roleIds = await db.Queryable().Where(x => x.UserId == userId).Select(x => x.RoleId).ToListAsync(); - var permissions = db.Queryable().Where(x => roleIds.Contains(x.RoleId)) - .Select(x => x.PermissionId).Distinct().ToList(); + var permissions = await db.Queryable().Where(x => roleIds.Contains(x.RoleId)) + .Select(x => x.PermissionId).Distinct().ToListAsync(); - var perlist = db.Queryable() + var perlist = await db.Queryable() .Where(x => x.MenuType == 1 && x.IsHidden == false && permissions.Contains(x.PermissionId) && (x.PermissionType == 1 || x.PermissionType == 0)) .OrderBy(x => x.SortCode) @@ -637,7 +640,7 @@ public class CommonService : ICommonService Icon = a.Icon, } }) - .ToList(); + .ToListAsync(); list.AddRange(perlist); //去重 @@ -648,7 +651,7 @@ public class CommonService : ICommonService foreach (var item in list) { - var childs = db.Queryable().Where(x => + var childs = await db.Queryable().Where(x => (x.MenuType == 1 || x.MenuType == 2) && x.ParentId == item.ParentId && x.IsHidden == false && permissions.Contains(x.PermissionId) && (x.PermissionType == 1 || x.PermissionType == 0) && @@ -668,7 +671,7 @@ public class CommonService : ICommonService Title = a.Title, Icon = a.Icon, } - }).ToList(); + }).ToListAsync(); //去重 childs.Distinct(); @@ -677,7 +680,7 @@ public class CommonService : ICommonService foreach (var child in childs) { - var grandsons = db.Queryable().Where(x => + var grandsons = await db.Queryable().Where(x => x.MenuType == 2 && x.ParentId == child.ParentId && x.IsHidden == false && permissions.Contains(x.PermissionId)) //获取第三层路由 .OrderBy(x => x.SortCode) @@ -695,7 +698,7 @@ public class CommonService : ICommonService Title = a.Title, Icon = a.Icon, } - }).ToList(); + }).ToListAsync(); if (grandsons.Count > 0) { //去重 @@ -715,7 +718,7 @@ public class CommonService : ICommonService } // list = list.OrderBy(x => x.Id).ToList(); - return DataResult>.Success("获取数据成功!", list); + return await Task.FromResult(DataResult>.Success("获取数据成功!", list)); } @@ -723,22 +726,22 @@ public class CommonService : ICommonService /// 获取客户端按钮权限 /// /// - public DataResult GetClientUserPermissionCode() { + public async Task> GetClientUserPermissionCode() { var userId = long.Parse(user.UserId); - var roleList = db.Queryable() - .Where(x => x.UserId == userId).Select(n => n.RoleId).ToList(); + var roleList = await db.Queryable() + .Where(x => x.UserId == userId).Select(n => n.RoleId).ToListAsync(); roleList.Distinct(); - var list = db.Queryable().Where(a => roleList.Contains(a.RoleId) && a.IsPermission == 1) + var list =await db.Queryable().Where(a => roleList.Contains(a.RoleId) && a.IsPermission == 1) .InnerJoin((a,b)=>a.PermissionId == b.Id) .Where((a, b) => b.MenuType == 3) .Select((a, b) => b.PermissionCode - ).ToArray(); + ).ToArrayAsync(); - return DataResult.Success("获取数据成功!", list); + return await Task.FromResult(DataResult.Success("获取数据成功!", list)); } #endregion diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/CommonController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/CommonController.cs index 5a9f6611..96327fb9 100644 --- a/ds-wms-service/DS.WMS.MainApi/Controllers/CommonController.cs +++ b/ds-wms-service/DS.WMS.MainApi/Controllers/CommonController.cs @@ -46,9 +46,9 @@ public class CommonController : ApiController [HttpPost] [AllowAnonymous] [Route("ClientUserLogin")] - public DataResult ClientUserLogin([FromBody] UserLoginModel model) + public async Task> ClientUserLogin([FromBody] UserLoginModel model) { - var res = _invokeService.ClientUserLogin(model); + var res = await _invokeService.ClientUserLogin(model); return res; } @@ -81,9 +81,9 @@ public class CommonController : ApiController /// [HttpGet] [Route("GetClientUserInfo")] - public DataResult GetClientUserInfo() + public async Task> GetClientUserInfo() { - var res = _invokeService.GetClientUserInfo(); + var res = await _invokeService.GetClientUserInfo(); return res; } @@ -93,9 +93,9 @@ public class CommonController : ApiController /// [HttpGet] [Route("GetClientUserPermissionByToken")] - public DataResult> GetClientUserPermissionByToken() + public async Task>> GetClientUserPermissionByToken() { - var res = _invokeService.GetClientUserPermissionByToken(); + var res = await _invokeService.GetClientUserPermissionByToken(); return res; } /// @@ -104,9 +104,9 @@ public class CommonController : ApiController /// [HttpGet] [Route("GetClientUserPermissionCode")] - public DataResult GetClientUserPermissionCode() + public async Task> GetClientUserPermissionCode() { - var res = _invokeService.GetClientUserPermissionCode(); + var res = await _invokeService.GetClientUserPermissionCode(); return res; } ///