mem_memberexts_tempController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using CoreEntity.DAL;
  8. using CoreEntity.Entity;
  9. using CoreEntity.ESEntity;
  10. using Elasticsearch.Net;
  11. using JCSoft.WX.Framework.Api;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.Extensions.Caching.Memory;
  14. using Newtonsoft.Json;
  15. using PublicLibrary.Model;
  16. using SupplierWeb.Commonss;
  17. using SupplierWeb.Service;
  18. namespace SupplierWeb.Controllers
  19. {
  20. [Route("web/mem_memberexts_temp")]
  21. public class mem_memberexts_tempController : BaseController
  22. {
  23. public mem_memberexts_tempController(IMemoryCache cache, IApiClient client,
  24. IEsClientProvider clientProvider) : base(cache, client, clientProvider)
  25. {
  26. }
  27. public IActionResult Index()
  28. {
  29. return View();
  30. }
  31. /// <summary>
  32. /// 会员列表
  33. /// </summary>
  34. /// <param name="data"></param>
  35. /// <param name="filters"></param>
  36. /// <returns></returns>
  37. [HttpPost]
  38. [Route("MemberextsByPhone")]
  39. public ActionResult MemberextsByPhone([FromBody]dynamic data, QueryFilter[] filters)
  40. {
  41. int start = 0;
  42. var filter = "";
  43. if (data != null)
  44. {
  45. filters = data.filters.ToObject<QueryFilter[]>();
  46. filter = QueryFilter.getFilterString(filters);
  47. if (data.pageIndex == 1)
  48. {
  49. start = 0;
  50. }
  51. else
  52. {
  53. start = ((data.pageIndex - 1) * data.pageSize) + 1;
  54. }
  55. data = new { query = "select OriginType,RegionCode,AConsigneePhone2,Consignee,ADeliveryAddress,Sex,CreationDate " +
  56. " from mem_order " +
  57. " where 1 = 1 "
  58. + filter
  59. };
  60. }
  61. //将参数转换成JSON数据
  62. var json = JsonConvert.SerializeObject(data);
  63. //通过传来的SQL语句,转换成DSL语句
  64. string sql = Util.ElasticQuery("_sql/translate?format=json", "POST", json);
  65. string from = "\"from\":" + start + ",";
  66. sql = sql.Insert(1, from);
  67. int sourceIndex = sql.IndexOf("\"_source\":{");
  68. int sourceIndexEnd = sql.IndexOf("},", sourceIndex);
  69. string sourcestr = sql.Substring(sourceIndex, sourceIndexEnd - sourceIndex + 1);
  70. sql = sql.Replace(sourcestr, "\"_source\":{\"includes\":[\"OriginType\",\"RegionCode\",\"AConsigneePhone2\",\"Consignee\",\"ADeliveryAddress\",\"Sex\",\"CreationDate\"]," +
  71. " \"excludes\": []}");
  72. int fieldIndex = sql.IndexOf("\"docvalue_fields\":[");
  73. int fieldIndexEnd = sql.IndexOf("],", fieldIndex);
  74. sql = sql.Remove(fieldIndex, fieldIndexEnd - fieldIndex + 2);
  75. PostData dsl = sql;
  76. //通过转换的DSL语句,获取数据
  77. var result = _LowLevelclient.Search<StringResponse>("mem_order", dsl);
  78. var DynamicObject = JsonConvert.DeserializeObject<dynamic>(result.Body);
  79. List<dynamic> source = new List<dynamic>();
  80. if (DynamicObject.hits.hits.Count > 0)
  81. {
  82. HitsItem<dynamic>[] hits = DynamicObject.hits.hits.ToObject<HitsItem<dynamic>[]>();
  83. //List<mem_MemberTerminal> _source = new List<mem_MemberTerminal>(0);
  84. //_source = inerhits.Select(x => x.entity()).ToList();
  85. foreach (HitsItem<dynamic> o in hits)
  86. {
  87. string[] phones = new string[1];
  88. phones[0] = o._source.AConsigneePhone2;
  89. var phones1 = CommonDAL.getPhoneDecrypt(phones);
  90. string phoneStars = phones1[0];
  91. if (phoneStars != null && phoneStars.Length > 8)
  92. {
  93. string replaced = phoneStars.Substring(3, 4);
  94. phoneStars = phoneStars.Replace(replaced, "****");
  95. }
  96. o._source.AConsigneePhone2Cr = o._source.AConsigneePhone2;
  97. o._source.AConsigneePhone2 = phoneStars;
  98. o._source.AConsigneePhone2Or = phones1[0];
  99. o._source._id = o._id;
  100. DataTable dt = CommonDAL.getRegions(o._source.RegionCode.ToString());
  101. o._source.MemUsualAreaCode = dt.Rows[0].ItemArray[0];
  102. o._source.MemUsualCityCode = dt.Rows[0].ItemArray[1];
  103. o._source.MemUsualProvinceCode = dt.Rows[0].ItemArray[2];
  104. source.Add(o._source);
  105. }
  106. }
  107. //JSON转Root对象
  108. //总数
  109. long totalcount = 0;
  110. data = new { query = "select count(1) from mem_order where 1 = 1 " +
  111. filter };
  112. var jsons = JsonConvert.SerializeObject(data);
  113. string obj = Util.ElasticQuery("_sql?format=json", "POST", jsons);
  114. Num num = EsCommon.FromJSON<Num>(obj);
  115. totalcount = num.rows[0][0];
  116. return Json(
  117. new
  118. {
  119. items = source,
  120. success = true,
  121. totalCount = totalcount
  122. });
  123. }
  124. }
  125. }