using Hotline.CallCenter.Calls; using Hotline.CallCenter.Tels; using Hotline.Repository.SqlSugar.DataPermissions; using SqlSugar; using XF.Domain.Dependency; namespace Hotline.Repository.SqlSugar.CallCenter { public class TelHoldRepository : BaseRepository, ITelHoldRepository, IScopeDependency { public TelHoldRepository(ISugarUnitOfWork uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder) : base(uow, dataPermissionFilterBuilder) { } /// /// 通话是否保持 /// /// /// /// /// /// public Task IsHoldingAsync(string telId, string userId, string callId, CancellationToken cancellationToken) { return Db.Queryable().AnyAsync(x => x.TelId == telId && x.UserId == userId && x.CallId == callId && !x.EndTime.HasValue); } /// /// 处理Hold时间计算 /// /// /// /// /// public async Task HandleHoldTime(string callId, string endTime, CancellationToken cancellationToken) { var model = await Db.Queryable().FirstAsync(x => x.Id == callId); if (model!=null) { var list = await Db.Queryable().Where(x => x.CallId == callId && !x.EndTime.HasValue).ToListAsync(); if (list.Any()) { foreach (var item in list) { item.EndHold(); Db.Updateable(item); } } var duration = await Db.Queryable().Where(x => x.CallId == callId).SumAsync(x=>x.HoldDuration); model.HoldDuration = Convert.ToInt32(duration); Db.Updateable(model); } } } }