(#2)万仕达接口完善

This commit is contained in:
falcon 2019-03-06 16:26:07 +08:00
parent 7b3cfa97fc
commit b7d11e991f
8 changed files with 294 additions and 29 deletions

View File

@ -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

View File

@ -46,7 +46,6 @@ namespace Cmdjy.Bll
/// 从Base64密文解密获取字符串
/// </summary>
/// <param name="str">密文</param>
/// <returns></returns>
public string DesCrypty(string str) {
var bStr = Convert.FromBase64String(str);
byte[] bKey = Encoding.UTF8.GetBytes(Key.Substring(0,8));

View File

@ -0,0 +1,38 @@
namespace Cmdjy.Bll
{
using System;
public static class ObjExtend
{
/// <summary>
/// 从目标对象中复制属性的值,执行浅表复制
/// </summary>
/// <param name="t">复制目标</param>
/// <param name="s">复制原</param>
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));
}
}
}
}
/// <summary>
/// 判断一个类型是否可以转换为另一个类型
/// </summary>
/// <param name="source">原类型</param>
/// <param name="target">目标类型</param>
private static bool canConvert(Type source,Type target) {
//引用类型判断
if(target.IsAssignableFrom(source)) {
return true;
}
//Nullable<>类型判断
//值类型判断
return false;
}
}
}

View File

@ -186,6 +186,7 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Bll\DesHelper.cs" />
<Compile Include="Bll\Cache.cs" />
<Compile Include="Bll\ObjExtend.cs" />
<Compile Include="Controllers\HisInfoController.cs" />
<Compile Include="Dal\Configuration.cs" />
<Compile Include="Dal\Queryes\HisDrugQuery.cs" />

View File

@ -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<WsdPrescriptionInfo>(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<WsdPrescriptionInfo>(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();
}
}
/// <summary>
/// 从数据库获取药品列表
/// </summary>
/// <param name="id">处方号</param>
private static List<WsdDrugInfo> getDrugInfoFromDb(int id) {
List<WsdDrugInfo> result = null;
using(var db = new Dal.DjyDbContext()) {
var qu = db.DrugInfos.Where(m => m.PrescriptionId == id);
if(qu.Any()) {
result = new List<WsdDrugInfo>();
foreach(var item in qu) {
var od = new WsdDrugInfo();
od.CopyFrom(item);
result.Add(od);
}
}
}
return result;
}
/// <summary>
/// 从数据库获取处方
/// </summary>
/// <param name="i">处方号</param>
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;
}
}
/// <summary>
/// 第三方请求数据
/// </summary>
public class WsdRequest
{
/// <summary>
@ -85,7 +131,9 @@ namespace Cmdjy.ws
/// </summary>
public string MaxCount { get; set; }
}
/// <summary>
/// 服务器响应数据
/// </summary>
public class WsdResult
{
/// <summary>
@ -127,7 +175,7 @@ namespace Cmdjy.ws
}
/// <summary>
/// HIS发送的处方信息
/// 处方信息
/// </summary>
public class WsdPrescriptionInfo
{
@ -278,7 +326,7 @@ namespace Cmdjy.ws
}
/// <summary>
/// HIS发送的药品信息
/// 药品信息
/// </summary>
public class WsdDrugInfo
{

View File

@ -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; }
}
}

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{812C9905-9C11-40FD-B58F-02C8A880C494}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CmdjyTests</RootNamespace>
<AssemblyName>CmdjyTests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Bll\ObjExtendTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cmdjy\Cmdjy.csproj">
<Project>{03F35833-1CF9-42BC-BF51-444F7181A967}</Project>
<Name>Cmdjy</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -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")]