namespace SafeCampus.Application.Services.Business.CameraGroupService; public class CameraGroupService :DbRepository, ICameraGroupService { public async Task Add(CameraGroupAddInput input) { var model = input.Adapt(); var sysOrgList = await GetListAsync();//获取全部 if (sysOrgList.Any(it =>it.Name==model.Name&&it.ParentId==model.ParentId))//判断同级是否有名称重复的 throw Oops.Bah($"存在重复名称:{model.Name}"); await InsertAsync(model); return true; } public async Task Update(CameraGroupInput input) { if (!input.Id.HasValue) { throw Oops.Oh("请填写ID"); } var model = await GetFirstAsync(p => p.Id == input.Id); if (model == null) { throw Oops.Oh("信息不存在"); } if (await Context.Queryable().AnyAsync(it => it.Name == input.Name && it.ParentId == model.ParentId&&it.Id!=model.Id))//判断同级是否有名称重复的 throw Oops.Bah($"存在重复名称:{input.Name}"); var res = input.Adapt(model); await UpdateAsync(res); return true; } public async Task Delete(long id) { var cameraInfo = ChangeRepository>();//切换仓储 var model = await GetFirstAsync(x => x.Id == id); if (model == null) { throw Oops.Oh("信息不存在"); } var isOK = await cameraInfo.IsAnyAsync(x => x.GroupId == model.Id); if (isOK) { throw Oops.Oh("分组下存在摄像头,请转移至其他分组后在删除!"); } var isOK1 = await IsAnyAsync(x => x.ParentId == model.Id); if (isOK1) { throw Oops.Oh("分组下存在分组,请先删除分组下分组!"); } await DeleteAsync(model); return true; } public async Task> GetNoPageList() { var list = await Context.Queryable() .Includes(x=>x.SysUserItem) .OrderByDescending(x=>x.Id) .ToTreeAsync(x => x.Children, x => x.ParentId, null); //var list = await GetListAsync(); return list; } public async Task> GetBIList() { var list = await Context.Queryable().Includes(x => x.CameraInfos).Where(x=>x.CameraInfos.Any()).ToListAsync(); return list; } }