From c4e13a4135d8eed451d3f2815a91fda154c978d8 Mon Sep 17 00:00:00 2001 From: lzw <605106923@qq.com> Date: Wed, 3 Nov 2021 18:26:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/SettingController.cs | 18 +- .../Yi.Framework.ApiMicroservice/Startup.cs | 5 +- .../appsettings.json | 5 +- .../wwwroot/Excel/Excel_20211102225436.xlsx | Bin 2958 -> 0 bytes .../wwwroot/Excel/Excel_20211102225553.xlsx | Bin 2958 -> 0 bytes .../Yi.Framework.Common/Const/RedisConst.cs | 44 ++-- .../Yi.Framework.DTOModel/SettingDto.cs | 4 + Yi.Framework/Yi.Framework.WebCore/Excel.cs | 228 ------------------ .../Init}/DataSeed.cs | 2 +- .../Yi.Framework.WebCore/Init/RedisInit.cs | 31 +++ .../MiddlewareExtend/DbSeedInitExtend.cs | 2 +- .../MiddlewareExtend/RedisExtension.cs | 2 + .../MiddlewareExtend/RedisInitExtend.cs | 37 +++ .../Yi.Framework.WebCore.csproj | 2 +- 14 files changed, 115 insertions(+), 265 deletions(-) delete mode 100644 Yi.Framework/Yi.Framework.ApiMicroservice/evn/wwwroot/Excel/Excel_20211102225436.xlsx delete mode 100644 Yi.Framework/Yi.Framework.ApiMicroservice/evn/wwwroot/Excel/Excel_20211102225553.xlsx delete mode 100644 Yi.Framework/Yi.Framework.WebCore/Excel.cs rename Yi.Framework/{Yi.Framework.Model/DbInit => Yi.Framework.WebCore/Init}/DataSeed.cs (99%) create mode 100644 Yi.Framework/Yi.Framework.WebCore/Init/RedisInit.cs create mode 100644 Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RedisInitExtend.cs diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/SettingController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/SettingController.cs index f30ecc46..a4a0945f 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/SettingController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/SettingController.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading.Tasks; using Yi.Framework.Common.Const; using Yi.Framework.Common.Models; +using Yi.Framework.Core; using Yi.Framework.DTOModel; using Yi.Framework.Interface; using Yi.Framework.Model.Models; @@ -20,10 +21,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers public class SettingController : ControllerBase { private readonly ILogger _logger; + private readonly CacheClientDB _cacheClientDB; - public SettingController(ILogger logger) + public SettingController(ILogger logger, CacheClientDB cacheClientDB) { _logger = logger; + _cacheClientDB = cacheClientDB; } @@ -33,21 +36,20 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// [HttpGet] - public async Task GetSetting() - { - var p = RedisConst.stringData[RedisConst.ImageList_key]; - return Result.Success(); + public Result GetSetting() + { + return Result.Success().SetData( _cacheClientDB.Get(RedisConst.key)); } /// /// 更 /// - /// + /// /// [HttpPut] - public async Task UpdateSetting() + public Result UpdateSetting(SettingDto settingDto) { - + _cacheClientDB.Set(RedisConst.key, settingDto); return Result.Success(); } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs index 9d31f9d3..2129958d 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Yi.Framework.Core; using Yi.Framework.Model.ModelFactory; using Yi.Framework.WebCore.MiddlewareExtend; using Yi.Framework.WebCore.Utility; @@ -83,7 +84,7 @@ namespace Yi.Framework.ApiMicroservice #endregion // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env,IDbContextFactory _DbFactory) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env,IDbContextFactory _DbFactory, CacheClientDB _cacheClientDB) { //if (env.IsDevelopment()) { @@ -141,7 +142,7 @@ namespace Yi.Framework.ApiMicroservice //ݿע #endregion app.UseDbSeedInitService(_DbFactory); - + app.UseRedisInitService(_cacheClientDB); #region //Endpointsע #endregion diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/appsettings.json b/Yi.Framework/Yi.Framework.ApiMicroservice/appsettings.json index 159ff0ad..8beca74e 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/appsettings.json +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/appsettings.json @@ -15,6 +15,7 @@ "Cors_Enabled": true, "RabbitMQ_Enabled": false, "Redis_Enabled": false, + "RedisSet_Enabled": false, "Kafka_Enabled": false, "MutiDB_Enabled": false, "DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle" ], @@ -40,10 +41,10 @@ "SecurityKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI2a2EJ7m872v0afyoSDJT2o1+SitIeJSWtLJU8/Wz2m7gStexajkeD+Lka6DSTy8gt9UwfgVQo6uKjVLG5Ex7PiGOODVqAEghBuS7JzIYU5RvI543nNDAPfnJsas96mSA7L/mD7RTE2drj6hf3oZjJpMPZUQI/B1Qjb5H3K3PNwIDAQAB" }, "RedisConn": { - "Host": "192.168.2.128", + "Host": "118.195.191.41", "Prot": 6379, "DB": 0, - "Password": "123456" + "Password": "Qz52013142020." }, "KafkaOptions": { "BrokerList": "192.168.3.230:9092", diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/evn/wwwroot/Excel/Excel_20211102225436.xlsx b/Yi.Framework/Yi.Framework.ApiMicroservice/evn/wwwroot/Excel/Excel_20211102225436.xlsx deleted file mode 100644 index 24bc5816916948488327d124875b7d7c31244d1e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2958 zcmZ`*c{r5q9v;~y>sYc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jP*620*_gjy5`dn#fAt@gUdmBWX`HR zg*|`^QRS1Q!I+zKn<}>8r4giT{P@1ncc>OJ0z3y7bCHOusA_dR3_qx~N*0I7oPLL} zeLl-uRgIJH)1L1k4=k7T>)V>#oA(L#_1B@Gen^}e_kdpmW?-g=Z`lE?w(KdH{=%Cp ziIp#1%EESO)0n5`rpVOBpQ(+=f3GDU3JgCRdF$W32+Y;+VVFd$2 z;3rRR`EvlSih=g>)_Wc5JS5V212&=jyu4f!8KRNhLBbKM7T_NFOzNAJm9B=`HB7K0 zUqeJVtsyBPTJCjA|HUhVDL+=H0=-%!lKjlTOSx0(`mc*n1d~HW+J}PRefzixS9#DA zZv*HPuQCMCNS&zDm&Ejy-C4T8Fp0Qtk#}g`=*>}cih|?o;QMMJ$2KB|46Qg&x`tj< zL)iz)xLRd@OWwXXWe1=F)(Yb?5cvAic3N&t4!a zsq_YwZE~dvpBnqAcjNr2A4mJe5O5aO!%SX(KesV6X2<%?6t}y;&e>!;`sWebHmU3e z?o9gaKoh3+yK;XwcxNJR2ir3TP$u{f`MA5z&fM5u=Q{iUHt~Ncvb)O83uSwiQf3}8 nck|EnvKzY7@7tj!z+cea?nl5mm_-2qF6Pt5q_}3!&%b{I#x<{M diff --git a/Yi.Framework/Yi.Framework.Common/Const/RedisConst.cs b/Yi.Framework/Yi.Framework.Common/Const/RedisConst.cs index 3a22a248..6b99c95e 100644 --- a/Yi.Framework/Yi.Framework.Common/Const/RedisConst.cs +++ b/Yi.Framework/Yi.Framework.Common/Const/RedisConst.cs @@ -11,32 +11,32 @@ namespace Yi.Framework.Common.Const /// /// 前缀 /// - private const string prefix = "Yi:"; + public const string key = "YiFramework:data"; - /// - /// 初始化角色名 - /// - public const string InitRole_key = nameof(InitRole_key); + ///// + ///// 初始化角色名 + ///// + //public const string InitRole_key = nameof(InitRole_key); - /// - /// 标题名 - /// - public const string Title_key = nameof(Title_key); + ///// + ///// 标题名 + ///// + //public const string Title_key = nameof(Title_key); - /// - /// 图片列表名 - /// - public const string ImageList_key = nameof(ImageList_key); + ///// + ///// 图片列表名 + ///// + //public const string ImageList_key = nameof(ImageList_key); - public static Dictionary stringData = new Dictionary() - { - {prefix+nameof(InitRole_key), "普通用户"}, - {prefix+nameof(Title_key), "YiFramework"}, - }; + //public static Dictionary stringData = new Dictionary() + //{ + // {prefix+nameof(InitRole_key), "普通用户"}, + // {prefix+nameof(Title_key), "YiFramework"}, + //}; - public static Dictionary> listData = new Dictionary>() - { - {prefix+nameof(ImageList_key), new List(){"图片地址1", "图片地址2", "图片地址3", "图片地址4" } } - }; + //public static Dictionary> listData = new Dictionary>() + //{ + // {prefix+nameof(ImageList_key), new List(){"图片地址1", "图片地址2", "图片地址3", "图片地址4" } } + //}; } } diff --git a/Yi.Framework/Yi.Framework.DTOModel/SettingDto.cs b/Yi.Framework/Yi.Framework.DTOModel/SettingDto.cs index a327a37e..0b8df4b4 100644 --- a/Yi.Framework/Yi.Framework.DTOModel/SettingDto.cs +++ b/Yi.Framework/Yi.Framework.DTOModel/SettingDto.cs @@ -8,5 +8,9 @@ namespace Yi.Framework.DTOModel { public class SettingDto { + public string InitIcon_key { get; set; } + public string InitRole_key { get; set; } + public string Title_key { get; set; } + public List ImageList_key { get; set; } } } diff --git a/Yi.Framework/Yi.Framework.WebCore/Excel.cs b/Yi.Framework/Yi.Framework.WebCore/Excel.cs deleted file mode 100644 index a7961b87..00000000 --- a/Yi.Framework/Yi.Framework.WebCore/Excel.cs +++ /dev/null @@ -1,228 +0,0 @@ -using NPOI.SS.UserModel; -using NPOI.XSSF.UserModel; -using System; -using System.Collections.Generic; -using System.Data; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace Yi.Framework.WebCore -{ - public class Excel - { - /// - /// 读取Excel多Sheet数据 - /// - /// 文件路径 - /// Sheet名 - /// - public static DataSet ReadExcelToDataSet(string filePath, string sheetName = null) - { - if (!File.Exists(filePath)) - { - //LogUtil.Debug($"未找到文件{filePath}"); - return null; - } - //获取文件信息 - FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); - IWorkbook workbook = WorkbookFactory.Create(fs); - //获取sheet信息 - ISheet sheet = null; - DataSet ds = new DataSet(); - if (!string.IsNullOrEmpty(sheetName)) - { - sheet = workbook.GetSheet(sheetName); - if (sheet == null) - { - //LogUtil.Debug($"{filePath}未找到sheet:{sheetName}"); - return null; - } - DataTable dt = ReadExcelFunc(workbook, sheet); - ds.Tables.Add(dt); - } - else - { - //遍历获取所有数据 - int sheetCount = workbook.NumberOfSheets; - for (int i = 0; i < sheetCount; i++) - { - sheet = workbook.GetSheetAt(i); - if (sheet != null) - { - DataTable dt = ReadExcelFunc(workbook, sheet); - ds.Tables.Add(dt); - } - } - } - return ds; - } - - /// - /// 读取Excel信息 - /// - /// 工作区 - /// sheet - /// - private static DataTable ReadExcelFunc(IWorkbook workbook, ISheet sheet) - { - DataTable dt = new DataTable(); - //获取列信息 - IRow cells = sheet.GetRow(sheet.FirstRowNum); - int cellsCount = cells.PhysicalNumberOfCells; - int emptyCount = 0; - int cellIndex = sheet.FirstRowNum; - List listColumns = new List(); - bool isFindColumn = false; - while (!isFindColumn) - { - emptyCount = 0; - listColumns.Clear(); - for (int i = 0; i < cellsCount; i++) - { - if (string.IsNullOrEmpty(cells.GetCell(i).StringCellValue)) - { - emptyCount++; - } - listColumns.Add(cells.GetCell(i).StringCellValue); - } - //这里根据逻辑需要,空列超过多少判断 - if (emptyCount == 0) - { - isFindColumn = true; - } - cellIndex++; - cells = sheet.GetRow(cellIndex); - } - - foreach (string columnName in listColumns) - { - if (dt.Columns.Contains(columnName)) - { - //如果允许有重复列名,自己做处理 - continue; - } - dt.Columns.Add(columnName, typeof(string)); - } - //开始获取数据 - int rowsCount = sheet.PhysicalNumberOfRows; - cellIndex += 1; - DataRow dr = null; - for (int i = cellIndex; i < rowsCount; i++) - { - cells = sheet.GetRow(i); - dr = dt.NewRow(); - for (int j = 0; j < dt.Columns.Count; j++) - { - //这里可以判断数据类型 - switch (cells.GetCell(j).CellType) - { - case CellType.String: - dr[j] = cells.GetCell(j).StringCellValue; - break; - case CellType.Numeric: - dr[j] = cells.GetCell(j).NumericCellValue.ToString(); - break; - case CellType.Unknown: - dr[j] = cells.GetCell(j).StringCellValue; - break; - } - } - dt.Rows.Add(dr); - } - return dt; - } - - /// - /// 导出Excel文件 - /// - /// 数据类型 - /// 数据实体 - /// 列对应关系,如Name->姓名 - /// 标题 - /// - public static byte[] ExportExcel(List entities, Dictionary dicColumns, string title = null) - { - if (entities.Count <= 0) - { - return null; - } - //HSSFWorkbook => xls - //XSSFWorkbook => xlsx - IWorkbook workbook = new XSSFWorkbook(); - ISheet sheet = workbook.CreateSheet("test");//名称自定义 - IRow cellsColumn = null; - IRow cellsData = null; - //获取实体属性名 - PropertyInfo[] properties = entities[0].GetType().GetProperties(); - int cellsIndex = 0; - //标题 - if (!string.IsNullOrEmpty(title)) - { - ICellStyle style = workbook.CreateCellStyle(); - //边框 - style.BorderBottom = BorderStyle.Dotted; - style.BorderLeft = BorderStyle.Hair; - style.BorderRight = BorderStyle.Hair; - style.BorderTop = BorderStyle.Dotted; - //水平对齐 - style.Alignment = HorizontalAlignment.Left; - - //垂直对齐 - style.VerticalAlignment = VerticalAlignment.Center; - - //设置字体 - IFont font = workbook.CreateFont(); - font.FontHeightInPoints = 10; - font.FontName = "微软雅黑"; - style.SetFont(font); - - IRow cellsTitle = sheet.CreateRow(0); - cellsTitle.CreateCell(0).SetCellValue(title); - cellsTitle.RowStyle = style; - //合并单元格 - sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 1, 0, dicColumns.Count - 1)); - cellsIndex = 2; - } - //列名 - cellsColumn = sheet.CreateRow(cellsIndex); - int index = 0; - Dictionary columns = new Dictionary(); - foreach (var item in dicColumns) - { - cellsColumn.CreateCell(index).SetCellValue(item.Value); - columns.Add(item.Value, index); - index++; - } - cellsIndex += 1; - //数据 - foreach (var item in entities) - { - cellsData = sheet.CreateRow(cellsIndex); - for (int i = 0; i < properties.Length; i++) - { - if (!dicColumns.ContainsKey(properties[i].Name)) continue; - //这里可以也根据数据类型做不同的赋值,也可以根据不同的格式参考上面的ICellStyle设置不同的样式 - object[] entityValues = new object[properties.Length]; - entityValues[i] = properties[i].GetValue(item); - //获取对应列下标 - index = columns[dicColumns[properties[i].Name]]; - cellsData.CreateCell(index).SetCellValue(entityValues[i].ToString()); - } - cellsIndex++; - } - - byte[] buffer = null; - using (MemoryStream ms = new MemoryStream()) - { - workbook.Write(ms); - buffer = ms.GetBuffer(); - ms.Close(); - } - - return buffer; - } - } -} diff --git a/Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs b/Yi.Framework/Yi.Framework.WebCore/Init/DataSeed.cs similarity index 99% rename from Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs rename to Yi.Framework/Yi.Framework.WebCore/Init/DataSeed.cs index 76f79513..4cd8ea76 100644 --- a/Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs +++ b/Yi.Framework/Yi.Framework.WebCore/Init/DataSeed.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Yi.Framework.Model.ModelFactory; using Yi.Framework.Model.Models; -namespace Yi.Framework.Model.DbInit +namespace Yi.Framework.WebCore.Init { public class DataSeed { diff --git a/Yi.Framework/Yi.Framework.WebCore/Init/RedisInit.cs b/Yi.Framework/Yi.Framework.WebCore/Init/RedisInit.cs new file mode 100644 index 00000000..25888d21 --- /dev/null +++ b/Yi.Framework/Yi.Framework.WebCore/Init/RedisInit.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Common.Const; +using Yi.Framework.Core; +using Yi.Framework.DTOModel; + +namespace Yi.Framework.WebCore.Init +{ + public class RedisInit + { + public static void Seed(CacheClientDB _cacheClientDB) + { + + if (_cacheClientDB.Get(RedisConst.key)==null) + { + _cacheClientDB.Add(RedisConst.key, new SettingDto() + { + ImageList_key = { "默认图片", "默认图片" } , + InitRole_key= "默认角色", + Title_key= "默认标题", + InitIcon_key= "默认头像" + }) ; + } + + Console.WriteLine(nameof(RedisInit) + ":Redis初始成功!"); + } + } +} diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/DbSeedInitExtend.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/DbSeedInitExtend.cs index 8d8d2d82..d43e2913 100644 --- a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/DbSeedInitExtend.cs +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/DbSeedInitExtend.cs @@ -6,8 +6,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Yi.Framework.Model.DbInit; using Yi.Framework.Model.ModelFactory; +using Yi.Framework.WebCore.Init; namespace Yi.Framework.WebCore.MiddlewareExtend { diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RedisExtension.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RedisExtension.cs index 6a9826ce..f17beb8a 100644 --- a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RedisExtension.cs +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RedisExtension.cs @@ -4,6 +4,7 @@ using Microsoft.OpenApi.Models; using System; using System.IO; using Yi.Framework.Common.IOCOptions; +using Yi.Framework.Core; namespace Yi.Framework.WebCore.MiddlewareExtend { @@ -17,6 +18,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend if (Appsettings.appBool("Redis_Enabled")) { services.Configure(Appsettings.appConfiguration("RedisConn")); + services.AddTransient(); } return services; } diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RedisInitExtend.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RedisInitExtend.cs new file mode 100644 index 00000000..8f813afd --- /dev/null +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/RedisInitExtend.cs @@ -0,0 +1,37 @@ +using log4net; +using Microsoft.AspNetCore.Builder; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Core; +using Yi.Framework.Model.ModelFactory; +using Yi.Framework.WebCore.Init; + +namespace Yi.Framework.WebCore.MiddlewareExtend +{ + public static class RedisInitExtend + { + private static readonly ILog log = LogManager.GetLogger(typeof(RedisInitExtend)); + public static void UseRedisInitService(this IApplicationBuilder app, CacheClientDB _cacheClientDB) + { + + if (Appsettings.appBool("RedisSet_Enabled")) + { + if (app == null) throw new ArgumentNullException(nameof(app)); + + try + { + RedisInit.Seed(_cacheClientDB); + } + catch (Exception e) + { + log.Error($"Error occured seeding the RedisInit.\n{e.Message}"); + throw; + } + } + } + } +} diff --git a/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj b/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj index 6af582f3..4e946f1b 100644 --- a/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj +++ b/Yi.Framework/Yi.Framework.WebCore/Yi.Framework.WebCore.csproj @@ -15,13 +15,13 @@ - +