调整字段初始化和获取Model列表,备份sql

This commit is contained in:
YUN-PC5\user 2023-10-16 17:00:45 +08:00
parent 52cd22c4c6
commit 10b57594ac
7 changed files with 1163 additions and 29 deletions

View File

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Protobuf Include="Protos\greet.proto" GrpcServices="Client"/>
<Protobuf Include="Protos\greet.proto" GrpcServices="Both"/>
<Protobuf Include="Protos\block.proto" GrpcServices="Client"/>
</ItemGroup>

View File

@ -1,4 +1,5 @@
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Services.IService;
@ -19,21 +20,8 @@ public class SysFieldController : BaseController
}
[HttpGet("getModelList")]
public IActionResult GetModelList()
{
var serviceCoreModels = AppDomain.CurrentDomain
.GetAssemblies()
.First(it => it.FullName.Contains("ZR.ServiceCore"))
.ExportedTypes
.Where(p => p.FullName.StartsWith("ZR.ServiceCore.Model"))
.Select(it => new
{
it.FullName,
// Properties = it.GetProperties()
})
.ToList();
return SUCCESS(serviceCoreModels);
}
public async Task<IActionResult> GetModelList([FromQuery] PagerInfo pagerInfo)
=> SUCCESS(await _sysFieldService.GetModelList(pagerInfo));
[HttpGet("getFields")]
public async Task<IActionResult> GetFields([FromQuery] string fullName, long roleId)

View File

@ -4,20 +4,14 @@ using Microsoft.AspNetCore.DataProtection;
using NLog.Web;
using System.Text.Json;
using BloomFilter.CSRedis.Configurations;
using Grpc.Net.Client;
using GrpcService1;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Redis;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ZR.Admin.Grpc;
using ZR.Admin.Grpc.Extensions;
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;
@ -203,7 +197,7 @@ using (var serviceScope = app.Services.CreateScope())
{
Name = "gree"
});
Console.WriteLine(helloReply);
// Console.WriteLine(helloReply);
}
app.Run();

View File

@ -0,0 +1,6 @@
namespace ZR.ServiceCore.Model.Dto;
public class SysModelDto
{
public string FullName { get; set; }
}

View File

@ -1,4 +1,5 @@
using ZR.Service;
using ZR.Model;
using ZR.Service;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
@ -6,6 +7,7 @@ namespace ZR.ServiceCore.Services.IService;
public interface ISysFieldService : IBaseService<SysField>
{
Task<PagedInfo<SysModelDto>> GetModelList(PagerInfo pagerInfo);
Task<List<SysFieldDto>> GetFields(string fullName, long roleId);
Task<bool> InitFields();
}

View File

@ -1,4 +1,7 @@
using Infrastructure.Attribute;
using Infrastructure;
using Infrastructure.Attribute;
using ZR.Infrastructure.Cache;
using ZR.Model;
using ZR.Service;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
@ -15,6 +18,20 @@ public class SysFieldService : BaseService<SysField>, ISysFieldService
_sysRoleFieldService = sysRoleFieldService;
}
public async Task<PagedInfo<SysModelDto>> GetModelList(PagerInfo pagerInfo)
{
if (!await RedisServer.Cache.ExistsAsync("ModelList")) throw new CustomException("请先初始化,再配置");
var list = (await RedisServer.Cache.GetAsync<List<SysModelDto>>("ModelList")).ToList();
var skipCount = (pagerInfo.PageNum - 1) * pagerInfo.PageSize;
return new PagedInfo<SysModelDto>
{
PageSize = pagerInfo.PageSize,
PageIndex = pagerInfo.PageNum,
Result = list.Skip(skipCount).Take(pagerInfo.PageSize).ToList(),
TotalNum = list.Count
};
}
public async Task<List<SysFieldDto>> GetFields(string fullName, long roleId)
{
var fields = await Queryable()
@ -43,9 +60,9 @@ public class SysFieldService : BaseService<SysField>, ISysFieldService
{
var serviceCoreModels = AppDomain.CurrentDomain
.GetAssemblies()
.First(it => it.FullName.Contains("ZR.ServiceCore"))
.First(it => it.FullName != null && it.FullName.Contains("ZR.ServiceCore"))
.ExportedTypes
.Where(p => p.FullName.StartsWith("ZR.ServiceCore.Model"))
.Where(p => p.FullName != null && p.FullName.StartsWith("ZR.ServiceCore.Model"))
.Select(it => new
{
it.FullName,
@ -53,13 +70,16 @@ public class SysFieldService : BaseService<SysField>, ISysFieldService
{
FieldName = pt.Name,
FieldType = pt.PropertyType.FullName,
IsClass = pt.PropertyType.IsClass,
IsArray = pt.PropertyType.IsArray,
// IsClass = pt.PropertyType.IsClass,
// IsArray = pt.PropertyType.IsArray,
// IsList = pt.PropertyType.IsClass ? pt.DeclaringType.FullName : string.Empty
}).ToList()
// Properties = it.GetProperties()
})
.ToList();
var modelList = serviceCoreModels.Select(it => new SysModelDto{ FullName = it.FullName }).ToList();
if (!await RedisServer.Cache.SetAsync("ModelList", modelList))
throw new CustomException("插入缓存失败,请联系管理员");
foreach (var serviceCoreModel in serviceCoreModels)
{

File diff suppressed because one or more lines are too long