123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- 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_prescriptionproduct")]
- public class mem_prescriptionproductController : BaseController
- {
- public mem_prescriptionproductController(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<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_prescriptionproduct where OrderCode in(" + code + ") " +
- " order by OrderCode " +
- " 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_prescriptionproduct/_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._source.ProductCode = x.fields.ProductCode[0].ToString();
- //x.fields.Manufacturer = x._source.Manufacturer;
- });
- //总数
- long totalcount = 0;
- var countdata = new { query = "select count(1) from mem_prescriptionproduct where OrderCode 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 _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 ProductCode { get; set; }
- /// <summary>
- /// [{"ProductName":"万通 乳酸左氧氟沙星分散片 0.1g*12片","Amount":"1","Pack":"po 0.2g bid","IsPrescription":"1","ProductCode":"726583"}]
- /// </summary>
- public string Contents { get; set; }
- /// <summary>
- /// 1张
- /// </summary>
- public string AtomUnit { get; set; }
- /// <summary>
- /// @21 药师服务卡(京东) 1张
- /// </summary>
- public string ProductName { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string ProductPacking { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string OrderCode { get; set; }
- /// <summary>
- /// 张
- /// </summary>
- public string Unit { get; set; }
- /// <summary>
- /// 王朝约
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string Dossage { get; set; }
- }
- public class Fields
- {
- /// <summary>
- ///
- /// </summary>
- public List<string> IsDelete { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> ProductCode { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<int> Amount { 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
- #region 订单code实体类
- public class Condition
- {
- /// <summary>
- ///
- /// </summary>
- public string name { get; set; }
- /// <summary>
- ///
- /// </summary>
- public string type { get; set; }
- }
- public class Orderscode
- {
- /// <summary>
- ///
- /// </summary>
- public List<Condition> columns { get; set; }
- /// <summary>
- ///
- /// </summary>
- public List<List<string>> rows { get; set; }
- }
- #endregion
- }
- }
|