Compare commits
2 Commits
641fb69dc3
...
f1fa2ac664
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1fa2ac664 | ||
|
|
b3309e2fef |
@ -60,36 +60,76 @@ namespace APT.BaseData.Domain.Enums.PF
|
||||
/// </summary>
|
||||
public enum FilePathHead
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 金源
|
||||
/// </summary>
|
||||
[Description("00300000-0000-0000-0000-000000000000")]
|
||||
JY = 5,
|
||||
|
||||
JY = 3,
|
||||
/// <summary>
|
||||
/// 邦泰
|
||||
/// </summary>
|
||||
[Description("00500000-0000-0000-0000-000000000000")]
|
||||
BT = 5,
|
||||
|
||||
/// <summary>
|
||||
/// 路源
|
||||
/// </summary>
|
||||
[Description("01000000-0000-0000-0000-000000000000")]
|
||||
LY = 10,
|
||||
|
||||
/// <summary>
|
||||
/// 金能昆仑
|
||||
/// </summary>
|
||||
[Description("01500000-0000-0000-0000-000000000000")]
|
||||
JNKL = 15,
|
||||
|
||||
/// <summary>
|
||||
/// 西拓
|
||||
/// </summary>
|
||||
[Description("02000000-0000-0000-0000-000000000000")]
|
||||
XT = 20,
|
||||
/// <summary>
|
||||
/// 聚源
|
||||
/// </summary>
|
||||
[Description("02500000-0000-0000-0000-000000000000")]
|
||||
JUYUAN = 25,
|
||||
/// <summary>
|
||||
/// 彩宏
|
||||
/// </summary>
|
||||
[Description("03000000-0000-0000-0000-000000000000")]
|
||||
CH = 30,
|
||||
/// <summary>
|
||||
/// 鑫源
|
||||
/// </summary>
|
||||
[Description("03500000-0000-0000-0000-000000000000")]
|
||||
XY = 35,
|
||||
/// <summary>
|
||||
/// 天山
|
||||
/// </summary>
|
||||
[Description("04000000-0000-0000-0000-000000000000")]
|
||||
TS = 40,
|
||||
/// <summary>
|
||||
/// 嘉鑫
|
||||
/// </summary>
|
||||
[Description("04500000-0000-0000-0000-000000000000")]
|
||||
JX = 45,
|
||||
/// <summary>
|
||||
/// 硝尔库勒
|
||||
/// </summary>
|
||||
[Description("05000000-0000-0000-0000-000000000000")]
|
||||
XEKL = 50,
|
||||
/// <summary>
|
||||
/// 浩特元素
|
||||
/// </summary>
|
||||
[Description("05500000-0000-0000-0000-000000000000")]
|
||||
HTYS = 55,
|
||||
/// <summary>
|
||||
/// 兴泰
|
||||
/// </summary>
|
||||
[Description("06000000-0000-0000-0000-000000000000")]
|
||||
XINGTAI = 60,
|
||||
/// <summary>
|
||||
/// 宝硕
|
||||
/// </summary>
|
||||
[Description("06500000-0000-0000-0000-000000000000")]
|
||||
BS = 65,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 上次文件转为图片
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("UploadVideo")]
|
||||
public JsonActionResult<dynamic> UploadVideo()
|
||||
{
|
||||
return SafeExecute<dynamic>(() =>
|
||||
{
|
||||
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<string> filenames = new List<string>();
|
||||
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<T_PF_FILE> fileList = new List<T_PF_FILE>();
|
||||
List<T_PF_IMG_FILE> imgFileList = new List<T_PF_IMG_FILE>();
|
||||
List<T_PF_IMG_FILE_DETAIL> imgFileDetailList = new List<T_PF_IMG_FILE_DETAIL>();
|
||||
|
||||
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<ConvertImageFile> list = new List<ConvertImageFile>();
|
||||
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<ConvertImageFileParam>(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;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据ID获取文件数据
|
||||
/// </summary>
|
||||
@ -968,8 +1213,9 @@ namespace APT.PF.WebApiControllers.Api.PF
|
||||
/// 根据OrgId获取文件夹名称
|
||||
/// </summary>
|
||||
/// <param name="OrgId"></param>
|
||||
/// <param name="PBN">文件包名称</param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -51,6 +51,10 @@
|
||||
//2、IIS有限制IIS上传附件大小 本地服务器暂时不做大附件处理
|
||||
return SafeExecute<bool>(() =>
|
||||
{
|
||||
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<T_PF_FILE_DB>(e => e.TYPE_ID == entity.TYPE_ID && e.NAME == entity.NAME);
|
||||
if (check != null)
|
||||
{
|
||||
throw new Exception("视频库中已存在该视频类型与视频名称,不能重复添加!");
|
||||
}
|
||||
UnifiedCommit(() =>
|
||||
{
|
||||
this.UpdateEntityNoCommit(entity);
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user