增加minio连接地址及名称密码、桶名读取方式写道config文件内

master
孙亮 12 months ago
parent 8a7a3758eb
commit b4e65f0b17

@ -34,6 +34,8 @@ using System.Net.Http.Headers;
using NPOI.SS.Formula.Functions;
using System.Xml.Linq;
using NPOI.HPSF;
using System.Configuration;
using NPOI.SS.Formula.Atp;
namespace IBKLinker_Minio.Common
{
@ -45,18 +47,19 @@ namespace IBKLinker_Minio.Common
public class MinioBusinessLogic
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
#region 异步处理取minio文件流数据方法
/// <summary>
/// 异步处理取minio文件流数据方法
/// </summary>
public async Task<string> Download(string bucketName, string path)
public async Task<string> Download(string BuckeName, string path)
{
MemoryStream memoryStream = new MemoryStream();
try
{
var minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//验证连接minio数据库
bucketName = "dayetegang";//桶名
await minio.GetObjectAsync(bucketName, path, (stream) =>
var minio = ConnectMinIO();//调用连接minio数据库方法
BuckeName = GetBuckName();//调用取桶名称方法
await minio.GetObjectAsync(BuckeName, path, (stream) =>
{
stream.CopyTo(memoryStream);//将文件去除复制到memoryStream
});
@ -70,6 +73,9 @@ namespace IBKLinker_Minio.Common
throw;
}
}
#endregion
#region 文件上传操作日志记录
/// <summary>
/// 文件上传操作日志记录
/// </summary>
@ -87,6 +93,9 @@ namespace IBKLinker_Minio.Common
MOdata.CreationTime = time;//创建时间
db.Insert<MinioOperationlog>(MOdata);//写入数据库
}
#endregion
#region 文件夹递归查询
/// <summary>
/// 文件夹递归查询
/// </summary>
@ -120,5 +129,95 @@ namespace IBKLinker_Minio.Common
}
return subDirs;
}
#endregion
#region 连接minio数据库公用方法
/// <summary>
/// 连接minio数据库公用方法
/// </summary>
public MinioClient ConnectMinIO()
{
string MinIOIp = ConfigurationManager.AppSettings["MinIOIp"];//minio数据库连接地址
string MinIOName = ConfigurationManager.AppSettings["MinIOName"];//minio数据库连接用户名
string MinIoPass = ConfigurationManager.AppSettings["MinIoPass"];//minio数据库连接密码
MinioClient minio = new MinioClient(MinIOIp, MinIOName, MinIoPass);//连接所需minio所在地址、登录名、密码
return minio;
}
#endregion
#region 取minio数据库中桶名称
/// <summary>
/// 取minio数据库中桶名称
/// </summary>
public string GetBuckName()
{
string BuckName = ConfigurationManager.AppSettings["BuckName"];//minio数据库连接地址
return BuckName;
}
#endregion
#region 公用方法
/// <summary>
/// 矫正pk值
/// </summary>
/// <param name="sequenceName"></param>
/// <param name="tableName"></param>
/// <returns></returns>
public Int32 getPk(String sequenceName, String tableName)
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长序列最大pk值
int pk_SequenceCurrentMax = Convert.ToInt32(db.QueryScalar("select " + sequenceName + ".nextval from dual"));
///拿到表目前最大pk值
Object pk_TableCurrentMaxObj = db.QueryScalar("select t.pk from " + tableName + " t where rownum <=1 order by t.pk desc");
int pk_TableCurrentMax = pk_SequenceCurrentMax;
//如果表最大值查询结果不为空进行对比,
if (pk_TableCurrentMaxObj != null)
{
pk_TableCurrentMax = Convert.ToInt32(pk_TableCurrentMaxObj);
//拿到表中最大值和序列最大值之间的差值
int num_BetweenTableSequence = pk_TableCurrentMax - pk_SequenceCurrentMax + 1;
//更改序列递增规则使下一次拿到的序列号比表中最大pk大1
db.QueryScalar("alter sequence " + sequenceName + " increment by " + num_BetweenTableSequence.ToString());
//执行nexval拿到下一个序列号
pk_TableCurrentMax = Convert.ToInt32(db.QueryScalar("select " + sequenceName + ".nextval from dual"));
//更改序列递增规则为每次递增一个。
db.QueryScalar("alter sequence " + sequenceName + " increment by 1");
}
return pk_TableCurrentMax;
}
}
/// <summary>
/// 编写内容:下载文件转换流数据方法
/// </summary>
public string Base64(string FilePath)
{
string data = "";
try
{
using (MemoryStream msReader = new MemoryStream())
{
using (FileStream fs = new FileStream(FilePath, FileMode.Open))
{
byte[] buffer = new byte[1024];
int readLen = 0;
while ((readLen = fs.Read(buffer, 0, buffer.Length)) > 0)
{
msReader.Write(buffer, 0, readLen);
}
}
data = Convert.ToBase64String(msReader.ToArray());//转换base64
}
return data;//返回值
}
catch (Exception ex)
{
logger.InfoFormat(ex.ToString());
throw;
}
}
#endregion
}
}

@ -38,6 +38,7 @@ using IBKLinker_Minio.Common;
using NPOI.POIFS.Crypt.Dsig;
using NPOI.SS.Formula.Atp;
using Org.BouncyCastle.Asn1.Pkcs;
using System.Windows.Forms;
namespace IBKLinker_Minio.Controller.MinioController
{
@ -64,13 +65,14 @@ namespace IBKLinker_Minio.Controller.MinioController
public RequestEntity AddAuthority(MinioAuthority minioAuthority)
{
RequestEntity request = new RequestEntity();
MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长的值赋值给自增长主键pk
minioAuthority.Id = getPk("S_MINIO_AUTHORITY", "MINIO_AUTHORITY");
minioAuthority.Id = bb.getPk("S_MINIO_AUTHORITY", "MINIO_AUTHORITY");
///给创建时间赋值
minioAuthority.CreatorTime = DateTime.Now;
@ -575,6 +577,7 @@ namespace IBKLinker_Minio.Controller.MinioController
[HttpPost, Route("AddRolePermission")]
public RequestEntity AddRolePermission(RolePermissionModel minioRolePermission)
{
MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
RequestEntity request = new RequestEntity();
try
{
@ -595,7 +598,7 @@ namespace IBKLinker_Minio.Controller.MinioController
{
db.BeginTransaction();
///拿到表自增长的值赋值给自增长主键pk
minioRolePermission.minioRolePermission.Pk = getPk("S_MINIO_ROLE_PERMISSION", "MINIO_ROLE_PERMISSION");
minioRolePermission.minioRolePermission.Pk = bb.getPk("S_MINIO_ROLE_PERMISSION", "MINIO_ROLE_PERMISSION");
///给创建时间赋值
minioRolePermission.minioRolePermission.CreatorTime = DateTime.Now;
@ -767,13 +770,18 @@ namespace IBKLinker_Minio.Controller.MinioController
public RequestEntity AddStoragePath(List<MinioStoragePath> minioStoragePath)
{
RequestEntity request = new RequestEntity();
MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
try
{
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//连接所需minio所在地址、登录名、密码
string buckname = "dayetegang";//桶名称
MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
MinioClient minio = bb.ConnectMinIO();//调用连接minio数据库方法
string BuckName = bb.GetBuckName();//调用取桶名称方法
var bucket = minio.BucketExistsAsync(BuckName);//判断桶是否存在
if (bucket.Result == false) //不存在就创建
{
minio.MakeBucketAsync(BuckName);//创建桶
}
string Operate = "";//操作
List<MinioStoragePath> date = new List<MinioStoragePath>();
List<MinioStoragePath> checkdatelist = new List<MinioStoragePath>();
@ -848,7 +856,7 @@ namespace IBKLinker_Minio.Controller.MinioController
var contentType = item.FileCategory;
string strBase64 = item.Bate64;//取文件base64流数据
byte[] bt = Convert.FromBase64String(strBase64);//获取html base64
var uploadTask = minio.PutObjectAsync(buckname, "/" + item.FileName, new MemoryStream(bt), bt.Length, contentType);//上传文件到minio数据库
var uploadTask = minio.PutObjectAsync(BuckName, "/" + item.FileName, new MemoryStream(bt), bt.Length, contentType);//上传文件到minio数据库
uploadTask.Wait();
if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted)//判断是否上传成功
{
@ -903,10 +911,16 @@ namespace IBKLinker_Minio.Controller.MinioController
public RequestEntity UpdateStoragePath(List<MinioStoragePath> data)
{
RequestEntity request = new RequestEntity();
MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
try
{
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//连接所需minio所在地址、登录名、密码
string buckname = "dayetegang";//桶名称
MinioClient minio = bb.ConnectMinIO();//调用连接minio数据库方法
string BuckName = bb.GetBuckName();//调用取桶名称方法
var bucket = minio.BucketExistsAsync(BuckName);//判断桶是否存在
if (bucket.Result == false) //不存在就创建
{
minio.MakeBucketAsync(BuckName);//创建桶
}
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
@ -918,7 +932,6 @@ namespace IBKLinker_Minio.Controller.MinioController
DateTime time = DateTime.Now;//取当前时间
MinioStoragePath date = new MinioStoragePath();
List<MinioStoragePath> datelist = new List<MinioStoragePath>();
MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
string Operate = "";//操作
if (data.Count > 0)
{
@ -942,7 +955,7 @@ namespace IBKLinker_Minio.Controller.MinioController
var contentType = item.FileCategory;
string strBase64 = item.Bate64;//取文件base64流数据
byte[] bt = Convert.FromBase64String(strBase64);//获取html base64
var uploadTask = minio.PutObjectAsync(buckname, "/" + item.FileName, new MemoryStream(bt), bt.Length, contentType);//上传文件到minio数据库
var uploadTask = minio.PutObjectAsync(BuckName, "/" + item.FileName, new MemoryStream(bt), bt.Length, contentType);//上传文件到minio数据库
uploadTask.Wait();
if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted)//判断是否上传成功
{
@ -997,14 +1010,14 @@ namespace IBKLinker_Minio.Controller.MinioController
public RequestEntity RemoveStoragePath(List<MinioStoragePath> master)
{
RequestEntity request = new RequestEntity();
MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
try
{
DateTime time = DateTime.Now;//取当前时间
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");
string buckname = "dayetegang";//桶名称
MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
MinioClient minio = bb.ConnectMinIO();//调用连接minio数据库方法
string BuckName = bb.GetBuckName();//调用取桶名称方法
string Operate = "";//操作
string FilePk = "";//文件pk
string fileUPk = "";//文件父级pk
@ -1015,7 +1028,7 @@ namespace IBKLinker_Minio.Controller.MinioController
{
if (item.FileType == 1) //如果类型是文件
{
var DelTask = minio.RemoveObjectAsync(buckname, item.FileName);//minio操作删除文件
var DelTask = minio.RemoveObjectAsync(BuckName, item.FileName);//minio操作删除文件
DelTask.Wait();
if (DelTask.Status == TaskStatus.RanToCompletion && !DelTask.IsFaulted)//判断是否删除成功
{
@ -1275,10 +1288,9 @@ namespace IBKLinker_Minio.Controller.MinioController
{
foreach (var item in minioStoragePath)
{
MinioStoragePath date = new MinioStoragePath();//定义单条返回数据
var minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//链接minio数据库
string bucketName = "dayetegang";
var uploadTask = bb.Download(bucketName, item.FileName);//异步取base64
MinioStoragePath date = new MinioStoragePath();//定义单条返回数据
string BuckName = bb.GetBuckName();//调用取桶名称方法
var uploadTask = bb.Download(BuckName, item.FileName);//异步取base64
uploadTask.Wait();//等待取值
if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted) //判读是否有数值
{
@ -1364,7 +1376,7 @@ namespace IBKLinker_Minio.Controller.MinioController
if (master.InventoryName != null && master.InventoryType != null)
{
string ExcelName = "";//定义导出Excel文件名称
FileStream file = new FileStream("D:/linshi/" + "清单模板.xlsx", FileMode.Open, FileAccess.Read);
FileStream file = new FileStream(Application.StartupPath + "\\Files\\" + "清单模板.xlsx", FileMode.Open, FileAccess.Read);
XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
string sql = "select * from MINIO_STORAGE_PATH where 1=1 and FILE_TYPE='1' ";
if (master.InventoryType == "0")//标准类型
@ -1513,71 +1525,5 @@ namespace IBKLinker_Minio.Controller.MinioController
return result;
}
#endregion
#region 公用方法
/// <summary>
/// 矫正pk值
/// </summary>
/// <param name="sequenceName"></param>
/// <param name="tableName"></param>
/// <returns></returns>
public Int32 getPk(String sequenceName, String tableName)
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长序列最大pk值
int pk_SequenceCurrentMax = Convert.ToInt32(db.QueryScalar("select " + sequenceName + ".nextval from dual"));
///拿到表目前最大pk值
Object pk_TableCurrentMaxObj = db.QueryScalar("select t.pk from " + tableName + " t where rownum <=1 order by t.pk desc");
int pk_TableCurrentMax = pk_SequenceCurrentMax;
//如果表最大值查询结果不为空进行对比,
if (pk_TableCurrentMaxObj != null)
{
pk_TableCurrentMax = Convert.ToInt32(pk_TableCurrentMaxObj);
//拿到表中最大值和序列最大值之间的差值
int num_BetweenTableSequence = pk_TableCurrentMax - pk_SequenceCurrentMax + 1;
//更改序列递增规则使下一次拿到的序列号比表中最大pk大1
db.QueryScalar("alter sequence " + sequenceName + " increment by " + num_BetweenTableSequence.ToString());
//执行nexval拿到下一个序列号
pk_TableCurrentMax = Convert.ToInt32(db.QueryScalar("select " + sequenceName + ".nextval from dual"));
//更改序列递增规则为每次递增一个。
db.QueryScalar("alter sequence " + sequenceName + " increment by 1");
}
return pk_TableCurrentMax;
}
}
/// <summary>
/// 编写内容:下载文件转换流数据方法
/// </summary>
public string Base64(string FilePath)
{
string data = "";
try
{
using (MemoryStream msReader = new MemoryStream())
{
using (FileStream fs = new FileStream(FilePath, FileMode.Open))
{
byte[] buffer = new byte[1024];
int readLen = 0;
while ((readLen = fs.Read(buffer, 0, buffer.Length)) > 0)
{
msReader.Write(buffer, 0, readLen);
}
}
data = Convert.ToBase64String(msReader.ToArray());//转换base64
}
return data;//返回值
}
catch (Exception ex)
{
logger.InfoFormat(ex.ToString());
throw;
}
}
#endregion
}
}

@ -8,6 +8,9 @@ using System.Threading.Tasks;
namespace IBKLinker_Minio.Entity.MinioController
{
/// <summary>
/// 文件夹递归查询model
/// </summary>
public class StoragePath
{
/// <summary>

@ -37,6 +37,9 @@
<object id="db" type="SOA.Persistent.OracleDataStore, SOA.Persistent" scope="prototype">
<constructor-arg value="Data Source=(DESCRIPTION= (ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.15.88.212)(PORT=1521))) (CONNECT_DATA=(SERVICE_NAME=ORCL))); User Id=RDMS;Password=nerc;"/>
</object>
<object id="qmsdb" type="SOA.Persistent.OracleDataStore, SOA.Persistent" scope="prototype">
<constructor-arg value="Data Source=(DESCRIPTION= (ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.15.89.233)(PORT=1522))) (CONNECT_DATA=(SERVICE_NAME=ORCL))); User Id=qms;Password=system;"/>
</object>
<!--<object id="db_1_21" type="SOA.Persistent.OracleDataStore, SOA.Persistent" scope="prototype">
<constructor-arg value="Data Source=(DESCRIPTION= (ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.15.1.21)(PORT=1525))) (CONNECT_DATA=(SERVICE_NAME=ygcgx1))); User Id=DTGC;Password=JySzh)_20220715;"/>
</object>
@ -65,6 +68,12 @@
</objects>
</soa>
<appSettings>
<add key="MinIOIp" value="172.15.88.212:9000" />
<add key="MinIOName" value="minioadmin" />
<add key="MinIoPass" value="minioadmin" />
<add key="BuckName" value="dayetegang" />
</appSettings>
<log4net>
<appender name="ConsoleLogOutput" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">

Loading…
Cancel
Save