You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.3 KiB
C#

using IBKLinker_Minio.Entity;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Minio;
using System.Net.PeerToPeer;
using System.IO;
using System.Reactive.Linq;
using Minio.DataModel;
using System.Security.AccessControl;
using System.IO.Pipes;
using System.Net.Mime;
using IBKLinker_Minio.Entity.MinioController;
using SOA.Objects;
using SOA.Persistent;
using System.Web.Http.Results;
using System.Runtime.InteropServices.ComTypes;
using System.Xml;
using Swashbuckle.Swagger;
using System.Runtime.ConstrainedExecution;
using System.Net.Http;
using System.Web.UI.WebControls;
using System.Runtime.Remoting.Contexts;
using System.Runtime.InteropServices;
using System.Net;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;
using System.Net.Http.Headers;
using NPOI.SS.Formula.Functions;
using System.Xml.Linq;
using NPOI.HPSF;
namespace IBKLinker_Minio.Common
{
/// <summary>
/// 作者:孙亮
/// 编写时间2023-10-13
/// 编写内容minio业务逻辑
/// </summary>
public class MinioBusinessLogic
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 异步处理取minio文件流数据方法
/// </summary>
public async Task<string> Download(string bucketName, 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) =>
{
stream.CopyTo(memoryStream);//将文件去除复制到memoryStream
});
memoryStream.Position = 0;//清除
string base64String = Convert.ToBase64String(memoryStream.ToArray());//转换base64
return base64String;//返回值
}
catch (Exception ex)
{
logger.InfoFormat(ex.ToString());
throw;
}
}
/// <summary>
/// 文件上传操作日志记录
/// </summary>
public void MinioOperationLog(string OperateUser, string FileName, string Operate, string FilePk, string FileUPk, IDbContext db) //传参为操作人、文件名、操作、数据库连接上下文对象
{
MinioOperationlog MOdata = new MinioOperationlog();
DateTime time = DateTime.Now;//时间
MOdata.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_OPERATIONLOG.nextval from dual"));///拿到表自增长的值赋值给自增长主键pk;
MOdata.OperateUser = OperateUser;//操作者
MOdata.OperateTime = time;//操作时间
MOdata.FilePk = FilePk.ToString();//文件pk
MOdata.FileUPk = FileUPk.ToString();//文件父级pk
MOdata.FileName = FileName;//文件名
MOdata.Operater = OperateUser + Operate + FileName + " " + time.ToString();//操作
MOdata.CreationTime = time;//创建时间
db.Insert<MinioOperationlog>(MOdata);//写入数据库
}
}
}