AttachFilesAppService.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using System.Web.Mvc;
  5. using Abp.Application.Services.Dto;
  6. using Abp.Auditing;
  7. using Abp.Authorization;
  8. using Abp.Domain.Repositories;
  9. using Abp.Runtime.Caching;
  10. using WePlatform.BaseInfo;
  11. using WePlatform.BaseSystem.AttachFile.Dto;
  12. using WePlatform.CommonManager.AttachFiles;
  13. using IwbZero.AppServiceBase;
  14. using WePlatform.Configuration;
  15. namespace WePlatform.BaseSystem.AttachFile
  16. {
  17. [AbpAuthorize]
  18. public class AttachFilesAppService : IwbAsyncCrudAppService<SysAttachFile, AttachFileDto, int, IwbPagedRequestDto>
  19. , IAttachFilesAppService
  20. {
  21. public AttachFilesAppService(
  22. ICacheManager cacheManager,
  23. IRepository<SysAttachFile, int> repository) : base(repository, "AttachNo")
  24. {
  25. CacheManager = cacheManager;
  26. }
  27. protected override bool KeyIsAuto { get; set; } = true;
  28. #region GetSelect
  29. [DisableAuditing]
  30. public override async Task<List<SelectListItem>> GetSelectList()
  31. {
  32. var list = await Repository.GetAllListAsync();
  33. var sList = new List<SelectListItem> { new SelectListItem { Text = @"请选择...", Value = "", Selected = true } };
  34. foreach (var l in list)
  35. {
  36. sList.Add(new SelectListItem { Text = l.AttachNo, Value = l.FileTitle });
  37. }
  38. return sList;
  39. }
  40. [DisableAuditing]
  41. public override async Task<string> GetSelectStr()
  42. {
  43. var list = await Repository.GetAllListAsync();
  44. string str = "<option value=\"\" selected>请选择...</option>";
  45. foreach (var l in list)
  46. {
  47. str += $"<option value=\"{l.AttachNo}\">{l.FileTitle}</option>";
  48. }
  49. return str;
  50. }
  51. [DisableAuditing]
  52. public async Task<List<SelectListItem>> GetTableSelectList(string tableName, string colName)
  53. {
  54. var list = await Repository.GetAllListAsync(a => a.TableName == tableName && a.ColumnName == colName);
  55. var sList = new List<SelectListItem> { new SelectListItem { Text = @"请选择...", Value = "", Selected = true } };
  56. foreach (var l in list)
  57. {
  58. sList.Add(new SelectListItem { Text = l.AttachNo, Value = l.FileTitle });
  59. }
  60. return sList;
  61. }
  62. [DisableAuditing]
  63. public async Task<string> GetTableSelectStr(string tableName, string colName)
  64. {
  65. var list = await Repository.GetAllListAsync(a => a.TableName == tableName && a.ColumnName == colName);
  66. string str = "<option value=\"\" selected>请选择...</option>";
  67. foreach (var l in list)
  68. {
  69. str += $"<option value=\"{l.AttachNo}\">{l.FileTitle}</option>";
  70. }
  71. return str;
  72. }
  73. #endregion
  74. #region CURD
  75. /// <summary>
  76. /// 上传附件
  77. /// </summary>
  78. /// <param name="input"></param>
  79. /// <returns></returns>
  80. [DisableAuditing]
  81. public Task FileUpload(AttachFileCreateDto input)
  82. {
  83. return AttachFileManager.FileUpload(input);
  84. }
  85. /// <summary>
  86. /// 查询附件
  87. /// </summary>
  88. /// <param name="input"></param>
  89. /// <returns></returns>
  90. public async Task<List<AttachFileDto>> QueryAttaches(QueryAttachDto input)
  91. {
  92. var entities = await Repository.GetAllListAsync(a =>
  93. a.TableName == input.TableName && a.ColumnName == input.ColName && a.SourceKey == input.Key);
  94. return entities.Select(MapToEntityDto).ToList();
  95. }
  96. /// <summary>
  97. /// 查询附件
  98. /// </summary>
  99. /// <param name="input"></param>
  100. /// <returns></returns>
  101. public async Task<AttachFileDto> QueryAttach(QueryAttachDto input)
  102. {
  103. var entity = await Repository.FirstOrDefaultAsync(a =>
  104. a.TableName == input.TableName && a.ColumnName == input.ColName && a.SourceKey == input.Key);
  105. return MapToEntityDto(entity);
  106. }
  107. [DisableAuditing]
  108. public override async Task<PagedResultDto<AttachFileDto>> GetAll(IwbPagedRequestDto input)
  109. {
  110. CheckGetAllPermission();
  111. var query = CreateFilteredQuery(input);
  112. query = ApplyFilter(query, input);
  113. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  114. query = ApplySorting(query, input);
  115. query = ApplyPaging(query, input);
  116. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  117. var dtos = new PagedResultDto<AttachFileDto>(
  118. totalCount,
  119. entities.Select(MapToEntityDto).ToList()
  120. );
  121. return dtos;
  122. }
  123. #endregion
  124. }
  125. }