1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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<MemoryCacheEntryOptions> iopCacheOp)
- {
- DbContext = dbContext;
- mCacheOp = iopCacheOp.Value;
- }
- private IQueryable<SystemModel> GetSystemModelQueryable()
- {
- var sql = (from sys in DbContext.SysSystem
- select new SystemModel
- {
- SystemID = sys.SystemId,
- Secret = sys.Secret
- });
- return sql;
- }
- private IQueryable<SysApiScope> GetScopeQueryable(Expression<Func<SysSystem, bool>> 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<string> GetScopeList(string systemID)
- {
- var key = "SystemScope_" + systemID + "_List_Cache";
- var json = (string)CacheHelper.Get(key);
- if (json != null)
- {
- return json.ToObject<List<string>>();
- }
- var scopeList = this.GetScopeQueryable(x => x.SystemId == systemID).OrderBy(x => x.Name).FromCacheAsync(mCacheOp).Result.Select(x => x.ApiScopeId).ToList();
- return scopeList;
- }
- public List<SystemModel> GetSystemList()
- {
- var key = "System_List_Cache";
- var json = (string)CacheHelper.Get(key);
- if (json != null)
- {
- return json.ToObject<List<SystemModel>>();
- }
- var systemList = this.GetSystemModelQueryable().OrderBy(x => x.SystemID).FromCacheAsync(mCacheOp).Result.ToList();
- return systemList;
- }
- }
- }
|