SystemService.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Bowin.Common.Cache;
  2. using Bowin.Common.JSON;
  3. using Bowin.Common.ServiceToken.ApiIdentity.Model;
  4. using Microsoft.Extensions.Caching.Memory;
  5. using Microsoft.Extensions.Options;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Linq.Expressions;
  10. using System.Text;
  11. using YLShipBuildLandMap.Entity;
  12. using Z.EntityFramework.Plus;
  13. namespace YLShipBuildLandMap.Services.SystemSetting
  14. {
  15. public class SystemService : ISystemService
  16. {
  17. private YLShipBuildLandMapContext DbContext { get; set; }
  18. private readonly MemoryCacheEntryOptions mCacheOp;
  19. public SystemService(YLShipBuildLandMapContext dbContext, IOptions<MemoryCacheEntryOptions> iopCacheOp)
  20. {
  21. DbContext = dbContext;
  22. mCacheOp = iopCacheOp.Value;
  23. }
  24. private IQueryable<SystemModel> GetSystemModelQueryable()
  25. {
  26. var sql = (from sys in DbContext.SysSystem
  27. select new SystemModel
  28. {
  29. SystemID = sys.SystemId,
  30. Secret = sys.Secret
  31. });
  32. return sql;
  33. }
  34. private IQueryable<SysApiScope> GetScopeQueryable(Expression<Func<SysSystem, bool>> exp)
  35. {
  36. var sql = (from sys in DbContext.SysSystem.Where(exp)
  37. join ssc in DbContext.SysSystemSysApiScope on sys.SystemId equals ssc.SystemId
  38. join scope in DbContext.SysApiScope on ssc.ApiScopeId equals scope.ApiScopeId
  39. select scope);
  40. return sql;
  41. }
  42. public List<string> GetScopeList(string systemID)
  43. {
  44. var key = "SystemScope_" + systemID + "_List_Cache";
  45. var json = (string)CacheHelper.Get(key);
  46. if (json != null)
  47. {
  48. return json.ToObject<List<string>>();
  49. }
  50. var scopeList = this.GetScopeQueryable(x => x.SystemId == systemID).OrderBy(x => x.Name).FromCacheAsync(mCacheOp).Result.Select(x => x.ApiScopeId).ToList();
  51. return scopeList;
  52. }
  53. public List<SystemModel> GetSystemList()
  54. {
  55. var key = "System_List_Cache";
  56. var json = (string)CacheHelper.Get(key);
  57. if (json != null)
  58. {
  59. return json.ToObject<List<SystemModel>>();
  60. }
  61. var systemList = this.GetSystemModelQueryable().OrderBy(x => x.SystemID).FromCacheAsync(mCacheOp).Result.ToList();
  62. return systemList;
  63. }
  64. }
  65. }