AttachFilesAppService.cs 5.2 KB

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