|
@@ -10,6 +10,7 @@ using Utils;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using System.IO;
|
|
|
+using MimeMapping;
|
|
|
|
|
|
namespace PMS.NetCore.Controllers
|
|
|
{
|
|
@@ -1203,13 +1204,7 @@ namespace PMS.NetCore.Controllers
|
|
|
#region 存文件到文件夹
|
|
|
var filePath = savePath;
|
|
|
|
|
|
- //获取日期路径
|
|
|
- var creatDate = DateTime.Now.ToString("yyyyMMDD");
|
|
|
- filePath += $"/{creatDate}";
|
|
|
- if (!Directory.Exists(filePath)) //若文件目录不存在,则创建目录
|
|
|
- {
|
|
|
- Directory.CreateDirectory(filePath);
|
|
|
- }
|
|
|
+ //获取日期路径
|
|
|
filePath += $"/{file.FileName}";
|
|
|
using (var sw = System.IO.File.Open(filePath, FileMode.Create, FileAccess.Write))
|
|
|
{
|
|
@@ -1246,41 +1241,22 @@ namespace PMS.NetCore.Controllers
|
|
|
/// <summary>
|
|
|
/// 附件显示
|
|
|
/// </summary>
|
|
|
- /// <param name="code"></param>
|
|
|
+ /// <param name="autoid"></param>
|
|
|
/// <returns></returns>
|
|
|
[AllowAnonymous]
|
|
|
[HttpGet]
|
|
|
[Route("ShowImg")]
|
|
|
- public FileResult ShowImg(string code)
|
|
|
+ public FileResult ShowImg(string autoid)
|
|
|
{
|
|
|
- var bll = new AttachMentManager();
|
|
|
- var entity = bll.GetAttachMent(code);
|
|
|
- if (entity.Content != null) //从数据库读取
|
|
|
- {
|
|
|
- return File(entity.Content, entity.Content_Type);
|
|
|
- }
|
|
|
- else //从路径读取
|
|
|
+ var bll = new fdc_pm_fileManager();
|
|
|
+ var entity = bll.GetList(m => m.autoid == autoid.ToInteger()).FirstOrDefault();
|
|
|
+ if (entity.fileurl != null) //从数据库读取
|
|
|
{
|
|
|
var filePath = savePath;
|
|
|
- var filename = entity.GuidName;
|
|
|
- //获取日期路径
|
|
|
- var creatDate = entity.CreateDate.Value.ToString("yyyyMMDD");
|
|
|
- if (pathPattern == "Root")
|
|
|
- {
|
|
|
- filePath += $"/{filename}";
|
|
|
- }
|
|
|
- else if (pathPattern == "YYYY")
|
|
|
- {
|
|
|
- filePath += $"/{creatDate.Substring(0, 4)}/{filename}";
|
|
|
- }
|
|
|
- else if (pathPattern == "YYYYMM")
|
|
|
- {
|
|
|
- filePath += $"/{creatDate.Substring(0, 6)}/{filename}";
|
|
|
- }
|
|
|
- else if (pathPattern == "YYYYMMDD")
|
|
|
- {
|
|
|
- filePath += $"/{creatDate}/{filename}";
|
|
|
- }
|
|
|
+ var filename = entity.fileurl;
|
|
|
+
|
|
|
+ filePath += $"/{filePath}/{filename}";
|
|
|
+
|
|
|
logger.Info($"附件保存路径:{filePath}");
|
|
|
if (!System.IO.File.Exists(filePath))
|
|
|
{
|
|
@@ -1290,11 +1266,16 @@ namespace PMS.NetCore.Controllers
|
|
|
byte[] infbytes = new byte[(int)fs.Length];
|
|
|
fs.Read(infbytes, 0, infbytes.Length);
|
|
|
fs.Close();
|
|
|
- var contentType = entity.Content_Type;
|
|
|
+ var contentType =MimeUtility.GetMimeMapping(filePath);
|
|
|
return File(infbytes, contentType);
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RedirectToAction("NotFound");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ return null;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|