PromptApplicationService.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 IwbZero.Auditing;
  11. using IwbZero.AppServiceBase;
  12. using WePlatform.Authorization;
  13. using WePlatform.WeLib.Guide.Dto;
  14. namespace WePlatform.WeLib.Guide
  15. {
  16. [AbpAuthorize, AuditLog("引导信息库管理")]
  17. public class PromptAppService : IwbAsyncCrudAppService<GuideInfo, GuideDto, string, IwbPagedRequestDto, GuideCreateDto, GuideUpdateDto >, IPromptAppService
  18. {
  19. public PromptAppService(
  20. ICacheManager cacheManager,
  21. IRepository<GuideInfo, string> repository) : base(repository, "Id")
  22. {
  23. CacheManager = cacheManager;
  24. }
  25. protected override bool KeyIsAuto { get; set; } = false;
  26. #region GetSelect
  27. [DisableAuditing]
  28. public override async Task<List<SelectListItem>> GetSelectList()
  29. {
  30. var list = await Repository.GetAllListAsync();
  31. var sList = new List<SelectListItem> {new SelectListItem {Text = @"请选择...", Value = "", Selected = true}};
  32. foreach (var l in list)
  33. {
  34. sList.Add(new SelectListItem { Value = l.Id, Text = l.Name });
  35. }
  36. return sList;
  37. }
  38. [DisableAuditing]
  39. public override async Task<string> GetSelectStr()
  40. {
  41. var list = await Repository.GetAllListAsync();
  42. string str = "<option value=\"\" selected>请选择...</option>";
  43. foreach (var l in list)
  44. {
  45. str += $"<option value=\"{l.Id}\">{l.Name}</option>";
  46. }
  47. return str;
  48. }
  49. #endregion
  50. #region CURD
  51. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgCreate)]
  52. public override async Task Create(GuideCreateDto input)
  53. {
  54. input.Id = await AppGuidManager.GetNextRecordIdAsync(DataLibType.GuidInfo);
  55. await CreateEntity(input);
  56. }
  57. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgUpdate)]
  58. public override async Task Update(GuideUpdateDto input)
  59. {
  60. await UpdateEntity(input);
  61. }
  62. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgDelete)]
  63. public override Task Delete(EntityDto<string> input)
  64. {
  65. return DeleteEntity(input);
  66. }
  67. [DisableAuditing]
  68. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgQuery)]
  69. public override async Task<PagedResultDto<GuideDto>> GetAll(IwbPagedRequestDto input)
  70. {
  71. var query = CreateFilteredQuery(input);
  72. query = ApplyFilter(query, input);
  73. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  74. query = ApplySorting(query, input);
  75. query = ApplyPaging(query, input);
  76. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  77. var dtoList = new PagedResultDto<GuideDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  78. return dtoList;
  79. }
  80. #region GetEntity/Dto
  81. /// <summary>
  82. /// 查询实体Dto
  83. /// </summary>
  84. /// <param name="input"></param>
  85. /// <returns></returns>
  86. [DisableAuditing]
  87. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgQuery)]
  88. public override async Task<GuideDto> GetDto(EntityDto<string> input)
  89. {
  90. var entity = await GetEntity(input);
  91. return MapToEntityDto(entity);
  92. }
  93. /// <summary>
  94. /// 查询实体Dto
  95. /// </summary>
  96. /// <param name="id"></param>
  97. /// <returns></returns>
  98. [DisableAuditing]
  99. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgQuery)]
  100. public override async Task<GuideDto> GetDtoById(string id)
  101. {
  102. var entity = await GetEntityById(id);
  103. return MapToEntityDto(entity);
  104. }
  105. /// <summary>
  106. /// 查询实体Dto(需指明自定义字段)
  107. /// </summary>
  108. /// <param name="no"></param>
  109. /// <returns></returns>
  110. [DisableAuditing]
  111. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgQuery)]
  112. public override async Task<GuideDto> GetDtoByNo(string no)
  113. {
  114. var entity = await GetEntityByNo(no);
  115. return MapToEntityDto(entity);
  116. }
  117. /// <summary>
  118. /// 查询实体
  119. /// </summary>
  120. /// <param name="input"></param>
  121. /// <returns></returns>
  122. [DisableAuditing]
  123. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgQuery)]
  124. public override async Task<GuideInfo> GetEntity(EntityDto<string> input)
  125. {
  126. var entity = await GetEntityById(input.Id);
  127. return entity;
  128. }
  129. /// <summary>
  130. /// 查询实体
  131. /// </summary>
  132. /// <param name="id"></param>
  133. /// <returns></returns>
  134. [DisableAuditing]
  135. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgQuery)]
  136. public override async Task<GuideInfo> GetEntityById(string id)
  137. {
  138. return await Repository.FirstOrDefaultAsync(a=>a.Id==id);
  139. }
  140. /// <summary>
  141. /// 查询实体(需指明自定义字段)
  142. /// </summary>
  143. /// <param name="no"></param>
  144. /// <returns></returns>
  145. [DisableAuditing]
  146. [AbpAuthorize(PermissionNames.PagesResourceMgGuideMgPromptMgQuery)]
  147. public override async Task<GuideInfo> GetEntityByNo(string no)
  148. {
  149. //CheckGetPermission();
  150. if (string.IsNullOrEmpty(KeyFiledName))
  151. {
  152. ThrowError("NoKeyFieldName");
  153. }
  154. return await base.GetEntityByNo(no);
  155. }
  156. #endregion
  157. #region Hide
  158. ///// <summary>
  159. ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{GuideInfo}"/>过滤查询.
  160. ///// </summary>
  161. ///// <param name="input">The input.</param>
  162. //protected override IQueryable<GuideInfo> CreateFilteredQuery(IwbPagedRequestDto input)
  163. //{
  164. // var query = Repository.GetAll();
  165. // var pagedInput = input as IIwbPagedRequest;
  166. // if (pagedInput == null)
  167. // {
  168. // return query;
  169. // }
  170. // if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  171. // {
  172. // object keyWords = pagedInput.KeyWords;
  173. // LambdaObject obj = new LambdaObject()
  174. // {
  175. // FieldType = (LambdaFieldType)pagedInput.FieldType,
  176. // FieldName = pagedInput.KeyField,
  177. // FieldValue = keyWords,
  178. // ExpType = (LambdaExpType)pagedInput.ExpType
  179. // };
  180. // var exp = obj.GetExp<GuideInfo>();
  181. // query = exp != null ? query.Where(exp) : query;
  182. // }
  183. // if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  184. // {
  185. // List<LambdaObject> objList = new List<LambdaObject>();
  186. // foreach (var o in pagedInput.SearchList)
  187. // {
  188. // if (string.IsNullOrEmpty(o.KeyWords))
  189. // continue;
  190. // object keyWords = o.KeyWords;
  191. // objList.Add(new LambdaObject
  192. // {
  193. // FieldType = (LambdaFieldType)o.FieldType,
  194. // FieldName = o.KeyField,
  195. // FieldValue = keyWords,
  196. // ExpType = (LambdaExpType)o.ExpType
  197. // });
  198. // }
  199. // var exp = objList.GetExp<GuideInfo>();
  200. // query = exp != null ? query.Where(exp) : query;
  201. // }
  202. // return query;
  203. //}
  204. //protected override IQueryable<GuideInfo> ApplySorting(IQueryable<GuideInfo> query, IwbPagedRequestDto input)
  205. //{
  206. // return query.OrderBy(a => a.No);
  207. //}
  208. //protected override IQueryable<GuideInfo> ApplyPaging(IQueryable<GuideInfo> query, IwbPagedRequestDto input)
  209. //{
  210. // if (input is IPagedResultRequest pagedInput)
  211. // {
  212. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  213. // }
  214. // return query;
  215. //}
  216. #endregion
  217. #endregion
  218. }
  219. }