public async Task <ActionResult> DeleteBatchAsync([FromBody] DeleteBatchModel <long> deleteBatchModel) { if (deleteBatchModel == null) { return(BadRequest(MessageFactory.CreateParamsIsNullMessage())); } var result = await commandDemoService.DeleteBatchAsync(deleteBatchModel).ConfigureAwait(false); return(Ok(result)); }
/// <summary> /// 批量删除索引 /// </summary> /// <typeparam name="TPrimaryKeyType"></typeparam> /// <param name="ids"></param> /// <param name="routing"></param> /// <returns></returns> public async Task <HttpResponseResultModel <bool> > DeleteBatchAsync <TPrimaryKeyType>(DeleteBatchModel <TPrimaryKeyType> deleteBatchModel) { HttpResponseResultModel <bool> httpResponseResultModel = new HttpResponseResultModel <bool>(); string indexName = deleteBatchModel.IndexName?.ToLower(); if (string.IsNullOrEmpty(indexName)) { indexName = PocoIndexName; } BulkDescriptor bulkDescriptor = new BulkDescriptor(); foreach (var id in deleteBatchModel.IdList) { bulkDescriptor.AddOperation(new BulkDeleteOperation <TEntity>(id.ToString())); } bulkDescriptor.Index(indexName); if (!string.IsNullOrEmpty(deleteBatchModel.Routing)) { bulkDescriptor.Routing(new Routing(deleteBatchModel.Routing)); } var result = await client.BulkAsync(bulkDescriptor).ConfigureAwait(false); GetDebugInfo(result); var isSuccess = result.ItemsWithErrors.IsListNullOrEmpty(); httpResponseResultModel.IsSuccess = isSuccess; string errorMessage = ""; if (!isSuccess) { var errorIdList = result.ItemsWithErrors.Select(t => t.Id); errorMessage = string.Join(",", errorIdList); } httpResponseResultModel.ErrorMessage = errorMessage; return(httpResponseResultModel); }
/// <summary> /// 批量删除 根据主键 /// </summary> /// <param name="deleteBatchModel"></param> /// <returns></returns> public async Task <HttpResponseResultModel <bool> > DeleteBatchAsync(DeleteBatchModel <long> deleteBatchModel) { return(await repository.DeleteBatchAsync(deleteBatchModel).ConfigureAwait(false)); }