平安校园
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.
 
 
 
 
 
 

71 regels
2.5 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. if (await Context.Queryable<CameraGroup>().AnyAsync(it => it.Name == input.Name && it.ParentId == model.ParentId&&it.Id!=model.Id))//判断同级是否有名称重复的
  25. throw Oops.Bah($"存在重复名称:{input.Name}");
  26. var res = input.Adapt(model);
  27. await UpdateAsync(res);
  28. return true;
  29. }
  30. public async Task<bool> Delete(long id)
  31. {
  32. var cameraInfo = ChangeRepository<DbRepository<CameraInfo>>();//切换仓储
  33. var model = await GetFirstAsync(x => x.Id == id);
  34. if (model == null)
  35. {
  36. throw Oops.Oh("信息不存在");
  37. }
  38. var isOK = await cameraInfo.IsAnyAsync(x => x.GroupId == model.Id);
  39. if (isOK)
  40. {
  41. throw Oops.Oh("分组下存在摄像头,请转移至其他分组后在删除!");
  42. }
  43. var isOK1 = await IsAnyAsync(x => x.ParentId == model.Id);
  44. if (isOK1)
  45. {
  46. throw Oops.Oh("分组下存在分组,请先删除分组下分组!");
  47. }
  48. await DeleteAsync(model);
  49. return true;
  50. }
  51. public async Task<List<CameraGroup>> GetNoPageList()
  52. {
  53. var list = await Context.Queryable<CameraGroup>()
  54. .Includes(x=>x.SysUserItem)
  55. .OrderByDescending(x=>x.Id)
  56. .ToTreeAsync(x => x.Children, x => x.ParentId, null);
  57. //var list = await GetListAsync();
  58. return list;
  59. }
  60. public async Task<List<CameraGroup>> GetBIList()
  61. {
  62. var list = await Context.Queryable<CameraGroup>().Includes(x => x.CameraInfos).Where(x=>x.CameraInfos.Any()).ToListAsync();
  63. return list;
  64. }
  65. }