mem_memberextsController.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_memberexts")]
  20. public class mem_MemberextsController : BaseController
  21. {
  22. public mem_MemberextsController(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("MemberextsByPhone")]
  38. public ActionResult MemberextsByPhone([FromBody]dynamic data, QueryFilter[] filters)
  39. {
  40. int start = 0;
  41. if (data != null)
  42. {
  43. data = new { query = "select * from mem_memberbase_p where MemUsualPhone='" + data.query+"'" };
  44. }
  45. //将参数转换成JSON数据
  46. var json = JsonConvert.SerializeObject(data);
  47. //通过传来的SQL语句,转换成DSL语句
  48. string sql = Util.ElasticQuery("_sql/translate?format=json", "POST", json);
  49. //TranslateSqlResponse result = _LowLevelclient.Sql.Translate<TranslateSqlResponse>(PostData.String(json));
  50. //string sql = result.ApiCall.ResponseBodyInBytes();
  51. string from = "\"from\":" + start + ",";
  52. sql = sql.Insert(1, from);
  53. //通过转换的DSL语句,获取数据
  54. //var str = Util.ElasticQuery("mem_memberbase_p/_search?format=json", "POST", sql);
  55. int sourceIndex = sql.IndexOf("\"_source\":{");
  56. int sourceIndexEnd = sql.IndexOf("},", sourceIndex);
  57. string sourcestr = sql.Substring(sourceIndex, sourceIndexEnd - sourceIndex + 1);
  58. sql = sql.Replace(sourcestr, "\"_source\":{\"includes\":[\"*\"], \"excludes\": []}");
  59. int fieldIndex = sql.IndexOf("\"docvalue_fields\":[");
  60. int fieldIndexEnd = sql.IndexOf("],", fieldIndex);
  61. sql = sql.Remove(fieldIndex, fieldIndexEnd - fieldIndex+2);
  62. PostData dsl = sql;
  63. var result = _LowLevelclient.Search<StringResponse>("mem_memberbase_p", dsl);
  64. var DynamicObject = JsonConvert.DeserializeObject<dynamic>(result.Body);
  65. List<dynamic> source = new List<dynamic>();
  66. //总数
  67. long totalCount = 0;
  68. //JSON转Root对象
  69. //将Root对象中的子对象取出来
  70. if (DynamicObject.hits.hits.Count > 0)
  71. {
  72. HitsItem<dynamic>[] hits = DynamicObject.hits.hits.ToObject<HitsItem<dynamic>[]>();
  73. //List<mem_MemberTerminal> _source = new List<mem_MemberTerminal>(0);
  74. //_source = inerhits.Select(x => x.entity()).ToList();
  75. foreach (HitsItem<dynamic> o in hits)
  76. {
  77. o._source._id = o._id;
  78. source.Add(o._source);
  79. }
  80. totalCount = DynamicObject.hits.total.value;
  81. //var jsonData = JsonConvert.SerializeObject(_source);
  82. }
  83. return Json(
  84. new
  85. {
  86. items = source,
  87. success = true
  88. });
  89. }
  90. [HttpPost]
  91. [Route("EditMemberExts")]
  92. public ActionResult EditMemberExts([FromBody]dynamic data)
  93. {
  94. var success = false;
  95. string docId = data._id;
  96. data.Remove("_id");
  97. data["LastUpdatedDate"] = DateTime.UtcNow;
  98. var jsons = JsonConvert.SerializeObject(new{
  99. doc = data
  100. }
  101. );
  102. var param = new UpdateRequestParameters();
  103. param.Refresh = Refresh.True;
  104. var Response = _LowLevelclient.Update<StringResponse>("mem_memberbase_p",docId, jsons, param);
  105. dynamic t = JsonConvert.DeserializeObject(
  106. Response.Body
  107. );
  108. if (t.result == "updated")
  109. {
  110. success = true;
  111. }
  112. else
  113. {
  114. success = false;
  115. }
  116. return Json(
  117. new
  118. {
  119. msg = "",
  120. success = success
  121. });
  122. }
  123. }
  124. }