From 28c53b71ce05ce02263e3d131b5ae03f415327ec Mon Sep 17 00:00:00 2001 From: "YUN-PC5\\user" Date: Wed, 11 Oct 2023 16:58:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSqlSugarSetup=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E4=BF=AE=E6=94=B9=E5=90=8E=EF=BC=8Cnlog=E4=B8=8D?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E6=97=B6=E9=97=B4=E8=BD=AC=E6=8D=A2=E7=B1=BB?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=BC=E5=BC=8F=EF=BC=8C=E6=9A=82=E5=AD=98?= =?UTF-8?q?=E5=8C=BA=E5=9D=97=E5=92=8C=E5=AD=97=E6=AE=B5=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/Extension.Convert.cs | 5 +- .../Controllers/System/SysFieldController.cs | 24 ++++++++ .../Controllers/System/SysLoginController.cs | 9 +-- ZR.Admin.WebApi/NLog.config | 28 ++++----- ZR.Admin.WebApi/Program.cs | 58 ------------------- ZR.ServiceCore/Filters/DataFieldFilter.cs | 2 +- ZR.ServiceCore/Model/SysBlock.cs | 13 +++++ ZR.ServiceCore/Model/SysField.cs | 2 - ZR.ServiceCore/Model/SysFieldBlock.cs | 11 ++++ .../Services/IService/ISysBlockService.cs | 9 +++ .../IService/ISysFieldBlockService.cs | 9 +++ ZR.ServiceCore/Services/SysBlockService.cs | 12 ++++ .../Services/SysFieldBlockService.cs | 12 ++++ ZR.ServiceCore/Services/SysFieldService.cs | 6 +- 14 files changed, 118 insertions(+), 82 deletions(-) create mode 100644 ZR.ServiceCore/Model/SysBlock.cs create mode 100644 ZR.ServiceCore/Model/SysFieldBlock.cs create mode 100644 ZR.ServiceCore/Services/IService/ISysBlockService.cs create mode 100644 ZR.ServiceCore/Services/IService/ISysFieldBlockService.cs create mode 100644 ZR.ServiceCore/Services/SysBlockService.cs create mode 100644 ZR.ServiceCore/Services/SysFieldBlockService.cs diff --git a/Infrastructure/Extensions/Extension.Convert.cs b/Infrastructure/Extensions/Extension.Convert.cs index 4710dfd..f7706e6 100644 --- a/Infrastructure/Extensions/Extension.Convert.cs +++ b/Infrastructure/Extensions/Extension.Convert.cs @@ -170,7 +170,7 @@ namespace Infrastructure.Extensions { try { - return bool.Parse(str.ToString()); + return bool.Parse(str.ToString() ?? string.Empty); } catch { @@ -284,6 +284,9 @@ namespace Infrastructure.Extensions return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); case 12: return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); + case 13: + return DateTime.ParseExact(str, "yyyy.MM.dd ddd", + System.Globalization.CultureInfo.CurrentCulture); case 14: return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); default: diff --git a/ZR.Admin.WebApi/Controllers/System/SysFieldController.cs b/ZR.Admin.WebApi/Controllers/System/SysFieldController.cs index 7d83a42..6ca29b6 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysFieldController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysFieldController.cs @@ -1,4 +1,5 @@ using ZR.Admin.WebApi.Filters; +using ZR.ServiceCore.Model; using ZR.ServiceCore.Model.Dto; using ZR.ServiceCore.Services.IService; @@ -47,4 +48,27 @@ public class SysFieldController : BaseController [FromRoute] long roleId) => SUCCESS(await _sysRoleFieldService.InsertOrUpdateSysRoleField(sysFieldDtos, roleId)); + [HttpPost("fieldDisplay")] + public async Task FieldDisplay(string blockCode) + { + var info = JwtUtil.GetLoginUser(HttpContext); + var roleIds = info.Roles.Select(it => it.RoleId).ToList(); + var list = await _sysFieldService.Queryable() + .LeftJoin((sf, sfb) => sf.Id == sfb.FieldId) + .LeftJoin((sf, sfb, sb) => sfb.BlockId == sb.Id ) + .LeftJoin((sf,sfb, sb, srf) => sf.Id == srf.FieldId) + .Where((sf,sfb, sb, srf) => roleIds.Contains(srf.RoleId)) + .Where((sf,sfb, sb, srf) => sb.Code == blockCode) + .WithCache(10 * 60) + .Select((sf,sfb, sb, srf) => sf.FieldName) + .ToListAsync(); + // var list = await _sysFieldService.Queryable() + // .LeftJoin((sf, srf) => sf.Id == srf.FieldId) + // .Where((sf, srf) => roleIds.Contains(srf.RoleId)) + // .WithCache(10 * 60) + // .Select((sf, srf) => sf.FieldName) + // .ToListAsync(); + return SUCCESS(list); + } + } \ No newline at end of file diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 25ddbe2..d561f4f 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -1,9 +1,7 @@ using Lazy.Captcha.Core; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using NETCore.Encrypt; using ZR.Admin.WebApi.Filters; -using ZR.Model.System; using ZR.Service.System; using ZR.Service.System.IService; using ZR.ServiceCore.Model; @@ -66,8 +64,11 @@ namespace ZR.Admin.WebApi.Controllers.System { if (loginBody == null) { throw new CustomException("请求参数错误"); } loginBody.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext); - SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff"); - if (sysConfig?.ConfigValue != "off" && !SecurityCodeHelper.Validate(loginBody.Uuid, loginBody.Code)) + var sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff"); + var headers = HttpContext.Request.Headers; + var isRemoteInvoke = headers["Remote-Invoke"].FirstOrDefault().ParseToBool(); + if (sysConfig?.ConfigValue != "off" && !SecurityCodeHelper.Validate(loginBody.Uuid, loginBody.Code) + && !isRemoteInvoke) { return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误"); } diff --git a/ZR.Admin.WebApi/NLog.config b/ZR.Admin.WebApi/NLog.config index fc07a6f..b72b504 100644 --- a/ZR.Admin.WebApi/NLog.config +++ b/ZR.Admin.WebApi/NLog.config @@ -1,10 +1,10 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" + autoReload="true" + internalLogLevel="Info" + internalLogFile="nlog-internal.log"> @@ -45,14 +45,14 @@ + fileName="${basedir}/adminlogs/sql.txt" + archiveFileName="${basedir}/adminlogs/bak/sql/sql{###}.txt" + archiveEvery="Day" + archiveNumbering="DateAndSequence" + archiveAboveSize="20000000" + maxArchiveFiles="30" + keepFileOpen="false" + layout="${longdate} | ${uppercase:${level}} | ${aspnet-request-iP} | ${aspnet-request-headers:HeaderNames=userName} | ${aspnet-request-url} ${newline}${message}"/> --> - + diff --git a/ZR.Admin.WebApi/Program.cs b/ZR.Admin.WebApi/Program.cs index 9c8a844..cd79a89 100644 --- a/ZR.Admin.WebApi/Program.cs +++ b/ZR.Admin.WebApi/Program.cs @@ -3,17 +3,13 @@ using Infrastructure.Converter; using Microsoft.AspNetCore.DataProtection; using NLog.Web; using System.Text.Json; -using BloomFilter; using BloomFilter.CSRedis.Configurations; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Redis; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using ZR.Admin.WebApi.Extensions; using ZR.Infrastructure.Cache; -using ZR.Infrastructure.Resolver; using ZR.Infrastructure.WebExtensions; -using ZR.ServiceCore.Model; using ZR.ServiceCore.Services.IService; using ZR.ServiceCore.Signalr; using ZR.ServiceCore.SqlSugar; @@ -184,58 +180,4 @@ using (var serviceScope = app.Services.CreateScope()) pol.IpRules.AddRange(ipRateLimitPolicies.Adapt>()); await ipPolicyStore.SetAsync(optionsAccessor.Value.IpPolicyPrefix, pol); } - -var serviceCoreModel = AppDomain.CurrentDomain - .GetAssemblies() - .First(it => it.FullName.Contains("ZR.ServiceCore")) - .ExportedTypes - .Where(p => p.FullName.StartsWith("ZR.ServiceCore.Model")) - .ToList(); -// var geoEntityTypes = currentAssembly[0].ExportedTypes -// .Where(p => p.FullName.StartsWith("ZR.ServiceCore.Model")) -// .ToList(); -var model = AppDomain.CurrentDomain - .GetAssemblies() - .First(it => it.FullName.Contains("ZR.Model")) - .ExportedTypes - .ToList(); -foreach (var assembly in serviceCoreModel) -{ - -} - -var user = new SysUser -{ - UserName = "admin", - Password = "123456" -}; -var props = new HashSet -{ - "Name", - "Children" -}; -var article = new Article -{ - Title = "aadad", - ArticleCategoryNav = new ArticleCategory - { - Name = "adsad", - Children = new List - { - new() - { - Name = "1213" - } - } - } -}; -var apiResult = new ApiResult(200, "SUCCESS", article); -var json = JsonConvert.SerializeObject(apiResult, new JsonSerializerSettings -{ - ContractResolver = new JsonPropertyContractResolver(props) -}); -var provider = builder.Services.BuildServiceProvider(); -var bf = provider.GetService(); -bf.Add("Value"); -Console.WriteLine(bf.Contains("Value")); app.Run(); \ No newline at end of file diff --git a/ZR.ServiceCore/Filters/DataFieldFilter.cs b/ZR.ServiceCore/Filters/DataFieldFilter.cs index a7af285..59b7ef3 100644 --- a/ZR.ServiceCore/Filters/DataFieldFilter.cs +++ b/ZR.ServiceCore/Filters/DataFieldFilter.cs @@ -26,7 +26,7 @@ public class DataFieldFilter : ActionFilterAttribute public Type ResultType { get; set; } - public string RulePath { get; set; } + public string Path { get; set; } public override void OnResultExecuting(ResultExecutingContext context) { diff --git a/ZR.ServiceCore/Model/SysBlock.cs b/ZR.ServiceCore/Model/SysBlock.cs new file mode 100644 index 0000000..1e276fd --- /dev/null +++ b/ZR.ServiceCore/Model/SysBlock.cs @@ -0,0 +1,13 @@ +namespace ZR.ServiceCore.Model; +[SugarTable("sys_block")] +[Tenant("0")] +public class SysBlock +{ + [SugarColumn(IsPrimaryKey = true)] + [JsonConverter(typeof(ValueToStringConverter))] + public long Id { get; set; } + + public string Code { get; set; } + + public string Name { get; set; } +} \ No newline at end of file diff --git a/ZR.ServiceCore/Model/SysField.cs b/ZR.ServiceCore/Model/SysField.cs index d0b577e..994a74c 100644 --- a/ZR.ServiceCore/Model/SysField.cs +++ b/ZR.ServiceCore/Model/SysField.cs @@ -13,6 +13,4 @@ public class SysField public string FullName { get; set; } public string FieldType { get; set; } - - public string IsClass { get; set; } } \ No newline at end of file diff --git a/ZR.ServiceCore/Model/SysFieldBlock.cs b/ZR.ServiceCore/Model/SysFieldBlock.cs new file mode 100644 index 0000000..c16723f --- /dev/null +++ b/ZR.ServiceCore/Model/SysFieldBlock.cs @@ -0,0 +1,11 @@ +namespace ZR.ServiceCore.Model; +[SugarTable("sys_field_block")] +[Tenant("0")] +public class SysFieldBlock +{ + [JsonConverter(typeof(ValueToStringConverter))] + public long BlockId { get; set; } + + [JsonConverter(typeof(ValueToStringConverter))] + public long FieldId { get; set; } +} \ No newline at end of file diff --git a/ZR.ServiceCore/Services/IService/ISysBlockService.cs b/ZR.ServiceCore/Services/IService/ISysBlockService.cs new file mode 100644 index 0000000..8dd54f8 --- /dev/null +++ b/ZR.ServiceCore/Services/IService/ISysBlockService.cs @@ -0,0 +1,9 @@ +using ZR.Service; +using ZR.ServiceCore.Model; + +namespace ZR.ServiceCore.Services.IService; + +public interface ISysBlockService : IBaseService +{ + +} \ No newline at end of file diff --git a/ZR.ServiceCore/Services/IService/ISysFieldBlockService.cs b/ZR.ServiceCore/Services/IService/ISysFieldBlockService.cs new file mode 100644 index 0000000..da00787 --- /dev/null +++ b/ZR.ServiceCore/Services/IService/ISysFieldBlockService.cs @@ -0,0 +1,9 @@ +using ZR.Service; +using ZR.ServiceCore.Model; + +namespace ZR.ServiceCore.Services.IService; + +public interface ISysFieldBlockService : IBaseService +{ + +} \ No newline at end of file diff --git a/ZR.ServiceCore/Services/SysBlockService.cs b/ZR.ServiceCore/Services/SysBlockService.cs new file mode 100644 index 0000000..972d781 --- /dev/null +++ b/ZR.ServiceCore/Services/SysBlockService.cs @@ -0,0 +1,12 @@ +using Infrastructure.Attribute; +using ZR.Service; +using ZR.ServiceCore.Model; +using ZR.ServiceCore.Services.IService; + +namespace ZR.ServiceCore.Services; + +[AppService(ServiceType = typeof(ISysBlockService), ServiceLifetime = LifeTime.Transient)] +public class SysBlockService : BaseService, ISysBlockService +{ + +} \ No newline at end of file diff --git a/ZR.ServiceCore/Services/SysFieldBlockService.cs b/ZR.ServiceCore/Services/SysFieldBlockService.cs new file mode 100644 index 0000000..1acb5fa --- /dev/null +++ b/ZR.ServiceCore/Services/SysFieldBlockService.cs @@ -0,0 +1,12 @@ +using Infrastructure.Attribute; +using ZR.Service; +using ZR.ServiceCore.Model; +using ZR.ServiceCore.Services.IService; + +namespace ZR.ServiceCore.Services; + +[AppService(ServiceType = typeof(ISysFieldBlockService), ServiceLifetime = LifeTime.Transient)] +public class SysFieldBlockService : BaseService, ISysFieldBlockService +{ + +} \ No newline at end of file diff --git a/ZR.ServiceCore/Services/SysFieldService.cs b/ZR.ServiceCore/Services/SysFieldService.cs index b8c1e1b..01a4864 100644 --- a/ZR.ServiceCore/Services/SysFieldService.cs +++ b/ZR.ServiceCore/Services/SysFieldService.cs @@ -19,11 +19,13 @@ public class SysFieldService : BaseService, ISysFieldService { var fields = await Queryable() .Where(it => it.FullName == fullName) + .WithCache(10 * 60) .ToListAsync(); var roleFields = await _sysRoleFieldService .Queryable() .Where(it => it.RoleId == roleId) .Select(it => it.FieldId) + .WithCache() .ToListAsync(); var list = fields.Select(it => new SysFieldDto { @@ -31,7 +33,7 @@ public class SysFieldService : BaseService, ISysFieldService FieldType = it.FieldType, FullName = it.FullName, Id = it.Id, - IsClass = it.IsClass, + // IsClass = it.IsClass, IsPermission = !roleFields.Contains(it.Id) }).ToList(); return list; @@ -67,7 +69,7 @@ public class SysFieldService : BaseService, ISysFieldService FieldName = property.FieldName, FullName = serviceCoreModel.FullName, FieldType = property.FieldType, - IsClass = property.IsClass ? "1" : "0" + // IsClass = property.IsClass ? "1" : "0" }).ToList(); await Deleteable() .Where(it =>