CalendarAppServiceBase.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System.Linq.Expressions;
  2. using Abp.Auditing;
  3. using Abp.Authorization;
  4. using Abp.Specifications;
  5. using Abp.UI;
  6. using VberZero.AppService.Base;
  7. using VberZero.AppService.Base.Dto;
  8. using VberZero.AppService.Calendars.Dto;
  9. using VberZero.Auditing;
  10. using VberZero.BaseSystem;
  11. using VberZero.DomainService.Calendar;
  12. using VberZero.Tools.StringModel;
  13. namespace VberZero.AppService.Calendars;
  14. [AbpAuthorize, AuditLog("日程管理", "日程")]
  15. public class CalendarAppServiceBase : VzAppServiceBase, ICalendarAppServiceBase
  16. {
  17. public CalendarAppServiceBase()
  18. {
  19. CalendarManger = NullCalendarManger.Instance;
  20. }
  21. public ICalendarManger CalendarManger { get; set; }
  22. [DisableAuditing]
  23. public async Task<List<CalendarDto>> GetAll(VzPagedRequestDto input)
  24. {
  25. Expression<Func<SysCalendar, bool>> exp = a => a.OwnerId == AbpSession.UserId && a.Start != null;
  26. foreach (var search in input.SearchList)
  27. {
  28. if (search.KeyField.ToLower() == "start" && DateTime.TryParse(search.KeyWords, out var start))
  29. {
  30. exp = exp.And(a => DateTime.Compare(a.Start.Value, start) >= 0);
  31. }
  32. if (search.KeyField.ToLower() == "end" && DateTime.TryParse(search.KeyWords, out var end))
  33. {
  34. exp = exp.And(a => DateTime.Compare(a.Start.Value, end) < 0);
  35. }
  36. }
  37. var entities = await CalendarManger.GetAllList(exp);
  38. return entities.Select(MapToDto).ToList();
  39. }
  40. public async Task<List<CalendarDto>> GetNotStartList()
  41. {
  42. var entities = await CalendarManger.GetAllList(a => a.OwnerId == AbpSession.UserId && a.Start == null);
  43. return entities.Select(MapToDto).ToList();
  44. }
  45. public async Task<CalendarDto> Get(int id)
  46. {
  47. var entity = await CalendarManger.GetById(id);
  48. return MapToDto(entity);
  49. }
  50. public virtual async Task<CalendarDto> Create(CreateCalendarDto input)
  51. {
  52. if (input.Start != null && DateTime.Compare(input.Start.Value, DateTime.Today) <= 0)
  53. {
  54. CheckErrors("日程时间不能早于当前时间!");
  55. }
  56. var info = ObjectMapper.Map<SysCalendar>(input);
  57. info.OwnerId = AbpSession.UserId;
  58. info.IsNotify = !input.NotifyType.Empty();
  59. var entity = await CalendarManger.Create(info);
  60. return MapToDto(entity);
  61. }
  62. public virtual async Task<CalendarDto> Update(UpdateCalendarDto input)
  63. {
  64. input.Start = input.Start == DateTime.MinValue ? null : input.Start;
  65. if (input.Start != null && DateTime.Compare(input.Start.Value, DateTime.Today) < 0)
  66. {
  67. CheckErrors("日程时间不能早于当前时间!");
  68. }
  69. input.End = input.End == DateTime.MinValue ? null : input.End;
  70. if (input.End != null && DateTime.Compare(input.End.Value, DateTime.Today) < 0)
  71. {
  72. CheckErrors("日程时间不能早于当前时间!");
  73. }
  74. if (input.Start != null && input.End != null && DateTime.Compare(input.End.Value, input.Start.Value) < 0)
  75. {
  76. CheckErrors("日程结束时间不能早于开始时间!");
  77. }
  78. var entity = await CalendarManger.GetById(input.Id);
  79. if (entity == null)
  80. {
  81. throw new UserFriendlyException("没有查询到日程!");
  82. }
  83. var info = ObjectMapper.Map(input, entity);
  84. info.IsNotify = !input.NotifyType.Empty();
  85. entity = await CalendarManger.Update(info);
  86. return MapToDto(entity);
  87. }
  88. public virtual Task Delete(int id)
  89. {
  90. return CalendarManger.Delete(id);
  91. }
  92. private CalendarDto MapToDto(SysCalendar entity)
  93. {
  94. var dto = ObjectMapper.Map<CalendarDto>(entity);
  95. return dto;
  96. }
  97. }