平安校园
 
 
 
 
 
 

79 lines
3.4 KiB

  1. namespace SafeCampus.Application.Services.Business.ClassRoomCallService;
  2. public class ClassRoomCallService : DbRepository<ClassRoomCall>, IClassRoomCallService
  3. {
  4. public async Task<bool> Add(ClassRoomCallDto input)
  5. {
  6. var model = input.Adapt<ClassRoomCall>();
  7. await InsertAsync(model);
  8. return true;
  9. }
  10. public async Task<bool> Update(ClassRoomCallUpdate input)
  11. {
  12. var model = await GetFirstAsync(p => p.Id == input.Id);
  13. if (model == null)
  14. {
  15. throw Oops.Oh("信息不存在");
  16. }
  17. //var res = input.Adapt(model);
  18. model.PersonSetId = input.PersonSetId;
  19. model.PersonId = input.PersonId;
  20. await Context.Updateable<ClassRoomCall>()
  21. .UpdateColumns(x => new
  22. {
  23. x.PersonSetId,
  24. x.PersonId
  25. })
  26. .ExecuteCommandAsync();
  27. //await UpdateAsync(model);
  28. return true;
  29. }
  30. public async Task<bool> Remove(long id)
  31. {
  32. var model = await GetFirstAsync(x => x.Id == id);
  33. if (model == null)
  34. {
  35. throw Oops.Oh("信息不存在");
  36. }
  37. await DeleteAsync(model);
  38. return true;
  39. }
  40. public async Task<SqlSugarPagedList<ClassRoomCallList>> GetPageList(ClassRoomCallSearch search)
  41. {
  42. var query = Context.Queryable<ClassRoomCall>()
  43. .Includes(x => x.CameraInfoItem)
  44. .WhereIF(!string.IsNullOrEmpty(search.AlarmType), x => x.AlarmType == search.AlarmType)
  45. .WhereIF(!string.IsNullOrEmpty(search.CameraId), x => x.CameraId == search.CameraId)
  46. .WhereIF(!string.IsNullOrEmpty(search.PersonSetId), x => x.PersonSetId == search.PersonSetId)
  47. .WhereIF(!string.IsNullOrEmpty(search.TaskId), x => x.TaskId == search.TaskId)
  48. .WhereIF(!string.IsNullOrEmpty(search.TrackId), x => x.TrackId == search.TrackId)
  49. .WhereIF(!string.IsNullOrEmpty(search.PersonId), x => x.PersonId == search.PersonId)
  50. .WhereIF(search.StartTick.HasValue, x => x.Tick >= search.StartTick)
  51. .WhereIF(search.EndTick.HasValue, x => x.Tick <= search.EndTick);
  52. var list = await query.OrderByDescending(x => x.Tick)
  53. .ToPagedListAsyncMapster<ClassRoomCall, ClassRoomCallList>(search.PageNum, search.PageSize);
  54. return list;
  55. }
  56. public async Task<List<ClassRoomCallList>> GetNoPageList(ClassRoomCallSearch search)
  57. {
  58. var query = Context.Queryable<ClassRoomCall>()
  59. .Includes(x => x.CameraInfoItem)
  60. .WhereIF(!string.IsNullOrEmpty(search.AlarmType), x => x.AlarmType == search.AlarmType)
  61. .WhereIF(!string.IsNullOrEmpty(search.CameraId), x => x.CameraId == search.CameraId)
  62. .WhereIF(!string.IsNullOrEmpty(search.PersonSetId), x => x.PersonSetId == search.PersonSetId)
  63. .WhereIF(!string.IsNullOrEmpty(search.TaskId), x => x.TaskId == search.TaskId)
  64. .WhereIF(!string.IsNullOrEmpty(search.TrackId), x => x.TrackId == search.TrackId)
  65. .WhereIF(!string.IsNullOrEmpty(search.PersonId), x => x.PersonId == search.PersonId)
  66. .WhereIF(search.StartTick.HasValue, x => x.Tick >= search.StartTick)
  67. .WhereIF(search.EndTick.HasValue, x => x.Tick <= search.EndTick);
  68. var list = await query.OrderByDescending(x => x.Tick)
  69. .ToListAsync();
  70. return list.Adapt<List<ClassRoomCallList>>();
  71. }
  72. }