StudentTipApplicationService.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.AppServiceBase;
  11. using IwbZero.Auditing;
  12. using WeApp.Authorization;
  13. using WeApp.BasicInfo.StudentTip.Dto;
  14. namespace WeApp.BasicInfo.StudentTip
  15. {
  16. [AbpAuthorize, AuditLog("学员提示信息")]
  17. public class StudentTipAppService : IwbAsyncCrudAppService<StudentTipInfo, StudentTipDto, string, IwbPagedRequestDto, StudentTipCreateDto, StudentTipUpdateDto>, IStudentTipAppService
  18. {
  19. public StudentTipAppService(
  20. ICacheManager cacheManager,
  21. IRepository<StudentTipInfo, 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. });
  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.}</option>";
  46. }
  47. return str;
  48. }
  49. #endregion GetSelect
  50. #region CURD
  51. [AbpAuthorize(PermissionNames.PagesBasicMgStudentHelpMgCreate)]
  52. public override async Task Create(StudentTipCreateDto input)
  53. {
  54. input.Id = await AppGuidManager.GetNextRecordIdAsync(DataLibType.StudentHelp);
  55. await CreateEntity(input);
  56. }
  57. [AbpAuthorize(PermissionNames.PagesBasicMgStudentHelpMgUpdate)]
  58. public override async Task Update(StudentTipUpdateDto input)
  59. {
  60. await UpdateEntity(input);
  61. }
  62. [AbpAuthorize(PermissionNames.PagesBasicMgStudentHelpMgDelete)]
  63. public override Task Delete(EntityDto<string> input)
  64. {
  65. return DeleteEntity(input);
  66. }
  67. [DisableAuditing]
  68. public override async Task<PagedResultDto<StudentTipDto>> GetAll(IwbPagedRequestDto input)
  69. {
  70. var query = CreateFilteredQuery(input);
  71. query = ApplyFilter(query, input);
  72. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  73. query = ApplySorting(query, input);
  74. query = ApplyPaging(query, input);
  75. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  76. var dtoList = new PagedResultDto<StudentTipDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  77. return dtoList;
  78. }
  79. //protected override IQueryable<StudentTipInfo> SelfSorting(IQueryable<StudentTipInfo> query, IwbPagedRequestDto input)
  80. //{
  81. // return query.OrderByDescending(r => r.Id);
  82. //}
  83. //protected override IQueryable<StudentTipInfo> KeyWordFilter(IQueryable<StudentTipInfo> query, string keyword)
  84. //{
  85. // return query.Where(a => a.Id.Contains(keyword));
  86. //}
  87. #region GetEntity/Dto
  88. /// <summary>
  89. /// 查询实体Dto
  90. /// </summary>
  91. /// <param name="input"></param>
  92. /// <returns></returns>
  93. [DisableAuditing]
  94. public override async Task<StudentTipDto> GetDto(EntityDto<string> input)
  95. {
  96. var entity = await GetEntity(input);
  97. return MapToEntityDto(entity);
  98. }
  99. /// <summary>
  100. /// 查询实体Dto
  101. /// </summary>
  102. /// <param name="id"></param>
  103. /// <returns></returns>
  104. [DisableAuditing]
  105. public override async Task<StudentTipDto> GetDtoById(string id)
  106. {
  107. var entity = await GetEntityById(id);
  108. return MapToEntityDto(entity);
  109. }
  110. /// <summary>
  111. /// 查询实体Dto(需指明自定义字段)
  112. /// </summary>
  113. /// <param name="no"></param>
  114. /// <returns></returns>
  115. [DisableAuditing]
  116. public override async Task<StudentTipDto> GetDtoByNo(string no)
  117. {
  118. var entity = await GetEntityByNo(no);
  119. return MapToEntityDto(entity);
  120. }
  121. /// <summary>
  122. /// 查询实体
  123. /// </summary>
  124. /// <param name="input"></param>
  125. /// <returns></returns>
  126. [DisableAuditing]
  127. public override async Task<StudentTipInfo> GetEntity(EntityDto<string> input)
  128. {
  129. var entity = await GetEntityById(input.Id);
  130. return entity;
  131. }
  132. /// <summary>
  133. /// 查询实体
  134. /// </summary>
  135. /// <param name="id"></param>
  136. /// <returns></returns>
  137. [DisableAuditing]
  138. public override async Task<StudentTipInfo> GetEntityById(string id)
  139. {
  140. return await Repository.FirstOrDefaultAsync(a => a.Id == id);
  141. }
  142. /// <summary>
  143. /// 查询实体(需指明自定义字段)
  144. /// </summary>
  145. /// <param name="no"></param>
  146. /// <returns></returns>
  147. [DisableAuditing]
  148. public override async Task<StudentTipInfo> GetEntityByNo(string no)
  149. {
  150. //CheckGetPermission();
  151. if (string.IsNullOrEmpty(KeyFiledName))
  152. {
  153. ThrowError("NoKeyFieldName");
  154. }
  155. return await base.GetEntityByNo(no);
  156. }
  157. #endregion GetEntity/Dto
  158. #region Hide
  159. ///// <summary>
  160. ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{StudentTipInfo}"/>过滤查询.
  161. ///// </summary>
  162. ///// <param name="input">The input.</param>
  163. //protected override IQueryable<StudentTipInfo> CreateFilteredQuery(IwbPagedRequestDto input)
  164. //{
  165. // var query = Repository.GetAll();
  166. // var pagedInput = input as IIwbPagedRequest;
  167. // if (pagedInput == null)
  168. // {
  169. // return query;
  170. // }
  171. // if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  172. // {
  173. // object keyWords = pagedInput.KeyWords;
  174. // LambdaObject obj = new LambdaObject()
  175. // {
  176. // FieldType = (LambdaFieldType)pagedInput.FieldType,
  177. // FieldName = pagedInput.KeyField,
  178. // FieldValue = keyWords,
  179. // ExpType = (LambdaExpType)pagedInput.ExpType
  180. // };
  181. // var exp = obj.GetExp<StudentTipInfo>();
  182. // query = exp != null ? query.Where(exp) : query;
  183. // }
  184. // if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  185. // {
  186. // List<LambdaObject> objList = new List<LambdaObject>();
  187. // foreach (var o in pagedInput.SearchList)
  188. // {
  189. // if (string.IsNullOrEmpty(o.KeyWords))
  190. // continue;
  191. // object keyWords = o.KeyWords;
  192. // objList.Add(new LambdaObject
  193. // {
  194. // FieldType = (LambdaFieldType)o.FieldType,
  195. // FieldName = o.KeyField,
  196. // FieldValue = keyWords,
  197. // ExpType = (LambdaExpType)o.ExpType
  198. // });
  199. // }
  200. // var exp = objList.GetExp<StudentTipInfo>();
  201. // query = exp != null ? query.Where(exp) : query;
  202. // }
  203. // return query;
  204. //}
  205. //protected override IQueryable<StudentTipInfo> ApplySorting(IQueryable<StudentTipInfo> query, IwbPagedRequestDto input)
  206. //{
  207. // return query.OrderBy(a => a.No);
  208. //}
  209. //protected override IQueryable<StudentTipInfo> ApplyPaging(IQueryable<StudentTipInfo> query, IwbPagedRequestDto input)
  210. //{
  211. // if (input is IPagedResultRequest pagedInput)
  212. // {
  213. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  214. // }
  215. // return query;
  216. //}
  217. #endregion Hide
  218. #endregion CURD
  219. }
  220. }