|
@@ -197,221 +197,6 @@ namespace Hotline.Api.Controllers
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
- #region IVR管理
|
|
|
-
|
|
|
- #region IVR分类
|
|
|
- /// <summary>
|
|
|
- /// 查询所有ivr分类
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.GetCategories)]
|
|
|
- [HttpGet("getcategories")]
|
|
|
- public async Task<IReadOnlyList<IvrCategory>> GetCategories()
|
|
|
- {
|
|
|
- return await _ivrCategoryRepository.QueryExtAsync(d => true, d => d.Includes(x => x.Ivrs));
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 查询ivr分类(含ivr)
|
|
|
- /// </summary>
|
|
|
- /// <param name="id"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.GetCategorie)]
|
|
|
- [HttpGet("category/{id}")]
|
|
|
- public async Task<IvrCategory> GetCategory(string id)
|
|
|
- {
|
|
|
- return await _ivrCategoryRepository.GetExtAsync(d => d.Id == id, d => d.Includes(x => x.Ivrs));
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 新增IVR分类
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.AddCategory)]
|
|
|
- [HttpPost("add-category")]
|
|
|
- public async Task<string> AddCategory([FromBody] AddIvrCategoryDto request)
|
|
|
- {
|
|
|
- var category = _mapper.Map<IvrCategory>(request);
|
|
|
- return await _ivrCategoryRepository.AddAsync(category, HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 更新IVR分类
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.UpdateCategory)]
|
|
|
- [HttpPut("update-category")]
|
|
|
- public async Task UpdateCategory([FromBody] UpdateIvrCategoryDto request)
|
|
|
- {
|
|
|
- var category = _mapper.Map<IvrCategory>(request);
|
|
|
- await _ivrCategoryRepository.UpdateAsync(category, HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 删除分类,含分类下所有IVR
|
|
|
- /// </summary>
|
|
|
- /// <param name="id"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.RemoveCategory)]
|
|
|
- [HttpDelete("removecategory/{id}")]
|
|
|
- public async Task RemoveCategory(string id)
|
|
|
- {
|
|
|
- var category = await _ivrCategoryRepository.GetExtAsync(d => d.Id == id, d => d.Includes(x => x.Ivrs));
|
|
|
- await _ivrRepository.RemoveRangeAsync(category.Ivrs, HttpContext.RequestAborted);
|
|
|
- await _ivrCategoryRepository.RemoveAsync(category);
|
|
|
- _cacheIvrList.Remove(Ivr.Key);
|
|
|
- }
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region IVR
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 新增IVR
|
|
|
- /// </summary>
|
|
|
- /// <param name="dto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.AddIvr)]
|
|
|
- [HttpPost("add-ivr")]
|
|
|
- public async Task<string> AddIvr([FromBody] AddIvrDto dto)
|
|
|
- {
|
|
|
- var ivr = _mapper.Map<Ivr>(dto);
|
|
|
- return await _ivrDomainService.AddIvrAsync(ivr, HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 更新IVR
|
|
|
- /// </summary>
|
|
|
- /// <param name="dto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.UpdateIvr)]
|
|
|
- [HttpPut("update-ivr")]
|
|
|
- public async Task UpdateIvr([FromBody] UpdateIvrDto dto)
|
|
|
- {
|
|
|
- var ivr = await _ivrRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
- _mapper.Map(dto, ivr);
|
|
|
- await _ivrDomainService.UpdateIvrAsync(ivr, HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 构建IVR关系
|
|
|
- /// </summary>
|
|
|
- /// <param name="dto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- /// <exception cref="UserFriendlyException"></exception>
|
|
|
- [Permission(EPermission.Structure)]
|
|
|
- [HttpPost("structure")]
|
|
|
- public async Task Structure([FromBody] StructureIvrDto dto)
|
|
|
- {
|
|
|
- await _ivrDomainService.StructureIvrAsync(dto, HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 删除IVR关系(并非删除IVR)
|
|
|
- /// </summary>
|
|
|
- /// <param name="ivrId"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.DeStructureIvr)]
|
|
|
- [HttpPut("destructure/{ivrId}")]
|
|
|
- public async Task DeStructureIvr(string ivrId)
|
|
|
- {
|
|
|
- await _ivrDomainService.DeStructureIvrAsync(ivrId, HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 替换某个IVR分组下的起始IVR(根节点)
|
|
|
- /// </summary>
|
|
|
- /// <param name="ivrId"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.ReplaceRoot)]
|
|
|
- [HttpPut("replace-root/{ivrId}")]
|
|
|
- public async Task ReplaceRootAsync(string ivrId)
|
|
|
- {
|
|
|
- await _ivrDomainService.ReplaceRootAsync(ivrId, HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 查询所有ivr
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.QueryIvrs)]
|
|
|
- [HttpGet("query-ivrs")]
|
|
|
- public async Task<IReadOnlyList<IvrDto>> QueryIvrs()
|
|
|
- {
|
|
|
- var ivrs = await _ivrRepository.QueryAsync();
|
|
|
- return _mapper.Map<IReadOnlyList<IvrDto>>(ivrs);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 查询ivr分类,以树形结构返回IVR关系
|
|
|
- /// </summary>
|
|
|
- /// <param name="categoryId"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.GetBeginingIvr)]
|
|
|
- [HttpGet("tree/{categoryId}")]
|
|
|
- public async Task<IvrDto> GetBeginingIvrAsync(string categoryId)
|
|
|
- {
|
|
|
- ////todo 1.
|
|
|
- ////超过1个根节点则视为未配置完成
|
|
|
- //var count = await _ivrRepository.CountAsync(
|
|
|
- // d => d.IvrCategoryId == categoryId && string.IsNullOrEmpty(d.PrevIvrNo), HttpContext.RequestAborted);
|
|
|
- //if (count > 1)
|
|
|
- // return null;
|
|
|
- var ivrs = await _ivrRepository.QueryAsync(d => d.IvrCategoryId == categoryId);
|
|
|
- var rootIvr = ivrs.FirstOrDefault(d => d.IsRoot);
|
|
|
- if (rootIvr == null)
|
|
|
- throw new UserFriendlyException("每个IVR分类至少存在一个根节点");
|
|
|
- var rootDto = _mapper.Map<IvrDto>(rootIvr);
|
|
|
- BuildIvrTree(ivrs, rootDto);
|
|
|
- return rootDto;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 查询语音文件
|
|
|
- /// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.VoiceQueryList)]
|
|
|
- [HttpGet("voicequerylist")]
|
|
|
- public async Task<List<string>> VoiceQueryList()
|
|
|
- {
|
|
|
- return await _voiceFileDomainService.VoiceQueryListAsync(HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 删除语音文件
|
|
|
- /// </summary>
|
|
|
- /// <param name="voiceFileName"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [Permission(EPermission.RemoveVoiceFile)]
|
|
|
- [HttpPost("removevoicefile")]
|
|
|
- public async Task RemoveVoiceFile(string voiceFileName)
|
|
|
- {
|
|
|
- await _voiceFileDomainService.RemoveVoiceFileAsync(new RemoveVoiceFileRequest(voiceFileName), HttpContext.RequestAborted);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- #region private
|
|
|
-
|
|
|
- private void BuildIvrTree(List<Ivr> ivrs, IvrDto dto)
|
|
|
- {
|
|
|
- var children = ivrs.Where(d => d.PrevIvrNo == dto.No && !d.IsRoot).ToList();
|
|
|
- if (!children.Any()) return;
|
|
|
- dto.ChildIvrs = _mapper.Map<IReadOnlyList<IvrDto>>(children);
|
|
|
- foreach (var dtoChildIvr in dto.ChildIvrs)
|
|
|
- {
|
|
|
- BuildIvrTree(ivrs, dtoChildIvr);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
#region 话机设备操作
|
|
|
|
|
|
/// <summary>
|