mem_prescriptionController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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 MemberWeb.Commonss.EsDAL;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Microsoft.Extensions.Caching.Memory;
  11. using Newtonsoft.Json;
  12. using PublicLibrary.Model;
  13. using SupplierWeb.Commonss;
  14. namespace SupplierWeb.Controllers
  15. {
  16. [Route("web/mem_prescription")]
  17. public class mem_PrescriptionController : BaseController
  18. {
  19. public mem_PrescriptionController(IMemoryCache cache, IApiClient client) : base(cache, client)
  20. {
  21. }
  22. public IActionResult Index()
  23. {
  24. return View();
  25. }
  26. /// <summary>
  27. /// 处方订单列表
  28. /// </summary>
  29. /// <param name="data"></param>
  30. /// <param name="filters"></param>
  31. /// <returns></returns>
  32. [HttpPost]
  33. [Route("index")]
  34. public ActionResult index([FromBody]dynamic data, QueryFilter[] filters)
  35. {
  36. string code = "";
  37. int start = 0;
  38. string filter = "";
  39. object query = null;
  40. if (data != null)
  41. {
  42. filters = data.filters.ToObject<QueryFilter[]>();
  43. filter = QueryFilter.getFilterString(filters);
  44. if (data.pageIndex == 1)
  45. {
  46. start = 0;
  47. }
  48. else
  49. {
  50. start = ((data.pageIndex - 1) * data.pageSize) + 1;
  51. }
  52. //根据会员电话号码,先找到他的所有订单
  53. code = OrderDAL.GetPrescriptionOderscode(data, filter);
  54. if(code == "")
  55. {
  56. return Json(
  57. new
  58. {
  59. items = new Object[] { },
  60. totalCount = 0
  61. });
  62. }
  63. //找到属于订单的处方
  64. query = new { query = "select * from mem_prescription where OrdersCode in(" + code+") " +
  65. " order by OrdersCode " +
  66. "limit "+ data.pageSize
  67. };
  68. }
  69. //将参数转换成JSON数据
  70. var json = JsonConvert.SerializeObject(query);
  71. //通过传来的SQL语句,转换成DSL语句
  72. string sql = Util.ElasticQuery("_sql/translate?format=json", "POST", json);
  73. string from = "\"from\":" + start + ",";
  74. sql = sql.Insert(1, from);
  75. //通过转换的DSL语句,获取数据
  76. var str = Util.ElasticQuery("mem_prescription/_search?format=json", "POST", sql);
  77. //JSON转Root对象
  78. Root stobj = FromJSON<Root>(str);
  79. //将Root对象中的子对象取出来
  80. List<_source> _source = new List<_source>();
  81. _source = stobj.hits.hits.Select(x => x._source).ToList();
  82. List<Fields> Fields = new List<Fields>();
  83. Fields = stobj.hits.hits.Select(x => x.fields).ToList();
  84. //给filed额外的属性赋值
  85. stobj.hits.hits.ForEach(x =>
  86. {
  87. x.fields._id = x._id;
  88. //x.fields.Manufacturer = x._source.Manufacturer;
  89. });
  90. //总数
  91. long totalcount = 0;
  92. var countdata = new { query = "select count(1) from mem_prescription where OrdersCode in(" + code + ") " };
  93. var jsons = JsonConvert.SerializeObject(countdata);
  94. string obj = Util.ElasticQuery("_sql?format=json", "POST", jsons);
  95. Num num = FromJSON<Num>(obj);
  96. totalcount = num.rows[0][0];
  97. var jsonData = JsonConvert.SerializeObject(_source);
  98. return Json(
  99. new
  100. {
  101. items = JsonConvert.DeserializeObject(jsonData),
  102. totalCount = totalcount
  103. });
  104. }
  105. /// <summary>
  106. /// JSON转对象
  107. /// </summary>
  108. /// <typeparam name="T"></typeparam>
  109. /// <param name="input"></param>
  110. /// <returns></returns>
  111. public static T FromJSON<T>(string input)
  112. {
  113. try
  114. {
  115. return JsonConvert.DeserializeObject<T>(input);
  116. }
  117. catch (Exception ex)
  118. {
  119. string a = ex.Message;
  120. return default(T);
  121. }
  122. }
  123. #region 列表实体类
  124. public class Filters
  125. {
  126. /// <summary>
  127. ///
  128. /// </summary>
  129. public int field { get; set; }
  130. /// <summary>
  131. ///
  132. /// </summary>
  133. public int value { get; set; }
  134. /// <summary>
  135. ///
  136. /// </summary>
  137. public int operate { get; set; }
  138. }
  139. public class _shards
  140. {
  141. /// <summary>
  142. ///
  143. /// </summary>
  144. public int total { get; set; }
  145. /// <summary>
  146. ///
  147. /// </summary>
  148. public int successful { get; set; }
  149. /// <summary>
  150. ///
  151. /// </summary>
  152. public int skipped { get; set; }
  153. /// <summary>
  154. ///
  155. /// </summary>
  156. public int failed { get; set; }
  157. }
  158. public class Total
  159. {
  160. /// <summary>
  161. ///
  162. /// </summary>
  163. public int value { get; set; }
  164. /// <summary>
  165. ///
  166. /// </summary>
  167. public string relation { get; set; }
  168. }
  169. public class _source
  170. {
  171. /// <summary>
  172. ///
  173. /// </summary>
  174. public string MemberId { get; set; }
  175. /// <summary>
  176. /// 陈红
  177. /// </summary>
  178. public string PrecDoctorName { get; set; }
  179. /// <summary>
  180. ///
  181. /// </summary>
  182. public string MemberAge { get; set; }
  183. /// <summary>
  184. ///
  185. /// </summary>
  186. public string PrescriptionDate { get; set; }
  187. /// <summary>
  188. ///
  189. /// </summary>
  190. public string OrdersCode { get; set; }
  191. /// <summary>
  192. /// 时野
  193. /// </summary>
  194. public string MemberName { get; set; }
  195. /// <summary>
  196. /// 前列腺炎
  197. /// </summary>
  198. public string Diagnosis { get; set; }
  199. /// <summary>
  200. ///
  201. /// </summary>
  202. public string PrecDoctorId { get; set; }
  203. }
  204. public class Fields
  205. {
  206. /// <summary>
  207. ///
  208. /// </summary>
  209. public string _id { get; set; }
  210. /// <summary>
  211. ///
  212. /// </summary>
  213. public string Manufacturer { get; set; }
  214. /// <summary>
  215. ///
  216. /// </summary>
  217. public List<string> CreationDate { get; set; }
  218. /// <summary>
  219. ///
  220. /// </summary>
  221. public List<string> SubProductLine { get; set; }
  222. /// <summary>
  223. ///
  224. /// </summary>
  225. public List<string> IsRecommend { get; set; }
  226. /// <summary>
  227. ///
  228. /// </summary>
  229. public List<string> FinancialType { get; set; }
  230. /// <summary>
  231. ///
  232. /// </summary>
  233. public List<string> LastModified { get; set; }
  234. /// <summary>
  235. ///
  236. /// </summary>
  237. public List<string> WapManual { get; set; }
  238. /// <summary>
  239. ///
  240. /// </summary>
  241. public List<string> GmpCode { get; set; }
  242. /// <summary>
  243. ///
  244. /// </summary>
  245. public List<int> AppreciationPrice { get; set; }
  246. /// <summary>
  247. ///
  248. /// </summary>
  249. public List<string> Packing { get; set; }
  250. /// <summary>
  251. ///
  252. /// </summary>
  253. public List<string> ProductImageUrl { get; set; }
  254. /// <summary>
  255. ///
  256. /// </summary>
  257. public List<string> IsLimitPrice { get; set; }
  258. /// <summary>
  259. ///
  260. /// </summary>
  261. public List<string> ToErp { get; set; }
  262. /// <summary>
  263. ///
  264. /// </summary>
  265. public List<string> CommonTitle { get; set; }
  266. /// <summary>
  267. ///
  268. /// </summary>
  269. public List<int> recordState { get; set; }
  270. /// <summary>
  271. ///
  272. /// </summary>
  273. public List<string> ProductLine { get; set; }
  274. /// <summary>
  275. ///
  276. /// </summary>
  277. public List<string> CommonTitlePinyin { get; set; }
  278. /// <summary>
  279. ///
  280. /// </summary>
  281. public List<int> MerchantManageCode { get; set; }
  282. /// <summary>
  283. ///
  284. /// </summary>
  285. public List<int> PackingNumber { get; set; }
  286. /// <summary>
  287. ///
  288. /// </summary>
  289. public List<string> ProductType { get; set; }
  290. /// <summary>
  291. ///
  292. /// </summary>
  293. public List<string> IsControl { get; set; }
  294. /// <summary>
  295. ///
  296. /// </summary>
  297. public List<string> PinyinFullCode { get; set; }
  298. /// <summary>
  299. ///
  300. /// </summary>
  301. public List<int> ControlNumber { get; set; }
  302. /// <summary>
  303. ///
  304. /// </summary>
  305. public List<string> OutOfStockRecommendCodes { get; set; }
  306. /// <summary>
  307. ///
  308. /// </summary>
  309. public List<string> PostageLogo { get; set; }
  310. /// <summary>
  311. ///
  312. /// </summary>
  313. public List<int> ManufacturerCode { get; set; }
  314. /// <summary>
  315. ///
  316. /// </summary>
  317. public List<int> ProductCodeForOutOfStock { get; set; }
  318. /// <summary>
  319. ///
  320. /// </summary>
  321. public List<int> PlaceCode { get; set; }
  322. /// <summary>
  323. ///
  324. /// </summary>
  325. public List<string> ApprovalNumber { get; set; }
  326. /// <summary>
  327. ///
  328. /// </summary>
  329. public List<int> PurchasePrice { get; set; }
  330. /// <summary>
  331. ///
  332. /// </summary>
  333. public List<int> CategoryType { get; set; }
  334. /// <summary>
  335. ///
  336. /// </summary>
  337. public List<int> MassDate { get; set; }
  338. /// <summary>
  339. ///
  340. /// </summary>
  341. public List<string> ProductAttribute { get; set; }
  342. /// <summary>
  343. ///
  344. /// </summary>
  345. public List<string> DivisionCode { get; set; }
  346. /// <summary>
  347. ///
  348. /// </summary>
  349. public List<string> Molecular { get; set; }
  350. /// <summary>
  351. ///
  352. /// </summary>
  353. public List<string> ProductRecommend { get; set; }
  354. /// <summary>
  355. ///
  356. /// </summary>
  357. public List<string> GiftCategory { get; set; }
  358. /// <summary>
  359. ///
  360. /// </summary>
  361. public List<string> Structure { get; set; }
  362. /// <summary>
  363. ///
  364. /// </summary>
  365. public List<int> HealthInsuranceType { get; set; }
  366. /// <summary>
  367. ///
  368. /// </summary>
  369. public List<string> IsDrugRecord { get; set; }
  370. /// <summary>
  371. ///
  372. /// </summary>
  373. public List<string> ShowMall { get; set; }
  374. /// <summary>
  375. ///
  376. /// </summary>
  377. public List<int> ConsumeDays { get; set; }
  378. /// <summary>
  379. ///
  380. /// </summary>
  381. public List<int> PlureProductStatusType { get; set; }
  382. /// <summary>
  383. ///
  384. /// </summary>
  385. public List<string> IsSuit { get; set; }
  386. /// <summary>
  387. ///
  388. /// </summary>
  389. public List<int> CheckPendingPrice { get; set; }
  390. /// <summary>
  391. ///
  392. /// </summary>
  393. public List<string> IsVisible { get; set; }
  394. /// <summary>
  395. ///
  396. /// </summary>
  397. public List<int> UsageCode { get; set; }
  398. /// <summary>
  399. ///
  400. /// </summary>
  401. public List<string> ThumbnailUrl { get; set; }
  402. /// <summary>
  403. ///
  404. /// </summary>
  405. public List<string> Productusecrowd { get; set; }
  406. /// <summary>
  407. ///
  408. /// </summary>
  409. public List<string> BtManual { get; set; }
  410. /// <summary>
  411. ///
  412. /// </summary>
  413. public List<int> BrandCode { get; set; }
  414. /// <summary>
  415. ///
  416. /// </summary>
  417. public List<string> ProductusecrowdCode { get; set; }
  418. /// <summary>
  419. ///
  420. /// </summary>
  421. public List<string> SFDAGmpCertificateDate { get; set; }
  422. /// <summary>
  423. ///
  424. /// </summary>
  425. public List<string> Unit { get; set; }
  426. /// <summary>
  427. ///
  428. /// </summary>
  429. public List<string> Formula { get; set; }
  430. /// <summary>
  431. ///
  432. /// </summary>
  433. public List<int> ProductHotType { get; set; }
  434. /// <summary>
  435. ///
  436. /// </summary>
  437. public List<string> Formulation { get; set; }
  438. /// <summary>
  439. ///
  440. /// </summary>
  441. public List<int> Views { get; set; }
  442. /// <summary>
  443. ///
  444. /// </summary>
  445. public List<string> PinyinCode { get; set; }
  446. /// <summary>
  447. ///
  448. /// </summary>
  449. public List<int> OurPrice { get; set; }
  450. /// <summary>
  451. ///
  452. /// </summary>
  453. public List<string> Img180 { get; set; }
  454. /// <summary>
  455. ///
  456. /// </summary>
  457. public List<string> Inspection { get; set; }
  458. /// <summary>
  459. ///
  460. /// </summary>
  461. public List<string> SyncStatus { get; set; }
  462. /// <summary>
  463. ///
  464. /// </summary>
  465. public List<string> SFDACode { get; set; }
  466. /// <summary>
  467. ///
  468. /// </summary>
  469. public List<int> Weight { get; set; }
  470. /// <summary>
  471. ///
  472. /// </summary>
  473. public List<string> Img100 { get; set; }
  474. /// <summary>
  475. ///
  476. /// </summary>
  477. public List<string> GmpCertificateUrl { get; set; }
  478. /// <summary>
  479. ///
  480. /// </summary>
  481. public List<string> ClassCode { get; set; }
  482. /// <summary>
  483. ///
  484. /// </summary>
  485. public List<int> MinMarketPrice { get; set; }
  486. /// <summary>
  487. ///
  488. /// </summary>
  489. public List<string> StandardCode { get; set; }
  490. /// <summary>
  491. ///
  492. /// </summary>
  493. public List<int> BranchCode { get; set; }
  494. /// <summary>
  495. ///
  496. /// </summary>
  497. public List<int> PriceSectorPricing { get; set; }
  498. /// <summary>
  499. ///
  500. /// </summary>
  501. public List<int> FormulationCode { get; set; }
  502. /// <summary>
  503. ///
  504. /// </summary>
  505. public List<int> CQuantity { get; set; }
  506. /// <summary>
  507. ///
  508. /// </summary>
  509. public List<string> BarCode { get; set; }
  510. /// <summary>
  511. ///
  512. /// </summary>
  513. public List<string> ExternalID { get; set; }
  514. /// <summary>
  515. ///
  516. /// </summary>
  517. public List<string> Productmainmaterial { get; set; }
  518. /// <summary>
  519. ///
  520. /// </summary>
  521. public List<string> BusinessIds { get; set; }
  522. /// <summary>
  523. ///
  524. /// </summary>
  525. public List<string> ControlAreaRegion { get; set; }
  526. /// <summary>
  527. ///
  528. /// </summary>
  529. public List<int> XQuantity { get; set; }
  530. /// <summary>
  531. ///
  532. /// </summary>
  533. public List<int> PrescriptionType { get; set; }
  534. /// <summary>
  535. ///
  536. /// </summary>
  537. public List<int> QcClass { get; set; }
  538. /// <summary>
  539. ///
  540. /// </summary>
  541. public List<string> ProfitLevel { get; set; }
  542. /// <summary>
  543. ///
  544. /// </summary>
  545. public List<string> PurchaseWhile { get; set; }
  546. /// <summary>
  547. ///
  548. /// </summary>
  549. public List<string> SuitDescription { get; set; }
  550. /// <summary>
  551. ///
  552. /// </summary>
  553. public List<int> MarketPrice { get; set; }
  554. /// <summary>
  555. ///
  556. /// </summary>
  557. public List<int> ProductStatusType { get; set; }
  558. /// <summary>
  559. ///
  560. /// </summary>
  561. public List<int> SFDAStatus { get; set; }
  562. /// <summary>
  563. ///
  564. /// </summary>
  565. public List<string> Composition { get; set; }
  566. /// <summary>
  567. ///
  568. /// </summary>
  569. public List<string> UserName { get; set; }
  570. /// <summary>
  571. ///
  572. /// </summary>
  573. public List<string> IsGifts { get; set; }
  574. /// <summary>
  575. ///
  576. /// </summary>
  577. public List<int> Quantity { get; set; }
  578. /// <summary>
  579. ///
  580. /// </summary>
  581. public List<string> Img320 { get; set; }
  582. /// <summary>
  583. ///
  584. /// </summary>
  585. public List<string> SFDAApprovalValidDate { get; set; }
  586. /// <summary>
  587. ///
  588. /// </summary>
  589. public List<string> Displaytab { get; set; }
  590. }
  591. public class HitsItem
  592. {
  593. /// <summary>
  594. ///
  595. /// </summary>
  596. public string _index { get; set; }
  597. /// <summary>
  598. ///
  599. /// </summary>
  600. public string _type { get; set; }
  601. /// <summary>
  602. ///
  603. /// </summary>
  604. public string _id { get; set; }
  605. /// <summary>
  606. ///
  607. /// </summary>
  608. public string _score { get; set; }
  609. /// <summary>
  610. ///
  611. /// </summary>
  612. public _source _source { get; set; }
  613. /// <summary>
  614. ///
  615. /// </summary>
  616. public Fields fields { get; set; }
  617. /// <summary>
  618. ///
  619. /// </summary>
  620. public List<int> sort { get; set; }
  621. }
  622. public class Hits
  623. {
  624. /// <summary>
  625. ///
  626. /// </summary>
  627. public Total total { get; set; }
  628. /// <summary>
  629. ///
  630. /// </summary>
  631. public string max_score { get; set; }
  632. /// <summary>
  633. ///
  634. /// </summary>
  635. public List<HitsItem> hits { get; set; }
  636. }
  637. public class Root
  638. {
  639. /// <summary>
  640. ///
  641. /// </summary>
  642. public int took { get; set; }
  643. /// <summary>
  644. ///
  645. /// </summary>
  646. public string timed_out { get; set; }
  647. /// <summary>
  648. ///
  649. /// </summary>
  650. public _shards _shards { get; set; }
  651. /// <summary>
  652. ///
  653. /// </summary>
  654. public Hits hits { get; set; }
  655. }
  656. #endregion
  657. # region 总数实体类
  658. public class ColumnsItem
  659. {
  660. /// <summary>
  661. ///
  662. /// </summary>
  663. public string name { get; set; }
  664. /// <summary>
  665. ///
  666. /// </summary>
  667. public string type { get; set; }
  668. }
  669. public class Num
  670. {
  671. /// <summary>
  672. ///
  673. /// </summary>
  674. public List<ColumnsItem> columns { get; set; }
  675. /// <summary>
  676. ///
  677. /// </summary>
  678. public List<List<int>> rows { get; set; }
  679. }
  680. #endregion
  681. }
  682. }