From b7d11e991f6d0a45bb54d5a731e6cab4c0c79630 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Wed, 6 Mar 2019 16:26:07 +0800 Subject: [PATCH] =?UTF-8?q?(#2)=E4=B8=87=E4=BB=95=E8=BE=BE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebSiteCode/Cmdjy/Cmdjy.sln | 6 + WebSiteCode/Cmdjy/Cmdjy/Bll/DesHelper.cs | 1 - WebSiteCode/Cmdjy/Cmdjy/Bll/ObjExtend.cs | 38 +++++++ WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj | 1 + .../Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs | 104 +++++++++++++----- .../Cmdjy/CmdjyTests/Bll/ObjExtendTests.cs | 47 ++++++++ .../Cmdjy/CmdjyTests/CmdjyTests.csproj | 90 +++++++++++++++ .../CmdjyTests/Properties/AssemblyInfo.cs | 36 ++++++ 8 files changed, 294 insertions(+), 29 deletions(-) create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Bll/ObjExtend.cs create mode 100644 WebSiteCode/Cmdjy/CmdjyTests/Bll/ObjExtendTests.cs create mode 100644 WebSiteCode/Cmdjy/CmdjyTests/CmdjyTests.csproj create mode 100644 WebSiteCode/Cmdjy/CmdjyTests/Properties/AssemblyInfo.cs diff --git a/WebSiteCode/Cmdjy/Cmdjy.sln b/WebSiteCode/Cmdjy/Cmdjy.sln index 4e9ac8a..78bf7da 100644 --- a/WebSiteCode/Cmdjy/Cmdjy.sln +++ b/WebSiteCode/Cmdjy/Cmdjy.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.27703.2042 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmdjy", "Cmdjy\Cmdjy.csproj", "{03F35833-1CF9-42BC-BF51-444F7181A967}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CmdjyTests", "CmdjyTests\CmdjyTests.csproj", "{812C9905-9C11-40FD-B58F-02C8A880C494}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {03F35833-1CF9-42BC-BF51-444F7181A967}.Debug|Any CPU.Build.0 = Debug|Any CPU {03F35833-1CF9-42BC-BF51-444F7181A967}.Release|Any CPU.ActiveCfg = Release|Any CPU {03F35833-1CF9-42BC-BF51-444F7181A967}.Release|Any CPU.Build.0 = Release|Any CPU + {812C9905-9C11-40FD-B58F-02C8A880C494}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {812C9905-9C11-40FD-B58F-02C8A880C494}.Debug|Any CPU.Build.0 = Debug|Any CPU + {812C9905-9C11-40FD-B58F-02C8A880C494}.Release|Any CPU.ActiveCfg = Release|Any CPU + {812C9905-9C11-40FD-B58F-02C8A880C494}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WebSiteCode/Cmdjy/Cmdjy/Bll/DesHelper.cs b/WebSiteCode/Cmdjy/Cmdjy/Bll/DesHelper.cs index 9e4d97d..d2d4d58 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Bll/DesHelper.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Bll/DesHelper.cs @@ -46,7 +46,6 @@ namespace Cmdjy.Bll /// 从Base64密文解密,获取字符串 /// /// 密文 - /// public string DesCrypty(string str) { var bStr = Convert.FromBase64String(str); byte[] bKey = Encoding.UTF8.GetBytes(Key.Substring(0,8)); diff --git a/WebSiteCode/Cmdjy/Cmdjy/Bll/ObjExtend.cs b/WebSiteCode/Cmdjy/Cmdjy/Bll/ObjExtend.cs new file mode 100644 index 0000000..3c0adca --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Bll/ObjExtend.cs @@ -0,0 +1,38 @@ +namespace Cmdjy.Bll +{ + using System; + + public static class ObjExtend + { + /// + /// 从目标对象中复制属性的值,执行浅表复制 + /// + /// 复制目标 + /// 复制原 + public static void CopyFrom(this object t,object s) { + foreach(var p in s.GetType().GetProperties()) { + if(p.CanRead) { + var tp = t.GetType().GetProperty(p.Name); + if(tp != null && tp.CanWrite && canConvert(p.PropertyType,tp.PropertyType)) { + tp.SetValue(t,p.GetValue(s)); + //tp.SetValue(t,Convert.ChangeType(p.GetValue(s),tp.PropertyType)); + } + } + } + } + /// + /// 判断一个类型是否可以转换为另一个类型 + /// + /// 原类型 + /// 目标类型 + private static bool canConvert(Type source,Type target) { + //引用类型判断 + if(target.IsAssignableFrom(source)) { + return true; + } + //Nullable<>类型判断 + //值类型判断 + return false; + } + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj index 4af261a..9a21f34 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj +++ b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj @@ -186,6 +186,7 @@ + diff --git a/WebSiteCode/Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs b/WebSiteCode/Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs index 3b889c9..d305b73 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/ws/WsdInterface.asmx.cs @@ -1,11 +1,9 @@ using System; 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 { @@ -17,7 +15,7 @@ namespace Cmdjy.ws [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService] - public class WsdInterface:System.Web.Services.WebService + public class WsdInterface:WebService { [WebMethod(Description = "获取代煎药处方信息")] @@ -29,51 +27,99 @@ namespace Cmdjy.ws int start = 0; if(!int.TryParse(info.StartNo,out start)) { result.Code = EnumCode.Exception; - result.Msg = "Start值错误,无法转换为正数"; + result.Msg = "Start值错误"; } int count = 0; if(!int.TryParse(info.MaxCount,out count)) { result.Code = EnumCode.Exception; - result.Msg = "MaxCount值错误,无法转换为正数"; + 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); - } + if(result.Code != EnumCode.Exception) { + 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) { + //从数据库获取处方信息 + one = getPrescriptionInfoFromDb(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 = ""; + using(var db = new Dal.DjyDbContext()) { + result.More = db.PrescriptionInfos.Max(m => m.Id) > (start + count); } - //从数据库获取 } //编码:json串 + 加密信息 try { var resStr = JsonConvert.SerializeObject(result); - var dsc = DesHelper.GetHelper(); - var mw = dsc.Encrypty(resStr); + var mw = DesHelper.GetHelper().Encrypty(resStr); return mw; } catch(Exception ex) { return ex.ToString(); } } + + /// + /// 从数据库获取药品列表 + /// + /// 处方号 + private static List getDrugInfoFromDb(int id) { + List result = null; + using(var db = new Dal.DjyDbContext()) { + 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 static WsdPrescriptionInfo getPrescriptionInfoFromDb(int i) { + WsdPrescriptionInfo result = 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()) { + var fir = qu.First(); + result = new WsdPrescriptionInfo(); + result.CopyFrom(fir); + } + } + return result; + } } + /// + /// 第三方请求数据 + /// public class WsdRequest { /// @@ -85,7 +131,9 @@ namespace Cmdjy.ws /// public string MaxCount { get; set; } } - + /// + /// 服务器响应数据 + /// public class WsdResult { /// @@ -127,7 +175,7 @@ namespace Cmdjy.ws } /// - /// HIS发送的处方信息 + /// 处方信息 /// public class WsdPrescriptionInfo { @@ -278,7 +326,7 @@ namespace Cmdjy.ws } /// - /// HIS发送的药品信息 + /// 药品信息 /// public class WsdDrugInfo { diff --git a/WebSiteCode/Cmdjy/CmdjyTests/Bll/ObjExtendTests.cs b/WebSiteCode/Cmdjy/CmdjyTests/Bll/ObjExtendTests.cs new file mode 100644 index 0000000..a73e928 --- /dev/null +++ b/WebSiteCode/Cmdjy/CmdjyTests/Bll/ObjExtendTests.cs @@ -0,0 +1,47 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Cmdjy.Bll; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cmdjy.Bll.Tests +{ + [TestClass()] + public class ObjExtendTests + { + [TestMethod()] + public void CopyFromTest() { + var s = new a { inta = 1,strb = "abc",c = 2,e = "eee",f = "6",g = 7 }; + var t = new b { intd = 3,e = 4,f = 1,}; + t.CopyFrom(s); + Assert.AreEqual(s.inta,t.inta); + Assert.AreEqual(s.strb,t.strb); + Assert.IsTrue(s.c == 2); + Assert.IsTrue(t.intd == 3); + Assert.IsTrue(t.e == 4); + Assert.IsTrue(t.f == 1); + //Assert.IsTrue(t.g == 7); + } + } + + public class a + { + public int inta { get; set; } + public string strb { get; set; } + public int c { get; set; } + public string e { get; set; } + public string f { get; set; } + public int g { get; set; } + } + public class b + { + public int inta { get; set; } + public string strb { get; set; } + public int intd { get; set; } + public int e { get; set; } + public int f { get; set; } + public double g { get; set; } + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/CmdjyTests/CmdjyTests.csproj b/WebSiteCode/Cmdjy/CmdjyTests/CmdjyTests.csproj new file mode 100644 index 0000000..22268a2 --- /dev/null +++ b/WebSiteCode/Cmdjy/CmdjyTests/CmdjyTests.csproj @@ -0,0 +1,90 @@ + + + + Debug + AnyCPU + {812C9905-9C11-40FD-B58F-02C8A880C494} + Library + Properties + CmdjyTests + CmdjyTests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {03F35833-1CF9-42BC-BF51-444F7181A967} + Cmdjy + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/CmdjyTests/Properties/AssemblyInfo.cs b/WebSiteCode/Cmdjy/CmdjyTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c4e4221 --- /dev/null +++ b/WebSiteCode/Cmdjy/CmdjyTests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("CmdjyTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("CmdjyTests")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("812c9905-9c11-40fd-b58f-02c8a880c494")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]