using Bowin.Common.Cache; using Bowin.Common.JSON; using Bowin.Common.ServiceToken.ApiIdentity.Model; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using YLShipBuildLandMap.Entity; using Z.EntityFramework.Plus; namespace YLShipBuildLandMap.Services.SystemSetting { public class SystemService : ISystemService { private YLShipBuildLandMapContext DbContext { get; set; } private readonly MemoryCacheEntryOptions mCacheOp; public SystemService(YLShipBuildLandMapContext dbContext, IOptions iopCacheOp) { DbContext = dbContext; mCacheOp = iopCacheOp.Value; } private IQueryable GetSystemModelQueryable() { var sql = (from sys in DbContext.SysSystem select new SystemModel { SystemID = sys.SystemId, Secret = sys.Secret }); return sql; } private IQueryable GetScopeQueryable(Expression> exp) { var sql = (from sys in DbContext.SysSystem.Where(exp) join ssc in DbContext.SysSystemSysApiScope on sys.SystemId equals ssc.SystemId join scope in DbContext.SysApiScope on ssc.ApiScopeId equals scope.ApiScopeId select scope); return sql; } public List GetScopeList(string systemID) { var key = "SystemScope_" + systemID + "_List_Cache"; var json = (string)CacheHelper.Get(key); if (json != null) { return json.ToObject>(); } var scopeList = this.GetScopeQueryable(x => x.SystemId == systemID).OrderBy(x => x.Name).FromCacheAsync(mCacheOp).Result.Select(x => x.ApiScopeId).ToList(); return scopeList; } public List GetSystemList() { var key = "System_List_Cache"; var json = (string)CacheHelper.Get(key); if (json != null) { return json.ToObject>(); } var systemList = this.GetSystemModelQueryable().OrderBy(x => x.SystemID).FromCacheAsync(mCacheOp).Result.ToList(); return systemList; } } }