增加上传文件或新建文件夹重复名称判断

master
孙亮 10 months ago
parent 3c61328e84
commit e13920c21c

@ -681,9 +681,21 @@ namespace IBKLinker_Minio.Controller.MinioController
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//连接所需minio所在地址、登录名、密码 MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//连接所需minio所在地址、登录名、密码
string buckname = "dayetegang";//桶名称 string buckname = "dayetegang";//桶名称
List<MinioStoragePath> date = new List<MinioStoragePath>(); List<MinioStoragePath> date = new List<MinioStoragePath>();
List<MinioStoragePath> checkdatelist = new List<MinioStoragePath>();
string RecordFileName = "";//重复文件名称记录
///创建数据库连接上下文对象 ///创建数据库连接上下文对象
db.BeginTransaction();//启动事务 db.BeginTransaction();//启动事务
if (minioStoragePath != null) if (minioStoragePath != null)
{
foreach (var items in minioStoragePath) //先循环接收数据
{
checkdatelist = db.Query<MinioStoragePath>("select t.FILE_NAME from MINIO_STORAGE_PATH where 1=1 and FILE_NAME='"+items.FileName+ "' and UPK='"+items.Upk+"'").ToList();//查询上传的文件或新建的文件夹在当前文件夹下是否有重复存在
if (checkdatelist.Count >0) //如果有
{
RecordFileName += items.FileName +",";//记录名称
}
}
if (RecordFileName == null)//如果没有正常上传
{ {
foreach (var item in minioStoragePath) foreach (var item in minioStoragePath)
{ {
@ -761,10 +773,16 @@ namespace IBKLinker_Minio.Controller.MinioController
else else
{ {
request.msg = "文件上传失败,请检查文件是否正确!"; request.msg = "文件上传失败,请检查文件是否正确!";
request.code = "0"; request.code = "1";
}
} }
} }
} }
else
{
request.msg = "文件上传失败,其中" + RecordFileName +"在此文件夹已经存在!";
request.code = "1";
}
db.Commit(); db.Commit();
} }
} }
@ -1102,9 +1120,9 @@ namespace IBKLinker_Minio.Controller.MinioController
[HttpPost, Route("FileDownload")] [HttpPost, Route("FileDownload")]
public RequestEntity FileDownload(List<MinioStoragePath> minioStoragePath) public RequestEntity FileDownload(List<MinioStoragePath> minioStoragePath)
{ {
MinioBusinessLogic bb = new MinioBusinessLogic(); MinioBusinessLogic bb = new MinioBusinessLogic();//定义业务逻辑方法
RequestEntity request = new RequestEntity(); RequestEntity request = new RequestEntity();//定义返回集合
MinioStoragePath data = new MinioStoragePath(); List<MinioStoragePath> data = new List<MinioStoragePath>();//定义输出下载的list
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db")) using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{ {
try try
@ -1113,20 +1131,21 @@ namespace IBKLinker_Minio.Controller.MinioController
{ {
foreach (var item in minioStoragePath) foreach (var item in minioStoragePath)
{ {
MinioStoragePath date = new MinioStoragePath();//定义单条返回数据
var minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin"); var minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//链接minio数据库
string bucketName = "dayetegang"; string bucketName = "dayetegang";
var uploadTask = bb.Download(bucketName, item.FileName);//异步取base64 var uploadTask = bb.Download(bucketName, item.FileName);//异步取base64
uploadTask.Wait();//等待取值 uploadTask.Wait();//等待取值
if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted) //判读是否有数值 if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted) //判读是否有数值
{ {
data.Bate64 = uploadTask.Result; date.Bate64 = uploadTask.Result;//赋值流文件
data.FileName = item.FileName; date.FileName = item.FileName;//赋值文件名称
data.Add(date);
if (item.OperationType == "0") //操作类型为下载 if (item.OperationType == "0") //操作类型为下载
{ {
int DownloadNum = item.DownloadNum + 1; int DownloadNum = item.DownloadNum + 1;//将下载次数加一
string sql = "update MINIO_STORAGE_PATH set DOWNLOAD_NUM='" + DownloadNum + "' where pk='" + item.Pk + "'"; string sql = "update MINIO_STORAGE_PATH set DOWNLOAD_NUM='" + DownloadNum + "' where pk='" + item.Pk + "'";
db.Execute(sql); db.Execute(sql);//更新下载次数
} }
request.code = "0"; request.code = "0";
} }
@ -1138,7 +1157,7 @@ namespace IBKLinker_Minio.Controller.MinioController
} }
if (data != null) if (data != null)
{ {
request.data = data; request.data = data;//返回数据
} }
} }
else else
@ -1158,11 +1177,15 @@ namespace IBKLinker_Minio.Controller.MinioController
return request; return request;
} }
#endregion #endregion
#region 标准清单 #region 标准清单
/// <summary>
/// 标准清单导出接口
/// </summary>
[HttpPost, Route("StandardListGeneration")] [HttpPost, Route("StandardListGeneration")]
public HttpResponseMessage StandardListGeneration(StandardListGenerationModel master) public HttpResponseMessage StandardListGeneration(StandardListGenerationModel master)
{ {
RequestEntity request = new RequestEntity(); RequestEntity request = new RequestEntity();//定义返回集合
IList<MinioStoragePath> date = new List<MinioStoragePath>(); IList<MinioStoragePath> date = new List<MinioStoragePath>();
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db")) using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
@ -1321,6 +1344,7 @@ namespace IBKLinker_Minio.Controller.MinioController
return result; return result;
} }
#endregion #endregion
#region 公用方法 #region 公用方法
/// <summary> /// <summary>
/// 矫正pk值 /// 矫正pk值

Loading…
Cancel
Save