ES_MemproductController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using CoreEntity.Entity;
  7. using JCSoft.WX.Framework.Api;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Caching.Memory;
  10. using Newtonsoft.Json;
  11. using PublicLibrary.Model;
  12. using SupplierWeb.Commonss;
  13. namespace SupplierWeb.Controllers
  14. {
  15. [Route("web/ES_Memproduct")]
  16. public class ES_MemproductController : BaseController
  17. {
  18. public ES_MemproductController(IMemoryCache cache, IApiClient client) : base(cache, client)
  19. {
  20. }
  21. public IActionResult Index()
  22. {
  23. return View();
  24. }
  25. [HttpPost]
  26. [Route("index")]
  27. public ActionResult index([FromBody]dynamic data, QueryFilter[] filters)
  28. {
  29. int start = 0;
  30. string field = "";
  31. string fieldvalue = "";
  32. if (data != null)
  33. {
  34. if (data.pageIndex == 1)
  35. {
  36. start = 0;
  37. }
  38. else
  39. {
  40. start = ((data.pageIndex - 1) * data.pageSize) + 1;
  41. }
  42. if (data.filters.Count != 0)
  43. {
  44. field = data.filters[0].field;
  45. fieldvalue = data.filters[0].value;
  46. data = new { query = "select * from mem_product1 where " + field + " like '%" + fieldvalue + "%' limit " + data.pageSize };
  47. }
  48. else
  49. {
  50. data = new { query = "select * from mem_product1 a limit " + data.pageSize };
  51. }
  52. }
  53. //将参数转换成JSON数据
  54. var json = JsonConvert.SerializeObject(data);
  55. //通过传来的SQL语句,转换成DSL语句
  56. string sql = Util.ElasticQuery("_sql/translate?format=json", "POST", json);
  57. string from = "\"from\":" + start + ",";
  58. sql = sql.Insert(1, from);
  59. //通过转换的DSL语句,获取数据
  60. var str = Util.ElasticQuery("mem_product1/_search?format=json", "POST", sql);
  61. #region
  62. //dynamic dyn = new System.Dynamic.ExpandoObject();
  63. //var obj = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(str, new
  64. //{
  65. // hits = new
  66. // {
  67. // hits = new[]
  68. // {
  69. // new {
  70. // _id =string.Empty,
  71. // _source = new
  72. // {
  73. // Manufacturer =String.Empty,
  74. // },
  75. // fields = dyn
  76. // }
  77. // }
  78. // }
  79. //});
  80. //foreach(var item in obj.hits.hits)
  81. //{
  82. //}
  83. #endregion
  84. //JSON转Root对象
  85. Root stobj = FromJSON<Root>(str);
  86. //将Root对象中的子对象取出来
  87. List<_source> _source = new List<_source>();
  88. _source = stobj.hits.hits.Select(x => x._source).ToList();
  89. List<Fields> Fields = new List<Fields>();
  90. Fields = stobj.hits.hits.Select(x => x.fields).ToList();
  91. //给filed额外的属性赋值
  92. stobj.hits.hits.ForEach(x =>
  93. {
  94. x.fields._id = x._id;
  95. x.fields.Manufacturer = x._source.Manufacturer;
  96. });
  97. //总数
  98. long totalcount = 0;
  99. data = new { query = "select count(1) from mem_product1" };
  100. var jsons = JsonConvert.SerializeObject(data);
  101. string obj = Util.ElasticQuery("_sql?format=json", "POST", jsons);
  102. Num num = FromJSON<Num>(obj);
  103. totalcount =num.rows[0][0];
  104. var jsonData = JsonConvert.SerializeObject(Fields);
  105. return Json(
  106. new
  107. {
  108. items = JsonConvert.DeserializeObject(jsonData),
  109. totalCount = totalcount
  110. });
  111. }
  112. /// <summary>
  113. /// JSON转对象
  114. /// </summary>
  115. /// <typeparam name="T"></typeparam>
  116. /// <param name="input"></param>
  117. /// <returns></returns>
  118. public static T FromJSON<T>(string input)
  119. {
  120. try
  121. {
  122. return JsonConvert.DeserializeObject<T>(input);
  123. }
  124. catch (Exception ex)
  125. {
  126. string a = ex.Message;
  127. return default(T);
  128. }
  129. }
  130. #region 实体类
  131. public class ColumnsItem
  132. {
  133. /// <summary>
  134. ///
  135. /// </summary>
  136. public string name { get; set; }
  137. /// <summary>
  138. ///
  139. /// </summary>
  140. public string type { get; set; }
  141. }
  142. public class Num
  143. {
  144. /// <summary>
  145. ///
  146. /// </summary>
  147. public List<ColumnsItem> columns { get; set; }
  148. /// <summary>
  149. ///
  150. /// </summary>
  151. public List<List<int>> rows { get; set; }
  152. }
  153. public class Filters
  154. {
  155. /// <summary>
  156. ///
  157. /// </summary>
  158. public int field { get; set; }
  159. /// <summary>
  160. ///
  161. /// </summary>
  162. public int value { get; set; }
  163. /// <summary>
  164. ///
  165. /// </summary>
  166. public int operate { get; set; }
  167. }
  168. public class _shards
  169. {
  170. /// <summary>
  171. ///
  172. /// </summary>
  173. public int total { get; set; }
  174. /// <summary>
  175. ///
  176. /// </summary>
  177. public int successful { get; set; }
  178. /// <summary>
  179. ///
  180. /// </summary>
  181. public int skipped { get; set; }
  182. /// <summary>
  183. ///
  184. /// </summary>
  185. public int failed { get; set; }
  186. }
  187. public class Total
  188. {
  189. /// <summary>
  190. ///
  191. /// </summary>
  192. public int value { get; set; }
  193. /// <summary>
  194. ///
  195. /// </summary>
  196. public string relation { get; set; }
  197. }
  198. public class _source
  199. {
  200. /// <summary>
  201. ///
  202. /// </summary>
  203. public string ProudctDescription { get; set; }
  204. /// <summary>
  205. /// 如与其他药物同时使用可能会发生药物相互作用,详情请咨询医师或药师。
  206. /// </summary>
  207. public string DrugInteractions { get; set; }
  208. /// <summary>
  209. /// 药用PVC硬片,药品包装用PTP铝箔。10粒x2板/盒。
  210. /// </summary>
  211. public string PackingProduct { get; set; }
  212. /// <summary>
  213. /// 辅仁 糖尿乐胶囊 0.3g*20粒
  214. /// </summary>
  215. public string ProductName { get; set; }
  216. /// <summary>
  217. /// 贪食症 糖尿病
  218. /// </summary>
  219. public string ProductTag { get; set; }
  220. /// <summary>
  221. /// 本品为胶囊剂,内容物为灰褐色粉末;味辛、微苦。
  222. /// </summary>
  223. public string Characters { get; set; }
  224. /// <summary>
  225. ///
  226. /// </summary>
  227. public string Manual { get; set; }
  228. /// <summary>
  229. ///
  230. /// </summary>
  231. public string PregnantWoman { get; set; }
  232. /// <summary>
  233. ///
  234. /// </summary>
  235. public string Pharmaco { get; set; }
  236. /// <summary>
  237. /// 口服,一次3—4粒,一日3次。
  238. /// </summary>
  239. public string Dosage { get; set; }
  240. /// <summary>
  241. /// 部颁标准中药成方制剂第十三册
  242. /// </summary>
  243. public string Standards { get; set; }
  244. /// <summary>
  245. ///
  246. /// </summary>
  247. public string OlderPatients { get; set; }
  248. /// <summary>
  249. /// 密封。
  250. /// </summary>
  251. public string Storage { get; set; }
  252. /// <summary>
  253. /// 滋阴补肾,益气润肺,和胃生津,调节代谢机能。用于消渴症引起的多食、多饮、多尿、四肢无力等症,降低血糖、尿糖。
  254. /// </summary>
  255. public string Introduction { get; set; }
  256. /// <summary>
  257. ///
  258. /// </summary>
  259. public string ChemicalName { get; set; }
  260. /// <summary>
  261. /// 河南辅仁堂制药有限公司
  262. /// </summary>
  263. public string Manufacturer { get; set; }
  264. /// <summary>
  265. /// 尚不明确。
  266. /// </summary>
  267. public string Taboo { get; set; }
  268. /// <summary>
  269. /// 尚不明确。
  270. /// </summary>
  271. public string Adverse { get; set; }
  272. /// <summary>
  273. ///
  274. /// </summary>
  275. public string Overdose { get; set; }
  276. /// <summary>
  277. /// 严忌含糖食物及烟酒。
  278. /// </summary>
  279. public string Precautions { get; set; }
  280. /// <summary>
  281. ///
  282. /// </summary>
  283. public string Pharmacokinetics { get; set; }
  284. /// <summary>
  285. ///
  286. /// </summary>
  287. public string Child { get; set; }
  288. /// <summary>
  289. ///
  290. /// </summary>
  291. public string EnglishName { get; set; }
  292. }
  293. public class Fields
  294. {
  295. /// <summary>
  296. ///
  297. /// </summary>
  298. public string _id { get; set; }
  299. /// <summary>
  300. ///
  301. /// </summary>
  302. public string Manufacturer { get; set; }
  303. /// <summary>
  304. ///
  305. /// </summary>
  306. public List<string> CreationDate { get; set; }
  307. /// <summary>
  308. ///
  309. /// </summary>
  310. public List<string> SubProductLine { get; set; }
  311. /// <summary>
  312. ///
  313. /// </summary>
  314. public List<string> IsRecommend { get; set; }
  315. /// <summary>
  316. ///
  317. /// </summary>
  318. public List<string> FinancialType { get; set; }
  319. /// <summary>
  320. ///
  321. /// </summary>
  322. public List<string> LastModified { get; set; }
  323. /// <summary>
  324. ///
  325. /// </summary>
  326. public List<string> WapManual { get; set; }
  327. /// <summary>
  328. ///
  329. /// </summary>
  330. public List<string> GmpCode { get; set; }
  331. /// <summary>
  332. ///
  333. /// </summary>
  334. public List<int> AppreciationPrice { get; set; }
  335. /// <summary>
  336. ///
  337. /// </summary>
  338. public List<string> Packing { get; set; }
  339. /// <summary>
  340. ///
  341. /// </summary>
  342. public List<string> ProductImageUrl { get; set; }
  343. /// <summary>
  344. ///
  345. /// </summary>
  346. public List<string> IsLimitPrice { get; set; }
  347. /// <summary>
  348. ///
  349. /// </summary>
  350. public List<string> ToErp { get; set; }
  351. /// <summary>
  352. ///
  353. /// </summary>
  354. public List<string> CommonTitle { get; set; }
  355. /// <summary>
  356. ///
  357. /// </summary>
  358. public List<int> recordState { get; set; }
  359. /// <summary>
  360. ///
  361. /// </summary>
  362. public List<string> ProductLine { get; set; }
  363. /// <summary>
  364. ///
  365. /// </summary>
  366. public List<string> CommonTitlePinyin { get; set; }
  367. /// <summary>
  368. ///
  369. /// </summary>
  370. public List<int> MerchantManageCode { get; set; }
  371. /// <summary>
  372. ///
  373. /// </summary>
  374. public List<int> PackingNumber { get; set; }
  375. /// <summary>
  376. ///
  377. /// </summary>
  378. public List<string> ProductType { get; set; }
  379. /// <summary>
  380. ///
  381. /// </summary>
  382. public List<string> IsControl { get; set; }
  383. /// <summary>
  384. ///
  385. /// </summary>
  386. public List<string> PinyinFullCode { get; set; }
  387. /// <summary>
  388. ///
  389. /// </summary>
  390. public List<int> ControlNumber { get; set; }
  391. /// <summary>
  392. ///
  393. /// </summary>
  394. public List<string> OutOfStockRecommendCodes { get; set; }
  395. /// <summary>
  396. ///
  397. /// </summary>
  398. public List<string> PostageLogo { get; set; }
  399. /// <summary>
  400. ///
  401. /// </summary>
  402. public List<int> ManufacturerCode { get; set; }
  403. /// <summary>
  404. ///
  405. /// </summary>
  406. public List<int> ProductCodeForOutOfStock { get; set; }
  407. /// <summary>
  408. ///
  409. /// </summary>
  410. public List<int> PlaceCode { get; set; }
  411. /// <summary>
  412. ///
  413. /// </summary>
  414. public List<string> ApprovalNumber { get; set; }
  415. /// <summary>
  416. ///
  417. /// </summary>
  418. public List<int> PurchasePrice { get; set; }
  419. /// <summary>
  420. ///
  421. /// </summary>
  422. public List<int> CategoryType { get; set; }
  423. /// <summary>
  424. ///
  425. /// </summary>
  426. public List<int> MassDate { get; set; }
  427. /// <summary>
  428. ///
  429. /// </summary>
  430. public List<string> ProductAttribute { get; set; }
  431. /// <summary>
  432. ///
  433. /// </summary>
  434. public List<string> DivisionCode { get; set; }
  435. /// <summary>
  436. ///
  437. /// </summary>
  438. public List<string> Molecular { get; set; }
  439. /// <summary>
  440. ///
  441. /// </summary>
  442. public List<string> ProductRecommend { get; set; }
  443. /// <summary>
  444. ///
  445. /// </summary>
  446. public List<string> GiftCategory { get; set; }
  447. /// <summary>
  448. ///
  449. /// </summary>
  450. public List<string> Structure { get; set; }
  451. /// <summary>
  452. ///
  453. /// </summary>
  454. public List<int> HealthInsuranceType { get; set; }
  455. /// <summary>
  456. ///
  457. /// </summary>
  458. public List<string> IsDrugRecord { get; set; }
  459. /// <summary>
  460. ///
  461. /// </summary>
  462. public List<string> ShowMall { get; set; }
  463. /// <summary>
  464. ///
  465. /// </summary>
  466. public List<int> ConsumeDays { get; set; }
  467. /// <summary>
  468. ///
  469. /// </summary>
  470. public List<int> PlureProductStatusType { get; set; }
  471. /// <summary>
  472. ///
  473. /// </summary>
  474. public List<string> IsSuit { get; set; }
  475. /// <summary>
  476. ///
  477. /// </summary>
  478. public List<int> CheckPendingPrice { get; set; }
  479. /// <summary>
  480. ///
  481. /// </summary>
  482. public List<string> IsVisible { get; set; }
  483. /// <summary>
  484. ///
  485. /// </summary>
  486. public List<int> UsageCode { get; set; }
  487. /// <summary>
  488. ///
  489. /// </summary>
  490. public List<string> ThumbnailUrl { get; set; }
  491. /// <summary>
  492. ///
  493. /// </summary>
  494. public List<string> Productusecrowd { get; set; }
  495. /// <summary>
  496. ///
  497. /// </summary>
  498. public List<string> BtManual { get; set; }
  499. /// <summary>
  500. ///
  501. /// </summary>
  502. public List<int> BrandCode { get; set; }
  503. /// <summary>
  504. ///
  505. /// </summary>
  506. public List<string> ProductusecrowdCode { get; set; }
  507. /// <summary>
  508. ///
  509. /// </summary>
  510. public List<string> SFDAGmpCertificateDate { get; set; }
  511. /// <summary>
  512. ///
  513. /// </summary>
  514. public List<string> Unit { get; set; }
  515. /// <summary>
  516. ///
  517. /// </summary>
  518. public List<string> Formula { get; set; }
  519. /// <summary>
  520. ///
  521. /// </summary>
  522. public List<int> ProductHotType { get; set; }
  523. /// <summary>
  524. ///
  525. /// </summary>
  526. public List<string> Formulation { get; set; }
  527. /// <summary>
  528. ///
  529. /// </summary>
  530. public List<int> Views { get; set; }
  531. /// <summary>
  532. ///
  533. /// </summary>
  534. public List<string> PinyinCode { get; set; }
  535. /// <summary>
  536. ///
  537. /// </summary>
  538. public List<int> OurPrice { get; set; }
  539. /// <summary>
  540. ///
  541. /// </summary>
  542. public List<string> Img180 { get; set; }
  543. /// <summary>
  544. ///
  545. /// </summary>
  546. public List<string> Inspection { get; set; }
  547. /// <summary>
  548. ///
  549. /// </summary>
  550. public List<string> SyncStatus { get; set; }
  551. /// <summary>
  552. ///
  553. /// </summary>
  554. public List<string> SFDACode { get; set; }
  555. /// <summary>
  556. ///
  557. /// </summary>
  558. public List<int> Weight { get; set; }
  559. /// <summary>
  560. ///
  561. /// </summary>
  562. public List<string> Img100 { get; set; }
  563. /// <summary>
  564. ///
  565. /// </summary>
  566. public List<string> GmpCertificateUrl { get; set; }
  567. /// <summary>
  568. ///
  569. /// </summary>
  570. public List<string> ClassCode { get; set; }
  571. /// <summary>
  572. ///
  573. /// </summary>
  574. public List<int> MinMarketPrice { get; set; }
  575. /// <summary>
  576. ///
  577. /// </summary>
  578. public List<string> StandardCode { get; set; }
  579. /// <summary>
  580. ///
  581. /// </summary>
  582. public List<int> BranchCode { get; set; }
  583. /// <summary>
  584. ///
  585. /// </summary>
  586. public List<int> PriceSectorPricing { get; set; }
  587. /// <summary>
  588. ///
  589. /// </summary>
  590. public List<int> FormulationCode { get; set; }
  591. /// <summary>
  592. ///
  593. /// </summary>
  594. public List<int> CQuantity { get; set; }
  595. /// <summary>
  596. ///
  597. /// </summary>
  598. public List<string> BarCode { get; set; }
  599. /// <summary>
  600. ///
  601. /// </summary>
  602. public List<string> ExternalID { get; set; }
  603. /// <summary>
  604. ///
  605. /// </summary>
  606. public List<string> Productmainmaterial { get; set; }
  607. /// <summary>
  608. ///
  609. /// </summary>
  610. public List<string> BusinessIds { get; set; }
  611. /// <summary>
  612. ///
  613. /// </summary>
  614. public List<string> ControlAreaRegion { get; set; }
  615. /// <summary>
  616. ///
  617. /// </summary>
  618. public List<int> XQuantity { get; set; }
  619. /// <summary>
  620. ///
  621. /// </summary>
  622. public List<int> PrescriptionType { get; set; }
  623. /// <summary>
  624. ///
  625. /// </summary>
  626. public List<int> QcClass { get; set; }
  627. /// <summary>
  628. ///
  629. /// </summary>
  630. public List<string> ProfitLevel { get; set; }
  631. /// <summary>
  632. ///
  633. /// </summary>
  634. public List<string> PurchaseWhile { get; set; }
  635. /// <summary>
  636. ///
  637. /// </summary>
  638. public List<string> SuitDescription { get; set; }
  639. /// <summary>
  640. ///
  641. /// </summary>
  642. public List<int> MarketPrice { get; set; }
  643. /// <summary>
  644. ///
  645. /// </summary>
  646. public List<int> ProductStatusType { get; set; }
  647. /// <summary>
  648. ///
  649. /// </summary>
  650. public List<int> SFDAStatus { get; set; }
  651. /// <summary>
  652. ///
  653. /// </summary>
  654. public List<string> Composition { get; set; }
  655. /// <summary>
  656. ///
  657. /// </summary>
  658. public List<string> UserName { get; set; }
  659. /// <summary>
  660. ///
  661. /// </summary>
  662. public List<string> IsGifts { get; set; }
  663. /// <summary>
  664. ///
  665. /// </summary>
  666. public List<int> Quantity { get; set; }
  667. /// <summary>
  668. ///
  669. /// </summary>
  670. public List<string> Img320 { get; set; }
  671. /// <summary>
  672. ///
  673. /// </summary>
  674. public List<string> SFDAApprovalValidDate { get; set; }
  675. /// <summary>
  676. ///
  677. /// </summary>
  678. public List<string> Displaytab { get; set; }
  679. }
  680. public class HitsItem
  681. {
  682. /// <summary>
  683. ///
  684. /// </summary>
  685. public string _index { get; set; }
  686. /// <summary>
  687. ///
  688. /// </summary>
  689. public string _type { get; set; }
  690. /// <summary>
  691. ///
  692. /// </summary>
  693. public string _id { get; set; }
  694. /// <summary>
  695. ///
  696. /// </summary>
  697. public string _score { get; set; }
  698. /// <summary>
  699. ///
  700. /// </summary>
  701. public _source _source { get; set; }
  702. /// <summary>
  703. ///
  704. /// </summary>
  705. public Fields fields { get; set; }
  706. /// <summary>
  707. ///
  708. /// </summary>
  709. public List<int> sort { get; set; }
  710. }
  711. public class Hits
  712. {
  713. /// <summary>
  714. ///
  715. /// </summary>
  716. public Total total { get; set; }
  717. /// <summary>
  718. ///
  719. /// </summary>
  720. public string max_score { get; set; }
  721. /// <summary>
  722. ///
  723. /// </summary>
  724. public List<HitsItem> hits { get; set; }
  725. }
  726. public class Root
  727. {
  728. /// <summary>
  729. ///
  730. /// </summary>
  731. public int took { get; set; }
  732. /// <summary>
  733. ///
  734. /// </summary>
  735. public string timed_out { get; set; }
  736. /// <summary>
  737. ///
  738. /// </summary>
  739. public _shards _shards { get; set; }
  740. /// <summary>
  741. ///
  742. /// </summary>
  743. public Hits hits { get; set; }
  744. }
  745. #endregion
  746. }
  747. }