UserService.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Fuel.Core.Entity;
  2. using FuelServer.Core.Entity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Fuel.Application.Service
  9. {
  10. public class UserService : IUserService
  11. {
  12. public readonly IFreeSql _fsql;
  13. public UserService(IFreeSql fsql)
  14. {
  15. _fsql = fsql;
  16. }
  17. public users ValidateCredentials(string username, string password)
  18. {
  19. return _fsql.Select<users>().Where(_ => _.Account == username && _.Password == password).First();
  20. }
  21. /// <summary>
  22. /// 获取权限
  23. /// </summary>
  24. /// <param name="userId">1 超级管理员</param>
  25. /// <returns></returns>
  26. public List<string> GetUserPermissions(int userId = 1)
  27. {
  28. var Permission = _fsql.Select<users, AdUserRole, AdRolePermission, AdPermission>()
  29. .LeftJoin((a, b, c, d) => a.Id == b.UserId)
  30. .LeftJoin((a, b, c, d) => b.RoleId == c.RoleId)
  31. .LeftJoin((a, b, c, d) => c.PermissionId == d.Id)
  32. .Where((a, b, c, d) => a.Id == userId)
  33. .ToList((a, b, c, d) => new { d });
  34. var permissionList = new List<string>();
  35. foreach (var permission in Permission)
  36. {
  37. if(permission.d != null)
  38. permissionList.Add(permission.d.Code);
  39. }
  40. permissionList.Add("Nozzle:uploadNozzle:POST");
  41. permissionList.Add("Nozzle:DeleteNozzle:Delete");
  42. return permissionList;
  43. }
  44. public List<string> GetSitePermissions(string Appid)
  45. {
  46. var Permission = _fsql.Select<AdApply, AdRoleApply, AdRole,AdRolePermission, AdPermission>()
  47. .LeftJoin((a, b, c, d,e) => a.Id == b.OauthApplyID)
  48. .LeftJoin((a, b, c, d, e) => b.OauthRoleID == c.Id)
  49. .LeftJoin((a, b, c, d, e) => c.Id == d.RoleId)
  50. .LeftJoin((a, b, c, d, e) => d.PermissionId == e.Id)
  51. .Where((a, b, c, d, e) => a.Appid == Appid)
  52. .ToList((a, b, c, d, e) => new { e });
  53. var permissionList = new List<string>();
  54. foreach (var permission in Permission)
  55. {
  56. if (permission.e != null)
  57. permissionList.Add(permission.e.Code);
  58. }
  59. permissionList.Add("Nozzle:uploadNozzle:POST");
  60. permissionList.Add("Nozzle:DeleteNozzle:Delete");
  61. return permissionList;
  62. }
  63. public Task<users> GetUsers()
  64. {
  65. return null;
  66. }
  67. }
  68. }