From 0ad2a4e62413a099be41fb9912974ef7ef35d7c9 Mon Sep 17 00:00:00 2001
From: sunliang <593170460@qq.com>
Date: Thu, 9 Nov 2023 17:34:37 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E4=B8=8A?=
=?UTF-8?q?=E4=BC=A0=E5=85=B3=E8=81=94=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8F=8A=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../MinioController/MinioApiController.cs | 93 +++++++++++++++----
.../Entity/MinioController/MinioAuthority.cs | 3 +-
.../MinioController/MinioFileassociation.cs | 3 +-
.../MinioController/MinioOperationlog.cs | 3 +-
.../MinioController/MinioRolePermission.cs | 3 +-
.../MinioController/MinioStoragePath.cs | 3 +-
.../Entity/MinioController/MinioUser.cs | 3 +-
7 files changed, 86 insertions(+), 25 deletions(-)
diff --git a/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs b/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs
index bbb5508..de8e90d 100644
--- a/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs
+++ b/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs
@@ -426,7 +426,7 @@ namespace IBKLinker_Minio.Controller.MinioController
///
///
[HttpPost, Route("GetFileassociation")]
- public RequestEntity GetFileassociation(MinioFileassociation minioFileassociation)
+ public RequestEntity GetFileassociation(string FileName)
{
RequestEntity request = new RequestEntity();
try
@@ -435,11 +435,10 @@ namespace IBKLinker_Minio.Controller.MinioController
{
string sql = string.Empty;
IList result = new List();
- if (!string.IsNullOrEmpty(minioFileassociation.FileName.ToString()))
+ if (!string.IsNullOrEmpty(FileName.ToString()))
{
- sql += " and FILE_NAME ='" + minioFileassociation.FileName + "'";
+ sql += " and FILE_NAME like'%" + FileName + "%'";
}
-
request.data = db.Query("select * from MINIO_FILEASSOCIATION where 1=1 " + sql + " ORDER BY PK");
request.code = "0";
}
@@ -599,7 +598,6 @@ namespace IBKLinker_Minio.Controller.MinioController
RequestEntity request = new RequestEntity();
using (IDbContext db = ObjectContainer.GetObject("db"))
{
-
try
{
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//连接所需minio所在地址、登录名、密码
@@ -612,11 +610,11 @@ namespace IBKLinker_Minio.Controller.MinioController
foreach (var item in minioStoragePath)
{
MinioStoragePath data = new MinioStoragePath();
+ date = db.Query("select * from MINIO_STORAGE_PATH where pk='" + minioStoragePath[0].Upk + "' ORDER BY PK").ToList();
if (item.FileType == 0) //如果是文件夹
{
if (item.Upk > 0)//判断如果创建的是根目录文件夹前端不需要对父级id传值
{
- date = db.Query("select * from MINIO_STORAGE_PATH where pk='" + minioStoragePath[0].Upk + "' ORDER BY PK").ToList();
if (date.Count > 0)
{
data.Upk = minioStoragePath[0].Upk;//子文件夹的父级id
@@ -624,6 +622,7 @@ namespace IBKLinker_Minio.Controller.MinioController
data.FileType = minioStoragePath[0].FileType;//文件类型
data.FilePath = minioStoragePath[0].FilePath;//文件路径
data.CreatorUser = minioStoragePath[0].CreatorUser;//创建者
+ data.ClearFlag = "0";//删除状态为未删除
data.CreatorTime = DateTime.Now;//创建时间
data.FileLevel = date[0].FileLevel + 1;//层级
data.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_STORAGE_PATH.nextval from dual"));///拿到表自增长的值赋值给自增长主键pk
@@ -639,6 +638,7 @@ namespace IBKLinker_Minio.Controller.MinioController
data.FilePath = minioStoragePath[0].FilePath;//文件路径
data.CreatorUser = minioStoragePath[0].CreatorUser;//创建者
data.CreatorTime = DateTime.Now;//创建时间
+ data.ClearFlag = "0";//删除状态为未删除
data.FileLevel = 1;//层级
db.Insert(data);
}
@@ -647,10 +647,25 @@ namespace IBKLinker_Minio.Controller.MinioController
//minio.PutObjectAsync(buckname, folderName, new MemoryStream(), 0, "application/octet-stream");
#endregion
request.msg = "文件夹创建成功!";
+ request.code = "0";
}
if (item.FileType == 1)//如果是文件
{
- var contentType = "application/" + item.FileCategory;
+ string type = "";
+ if (item.FileCategory == "doc")
+ {
+ type = "application/msword";
+ }
+ else if (item.FileCategory == "pdf")
+ {
+ type = "application/pdf";
+ }
+ else if (item.FileCategory == "docx")
+ {
+ type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+ }
+
+ 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数据库
@@ -664,7 +679,8 @@ namespace IBKLinker_Minio.Controller.MinioController
data.FilePath = item.FilePath;//文件路径
data.CreatorUser = item.CreatorUser;//创建者
data.CreatorTime = DateTime.Now;//创建时间
- data.FileLevel = item.FileLevel + 1;//层级
+ data.ClearFlag = "0";//删除状态为未删除
+ data.FileLevel = date[0].FileLevel + 1;//层级
db.Insert(data);
request.msg = "文件上传成功!";
request.code = "0";
@@ -706,15 +722,34 @@ namespace IBKLinker_Minio.Controller.MinioController
///启动事务
db.BeginTransaction();
///给修改时间赋值
- DateTime time = DateTime.Now;
+ DateTime time = DateTime.Now;//取当前时间
+ MinioStoragePath date = new MinioStoragePath();
+ List datebase = new List();
+ foreach (var item in data)
+ {
+ date.Pk = item.Pk;//主键ID
+ date.Upk = item.Upk;//子文件夹的父ID
+ date.FileName = item.FileName;//文件名称
+ date.FileType = item.FileType;//文件类型
+ date.FilePath = item.FilePath;//文件路径
+ date.CreatorUser = item.CreatorUser;//创建者
+ date.CreatorTime = item.CreatorTime;//创建时间
+ date.DownloadNum = item.DownloadNum;//下载次数
+ date.FileLevel = item.FileLevel;//层级
+ date.ModifyUsers = item.ModifyUsers;//修改用户
+ date.ModifyTime = time;//修改时间
+ date.ClearFlag = "0";//删除标记 0未删除 1删除
+ datebase.Add(date);
+ }
db.Update(data);
- db.Commit();
+ db.Commit();//提交事务
request.code = "0";
+ request.msg = "修改成功!";
}
catch (Exception ex)
{
request.code = "1";
- db.Rollback();
+ db.Rollback();//回滚
///把错误日志写到日志文件
logger.ErrorFormat("主表:MINIO_STORAGE_PATH,修改minio文件文件夹路径表失败,错误原因:{0}", ex);
}
@@ -733,34 +768,54 @@ namespace IBKLinker_Minio.Controller.MinioController
///
/// 需要删除的数据
[HttpPost, Route("RemoveStoragePath")]
- public RequestEntity RemoveStoragePath(IList master)
+ public RequestEntity RemoveStoragePath(List master)
{
RequestEntity request = new RequestEntity();
using (IDbContext db = ObjectContainer.GetObject("db"))
{
try
{
+ DateTime time = DateTime.Now;//取当前时间
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");
string buckname = "dayetegang";//桶名称
db.BeginTransaction();
- db.Delete(master);
+ string sql = "";
+ //db.Delete(master);
foreach (var item in master)
{
if (item.FileType == 1) //如果类型是文件
{
- //minio.RemoveObjectAsync(buckname, item.FileName);//minio操作删除文件
- string sql = string.Format("update MINIO_STORAGE_PATH set CLEAR_FLAG='1',CLEAR_USERS='{0}',CLEAR_TIME='{1}' where PK='{2}' ", item.ClearUsers, item.ClearTime, item.Pk);//更新文件路径表中的删除状态
- db.Execute(sql);
- sql = string.Format(" delete from MINIO_FILEASSOCIATION where FILE_PK like'%{0}%' or ASSOCIATION_FILE_PK like'%{0}%'", item.Pk);//删除关联表中的关联关系
+ sql = "begin ";
+ sql += string.Format("update MINIO_STORAGE_PATH set CLEAR_FLAG='1',CLEAR_USERS='{0}',CLEAR_TIME='{1}' where PK='{2}';", item.ClearUsers, time, item.Pk);//更新文件路径表中的删除状态
+ sql += string.Format(" delete from MINIO_FILEASSOCIATION where FILE_PK like'%{0}%' or ASSOCIATION_FILE_PK like'%{0}%';", item.Pk);//删除关联表中的关联关系
+ sql += "end;";
db.Execute(sql);
+ //minio.RemoveObjectAsync(buckname, item.FileName);//minio操作删除文件
}
else
{
- string sql = string.Format("update MINIO_STORAGE_PATH set CLEAR_FLAG='1',CLEAR_USERS='{0}',CLEAR_TIME='{1}' where PK='{2}' ",item.ClearUsers,item.ClearTime, item.Pk);//更新文件路径表中的删除状态
+ string sel =string.Format( "select * from MINIO_STORAGE_PATH where UPK='{0}'",item.Pk);
+ IList date = db.Query(sel);//查询删除文件夹时文件夹是否存在文件
+ if (date.Count > 0)
+ {
+ sql = "begin ";
+ foreach (var data in date)
+ {
+ sql += string.Format("update MINIO_STORAGE_PATH set CLEAR_FLAG='1',CLEAR_USERS='{0}',CLEAR_TIME='{1}' where PK='{2}' ", item.ClearUsers, item.ClearTime, data.Pk);
+ sql += string.Format(" delete from MINIO_FILEASSOCIATION where FILE_PK like'%{0}%' or ASSOCIATION_FILE_PK like'%{0}%';", item.Pk);//删除关联表中的关联关系
+ }
+ sql += string.Format("update MINIO_STORAGE_PATH set CLEAR_FLAG='1',CLEAR_USERS='{0}',CLEAR_TIME='{1}' where PK='{2}' ", item.ClearUsers, time, item.Pk);//更新文件路径表中的删除状态
+ }
+ else
+ {
+ sql = string.Format("update MINIO_STORAGE_PATH set CLEAR_FLAG='1',CLEAR_USERS='{0}',CLEAR_TIME='{1}' where PK='{2}' ", item.ClearUsers, time, item.Pk);//更新文件路径表中的删除状态
+ }
+
db.Execute(sql);
}
}
request.code = "0";
+ request.msg = "删除成功";
db.Commit();
}
@@ -990,7 +1045,7 @@ namespace IBKLinker_Minio.Controller.MinioController
string bucketName = "dayetegang";
var uploadTask = bb.Download(bucketName, item.FileName);//异步取base64
uploadTask.Wait();//等待取值
- if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted) //判读是否由数值
+ if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted) //判读是否有数值
{
data.Bate64 = uploadTask.Result;
data.FileName = item.FileName;
diff --git a/IBKLinker-Minio/Entity/MinioController/MinioAuthority.cs b/IBKLinker-Minio/Entity/MinioController/MinioAuthority.cs
index e5b94b8..e8d4cd8 100644
--- a/IBKLinker-Minio/Entity/MinioController/MinioAuthority.cs
+++ b/IBKLinker-Minio/Entity/MinioController/MinioAuthority.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
+using Newtonsoft.Json;
using SOA.Persistent;
namespace IBKLinker_Minio.Entity.MinioController
@@ -10,7 +11,7 @@ namespace IBKLinker_Minio.Entity.MinioController
///
///minio权限表
///
- [Serializable, Table("MINIO_AUTHORITY")]
+ [Serializable, Table("MINIO_AUTHORITY"), JsonObject]
public class MinioAuthority
{
///
diff --git a/IBKLinker-Minio/Entity/MinioController/MinioFileassociation.cs b/IBKLinker-Minio/Entity/MinioController/MinioFileassociation.cs
index 8a294b8..90cfa57 100644
--- a/IBKLinker-Minio/Entity/MinioController/MinioFileassociation.cs
+++ b/IBKLinker-Minio/Entity/MinioController/MinioFileassociation.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
+using Newtonsoft.Json;
using SOA.Persistent;
namespace IBKLinker_Minio.Entity.MinioController
@@ -10,7 +11,7 @@ namespace IBKLinker_Minio.Entity.MinioController
///
///文件关联表
///
- [Serializable, Table("MINIO_FILEASSOCIATION")]
+ [Serializable, Table("MINIO_FILEASSOCIATION"), JsonObject]
public class MinioFileassociation
{
///
diff --git a/IBKLinker-Minio/Entity/MinioController/MinioOperationlog.cs b/IBKLinker-Minio/Entity/MinioController/MinioOperationlog.cs
index 0c91dac..4631ddf 100644
--- a/IBKLinker-Minio/Entity/MinioController/MinioOperationlog.cs
+++ b/IBKLinker-Minio/Entity/MinioController/MinioOperationlog.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
+using Newtonsoft.Json;
using SOA.Persistent;
namespace IBKLinker_Minio.Entity.MinioController
@@ -10,7 +11,7 @@ namespace IBKLinker_Minio.Entity.MinioController
///
///操作日志
///
- [Serializable, Table("MINIO_OPERATIONLOG")]
+ [Serializable, Table("MINIO_OPERATIONLOG"), JsonObject]
public class MinioOperationlog
{
///
diff --git a/IBKLinker-Minio/Entity/MinioController/MinioRolePermission.cs b/IBKLinker-Minio/Entity/MinioController/MinioRolePermission.cs
index 33bef98..f23e7a2 100644
--- a/IBKLinker-Minio/Entity/MinioController/MinioRolePermission.cs
+++ b/IBKLinker-Minio/Entity/MinioController/MinioRolePermission.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
+using Newtonsoft.Json;
using SOA.Persistent;
namespace IBKLinker_Minio.Entity.MinioController
@@ -10,7 +11,7 @@ namespace IBKLinker_Minio.Entity.MinioController
///
///minio角色权限表
///
- [Serializable, Table("MINIO_ROLE_PERMISSION")]
+ [Serializable, Table("MINIO_ROLE_PERMISSION"), JsonObject]
public class MinioRolePermission
{
///
diff --git a/IBKLinker-Minio/Entity/MinioController/MinioStoragePath.cs b/IBKLinker-Minio/Entity/MinioController/MinioStoragePath.cs
index 4c02a8f..8e6e26a 100644
--- a/IBKLinker-Minio/Entity/MinioController/MinioStoragePath.cs
+++ b/IBKLinker-Minio/Entity/MinioController/MinioStoragePath.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
+using Newtonsoft.Json;
using SOA.Persistent;
namespace IBKLinker_Minio.Entity.MinioController
@@ -10,7 +11,7 @@ namespace IBKLinker_Minio.Entity.MinioController
///
///文件文件夹路径表
///
- [Serializable, Table("MINIO_STORAGE_PATH")]
+ [Serializable, Table("MINIO_STORAGE_PATH"), JsonObject]
public class MinioStoragePath
{
///
diff --git a/IBKLinker-Minio/Entity/MinioController/MinioUser.cs b/IBKLinker-Minio/Entity/MinioController/MinioUser.cs
index ae9adce..6631bd6 100644
--- a/IBKLinker-Minio/Entity/MinioController/MinioUser.cs
+++ b/IBKLinker-Minio/Entity/MinioController/MinioUser.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
+using Newtonsoft.Json;
using SOA.Persistent;
namespace IBKLinker_Minio.Entity.MinioController
@@ -10,7 +11,7 @@ namespace IBKLinker_Minio.Entity.MinioController
///
///minio用户表
///
- [Serializable, Table("MINIO_USER")]
+ [Serializable, Table("MINIO_USER"), JsonObject]
public class MinioUser
{
///