From d9305c76203de0951ef742d1435855f4ca223ba3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= <454313500@qq.com>
Date: Wed, 22 Nov 2023 11:10:12 +0800
Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=9E=84=E5=BB=BA=E8=BF=98?=
=?UTF-8?q?=E5=8E=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Yi.Framework.Module/Excel/ExcelManager.cs | 12 --
.../Yi.Framework.Module/Excel/OemClient.cs | 130 ------------------
.../Yi.Framework.Module.csproj | 1 -
Yi.Furion.Net6/Yi.Furion.Web.Core/Startup.cs | 2 +-
4 files changed, 1 insertion(+), 144 deletions(-)
delete mode 100644 Yi.Furion.Net6/Yi.Framework.Module/Excel/ExcelManager.cs
delete mode 100644 Yi.Furion.Net6/Yi.Framework.Module/Excel/OemClient.cs
diff --git a/Yi.Furion.Net6/Yi.Framework.Module/Excel/ExcelManager.cs b/Yi.Furion.Net6/Yi.Framework.Module/Excel/ExcelManager.cs
deleted file mode 100644
index 02b5ea9c..00000000
--- a/Yi.Furion.Net6/Yi.Framework.Module/Excel/ExcelManager.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Yi.Framework.Module.Excel
-{
- public class ExcelManager
- {
- }
-}
diff --git a/Yi.Furion.Net6/Yi.Framework.Module/Excel/OemClient.cs b/Yi.Furion.Net6/Yi.Framework.Module/Excel/OemClient.cs
deleted file mode 100644
index 7778b2b9..00000000
--- a/Yi.Furion.Net6/Yi.Framework.Module/Excel/OemClient.cs
+++ /dev/null
@@ -1,130 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Text.Json;
-using System.Threading.Tasks;
-using NPOI.SS.UserModel;
-using NPOI.XSSF.UserModel;
-using Org.BouncyCastle.Utilities.Collections;
-
-namespace Yi.Framework.Module.Excel
-{
- public class OemClient
- {
- ///
- /// 导出excel
- ///
- ///
- ///
- ///
- public void Export(List entityList, string filePath)
- {
- var properties = typeof(T).GetProperties().Where(x => x.GetCustomAttribute() is not null).Where(x => x.GetGetMethod().IsPublic).ToList();
- // 创建工作簿
- IWorkbook workbook = new XSSFWorkbook();
- // 创建工作表
- ISheet sheet = workbook.CreateSheet("sheet");
-
-
- // 写入表头
- IRow headerRow = sheet.CreateRow(0);
- for (int j = 0; j < properties.Count(); j++)
- {
- headerRow.CreateCell(j).SetCellValue(properties[j].GetCustomAttribute()!.DisplayName);
- }
-
- // 写入数据
- for (int i = 0; i < entityList.Count(); i++)
- {
- var currentEntity = entityList[i];
- IRow dataRow = sheet.CreateRow(i + 1);
- for (int j = 0; j < properties.Count(); j++)
- {
- var currentPropertiy = properties[j];
-
- //只处理简单类型
- dataRow.CreateCell(j).SetCellValue(JsonSerializer.Serialize(currentPropertiy.GetValue(currentEntity)).TrimStart("\"".ToCharArray()).TrimEnd("\"".ToCharArray()));
- }
- }
-
- // 保存文件
- using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
- {
- workbook.Write(fs);
- }
-
- workbook.Dispose();
- }
-
- ///
- /// 导入excel
- ///
- ///
- ///
- ///
- public List Import(string filePath) where T : new()
- {
- List result = new();
-
- Dictionary propHas = new Dictionary();
- var properties = typeof(T).GetProperties().Where(x => x.GetCustomAttribute() is not null).Where(x => x.GetGetMethod().IsPublic).ToList();
-
-
- // 创建文件流
- using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
- {
- // 创建工作簿
- IWorkbook workbook = new XSSFWorkbook(fileStream);
-
- // 选择第一个工作表
- ISheet sheet = workbook.GetSheetAt(0);
-
- //获取表头
- IRow headerRow = sheet.GetRow(0);
-
-
- for (int col = 0; col < headerRow.LastCellNum; col++)
- {
- // 获取单元格的值
- ICell cell = headerRow.GetCell(col);
- var property = properties.Where(x => x.GetCustomAttribute().DisplayName == cell.StringCellValue).FirstOrDefault();
- if (property is not null && !propHas.Values.Contains(property))
- {
- propHas[col] = property;
- }
- }
-
- // 遍历行
- for (int row = 1; row <= sheet.LastRowNum; row++)
- {
- //一行一个对象
-
-
- IRow currentRow = sheet.GetRow(row);
- var currentResult = new T();
- // 遍历列
- for (int col = 0; col < currentRow.LastCellNum; col++)
- {
- // 获取单元格的值
- ICell cell = currentRow.GetCell(col);
- string? cellValue = cell.ToString();
- object value = cellValue.TrimStart("\"".ToCharArray()).TrimEnd("\"".ToCharArray());
-
- value = Convert.ChangeType(cellValue, propHas[col].PropertyType);
-
-
- propHas[col].SetValue(currentResult, value);
-
- }
-
- result.Add(currentResult);
- }
- }
-
- return result;
- }
- }
-}
diff --git a/Yi.Furion.Net6/Yi.Framework.Module/Yi.Framework.Module.csproj b/Yi.Furion.Net6/Yi.Framework.Module/Yi.Framework.Module.csproj
index 6f5f3f76..7c74970e 100644
--- a/Yi.Furion.Net6/Yi.Framework.Module/Yi.Framework.Module.csproj
+++ b/Yi.Furion.Net6/Yi.Framework.Module/Yi.Framework.Module.csproj
@@ -23,7 +23,6 @@
-
diff --git a/Yi.Furion.Net6/Yi.Furion.Web.Core/Startup.cs b/Yi.Furion.Net6/Yi.Furion.Web.Core/Startup.cs
index 0f13abf7..d83edb04 100644
--- a/Yi.Furion.Net6/Yi.Furion.Web.Core/Startup.cs
+++ b/Yi.Furion.Net6/Yi.Furion.Web.Core/Startup.cs
@@ -37,7 +37,7 @@ public class Startup : AppStartup
services.AddSchedule(options =>
{
// 注册作业,并配置作业触发器
- //options.AddJob(Triggers.Period(10000));
+ options.AddJob(Triggers.Period(10000));
//options.AddJob(Triggers.Period(10000));
options.AddJob(Triggers.Cron("0 0 0,12 ? * ?", CronStringFormat.WithSeconds)); // 表示每天凌晨与12点
});