@ -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 ( I List< 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 , i tem. ClearT ime, 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 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
{
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 ) ; //更新文件路径表中的删除状态
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 ;