平安校园
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

80 行
2.4 KiB

  1. namespace SafeCampus.Application.Services.Business.BuildingService;
  2. public class BuildingService:DbRepository<BuildingInfo>,IBuildingService
  3. {
  4. public async Task<bool> Add(BuildingInfoDto input)
  5. {
  6. var model = input.Adapt<BuildingInfo>();
  7. var modelold = await GetFirstAsync(p => p.Name == input.Name);
  8. if (modelold != null)
  9. {
  10. throw Oops.Oh("宿舍楼已存在");
  11. }
  12. await InsertAsync(model);
  13. return true;
  14. }
  15. public async Task<bool> Update(BuildingInfoDto input)
  16. {
  17. if (!input.Id.HasValue)
  18. {
  19. throw Oops.Oh("请填写ID");
  20. }
  21. var model = await GetFirstAsync(p => p.Id == input.Id);
  22. if (model == null)
  23. {
  24. throw Oops.Oh("信息不存在");
  25. }
  26. var res = input.Adapt(model);
  27. await UpdateAsync(res);
  28. return true;
  29. }
  30. public async Task<BuildingInfoDto> GetInfo(long id)
  31. {
  32. var model = await Context.Queryable<BuildingInfo>()
  33. .FirstAsync(x => x.Id == id);
  34. if (model == null)
  35. {
  36. return null;
  37. }
  38. return model.Adapt<BuildingInfoDto>();
  39. }
  40. public async Task<bool> Delete(long id)
  41. {
  42. var model = await GetFirstAsync(x => x.Id == id);
  43. if (model == null)
  44. {
  45. throw Oops.Oh("信息不存在");
  46. }
  47. var dor = ChangeRepository<DbRepository<DormitoryInfo>>();//切换仓储
  48. var build = await dor.GetListAsync(x=>x.BuildId==model.Id);
  49. if (build.Any())
  50. {
  51. throw Oops.Oh("宿舍楼下还有寝室不可删除!");
  52. }
  53. await DeleteAsync(model);
  54. return true;
  55. }
  56. public async Task<List<BuildingInfoDto>> GetNoPageList()
  57. {
  58. var list = await Context.Queryable<BuildingInfo>()
  59. .Includes(x => x.InsCameraInfoItem)
  60. .Includes(x => x.OutCameraInfoItem)
  61. .OrderBy(x=>x.CreateTime)
  62. .ToListAsync();
  63. //var list = await GetListAsync();
  64. return list.Adapt<List<BuildingInfoDto>>();
  65. }
  66. public async Task<List<string>> GetUseCameraList()
  67. {
  68. var list = await GetListAsync();
  69. var camera = new List<string>();
  70. camera.AddRange(list.Select(x=>x.InsCameraId));
  71. camera.AddRange(list.Select(x=>x.OutCameraId));
  72. return camera;
  73. }
  74. }