123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779 |
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Threading.Tasks;
- using CoreEntity.Entity;
- using JCSoft.WX.Framework.Api;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Caching.Memory;
- using Newtonsoft.Json;
- using PublicLibrary.Model;
- using SupplierWeb.Commonss;
- namespace SupplierWeb.Controllers
- {
- [Route("web/ES_Memproduct")]
- public class ES_MemproductController : BaseController
- {
- public ES_MemproductController(IMemoryCache cache, IApiClient client) : base(cache, client)
- {
- }
- public IActionResult Index()
- {
- return View();
- }
- [HttpPost]
- [Route("index")]
- public ActionResult index([FromBody]dynamic data, QueryFilter[] filters)
- {
- int start = 0;
- string field = "";
- string fieldvalue = "";
- if (data != null)
- {
- if (data.pageIndex == 1)
- {
- start = 0;
- }
- else
- {
- start = ((data.pageIndex - 1) * data.pageSize) + 1;
- }
- if (data.filters.Count != 0)
- {
- field = data.filters[0].field;
- fieldvalue = data.filters[0].value;
- data = new { query = "select * from mem_product1 where " + field + " like '%" + fieldvalue + "%' limit " + data.pageSize };
- }
- else
- {
- data = new { query = "select * from mem_product1 a limit " + data.pageSize };
- }
- }
- //将参数转换成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);
- //通过转换的DSL语句,获取数据
- var str = Util.ElasticQuery("mem_product1/_search?format=json", "POST", sql);
- #region
- //dynamic dyn = new System.Dynamic.ExpandoObject();
- //var obj = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(str, new
- //{
- // hits = new
- // {
- // hits = new[]
- // {
- // new {
- // _id =string.Empty,
- // _source = new
- // {
- // Manufacturer =String.Empty,
- // },
- // fields = dyn
- // }
- // }
- // }
- //});
- //foreach(var item in obj.hits.hits)
- //{
- //}
- #endregion
- //JSON转Root对象
- Root stobj = FromJSON<Root>(str);
- //将Root对象中的子对象取出来
- List<_source> _source = new List<_source>();
- _source = stobj.hits.hits.Select(x => x._source).ToList();
- List<Fields> Fields = new List<Fields>();
- Fields = stobj.hits.hits.Select(x => x.fields).ToList();
- //给filed额外的属性赋值
- stobj.hits.hits.ForEach(x =>
- {
- x.fields._id = x._id;
- x.fields.Manufacturer = x._source.Manufacturer;
- });
- //总数
- long totalcount = 0;
- data = new { query = "select count(1) from mem_product1" };
- var jsons = JsonConvert.SerializeObject(data);
- string obj = Util.ElasticQuery("_sql?format=json", "POST", jsons);
- Num num = FromJSON<Num>(obj);
- totalcount =num.rows[0][0];
- var jsonData = JsonConvert.SerializeObject(Fields);
- return Json(
- new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- totalCount = totalcount
- });
- }
- /// <summary>
- /// JSON转对象
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="input"></param>
- /// <returns></returns>
- public static T FromJSON<T>(string input)
- {
- try
- {
- return JsonConvert.DeserializeObject<T>(input);
- }
- catch (Exception ex)
- {
- string a = ex.Message;
- return default(T);
- }
- }
- #region 实体类
- public class ColumnsItem
- {
- /// <summary>
- ///
- /// </summary>
- public string name { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string type { get; set; }
- }
- public class Num
- {
- /// <summary>
- ///
- /// </summary>
- public List<ColumnsItem> columns { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<List<int>> rows { get; set; }
- }
- public class Filters
- {
- /// <summary>
- ///
- /// </summary>
- public int field { get; set; }
- /// <summary>
- ///
- /// </summary>
- public int value { get; set; }
- /// <summary>
- ///
- /// </summary>
- public int operate { get; set; }
- }
- public class _shards
- {
- /// <summary>
- ///
- /// </summary>
- public int total { get; set; }
- /// <summary>
- ///
- /// </summary>
- public int successful { get; set; }
- /// <summary>
- ///
- /// </summary>
- public int skipped { get; set; }
- /// <summary>
- ///
- /// </summary>
- public int failed { get; set; }
- }
- public class Total
- {
- /// <summary>
- ///
- /// </summary>
- public int value { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string relation { get; set; }
- }
- public class _source
- {
- /// <summary>
- ///
- /// </summary>
- public string ProudctDescription { get; set; }
- /// <summary>
- /// 如与其他药物同时使用可能会发生药物相互作用,详情请咨询医师或药师。
- /// </summary>
- public string DrugInteractions { get; set; }
- /// <summary>
- /// 药用PVC硬片,药品包装用PTP铝箔。10粒x2板/盒。
- /// </summary>
- public string PackingProduct { get; set; }
- /// <summary>
- /// 辅仁 糖尿乐胶囊 0.3g*20粒
- /// </summary>
- public string ProductName { get; set; }
- /// <summary>
- /// 贪食症 糖尿病
- /// </summary>
- public string ProductTag { get; set; }
- /// <summary>
- /// 本品为胶囊剂,内容物为灰褐色粉末;味辛、微苦。
- /// </summary>
- public string Characters { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string Manual { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string PregnantWoman { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string Pharmaco { get; set; }
- /// <summary>
- /// 口服,一次3—4粒,一日3次。
- /// </summary>
- public string Dosage { get; set; }
- /// <summary>
- /// 部颁标准中药成方制剂第十三册
- /// </summary>
- public string Standards { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string OlderPatients { get; set; }
- /// <summary>
- /// 密封。
- /// </summary>
- public string Storage { get; set; }
- /// <summary>
- /// 滋阴补肾,益气润肺,和胃生津,调节代谢机能。用于消渴症引起的多食、多饮、多尿、四肢无力等症,降低血糖、尿糖。
- /// </summary>
- public string Introduction { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string ChemicalName { get; set; }
- /// <summary>
- /// 河南辅仁堂制药有限公司
- /// </summary>
- public string Manufacturer { get; set; }
- /// <summary>
- /// 尚不明确。
- /// </summary>
- public string Taboo { get; set; }
- /// <summary>
- /// 尚不明确。
- /// </summary>
- public string Adverse { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string Overdose { get; set; }
- /// <summary>
- /// 严忌含糖食物及烟酒。
- /// </summary>
- public string Precautions { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string Pharmacokinetics { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string Child { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string EnglishName { get; set; }
- }
- public class Fields
- {
- /// <summary>
- ///
- /// </summary>
- public string _id { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string Manufacturer { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> CreationDate { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> SubProductLine { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> IsRecommend { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> FinancialType { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> LastModified { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> WapManual { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> GmpCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> AppreciationPrice { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Packing { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ProductImageUrl { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> IsLimitPrice { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ToErp { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> CommonTitle { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> recordState { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ProductLine { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> CommonTitlePinyin { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> MerchantManageCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> PackingNumber { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ProductType { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> IsControl { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> PinyinFullCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> ControlNumber { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> OutOfStockRecommendCodes { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> PostageLogo { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> ManufacturerCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> ProductCodeForOutOfStock { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> PlaceCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ApprovalNumber { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> PurchasePrice { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> CategoryType { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> MassDate { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ProductAttribute { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> DivisionCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Molecular { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ProductRecommend { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> GiftCategory { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Structure { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> HealthInsuranceType { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> IsDrugRecord { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ShowMall { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> ConsumeDays { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> PlureProductStatusType { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> IsSuit { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> CheckPendingPrice { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> IsVisible { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> UsageCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ThumbnailUrl { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Productusecrowd { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> BtManual { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> BrandCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ProductusecrowdCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> SFDAGmpCertificateDate { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Unit { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Formula { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> ProductHotType { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Formulation { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> Views { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> PinyinCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> OurPrice { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Img180 { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Inspection { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> SyncStatus { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> SFDACode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> Weight { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Img100 { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> GmpCertificateUrl { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ClassCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> MinMarketPrice { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> StandardCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> BranchCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> PriceSectorPricing { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> FormulationCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> CQuantity { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> BarCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ExternalID { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Productmainmaterial { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> BusinessIds { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ControlAreaRegion { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> XQuantity { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> PrescriptionType { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> QcClass { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> ProfitLevel { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> PurchaseWhile { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> SuitDescription { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> MarketPrice { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> ProductStatusType { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> SFDAStatus { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Composition { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> UserName { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> IsGifts { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> Quantity { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Img320 { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> SFDAApprovalValidDate { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<string> Displaytab { get; set; }
- }
- public class HitsItem
- {
- /// <summary>
- ///
- /// </summary>
- public string _index { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string _type { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string _id { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string _score { get; set; }
- /// <summary>
- ///
- /// </summary>
- public _source _source { get; set; }
- /// <summary>
- ///
- /// </summary>
- public Fields fields { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> sort { get; set; }
- }
- public class Hits
- {
- /// <summary>
- ///
- /// </summary>
- public Total total { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string max_score { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<HitsItem> hits { get; set; }
- }
- public class Root
- {
- /// <summary>
- ///
- /// </summary>
- public int took { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string timed_out { get; set; }
- /// <summary>
- ///
- /// </summary>
- public _shards _shards { get; set; }
- /// <summary>
- ///
- /// </summary>
- public Hits hits { get; set; }
- }
- #endregion
- }
- }
|