|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- namespace SafeCampus.Application.Services.Business.CameraGroupService;
-
- public class CameraGroupService :DbRepository<CameraGroup>, ICameraGroupService
- {
- public async Task<bool> Add(CameraGroupAddInput input)
- {
- var model = input.Adapt<CameraGroup>();
- 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<bool> 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<CameraGroup>().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<bool> Delete(long id)
- {
- var cameraInfo = ChangeRepository<DbRepository<CameraInfo>>();//切换仓储
- 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<List<CameraGroup>> GetNoPageList()
- {
- var list = await Context.Queryable<CameraGroup>()
- .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<List<CameraGroup>> GetBIList()
- {
- var list = await Context.Queryable<CameraGroup>().Includes(x => x.CameraInfos).Where(x=>x.CameraInfos.Any()).ToListAsync();
- return list;
- }
- }
|