添加excel模块

This commit is contained in:
橙子
2023-01-16 23:05:01 +08:00
parent 46b176fc59
commit 034abb06ad
159 changed files with 328 additions and 97 deletions

View File

@@ -0,0 +1,7 @@
namespace Yi.Framework.BackgroundJobs.Quartz
{
public class Class1
{
}
}

View File

@@ -0,0 +1,12 @@
{
"profiles": {
"Yi.Framework.BackgroundJobs.Quartz": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:53041;http://localhost:53042"
}
}
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,41 @@
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Caching.MemoryCache
{
public class MemoryCacheClient : CacheManager
{
private IMemoryCache _client;
public MemoryCacheClient()
{
_client = new Microsoft.Extensions.Caching.Memory.MemoryCache(new MemoryCacheOptions());
}
public override bool Exits(string key)
{
return _client.TryGetValue(key, out var _);
}
public override T Get<T>(string key)
{
return _client.Get<T>(key);
}
public override bool Set<T>(string key, T item)
{
return _client.Set(key, item) is not null;
}
public override bool Set<T>(string key, T item, TimeSpan time)
{
return _client.Set(key, item, time) is not null;
}
public override long Del(string key)
{
_client.Remove(key);
return 1;
}
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\Yi.Framework.Core\Yi.Framework.Core.csproj" />
<ProjectReference Include="..\Yi.Framework.Caching\Yi.Framework.Caching.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Caching.MemoryCache;
using Yi.Framework.Caching;
namespace Yi.Framework.Ddd
{
public class YiFrameworkCachingMemoryCacheModule:IStartupModule
{
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
{
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
services.AddSingleton<CacheManager, MemoryCacheClient>();
}
}
}

View File

@@ -0,0 +1,165 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Caching;
using Microsoft.Extensions.Options;
using Yi.Framework.Caching.Redis;
using static CSRedis.CSRedisClient;
using CSRedis;
namespace Yi.Framework.Caching.Redis
{
public class RedisCacheClient : CacheManager
{
private readonly CachingConnOptions _RedisOptions;
private CSRedisClient _client;
public RedisCacheClient(IOptionsMonitor<CachingConnOptions> redisConnOptions)
{
this._RedisOptions = redisConnOptions.CurrentValue;
_client = new CSRedisClient($"{_RedisOptions.Host}:{_RedisOptions.Prot},password={_RedisOptions.Password},defaultDatabase ={_RedisOptions.DB}");
}
public override bool Exits(string key)
{
return _client.Exists(key);
}
public override T Get<T>(string key)
{
return _client.Get<T>(key);
}
public override bool Set<T>(string key, T data, TimeSpan time)
{
return _client.Set(key, data, time);
}
public override bool Set<T>(string key, T data)
{
return _client.Set(key, data);
}
public override long Del(string key)
{
return _client.Del(key);
}
public override bool HSet(string key, string fieId, object data)
{
return _client.HSet(key, fieId, data);
}
public override bool HSet(string key, string fieId, object data, TimeSpan time)
{
var res = _client.HSet(key, fieId, data);
var res2 = _client.Expire(key, time);
return res && res2;
}
public override T HGet<T>(string key, string field)
{
return _client.HGet<T>(key, field);
}
public override long HDel(string key, params string[] par)
{
return _client.HDel(key, par);
}
public override long HLen(string key)
{
return _client.HLen(key);
}
public override Dictionary<string, string> HGetAll(string key)
{
return _client.HGetAll(key);
}
/// <summary>
/// 简单发布
/// </summary>
/// <param name="channel"></param>
/// <param name="message"></param>
/// <returns></returns>
public override long Publish(string channel, string message)
{
return _client.Publish(channel, message);
}
/// <summary>
/// 简单订阅广播无持久化需要Publish写入队列
/// </summary>
/// <param name="channels"></param>
/// <returns></returns>
public SubscribeObject Subscribe(params (string, Action<SubscribeMessageEventArgs>)[] channels)
{
return _client.Subscribe(channels);
}
/// <summary>
/// 多端争抢模式订阅需要Lpush写入队列
/// </summary>
/// <param name="listKey"></param>
/// <param name="onMessage"></param>
/// <returns></returns>
public SubscribeListObject SubscribeList(string listKey, Action<string> onMessage)
{
return _client.SubscribeList(listKey, onMessage);
}
/// <summary>
/// 多端非争抢模式订阅需要Lpush写入队列
/// </summary>
/// <param name="listKey"></param>
/// <param name="clientId"></param>
/// <param name="onMessage"></param>
/// <returns></returns>
public SubscribeListBroadcastObject SubscribeListBroadcast(string listKey, string clientId, Action<string> onMessage)
{
return _client.SubscribeListBroadcast(listKey, clientId, onMessage);
}
public override bool LSet(string key, long index, object value)
{
return _client.LSet(key, index, value);
}
/// <summary>
/// 列表插入头部
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public override long LPush<T>(string key, params T[] value)
{
return _client.LPush<T>(key, value);
}
/// <summary>
/// 列表弹出头部
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public override T LPop<T>(string key)
{
return _client.LPop<T>(key);
}
public override string[] Keys(string pattern)
{
return _client.Keys(pattern);
}
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSRedisCore" Version="3.8.670" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\Yi.Framework.Core\Yi.Framework.Core.csproj" />
<ProjectReference Include="..\Yi.Framework.Caching\Yi.Framework.Caching.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
using Yi.Framework.Core.Configuration;
namespace Yi.Framework.Caching.Redis
{
public class YiFrameworkCachingRedisModule : IStartupModule
{
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
{
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
services.Configure<CachingConnOptions>(Appsettings.appConfiguration("CachingConnOptions"));
services.AddSingleton<CacheManager, RedisCacheClient>();
}
}
}

View File

@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Caching
{
public abstract class CacheManager
{
public virtual bool Exits(string key)
{
throw new NotImplementedException();
}
public virtual T Get<T>(string key)
{
throw new NotImplementedException();
}
public virtual bool Set<T>(string key, T data, TimeSpan time)
{
throw new NotImplementedException();
}
public virtual bool Set<T>(string key, T data)
{
throw new NotImplementedException();
}
public virtual long Del(string key)
{
throw new NotImplementedException();
}
public virtual bool HSet(string key, string fieId, object data)
{
throw new NotImplementedException();
}
public virtual bool HSet(string key, string fieId, object data, TimeSpan time)
{
throw new NotImplementedException();
}
public virtual T HGet<T>(string key, string field)
{
throw new NotImplementedException();
}
public virtual long HDel(string key, params string[] par)
{
throw new NotImplementedException();
}
public virtual long HLen(string key)
{
throw new NotImplementedException();
}
public virtual Dictionary<string, string> HGetAll(string key)
{
throw new NotImplementedException();
}
/// <summary>
/// 简单发布
/// </summary>
/// <param name="channel"></param>
/// <param name="message"></param>
/// <returns></returns>
public virtual long Publish(string channel, string message)
{
throw new NotImplementedException();
}
public virtual bool LSet(string key, long index, object value)
{
throw new NotImplementedException();
}
/// <summary>
/// 列表插入头部
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public virtual long LPush<T>(string key, params T[] value)
{
throw new NotImplementedException();
}
/// <summary>
/// 列表弹出头部
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public virtual T LPop<T>(string key)
{
throw new NotImplementedException();
}
public virtual string[] Keys(string pattern)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Caching
{
public class CachingConnOptions
{
public string? Host { get; set; }
public int DB { get; set; } = 0;
public int Prot { get; set; }
public string? Password { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,47 @@
using OEM.Core;
namespace Yi.Framework.Office.Excel
{
public class ExcelManager
{
private IExcelFactory _excelFactory;
public ExcelManager(IExcelFactory excelFactory)
{
_excelFactory = excelFactory;
}
public List<T> ReadListByNameManager<T>(string path, string sheet) where T : class, new()
{
using (var excelAppService = _excelFactory.Create(System.IO.File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
return excelAppService.ReadListByNameManager<T>(sheet);
}
}
public T ReadByNameManager<T>(string path, string sheet) where T : class, new()
{
using (var excelAppService = _excelFactory.Create(System.IO.File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
return excelAppService.ReadByNameManager<T>(sheet);
}
}
public void WriteListByNameManager<T>(List<T> objcts, string sheet, string oldPath, string newPath) where T : class, new()
{
using (var excelAppService = _excelFactory.Create(System.IO.File.Open(oldPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
excelAppService.WriteListByNameManager(objcts, sheet);
excelAppService.Write(newPath);
}
}
public void WriteByNameManager<T>(T objct, string sheet, string oldPath, string newPath) where T : class, new()
{
using (var excelAppService = _excelFactory.Create(System.IO.File.Open(oldPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
excelAppService.WriteByNameManager(objct, sheet);
excelAppService.Write(newPath);
}
}
}
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ExcelToObject.Npoi" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\Yi.Framework.Core\Yi.Framework.Core.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Office.Excel
{
public class YiFrameworkOfficeExcelModule : IStartupModule
{
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
{
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
services.AddExcelToObjectNpoiService();
}
}
}