using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; using CoreEntity.DAL; using CoreEntity.Entity; using CoreEntity.ESEntity; using Elasticsearch.Net; using JCSoft.WX.Framework.Api; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; using Newtonsoft.Json; using PublicLibrary.Model; using SupplierWeb.Commonss; using SupplierWeb.Service; namespace SupplierWeb.Controllers { [Route("web/mem_memberexts_temp")] public class mem_memberexts_tempController : BaseController { public mem_memberexts_tempController(IMemoryCache cache, IApiClient client, IEsClientProvider clientProvider) : base(cache, client, clientProvider) { } public IActionResult Index() { return View(); } /// /// 会员列表 /// /// /// /// [HttpPost] [Route("MemberextsByPhone")] public ActionResult MemberextsByPhone([FromBody]dynamic data, QueryFilter[] filters) { int start = 0; var filter = ""; if (data != null) { filters = data.filters.ToObject(); filter = QueryFilter.getFilterString(filters); if (data.pageIndex == 1) { start = 0; } else { start = ((data.pageIndex - 1) * data.pageSize) + 1; } data = new { query = "select OriginType,RegionCode,AConsigneePhone2,Consignee,ADeliveryAddress,Sex,CreationDate " + " from mem_order " + " where 1 = 1 " + filter }; } //将参数转换成JSON数据 var json = JsonConvert.SerializeObject(data); //通过传来的SQL语句,转换成DSL语句 string sql = Util.ElasticQuery("_sql/translate?format=json", "POST", json); string from = "\"from\":" + start + ","; sql = sql.Insert(1, from); int sourceIndex = sql.IndexOf("\"_source\":{"); int sourceIndexEnd = sql.IndexOf("},", sourceIndex); string sourcestr = sql.Substring(sourceIndex, sourceIndexEnd - sourceIndex + 1); sql = sql.Replace(sourcestr, "\"_source\":{\"includes\":[\"OriginType\",\"RegionCode\",\"AConsigneePhone2\",\"Consignee\",\"ADeliveryAddress\",\"Sex\",\"CreationDate\"]," + " \"excludes\": []}"); int fieldIndex = sql.IndexOf("\"docvalue_fields\":["); int fieldIndexEnd = sql.IndexOf("],", fieldIndex); sql = sql.Remove(fieldIndex, fieldIndexEnd - fieldIndex + 2); PostData dsl = sql; //通过转换的DSL语句,获取数据 var result = _LowLevelclient.Search("mem_order", dsl); var DynamicObject = JsonConvert.DeserializeObject(result.Body); List source = new List(); if (DynamicObject.hits.hits.Count > 0) { HitsItem[] hits = DynamicObject.hits.hits.ToObject[]>(); //List _source = new List(0); //_source = inerhits.Select(x => x.entity()).ToList(); foreach (HitsItem o in hits) { string[] phones = new string[1]; phones[0] = o._source.AConsigneePhone2; var phones1 = CommonDAL.getPhoneDecrypt(phones); string phoneStars = phones1[0]; if (phoneStars != null && phoneStars.Length > 8) { string replaced = phoneStars.Substring(3, 4); phoneStars = phoneStars.Replace(replaced, "****"); } o._source.AConsigneePhone2Cr = o._source.AConsigneePhone2; o._source.AConsigneePhone2 = phoneStars; o._source.AConsigneePhone2Or = phones1[0]; o._source._id = o._id; DataTable dt = CommonDAL.getRegions(o._source.RegionCode.ToString()); o._source.MemUsualAreaCode = dt.Rows[0].ItemArray[0]; o._source.MemUsualCityCode = dt.Rows[0].ItemArray[1]; o._source.MemUsualProvinceCode = dt.Rows[0].ItemArray[2]; source.Add(o._source); } } //JSON转Root对象 //总数 long totalcount = 0; data = new { query = "select count(1) from mem_order where 1 = 1 " + filter }; var jsons = JsonConvert.SerializeObject(data); string obj = Util.ElasticQuery("_sql?format=json", "POST", jsons); Num num = EsCommon.FromJSON(obj); totalcount = num.rows[0][0]; return Json( new { items = source, success = true, totalCount = totalcount }); } } }