文件上传接口优化

master
xiaochanghai 1 month ago
parent 0dc5681100
commit 666b5dd4f7
  1. 7
      Tiobon.Core.Api/Controllers/FileController.cs
  2. 11
      Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamRecordController.cs
  3. 6
      Tiobon.Core.Api/Tiobon.Core.xml
  4. 1
      Tiobon.Core.Model/ViewModels/Extend/ChunkUpload.cs
  5. 3
      Tiobon.Core.Model/ViewModels/Extend/Ghre_ExamRecordExtend.cs
  6. 1
      Tiobon.Core.Model/ViewModels/FileUpload.cs
  7. 8
      Tiobon.Core.Services/Ghre/Ghre_AttachmentServices.cs
  8. 2
      Tiobon.Core.Services/Ghre/Ghre_CertificateRuleServices.cs
  9. 1
      Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs
  10. 9
      Tiobon.Core.Services/Ghre/Ghre_OpenClassServices.cs
  11. 6
      Tiobon.Core/Tiobon.Core.xml

@ -92,8 +92,9 @@ public class FileController : BaseApiController
{
string filePath = null;
using var _context = ContextFactory.CreateContext();
FileHelper.CreateDirectory($"/files/upload/{upload.masterId}");
filePath = !string.IsNullOrEmpty(filePath) ? filePath : "upload";
filePath = !string.IsNullOrEmpty(filePath) ? filePath : $"upload/{upload.masterId}";
var ext = string.Empty;
if (string.IsNullOrEmpty(upload.file.FileName) == false)
{
@ -162,7 +163,9 @@ public class FileController : BaseApiController
[HttpPost, Route("CheckExists")]
public ServiceResult<bool> CheckExistsAsync([FromBody] FileUpload upload)
{
var filePath = $"/files/upload/{upload.fileName}";
FileHelper.CreateDirectory($"/files/upload/{upload.masterId}");
var filePath = $"/files/upload/{upload.masterId}/{upload.fileName}";
#region 判断文件是否重复,重复即删除
var webRootPath = _hostingEnvironment.WebRootPath;
if (System.IO.File.Exists(webRootPath + filePath))

@ -291,4 +291,15 @@ public class Ghre_ExamRecordController : BaseController<IGhre_ExamRecordServices
{
return await _service.QueryGroups(examRecordId);
}
/// <summary>
/// IssueCertificate
/// </summary>
/// <returns></returns>
[HttpPost("IssueCertificate")]
public async Task<ServiceResult> IssueCertificate()
{
return await _service.IssueCertificate();
}
}

@ -1145,6 +1145,12 @@
<param name="examRecordId"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Api.Controllers.Ghre_ExamRecordController.IssueCertificate">
<summary>
IssueCertificate
</summary>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Api.Controllers.Ghre_ExamRecordDetailController">
<summary>
Ghre_ExamRecordDetail(Controller)

@ -10,4 +10,5 @@ public class ChunkUpload
public int chunkIndex { get; set; }
public int totalChunks { get; set; }
public string id { get; set; } = null;
public string masterId { get; set; }
}

@ -114,6 +114,9 @@ public class QueryExam : DefaultGhre_ExamPaperPageData
/// </summary>
public bool? IsAllowExam { get; set; } = true;
public bool? IsAfterViewResultRetake { get; set; }
public List<ExamGroup> Groups { get; set; } = new List<ExamGroup>();
}

@ -10,6 +10,7 @@ public class FileUpload
public string fileName { get; set; }
public string userId { get; set; }
public string langId { get; set; }
public string masterId { get; set; }
}

@ -15,7 +15,7 @@ public class Ghre_AttachmentServices : BaseServices<Ghre_Attachment, Ghre_Attach
public async Task<ServiceResult<FileUploadResult>> UploadVideoAsync(ChunkUpload upload)
{
var file = upload.file;
var path = $"{$"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}upload{Path.DirectorySeparatorChar}{upload.id}{Path.DirectorySeparatorChar}"}";
var path = $"{$"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}upload/{upload.masterId}/{Path.DirectorySeparatorChar}{upload.id}{Path.DirectorySeparatorChar}"}";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
using (var stream = File.Create(path + $"{upload.chunkIndex}"))
@ -32,11 +32,11 @@ public class Ghre_AttachmentServices : BaseServices<Ghre_Attachment, Ghre_Attach
ext = upload.fileName.Substring(dotPos + 1);
}
var id = SnowFlakeSingle.Instance.NextId();
await FileMerge(upload.id, "."+ ext, id);
await FileMerge(upload.id, "." + ext, id);
using var _context = ContextFactory.CreateContext();
var filePath = $"/files/upload/{id}.{ext}";
var filePath = $"/files/upload/{upload.masterId}/{id}.{ext}";
var fileAttachment = new Ghre_Attachment();
fileAttachment.Id = SnowFlakeSingle.Instance.NextId();
fileAttachment.AttachmentNo = upload.file.FileName;

@ -278,7 +278,7 @@ public class Ghre_CertificateRuleServices : BaseServices<Ghre_CertificateRule, G
break;
case "StudyTime"://学习时间
item.text = $"{studyRecord.BeginTime}~{studyRecord.EndTime}";
item.text = $"{studyRecord?.BeginTime}~{studyRecord?.EndTime}";
break;
case "ExamName"://考试名称

@ -889,6 +889,7 @@ public class Ghre_ExamRecordServices : BaseServices<Ghre_ExamRecord, Ghre_ExamRe
else
extend.IsAllowView = false;
}
extend.IsAfterViewResultRetake = exam.IsAfterViewResultRetake;
#endregion
var Groups = await Db.Queryable<Ghre_ExamRecordGroup>()

@ -475,6 +475,15 @@ public class Ghre_OpenClassServices : BaseServices<Ghre_OpenClass, Ghre_OpenClas
})
.Where(it => it.Id == entity.ExamId)
.ExecuteCommandAsync();
await Db.Updateable<Ghre_ExamRecord>()
.SetColumns(it => new Ghre_ExamRecord()
{
BeginTime = entity.ExamStartTime,
EndTime = entity.ExamEndTime,
})
.Where(it => it.ExamId == entity.ExamId)
.ExecuteCommandAsync();
}
#region 生成反馈数据

@ -1145,6 +1145,12 @@
<param name="examRecordId"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Api.Controllers.Ghre_ExamRecordController.IssueCertificate">
<summary>
IssueCertificate
</summary>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Api.Controllers.Ghre_ExamRecordDetailController">
<summary>
Ghre_ExamRecordDetail(Controller)

Loading…
Cancel
Save