平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

85 lines
4.2 KiB

  1. using IP2Region.Net.XDB;
  2. using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
  3. namespace SafeCampus.Application.Services.Business.AttendanceService;
  4. public class AttendanceService:DbRepository<Attendance>, IAttendanceService
  5. {
  6. public async Task<bool> Add(AttendanceDto input)
  7. {
  8. var buildingInfo = ChangeRepository<DbRepository<BuildingInfo>>();//切换仓储
  9. var build = await buildingInfo.GetListAsync();
  10. var model = input.Adapt<Attendance>();
  11. //if (string.IsNullOrEmpty(model.PersonId))
  12. //{
  13. // if (await IsAnyAsync(x => x.TaskId == model.TaskId && x.PersonId == model.PersonId && x.PersonSetId == model.PersonSetId))
  14. // {
  15. // //该批次点名任务已经出现过这个人,不在重复添加
  16. // return true;
  17. // }
  18. //}
  19. //else
  20. //{
  21. // if (await IsAnyAsync(x => x.TaskId == model.TaskId && x.TrackId == model.TrackId))
  22. // {
  23. // //没有匹配到人员,但是所属同一跟踪id
  24. // //该批次点名任务已经出现过这个人,不在重复添加
  25. // return true;
  26. // }
  27. //}
  28. model.InsOut = build.Any(x=>x.InsCameraId==model.CameraId);
  29. await InsertAsync(model);
  30. return true;
  31. }
  32. public async Task<SqlSugarPagedList<AttendanceList>> GetPageList(AttendanceSearch search)
  33. {
  34. var query = Context.Queryable<Attendance>()
  35. //.Includes(x => x.CameraInfoItem)
  36. .WhereIF(search.IsAuto.HasValue, x => x.IsAuto == search.IsAuto)
  37. .WhereIF(!string.IsNullOrEmpty(search.PersonSetId), x => x.PersonSetId == search.PersonSetId)
  38. .WhereIF(!string.IsNullOrEmpty(search.PersonId), x => x.PersonId == search.PersonId)
  39. .WhereIF(!string.IsNullOrEmpty(search.TrackId), x => x.TrackId == search.TrackId)
  40. .WhereIF(!string.IsNullOrEmpty(search.CameraId), x => x.CameraId == search.CameraId)
  41. .WhereIF(search.StartTick.HasValue, x => x.Tick >= search.StartTick)
  42. .WhereIF(search.EndTick.HasValue, x => x.Tick <= search.EndTick);
  43. var list = await query.OrderByDescending(x => x.Tick)
  44. .ToPagedListAsyncMapster<Attendance, AttendanceList>(search.PageNum, search.PageSize);
  45. return list;
  46. }
  47. public async Task<List<AttendanceList>> GetNoPageList(AttendanceSearch search)
  48. {
  49. var query = Context.Queryable<Attendance>()
  50. //.Includes(x => x.CameraInfoItem)
  51. .Includes(x=>x.PersonInfoItem,x=>x.DormitoryInfoItem)
  52. .Includes(x=>x.PersonInfoItem,x=>x.PersonSetInfoItem)
  53. .WhereIF(search.IsAuto.HasValue, x => x.IsAuto == search.IsAuto)
  54. .WhereIF(!string.IsNullOrEmpty(search.PersonSetId), x => x.PersonSetId == search.PersonSetId)
  55. .WhereIF(!string.IsNullOrEmpty(search.PersonId), x => x.PersonId == search.PersonId)
  56. .WhereIF(!string.IsNullOrEmpty(search.TrackId), x => x.TrackId == search.TrackId)
  57. .WhereIF(!string.IsNullOrEmpty(search.CameraId), x => x.CameraId == search.CameraId)
  58. .WhereIF(search.CameraIds!=null&&search.CameraIds.Any(),x=>search.CameraIds.Contains(x.CameraId))
  59. .WhereIF(search.StartTick.HasValue, x => x.Tick >= search.StartTick)
  60. .WhereIF(search.EndTick.HasValue, x => x.Tick <= search.EndTick);
  61. var list = await query.OrderByDescending(x => x.Tick)
  62. .ToListAsync();
  63. return list.Adapt<List<AttendanceList>>();
  64. }
  65. public async Task<SqlSugarPagedList<AttendanceList>> GetPageListByBuild(BuildAttendanceSearch search)
  66. {
  67. var buildingInfo = ChangeRepository<DbRepository<BuildingInfo>>();//切换仓储
  68. var build = await buildingInfo.GetFirstAsync(x => x.Id == search.BuildId);
  69. var query = Context.Queryable<Attendance>()
  70. //.Includes(x => x.CameraInfoItem)
  71. .Where(x=>x.CameraId==build.InsCameraId||x.CameraId==build.OutCameraId)
  72. .WhereIF(search.IsAuto.HasValue, x => x.IsAuto == search.IsAuto);
  73. var list = await query.OrderByDescending(x => x.Tick)
  74. .ToPagedListAsyncMapster<Attendance, AttendanceList>(search.PageNum, search.PageSize);
  75. return list;
  76. }
  77. }