using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; using CoreEntity.Entity; using CoreEntity.ESEntity; using Elasticsearch.Net; using JCSoft.WX.Framework.Api; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; using Nest; using Newtonsoft.Json; using PublicLibrary.Model; using SupplierWeb.Commonss; using SupplierWeb.Service; namespace SupplierWeb.Controllers { [Route("web/Mem_memberterminal")] public class mem_MemberTerminalController : BaseController { public mem_MemberTerminalController(IMemoryCache cache, IApiClient client, IEsClientProvider clientProvider) : base(cache, client, clientProvider) { } public IActionResult Index() { return View(); } /// /// 会员平台列表 /// /// /// /// [HttpPost] [Route("doclist")] public ActionResult terminalList([FromBody]dynamic data, QueryFilter[] filters) { int start = 0; Object query = null; string filter = null; string MemberPhone = ""; //sql = sql.Substring(0, innerHitsStart) + sqlInner; string sql = @"{ ""size"": 10, ""query"": { ""bool"": { ""must"": [ { ""term"": { ""MemUsualPhone"": { ""value"": ""{@MemUsualPhone}"", ""boost"": 1 } } }, { ""nested"": { ""query"": { ""match_all"": { ""boost"": 1 } }, ""path"": ""Terminals"", ""ignore_unmapped"": false, ""score_mode"": ""none"", ""boost"": 1, ""inner_hits"": { ""ignore_unmapped"": false, ""from"": {@from}, ""size"": {@size}, ""version"": false, ""seq_no_primary_term"": false, ""explain"": false, ""track_scores"": false, ""_source"": { ""includes"": [ ""Terminals.*"" ], ""excludes"": [] } } } } ], ""adjust_pure_negative"": true, ""boost"": 1 } }, ""_source"": false, ""stored_fields"": ""_none_"", ""docvalue_fields"": [ { ""field"": ""MemUsualPhone"" } ], ""sort"": [ { ""_doc"": { ""order"": ""asc"" } } ] }"; //通过转换的DSL语句,获取数据 sql = sql.Replace("{@from}", "" + start).Replace("{@size}", "" + data.pageSize) .Replace("{@MemUsualPhone}", MemberPhone); PostData dsl = sql; var result = _LowLevelclient.Search("mem_memberbase_p", dsl); var DynamicObject = JsonConvert.DeserializeObject(result.Body); List source = new List(); //总数 long totalCount = 0; //JSON转Root对象 //将Root对象中的子对象取出来 if (DynamicObject.hits.hits.Count > 0) { HitsItem[] inerhits = DynamicObject.hits.hits[0].inner_hits.Terminals.hits.hits.ToObject[]>(); //List _source = new List(0); //_source = inerhits.Select(x => x.entity()).ToList(); foreach(HitsItem o in inerhits) { o._source._id = o._id; source.Add(o._source); } totalCount = DynamicObject.hits.hits[0].inner_hits.Terminals.hits.total.value; //var jsonData = JsonConvert.SerializeObject(_source); } return Json( new { items = source, success = true, totalCount = totalCount }); } } }