平安校园
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

64 lines
2.1 KiB

  1. namespace SafeCampus.Application.Services.Business.CameraGroupService;
  2. public class CameraGroupService :DbRepository<CameraGroup>, ICameraGroupService
  3. {
  4. public async Task<bool> Add(CameraGroupAddInput input)
  5. {
  6. var model = input.Adapt<CameraGroup>();
  7. var sysOrgList = await GetListAsync();//获取全部
  8. if (sysOrgList.Any(it =>it.Name==model.Name&&it.ParentId==model.ParentId))//判断同级是否有名称重复的
  9. throw Oops.Bah($"存在重复名称:{model.Name}");
  10. await InsertAsync(model);
  11. return true;
  12. }
  13. public async Task<bool> Update(CameraGroupInput input)
  14. {
  15. if (!input.Id.HasValue)
  16. {
  17. throw Oops.Oh("请填写ID");
  18. }
  19. var model = await GetFirstAsync(p => p.Id == input.Id);
  20. if (model == null)
  21. {
  22. throw Oops.Oh("信息不存在");
  23. }
  24. var res = input.Adapt(model);
  25. await UpdateAsync(res);
  26. return true;
  27. }
  28. public async Task<bool> Delete(long id)
  29. {
  30. var cameraInfo = ChangeRepository<DbRepository<CameraInfo>>();//切换仓储
  31. var model = await GetFirstAsync(x => x.Id == id);
  32. if (model == null)
  33. {
  34. throw Oops.Oh("信息不存在");
  35. }
  36. var isOK = await cameraInfo.IsAnyAsync(x => x.GroupId == model.Id);
  37. if (isOK)
  38. {
  39. throw Oops.Oh("分组下存在摄像头,请转移至其他分组后在删除!");
  40. }
  41. await DeleteAsync(model);
  42. return true;
  43. }
  44. public async Task<List<CameraGroup>> GetNoPageList()
  45. {
  46. var list = await Context.Queryable<CameraGroup>()
  47. .Includes(x=>x.SysUserItem)
  48. .OrderByDescending(x=>x.Id)
  49. .ToTreeAsync(x => x.Children, x => x.ParentId, null);
  50. //var list = await GetListAsync();
  51. return list;
  52. }
  53. public async Task<List<CameraGroup>> GetBIList()
  54. {
  55. var list = await Context.Queryable<CameraGroup>().Includes(x => x.CameraInfos).Where(x=>x.CameraInfos.Any()).ToListAsync();
  56. return list;
  57. }
  58. }