From f8e0ef6d33553ade493cc02d8755b0fd1ba99310 Mon Sep 17 00:00:00 2001 From: sunliang <593170460@qq.com> Date: Sat, 18 Nov 2023 14:46:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=87=8D=E5=A4=8D=E6=96=87=E4=BB=B6=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MinioController/MinioApiController.cs | 124 ++++++++++++------ 1 file changed, 86 insertions(+), 38 deletions(-) diff --git a/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs b/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs index ac067f0..9c8af3c 100644 --- a/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs +++ b/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs @@ -36,6 +36,8 @@ using System.Xml.Linq; using NPOI.HPSF; using IBKLinker_Minio.Common; using NPOI.POIFS.Crypt.Dsig; +using NPOI.SS.Formula.Atp; +using Org.BouncyCastle.Asn1.Pkcs; namespace IBKLinker_Minio.Controller.MinioController { @@ -689,13 +691,13 @@ namespace IBKLinker_Minio.Controller.MinioController { foreach (var items in minioStoragePath) //先循环接收数据 { - checkdatelist = db.Query("select t.FILE_NAME from MINIO_STORAGE_PATH where 1=1 and FILE_NAME='"+items.FileName+ "' and UPK='"+items.Upk+"'").ToList();//查询上传的文件或新建的文件夹在当前文件夹下是否有重复存在 + 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) //如果有 { RecordFileName += items.FileName +",";//记录名称 } } - if (RecordFileName == null)//如果没有正常上传 + if (RecordFileName == "")//如果正常上传 { foreach (var item in minioStoragePath) { @@ -765,7 +767,7 @@ namespace IBKLinker_Minio.Controller.MinioController 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.Operater = item.CreatorUser + " 上传了一个新的文档," + item.FileName + " " +DateTime.Now.ToString();//操作 MOdata.CreationTime = DateTime.Now;//创建时间 db.Insert(MOdata);//写入数据库 #endregion @@ -805,6 +807,8 @@ namespace IBKLinker_Minio.Controller.MinioController RequestEntity request = new RequestEntity(); try { + MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//连接所需minio所在地址、登录名、密码 + string buckname = "dayetegang";//桶名称 ///创建数据库连接上下文对象 using (IDbContext db = ObjectContainer.GetObject("db")) { @@ -815,27 +819,62 @@ namespace IBKLinker_Minio.Controller.MinioController ///给修改时间赋值 DateTime time = DateTime.Now;//取当前时间 MinioStoragePath date = new MinioStoragePath(); - List datebase = new List(); - foreach (var item in data) + List datelist = new List(); + MinioOperationlog MOdata = new MinioOperationlog(); + if (data.Count > 0) { - 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); + 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删除 + if (item.Bate64 != null)//如果是修改文件 + { + 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数据库 + uploadTask.Wait(); + if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted)//判断是否上传成功 + { + 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);//写入数据库 + #endregion + } + } + else //正常修改文件/文件夹名称或移动 + { + datelist.Add(date); + } + } + if (datelist != null) + { + db.Update(datelist); + db.Commit();//提交事务 + request.code = "0"; + request.msg = "修改成功!"; + } + else + { + request.code = "1"; + request.msg = "请检查是否符合修改规范!"; + } } - db.Update(datebase); - db.Commit();//提交事务 - request.code = "0"; - request.msg = "修改成功!"; } catch (Exception ex) { @@ -869,11 +908,20 @@ 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(); db.BeginTransaction(); string sql = ""; //db.Delete(master); foreach (var item in master) { + #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);//写入数据库 + #endregion if (item.FileType == 1) //如果类型是文件 { sql = "begin "; @@ -885,24 +933,24 @@ namespace IBKLinker_Minio.Controller.MinioController } else { - 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 - { + //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";