|
|
|
@ -360,18 +360,18 @@ public class CommonService : ICommonService
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<string> ClientUserLogin(UserLoginModel model)
|
|
|
|
|
public async Task<DataResult<string>> ClientUserLogin(UserLoginModel model)
|
|
|
|
|
{
|
|
|
|
|
var userInfo = db.Queryable<SysUser>().Filter(null, true)
|
|
|
|
|
.First(x => x.UserCode == model.UserName);
|
|
|
|
|
var userInfo = await db.Queryable<SysUser>().Filter(null, true)
|
|
|
|
|
.FirstAsync(x => x.UserCode == model.UserName);
|
|
|
|
|
if (userInfo == null)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("账号不存在,请检查!");
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("账号不存在,请检查!"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userInfo.MD5Password != model.Password)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("密码错误!");
|
|
|
|
|
return await Task.FromResult(DataResult<string>.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<string>.Success(token);
|
|
|
|
|
await saasService.GetLogDb().Insertable(visLog).ExecuteCommandAsync();
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Success(token));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<CurrentUserViewModel> GetClientUserInfo()
|
|
|
|
|
public async Task<DataResult<CurrentUserViewModel>> GetClientUserInfo()
|
|
|
|
|
{
|
|
|
|
|
var userId = long.Parse(user.UserId);
|
|
|
|
|
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)
|
|
|
|
|
.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<SysUser>().Filter(null, true).FirstAsync(x => x.Id == userId);
|
|
|
|
|
|
|
|
|
|
var tokenModel = new JwtHelper.JwtTokenModel
|
|
|
|
|
{
|
|
|
|
|
Uid = user.UserId,
|
|
|
|
|
Name = db.Queryable<SysUser>().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<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
|
|
|
|
|
{
|
|
|
|
|
UserId = a.Id,
|
|
|
|
@ -446,10 +449,10 @@ public class CommonService : ICommonService
|
|
|
|
|
//只能写在Select后面
|
|
|
|
|
it.HomePath = "/analysis";
|
|
|
|
|
})
|
|
|
|
|
.First();
|
|
|
|
|
.FirstAsync();
|
|
|
|
|
data.UserOrgs = orgRelations;
|
|
|
|
|
|
|
|
|
|
return DataResult<CurrentUserViewModel>.Success(data);
|
|
|
|
|
return await Task.FromResult(DataResult<CurrentUserViewModel>.Success(data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 更换机构
|
|
|
|
@ -498,16 +501,16 @@ public class CommonService : ICommonService
|
|
|
|
|
/// 查询客户 用户拥有的菜单权限
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<List<RouteItem>> GetClientUserPermissionByToken()
|
|
|
|
|
public async Task<DataResult<List<RouteItem>>> GetClientUserPermissionByToken()
|
|
|
|
|
{
|
|
|
|
|
List<RouteItem> list = new List<RouteItem>();
|
|
|
|
|
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())
|
|
|
|
|
{
|
|
|
|
|
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))
|
|
|
|
|
.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<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 &&
|
|
|
|
|
(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<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))
|
|
|
|
|
.Select(x => x.PermissionId).Distinct().ToList();
|
|
|
|
|
var permissions = await db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId))
|
|
|
|
|
.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) &&
|
|
|
|
|
(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<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.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<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))
|
|
|
|
|
.Select(x => x.PermissionId).Distinct().ToList();
|
|
|
|
|
var permissions = await db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId))
|
|
|
|
|
.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) &&
|
|
|
|
|
(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<SysPermissionTenant>().Where(x =>
|
|
|
|
|
var childs = await db.Queryable<SysPermissionTenant>().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<SysPermissionTenant>().Where(x =>
|
|
|
|
|
var grandsons = await db.Queryable<SysPermissionTenant>().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<List<RouteItem>>.Success("获取数据成功!", list);
|
|
|
|
|
return await Task.FromResult(DataResult<List<RouteItem>>.Success("获取数据成功!", list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -723,22 +726,22 @@ public class CommonService : ICommonService
|
|
|
|
|
/// 获取客户端按钮权限
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<string[]> GetClientUserPermissionCode() {
|
|
|
|
|
public async Task<DataResult<string[]>> GetClientUserPermissionCode() {
|
|
|
|
|
|
|
|
|
|
var userId = long.Parse(user.UserId);
|
|
|
|
|
|
|
|
|
|
var roleList = db.Queryable<SysRoleUser>()
|
|
|
|
|
.Where(x => x.UserId == userId).Select(n => n.RoleId).ToList();
|
|
|
|
|
var roleList = await db.Queryable<SysRoleUser>()
|
|
|
|
|
.Where(x => x.UserId == userId).Select(n => n.RoleId).ToListAsync();
|
|
|
|
|
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)
|
|
|
|
|
.Where((a, b) => b.MenuType == 3)
|
|
|
|
|
.Select((a, b) => b.PermissionCode
|
|
|
|
|
).ToArray();
|
|
|
|
|
).ToArrayAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<string[]>.Success("获取数据成功!", list);
|
|
|
|
|
return await Task.FromResult(DataResult<string[]>.Success("获取数据成功!", list));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|