From 18980f1187aeba16112bfe7e275bf419fef6bb3c Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Tue, 26 Mar 2019 14:35:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=87=E4=BB=95=E8=BE=BE?= =?UTF-8?q?=E4=BB=A3=E7=85=8E=E8=8D=AFwebapi=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj | 2 +- .../Controllers/WsdInterfaceController.cs | 150 +++++++++++++++++- .../Cmdjy/Cmdjy/Views/Home/Index.cshtml | 1 + .../Cmdjy/Views/WsdInterface/Index.cshtml | 21 +++ 4 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Views/WsdInterface/Index.cshtml diff --git a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj index f6455d7..3c5f8cd 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj +++ b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj @@ -277,12 +277,12 @@ + - diff --git a/WebSiteCode/Cmdjy/Cmdjy/Controllers/WsdInterfaceController.cs b/WebSiteCode/Cmdjy/Cmdjy/Controllers/WsdInterfaceController.cs index 3edb71a..5fdda5e 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Controllers/WsdInterfaceController.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Controllers/WsdInterfaceController.cs @@ -3,15 +3,155 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; +using WsdInterfaceModels; +using Cmdjy.Dal; +using Cmdjy.Dal.Tables; +using Cmdjy.Bll; +using Newtonsoft.Json; +using CommonHelper; namespace Cmdjy.Controllers { - public class WsdInterfaceController : Controller + public class WsdInterfaceController:Controller { - // GET: WsdInterface - public ActionResult Index() - { - return View(); + public Lazy Db { get; set; } + + public ActionResult Index() { + var model = new WsdRequest { + StartNo = "0",MaxCount = "10", + CompanyCode="1", CompanyName= "万仕达", + }; + return PartialView(model); } + + public ActionResult GetData(WsdRequest info) { + var result = new WsdResult { + Code = EnumCode.Success, + }; + string cKey = null; + var db = this.Db.Value; + var companyInfo = db.CompanyInfos.Where(m => m.Id.ToString() == info.CompanyCode); + if(companyInfo.Any()) { + cKey = companyInfo.First().SecurityKey; + } + if(string.IsNullOrEmpty(cKey)) { + result.Code = EnumCode.Exception; + result.Msg = "CompanyCode值错误"; + } + //获取数据 + int start = 0; + if(!int.TryParse(info.StartNo,out start)) { + result.Code = EnumCode.Exception; + result.Msg = "Start值错误"; + } + int count = 0; + if(!int.TryParse(info.MaxCount,out count)) { + result.Code = EnumCode.Exception; + result.Msg = "MaxCount值错误"; + } + if(count <= 0) { + result.Code = EnumCode.Exception; + result.Msg = "Count值错误。"; + } + if(result.Code != EnumCode.Exception) { + result.Prescriptions = new List(); + count = count > WebSettings.WsdMaxCount ? WebSettings.WsdMaxCount : count; + var cache = CacheFactory.Cache; + for(int i = start;i < start + count;i++) { + //从缓存获取 + var pkey = $"Company:Id:{info.CompanyCode}:Pre:Id:{i}"; + var one = cache.GetData(pkey); + if(one == null) { + //从数据库获取处方信息 + one = getPrescriptionInfoFromDb(info.CompanyCode,i); + //判断是否为 + //获取药品信息 + if(one != null) one.Drugs = getDrugInfoFromDb(one.Id); + //存缓存 + if(one != null) cache.SetData(pkey,one); + } + //对应代煎药厂商 + if(one == null) { + one = new WsdPrescriptionInfo { + Type = WsdPrescriptionType.NullOrder,Id = i, + }; + } + result.Prescriptions.Add(one); + } + result.Code = EnumCode.Success; + result.Count = result.Prescriptions.Where(m => m.Type != WsdPrescriptionType.NullOrder).Count(); + result.Msg = ""; + result.More = db.PrescriptionInfos.Max(m => m.Id) > (start + count); + } + //编码:json串 + 加密信息 + var resStr = JsonConvert.SerializeObject(result); + return Content(resStr); + //var mw = DesHelper.GetHelper().Encrypty(cKey,resStr); + //logWsdRequest(info,result,resStr,mw); + //return mw; + } + /// + /// 记录日志 + /// + /// 请求信息 + /// 响应对象 + /// 响应字符串 + /// 响应密文 + private void logWsdRequest(WsdRequest info,WsdResult result,string resStr,string mw) { + var db = this.Db.Value; + if(result != null && result.Prescriptions != null) { + foreach(var p in result.Prescriptions) { + if(p.Drugs != null) { + foreach(var d in p.Drugs) { + db.WsdRequestLogs.Add(new Dal.Tables.WsdRequestLog { + StartNo = info.StartNo,MaxCount = info.MaxCount, + ClientAddress = Request.UserHostAddress, + LogDatatime = DateTime.Now,DrugId = d.Id.ToString(), + PrescriptionId = p.Id.ToString(), + Code = result.Code.ToString(),Msg = result.Msg, + }); + } + } + } + } + db.SaveChanges(); + } + + /// + /// 从数据库获取药品列表 + /// + /// 处方号 + private List getDrugInfoFromDb(int id) { + List result = null; + var db = this.Db.Value; + var qu = db.DrugInfos.Where(m => m.PrescriptionId == id); + if(qu.Any()) { + result = new List(); + foreach(var item in qu) { + var od = new WsdDrugInfo(); + od.CopyFrom(item); + result.Add(od); + } + } + return result; + } + /// + /// 从数据库获取处方 + /// + /// 处方号 + private WsdPrescriptionInfo getPrescriptionInfoFromDb(string cId,int i) { + WsdPrescriptionInfo result = null; + var db = this.Db.Value; + var qu = db.PrescriptionInfos + .Where(m => m.Id == i && m.CompanyCode == cId) + .Where(m => m.Type == Dal.Tables.PrescriptionType.Order || m.Type == Dal.Tables.PrescriptionType.CancelOrder); + if(qu.Any()) { + var fir = qu.First(); + result = new WsdPrescriptionInfo(); + result.CopyFrom(fir); + } + return result; + } + } } \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Views/Home/Index.cshtml b/WebSiteCode/Cmdjy/Cmdjy/Views/Home/Index.cshtml index d14c16c..1b5b0da 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Views/Home/Index.cshtml +++ b/WebSiteCode/Cmdjy/Cmdjy/Views/Home/Index.cshtml @@ -3,6 +3,7 @@
  1. @Ajax.ActionLink("厂商列表","Index","Company",new AjaxOptions { UpdateTargetId = "main" })
  2. @Ajax.ActionLink("医疗机构处方列表","Index","HisInfo",new AjaxOptions { UpdateTargetId = "main" })
  3. +
  4. @Ajax.ActionLink("万仕达下载测试","Index","WsdInterface",new AjaxOptions { UpdateTargetId = "main" })

\ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Views/WsdInterface/Index.cshtml b/WebSiteCode/Cmdjy/Cmdjy/Views/WsdInterface/Index.cshtml new file mode 100644 index 0000000..abbf679 --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Views/WsdInterface/Index.cshtml @@ -0,0 +1,21 @@ +@model WsdInterfaceModels.WsdRequest + +
+ 要查询的数据 + @using(Ajax.BeginForm("GetData",new AjaxOptions { + OnSuccess = "wsdSucc", + })) { + + + + + + } +
+
+ + \ No newline at end of file