修改文件上传关联信息查询接口及修改文件接口

master
孙亮 1 year ago
parent 6e83ebf287
commit 0ad2a4e624

@ -426,7 +426,7 @@ namespace IBKLinker_Minio.Controller.MinioController
/// </summary>
/// <returns></returns>
[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<MinioFileassociation> result = new List<MinioFileassociation>();
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<MinioFileassociation>("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<IDbContext>("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<MinioStoragePath>("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<MinioStoragePath>("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<MinioStoragePath>(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<MinioStoragePath>(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<MinioStoragePath> datebase = new List<MinioStoragePath>();
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<MinioStoragePath>(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
/// </summary>
/// <param name="master">需要删除的数据</param>
[HttpPost, Route("RemoveStoragePath")]
public RequestEntity RemoveStoragePath(IList<MinioStoragePath> master)
public RequestEntity RemoveStoragePath(List<MinioStoragePath> master)
{
RequestEntity request = new RequestEntity();
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";//桶名称
db.BeginTransaction();
db.Delete<MinioStoragePath>(master);
string sql = "";
//db.Delete<MinioStoragePath>(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<MinioStoragePath> date = db.Query<MinioStoragePath>(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;

@ -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
/// <summary>
///minio权限表
/// </summary>
[Serializable, Table("MINIO_AUTHORITY")]
[Serializable, Table("MINIO_AUTHORITY"), JsonObject]
public class MinioAuthority
{
/// <summary>

@ -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
/// <summary>
///文件关联表
/// </summary>
[Serializable, Table("MINIO_FILEASSOCIATION")]
[Serializable, Table("MINIO_FILEASSOCIATION"), JsonObject]
public class MinioFileassociation
{
/// <summary>

@ -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
/// <summary>
///操作日志
/// </summary>
[Serializable, Table("MINIO_OPERATIONLOG")]
[Serializable, Table("MINIO_OPERATIONLOG"), JsonObject]
public class MinioOperationlog
{
/// <summary>

@ -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
/// <summary>
///minio角色权限表
/// </summary>
[Serializable, Table("MINIO_ROLE_PERMISSION")]
[Serializable, Table("MINIO_ROLE_PERMISSION"), JsonObject]
public class MinioRolePermission
{
/// <summary>

@ -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
/// <summary>
///文件文件夹路径表
/// </summary>
[Serializable, Table("MINIO_STORAGE_PATH")]
[Serializable, Table("MINIO_STORAGE_PATH"), JsonObject]
public class MinioStoragePath
{
/// <summary>

@ -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
/// <summary>
///minio用户表
/// </summary>
[Serializable, Table("MINIO_USER")]
[Serializable, Table("MINIO_USER"), JsonObject]
public class MinioUser
{
/// <summary>

Loading…
Cancel
Save