AttachFilesAppServiceBase.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Abp.Application.Services.Dto;
  2. using Abp.Auditing;
  3. using Abp.Authorization;
  4. using Abp.Domain.Repositories;
  5. using Microsoft.EntityFrameworkCore;
  6. using VberZero.AppService.Attaches.Dto;
  7. using VberZero.AppService.Base;
  8. using VberZero.AppService.Base.Dto;
  9. using VberZero.Auditing;
  10. using VberZero.BaseSystem;
  11. namespace VberZero.AppService.Attaches;
  12. [AbpAuthorize, AuditLog("文件上传")]
  13. public class AttachFilesAppServiceBase : VzAppServiceBase, IAttachFilesAppServiceBase
  14. {
  15. private readonly IRepository<SysAttach, int> _repository;
  16. public AttachFilesAppServiceBase(IRepository<SysAttach, int> repository)
  17. {
  18. _repository = repository;
  19. }
  20. /// <summary>
  21. /// 上传附件
  22. /// </summary>
  23. /// <param name="input"></param>
  24. /// <returns></returns>
  25. [DisableAuditing]
  26. public virtual Task FileUpload(AttachDto input)
  27. {
  28. return AttachManager.FileUpload(input);
  29. }
  30. /// <summary>
  31. /// 查询附件
  32. /// </summary>
  33. /// <param name="input"></param>
  34. /// <returns></returns>
  35. [DisableAuditing]
  36. public async Task<List<AttachFileDto>> QueryAttaches(QueryAttachDto input)
  37. {
  38. var dtos = await _repository.GetAll().Where(a =>
  39. a.CodeKey == input.CodeKey && a.SourceKey == input.Key).Select(a => new AttachFileDto()
  40. {
  41. Id = a.Id,
  42. CodeKey = a.CodeKey,
  43. SourceKey = a.SourceKey,
  44. FileExt = a.FileExt,
  45. FileName = a.FileName,
  46. FileTitle = a.FileTitle,
  47. FilePath = a.FilePath,
  48. FileType = a.FileType,
  49. }).ToListAsync();
  50. return dtos;
  51. }
  52. /// <summary>
  53. /// 查询附件
  54. /// </summary>
  55. /// <param name="input"></param>
  56. /// <returns></returns>
  57. [DisableAuditing]
  58. public async Task<AttachFileDto> QueryAttach(QueryAttachDto input)
  59. {
  60. var dto = await _repository.GetAll().Where(a =>
  61. a.CodeKey == input.CodeKey && a.SourceKey == input.Key).Select(a => new AttachFileDto()
  62. {
  63. Id = a.Id,
  64. CodeKey = a.CodeKey,
  65. SourceKey = a.SourceKey,
  66. Description = a.Description,
  67. FileExt = a.FileExt,
  68. FileName = a.FileName,
  69. FileTitle = a.FileTitle,
  70. FilePath = a.FilePath,
  71. FileType = a.FileType,
  72. }).FirstOrDefaultAsync();
  73. return dto;
  74. }
  75. /// <summary>
  76. /// 查询附件
  77. /// </summary>
  78. /// <param name="input"></param>
  79. /// <returns></returns>
  80. [AuditLog("删除文件")]
  81. public virtual async Task DeleteAttach(VzEntityDto<int> input)
  82. {
  83. var entity = await _repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  84. if (entity != null)
  85. {
  86. await _repository.DeleteAsync(entity);
  87. }
  88. }
  89. [DisableAuditing]
  90. public async Task<string> GetSelectStrWithCodeKey(string codeKey)
  91. {
  92. var list = await _repository.GetAllListAsync(a => a.CodeKey == codeKey);
  93. string str = "<option value=\"\" selected>请选择...</option>";
  94. foreach (var l in list)
  95. {
  96. str += $"<option value=\"{l.Id}\">{l.FileTitle}</option>";
  97. }
  98. return str;
  99. }
  100. }