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(); } /// /// 处方订单列表 /// /// /// /// [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(); 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(str); //将Root对象中的子对象取出来 List<_source> _source = new List<_source>(); _source = stobj.hits.hits.Select(x => x._source).ToList(); List Fields = new List(); 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(obj); totalcount = num.rows[0][0]; var jsonData = JsonConvert.SerializeObject(_source); return Json( new { items = JsonConvert.DeserializeObject(jsonData), totalCount = totalcount }); } /// /// JSON转对象 /// /// /// /// public static T FromJSON(string input) { try { return JsonConvert.DeserializeObject(input); } catch (Exception ex) { string a = ex.Message; return default(T); } } #region 列表实体类 public class Filters { /// /// /// public int field { get; set; } /// /// /// public int value { get; set; } /// /// /// public int operate { get; set; } } public class _shards { /// /// /// public int total { get; set; } /// /// /// public int successful { get; set; } /// /// /// public int skipped { get; set; } /// /// /// public int failed { get; set; } } public class Total { /// /// /// public int value { get; set; } /// /// /// public string relation { get; set; } } public class _source { /// /// /// public string MemberId { get; set; } /// /// 陈红 /// public string PrecDoctorName { get; set; } /// /// /// public string MemberAge { get; set; } /// /// /// public string PrescriptionDate { get; set; } /// /// /// public string OrdersCode { get; set; } /// /// 时野 /// public string MemberName { get; set; } /// /// 前列腺炎 /// public string Diagnosis { get; set; } /// /// /// public string PrecDoctorId { get; set; } } public class Fields { /// /// /// public string _id { get; set; } /// /// /// public string Manufacturer { get; set; } /// /// /// public List CreationDate { get; set; } /// /// /// public List SubProductLine { get; set; } /// /// /// public List IsRecommend { get; set; } /// /// /// public List FinancialType { get; set; } /// /// /// public List LastModified { get; set; } /// /// /// public List WapManual { get; set; } /// /// /// public List GmpCode { get; set; } /// /// /// public List AppreciationPrice { get; set; } /// /// /// public List Packing { get; set; } /// /// /// public List ProductImageUrl { get; set; } /// /// /// public List IsLimitPrice { get; set; } /// /// /// public List ToErp { get; set; } /// /// /// public List CommonTitle { get; set; } /// /// /// public List recordState { get; set; } /// /// /// public List ProductLine { get; set; } /// /// /// public List CommonTitlePinyin { get; set; } /// /// /// public List MerchantManageCode { get; set; } /// /// /// public List PackingNumber { get; set; } /// /// /// public List ProductType { get; set; } /// /// /// public List IsControl { get; set; } /// /// /// public List PinyinFullCode { get; set; } /// /// /// public List ControlNumber { get; set; } /// /// /// public List OutOfStockRecommendCodes { get; set; } /// /// /// public List PostageLogo { get; set; } /// /// /// public List ManufacturerCode { get; set; } /// /// /// public List ProductCodeForOutOfStock { get; set; } /// /// /// public List PlaceCode { get; set; } /// /// /// public List ApprovalNumber { get; set; } /// /// /// public List PurchasePrice { get; set; } /// /// /// public List CategoryType { get; set; } /// /// /// public List MassDate { get; set; } /// /// /// public List ProductAttribute { get; set; } /// /// /// public List DivisionCode { get; set; } /// /// /// public List Molecular { get; set; } /// /// /// public List ProductRecommend { get; set; } /// /// /// public List GiftCategory { get; set; } /// /// /// public List Structure { get; set; } /// /// /// public List HealthInsuranceType { get; set; } /// /// /// public List IsDrugRecord { get; set; } /// /// /// public List ShowMall { get; set; } /// /// /// public List ConsumeDays { get; set; } /// /// /// public List PlureProductStatusType { get; set; } /// /// /// public List IsSuit { get; set; } /// /// /// public List CheckPendingPrice { get; set; } /// /// /// public List IsVisible { get; set; } /// /// /// public List UsageCode { get; set; } /// /// /// public List ThumbnailUrl { get; set; } /// /// /// public List Productusecrowd { get; set; } /// /// /// public List BtManual { get; set; } /// /// /// public List BrandCode { get; set; } /// /// /// public List ProductusecrowdCode { get; set; } /// /// /// public List SFDAGmpCertificateDate { get; set; } /// /// /// public List Unit { get; set; } /// /// /// public List Formula { get; set; } /// /// /// public List ProductHotType { get; set; } /// /// /// public List Formulation { get; set; } /// /// /// public List Views { get; set; } /// /// /// public List PinyinCode { get; set; } /// /// /// public List OurPrice { get; set; } /// /// /// public List Img180 { get; set; } /// /// /// public List Inspection { get; set; } /// /// /// public List SyncStatus { get; set; } /// /// /// public List SFDACode { get; set; } /// /// /// public List Weight { get; set; } /// /// /// public List Img100 { get; set; } /// /// /// public List GmpCertificateUrl { get; set; } /// /// /// public List ClassCode { get; set; } /// /// /// public List MinMarketPrice { get; set; } /// /// /// public List StandardCode { get; set; } /// /// /// public List BranchCode { get; set; } /// /// /// public List PriceSectorPricing { get; set; } /// /// /// public List FormulationCode { get; set; } /// /// /// public List CQuantity { get; set; } /// /// /// public List BarCode { get; set; } /// /// /// public List ExternalID { get; set; } /// /// /// public List Productmainmaterial { get; set; } /// /// /// public List BusinessIds { get; set; } /// /// /// public List ControlAreaRegion { get; set; } /// /// /// public List XQuantity { get; set; } /// /// /// public List PrescriptionType { get; set; } /// /// /// public List QcClass { get; set; } /// /// /// public List ProfitLevel { get; set; } /// /// /// public List PurchaseWhile { get; set; } /// /// /// public List SuitDescription { get; set; } /// /// /// public List MarketPrice { get; set; } /// /// /// public List ProductStatusType { get; set; } /// /// /// public List SFDAStatus { get; set; } /// /// /// public List Composition { get; set; } /// /// /// public List UserName { get; set; } /// /// /// public List IsGifts { get; set; } /// /// /// public List Quantity { get; set; } /// /// /// public List Img320 { get; set; } /// /// /// public List SFDAApprovalValidDate { get; set; } /// /// /// public List Displaytab { get; set; } } public class HitsItem { /// /// /// public string _index { get; set; } /// /// /// public string _type { get; set; } /// /// /// public string _id { get; set; } /// /// /// public string _score { get; set; } /// /// /// public _source _source { get; set; } /// /// /// public Fields fields { get; set; } /// /// /// public List sort { get; set; } } public class Hits { /// /// /// public Total total { get; set; } /// /// /// public string max_score { get; set; } /// /// /// public List hits { get; set; } } public class Root { /// /// /// public int took { get; set; } /// /// /// public string timed_out { get; set; } /// /// /// public _shards _shards { get; set; } /// /// /// public Hits hits { get; set; } } #endregion # region 总数实体类 public class ColumnsItem { /// /// /// public string name { get; set; } /// /// /// public string type { get; set; } } public class Num { /// /// /// public List columns { get; set; } /// /// /// public List> rows { get; set; } } #endregion } }