123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using System;
- using System.Collections.Generic;
- 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 Nest;
- using Newtonsoft.Json;
- using PublicLibrary.Model;
- using SupplierWeb.Commonss;
- using SupplierWeb.Service;
- namespace SupplierWeb.Controllers
- {
- [Route("web/Mem_memberinformation")]
- public class Mem_memberinformationController : BaseController
- {
-
- public Mem_memberinformationController(IMemoryCache cache, IApiClient client,
- IEsClientProvider clientProvider) : base(cache, client, clientProvider)
- {
- }
- public IActionResult Index()
- {
- return View();
- }
- /// <summary>
- /// 会员中心列表
- /// </summary>
- /// <param name="data"></param>
- /// <param name="filters"></param>
- /// <returns></returns>
- [HttpPost]
- [Route("index")]
- public ActionResult index([FromBody]dynamic data, QueryFilter[] filters)
- {
- int start = 0;
- string MemberPhone = "";
- if (data != null)
- {
- MemberPhone = data.query;
- data = new { query = "select * from mem_memberbase_p where MemUsualPhone='"+ MemberPhone+"'" };
- }
- //将参数转换成JSON数据
- var json = JsonConvert.SerializeObject(data);
- //通过传来的SQL语句,转换成DSL语句
- string sql = Util.ElasticQuery("_sql/translate?format=json", "POST", json);
- //TranslateSqlResponse result = _LowLevelclient.Sql.Translate<TranslateSqlResponse>(PostData.String(json));
- //string sql = result.ApiCall.ResponseBodyInBytes();
- string from = "\"from\":" + start + ",";
- sql = sql.Insert(1, from);
- //通过转换的DSL语句,获取数据
- //var str = Util.ElasticQuery("mem_memberbase_p/_search?format=json", "POST", sql);
- int sourceIndex = sql.IndexOf("\"_source\":{");
- int sourceIndexEnd = sql.IndexOf("},", sourceIndex);
- string sourcestr = sql.Substring(sourceIndex, sourceIndexEnd - sourceIndex + 1);
- sql = sql.Replace(sourcestr, "\"_source\":{\"includes\":[\"*\"], \"excludes\": []}");
- int fieldIndex = sql.IndexOf("\"docvalue_fields\":[");
- int fieldIndexEnd = sql.IndexOf("],", fieldIndex);
- sql = sql.Remove(fieldIndex, fieldIndexEnd - fieldIndex + 2);
- PostData dsl = sql;
- var result = _LowLevelclient.Search<StringResponse>("mem_memberbase_p", dsl);
- var DynamicObject = JsonConvert.DeserializeObject<dynamic>(result.Body);
- List<dynamic> source = new List<dynamic>();
- //总数
- long totalCount = 0;
- //JSON转Root对象
- //将Root对象中的子对象取出来
- if (DynamicObject.hits.hits.Count > 0)
- {
- HitsItem<dynamic>[] hits = DynamicObject.hits.hits.ToObject<HitsItem<dynamic>[]>();
- //List<mem_MemberTerminal> _source = new List<mem_MemberTerminal>(0);
- //_source = inerhits.Select(x => x.entity()).ToList();
- foreach (HitsItem<dynamic> o in hits)
- {
- string[] phones = new string[1];
- phones[0] = o._source.MemUsualPhone;
- 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.MemUsualPhoneCr = o._source.MemUsualPhone;
- o._source.MemUsualPhone = phoneStars;
- o._source.MemUsualPhoneOr = phones1[0];
- o._source._id = o._id;
- source.Add(o._source);
- }
- totalCount = DynamicObject.hits.total.value;
- //var jsonData = JsonConvert.SerializeObject(_source);
- }
- return Json(
- new
- {
- items = source,
- temsCount = totalCount,
- success =true
- });
- }
-
- [HttpPost]
- [Route("EditMemberBase")]
- public ActionResult EditMemberBase([FromBody]dynamic data)
- {
- var success = false;
- string docId = data._id;
- data.Remove("_id");
- data.MemUsualPhone = data.MemUsualPhoneCr;
- data.Remove("MemUsualPhoneOr");
- data.Remove("MemUsualPhoneCr");
- Dictionary<string, Object> doc = null;
- if (data.updates !=null && data.updates.Count>0)
- {
- docId = data.updates[0]._id;
- //var response = _esclient.Get<dynamic>(docId, idx => idx.Index("mem_memberbase_p")); // returns an IGetResponse mapped 1-to-1 with the Elasticsearch JSON response
- //var Source = response.Source; // the original document
- Dictionary<string, Object> memdoc = new Dictionary<string, Object>();
- foreach(var data1 in data.updates) {
- if (data1.update == "true" && data1.updateField != null
- && data1.updateFieldValue != null) {
- string updateField = data1.updateField;
- string updateFieldValue = data1.updateFieldValue;
- memdoc[updateField] = updateFieldValue;
- }
- }
- doc = memdoc;
- }
- else
- {
- doc = data.ToObject<Dictionary<string, Object>>();
-
- }
- data["LastUpdatedDate"] = DateTime.UtcNow;
- var jsons = JsonConvert.SerializeObject(new
- {
- doc = doc
- }
- );
- var param = new UpdateRequestParameters();
- param.Refresh = Refresh.True;
- var Response = _LowLevelclient.Update<StringResponse>("mem_memberbase_p", docId, jsons, param);
- dynamic t = JsonConvert.DeserializeObject(
- Response.Body
- );
- if (t.result == "updated")
- {
- success = true;
- }
- else
- {
- success = false;
- }
- return Json(
- new
- {
- msg = "",
- success = success
- });
- }
-
- }
- }
|