新增文件服务接口

master
xiaochanghai 1 year ago
parent cfe350e3ee
commit e6273e2487
  1. 1
      .gitignore
  2. 2403
      Model/Tiobon.Web.pdm
  3. 85
      Tiobon.Core.Api/Controllers/FileController.cs
  4. 4
      Tiobon.Core.Api/Tiobon.Core.Model.xml
  5. 19
      Tiobon.Core.Api/Tiobon.Core.xml
  6. 22
      Tiobon.Core.Common/Helper/StringHelper.cs
  7. 1
      Tiobon.Core.DataAccess/DataContext.cs
  8. 2
      Tiobon.Core.Model/Base/BasePoco.cs
  9. 3
      Tiobon.Core.Model/Base/Ghre/Ghre_Attachment.Dto.Base.cs
  10. 2
      Tiobon.Core.Model/Edit/Ghre/Ghre_Attachment.Dto.EditInput.cs
  11. 2
      Tiobon.Core.Model/Insert/Ghre/Ghre_Attachment.Dto.InsertInput.cs
  12. 4
      Tiobon.Core.Model/Models/Ghre/Ghre_Attachment.cs
  13. 2
      Tiobon.Core.Model/View/Ghre/Ghre_Attachment.Dto.View.cs

1
.gitignore vendored

@ -28,6 +28,7 @@ bld/
[Ll]og/
Log/
Logs/
upload/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot

File diff suppressed because it is too large Load Diff

@ -0,0 +1,85 @@
using System.Dynamic;
using MySqlX.XDevAPI.Common;
using SqlSugar;
using Tiobon.Core.DataAccess;
namespace Tiobon.Core.Controllers;
/// <summary>
/// 文件服务
/// </summary>
[Produces("application/json")]
[Route("api/File"), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)]
public class FileController : BaseApiController
{
public ITiobonArticleServices _TiobonArticleServices { get; set; }
private readonly ILogger<TiobonController> _logger;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="logger"></param>
///
public FileController(ILogger<TiobonController> logger)
{
_logger = logger;
}
#region 上传图片
/// <summary>
/// 上传图片
/// </summary>
/// <param name="fileList"></param>
/// <returns></returns>
[HttpPost, Route("UploadImage")]
public async Task<ServiceResult<string>> UploadImageAsync(IFormFileCollection fileList)
{
string filePath = null;
using var _context = ContextFactory.CreateContext();
if (fileList.Count > 0)
{
filePath = !string.IsNullOrEmpty(filePath) ? filePath : "upload";
foreach (var file in fileList)
{
var ext = string.Empty;
if (string.IsNullOrEmpty(file.FileName) == false)
{
var dotPos = file.FileName.LastIndexOf('.');
ext = file.FileName.Substring(dotPos + 1);
}
string pathHeader = "wwwroot/" + filePath;
if (!Directory.Exists(pathHeader))
Directory.CreateDirectory(pathHeader);
string fileName = StringHelper.GetSysID();
filePath = "/" + filePath + "/" + $"{fileName}.{ext}";
//var filepath = Path.Combine(pathHeader, file.FileName);
using (var stream = global::System.IO.File.Create("wwwroot/" + filePath))
{
await file.CopyToAsync(stream);
}
Ghre_Attachment fileAttachment = new Ghre_Attachment();
fileAttachment.Id = SnowFlakeSingle.Instance.NextId();
fileAttachment.AttachFileName = file.FileName;
fileAttachment.CreateBy = App.User.ID;
fileAttachment.CreateTime = DateTime.Now;
fileAttachment.AttachmentName = fileName;
fileAttachment.AttachFileExtension = ext;
fileAttachment.AttachFileSize = file.Length;
fileAttachment.PhysicsPath = filePath;
fileAttachment.AttachmentType = file.ContentType;
//url = fileName + "." + ext;
_context.Add(fileAttachment);
_context.SaveChanges();
}
}
return Success<string>(filePath);
}
#endregion
}

@ -197,12 +197,10 @@
附件扩展名
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_AttachmentBase.AttachFileSize">
<member name="P:Tiobon.Core.Model.Models.Ghre_AttachmentBase.PhysicsPath">
<summary>
附件大小
</summary>
</member>
<member name="P:Tiobon.Core.Model.Models.Ghre_AttachmentBase.PhysicsPath">
<summary>
物理路径
</summary>

@ -273,6 +273,25 @@
</summary>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Controllers.FileController">
<summary>
文件服务
</summary>
</member>
<member name="M:Tiobon.Core.Controllers.FileController.#ctor(Microsoft.Extensions.Logging.ILogger{Tiobon.Core.Controllers.TiobonController})">
<summary>
构造函数
</summary>
<param name="logger"></param>
</member>
<member name="M:Tiobon.Core.Controllers.FileController.UploadImageAsync(Microsoft.AspNetCore.Http.IFormFileCollection)">
<summary>
上传图片
</summary>
<param name="fileList"></param>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Controllers.LoginController">
<summary>
登录管理【无权限】

@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text;
namespace Tiobon.Core.Common.Helper;
namespace Tiobon.Core.Common.Helper
{
public class StringHelper
{
/// <summary>
@ -106,6 +102,18 @@ namespace Tiobon.Core.Common.Helper
string[] arrStr = resourceStr.Split("\r\n");
return string.Join("", (from q in arrStr select q).Skip(arrStr.Length - length + 1).Take(length).ToArray());
}
#region 求系统唯一字符串
/// <summary>
/// 求系统唯一字符串,常用于ROW_ID值。
/// </summary>
/// <returns>字符串</returns>
public static string GetSysID()
{
string sid = string.Empty;
byte[] buffer = Guid.NewGuid().ToByteArray();
sid = DateTime.Now.ToString("yyMMddHHmmss") + BitConverter.ToInt64(buffer, 0).ToString();
return sid;
}
#endregion
}

@ -8,6 +8,7 @@ namespace Tiobon.Core.DataAccess
public virtual DbSet<Ghra_Grade> Ghra_Grade { get; set; }
public virtual DbSet<Ghre_Attachment> Ghre_Attachment { get; set; }
//占位符

@ -34,7 +34,7 @@ namespace Tiobon.Core.Model
/// 创建人
/// </summary>
[Display(Name = "创建人"), SugarColumn(IsOnlyIgnoreUpdate = true)]
public int? CreateBy { get; set; }
public long? CreateBy { get; set; }
/// <summary>
/// 创建时间

@ -6,7 +6,7 @@
*
* Ver
*
*V0.01 2024/4/23 16:02:54 SimonHsiao
*V0.01 2024/4/23 16:17:18 SimonHsiao
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*
@ -90,7 +90,6 @@ namespace Tiobon.Core.Model.Models
/// <summary>
/// 附件大小
/// </summary>
public int? AttachFileSize { get; set; }
/// <summary>
/// 物理路径

@ -6,7 +6,7 @@
*
* Ver
*
*V0.01 2024/4/23 16:02:54 SimonHsiao
*V0.01 2024/4/23 16:17:18 SimonHsiao
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*

@ -6,7 +6,7 @@
*
* Ver
*
*V0.01 2024/4/23 16:02:54 SimonHsiao
*V0.01 2024/4/23 16:17:18 SimonHsiao
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*

@ -6,7 +6,7 @@
*
* Ver
*
*V0.01 2024/4/23 16:02:54 SimonHsiao
*V0.01 2024/4/23 16:17:18 SimonHsiao
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*
@ -92,7 +92,7 @@ namespace Tiobon.Core.Model.Models
/// <summary>
/// 附件大小
/// </summary>
public int? AttachFileSize { get; set; }
public long? AttachFileSize { get; set; }
/// <summary>
/// 物理路径

@ -6,7 +6,7 @@
*
* Ver
*
*V0.01 2024/4/23 16:02:54 SimonHsiao
*V0.01 2024/4/23 16:17:18 SimonHsiao
*
* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved.
*

Loading…
Cancel
Save