You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1003 lines
38 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using IBKLinker_Minio.Entity;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Minio;
using System.Net.PeerToPeer;
using System.IO;
using System.Reactive.Linq;
using Minio.DataModel;
using System.Security.AccessControl;
using System.IO.Pipes;
using System.Net.Mime;
using IBKLinker_Minio.Entity.MinioController;
using SOA.Objects;
using SOA.Persistent;
namespace IBKLinker_Minio.Controller.MinioController
{
/// <summary>
/// 作者:孙亮
/// 编写时间2023-08-15
/// 编写内容mino上传接口
/// </summary>
[RoutePrefix("minio/minioapi")]
public class MinioApiController : ApiController
{
/// <summary>
/// 调用log日志文件接口
/// </summary>
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// minio数据库创建文件夹接口
/// </summary>
[HttpPost, Route("CreateFolder")]
public RequestEntity CreateFolder(List<CreateFolderInputModel> cert)
{
RequestEntity result = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
#region minio创建文件夹
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//连接所需minio所在地址、登录名、密码
//取前端发送路径(或单一文件夹名称)
var folderName = cert[0].Path + "/";
//桶名称
string buckname = "dayetegang";
minio.PutObjectAsync(buckname, folderName, new MemoryStream(), 0, "application/octet-stream");
#endregion
result.code = "0";
result.msg = "文件夹创建成功";
}
}
catch (Exception ex)
{
result.msg = ex.ToString();
result.code = "1";
logger.InfoFormat(ex.ToString());
}
return result;
}
/// <summary>
/// minio数据库删除文件夹接口
/// </summary>
[HttpPost, Route("RemoveFolder")]
public RequestEntity RemoveFolder(List<RemoveFolderInputModel> cert)
{
RequestEntity result = new RequestEntity();
try
{
#region minio删除文件夹
MinioClient minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");
string buckname = "dayetegang";//桶名称
string state = "";//提示状态
var folderName = ""; //文件或文件夹
if (cert[0].Type.ToString() == "0")//判断是删除文件加还是文件 0为文件夹 1为文件
{
folderName = cert[0].Path.ToString() + "/";//文件夹后缀需要加上/
state = "文件夹";
}
else
{
folderName = cert[0].Path.ToString();//文件不需要后缀/
state = "文件";
}
minio.RemoveObjectAsync(buckname, folderName);
#endregion
result.code = "0";
result.msg = state + "删除成功!";
}
catch (Exception ex)
{
result.msg = ex.ToString();
result.code = "1";
logger.InfoFormat(ex.ToString());
}
return result;
}
/// <summary>
/// minio数据库查询文件夹接口
/// </summary>
[HttpPost, Route("QueryFolder")]
public RequestEntity QueryFolder(string fileneme)
{
RequestEntity result = new RequestEntity();
try
{
#region minio查询文件夹
var minio = new MinioClient("127.0.0.1:9000", "minioadmin", "minioadmin");
//var folderName = fileneme + "/";
string bucketName = "dayetegang";
// 获取存储桶中的所有对象
var objects = minio.ListObjectsAsync(bucketName, null, true);
// 存储文件夹名称的集合
var folders = new HashSet<string>();
var stream = new MemoryStream();
// 设置链接的有效期(以秒为单位)
int expiresInt = 3600; // 1小时
// 设置响应内容类型为 "application/pdf"
var presignedUrl = minio.PresignedGetObjectAsync(bucketName, fileneme, expiresInt: expiresInt);
#endregion
result.code = "0";
result.msg = "文件夹删除成功";
}
catch (Exception ex)
{
result.msg = ex.ToString();
result.code = "1";
logger.InfoFormat(ex.ToString());
}
return result;
}
/// <summary>
/// minio数据库上传文件接口
/// </summary>
[HttpPost, Route("FileUpload")]
public RequestEntity FileUpload(List<FileUploadInputModel> cert)
{
RequestEntity result = new RequestEntity();
try
{
var minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");
string bucketName = "dayetegang";
int a = 0;
for (int i = 0; i < cert[0].FileData.Length; i++)
{
var contentType = "application/" + cert[0].FileType[i].ToString();
string strBase64 = cert[0].FileData[i].Split(',')[1];//取文件base64流数据
byte[] bt = Convert.FromBase64String(strBase64);//获取html base64
minio.PutObjectAsync(bucketName, cert[0].StoragePath.ToString(), new MemoryStream(bt), bt.Length, contentType);
a++;
}
result.code = "0";
result.msg = "共计成功上传" + a + "个文件!";
}
catch (Exception ex)
{
result.code = "1";
result.msg = ex.ToString();
}
return result;
}
#region minio权限表
/// <summary>
/// 添加minio权限表
/// </summary>
/// <param name="minioAuthority">权限表</param>
[HttpPost, Route("AddAuthority")]
public RequestEntity AddAuthority(MinioAuthority minioAuthority)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长的值赋值给自增长主键pk
minioAuthority.Id = getPk("S_MINIO_AUTHORITY", "MINIO_AUTHORITY");
///给创建时间赋值
minioAuthority.CreatorTime = DateTime.Now;
///把需要添加的数据同步到数据库
db.Insert<MinioAuthority>(minioAuthority);
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_AUTHORITYminio权限表添加数据失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 修改minio权限表
/// </summary>
/// <param name="data">修改数据</param>
[HttpPost, Route("UpdateAuthority")]
public RequestEntity UpdateAuthority(IList<MinioAuthority> data)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
try
{
///启动事务
db.BeginTransaction();
///给修改时间赋值
DateTime time = DateTime.Now;
db.Update<MinioAuthority>(data);
db.Commit();
request.code = "0";
}
catch (Exception ex)
{
request.code = "1";
db.Rollback();
///把错误日志写到日志文件
logger.ErrorFormat("主表:MINIO_AUTHORITY修改minio权限表失败错误原因:{0}", ex);
}
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_AUTHORITY创建数据库连接对象错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 删除minio权限表
/// </summary>
/// <param name="master">需要删除的数据</param>
[HttpPost, Route("RemoveAuthority")]
public RequestEntity RemoveAuthority(IList<MinioAuthority> master)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
db.BeginTransaction();
db.Delete<MinioAuthority>(master);
db.Commit();
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_AUTHORITY创建数据库连接对象失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 查询minio权限表
/// </summary>
/// <returns></returns>
[HttpPost, Route("GetAuthority")]
public RequestEntity GetAuthority(MinioAuthority minioAuthority)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
string sql = string.Empty;
IList<MinioAuthority> result = new List<MinioAuthority>();
if (!string.IsNullOrEmpty(minioAuthority.LimitsAuthorityId.ToString()))
{
sql += " and LIMITS_AUTHORITY_ID ='" + minioAuthority.LimitsAuthorityId + "'";
}
request.data = db.Query<MinioAuthority>("select * from MINIO_AUTHORITY where 1=1 " + sql + " ORDER BY PK");
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_AUTHORITY查询minio权限表失败错误原因:{0}", ex);
}
return request;
}
#endregion
#region minio角色表
/// <summary>
/// 添加minio角色表
/// </summary>
/// <param name="minioUser">角色表</param>
[HttpPost, Route("AddUSER")]
public RequestEntity AddUSER(MinioUser minioUser)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长的值赋值给自增长主键pk
minioUser.UserId = getPk("S_MINIO_USER", "MINIO_USER");
///给创建时间赋值
minioUser.CreatorTime = DateTime.Now;
///把需要添加的数据同步到数据库
db.Insert<MinioUser>(minioUser);
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_USERminio角色表添加数据失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 修改minio角色表
/// </summary>
/// <param name="data">修改数据</param>
[HttpPost, Route("UpdateUSER")]
public RequestEntity UpdateUSER(IList<MinioUser> data)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
try
{
///启动事务
db.BeginTransaction();
///给修改时间赋值
DateTime time = DateTime.Now;
db.Update<MinioUser>(data);
db.Commit();
request.code = "0";
}
catch (Exception ex)
{
request.code = "1";
db.Rollback();
///把错误日志写到日志文件
logger.ErrorFormat("主表:MINIO_USER修改minio角色表失败错误原因:{0}", ex);
}
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_USER创建数据库连接对象错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 删除minio角色表
/// </summary>
/// <param name="master">需要删除的数据</param>
[HttpPost, Route("RemoveUSER")]
public RequestEntity RemoveUSER(IList<MinioUser> master)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
db.BeginTransaction();
db.Delete<MinioUser>(master);
db.Commit();
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_USER创建数据库连接对象失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 查询minio角色表
/// </summary>
/// <returns></returns>
[HttpPost, Route("GetUSER")]
public RequestEntity GetUSER(MinioUser minioUser)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
string sql = string.Empty;
IList<MinioUser> result = new List<MinioUser>();
if (!string.IsNullOrEmpty(minioUser.UserName.ToString()))
{
sql += " and USER_NAME ='" + minioUser.UserName + "'";
}
request.data = db.Query<MinioUser>("select * from MINIO_USER where 1=1 " + sql + " ORDER BY PK");
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_USER查询minio角色表失败错误原因:{0}", ex);
}
return request;
}
#endregion
#region minio文件关联表
/// <summary>
/// 添加minio角色表
/// </summary>
/// <param name="minioFileassociation">文件关联表</param>
[HttpPost, Route("AddFileassociation")]
public RequestEntity AddFileassociation(MinioFileassociation minioFileassociation)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长的值赋值给自增长主键pk
minioFileassociation.Pk = getPk("S_MINIO_FILEASSOCIATION", "MINIO_FILEASSOCIATION");
///给创建时间赋值
minioFileassociation.CreatorTime = DateTime.Now;
///把需要添加的数据同步到数据库
db.Insert<MinioFileassociation>(minioFileassociation);
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_FILEASSOCIATIONminio文件关联表表添加数据失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 修改minio角色表
/// </summary>
/// <param name="data">修改数据</param>
[HttpPost, Route("UpdateFileassociation")]
public RequestEntity UpdateFileassociation(IList<MinioFileassociation> data)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
try
{
///启动事务
db.BeginTransaction();
///给修改时间赋值
DateTime time = DateTime.Now;
db.Update<MinioFileassociation>(data);
db.Commit();
request.code = "0";
}
catch (Exception ex)
{
request.code = "1";
db.Rollback();
///把错误日志写到日志文件
logger.ErrorFormat("主表:MINIO_FILEASSOCIATION修改minio文件关联表表失败错误原因:{0}", ex);
}
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_FILEASSOCIATION创建数据库连接对象错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 删除minio角色表
/// </summary>
/// <param name="master">需要删除的数据</param>
[HttpPost, Route("RemoveFileassociation")]
public RequestEntity RemoveFileassociation(IList<MinioFileassociation> master)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
db.BeginTransaction();
db.Delete<MinioFileassociation>(master);
db.Commit();
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_FILEASSOCIATION创建数据库连接对象失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 查询minio角色表
/// </summary>
/// <returns></returns>
[HttpPost, Route("GetFileassociation")]
public RequestEntity GetFileassociation(MinioFileassociation minioFileassociation)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
string sql = string.Empty;
IList<MinioFileassociation> result = new List<MinioFileassociation>();
if (!string.IsNullOrEmpty(minioFileassociation.FileName.ToString()))
{
sql += " and FILE_NAME ='" + minioFileassociation.FileName + "'";
}
request.data = db.Query<MinioFileassociation>("select * from MINIO_FILEASSOCIATION where 1=1 " + sql + " ORDER BY PK");
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_FILEASSOCIATION查询minio文件关联表表失败错误原因:{0}", ex);
}
return request;
}
#endregion
#region minio角色权限表
/// <summary>
/// 添加minio角色权限表
/// </summary>
/// <param name="minioRolePermission">minio角色权限表</param>
[HttpPost, Route("AddRolePermission")]
public RequestEntity AddRolePermission(MinioRolePermission minioRolePermission)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长的值赋值给自增长主键pk
minioRolePermission.Pk = getPk("S_MINIO_ROLE_PERMISSION", "MINIO_ROLE_PERMISSION");
///给创建时间赋值
minioRolePermission.CreatorTime = DateTime.Now;
///把需要添加的数据同步到数据库
db.Insert<MinioRolePermission>(minioRolePermission);
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_ROLE_PERMISSIONminio角色权限表添加数据失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 修改minio角色表
/// </summary>
/// <param name="data">修改数据</param>
[HttpPost, Route("UpdateRolePermission")]
public RequestEntity UpdateRolePermission(IList<MinioRolePermission> data)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
try
{
///启动事务
db.BeginTransaction();
///给修改时间赋值
DateTime time = DateTime.Now;
db.Update<MinioRolePermission>(data);
db.Commit();
request.code = "0";
}
catch (Exception ex)
{
request.code = "1";
db.Rollback();
///把错误日志写到日志文件
logger.ErrorFormat("主表:MINIO_ROLE_PERMISSION修改minio角色权限表表失败错误原因:{0}", ex);
}
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_ROLE_PERMISSION创建数据库连接对象错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 删除minio角色表
/// </summary>
/// <param name="master">需要删除的数据</param>
[HttpPost, Route("RemoveRolePermission")]
public RequestEntity RemoveRolePermission(IList<MinioRolePermission> master)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
db.BeginTransaction();
db.Delete<MinioRolePermission>(master);
db.Commit();
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_ROLE_PERMISSION创建数据库连接对象失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 查询minio角色表
/// </summary>
/// <returns></returns>
[HttpPost, Route("GetRolePermission")]
public RequestEntity GetRolePermission(MinioRolePermission minioRolePermission)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
string sql = string.Empty;
IList<MinioRolePermission> result = new List<MinioRolePermission>();
if (!string.IsNullOrEmpty(minioRolePermission.Id.ToString()))
{
sql += " and ID =" + minioRolePermission.Id;
}
request.data = db.Query<MinioRolePermission>("select * from MINIO_ROLE_PERMISSION where 1=1 " + sql + " ORDER BY PK");
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_ROLE_PERMISSION查询minio角色权限表失败错误原因:{0}", ex);
}
return request;
}
#endregion
#region minio文件文件夹路径表
/// <summary>
/// 添加minio文件文件夹路径表
/// </summary>
/// <param name="minioStoragePath">minio文件文件夹路径表</param>
[HttpPost, Route("AddStoragePath")]
public RequestEntity AddStoragePath(MinioStoragePath minioStoragePath)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长的值赋值给自增长主键pk
minioStoragePath.Pk = getPk("S_MINIO_STORAGE_PATH", "MINIO_STORAGE_PATH");
///给创建时间赋值
minioStoragePath.CreatorTime = DateTime.Now;
///把需要添加的数据同步到数据库
db.Insert<MinioStoragePath>(minioStoragePath);
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_STORAGE_PATHminio文件文件夹路径表添加数据失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 修改minio文件文件夹路径
/// </summary>
/// <param name="data">修改数据</param>
[HttpPost, Route("UpdateStoragePath")]
public RequestEntity UpdateStoragePath(IList<MinioStoragePath> data)
{
RequestEntity request = new RequestEntity();
try
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
try
{
///启动事务
db.BeginTransaction();
///给修改时间赋值
DateTime time = DateTime.Now;
db.Update<MinioStoragePath>(data);
db.Commit();
request.code = "0";
}
catch (Exception ex)
{
request.code = "1";
db.Rollback();
///把错误日志写到日志文件
logger.ErrorFormat("主表:MINIO_STORAGE_PATH修改minio文件文件夹路径表失败错误原因:{0}", ex);
}
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_STORAGE_PATH创建数据库连接对象错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 删除minio文件文件夹路径表
/// </summary>
/// <param name="master">需要删除的数据</param>
[HttpPost, Route("RemoveStoragePath")]
public RequestEntity RemoveStoragePath(IList<MinioStoragePath> master)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
db.BeginTransaction();
db.Delete<MinioStoragePath>(master);
db.Commit();
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_ROLE_PERMISSION创建数据库连接对象失败错误原因:{0}", ex);
}
return request;
}
/// <summary>
/// 查询minio文件文件夹路径表
/// </summary>
/// <returns></returns>
[HttpPost, Route("GetStoragePath")]
public RequestEntity GetStoragePath(MinioStoragePath minioStoragePath)
{
RequestEntity request = new RequestEntity();
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
string sql = string.Empty;
IList<MinioStoragePath> result = new List<MinioStoragePath>();
if (!string.IsNullOrEmpty(minioStoragePath.FileName.ToString()))
{
sql += " and FILE_NAME ='" + minioStoragePath.FileName + "'";
}
request.data = db.Query<MinioStoragePath>("select * from MINIO_STORAGE_PATH where 1=1 " + sql + " ORDER BY PK");
request.code = "0";
}
}
catch (Exception ex)
{
request.code = "1";
logger.ErrorFormat("主表:MINIO_STORAGE_PATH查询minio文件文件夹路径表失败错误原因:{0}", ex);
}
return request;
}
#endregion
#region minio文件菜单递归和权限判断
/// <summary>
/// 根据ID查询子菜单
/// </summary>
/// <param name="PK"></param>
/// <returns></returns>
[HttpPost, Route("GetMenuTree")]
public List<MinioStoragePath> GetMenuTree(string PK = "")
{
List<MinioStoragePath> date = new List<MinioStoragePath>();
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
string sql = string.Empty;
if (!string.IsNullOrEmpty(PK))
{
sql += " and UPK =" + int.Parse(PK);
}
date = db.Query<MinioStoragePath>("select * from MINIO_STORAGE_PATH where 1=1 " + sql + " ORDER BY PK").ToList();
}
return date;
}
/// <summary>
/// 获取根目录和根目录下一级得菜单信息
/// </summary>
/// <returns></returns>
[HttpPost, Route("GetRecursion")]
public RequestEntity GetRecursion()
{
RequestEntity request = new RequestEntity();
try
{
//拿到根目录
List<RequstStoragePath> requstStoragePaths = new List<RequstStoragePath>();
List<MinioStoragePath> date = new List<MinioStoragePath>();
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
string sql = string.Empty;
date = db.Query<MinioStoragePath>("select * from MINIO_STORAGE_PATH ORDER BY PK").ToList();
}
if (date.Count > 0)
{
foreach (var item in date)
{
RequstStoragePath model = new RequstStoragePath();
model.Pk = item.Pk;
model.FileName = item.FileName;
model.FilePate = item.FilePate;
model.FileType = item.FileType;
model.requstStoragePaths = new List<StoragePath>();
List<MinioStoragePath> ds = GetMenuTree(item.Pk.ToString());
foreach (var items in ds)
{
StoragePath models = new StoragePath();
models.Pk = items.Pk;
models.FileName = items.FileName;
models.FilePate = items.FilePate;
models.FileType = items.FileType;
model.requstStoragePaths.Add(models);
}
requstStoragePaths.Add(model);
}
}
request.data = requstStoragePaths;
request.code = "0";
}
catch (Exception)
{
request.code = "1";
throw;
}
return request;
}
/// <summary>
/// 权限查询
/// </summary>
/// <param name="UserID"></param>
/// <param name="FileName"></param>
/// <param name="EmpowerType"></param>
/// <returns></returns>
[HttpPost, Route("GetEmpower")]
public bool GetEmpower(string UserID, string FileName, string EmpowerType)
{
bool Empower=false;
//用户ID文件ID文件操作类型查看/移动)
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
string sql = string.Empty;
if (!string.IsNullOrEmpty(UserID))
{
sql += "a.USER_ID=" + UserID;
}
if (!string.IsNullOrEmpty(FileName))
{
sql += "d.File_Name='" + FileName + "'";
}
if (!string.IsNullOrEmpty(FileName))
{
sql += "b." + EmpowerType + "=1";
}
List<MinioUser> dt = db.Query<MinioUser>("select a.* from minio_user a left join minio_role_permission b on a.role_id=b.id left join minio_authority c on b.limits_authority_id=c.limits_authority_id left join minio_storage_path d on c.file_id=d.pk where 1=1 " + sql + " ORDER BY a.creator_time").ToList();
if (dt.Count > 0)
{
Empower = true;
}
}
//通过用户ID查询用户得角色ID
//判断当前角色是否有操作权限
//通过角色ID查询用户有权限得文件夹
return Empower;
}
#endregion
#region 公用方法
/// <summary>
/// 矫正pk值
/// </summary>
/// <param name="sequenceName"></param>
/// <param name="tableName"></param>
/// <returns></returns>
public Int32 getPk(String sequenceName, String tableName)
{
///创建数据库连接上下文对象
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
///拿到表自增长序列最大pk值
int pk_SequenceCurrentMax = Convert.ToInt32(db.QueryScalar("select " + sequenceName + ".nextval from dual"));
///拿到表目前最大pk值
Object pk_TableCurrentMaxObj = db.QueryScalar("select t.pk from " + tableName + " t where rownum <=1 order by t.pk desc");
int pk_TableCurrentMax = pk_SequenceCurrentMax;
//如果表最大值查询结果不为空进行对比,
if (pk_TableCurrentMaxObj != null)
{
pk_TableCurrentMax = Convert.ToInt32(pk_TableCurrentMaxObj);
//拿到表中最大值和序列最大值之间的差值
int num_BetweenTableSequence = pk_TableCurrentMax - pk_SequenceCurrentMax + 1;
//更改序列递增规则使下一次拿到的序列号比表中最大pk大1
db.QueryScalar("alter sequence " + sequenceName + " increment by " + num_BetweenTableSequence.ToString());
//执行nexval拿到下一个序列号
pk_TableCurrentMax = Convert.ToInt32(db.QueryScalar("select " + sequenceName + ".nextval from dual"));
//更改序列递增规则为每次递增一个。
db.QueryScalar("alter sequence " + sequenceName + " increment by 1");
}
return pk_TableCurrentMax;
}
}
#endregion
}
}