123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713 |
- 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 MemberWeb.Commonss.EsDAL;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Caching.Memory;
- using Newtonsoft.Json;
- using PublicLibrary.Model;
- using SupplierWeb.Commonss;
- namespace SupplierWeb.Controllers
- {
- [Route("web/mem_prescription")]
- public class mem_PrescriptionController : BaseController
- {
- public mem_PrescriptionController(IMemoryCache cache, IApiClient client) : base(cache, client)
- {
- }
- 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)
- {
- string code = "";
- int start = 0;
- string filter = "";
- object query = null;
- if (data != null)
- {
- filters = data.filters.ToObject<QueryFilter[]>();
- filter = QueryFilter.getFilterString(filters);
- if (data.pageIndex == 1)
- {
- start = 0;
- }
- else
- {
- start = ((data.pageIndex - 1) * data.pageSize) + 1;
- }
- //根据会员电话号码,先找到他的所有订单
- code = OrderDAL.GetPrescriptionOderscode(data, filter);
- if(code == "")
- {
- return Json(
- new
- {
- items = new Object[] { },
- totalCount = 0
- });
- }
- //找到属于订单的处方
- query = new { query = "select * from mem_prescription where OrdersCode in(" + code+") " +
- " order by OrdersCode " +
- "limit "+ data.pageSize
- };
-
- }
- //将参数转换成JSON数据
- var json = JsonConvert.SerializeObject(query);
- //通过传来的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_prescription/_search?format=json", "POST", sql);
- //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;
- var countdata = new { query = "select count(1) from mem_prescription where OrdersCode in(" + code + ") " };
- var jsons = JsonConvert.SerializeObject(countdata);
- string obj = Util.ElasticQuery("_sql?format=json", "POST", jsons);
- Num num = FromJSON<Num>(obj);
- totalcount = num.rows[0][0];
- var jsonData = JsonConvert.SerializeObject(_source);
- 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 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 MemberId { get; set; }
- /// <summary>
- /// 陈红
- /// </summary>
- public string PrecDoctorName { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string MemberAge { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string PrescriptionDate { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string OrdersCode { get; set; }
- /// <summary>
- /// 时野
- /// </summary>
- public string MemberName { get; set; }
- /// <summary>
- /// 前列腺炎
- /// </summary>
- public string Diagnosis { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string PrecDoctorId { 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
- # 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; }
- }
- #endregion
- }
- }
|