123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Threading.Tasks;
- using CoreEntity.Entity;
- using CoreEntity.ESEntity;
- 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/mem_orderproducts")]
- public class mem_orderproductsController : BaseController
- {
- public mem_orderproductsController(IMemoryCache cache, IApiClient client) : base(cache, client)
- {
- }
- public IActionResult Index()
- {
- return View();
- }
- /// <summary>
- /// all订单产品列表
- /// </summary>
- /// <param name="data"></param>
- /// <param name="filters"></param>
- /// <returns></returns>
- [HttpPost]
- [Route("OrderproductsList")]
- public ActionResult OrderproductsList([FromBody]dynamic data, QueryFilter[] filters)
- {
- 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;
- }
- //根据会员电话号码,先找到他的所有订单
- //找到属于处方的订单
- query = new { query = "select * from mem_orderproducts where 1=1"+
- filter +
- " order by CreationDate " +
- "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_orderproducts/_search?format=json", "POST", sql);
- //JSON转Root对象
- Root<OrderProducts> stobj = EsCommon.FromJSON<Root<OrderProducts>>(str);
- //总数
- List<OrderProducts> _source = new List<OrderProducts>();
- long totalcount = 0;
- if (stobj.hits.hits.Count > 0) {
- //给filed额外的属性赋值
- stobj.hits.hits.ForEach(x =>
- {
- x._source._id = x._id;
- //x._source.ProductCode = x.fields.ProductCode[0].ToString();
- x.fields.ActualPrice[0] = x.fields.ActualPrice[0] > 0 ?
- x.fields.ActualPrice[0] / 100 : 0;
-
- });
- //将Root对象中的子对象取出来
- _source = stobj.hits.hits.Select(x => x.entity()).ToList();
- var countdata = new { query = "select count(1) from mem_orderproducts where 1=1"+
- filter
- };
- var jsons = JsonConvert.SerializeObject(countdata);
- //ES获取SQL执行结果
- 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>
- /// 订单产品列表ByOderCode
- /// </summary>
- /// <param name="data"></param>
- /// <param name="filters"></param>
- /// <returns></returns>
- [HttpPost]
- [Route("ProductsListByOderCode")]
- public ActionResult ProductsListByOderCode([FromBody]dynamic data, QueryFilter[] filters)
- {
- int start = 0;
- //string OrdersCode = "JD84666969985";
- string OrdersCode = "";
- if (data != null)
- {
- OrdersCode = data.query[0];
- data = new { query = "select * from mem_orderproducts where OrdersCode='" + OrdersCode + "' " };
- }
- //将参数转换成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_orderproducts/_search?format=json", "POST", sql);
- //JSON转Root对象
- Root<OrderProducts> stobj = FromJSON<Root<OrderProducts>>(str);
- //List<Fields> Fields = new List<Fields>();
- //Fields = stobj.hits.hits.Select(x => x.fields).ToList();
- //给filed额外的属性赋值
- stobj.hits.hits.ForEach(x =>
- {
- x._source._id = x._id;
- //x._source.ProductCode = x.fields.ProductCode[0].ToString();
- x.fields.ActualPrice[0] = x.fields.ActualPrice[0] > 0 ?
- x.fields.ActualPrice[0] / 100 : 0;
- });
- //将Root对象中的子对象取出来
- List<OrderProducts> _source = new List<OrderProducts>();
- _source = stobj.hits.hits.Select(x => x.entity()).ToList();
- //总数
- long totalcount = 0;
- data = new { query = "select count(1) from mem_orderproducts where OrdersCode='"+ OrdersCode + "'" };
- var jsons = JsonConvert.SerializeObject(data);
- //ES获取SQL执行结果
- 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,
- success = true
- });
- }
- /// <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
- //{
- // public string ProductCode { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string CreationDate { get; set; }
- // /// <summary>
- // /// 仁和 痔速宁片 0.31g*12片*3板
- // /// </summary>
- // public string ProductName { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string ProductPromotionSet { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string AssociateProudctCode { get; set; }
- // /// <summary>
- // /// 盒
- // /// </summary>
- // public string Unit { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string ProfitLevel { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string LastModified { get; set; }
- // /// <summary>
- // /// 0.31g*12片*3板(仁和)
- // /// </summary>
- // public string Packing { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string Batch { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string Picture { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string Barcode { get; set; }
- // /// <summary>
- // /// 江西药都仁和制药有限公司
- // /// </summary>
- // public string Manufacturer { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string OrdersCode { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string DamagedRemark { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string MemberPhone { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public string Id { get; set; }
- //}
- //public class Fields
- //{
- // /// <summary>
- // ///
- // /// </summary>
- // public List<int> ActualPrice { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public List<int> AvgDiscount { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public List<int> MarketPrice { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public List<int> ProductCode { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public List<int> AvgFreight { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public List<int> OurPrice { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public List<int> Amount { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public List<string> IntegralAmount { get; set; }
- // /// <summary>
- // ///
- // /// </summary>
- // public List<int> PurchasePrice { 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 string _routing { 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
-
- }
- }
|