From 7391532639099b436debdeaa6012f5ff6bdbaac1 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Mon, 4 Mar 2019 17:02:09 +0800 Subject: [PATCH] =?UTF-8?q?(#3)=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=92=8C=E6=95=B0=E6=8D=AE=E7=BC=93=E5=AD=98=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs | 14 ++-- WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj | 2 + .../Cmdjy/Cmdjy/Dal/Queryes/HisDrugQuery.cs | 84 +++++++++++++++++++ .../Cmdjy/Dal/Queryes/HisPrescriptionQuery.cs | 56 +++++++++++++ .../Cmdjy/Cmdjy/Dal/Queryes/IDbQuery.cs | 17 ++++ .../Cmdjy/Cmdjy/Dal/Tables/HisDrugInfo.cs | 2 +- WebSiteCode/Cmdjy/Cmdjy/Web.config | 3 + WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs | 12 +++ .../Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs | 82 ++++++++++++++++-- 9 files changed, 258 insertions(+), 14 deletions(-) create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/HisDrugQuery.cs create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/HisPrescriptionQuery.cs create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/IDbQuery.cs diff --git a/WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs b/WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs index 7d6037a..608bd41 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs @@ -7,7 +7,7 @@ namespace Cmdjy.Bll /// /// 缓冲提供器工厂 /// - public class CacheFactory + public static class CacheFactory { /// /// 缓冲提供器 @@ -63,21 +63,23 @@ namespace Cmdjy.Bll public RedisHelper() { if(Connection == null) { var connectionStr = WebSettings.RedisConnectionString; - Connection = ConnectionMultiplexer.Connect(connectionStr); + if(!string.IsNullOrEmpty(connectionStr)) Connection = ConnectionMultiplexer.Connect(connectionStr); + } + if(Connection != null && Connection.IsConnected) { + this.Database = this.Database ?? Connection.GetDatabase(0); } - this.Database = this.Database ?? Connection.GetDatabase(0); } - public T GetData(string key) where T : class { + public virtual T GetData(string key) where T : class { if(!Usable) return null; return fromJson(Database.StringGet(key)); } - public void SetData(string key,T obj) { + public virtual void SetData(string key,T obj) { SetData(key,obj,new TimeSpan(3,0,0,0)); } - public void SetData(string key,T obj,TimeSpan timeSpan) { + public virtual void SetData(string key,T obj,TimeSpan timeSpan) { if(!Usable) return; if(timeSpan == null) { this.Database.StringSet(key,toJson(obj)); diff --git a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj index d5decd4..834de0a 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj +++ b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj @@ -186,6 +186,8 @@ + + diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/HisDrugQuery.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/HisDrugQuery.cs new file mode 100644 index 0000000..991f579 --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/HisDrugQuery.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Cmdjy.Dal.Tables; +using System.Linq; +using Cmdjy.Bll; +using System.Data.Entity; + +namespace Cmdjy.Dal.Queryes +{ + public interface IHisDrugQuery:IDbQuery + { + IEnumerable GetDataByPrescriptionId(int pId); + } + + public class HisDrugQuery:IHisDrugQuery + { + + public Lazy Cache { get; set; } + + public HisDrugQuery() { + this.Cache = new Lazy(() => CacheFactory.Cache); + } + + + public IEnumerable GetAll() { + using(var db = new DjyDbContext()) { + return GetQuery(db).ToList(); + } + } + + public IEnumerable GetDataByPrescriptionId(int pId) { + var key = getPKey(pId.ToString()); + var val = this.Cache.Value.GetData>(key); + if(val == null) { + using(var db = new DjyDbContext()) { + val = GetQuery(db).Where(m => m.PrescriptionId == pId).ToList(); + if(val != null) this.Cache.Value.SetData(key,val); + } + } + return val; + } + + public HisDrugInfo GetOne(TKey id) { + var key = getKey(id.ToString()); + var val = this.Cache.Value.GetData(key); + if(val == null) { + using(var db = new DjyDbContext()) { + val = db.DrugInfos.Find(id); + if(val != null) this.Cache.Value.SetData(key,val); + } + } + return val; + } + + public IQueryable GetQuery(DjyDbContext db) { + return db.DrugInfos.AsQueryable(); + } + + public void Insert(HisDrugInfo obj) { + using(var db = new DjyDbContext()) { + db.Entry(obj).State = EntityState.Added; + db.SaveChanges(); + } + var key = getKey(obj.Id.ToString()); + this.Cache.Value.SetData(key,obj); + var pkey = getPKey(obj.PrescriptionId.ToString()); + var val = this.Cache.Value.GetData>(key); + if(val == null) val = new List(); + val.ToList().Add(obj); + this.Cache.Value.SetData(pkey,val); + } + + private string getKey(string id) { + return $"Db:HisDrugInfo:Id:{id}"; + } + + private string getPKey(string pId) { + return $"Db:HisDrugInfo:PrescriptionId:{pId}"; + } + + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/HisPrescriptionQuery.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/HisPrescriptionQuery.cs new file mode 100644 index 0000000..b9cbfee --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/HisPrescriptionQuery.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Cmdjy.Dal.Tables; +using System.Data.Entity; +using Cmdjy.Bll; + +namespace Cmdjy.Dal.Queryes +{ + public interface IHisPrescriptionQuery:IDbQuery { } + + public class HisPrescriptionQuery:IHisPrescriptionQuery + { + public Lazy Cache { get; set; } + + public HisPrescriptionQuery() { + this.Cache = new Lazy(() => CacheFactory.Cache); + } + + public IEnumerable GetAll() { + using(var db = new DjyDbContext()) { + return db.PrescriptionInfos.ToList(); + } + } + + public HisPrescriptionInfo GetOne(TKey id) { + var key = getKey(id.ToString()); + var val = this.Cache.Value.GetData(key); + if(val == null) { + using(var db = new DjyDbContext()) { + val = db.PrescriptionInfos.Find(id); + if(val != null) this.Cache.Value.SetData(key,val); + } + } + return val; + } + + public void Insert(HisPrescriptionInfo obj) { + using(var db = new DjyDbContext()) { + db.Entry(obj).State = EntityState.Added; + db.SaveChanges(); + } + var key = getKey(obj.Id.ToString()); + this.Cache.Value.SetData(key,obj); + } + + IQueryable IDbQuery.GetQuery(DjyDbContext db) { + return db.PrescriptionInfos.AsQueryable(); + } + + private string getKey(string id) { + return $"Db:HisPrescriptionInfo:Id:{id}"; + } + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/IDbQuery.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/IDbQuery.cs new file mode 100644 index 0000000..e74005a --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/Queryes/IDbQuery.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Cmdjy.Dal.Queryes +{ + /// + /// 数据查询基础接口 + /// + /// 数据类型 + public interface IDbQuery + { + T GetOne(TKey id); + IEnumerable GetAll(); + void Insert(T obj); + IQueryable GetQuery(DjyDbContext db); + } +} diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/HisDrugInfo.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/HisDrugInfo.cs index 3b8932b..49dc655 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/HisDrugInfo.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/HisDrugInfo.cs @@ -10,7 +10,7 @@ namespace Cmdjy.Dal.Tables /// /// HIS发送的药品信息 /// - [Table("HisPrescriptionInfo")] + [Table("HisDrugInfo")] public class HisDrugInfo { /// diff --git a/WebSiteCode/Cmdjy/Cmdjy/Web.config b/WebSiteCode/Cmdjy/Cmdjy/Web.config index 99f2394..ed1eddc 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Web.config +++ b/WebSiteCode/Cmdjy/Cmdjy/Web.config @@ -19,6 +19,9 @@ + + + diff --git a/WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs b/WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs index 95133b9..e23cc23 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs @@ -27,5 +27,17 @@ namespace Cmdjy public static string RedisConnectionString { get => GetValue("RedisConnectionString"); } + /// + /// 万仕达接口一次最大传送处方数 + /// + public static int WsdMaxCount { + get { + var v = GetValue("wsd:maxCount"); + if(int.TryParse(v,out int iv)) { + return iv; + } + return 100; + } + } } } \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs b/WebSiteCode/Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs index 9842e6d..3b889c9 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; +using Cmdjy.Bll; +using Newtonsoft.Json; +using Cmdjy.Bll; namespace Cmdjy.ws { @@ -18,15 +21,56 @@ namespace Cmdjy.ws { [WebMethod(Description = "获取代煎药处方信息")] - public string GetData(WsdPrescriptionInfo info) { - //获取数据 - - //实例化WsdResult - var result = new WsdRequest { - + public string GetData(WsdRequest info) { + var result = new WsdResult { }; + result.Prescriptions = new List(); + //获取数据 + 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值小于0。"; + } + count = count > WebSettings.WsdMaxCount ? WebSettings.WsdMaxCount : count; + var cache = CacheFactory.Cache; + for(int i = start;i < start + count;i++) { + //从缓存获取 + var pkey = $"Wsd:Pre:Id:{i}"; + var one = cache.GetData(pkey); + if(one == null) { + using(var db = new Dal.DjyDbContext()) { + var qu = db.PrescriptionInfos + .Where(m => m.Id == i) + .Where(m => m.Type == Dal.Tables.PrescriptionType.Order || m.Type == Dal.Tables.PrescriptionType.CancelOrder); + if(qu.Any()) { + one = new WsdPrescriptionInfo { + + }; + cache.SetData(pkey,one); + } + } + } + //从数据库获取 + } //编码:json串 + 加密信息 - return "Hello World"; + try { + var resStr = JsonConvert.SerializeObject(result); + var dsc = DesHelper.GetHelper(); + var mw = dsc.Encrypty(resStr); + return mw; + } + catch(Exception ex) { + return ex.ToString(); + } } } @@ -44,6 +88,14 @@ namespace Cmdjy.ws public class WsdResult { + /// + /// 返回信息代码 + /// + public EnumCode Code { get; set; } + /// + /// 返回信息 + /// + public string Msg { get; set; } /// /// 本次发送的处方数 /// @@ -58,6 +110,22 @@ namespace Cmdjy.ws public List Prescriptions { get; set; } } + /// + /// 返回信息代码 + /// + [Flags] + public enum EnumCode + { + /// + /// 执行成功。 + /// + Success = 1, + /// + /// 发生异常,异常信息见msg参数。 + /// + Exception = 2, + } + /// /// HIS发送的处方信息 ///