From ae1c60aa4a4a127db086a3200c52b56d08e1f58b Mon Sep 17 00:00:00 2001
From: sunliang <593170460@qq.com>
Date: Tue, 21 Nov 2023 17:13:39 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E8=AE=B0=E5=BD=95=E6=93=8D=E4=BD=9C?=
=?UTF-8?q?=E6=97=A5=E5=BF=97=E6=94=B9=E4=B8=BA=E7=BB=9F=E4=B8=80=E6=96=B9?=
=?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E8=A1=A8?=
=?UTF-8?q?=E5=AE=9E=E4=BD=93=E7=B1=BB=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6?=
=?UTF-8?q?pk=E3=80=81=E6=96=87=E4=BB=B6=E7=88=B6=E7=BA=A7pk=E3=80=81?=
=?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E6=9F=A5=E8=AF=A2=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
IBKLinker-Minio/Common/MinioBusinessLogic.cs | 21 ++-
.../MinioController/MinioApiController.cs | 148 +++++++++++-------
.../MinioController/GetStoragePathModel.cs | 35 +++++
.../MinioController/MinioOperationlog.cs | 18 +++
4 files changed, 166 insertions(+), 56 deletions(-)
create mode 100644 IBKLinker-Minio/Entity/MinioController/GetStoragePathModel.cs
diff --git a/IBKLinker-Minio/Common/MinioBusinessLogic.cs b/IBKLinker-Minio/Common/MinioBusinessLogic.cs
index dd37a46..51ba4bd 100644
--- a/IBKLinker-Minio/Common/MinioBusinessLogic.cs
+++ b/IBKLinker-Minio/Common/MinioBusinessLogic.cs
@@ -45,7 +45,9 @@ namespace IBKLinker_Minio.Common
public class MinioBusinessLogic
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
+ ///
+ /// 异步处理取minio文件流数据方法
+ ///
public async Task Download(string bucketName, string path)
{
@@ -68,5 +70,22 @@ namespace IBKLinker_Minio.Common
throw;
}
}
+ ///
+ /// 文件上传操作日志记录
+ ///
+ 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(MOdata);//写入数据库
+ }
}
}
diff --git a/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs b/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs
index 847a4c5..d1feb7b 100644
--- a/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs
+++ b/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs
@@ -315,7 +315,7 @@ namespace IBKLinker_Minio.Controller.MinioController
{
sql += " and a.STATE =" + minioUser.State + "";
}
- if (minioUser.RoleId>0)
+ if (minioUser.RoleId > 0)
{
sql += " and a.ROLE_ID =" + minioUser.RoleId + "";
}
@@ -424,12 +424,20 @@ namespace IBKLinker_Minio.Controller.MinioController
{
try
{
- db.BeginTransaction();//启动事务
- db.Delete(master);
- db.Commit();//提交事务
- request.code = "0";
- request.msg = "删除成功!";
-
+ if (master != null)
+ {
+ db.BeginTransaction();//启动事务
+ string sql = string.Format("delete from MINIO_FILEASSOCIATION where 1=1 and PK={0}", master.Pk);
+ db.Execute(sql);
+ db.Commit();//提交事务
+ request.code = "0";
+ request.msg = "删除成功!";
+ }
+ else
+ {
+ request.code = "1";
+ request.msg = "删除失败!";
+ }
}
catch (Exception ex)
{
@@ -454,11 +462,11 @@ namespace IBKLinker_Minio.Controller.MinioController
{
using (IDbContext db = ObjectContainer.GetObject("db"))
{
- if (FilePk != null)
+ if (FilePk != null)
{
string sql = string.Empty;
//先通过文件ID拿到文件的类型是技术协议还是质量要点或者工艺卡
- MinioStoragePath ds= db.Query("select * from MINIO_STORAGE_PATH where PK= " + int.Parse(FilePk) + " and CLEAR_FLAG='0' ORDER BY PK").FirstOrDefault();
+ MinioStoragePath ds = db.Query("select * from MINIO_STORAGE_PATH where PK= " + int.Parse(FilePk) + " and CLEAR_FLAG='0' ORDER BY PK").FirstOrDefault();
if (ds != null)
{
if (ds.DocumentType == "1")
@@ -469,14 +477,14 @@ namespace IBKLinker_Minio.Controller.MinioController
{
sql += string.Format(" and FILE_PK ={0} or ASSOCIATION_FILE_PK ={0}", int.Parse(FilePk));
}
- else
+ else
{
sql += string.Format(" and ASSOCIATION_FILE_PK ={0}", int.Parse(FilePk));
}
}
//通过文件类型判断是查文件的下一级还是查文件的上下级
-
+
IList result = new List();
request.data = db.Query("select * from MINIO_FILEASSOCIATION where 1=1 " + sql + " ORDER BY PK");
request.code = "0";
@@ -576,7 +584,7 @@ namespace IBKLinker_Minio.Controller.MinioController
//DateTime time = DateTime.Now;
db.Update(minioRolePermission.minioRolePermission);
//删除历史记录加入新的记录
- db.Query("delete from MINIO_AUTHORITY where LIMITS_AUTHORITY_ID='"+ minioRolePermission.minioRolePermission.LimitsAuthorityId + "' ");
+ db.Query("delete from MINIO_AUTHORITY where LIMITS_AUTHORITY_ID='" + minioRolePermission.minioRolePermission.LimitsAuthorityId + "' ");
db.Insert(AuthorityList);
db.Commit();
request.code = "0";
@@ -608,16 +616,16 @@ namespace IBKLinker_Minio.Controller.MinioController
RequestEntity request = new RequestEntity();
IList MUData = new List();
IList UdpData = new List();
- string sql = "";
+ string sql = "begin ";
using (IDbContext db = ObjectContainer.GetObject("db"))
{
try
{
if (data != null)
{
- MUData = db.Query("select * from MINIO_USER where 1=1 and ROLE_ID='"+data.Id+"'");//查询用户表中使用要被删除的角色
+ MUData = db.Query("select * from MINIO_USER where 1=1 and ROLE_ID='" + data.Id + "'");//查询用户表中使用要被删除的角色
db.BeginTransaction();//启动事务
- if (MUData.Count > 0)
+ if (MUData.Count > 0)//如果有数据需要同步修改用户表中的角色
{
foreach (var item in MUData)
{
@@ -632,8 +640,9 @@ namespace IBKLinker_Minio.Controller.MinioController
}
db.Update(UdpData);
}
- db.Query("delete from MINIO_AUTHORITY where LIMITS_AUTHORITY_ID='" + data.LimitsAuthorityId + "' ");
- sql = string.Format("delete from MINIO_ROLE_PERMISSION where 1=1 and PK={0}", data.Pk);
+ sql += string.Format("delete from MINIO_AUTHORITY where 1=1 and LIMITS_AUTHORITY_ID={0};", data.LimitsAuthorityId);
+ sql = string.Format("delete from MINIO_ROLE_PERMISSION where 1=1 and PK={0};", data.Pk);
+ sql += "end;";
db.Execute(sql);
db.Commit();//提交事务
request.code = "0";
@@ -667,7 +676,7 @@ namespace IBKLinker_Minio.Controller.MinioController
IList result = new List();
if (!string.IsNullOrEmpty(minioRolePermission.Id))
{
- sql += " and ID ='" + minioRolePermission.Id+"'";
+ sql += " and ID ='" + minioRolePermission.Id + "'";
}
request.data = db.Query("select * from MINIO_ROLE_PERMISSION where 1=1 " + sql + " ORDER BY PK");
request.code = "0";
@@ -698,6 +707,8 @@ namespace IBKLinker_Minio.Controller.MinioController
{
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//连接所需minio所在地址、登录名、密码
string buckname = "dayetegang";//桶名称
+ MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
+ string Operate = "";//操作
List date = new List();
List checkdatelist = new List();
string RecordFileName = "";//重复文件名称记录
@@ -707,10 +718,10 @@ namespace IBKLinker_Minio.Controller.MinioController
{
foreach (var items in minioStoragePath) //先循环接收数据
{
- checkdatelist = db.Query("select t.FILE_NAME from MINIO_STORAGE_PATH t where 1=1 and t.FILE_NAME='"+items.FileName+ "' and t.UPK='"+items.Upk+"'").ToList();//查询上传的文件或新建的文件夹在当前文件夹下是否有重复存在
- if (checkdatelist.Count >0) //如果有
+ checkdatelist = db.Query("select t.* from MINIO_STORAGE_PATH t where 1=1 and t.FILE_NAME='" + items.FileName + "' and t.UPK='" + items.Upk + "'").ToList();//查询上传的文件或新建的文件夹在当前文件夹下是否有重复存在
+ if (checkdatelist.Count > 0) //如果有
{
- RecordFileName += items.FileName +",";//记录名称
+ RecordFileName += items.FileName + ",";//记录名称
}
}
if (RecordFileName == "")//如果正常上传
@@ -718,7 +729,7 @@ namespace IBKLinker_Minio.Controller.MinioController
foreach (var item in minioStoragePath)
{
MinioStoragePath data = new MinioStoragePath();
- MinioOperationlog MOdata = new MinioOperationlog();
+
date = db.Query("select * from MINIO_STORAGE_PATH where pk='" + minioStoragePath[0].Upk + "' ORDER BY PK").ToList();
if (item.FileType == 0) //如果是文件夹
{
@@ -736,6 +747,10 @@ namespace IBKLinker_Minio.Controller.MinioController
data.FileLevel = date[0].FileLevel + 1;//层级
data.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_STORAGE_PATH.nextval from dual"));///拿到表自增长的值赋值给自增长主键pk
db.Insert(data);
+ #region 记录日志
+ Operate = " 创建了一个新的文件夹,";
+ bb.MinioOperationLog(data.CreatorUser, data.FileName, Operate, data.Pk.ToString(), data.Upk.ToString(), db);
+ #endregion
}
}
else
@@ -750,6 +765,10 @@ namespace IBKLinker_Minio.Controller.MinioController
data.ClearFlag = "0";//删除状态为未删除
data.FileLevel = 1;//层级
db.Insert(data);
+ #region 记录日志
+ Operate = " 创建了一个新的文件夹,";
+ bb.MinioOperationLog(data.CreatorUser, data.FileName, Operate, data.Pk.ToString(), data.Upk.ToString(), db);
+ #endregion
}
#region minio创建文件夹
//var folderName = minioStoragePath[0].FilePath + "/";//取前端发送路径(或单一文件夹名称)
@@ -781,12 +800,8 @@ namespace IBKLinker_Minio.Controller.MinioController
request.msg = "文件上传成功!";
request.code = "0";
#region 记录日志
- MOdata.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_OPERATIONLOG.nextval from dual"));///拿到表自增长的值赋值给自增长主键pk;
- MOdata.OperateUser = item.CreatorUser;//操作者
- MOdata.OperateTime = DateTime.Now;//操作时间
- MOdata.Operater = item.CreatorUser + " 上传了一个新的文档," + item.FileName + " " +DateTime.Now.ToString();//操作
- MOdata.CreationTime = DateTime.Now;//创建时间
- db.Insert(MOdata);//写入数据库
+ Operate = " 上传了一个新的文档,";
+ bb.MinioOperationLog(item.CreatorUser, item.FileName, Operate, data.Pk.ToString(), data.Upk.ToString(), db);
#endregion
}
else
@@ -797,9 +812,9 @@ namespace IBKLinker_Minio.Controller.MinioController
}
}
}
- else
+ else
{
- request.msg = "文件上传失败,其中" + RecordFileName +"在此文件夹已经存在!";
+ request.msg = "文件上传失败,其中" + RecordFileName + "在此文件已经存在!";
request.code = "1";
}
db.Commit();
@@ -837,7 +852,8 @@ namespace IBKLinker_Minio.Controller.MinioController
DateTime time = DateTime.Now;//取当前时间
MinioStoragePath date = new MinioStoragePath();
List datelist = new List();
- MinioOperationlog MOdata = new MinioOperationlog();
+ MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
+ string Operate = "";//操作
if (data.Count > 0)
{
foreach (var item in data)
@@ -866,19 +882,15 @@ namespace IBKLinker_Minio.Controller.MinioController
{
datelist.Add(date);
#region 记录日志
- MOdata.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_OPERATIONLOG.nextval from dual"));///拿到表自增长的值赋值给自增长主键pk;
- MOdata.OperateUser = item.CreatorUser;//操作者
- MOdata.OperateTime = DateTime.Now;//操作时间
- MOdata.Operater = item.CreatorUser + " 更新了 " + item.FileName +" 这个文档。 " + DateTime.Now.ToString();//操作
- MOdata.CreationTime = DateTime.Now;//创建时间
- db.Insert(MOdata);//写入数据库
+ Operate = " 更新了这个文档, ";
+ bb.MinioOperationLog(item.CreatorUser, item.FileName, Operate, item.Pk.ToString(), item.Upk.ToString(), db);
#endregion
}
}
else //正常修改文件/文件夹名称或移动
{
datelist.Add(date);
- }
+ }
}
if (datelist != null)
{
@@ -887,7 +899,7 @@ namespace IBKLinker_Minio.Controller.MinioController
request.code = "0";
request.msg = "修改成功!";
}
- else
+ else
{
request.code = "1";
request.msg = "请检查是否符合修改规范!";
@@ -926,7 +938,10 @@ namespace IBKLinker_Minio.Controller.MinioController
DateTime time = DateTime.Now;//取当前时间
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");
string buckname = "dayetegang";//桶名称
- MinioOperationlog MOdata = new MinioOperationlog();
+ MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
+ string Operate = "";//操作
+ string FilePk = "";//文件pk
+ string fileUPk = "";//文件父级pk
db.BeginTransaction();
string sql = "";
//db.Delete(master);
@@ -944,12 +959,8 @@ namespace IBKLinker_Minio.Controller.MinioController
sql += "end;";
db.Execute(sql);
#region 记录日志
- MOdata.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_OPERATIONLOG.nextval from dual"));///拿到表自增长的值赋值给自增长主键pk;
- MOdata.OperateUser = item.ClearUsers;//操作者
- MOdata.OperateTime = DateTime.Now;//操作时间
- MOdata.Operater = item.ClearUsers + " 删除了 " + item.FileName + " 这个文档。 " + DateTime.Now.ToString();//操作
- MOdata.CreationTime = DateTime.Now;//创建时间
- db.Insert(MOdata);//写入数据库
+ Operate = " 删除了这个文档, ";
+ bb.MinioOperationLog(item.ClearUsers, item.FileName, Operate, FilePk, fileUPk, db);
#endregion
}
}
@@ -957,12 +968,15 @@ namespace IBKLinker_Minio.Controller.MinioController
{
sql = string.Format("delete from MINIO_STORAGE_PATH where 1=1 and PK='{2}' ", item.ClearUsers, time, item.Pk);//更新文件路径表中的删除状态
db.Execute(sql);
+ #region 记录日志
+ Operate = " 删除了这个文件夹, ";
+ bb.MinioOperationLog(item.ClearUsers, item.FileName, Operate, FilePk, fileUPk, db);
+ #endregion
}
}
request.code = "0";
request.msg = "删除成功";
db.Commit();
-
}
catch (Exception ex)
{
@@ -995,9 +1009,9 @@ namespace IBKLinker_Minio.Controller.MinioController
{
sql += " and FILE_NAME like'%" + PathData.FileName + "%'";
}
- if (PathData.Upk >0) //如果在子文件夹内
+ if (PathData.Upk > 0) //如果在子文件夹内
{
- sql += " and UPK = '"+ PathData .Upk+ "'";
+ sql += " and UPK = '" + PathData.Upk + "'";
}
if (!string.IsNullOrEmpty(PathData.BeginTime))//如果有开始时间
{
@@ -1007,15 +1021,13 @@ namespace IBKLinker_Minio.Controller.MinioController
{
sql += string.Format(" and CREATE_TIME <= to_date('{0}', 'yyyy/mm/dd hh24:mi:ss')", PathData.EndTime);//结束时间
}
-
request.data = db.Query("select * from MINIO_STORAGE_PATH where 1=1 " + sql + " and CLEAR_FLAG='0' ORDER BY PK");
request.code = "0";
}
- else
+ else
{
request.code = "1";
request.msg = "查询失败,请检查查询条件!";
-
}
}
}
@@ -1253,6 +1265,32 @@ namespace IBKLinker_Minio.Controller.MinioController
}
#endregion
+ #region 操作日志接口
+ ///
+ /// 查询minio文件操作日志
+ ///
+ ///
+ [HttpPost, Route("GetMinioBusinessLogic")]
+ public RequestEntity GetMinioBusinessLogic()
+ {
+ RequestEntity request = new RequestEntity();
+ try
+ {
+ using (IDbContext db = ObjectContainer.GetObject("db"))
+ {
+ request.data = db.Query("select * from MINIO_OPERATIONLOG where 1=1");
+ request.code = "0";
+ }
+ }
+ catch (Exception ex)
+ {
+ request.code = "1";
+ logger.ErrorFormat("主表:MINIO_OPERATIONLOG,查询minio文件操作日志表失败,错误原因:{0}", ex);
+ }
+ return request;
+ }
+ #endregion
+
#region 标准清单
///
/// 标准清单导出接口
@@ -1376,7 +1414,7 @@ namespace IBKLinker_Minio.Controller.MinioController
curRow.GetCell(1).SetCellValue(data.FileName.Substring(0, Num).Trim());//协议编号
curRow.GetCell(2).SetCellValue(data.FileName.Substring(Num, name).Trim());//名称
}
- if (data.FilePath.IndexOf("标准通知")>=0)
+ if (data.FilePath.IndexOf("标准通知") >= 0)
{
int Num = data.FileName.IndexOf("号");//取文件名称编号位数
int name = data.FileName.Length - Num;//取文件名称名称位数
@@ -1384,7 +1422,7 @@ namespace IBKLinker_Minio.Controller.MinioController
curRow.GetCell(1).SetCellValue(data.FileName.Substring(0, Num).Trim());//编号
curRow.GetCell(2).SetCellValue(data.FileName.Substring(Num, name).Replace(":", "").Trim());//名称
}
- if(data.FilePath.IndexOf("标准通知") == -1 && data.FilePath.IndexOf("企业标准/XYGN") == -1 || data.FilePath.IndexOf("企业标准/XYGW") == -1)
+ if (data.FilePath.IndexOf("标准通知") == -1 && data.FilePath.IndexOf("企业标准/XYGN") == -1 || data.FilePath.IndexOf("企业标准/XYGW") == -1)
{
var filecontent = data.FileName.Split(' ');//以空格进行区分
curRow.GetCell(0).SetCellValue(data.FilePath.Replace(data.FileName, ""));//路径
@@ -1483,6 +1521,6 @@ namespace IBKLinker_Minio.Controller.MinioController
}
}
#endregion
-
+
}
}
diff --git a/IBKLinker-Minio/Entity/MinioController/GetStoragePathModel.cs b/IBKLinker-Minio/Entity/MinioController/GetStoragePathModel.cs
new file mode 100644
index 0000000..f22f8da
--- /dev/null
+++ b/IBKLinker-Minio/Entity/MinioController/GetStoragePathModel.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace IBKLinker_Minio.Entity.MinioController
+{
+ ///
+ /// 查询minio文件文件夹路径model(包括模糊查询文件名称以及根据时间查询)
+ ///
+ ///
+ public class GetStoragePathModel
+ {
+ ///
+ /// 文件名称
+ ///
+ public string FileName { get; set; }
+
+ ///
+ ///子文件夹的父ID
+ ///
+ public int Upk { get; set; }
+
+ ///
+ /// 开始时间
+ ///
+ public string BeginTime { set; get; }
+
+ ///
+ /// 结束时间
+ ///
+ public string EndTime { set; get; }
+ }
+}
diff --git a/IBKLinker-Minio/Entity/MinioController/MinioOperationlog.cs b/IBKLinker-Minio/Entity/MinioController/MinioOperationlog.cs
index 4631ddf..2117fad 100644
--- a/IBKLinker-Minio/Entity/MinioController/MinioOperationlog.cs
+++ b/IBKLinker-Minio/Entity/MinioController/MinioOperationlog.cs
@@ -55,6 +55,24 @@ namespace IBKLinker_Minio.Entity.MinioController
[Persistent("ALTERNATE_FIELDS"), DisplayName("备用字段")]
public string AlternateFilelds { get; set; }
+ ///
+ ///文件pk
+ ///
+ [Persistent("FILE_PK", IsKey = true), DisplayName("主键")]
+ public string FilePk { get; set; }
+
+ ///
+ ///文件父级pk
+ ///
+ [Persistent("FILE_UPK", IsKey = true), DisplayName("主键")]
+ public string FileUPk { get; set; }
+
+ ///
+ ///文件名
+ ///
+ [Persistent("FILE_NAME"), DisplayName("文件名")]
+ public string FileName { get; set; }
+
}
}