From b3309e2fef84ef814741033531b8f4a8bf2eb45c Mon Sep 17 00:00:00 2001
From: wyw <571921741@qq.com>
Date: Fri, 26 Dec 2025 13:48:14 +0800
Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=AE=8C=E5=96=84=20=20FilePathHead?=
=?UTF-8?q?=20=20=E4=BD=BF=E5=AF=B9=E5=BA=94=E7=94=A8=E6=88=B7=E8=83=BD?=
=?UTF-8?q?=E5=88=86=E6=96=87=E4=BB=B6=E5=A4=B9=E5=AD=98=E9=99=84=E4=BB=B6?=
=?UTF-8?q?=202=E3=80=81=E9=99=84=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E5=AE=8C=E5=96=84=20=E4=BD=BF=E5=8F=AF=E4=BB=A5?=
=?UTF-8?q?=E9=80=9A=E8=BF=87=E4=BC=A0=E5=8F=82=20=E7=8B=AC=E7=AB=8B?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=8B=AC=E7=AB=8B=E4=BA=8C=E7=BA=A7=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E5=A4=B9=203=E3=80=81=E8=A7=86=E9=A2=91=E5=BA=93=20?=
=?UTF-8?q?=E7=B1=BB=E5=9E=8B=20=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0=20?=
=?UTF-8?q?=E5=88=A4=E6=96=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
APT.BaseData.Domain/Enums/PF/PFEnums.cs | 52 +++-
.../Controllers/Api/FileController.cs | 257 +++++++++++++++++-
.../Controllers/Api/PFFileDBController.cs | 10 +
.../APT.PF.WebApi/appsettings.Test.json | 2 +-
APT.MicroApi/APT.PF.WebApi/appsettings.json | 2 +-
5 files changed, 312 insertions(+), 11 deletions(-)
diff --git a/APT.BaseData.Domain/Enums/PF/PFEnums.cs b/APT.BaseData.Domain/Enums/PF/PFEnums.cs
index 1f2263b..a1ddf6e 100644
--- a/APT.BaseData.Domain/Enums/PF/PFEnums.cs
+++ b/APT.BaseData.Domain/Enums/PF/PFEnums.cs
@@ -60,36 +60,76 @@ namespace APT.BaseData.Domain.Enums.PF
///
public enum FilePathHead
{
-
///
/// 金源
///
[Description("00300000-0000-0000-0000-000000000000")]
- JY = 5,
-
+ JY = 3,
///
/// 邦泰
///
[Description("00500000-0000-0000-0000-000000000000")]
BT = 5,
-
///
/// 路源
///
[Description("01000000-0000-0000-0000-000000000000")]
LY = 10,
-
///
/// 金能昆仑
///
[Description("01500000-0000-0000-0000-000000000000")]
JNKL = 15,
-
///
/// 西拓
///
[Description("02000000-0000-0000-0000-000000000000")]
XT = 20,
+ ///
+ /// 聚源
+ ///
+ [Description("02500000-0000-0000-0000-000000000000")]
+ JUYUAN = 25,
+ ///
+ /// 彩宏
+ ///
+ [Description("03000000-0000-0000-0000-000000000000")]
+ CH = 30,
+ ///
+ /// 鑫源
+ ///
+ [Description("03500000-0000-0000-0000-000000000000")]
+ XY = 35,
+ ///
+ /// 天山
+ ///
+ [Description("04000000-0000-0000-0000-000000000000")]
+ TS = 40,
+ ///
+ /// 嘉鑫
+ ///
+ [Description("04500000-0000-0000-0000-000000000000")]
+ JX = 45,
+ ///
+ /// 硝尔库勒
+ ///
+ [Description("05000000-0000-0000-0000-000000000000")]
+ XEKL = 50,
+ ///
+ /// 浩特元素
+ ///
+ [Description("05500000-0000-0000-0000-000000000000")]
+ HTYS = 55,
+ ///
+ /// 兴泰
+ ///
+ [Description("06000000-0000-0000-0000-000000000000")]
+ XINGTAI = 60,
+ ///
+ /// 宝硕
+ ///
+ [Description("06500000-0000-0000-0000-000000000000")]
+ BS = 65,
}
///
diff --git a/APT.MicroApi/APT.PF.WebApi/Controllers/Api/FileController.cs b/APT.MicroApi/APT.PF.WebApi/Controllers/Api/FileController.cs
index 1b79738..fe076d9 100644
--- a/APT.MicroApi/APT.PF.WebApi/Controllers/Api/FileController.cs
+++ b/APT.MicroApi/APT.PF.WebApi/Controllers/Api/FileController.cs
@@ -650,6 +650,19 @@ namespace APT.PF.WebApiControllers.Api.PF
dynamic result = new ExpandoObject();
var httpRequest = HttpContext.Request;
+ string PBN = string.Empty;
+ if (httpRequest.Headers.ContainsKey("PBN"))
+ {
+ try
+ {
+ PBN = httpRequest.Headers["PBN"];
+ }
+ catch
+ {
+ PBN = "";
+ }
+ }
+
var strOrgId = httpRequest.Form["OrgId"][0]; // 获取 组织
var strImgID = string.Empty;
if (httpRequest.Form.ContainsKey("imgFileID"))
@@ -680,7 +693,7 @@ namespace APT.PF.WebApiControllers.Api.PF
var now = DateTime.Now;
//文件存储路径
//var filePath = string.Format("/{0}/{1}/{2}/", now.ToString("yyyy"), now.ToString("yyyyMM"), now.ToString("yyyyMMdd"));
- string filePath = GetFilePath(orgId);
+ string filePath = GetFilePath(orgId, PBN);
var fullFilePath = $"{ ConfigurationManager.AppSettings["Img_Local"]}{filePath}";
@@ -846,14 +859,246 @@ namespace APT.PF.WebApiControllers.Api.PF
this.BantchAddEntity(fileList);
this.BantchAddEntity(imgFileList);
this.BantchAddEntity(imgFileDetailList);
+
return result;
});
}
+ ///
+ /// 上次文件转为图片
+ ///
+ ///
+ ///
+ [HttpPost, Route("UploadVideo")]
+ public JsonActionResult UploadVideo()
+ {
+ return SafeExecute(() =>
+ {
+ dynamic result = new ExpandoObject();
+ try
+ {
+ var httpRequest = HttpContext.Request;
+ string PBN = string.Empty;
+ if (httpRequest.Headers.ContainsKey("PBN"))
+ {
+ try
+ {
+ PBN = httpRequest.Headers["PBN"];
+ }
+ catch
+ {
+ PBN = "";
+ }
+ }
+ var strOrgId = httpRequest.Form["OrgId"][0]; // 获取 组织
+ var strImgID = string.Empty;
+ if (httpRequest.Form.ContainsKey("imgFileID"))
+ {
+ strImgID = httpRequest.Form["imgFileID"][0];
+ } // 获取 组织
+ var isSaveSelfStr = httpRequest.Form["IsSaveSelf"].Any() ? httpRequest.Form["IsSaveSelf"][0] : "false"; // 是否存储本身
+ if (string.IsNullOrEmpty(strOrgId))
+ throw new Exception("组织不允许为空");
+ var orgId = new Guid(strOrgId);
+ Guid ImgID = Guid.Empty;
+ if (strImgID != null && !string.IsNullOrEmpty(strImgID))
+ {
+ try
+ {
+ ImgID = new Guid(strImgID.ToString());
+ }
+ catch { }
+ }
+ if (ImgID == Guid.Empty)
+ {
+ ImgID = Guid.NewGuid();
+ }
+ //返回的文件地址
+ //List filenames = new List();
+ var now = DateTime.Now;
+ //文件存储路径
+ //var filePath = string.Format("/{0}/{1}/{2}/", now.ToString("yyyy"), now.ToString("yyyyMM"), now.ToString("yyyyMMdd"));
+ string filePath = GetFilePath(orgId, PBN);
+
+ var fullFilePath = $"{ ConfigurationManager.AppSettings["Img_Local"]}{filePath}";
+
+ ImageConverterFactory imageConverterFactory = new ImageConverterFactory();
+ var host = ConfigurationManager.AppSettings["SapInvokeHost"];
+
+ List fileList = new List();
+ List imgFileList = new List();
+ List imgFileDetailList = new List();
+
+ var files = httpRequest.Form.Files;
+
+ if (!Directory.Exists(fullFilePath))
+ {
+ Directory.CreateDirectory(fullFilePath);
+ }
+
+ //wyw 2023-12-15 保存的文件还是用自动生成的文件名吧 省得处理url转译
+ foreach (var item in files)
+ {
+ if (item != null)
+ {
+ //文件后缀
+ var fileExtension = Path.GetExtension(item.FileName);
+
+ var strDateTime = DateTime.Now.ToString("yyMMddhhmmssfff"); //取得时间字符串
+ var strRan = Convert.ToString(new Random().Next(100, 999)); //生成三位随机数
+ var saveName = strDateTime + strRan + fileExtension;
+ string fileName = item.FileName;
+
+ //插入图片数据
+ using (FileStream fs = System.IO.File.Create(fullFilePath + saveName))//fullFilePath + fileName wyw
+ {
+ item.CopyTo(fs);
+ fs.Flush();
+ }
+ if (fileExtension == ".jpg" || fileExtension == ".png" || fileExtension == ".jpeg")
+ {
+ using (FileStream inputFileStream = new FileStream(fullFilePath + saveName, FileMode.Open, FileAccess.Read))
+ {
+ MemoryStream compressedStream = CompressImageFileStream(inputFileStream);
+ inputFileStream.Close();
+ using (FileStream outputFileStream = new FileStream(fullFilePath + saveName, FileMode.Create, FileAccess.Write))
+ {
+ compressedStream.CopyTo(outputFileStream);
+ }
+ }
+ }
+ //filenames.Add(filePath + fileName);
+ var pos = fileName.LastIndexOf(".");
+ var extendName = fileName.Substring(pos);
+ List list = new List();
+ bool isSuppot = imageConverterFactory.Support(extendName);
+ bool isSaveSelf = true;
+
+ T_PF_IMG_FILE imgFile = new T_PF_IMG_FILE
+ {
+ ID = ImgID,
+ FILE_NAME = fileName,
+ FILE_TYPE = item.ContentType,
+ ORG_ID = orgId
+ };
+
+ var inputStream = item.OpenReadStream();
+ //支持转换时,按类型转为图片,否则直接存储
+ if (isSuppot)
+ {
+ if (!string.IsNullOrEmpty(host))
+ {
+ ConvertImageFileParam param = new ConvertImageFileParam();
+ param.FileName = fileName;
+ Byte[] fileData = new Byte[(int)item.Length];
+ Stream sr = inputStream;//创建数据流对象
+ sr.Read(fileData, 0, (int)item.Length);
+ param.FileData = fileData;
+ string url = host + "ImageConvert/ImageConvert";
+ ConvertImageFileParam retModel =
+ WebUtils.Execute(url, param, string.Empty, SendType.Post);
+ if (retModel != null && retModel.Files != null && retModel.Files.Any())
+ list.AddRange(retModel.Files);
+ }
+ else
+ {
+ var convert = imageConverterFactory.CreateImageConverter(fileName);
+ convert.ConvertToImage(fileName, inputStream, list);
+ }
+ if (isSaveSelf)//保存自身数据
+ {
+ Byte[] fileData = new Byte[(int)item.Length];
+ Stream sr = inputStream;//创建数据流对象
+ sr.Read(fileData, 0, (int)item.Length);
+ T_PF_FILE file = new T_PF_FILE
+ {
+ FILE_NAME = fileName,
+ FILE_TYPE = item.ContentType,
+ //FILE_DATA = fileData,
+ ORG_ID = orgId,
+ //FILE_PATH = filePath + fileName
+ FILE_PATH = filePath + saveName//wyw
+ };
+ imgFile.FILE_ID = file.ID;
+ imgFile.Nav_File = file;
+ fileList.Add(file);
+ }
+ }
+ else
+ {
+ ConvertImageFile tmpImgFile = new ConvertImageFile();
+ //tmpImgFile.FileName = fileName;
+ tmpImgFile.FileName = saveName;//wyw
+ tmpImgFile.FileType = item.ContentType;
+ Byte[] fileData = new Byte[(int)item.Length];
+ Stream sr = inputStream;//创建数据流对象
+ sr.Read(fileData, 0, (int)item.Length);
+ tmpImgFile.FileData = fileData;
+ list.Add(tmpImgFile);
+ }
+ //保存文件数据
+ if (list.Any())
+ {
+ int i = 1;
+ foreach (var fileitem in list)
+ {
+ T_PF_FILE file = new T_PF_FILE
+ {
+ ID = Guid.NewGuid(),
+ FILE_NAME = fileitem.FileName,
+ FILE_TYPE = fileitem.FileType,
+ //FILE_DATA = fileitem.FileData,
+ //FILE_PATH = filePath + fileName,
+ FILE_PATH = filePath + saveName,//wyw,
+ ORG_ID = orgId
+ };
+
+ if (!isSuppot && isSaveSelf)
+ {
+ imgFile.FILE_ID = file.ID;
+ imgFile.Nav_File = file;
+ }
+
+ if (string.IsNullOrEmpty(imgFile.FILE_PATH) && !string.IsNullOrEmpty(file.FILE_PATH))
+ {
+ imgFile.FILE_PATH = file.FILE_PATH;
+ }
+
+ T_PF_IMG_FILE_DETAIL detail = new T_PF_IMG_FILE_DETAIL
+ {
+ ORG_ID = orgId,
+ IMG_FILE_ID = imgFile.ID,
+ FILE_ID = file.ID,
+ NUM = i
+ };
+ i++;
+ fileList.Add(file);
+ imgFileDetailList.Add(detail);
+ }
+ }
+ imgFileList.Add(imgFile);
+ result.imgFileID = imgFile.ID;
+ result.imgFilePath = imgFile.Nav_File?.FILE_PATH;
+ }
+ }
+ this.BantchAddEntity(fileList);
+ this.BantchAddEntity(imgFileList);
+ this.BantchAddEntity(imgFileDetailList);
+
+ }
+ catch (Exception ex)
+ {
+ result.status = 200;
+ result.CODE = 400;
+ result.ERROR = "视频上传失败!" + ex.Message;
+ }
+ return result;
+ });
+ }
///
/// 根据ID获取文件数据
///
@@ -968,8 +1213,9 @@ namespace APT.PF.WebApiControllers.Api.PF
/// 根据OrgId获取文件夹名称
///
///
+ /// 文件包名称
///
- public string GetFilePath(Guid OrgId)
+ public string GetFilePath(Guid OrgId, string PBN = "")
{
string orgid = OrgId.ToString().ToUpperInvariant();
string pathHead = "";
@@ -985,7 +1231,12 @@ namespace APT.PF.WebApiControllers.Api.PF
}
DateTime dtNow = DateTime.Now;
//var strRan = Convert.ToString(new Random().Next(100, 999)); //生成三位随机数
- var filePath = string.Format("/{0}/{1}/{2}/", dtNow.ToString("yyyy"), dtNow.ToString("yyyyMM"), dtNow.ToString("yyyyMMdd"));
+ string filePath = "";
+ if (string.IsNullOrEmpty(PBN))
+ filePath = string.Format("/{0}/{1}/{2}/", dtNow.ToString("yyyy"), dtNow.ToString("yyyyMM"), dtNow.ToString("yyyyMMdd"));
+ else
+ filePath = string.Format("/{0}/{1}/", PBN, dtNow.ToString("yyyyMMdd"));//不要那么多层级不然太难找了
+
return string.IsNullOrEmpty(pathHead) ? filePath : "/" + pathHead + filePath;
}
diff --git a/APT.MicroApi/APT.PF.WebApi/Controllers/Api/PFFileDBController.cs b/APT.MicroApi/APT.PF.WebApi/Controllers/Api/PFFileDBController.cs
index 32f5c2f..2a1d313 100644
--- a/APT.MicroApi/APT.PF.WebApi/Controllers/Api/PFFileDBController.cs
+++ b/APT.MicroApi/APT.PF.WebApi/Controllers/Api/PFFileDBController.cs
@@ -51,6 +51,10 @@
//2、IIS有限制IIS上传附件大小 本地服务器暂时不做大附件处理
return SafeExecute(() =>
{
+ if (string.IsNullOrEmpty(entity.NAME))
+ {
+ throw new Exception("视频库名称不能为空!");
+ }
var files = entity.Nav_Files;
entity.Nav_Files = null;
if (files != null && files.Any())
@@ -60,6 +64,12 @@
item.Nav_FileDB = null;
}
}
+
+ var check = GetEntity(e => e.TYPE_ID == entity.TYPE_ID && e.NAME == entity.NAME);
+ if (check != null)
+ {
+ throw new Exception("视频库中已存在该视频类型与视频名称,不能重复添加!");
+ }
UnifiedCommit(() =>
{
this.UpdateEntityNoCommit(entity);
diff --git a/APT.MicroApi/APT.PF.WebApi/appsettings.Test.json b/APT.MicroApi/APT.PF.WebApi/appsettings.Test.json
index 125af5a..8b356b8 100644
--- a/APT.MicroApi/APT.PF.WebApi/appsettings.Test.json
+++ b/APT.MicroApi/APT.PF.WebApi/appsettings.Test.json
@@ -21,7 +21,7 @@
"ConnDataKey": "MHKSAQ1212010101",
"TenantConnKey": "MHJY",
"RedisFormConfig": "false",
- "Img_Local": "C:\\release\\jy\\uploadFile\\"
+ "Img_Local": "D:\\uploadFile\\"
},
"RedisConfig": {
"RedisConnectionString": "121.41.2.71:6379,password=mhsaferedis,defaultDatabase=5",
diff --git a/APT.MicroApi/APT.PF.WebApi/appsettings.json b/APT.MicroApi/APT.PF.WebApi/appsettings.json
index 5cc2660..2129511 100644
--- a/APT.MicroApi/APT.PF.WebApi/appsettings.json
+++ b/APT.MicroApi/APT.PF.WebApi/appsettings.json
@@ -19,7 +19,7 @@
"RedisFormConfig": "false",
"ConnDataKey": "MHKSAQ1212010101",
"TenantConnKey": "MHJY",
- "Img_Local": "C:\\release\\jy\\uploadFile\\"
+ "Img_Local": "D:\\uploadFile\\"
},
"RedisConfig": {
"RedisConnectionString": "120.25.146.51:6379",