Mem_memberterminalController.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using CoreEntity.Entity;
  7. using CoreEntity.ESEntity;
  8. using Elasticsearch.Net;
  9. using JCSoft.WX.Framework.Api;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.Extensions.Caching.Memory;
  12. using Nest;
  13. using Newtonsoft.Json;
  14. using PublicLibrary.Model;
  15. using SupplierWeb.Commonss;
  16. using SupplierWeb.Service;
  17. namespace SupplierWeb.Controllers
  18. {
  19. [Route("web/Mem_memberterminal")]
  20. public class mem_MemberTerminalController : BaseController
  21. {
  22. public mem_MemberTerminalController(IMemoryCache cache, IApiClient client,
  23. IEsClientProvider clientProvider) : base(cache, client, clientProvider)
  24. {
  25. }
  26. public IActionResult Index()
  27. {
  28. return View();
  29. }
  30. /// <summary>
  31. /// 会员平台列表
  32. /// </summary>
  33. /// <param name="data"></param>
  34. /// <param name="filters"></param>
  35. /// <returns></returns>
  36. [HttpPost]
  37. [Route("doclist")]
  38. public ActionResult terminalList([FromBody]dynamic data, QueryFilter[] filters)
  39. {
  40. int start = 0;
  41. Object query = null;
  42. string filter = null;
  43. string MemberPhone = "";
  44. //sql = sql.Substring(0, innerHitsStart) + sqlInner;
  45. string sql = @"{
  46. ""size"": 10,
  47. ""query"": {
  48. ""bool"": {
  49. ""must"": [
  50. {
  51. ""term"": {
  52. ""MemUsualPhone"": {
  53. ""value"": ""{@MemUsualPhone}"",
  54. ""boost"": 1
  55. }
  56. }
  57. },
  58. {
  59. ""nested"": {
  60. ""query"": {
  61. ""match_all"": {
  62. ""boost"": 1
  63. }
  64. },
  65. ""path"": ""Terminals"",
  66. ""ignore_unmapped"": false,
  67. ""score_mode"": ""none"",
  68. ""boost"": 1,
  69. ""inner_hits"": {
  70. ""ignore_unmapped"": false,
  71. ""from"": {@from},
  72. ""size"": {@size},
  73. ""version"": false,
  74. ""seq_no_primary_term"": false,
  75. ""explain"": false,
  76. ""track_scores"": false,
  77. ""_source"": {
  78. ""includes"": [
  79. ""Terminals.*""
  80. ],
  81. ""excludes"": []
  82. }
  83. }
  84. }
  85. }
  86. ],
  87. ""adjust_pure_negative"": true,
  88. ""boost"": 1
  89. }
  90. },
  91. ""_source"": false,
  92. ""stored_fields"": ""_none_"",
  93. ""docvalue_fields"": [
  94. {
  95. ""field"": ""MemUsualPhone""
  96. }
  97. ],
  98. ""sort"": [
  99. {
  100. ""_doc"": {
  101. ""order"": ""asc""
  102. }
  103. }
  104. ]
  105. }";
  106. //通过转换的DSL语句,获取数据
  107. sql = sql.Replace("{@from}", "" + start).Replace("{@size}", "" + data.pageSize)
  108. .Replace("{@MemUsualPhone}", MemberPhone);
  109. PostData dsl = sql;
  110. var result = _LowLevelclient.Search<StringResponse>("mem_memberbase_p", dsl);
  111. var DynamicObject = JsonConvert.DeserializeObject<dynamic>(result.Body);
  112. List<dynamic> source = new List<dynamic>();
  113. //总数
  114. long totalCount = 0;
  115. //JSON转Root对象
  116. //将Root对象中的子对象取出来
  117. if (DynamicObject.hits.hits.Count > 0) {
  118. HitsItem<dynamic>[] inerhits = DynamicObject.hits.hits[0].inner_hits.Terminals.hits.hits.ToObject<HitsItem<dynamic>[]>();
  119. //List<mem_MemberTerminal> _source = new List<mem_MemberTerminal>(0);
  120. //_source = inerhits.Select(x => x.entity()).ToList();
  121. foreach(HitsItem <dynamic> o in inerhits)
  122. {
  123. o._source._id = o._id;
  124. source.Add(o._source);
  125. }
  126. totalCount = DynamicObject.hits.hits[0].inner_hits.Terminals.hits.total.value;
  127. //var jsonData = JsonConvert.SerializeObject(_source);
  128. }
  129. return Json(
  130. new
  131. {
  132. items = source,
  133. success = true,
  134. totalCount = totalCount
  135. });
  136. }
  137. }
  138. }