修改文件上传中因移动文件导致的关联关系路径及层级错误问题

master
孙亮 8 months ago
parent a622f0a9cb
commit a68f13316a

@ -965,6 +965,7 @@ namespace IBKLinker_Minio.Controller.MinioController
///给修改时间赋值
DateTime time = DateTime.Now;//取当前时间
MinioStoragePath date = new MinioStoragePath();
IList<MinioFileassociation> UdpMFdata = new List<MinioFileassociation>();
List<MinioStoragePath> datelist = new List<MinioStoragePath>();
string Operate = "";//操作
if (data.Count > 0)
@ -985,6 +986,27 @@ namespace IBKLinker_Minio.Controller.MinioController
date.ClearFlag = "0";//删除标记 0未删除 1删除
date.DocumentType = item.DocumentType;//文件种类
date.Version = item.Version;//版本
#region 判断修改关联信息
IList<MinioFileassociation> SelMFdata = new List<MinioFileassociation>();
SelMFdata = db.Query<MinioFileassociation>("select * from MINIO_FILEASSOCIATION where 1=1 and (FILE_PK='" +item.Pk + "' or ASSOCIATION_FILE_PK='" + item.Pk + "')");//查询修改路径的文件关联关系
if (SelMFdata.Count >0) //如果有数据
{
foreach (var itemmf in SelMFdata)
{
if (itemmf.FilePk == item.Pk) //判断是关联的文件
{
itemmf.FilePath = item.FilePath;//替换文件路径
itemmf.FileLevel = item.FileLevel;//替换文件层级
}
if (itemmf.AssociationFilePk == item.Pk) //判断是被关联的文件
{
itemmf.AssociationFilePath = item.FilePath;//替换文件路径
itemmf.AssociationFileLevel = item.FileLevel;//替换文件层级
}
UdpMFdata.Add(itemmf);//写入list
}
}
#endregion
if (item.Bate64 != null)//如果是修改文件
{
var contentType = item.FileCategory;
@ -1008,6 +1030,10 @@ namespace IBKLinker_Minio.Controller.MinioController
}
if (datelist != null)
{
if (UdpMFdata.Count > 0)
{
db.Update<MinioFileassociation>(UdpMFdata);
}
db.Update<MinioStoragePath>(datelist);
db.Commit();//提交事务
request.code = "0";
@ -1577,7 +1603,7 @@ namespace IBKLinker_Minio.Controller.MinioController
/// 接收切片
/// </summary>
[HttpPost, Route("SliceUpload")]
public async Task<RequestEntity> SliceUploadAsync()//string FileName,string SliceQuantity,string FileNum, string FileId,string Size,string Upk, string FileType, string FilePath, string CreatorUser, string DownloadNum, string FileLevel, string FileCategory
public async Task<RequestEntity> SliceUploadAsync()
{
Dictionary<string, string> dic = new Dictionary<string, string>();
SliceUploadModel master = new SliceUploadModel();
@ -1587,7 +1613,7 @@ namespace IBKLinker_Minio.Controller.MinioController
var multipartMemoryStreamProvider = await Request.Content.ReadAsMultipartAsync();
foreach (var content in multipartMemoryStreamProvider.Contents)
{
if (!string.IsNullOrEmpty(content.Headers.ContentDisposition.FileName))
if (!string.IsNullOrEmpty(content.Headers.ContentDisposition.FileName))//判断是否是文件
{
using (Stream stream = await content.ReadAsStreamAsync())
{
@ -1606,26 +1632,26 @@ namespace IBKLinker_Minio.Controller.MinioController
}
}
}
else
else//否则就为其他字段
{
string val = await content.ReadAsStringAsync();
dic.Add(content.Headers.ContentDisposition.Name.Replace("\"", ""), System.Web.HttpUtility.UrlDecode(val));
dic.Add(content.Headers.ContentDisposition.Name.Replace("\"", ""), System.Web.HttpUtility.UrlDecode(val));//写入缓存变量中
}
}
#region 字段赋值
master.FileName = dic["FileName"].ToString();//文件名称
master.SliceQuantity = dic["SliceQuantity"].ToString();//切片总数量
master.FileNum = dic["FileNum"].ToString();
master.FileId = dic["FileId"].ToString();
master.Upk = Convert.ToInt32( dic["Upk"].ToString());
master.FileType = Convert.ToInt32(dic["FileType"].ToString());
master.FilePath = dic["FilePath"].ToString();
master.CreatorUser = dic["CreatorUser"].ToString();
master.DownloadNum = Convert.ToInt32(dic["DownloadNum"].ToString());
master.FileLevel = Convert.ToInt32(dic["FileLevel"].ToString());
master.FileCategory = dic["FileCategory"].ToString();
SliceUploadData.Add(master);
master.FileNum = dic["FileNum"].ToString();//文件序号
master.FileId = dic["FileId"].ToString();//文件唯一标识
master.Upk = Convert.ToInt32( dic["Upk"].ToString());//子文件夹的父ID
master.FileType = Convert.ToInt32(dic["FileType"].ToString());//文件类型
master.FilePath = dic["FilePath"].ToString();//文件路径
master.CreatorUser = dic["CreatorUser"].ToString();//创建者
master.DownloadNum = Convert.ToInt32(dic["DownloadNum"].ToString());//下载次数
master.FileLevel = Convert.ToInt32(dic["FileLevel"].ToString());//层级
master.FileCategory = dic["FileCategory"].ToString();//文件格式
#endregion
SliceUploadData.Add(master);//写入数据到全局变量缓存中
request.code = "0";
request.msg = "已接收切片";
}
@ -1657,7 +1683,6 @@ namespace IBKLinker_Minio.Controller.MinioController
minio.MakeBucketAsync(BuckName);//创建桶
}
#endregion
string base64 = "";
string Operate = "";//操作
MinioStoragePath date = new MinioStoragePath();
var file = SliceUploadData.Where(a => a.FileId == master.FileId).OrderBy(a => a.FileNum).ToList();//查询已经传完的唯一标识数据并以切片顺序排序
@ -1671,7 +1696,6 @@ namespace IBKLinker_Minio.Controller.MinioController
combinedList.AddRange(item.FileBase64);
}
var contentType = file[0].FileCategory;//获取文件类型
//byte[] bt = Convert.FromBase64String(base64);//获取html base64
byte[] bt = combinedList.ToArray();
var uploadTask = minio.PutObjectAsync(BuckName, "/" + file[0].FileName, new MemoryStream(bt), bt.Length, contentType);//上传文件到minio数据库
uploadTask.Wait();
@ -1738,9 +1762,10 @@ namespace IBKLinker_Minio.Controller.MinioController
using (IDbContext filedb = ObjectContainer.GetObject<IDbContext>("filedb"))
{
string sql = "";
data = db.Query<MinioStoragePath>("select * from minio_storage_path where file_type='1' and upk='" + master + "' order by CREATOR_TIME asc").ToList();
data = db.Query<MinioStoragePath>("select * from minio_storage_path where upk='" + master + "' order by CREATOR_TIME asc").ToList();
foreach (var item in data)
{
bool Asstion = true;//定义是否执行关联
//sql = string.Format("select g.title from ASSETENTRY g where entryid in (select entryid2 from ASSETLINK t where entryid1 = (select t.entryid from ASSETENTRY t ,(select p.fileid from DLSYNC p where p.name = '{0}' and (p.event='add' or p.event = 'update') )o where t.classpk = o.fileid))", item.FileName);
sql = string.Format("select g.title,g.username,g.createdate from ASSETENTRY g where entryid in (select entryid2 from ASSETLINK t where entryid1 = (select t.entryid from ASSETENTRY t ,(select p.fileid from DLSYNC p where p.name = '{0}' and (p.event='add' or p.event = 'update') and p.version='{1}' and ROWNUM = 1 order by p.version desc)o where t.classpk = o.fileid)) ", item.FileName, item.Version);
dt = filedb.Query(sql);
@ -1752,80 +1777,43 @@ namespace IBKLinker_Minio.Controller.MinioController
datan = db.Query<MinioStoragePath>("select * from minio_storage_path where file_name='" + dt.Rows[i]["title"].ToString() + "'").ToList();
if (datan.Count != 0)
{
if (item.DocumentType == "1")
IList<MinioFileassociation> SelMFdata = new List<MinioFileassociation>();
SelMFdata = db.Query<MinioFileassociation>("select * from MINIO_FILEASSOCIATION where 1=1 and (FILE_PK='" + item.Pk + "' or ASSOCIATION_FILE_PK='" + item.Pk + "')");
if (SelMFdata.Count > 0)
{
if (datan[0].DocumentType == "2" || datan[0].DocumentType == "4")
foreach (var ca in SelMFdata)
{
dc.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_FILEASSOCIATION.nextval from dual"));
dc.FilePk = item.Pk;
dc.FileName = item.FileName;
dc.CreatorUser = dt.Rows[i]["username"].ToString().Replace(" ", "");
dc.CreatorTime = dt.Rows[i]["createdate"].ToString().ToDateTime();
dc.FilePath = item.FilePath;
dc.FileLevel = item.FileLevel;
dc.DownloadNum = item.DownloadNum;
dc.FileType = item.FileType;
dc.Version = item.Version;
dc.AssociationFilePk = datan[0].Pk;
dc.AssociationFileName = datan[0].FileName;
dc.AssociationFilePath = datan[0].FilePath;
dc.AssociationFileType = datan[0].FileType;
dc.AssociationFileLevel = datan[0].FileLevel;
dc.AssociationDownloadNum = datan[0].DownloadNum;
dc.AssociationVersion = datan[0].Version;
mfcion.Add(dc);
if (item.Pk == ca.FilePk && datan[0].Pk == ca.AssociationFilePk) //如果当前要关联的pk 等于已有的关联pk 被关联pk 等于已有的被关联pk
{
Asstion = false;
}
if (item.Pk == ca.AssociationFilePk && datan[0].Pk == ca.FilePk) //如果当前要关联的pk 等于已有的被关联pk 被关联pk 等于已有的关联pk
{
Asstion = false;
}
}
}
if (item.DocumentType == "2")
if (Asstion)
{
if (datan[0].DocumentType == "3" || datan[0].DocumentType == "4")
{
dc.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_FILEASSOCIATION.nextval from dual"));
dc.FilePk = item.Pk;
dc.FileName = item.FileName;
dc.CreatorUser = dt.Rows[i]["username"].ToString().Replace(" ", "");
dc.CreatorTime = dt.Rows[i]["createdate"].ToString().ToDateTime();
dc.FilePath = item.FilePath;
dc.FileLevel = item.FileLevel;
dc.DownloadNum = item.DownloadNum;
dc.FileType = item.FileType;
dc.Version = item.Version;
dc.AssociationFilePk = datan[0].Pk;
dc.AssociationFileName = datan[0].FileName;
dc.AssociationFilePath = datan[0].FilePath;
dc.AssociationFileType = datan[0].FileType;
dc.AssociationFileLevel = datan[0].FileLevel;
dc.AssociationDownloadNum = datan[0].DownloadNum;
dc.AssociationVersion = datan[0].Version;
mfcion.Add(dc);
}
}
if (item.DocumentType == "3")
{
if (datan[0].DocumentType == "4")
{
dc.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_FILEASSOCIATION.nextval from dual"));
dc.FilePk = item.Pk;
dc.FileName = item.FileName;
dc.CreatorUser = dt.Rows[i]["username"].ToString().Replace(" ", "");
dc.CreatorTime = dt.Rows[i]["createdate"].ToString().ToDateTime();
dc.FilePath = item.FilePath;
dc.FileLevel = item.FileLevel;
dc.DownloadNum = item.DownloadNum;
dc.FileType = item.FileType;
dc.Version = item.Version;
dc.AssociationFilePk = datan[0].Pk;
dc.AssociationFileName = datan[0].FileName;
dc.AssociationFilePath = datan[0].FilePath;
dc.AssociationFileType = datan[0].FileType;
dc.AssociationFileLevel = datan[0].FileLevel;
dc.AssociationDownloadNum = datan[0].DownloadNum;
dc.AssociationVersion = datan[0].Version;
mfcion.Add(dc);
}
dc.Pk = Convert.ToInt32(db.QueryScalar("select S_MINIO_FILEASSOCIATION.nextval from dual"));
dc.FilePk = item.Pk;
dc.FileName = item.FileName;
dc.CreatorUser = dt.Rows[i]["username"].ToString().Replace(" ", "");
dc.CreatorTime = dt.Rows[i]["createdate"].ToString().ToDateTime();
dc.FilePath = item.FilePath;
dc.FileLevel = item.FileLevel;
dc.DownloadNum = item.DownloadNum;
dc.FileType = item.FileType;
dc.Version = item.Version;
dc.AssociationFilePk = datan[0].Pk;
dc.AssociationFileName = datan[0].FileName;
dc.AssociationFilePath = datan[0].FilePath;
dc.AssociationFileType = datan[0].FileType;
dc.AssociationFileLevel = datan[0].FileLevel;
dc.AssociationDownloadNum = datan[0].DownloadNum;
dc.AssociationVersion = datan[0].Version;
mfcion.Add(dc);
}
}
}
@ -1841,10 +1829,10 @@ namespace IBKLinker_Minio.Controller.MinioController
#region
[HttpPost, Route("UdpDlsyncFile")]
public RequestEntity UdpDlsyncFile(string master,string parentfolderid, string DocumentType)
public RequestEntity UdpDlsyncFile(string master,string parentfolderid)
{
RequestEntity request = new RequestEntity();//定义返回集合
List<MinioStoragePath> data = new List<MinioStoragePath>();//定义输出下载的list
//List<MinioStoragePath> data = new List<MinioStoragePath>();//定义输出下载的list
List<MinioStoragePath> newdata = new List<MinioStoragePath>();//定义输出下载的list
List<Dlsync> dldata = new List<Dlsync>();//定义输出下载的list
List<MinioStoragePath> datan = new List<MinioStoragePath>();
@ -1858,12 +1846,12 @@ namespace IBKLinker_Minio.Controller.MinioController
using (IDbContext filedb = ObjectContainer.GetObject<IDbContext>("filedb"))
{
string sql = "";
data = db.Query<MinioStoragePath>("select * from minio_storage_path where file_type='1' and upk='" + master + "' order by CREATOR_TIME desc").ToList();
//data = db.Query<MinioStoragePath>("select * from minio_storage_path where upk='" + master + "' order by CREATOR_TIME desc").ToList();
//foreach (var item in data)
//{
//sql = string.Format("select g.title from ASSETENTRY g where entryid in (select entryid2 from ASSETLINK t where entryid1 = (select t.entryid from ASSETENTRY t ,(select p.fileid from DLSYNC p where p.name = '{0}' and (p.event='add' or p.event = 'update') )o where t.classpk = o.fileid))", item.FileName);
sql = string.Format("select * from DLSYNC where parentfolderid='{0}' and (event='update' or event='add') ", parentfolderid, data[0].CreatorTime);
sql = string.Format("select * from DLSYNC where parentfolderid='{0}' and (event='update' or event='add') ", parentfolderid);
dt = filedb.Query(sql);
string sel = string.Format("select * from minio_storage_path where pk='{0}'", master); ;
dta = db.Query(sel);
@ -1888,7 +1876,6 @@ namespace IBKLinker_Minio.Controller.MinioController
dc.FileLevel = Convert.ToInt32( dta.Rows[0]["FILE_LEVEL"].ToString())+1;
dc.ModifyTime = mtime.ToDateTime();
dc.ClearFlag = "0";
dc.DocumentType = DocumentType;
dc.Version = dt.Rows[i]["VERSION"].ToString();
newdata.Add(dc);
}

Loading…
Cancel
Save