diff --git a/Lib/Tiobon.Core.Base.dll b/Lib/Tiobon.Core.Base.dll index f7365b8d..dd3d16bd 100644 Binary files a/Lib/Tiobon.Core.Base.dll and b/Lib/Tiobon.Core.Base.dll differ diff --git a/Lib/Tiobon.Core.Base.xml b/Lib/Tiobon.Core.Base.xml index 1ae623d0..dfdfdb70 100644 --- a/Lib/Tiobon.Core.Base.xml +++ b/Lib/Tiobon.Core.Base.xml @@ -41,7 +41,7 @@ 缓存 - + diff --git a/Lib/Tiobon.Core.dll b/Lib/Tiobon.Core.dll index f5d6e3ff..691ac89c 100644 Binary files a/Lib/Tiobon.Core.dll and b/Lib/Tiobon.Core.dll differ diff --git a/Lib/Tiobon.Core.xml b/Lib/Tiobon.Core.xml index 71f1c350..29a3771a 100644 --- a/Lib/Tiobon.Core.xml +++ b/Lib/Tiobon.Core.xml @@ -157,6 +157,121 @@ 事务传播方式 + + + 增加缓存Key + + + + + + + 删除某特征关键字缓存 + + + + + + + 删除缓存 + + + + + + + 检查给定 key 是否存在 + + 键 + + + + + 获取所有缓存列表 + + + + + + 获取缓存 + + + + + + + + 获取缓存 + + + + + + + 删除缓存 + + + + + + + 增加对象缓存 + + + + + + + + 增加对象缓存,并设置过期时间 + + + + + + + + + 增加字符串缓存 + + + + + + + + 增加字符串缓存,并设置过期时间 + + + + + + + + + 缓存最大角色数据范围 + + + + + + + + 根据父键清空 + + + + + + + 缓存抽象接口,基于IDistributedCache封装 + + + + + 实现SqlSugar的ICacheService接口 + + 缓存相关常量 @@ -289,6 +404,26 @@ 以嵌套事务方式执行 + + + 资料修改模式 + + + + + 新增模式。 + + + + + 修改模式。 + + + + + 删除模式 + + 获取项目程序集,排除所有的系统程序集(Microsoft.***、System.***等)、Nuget下载包 diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRuleResultController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRuleResultController.cs index 349b259f..34646206 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRuleResultController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRuleResultController.cs @@ -23,7 +23,28 @@ public class Ghre_StudyRuleResultController : BaseController> Query(long RuleId, [FromBody] QueryBody body) { - return await _service.QueryFilterPage(body, $"StudyRuleId='{RuleId}'"); + + var result = await _service.QueryFilterPage(body, $"StudyRuleId='{RuleId}'"); + var DT_TableDataT1 = result.result.DT_TableDataT1; + int index1 = 0; + int index2 = 0; + for (int i = 0; i < DT_TableDataT1.Count; i++) + { + if (DT_TableDataT1[i].Status == "SUCCESS") + { + index1++; + DT_TableDataT1[i].Index = index1; + } + else + { + index2++; + DT_TableDataT1[i].Index = index2; + } + } + + + result.result.DT_TableDataT1 = DT_TableDataT1; + return result; } #endregion diff --git a/Tiobon.Core.Api/Controllers/Systems/CacheManageController.cs b/Tiobon.Core.Api/Controllers/Systems/CacheManageController.cs index c5c0dd1d..5093f7df 100644 --- a/Tiobon.Core.Api/Controllers/Systems/CacheManageController.cs +++ b/Tiobon.Core.Api/Controllers/Systems/CacheManageController.cs @@ -1,4 +1,4 @@ -using Tiobon.Core.Common.Caches; +using Tiobon.Core.Caches; namespace Tiobon.Core.Api.Controllers.Systems; /// diff --git a/Tiobon.Core.Common/Caches/Caching.cs b/Tiobon.Core.Common/Caches/Caching.cs deleted file mode 100644 index 5cca5033..00000000 --- a/Tiobon.Core.Common/Caches/Caching.cs +++ /dev/null @@ -1,342 +0,0 @@ -using Microsoft.Extensions.Caching.Distributed; -using Newtonsoft.Json; -using System.Text; -using Tiobon.Core.Const; - -namespace Tiobon.Core.Common.Caches; - -public class Caching : ICaching -{ - private readonly IDistributedCache _cache; - - public Caching(IDistributedCache cache) - { - _cache = cache; - } - - private byte[] GetBytes(T source) - { - return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(source)); - } - - public IDistributedCache Cache => _cache; - - public void AddCacheKey(string cacheKey) - { - var res = _cache.GetString(CacheConst.KeyAll); - var allkeys = string.IsNullOrWhiteSpace(res) ? new List() : JsonConvert.DeserializeObject>(res); - if (!allkeys.Any(m => m == cacheKey)) - { - allkeys.Add(cacheKey); - _cache.SetString(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); - } - } - - /// - /// 增加缓存Key - /// - /// - /// - public async Task AddCacheKeyAsync(string cacheKey) - { - var res = await _cache.GetStringAsync(CacheConst.KeyAll); - var allkeys = string.IsNullOrWhiteSpace(res) ? new List() : JsonConvert.DeserializeObject>(res); - if (!allkeys.Any(m => m == cacheKey)) - { - allkeys.Add(cacheKey); - await _cache.SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); - } - } - - public void DelByPattern(string key) - { - var allkeys = GetAllCacheKeys(); - if (allkeys == null) return; - - var delAllkeys = allkeys.Where(u => u.Contains(key)).ToList(); - delAllkeys.ForEach(u => { _cache.Remove(u); }); - - // 更新所有缓存键 - allkeys = allkeys.Where(u => !u.Contains(key)).ToList(); - _cache.SetString(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); - } - - /// - /// 删除某特征关键字缓存 - /// - /// - /// - public async Task DelByPatternAsync(string key) - { - var allkeys = await GetAllCacheKeysAsync(); - if (allkeys == null) return; - - var delAllkeys = allkeys.Where(u => u.Contains(key)).ToList(); - delAllkeys.ForEach(u => { _cache.Remove(u); }); - - // 更新所有缓存键 - allkeys = allkeys.Where(u => !u.Contains(key)).ToList(); - await _cache.SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); - } - - public void DelCacheKey(string cacheKey) - { - var res = _cache.GetString(CacheConst.KeyAll); - var allkeys = string.IsNullOrWhiteSpace(res) ? new List() : JsonConvert.DeserializeObject>(res); - if (allkeys.Any(m => m == cacheKey)) - { - allkeys.Remove(cacheKey); - _cache.SetString(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); - } - } - - /// - /// 删除缓存 - /// - /// - /// - public async Task DelCacheKeyAsync(string cacheKey) - { - var res = await _cache.GetStringAsync(CacheConst.KeyAll); - var allkeys = string.IsNullOrWhiteSpace(res) ? new List() : JsonConvert.DeserializeObject>(res); - if (allkeys.Any(m => m == cacheKey)) - { - allkeys.Remove(cacheKey); - await _cache.SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); - } - } - - public bool Exists(string cacheKey) - { - var res = _cache.Get(cacheKey); - return res != null; - } - - /// - /// 检查给定 key 是否存在 - /// - /// 键 - /// - public async Task ExistsAsync(string cacheKey) - { - var res = await _cache.GetAsync(cacheKey); - return res != null; - } - - public List GetAllCacheKeys() - { - var res = _cache.GetString(CacheConst.KeyAll); - return string.IsNullOrWhiteSpace(res) ? null : JsonConvert.DeserializeObject>(res); - } - - /// - /// 获取所有缓存列表 - /// - /// - public async Task> GetAllCacheKeysAsync() - { - var res = await _cache.GetStringAsync(CacheConst.KeyAll); - return string.IsNullOrWhiteSpace(res) ? null : JsonConvert.DeserializeObject>(res); - } - - public T Get(string cacheKey) - { - var res = _cache.Get(cacheKey); - return res == null ? default : JsonConvert.DeserializeObject(Encoding.UTF8.GetString(res)); - } - - /// - /// 获取缓存 - /// - /// - /// - /// - public async Task GetAsync(string cacheKey) - { - var res = await _cache.GetAsync(cacheKey); - return res == null ? default : JsonConvert.DeserializeObject(Encoding.UTF8.GetString(res)); - } - - public object Get(Type type, string cacheKey) - { - var res = _cache.Get(cacheKey); - return res == null ? default : JsonConvert.DeserializeObject(Encoding.UTF8.GetString(res), type); - } - - public async Task GetAsync(Type type, string cacheKey) - { - var res = await _cache.GetAsync(cacheKey); - return res == null ? default : JsonConvert.DeserializeObject(Encoding.UTF8.GetString(res), type); - } - - public string GetString(string cacheKey) - { - return _cache.GetString(cacheKey); - } - - /// - /// 获取缓存 - /// - /// - /// - public async Task GetStringAsync(string cacheKey) - { - return await _cache.GetStringAsync(cacheKey); - } - - public void Remove(string key) - { - _cache.Remove(key); - DelCacheKey(key); - } - - /// - /// 删除缓存 - /// - /// - /// - public async Task RemoveAsync(string key) - { - await _cache.RemoveAsync(key); - await DelCacheKeyAsync(key); - } - - public void RemoveAll() - { - var catches = GetAllCacheKeys(); - foreach (var @catch in catches) Remove(@catch); - - catches.Clear(); - _cache.SetString(CacheConst.KeyAll, JsonConvert.SerializeObject(catches)); - } - - public async Task RemoveAllAsync() - { - var catches = await GetAllCacheKeysAsync(); - foreach (var @catch in catches) await RemoveAsync(@catch); - - catches.Clear(); - await _cache.SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(catches)); - } - - - public void Set(string cacheKey, T value, TimeSpan? expire = null) - { - _cache.Set(cacheKey, GetBytes(value), - expire == null - ? new DistributedCacheEntryOptions() {AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6)} - : new DistributedCacheEntryOptions() {AbsoluteExpirationRelativeToNow = expire}); - - AddCacheKey(cacheKey); - } - - /// - /// 增加对象缓存 - /// - /// - /// - /// - public async Task SetAsync(string cacheKey, T value) - { - await _cache.SetAsync(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)), - new DistributedCacheEntryOptions() {AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6)}); - - await AddCacheKeyAsync(cacheKey); - } - - /// - /// 增加对象缓存,并设置过期时间 - /// - /// - /// - /// - /// - public async Task SetAsync(string cacheKey, T value, TimeSpan expire) - { - await _cache.SetAsync(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)), - new DistributedCacheEntryOptions() {AbsoluteExpirationRelativeToNow = expire}); - - await AddCacheKeyAsync(cacheKey); - } - - public void SetPermanent(string cacheKey, T value) - { - _cache.Set(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value))); - AddCacheKey(cacheKey); - } - - public async Task SetPermanentAsync(string cacheKey, T value) - { - await _cache.SetAsync(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value))); - await AddCacheKeyAsync(cacheKey); - } - - public void SetString(string cacheKey, string value, TimeSpan? expire = null) - { - if (expire == null) - _cache.SetString(cacheKey, value, new DistributedCacheEntryOptions() {AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6)}); - else - _cache.SetString(cacheKey, value, new DistributedCacheEntryOptions() {AbsoluteExpirationRelativeToNow = expire}); - - AddCacheKey(cacheKey); - } - - /// - /// 增加字符串缓存 - /// - /// - /// - /// - public async Task SetStringAsync(string cacheKey, string value) - { - await _cache.SetStringAsync(cacheKey, value, new DistributedCacheEntryOptions() {AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6)}); - - await AddCacheKeyAsync(cacheKey); - } - - /// - /// 增加字符串缓存,并设置过期时间 - /// - /// - /// - /// - /// - public async Task SetStringAsync(string cacheKey, string value, TimeSpan expire) - { - await _cache.SetStringAsync(cacheKey, value, new DistributedCacheEntryOptions() {AbsoluteExpirationRelativeToNow = expire}); - - await AddCacheKeyAsync(cacheKey); - } - - - /// - /// 缓存最大角色数据范围 - /// - /// - /// - /// - public async Task SetMaxDataScopeType(long userId, int dataScopeType) - { - var cacheKey = CacheConst.KeyMaxDataScopeType + userId; - await SetStringAsync(cacheKey, dataScopeType.ToString()); - - await AddCacheKeyAsync(cacheKey); - } - - /// - /// 根据父键清空 - /// - /// - /// - public async Task DelByParentKeyAsync(string key) - { - var allkeys = await GetAllCacheKeysAsync(); - if (allkeys == null) return; - - var delAllkeys = allkeys.Where(u => u.StartsWith(key)).ToList(); - delAllkeys.ForEach(Remove); - // 更新所有缓存键 - allkeys = allkeys.Where(u => !u.StartsWith(key)).ToList(); - await SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); - } -} \ No newline at end of file diff --git a/Tiobon.Core.Common/Caches/ICaching.cs b/Tiobon.Core.Common/Caches/ICaching.cs deleted file mode 100644 index e2710358..00000000 --- a/Tiobon.Core.Common/Caches/ICaching.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Microsoft.Extensions.Caching.Distributed; - -namespace Tiobon.Core.Common.Caches; - -/// -/// 缓存抽象接口,基于IDistributedCache封装 -/// -public interface ICaching -{ - public IDistributedCache Cache { get; } - void AddCacheKey(string cacheKey); - Task AddCacheKeyAsync(string cacheKey); - - void DelByPattern(string key); - Task DelByPatternAsync(string key); - - void DelCacheKey(string cacheKey); - Task DelCacheKeyAsync(string cacheKey); - - bool Exists(string cacheKey); - Task ExistsAsync(string cacheKey); - - List GetAllCacheKeys(); - Task> GetAllCacheKeysAsync(); - - T Get(string cacheKey); - Task GetAsync(string cacheKey); - - object Get(Type type, string cacheKey); - Task GetAsync(Type type, string cacheKey); - - string GetString(string cacheKey); - Task GetStringAsync(string cacheKey); - - void Remove(string key); - Task RemoveAsync(string key); - - void RemoveAll(); - Task RemoveAllAsync(); - - void Set(string cacheKey, T value, TimeSpan? expire = null); - Task SetAsync(string cacheKey, T value); - Task SetAsync(string cacheKey, T value, TimeSpan expire); - - void SetPermanent(string cacheKey, T value); - Task SetPermanentAsync(string cacheKey, T value); - - void SetString(string cacheKey, string value, TimeSpan? expire = null); - Task SetStringAsync(string cacheKey, string value); - Task SetStringAsync(string cacheKey, string value, TimeSpan expire); - - Task DelByParentKeyAsync(string key); -} \ No newline at end of file diff --git a/Tiobon.Core.Common/Caches/SqlSugarCacheService.cs b/Tiobon.Core.Common/Caches/SqlSugarCacheService.cs deleted file mode 100644 index c10ed8e0..00000000 --- a/Tiobon.Core.Common/Caches/SqlSugarCacheService.cs +++ /dev/null @@ -1,60 +0,0 @@ -using SqlSugar; - -namespace Tiobon.Core.Common.Caches; - -/// -/// 实现SqlSugar的ICacheService接口 -/// -public class SqlSugarCacheService : ICacheService -{ - private readonly Lazy _caching = new(() => App.GetService(false)); - private ICaching Caching => _caching.Value; - - public void Add(string key, V value) - { - Caching.Set(key, value); - } - - public void Add(string key, V value, int cacheDurationInSeconds) - { - Caching.Set(key, value, TimeSpan.FromSeconds(cacheDurationInSeconds)); - } - - public bool ContainsKey(string key) - { - return Caching.Exists(key); - } - - public V Get(string key) - { - return Caching.Get(key); - } - - public IEnumerable GetAllKey() - { - return Caching.GetAllCacheKeys(); - } - - public V GetOrCreate(string cacheKey, Func create, int cacheDurationInSeconds = int.MaxValue) - { - if (!ContainsKey(cacheKey)) - { - var value = create(); - Caching.Set(cacheKey, value, TimeSpan.FromSeconds(cacheDurationInSeconds)); - return value; - } - - return Caching.Get(cacheKey); - } - - public void Remove(string key) - { - Caching.Remove(key); - } - - public bool RemoveAll() - { - Caching.RemoveAll(); - return true; - } -} \ No newline at end of file diff --git a/Tiobon.Core.Common/Enums/ModifyType.cs b/Tiobon.Core.Common/Enums/ModifyType.cs deleted file mode 100644 index 246b0568..00000000 --- a/Tiobon.Core.Common/Enums/ModifyType.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Tiobon.Core.Common.Enums; - -/// -/// 资料修改模式 -/// -public enum ModifyType -{ - /// - /// 新增模式。 - /// - Add, - /// - /// 修改模式。 - /// - Edit, - /// - /// 删除模式 - /// - Delete -} diff --git a/Tiobon.Core.Common/Extensions/ExpressionExtensions.cs b/Tiobon.Core.Common/Extensions/ExpressionExtensions.cs index 74cd3542..fe00f4e4 100644 --- a/Tiobon.Core.Common/Extensions/ExpressionExtensions.cs +++ b/Tiobon.Core.Common/Extensions/ExpressionExtensions.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Http; using System.Linq.Expressions; -using Tiobon.Core.Common.Caches; +using Tiobon.Core.Caches; namespace Tiobon.Core.Common.Helper; diff --git a/Tiobon.Core.Extensions/AOP/BlogCacheAOP.cs b/Tiobon.Core.Extensions/AOP/BlogCacheAOP.cs index 72f7c3df..1d3f3c31 100644 --- a/Tiobon.Core.Extensions/AOP/BlogCacheAOP.cs +++ b/Tiobon.Core.Extensions/AOP/BlogCacheAOP.cs @@ -1,6 +1,6 @@ using Castle.DynamicProxy; using Tiobon.Core.Common; -using Tiobon.Core.Common.Caches; +using Tiobon.Core.Caches; namespace Tiobon.Core.AOP; diff --git a/Tiobon.Core.Extensions/ServiceExtensions/CacheSetup.cs b/Tiobon.Core.Extensions/ServiceExtensions/CacheSetup.cs index 91717d1f..dba32c9b 100644 --- a/Tiobon.Core.Extensions/ServiceExtensions/CacheSetup.cs +++ b/Tiobon.Core.Extensions/ServiceExtensions/CacheSetup.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using StackExchange.Redis; -using Tiobon.Core.Common.Caches; +using Tiobon.Core.Caches; using Tiobon.Core.Option; namespace Tiobon.Core.Extensions.ServiceExtensions; diff --git a/Tiobon.Core.Extensions/ServiceExtensions/SqlsugarSetup.cs b/Tiobon.Core.Extensions/ServiceExtensions/SqlsugarSetup.cs index 2f99bc4b..71630679 100644 --- a/Tiobon.Core.Extensions/ServiceExtensions/SqlsugarSetup.cs +++ b/Tiobon.Core.Extensions/ServiceExtensions/SqlsugarSetup.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using SqlSugar; using System.Text.RegularExpressions; -using Tiobon.Core.Common.Caches; +using Tiobon.Core.Caches; using Tiobon.Core.Common.DB; using Tiobon.Core.Common.DB.Aop; using Tiobon.Core.Const; @@ -32,7 +32,7 @@ public static class SqlsugarSetup { ConfigId = m.ConnId.ObjToString().ToLower(), ConnectionString = m.Connection, - DbType = (DbType) m.DbType, + DbType = (DbType)m.DbType, IsAutoCloseConnection = true, // Check out more information: https://github.com/anjoy8/Tiobon.Core/issues/122 //IsShardSameThread = false, @@ -99,7 +99,7 @@ public static class SqlsugarSetup { BaseDBConfig.ValidConfig.ForEach(config => { - var dbProvider = db.GetConnectionScope((string) config.ConfigId); + var dbProvider = db.GetConnectionScope((string)config.ConfigId); // 打印SQL语句 dbProvider.Aop.OnLogExecuting = (s, parameters) => diff --git a/Tiobon.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs b/Tiobon.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs index 9b238138..4608939d 100644 --- a/Tiobon.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs +++ b/Tiobon.Core.Gateway/Helper/CustomJwtTokenAuthMiddleware.cs @@ -2,7 +2,7 @@ using System.Text.RegularExpressions; using Microsoft.AspNetCore.Authentication; using Tiobon.Core.Common; -using Tiobon.Core.Common.Caches; +using Tiobon.Core.Caches; using Tiobon.Core.Common.Helper; namespace Tiobon.Core.AuthHelper diff --git a/Tiobon.Core.Gateway/Startup.cs b/Tiobon.Core.Gateway/Startup.cs index 458a56a8..05dc484a 100644 --- a/Tiobon.Core.Gateway/Startup.cs +++ b/Tiobon.Core.Gateway/Startup.cs @@ -1,79 +1,77 @@ -using Tiobon.Core.AuthHelper; -using Tiobon.Core.Common; -using Tiobon.Core.Common.Caches; +using Microsoft.AspNetCore.Authentication; +using System.Reflection; +using Tiobon.Core.AuthHelper; +using Tiobon.Core.Caches; using Tiobon.Core.Extensions; using Tiobon.Core.Gateway.Extensions; -using Microsoft.AspNetCore.Authentication; -using System.Reflection; -namespace Tiobon.Core.AdminMvc +namespace Tiobon.Core.AdminMvc; + +public class Startup { - public class Startup + /** + *┌──────────────────────────────────────────────────────────────┐ + *│ 描 述:模拟一个网关项目 + *│ 测 试:在网关swagger中查看具体的服务 + *│ 作 者:anson zhang + *└──────────────────────────────────────────────────────────────┘ + */ + public Startup(IConfiguration configuration, IWebHostEnvironment env) { - /** - *┌──────────────────────────────────────────────────────────────┐ - *│ 描 述:模拟一个网关项目 - *│ 测 试:在网关swagger中查看具体的服务 - *│ 作 者:anson zhang - *└──────────────────────────────────────────────────────────────┘ - */ - public Startup(IConfiguration configuration, IWebHostEnvironment env) - { - Configuration = configuration; - } + Configuration = configuration; + } - public IConfiguration Configuration { get; } + public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) - { - services.AddSingleton(new AppSettings(Configuration)); + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + services.AddSingleton(new AppSettings(Configuration)); - services.AddAuthentication() - .AddScheme(Permissions.GWName, _ => { }); + services.AddAuthentication() + .AddScheme(Permissions.GWName, _ => { }); - services.AddCustomSwaggerSetup(); + services.AddCustomSwaggerSetup(); - services.AddControllers(); + services.AddControllers(); - services.AddHttpContextSetup(); + services.AddHttpContextSetup(); - services.AddCorsSetup(); + services.AddCorsSetup(); - services.AddMemoryCache(); - services.AddDistributedMemoryCache(); - services.AddSingleton(); + services.AddMemoryCache(); + services.AddDistributedMemoryCache(); + services.AddSingleton(); - services.AddCustomOcelotSetup(); - } + services.AddCustomOcelotSetup(); + } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } + app.UseDeveloperExceptionPage(); + } - app.UseRouting(); + app.UseRouting(); - app.UseAuthentication(); - app.UseAuthorization(); + app.UseAuthentication(); + app.UseAuthorization(); - app.UseCustomSwaggerMildd(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("Tiobon.Core.Gateway.index.html")); + app.UseCustomSwaggerMildd(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("Tiobon.Core.Gateway.index.html")); - app.UseCors(AppSettings.app(new string[] { "Startup", "Cors", "PolicyName" })); + app.UseCors(AppSettings.app(new string[] { "Startup", "Cors", "PolicyName" })); - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); - app.UseMiddleware(); + app.UseMiddleware(); - app.UseCustomOcelotMildd().Wait(); - } + app.UseCustomOcelotMildd().Wait(); } } diff --git a/Tiobon.Core.Model/View/Ghre/Ghre_StudyRuleResult.Dto.View.cs b/Tiobon.Core.Model/View/Ghre/Ghre_StudyRuleResult.Dto.View.cs index bd0a5442..6de299bd 100644 --- a/Tiobon.Core.Model/View/Ghre/Ghre_StudyRuleResult.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghre/Ghre_StudyRuleResult.Dto.View.cs @@ -31,4 +31,5 @@ public class Ghre_StudyRuleResultDto : Ghre_StudyRuleResult /// 修改信息 /// public string UpdateDataInfo { get; set; } + public int Index { get; set; } } diff --git a/Tiobon.Core.Services/Ghra/Ghra_StaffGroupServices.cs b/Tiobon.Core.Services/Ghra/Ghra_StaffGroupServices.cs index 08dc3b38..7ac2c7ab 100644 --- a/Tiobon.Core.Services/Ghra/Ghra_StaffGroupServices.cs +++ b/Tiobon.Core.Services/Ghra/Ghra_StaffGroupServices.cs @@ -1,74 +1,57 @@ - -using Tiobon.Core.IServices; -using Tiobon.Core.Model.Models; -using Tiobon.Core.Services.BASE; -using Tiobon.Core.IRepository.Base; -using Tiobon.Core.Common.Caches; -using System.Collections.Generic; -using MySqlX.XDevAPI.Relational; -using Microsoft.EntityFrameworkCore.Metadata.Internal; -using NPOI.POIFS.NIO; -using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource; -using MySqlX.XDevAPI.Common; -using System.Text; -using Microsoft.AspNetCore.Identity; -using System.Linq; -using Amazon.Runtime.Internal.Transform; +namespace Tiobon.Core.Services; -namespace Tiobon.Core.Services +/// +/// 人员群组 (服务) +/// +public class Ghra_StaffGroupServices : BaseServices, IGhra_StaffGroupServices { - /// - /// 人员群组 (服务) - /// - public class Ghra_StaffGroupServices : BaseServices, IGhra_StaffGroupServices + private readonly IBaseRepository _dal; + private IGhra_StaffGroupDetailServices _StaffGroupDetailServices; + public Ghra_StaffGroupServices(ICaching caching, IBaseRepository dal, + IGhra_StaffGroupDetailServices StaffGroupDetailServices + ) { - private readonly IBaseRepository _dal; - private IGhra_StaffGroupDetailServices _StaffGroupDetailServices; - public Ghra_StaffGroupServices(ICaching caching, IBaseRepository dal, - IGhra_StaffGroupDetailServices StaffGroupDetailServices - ) - { - this._dal = dal; - base.BaseDal = dal; - base._caching = caching; - _StaffGroupDetailServices = StaffGroupDetailServices; - } + this._dal = dal; + base.BaseDal = dal; + base._caching = caching; + _StaffGroupDetailServices = StaffGroupDetailServices; + } - public override async Task Add(InsertGhra_StaffGroupInput entity) + public override async Task Add(InsertGhra_StaffGroupInput entity) + { + + var result = await base.Add(entity); + entity.StaffGroupDetail.ForEach(x => { + x.StaffGroupID = result; + }); - var result = await base.Add(entity); - entity.StaffGroupDetail.ForEach(x => - { - x.StaffGroupID = result; - }); + await _StaffGroupDetailServices.Add(entity.StaffGroupDetail); - await _StaffGroupDetailServices.Add(entity.StaffGroupDetail); + return result; + } - return result; - } + public override async Task Update(long Id, EditGhra_StaffGroupInput editModel) + { + await _StaffGroupDetailServices.Delete(x => x.StaffGroupID == Id); - public override async Task Update(long Id, EditGhra_StaffGroupInput editModel) + editModel.StaffGroupDetail.ForEach(x => { - await _StaffGroupDetailServices.Delete(x => x.StaffGroupID == Id); - - editModel.StaffGroupDetail.ForEach(x => - { - x.StaffGroupID = Id; - }); - await _StaffGroupDetailServices.Add(editModel.StaffGroupDetail); + x.StaffGroupID = Id; + }); + await _StaffGroupDetailServices.Add(editModel.StaffGroupDetail); - return await base.Update(Id, editModel); - } - public override async Task DeleteById1(object id) - { - var entity = await BaseDal.QueryById(id); - BasePoco ent = entity as BasePoco; - ent.IsEnable = 0; - HttpRequest request = UserContext.Context.Request; - var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - var ip = GetUserIp(UserContext.Context); - string sql = @$"update Ghra_StaffGroupDetail + return await base.Update(Id, editModel); + } + public override async Task DeleteById1(object id) + { + var entity = await BaseDal.QueryById(id); + BasePoco ent = entity as BasePoco; + ent.IsEnable = 0; + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); + string sql = @$"update Ghra_StaffGroupDetail set IsEnable=0, UpdateBy={App.User.ID.ToString()}, UpdateIP={ip}, @@ -77,58 +60,58 @@ namespace Tiobon.Core.Services where StaffGroupID={id.ToString()} and IsEnable= 1"; - return await BaseDal.Update(entity); - } + return await BaseDal.Update(entity); + } - public override async Task> QueryForm(QueryForm body) - { - var result = await base.QueryForm(body); + public override async Task> QueryForm(QueryForm body) + { + var result = await base.QueryForm(body); - var StaffGroupDetail = await _StaffGroupDetailServices.Query(x => x.StaffGroupID == body.id); - result.result.DT_TableDataT1[0].StaffGroupDetail = StaffGroupDetail.OrderBy(x => x.SortNo).ToList(); - result.result.DT_TableDataT1[0].StaffGroupDetail.ForEach((x) => + var StaffGroupDetail = await _StaffGroupDetailServices.Query(x => x.StaffGroupID == body.id); + result.result.DT_TableDataT1[0].StaffGroupDetail = StaffGroupDetail.OrderBy(x => x.SortNo).ToList(); + result.result.DT_TableDataT1[0].StaffGroupDetail.ForEach((x) => + { + if (x.FieldValue != null) { - if (x.FieldValue != null) + if (JsonHelper.IsJson(x.FieldValue.ToString())) { - if (JsonHelper.IsJson(x.FieldValue.ToString())) + try + { + x.FieldValue = JsonHelper.JsonToObj>(x.FieldValue.ToString()); + } + catch (Exception) { - try - { - x.FieldValue = JsonHelper.JsonToObj>(x.FieldValue.ToString()); - } - catch (Exception) - { - x.FieldValue = JsonHelper.JsonToObj>(x.FieldValue.ToString()); - } + x.FieldValue = JsonHelper.JsonToObj>(x.FieldValue.ToString()); } } - }); - if (body.doType == "Copy") - { - result.result.DT_TableDataT1[0].StaffGroupNo = null; - result.result.DT_TableDataT1[0].StaffGroupName = null; } - return result; - } - public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + }); + if (body.doType == "Copy") { + result.result.DT_TableDataT1[0].StaffGroupNo = null; + result.result.DT_TableDataT1[0].StaffGroupName = null; + } + return result; + } + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + { - var result = await base.QueryFilterPage(filter, condition, IsEnable); + var result = await base.QueryFilterPage(filter, condition, IsEnable); - result.result.DT_TableDataT1.ForEach(async x => - { - x.DetailInfo = Db.Ado.SqlQuerySingle($@"select stuff((select distinct ',' + (select top 1 dbo.FLangKeyToValue(MKey,1,StaffInfoColumnName) from Ghra_StaffInfoColumn where IsEnable=1 and StaffInfoGroupId = 1 and IsRelease = 1 and StaffInfoColumnNo=a.StaffField) + result.result.DT_TableDataT1.ForEach(async x => + { + x.DetailInfo = Db.Ado.SqlQuerySingle($@"select stuff((select distinct ',' + (select top 1 dbo.FLangKeyToValue(MKey,1,StaffInfoColumnName) from Ghra_StaffInfoColumn where IsEnable=1 and StaffInfoGroupId = 1 and IsRelease = 1 and StaffInfoColumnNo=a.StaffField) from Ghra_StaffGroupDetail a where StaffGroupID = {x.Id} for XML path(''),type).value('.','nvarchar(max)'),1,1,'')"); - }); + }); - return result; - } + return result; + } - public async Task> GetStaffInfoColumnData() - { - string sql = @$"select StaffInfoColumnNo, + public async Task> GetStaffInfoColumnData() + { + string sql = @$"select StaffInfoColumnNo, dbo.FLangKeyToValue(MKey,1,StaffInfoColumnName) StaffInfoColumnName, ColumnType elementType, DataType dataType, @@ -160,20 +143,20 @@ namespace Tiobon.Core.Services and IsRelease = 1 and StaffInfoColumnNo != 'AttachmentIDs' "; - var result = Db.Ado.SqlQuery(sql); - result.ForEach(x => - { - x.operatorData = JsonConvert.DeserializeObject>(x.OperatorDataStr); - }); - return ServiceResult.OprateSuccess("查询成功!", result); - } - - public async Task>> GetStaffGroupInfoByID(long Id,JObject FBody) + var result = Db.Ado.SqlQuery(sql); + result.ForEach(x => { - string LangID = App.User.GetLangId().ToString(); - string BaseDate = FBody["BaseDate"]?.Value() ?? DateTime.Now.ToString("yyyy-MM-dd"); - if (LangID == "0") LangID = "1"; - string sql = @$"select case when Operator not in ('IsNull','NotNull') then iif(IsChangeColumn = 1,'b.','a.')+StaffField + x.operatorData = JsonConvert.DeserializeObject>(x.OperatorDataStr); + }); + return ServiceResult.OprateSuccess("查询成功!", result); + } + + public async Task>> GetStaffGroupInfoByID(long Id, JObject FBody) + { + string LangID = App.User.GetLangId().ToString(); + string BaseDate = FBody["BaseDate"]?.Value() ?? DateTime.Now.ToString("yyyy-MM-dd"); + if (LangID == "0") LangID = "1"; + string sql = @$"select case when Operator not in ('IsNull','NotNull') then iif(IsChangeColumn = 1,'b.','a.')+StaffField + case when Operator = 'Equal' then ' = '+' '''+ISNULL(FieldValue,'')+''' ' when Operator = 'NotEqual' @@ -231,31 +214,31 @@ namespace Tiobon.Core.Services and StaffGroupID = '{Id}' order by b.SortNo"; - DataTable dt = await Db.Ado.GetDataTableAsync(sql); - string WhereSQL = string.Empty; - string SqlStr = string.Empty; - - List staffInfoColumns = new List(); - staffInfoColumns.Add(new StaffInfoColumn() { StaffInfoColumnNo = "StaffID", StaffInfoColumnName = "ID",isHidden=true }); - staffInfoColumns.Add(new StaffInfoColumn() { StaffInfoColumnNo = "StaffNo", StaffInfoColumnName = "工号" }); - staffInfoColumns.Add(new StaffInfoColumn() { StaffInfoColumnNo = "StaffName", StaffInfoColumnName = "姓名" }); - staffInfoColumns.Add(new StaffInfoColumn() { StaffInfoColumnNo = "DeptFullPateName", StaffInfoColumnName = "全部门" }); - foreach (DataRow dr in dt.Rows) - { - WhereSQL += " and "+dr["WhereStr"].ToString(); + DataTable dt = await Db.Ado.GetDataTableAsync(sql); + string WhereSQL = string.Empty; + string SqlStr = string.Empty; - StaffInfoColumn staffInfo = new StaffInfoColumn(); - staffInfo.StaffInfoColumnNo = dr["ColumnNo"].ToString(); - staffInfo.StaffInfoColumnName = dr["ColumnName"].ToString(); - -; if ( !staffInfoColumns.Any(x => x.StaffInfoColumnNo == dr["ColumnNo"].ToString())) - { - staffInfoColumns.Add(staffInfo); - SqlStr += ","+dr["SqlStr"].ToString(); - } + List staffInfoColumns = new List(); + staffInfoColumns.Add(new StaffInfoColumn() { StaffInfoColumnNo = "StaffID", StaffInfoColumnName = "ID", isHidden = true }); + staffInfoColumns.Add(new StaffInfoColumn() { StaffInfoColumnNo = "StaffNo", StaffInfoColumnName = "工号" }); + staffInfoColumns.Add(new StaffInfoColumn() { StaffInfoColumnNo = "StaffName", StaffInfoColumnName = "姓名" }); + staffInfoColumns.Add(new StaffInfoColumn() { StaffInfoColumnNo = "DeptFullPateName", StaffInfoColumnName = "全部门" }); + foreach (DataRow dr in dt.Rows) + { + WhereSQL += " and " + dr["WhereStr"].ToString(); + + StaffInfoColumn staffInfo = new StaffInfoColumn(); + staffInfo.StaffInfoColumnNo = dr["ColumnNo"].ToString(); + staffInfo.StaffInfoColumnName = dr["ColumnName"].ToString(); + + ; if (!staffInfoColumns.Any(x => x.StaffInfoColumnNo == dr["ColumnNo"].ToString())) + { + staffInfoColumns.Add(staffInfo); + SqlStr += "," + dr["SqlStr"].ToString(); } + } - string StaffSql = @$"select a.StaffID,a.StaffNo,a.StaffName, + string StaffSql = @$"select a.StaffID,a.StaffNo,a.StaffName, dbo.FA_StaffInfoRepItemStaffInfo(a.StaffID,null,{LangID},'DeptFullPateName') DeptFullPateName {SqlStr} from Ghra_Staff a inner join (select * from Ghra_StaffChange where IsEnable=1 and ChangeDate= [dbo].[FLatestStaffChangeDate](StaffID,'{BaseDate}') )b @@ -263,39 +246,36 @@ namespace Tiobon.Core.Services where a.IsEnable=1 and a.InDate <= '{BaseDate}' and (a.OutDate is null or a.OutDate>= '{BaseDate}' ) " - + WhereSQL; + + WhereSQL; - DataTable staffTable = await Db.Ado.GetDataTableAsync(StaffSql); - Dictionary result = new Dictionary() - { - ["TableColumns"] = staffInfoColumns, - ["TableData"] = staffTable - }; - return ServiceResult>.OprateSuccess("查询成功!", result); - } - public class StaffInfoColumn() - { - public string StaffInfoColumnNo { get; set; } - public string StaffInfoColumnName { get; set; } - public bool isHidden { get; set; } = false; - public string elementType { get; set; } - public string dataType { get; set; } - public string dataSourceType { get; set; } - public string dataSource { get; set; } - public int multipleSelectInt { get; set; } - public bool multipleSelect => multipleSelectInt == 1 ? true : false; - public string OperatorDataStr { get; set; } - public List operatorData { get; set; } - } - public class OperatorData() + DataTable staffTable = await Db.Ado.GetDataTableAsync(StaffSql); + Dictionary result = new Dictionary() { - public string operatorNo { get; set; } - public string ParaDetailName { get; set; } - public string operatorIcon { get; set; } - public string SortNo { get; set; } - } - + ["TableColumns"] = staffInfoColumns, + ["TableData"] = staffTable + }; + return ServiceResult>.OprateSuccess("查询成功!", result); + } + public class StaffInfoColumn() + { + public string StaffInfoColumnNo { get; set; } + public string StaffInfoColumnName { get; set; } + public bool isHidden { get; set; } = false; + public string elementType { get; set; } + public string dataType { get; set; } + public string dataSourceType { get; set; } + public string dataSource { get; set; } + public int multipleSelectInt { get; set; } + public bool multipleSelect => multipleSelectInt == 1 ? true : false; + public string OperatorDataStr { get; set; } + public List operatorData { get; set; } + } + public class OperatorData() + { + public string operatorNo { get; set; } + public string ParaDetailName { get; set; } + public string operatorIcon { get; set; } + public string SortNo { get; set; } } - } \ No newline at end of file diff --git a/Tiobon.Core.Services/GlobalUsings.cs b/Tiobon.Core.Services/GlobalUsings.cs index 72cf6f70..f5abec83 100644 --- a/Tiobon.Core.Services/GlobalUsings.cs +++ b/Tiobon.Core.Services/GlobalUsings.cs @@ -8,7 +8,7 @@ global using System.Dynamic; global using System.Linq.Expressions; global using System.Reflection; global using Tiobon.Core.Common; -global using Tiobon.Core.Common.Caches; +global using Tiobon.Core.Caches; global using Tiobon.Core.Common.DB.Dapper; global using Tiobon.Core.Common.DB.Dapper.Extensions; global using Tiobon.Core.Common.Enums;