From f4341c813a417d8059fffa6c3feb35e593cb935a Mon Sep 17 00:00:00 2001 From: LiJiaWen Date: Thu, 6 Aug 2026 16:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 项目全量提交 --- .gitignore | 54 ++ LIS-Platform-Linker.sln | 25 + .../Controllers/ReceiverController.cs | 44 + .../Controllers/SenderController.cs | 17 + .../Dtos/LIS/QueryApplyLISRequest.cs | 21 + .../Dtos/LIS/SubmitReportLISRequest.cs | 21 + .../Dtos/Platform/BasePlatformRequest.cs | 29 + .../Dtos/Platform/QueryApplyData.cs | 27 + .../Dtos/Platform/SubmitReportData.cs | 769 ++++++++++++++++++ .../LIS-Platform-Linker.csproj | 23 + LIS-Platform-Linker/Program.cs | 66 ++ .../Properties/launchSettings.json | 30 + .../Services/Interfaces/IReceiverService.cs | 54 ++ .../Services/Interfaces/ISenderService.cs | 11 + .../Services/ReceiverService.cs | 289 +++++++ LIS-Platform-Linker/Services/SenderService.cs | 12 + LIS-Platform-Linker/Startup.cs | 85 ++ LIS-Platform-Linker/Tools/ConfigHelper.cs | 30 + LIS-Platform-Linker/Tools/DBHelper.cs | 109 +++ .../Tools/Extensions/DateTimeExtensions.cs | 15 + LIS-Platform-Linker/Tools/HttpClientHelper.cs | 30 + LIS-Platform-Linker/Tools/LoggerHelper.cs | 13 + LIS-Platform-Linker/Tools/MySecurity.cs | 253 ++++++ .../Nlog/CallsiteNamespaceLayoutRenderer.cs | 30 + LIS-Platform-Linker/Tools/Nlog/LogHelper.cs | 21 + LIS-Platform-Linker/Tools/Result.cs | 165 ++++ .../appsettings.Development.json | 9 + LIS-Platform-Linker/appsettings.json | 15 + LIS-Platform-Linker/nlog.config | 77 ++ 29 files changed, 2344 insertions(+) create mode 100644 .gitignore create mode 100644 LIS-Platform-Linker.sln create mode 100644 LIS-Platform-Linker/Controllers/ReceiverController.cs create mode 100644 LIS-Platform-Linker/Controllers/SenderController.cs create mode 100644 LIS-Platform-Linker/Dtos/LIS/QueryApplyLISRequest.cs create mode 100644 LIS-Platform-Linker/Dtos/LIS/SubmitReportLISRequest.cs create mode 100644 LIS-Platform-Linker/Dtos/Platform/BasePlatformRequest.cs create mode 100644 LIS-Platform-Linker/Dtos/Platform/QueryApplyData.cs create mode 100644 LIS-Platform-Linker/Dtos/Platform/SubmitReportData.cs create mode 100644 LIS-Platform-Linker/LIS-Platform-Linker.csproj create mode 100644 LIS-Platform-Linker/Program.cs create mode 100644 LIS-Platform-Linker/Properties/launchSettings.json create mode 100644 LIS-Platform-Linker/Services/Interfaces/IReceiverService.cs create mode 100644 LIS-Platform-Linker/Services/Interfaces/ISenderService.cs create mode 100644 LIS-Platform-Linker/Services/ReceiverService.cs create mode 100644 LIS-Platform-Linker/Services/SenderService.cs create mode 100644 LIS-Platform-Linker/Startup.cs create mode 100644 LIS-Platform-Linker/Tools/ConfigHelper.cs create mode 100644 LIS-Platform-Linker/Tools/DBHelper.cs create mode 100644 LIS-Platform-Linker/Tools/Extensions/DateTimeExtensions.cs create mode 100644 LIS-Platform-Linker/Tools/HttpClientHelper.cs create mode 100644 LIS-Platform-Linker/Tools/LoggerHelper.cs create mode 100644 LIS-Platform-Linker/Tools/MySecurity.cs create mode 100644 LIS-Platform-Linker/Tools/Nlog/CallsiteNamespaceLayoutRenderer.cs create mode 100644 LIS-Platform-Linker/Tools/Nlog/LogHelper.cs create mode 100644 LIS-Platform-Linker/Tools/Result.cs create mode 100644 LIS-Platform-Linker/appsettings.Development.json create mode 100644 LIS-Platform-Linker/appsettings.json create mode 100644 LIS-Platform-Linker/nlog.config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c58c90 --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# 编译输出目录 +[Dd]ebug/ +[Rr]elease/ +bin/ +obj/ + +# .NET 生成文件 +*.cs.user +*.csproj.user +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio +.vs/ +*.swp +*.vspx +*.vspscc +*.vssscc +_ReSharper*/ +*.ReSharper* + +# Rider / JetBrains +.idea/ +*.iml +*.iws +*.xml + +# VS Code +.vscode/ +*.code-workspace + +# 日志 +logs/ +*.log + +# 临时文件 +*.tmp +*.temp + +# 操作系统文件 +.DS_Store +Thumbs.db + +# dotnet tools 本地安装 +.dotnet/ + +# NuGet +*.nupkg +.nuget/ + +# 测试覆盖率 +coverage/ \ No newline at end of file diff --git a/LIS-Platform-Linker.sln b/LIS-Platform-Linker.sln new file mode 100644 index 0000000..2d409ac --- /dev/null +++ b/LIS-Platform-Linker.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.36324.18 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LIS-Platform-Linker", "LIS-Platform-Linker\LIS-Platform-Linker.csproj", "{593EF56D-F8AE-4A4F-B12D-8CA6C13885A1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {593EF56D-F8AE-4A4F-B12D-8CA6C13885A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {593EF56D-F8AE-4A4F-B12D-8CA6C13885A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {593EF56D-F8AE-4A4F-B12D-8CA6C13885A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {593EF56D-F8AE-4A4F-B12D-8CA6C13885A1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {466EAB96-E647-4084-8FD2-7D573E73B85E} + EndGlobalSection +EndGlobal diff --git a/LIS-Platform-Linker/Controllers/ReceiverController.cs b/LIS-Platform-Linker/Controllers/ReceiverController.cs new file mode 100644 index 0000000..53c01fd --- /dev/null +++ b/LIS-Platform-Linker/Controllers/ReceiverController.cs @@ -0,0 +1,44 @@ +using LIS_Platform_Linker.Dtos.LIS; +using LIS_Platform_Linker.Services.Interfaces; +using LIS_Platform_Linker.Tools; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Controllers +{ + [Route("[controller]/[action]")] + [ApiController] + public class ReceiverController : ControllerBase + { + private readonly IReceiverService receiverService; + + public ReceiverController(IReceiverService ireceiverService) + { + receiverService = ireceiverService; + } + + /// + /// 查询申请单 + /// + /// + [HttpPost] + public ActionResult QueryApply([FromBody] QueryApplyLISRequest queryApplyLISRequest) + { + return receiverService.QueryApply(queryApplyLISRequest); + } + + /// + /// 发送报告单 + /// + /// + [HttpPost] + public ActionResult SubmitReport([FromBody] SubmitReportLISRequest submitReportRequest) + { + return receiverService.SubmitReport(submitReportRequest); + } + } +} diff --git a/LIS-Platform-Linker/Controllers/SenderController.cs b/LIS-Platform-Linker/Controllers/SenderController.cs new file mode 100644 index 0000000..a3dde9a --- /dev/null +++ b/LIS-Platform-Linker/Controllers/SenderController.cs @@ -0,0 +1,17 @@ +using LIS_Platform_Linker.Tools; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Controllers +{ + [Route("[controller]/[action]")] + [ApiController] + public class SenderController : ControllerBase + { + + } +} diff --git a/LIS-Platform-Linker/Dtos/LIS/QueryApplyLISRequest.cs b/LIS-Platform-Linker/Dtos/LIS/QueryApplyLISRequest.cs new file mode 100644 index 0000000..7277478 --- /dev/null +++ b/LIS-Platform-Linker/Dtos/LIS/QueryApplyLISRequest.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Dtos.LIS +{ + public class QueryApplyLISRequest + { + //标本所属医疗机构代码 + public string srclabcode { get; set; } + //标本所属医疗机构名称 + public string srclabname { get; set; } + //操作人工号 + public string operatorcode { get; set; } + //操作人姓名 + public string operatorname { get; set; } + //条形码 + public string barcode { get; set; } + } +} diff --git a/LIS-Platform-Linker/Dtos/LIS/SubmitReportLISRequest.cs b/LIS-Platform-Linker/Dtos/LIS/SubmitReportLISRequest.cs new file mode 100644 index 0000000..c7facfa --- /dev/null +++ b/LIS-Platform-Linker/Dtos/LIS/SubmitReportLISRequest.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Dtos.LIS +{ + public class SubmitReportLISRequest + { + //标本所属医疗机构代码 + public string srclabcode { get; set; } + //标本所属医疗机构名称 + public string srclabname { get; set; } + //操作人工号 + public string operatorcode { get; set; } + //操作人姓名 + public string operatorname { get; set; } + //条形码 + public List barcodes { get; set; } + } +} diff --git a/LIS-Platform-Linker/Dtos/Platform/BasePlatformRequest.cs b/LIS-Platform-Linker/Dtos/Platform/BasePlatformRequest.cs new file mode 100644 index 0000000..949e131 --- /dev/null +++ b/LIS-Platform-Linker/Dtos/Platform/BasePlatformRequest.cs @@ -0,0 +1,29 @@ +using LIS_Platform_Linker.Tools; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Dtos.Platform +{ + public class BasePlatformRequest + { + public Header header; + public object data; + + public BasePlatformRequest(string servicename) + { + header = new Header + { + servicename = servicename + }; + } + } + + public class Header + { + public string hospitalcode = ConfigHelper.HospitalCode; + public string hospitalname = ConfigHelper.HospitalName; + public string servicename; + } +} diff --git a/LIS-Platform-Linker/Dtos/Platform/QueryApplyData.cs b/LIS-Platform-Linker/Dtos/Platform/QueryApplyData.cs new file mode 100644 index 0000000..5b9c7a9 --- /dev/null +++ b/LIS-Platform-Linker/Dtos/Platform/QueryApplyData.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Dtos.Platform +{ + public class QueryApplyData + { + public QueryApply queryapply; + } + + /// + /// 查询申请信息 + /// + public class QueryApply + { + public string srclabcode; + public string srclabname; + public string targetlabcode; + public string targetlabname; + public string barcode; + public string operatetime; + public string operatorcode; + public string operatorname; + } +} diff --git a/LIS-Platform-Linker/Dtos/Platform/SubmitReportData.cs b/LIS-Platform-Linker/Dtos/Platform/SubmitReportData.cs new file mode 100644 index 0000000..5830db0 --- /dev/null +++ b/LIS-Platform-Linker/Dtos/Platform/SubmitReportData.cs @@ -0,0 +1,769 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Dtos.Platform +{ + public class SubmitReportData + { + public SubmitReport report; + public List order; + public SubmitFile file; + public List item; + public List bacterias; + } + + /// + /// 报告信息 + /// + public class SubmitReport + { + /// + /// 标本所属医疗机构代码 + /// + public string srclabcode { get; set; } + + /// + /// 标本所属医疗机构名称 + /// + public string srclabname { get; set; } + + /// + /// 标本送往医疗机构代码 + /// + public string targetlabcode { get; set; } + + /// + /// 标本送往医疗机构名称 + /// + public string targetlabname { get; set; } + + /// + /// 操作时间 + /// + public string operatetime { get; set; } + + /// + /// 操作人工号 + /// + public string operatorcode { get; set; } + + /// + /// 操作人姓名 + /// + public string operatorname { get; set; } + + /// + /// 条码号 + /// + public string barcode { get; set; } + + /// + /// 报告单号 + /// + public string reportno { get; set; } + + /// + /// 患者姓名 + /// + public string patname { get; set; } + + /// + /// 患者唯一号 + /// + public string patientid { get; set; } + + /// + /// 就诊号 + /// + public string cureno { get; set; } + + /// + /// 住院号 + /// + public string hospno { get; set; } + + /// + /// 磁卡号 + /// + public string cardno { get; set; } + + /// + /// 卡类型 + /// + public string cardtype { get; set; } + + /// + /// 出生日期 + /// + public string birthday { get; set; } + + /// + /// 身份证号 + /// + public string idnum { get; set; } + + /// + /// 年龄 + /// + public string age { get; set; } + + /// + /// 年龄单位 + /// + public string ageunit { get; set; } + + /// + /// 性别 + /// + public string sex { get; set; } + + /// + /// 病人类型代码 + /// + public string wardorreg { get; set; } + + /// + /// 病人类型名称 + /// + public string wardorregname { get; set; } + + /// + /// 标本类型代码 + /// + public string samplecode { get; set; } + + /// + /// 标本类型名称 + /// + public string samplename { get; set; } + + /// + /// 标本说明代码 + /// + public string sampledescode { get; set; } + + /// + /// 标本说明名称 + /// + public string sampledescname { get; set; } + + /// + /// 标本性状代码 + /// + public string sampleshapecode { get; set; } + + /// + /// 标本性状名称 + /// + public string sampleshapename { get; set; } + + /// + /// 检验机构报告的仪器id + /// + public string testinstid { get; set; } + + /// + /// 检验机构报告的仪器代码 + /// + public string testinstcode { get; set; } + + /// + /// 检验机构报告的仪器名称 + /// + public string testinstname { get; set; } + + /// + /// 检验机构报告的样本号 + /// + public string testtechno { get; set; } + + /// + /// 检验时间 + /// + public string exectime { get; set; } + + /// + /// 检验医生工号 + /// + public string execdoccode { get; set; } + + /// + /// 检验医生姓名 + /// + public string execdocname { get; set; } + + /// + /// 审核时间 + /// + public string verifytime { get; set; } + + /// + /// 审核人工号 + /// + public string verifiercode { get; set; } + + /// + /// 审核人姓名 + /// + public string verifiername { get; set; } + + /// + /// 报告时间 + /// + public string reporttime { get; set; } + + /// + /// 发布时间 + /// + public string pubtime { get; set; } + + /// + /// 发布人工号 + /// + public string pubdoccode { get; set; } + + /// + /// 发布人姓名 + /// + public string pubdocname { get; set; } + + /// + /// 备注 + /// + public string remark { get; set; } + + /// + /// 检验结论 + /// + public string examresult { get; set; } + + /// + /// 实验室诊断 + /// + public string labdiagnosis { get; set; } + + /// + /// 复做标志 + /// + public string redoflag { get; set; } + + /// + /// 复做标本来源 + /// + public string redosample { get; set; } + + /// + /// 复做原因 + /// + public string redoreason { get; set; } + + /// + /// 复做标本说明 + /// + public string redosampledesc { get; set; } + + /// + /// 危急值报告标志 + /// + public string panicflag { get; set; } + + /// + /// 传染病报告标志 + /// + public string biohazardflag { get; set; } + + /// + /// 微生物报告标志 + /// + public string micflag { get; set; } + + /// + /// 报告完成标志 + /// + public string finishflag { get; set; } + } + + /// + /// 医嘱信息 + /// + public class SubmitOrder + { + /// + /// 项目代码 + /// + public string itemcode { get; set; } + + /// + /// 项目名称 + /// + public string itemname { get; set; } + + /// + /// 项目类型 + /// + public string itemtype { get; set; } + + /// + /// 项目数量 + /// + public string itemqty { get; set; } + + /// + /// 项目单位 + /// + public string itemunit { get; set; } + + /// + /// 项目单价 + /// + public string price { get; set; } + + /// + /// 申请单号 + /// + public string hisapplyno { get; set; } + + /// + /// 分组序号 + /// + public string groupno { get; set; } + + /// + /// 医嘱序号 + /// + public string logno { get; set; } + + /// + /// 标本类型代码 + /// + public string specimencode { get; set; } + + /// + /// 标本类型名称 + /// + public string specimenname { get; set; } + + /// + /// 项目状态 + /// + public string status { get; set; } + + /// + /// 费用类别 + /// + public string chargeflag { get; set; } + } + + /// + /// 报告文件信息 + /// + public class SubmitFile + { + /// + /// 报告文件列表 + /// + public List reportfile { get; set; } + + /// + /// 项目图片列表 + /// + public List itemimg { get; set; } + } + + public class ReportFile + { + /// + /// 文件名称 + /// + public string filename { get; set; } + + /// + /// 报告标志 + /// + public string reportflag { get; set; } + + /// + /// 文件类型 + /// + public string filetype { get; set; } + + /// + /// 文件数据 (Base64编码) + /// + public string filedata { get; set; } + } + + public class ItemImage + { + /// + /// 项目代码 + /// + public string itemcode { get; set; } + + /// + /// 文件名称 + /// + public string filename { get; set; } + + /// + /// 文件类型 + /// + public string filetype { get; set; } + + /// + /// 文件数据 (Base64编码) + /// + public string filedata { get; set; } + } + + /// + /// 检验指标信息-常规 + /// + public class SubmitItem + { + /// + /// 项目编码 + /// + public string itemnum { get; set; } + + /// + /// 项目代码 + /// + public string itemcode { get; set; } + + /// + /// 项目名称 + /// + public string itemname { get; set; } + + /// + /// 出结果时间 + /// + public string resulttime { get; set; } + + /// + /// 检测仪器ID + /// + public string instid { get; set; } + + /// + /// 检测仪器编码 + /// + public string instcode { get; set; } + + /// + /// 检测仪器名称 + /// + public string instname { get; set; } + + /// + /// 定量结果 + /// + public string resultvalue { get; set; } + + /// + /// 定性结果 + /// + public string resultchar { get; set; } + + /// + /// 报告结果 + /// + public string result { get; set; } + + /// + /// 提示信息 + /// + public string hintinfo { get; set; } + + /// + /// 显示状态 + /// + public string displayflag { get; set; } + + /// + /// 隐藏标志 + /// + public string hideflag { get; set; } + + /// + /// 科研标志 + /// + public string scientificflag { get; set; } + + /// + /// OD值 + /// + public string odresult { get; set; } + + /// + /// OD值字符表示 + /// + public string odresultchar { get; set; } + + /// + /// CUTOFF比值 + /// + public string cutoffvalue { get; set; } + + /// + /// CUTOFF比值字符表示 + /// + public string cutoffvaluechar { get; set; } + + /// + /// SCO比值 + /// + public string scovalue { get; set; } + + /// + /// SCO比值字符表示 + /// + public string scovaluechar { get; set; } + + /// + /// 检测方法 + /// + public string testmethod { get; set; } + + /// + /// 打印序号 + /// + public string printorder { get; set; } + + /// + /// 异常标志 + /// + public string highlowflag { get; set; } + + /// + /// 参考区间 + /// + public string referencerange { get; set; } + + /// + /// 单位 + /// + public string unit { get; set; } + + /// + /// 结果类型 + /// + public string resulttype { get; set; } + + /// + /// 复做标记 + /// + public string redo { get; set; } + + /// + /// 危急值项目 + /// + public string panicflag { get; set; } + + /// + /// 危急值参考区间 + /// + public string panicreferencerange { get; set; } + + /// + /// 传染病标志 + /// + public string biohazardflag { get; set; } + + /// + /// 镜检复片标志 + /// + public string scopicflag { get; set; } + } + + /// + /// 细菌结果信息-微生物 + /// + public class SubmitBacteria + { + /// + /// 细菌报告单号 + /// + public string orgreportno { get; set; } + + /// + /// 涂片方法代码 + /// + public string smearcode { get; set; } + + /// + /// 涂片方法名称 + /// + public string smearname { get; set; } + + /// + /// 涂片结果 + /// + public string smearresult { get; set; } + + /// + /// 细菌代码 + /// + public string organismcode { get; set; } + + /// + /// 细菌名称 + /// + public string organismname { get; set; } + + /// + /// 菌落计数 + /// + public string quantity { get; set; } + + /// + /// 检测结果 + /// + public string result { get; set; } + + /// + /// 培养基 + /// + public string culturemedium { get; set; } + + /// + /// 培养时间 + /// + public string culturetimes { get; set; } + + /// + /// 发现方式 + /// + public string foundway { get; set; } + + /// + /// 备注 + /// + public string remark { get; set; } + + /// + /// 检测仪器ID + /// + public string testinstid { get; set; } + + /// + /// 检测仪器名称 + /// + public string testinstname { get; set; } + + /// + /// 打印顺序 + /// + public string printorder { get; set; } + + /// + /// 综合评价 + /// + public string summingup { get; set; } + + /// + /// 细菌检测人工号 + /// + public string orgdoccode { get; set; } + + /// + /// 细菌检测人姓名 + /// + public string orgdocname { get; set; } + + /// + /// 细菌检测时间 + /// + public string organismtime { get; set; } + + /// + /// 阳性细菌标志 + /// + public string positiveflag { get; set; } + + /// + /// 多重耐药标记 + /// + public string warnorganism { get; set; } + + /// + /// 耐药机制代码 + /// + public string mdrcode { get; set; } + + /// + /// 耐药机制名称 + /// + public string mdrname { get; set; } + + /// + /// 药敏结果信息列表 + /// + public List antibiotics { get; set; } + + } + + /// + /// 药敏结果信息 + /// + public class Antibiotic + { + /// + /// 细菌报告单号 + /// + public string orgreportno { get; set; } + + /// + /// 细菌代码 + /// + public string organismcode { get; set; } + + /// + /// 药敏代码 + /// + public string anticode { get; set; } + + /// + /// 药敏名称 + /// + public string antiname { get; set; } + + /// + /// 测定值 + /// + public string antivalue { get; set; } + + /// + /// 参考范围 + /// + public string referevalue { get; set; } + + /// + /// 药敏结果 + /// + public string antiresult { get; set; } + + /// + /// 备注 + /// + public string remark { get; set; } + + /// + /// 抗生素分组 + /// + public string antigroup { get; set; } + + /// + /// 药敏结果是否打印 + /// + public string printflag { get; set; } + + /// + /// 打印序号 + /// + public string printorder { get; set; } + } +} diff --git a/LIS-Platform-Linker/LIS-Platform-Linker.csproj b/LIS-Platform-Linker/LIS-Platform-Linker.csproj new file mode 100644 index 0000000..109282c --- /dev/null +++ b/LIS-Platform-Linker/LIS-Platform-Linker.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp3.1 + LIS_Platform_Linker + + + + + + + + + + + + + Always + + + + + diff --git a/LIS-Platform-Linker/Program.cs b/LIS-Platform-Linker/Program.cs new file mode 100644 index 0000000..632e5d5 --- /dev/null +++ b/LIS-Platform-Linker/Program.cs @@ -0,0 +1,66 @@ +using LIS_Platform_Linker.Tools; +using LIS_Platform_Linker.Tools.Nlog; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using NLog.LayoutRenderers; +using NLog.Web; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker +{ + public class Program + { + public static void Main(string[] args) + { + #region עNlogԶ岼Ⱦ + LayoutRenderer.Register("callsite-namespace"); + #endregion + + //var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); // Nlogļʼ + try + { + LoggerHelper.Log.Info("===========program initialization==============="); + + JsonConvert.DefaultSettings = () => new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore + }; + + CreateHostBuilder(args).Build().Run(); + } + catch (Exception exception) + { + // Nlogô + LoggerHelper.Log.Error(exception, "Stopped program because of exception"); + throw; + } + finally + { + // ȷӦó˳ǰˢºֹͣڲʱ/̣߳Linuxϵķֶιϣ + NLog.LogManager.Shutdown(); + } + + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) + .ConfigureLogging(logging => + { + //logging.ClearProviders(); // п̨ + // ־ą̃־ʱ + logging.AddConsole(c => c.TimestampFormat = "yyyy-MM-dd HH:mm:ss"); + logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace).AddConsole(); // ̨־ + }) + .UseNLog(); //־עNlog; + } +} diff --git a/LIS-Platform-Linker/Properties/launchSettings.json b/LIS-Platform-Linker/Properties/launchSettings.json new file mode 100644 index 0000000..afa1ebc --- /dev/null +++ b/LIS-Platform-Linker/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:65422", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "LIS_Platform_Linker": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/LIS-Platform-Linker/Services/Interfaces/IReceiverService.cs b/LIS-Platform-Linker/Services/Interfaces/IReceiverService.cs new file mode 100644 index 0000000..6a60858 --- /dev/null +++ b/LIS-Platform-Linker/Services/Interfaces/IReceiverService.cs @@ -0,0 +1,54 @@ +using LIS_Platform_Linker.Dtos.LIS; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Services.Interfaces +{ + public interface IReceiverService + { + /// + /// 查询申请单 + /// + /// + public ActionResult QueryApply(QueryApplyLISRequest queryApplyLISRequest); + + /// + /// 撤销签收申请单 + /// + /// + public ActionResult CancelRegApply(string jsonString); + + /// + /// 拒绝签收申请单 + /// + /// + public ActionResult RejectApply(string jsonString); + + /// + /// 发送报告单 + /// + /// + public ActionResult SubmitReport(SubmitReportLISRequest submitReportRequest); + + /// + /// 召回报告单 + /// + /// + public ActionResult CallbackReport(string jsonString); + + /// + /// 发送PDF报告 + /// + /// + public ActionResult ImportPDF(string jsonString); + + /// + /// 查询申请单-按时间 + /// + /// + public ActionResult QueryApplyByTime(string jsonString); + } +} diff --git a/LIS-Platform-Linker/Services/Interfaces/ISenderService.cs b/LIS-Platform-Linker/Services/Interfaces/ISenderService.cs new file mode 100644 index 0000000..f5f8698 --- /dev/null +++ b/LIS-Platform-Linker/Services/Interfaces/ISenderService.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Services.Interfaces +{ + public interface ISenderService + { + } +} diff --git a/LIS-Platform-Linker/Services/ReceiverService.cs b/LIS-Platform-Linker/Services/ReceiverService.cs new file mode 100644 index 0000000..c703989 --- /dev/null +++ b/LIS-Platform-Linker/Services/ReceiverService.cs @@ -0,0 +1,289 @@ +using LIS_Platform_Linker.Dtos.LIS; +using LIS_Platform_Linker.Dtos.Platform; +using LIS_Platform_Linker.Services.Interfaces; +using LIS_Platform_Linker.Tools; +using LIS_Platform_Linker.Tools.Extensions; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Services +{ + public class ReceiverService : IReceiverService + { + + public ActionResult QueryApply(QueryApplyLISRequest queryApplyLISRequest) + { + try + { + LoggerHelper.Log.Info("【查询申请单】接收入参:" + JsonConvert.SerializeObject(queryApplyLISRequest)); + + var request = new BasePlatformRequest("QUERYAPPLY"); + var data = new QueryApplyData(); + request.data = data; + var queryApply = new QueryApply(); + data.queryapply = queryApply; + queryApply.srclabcode = queryApplyLISRequest.srclabcode; + queryApply.srclabname = queryApplyLISRequest.srclabname; + queryApply.targetlabcode = ConfigHelper.HospitalCode; + queryApply.targetlabname = ConfigHelper.HospitalName; + queryApply.barcode = queryApplyLISRequest.barcode; + queryApply.operatetime = DateTime.Now.ToStandardString(); + queryApply.operatorcode = queryApplyLISRequest.operatorcode; + queryApply.operatorname = queryApplyLISRequest.operatorname; + + var response = HttpClientHelper.Post(request); + LoggerHelper.Log.Info("【查询申请单】返回结果:" + JsonConvert.SerializeObject(response)); + return Result.Success(response); + } + catch (Exception ex) + { + LoggerHelper.Log.Error(ex); + return Result.Fail(ex.Message); + } + } + + public ActionResult CancelRegApply(string jsonString) + { + throw new NotImplementedException(); + } + + public ActionResult RejectApply(string jsonString) + { + throw new NotImplementedException(); + } + + public ActionResult SubmitReport(SubmitReportLISRequest submitReportRequest) + { + try + { + LoggerHelper.Log.Info("【发送报告单】接收入参:" + JsonConvert.SerializeObject(submitReportRequest)); + + var request = new BasePlatformRequest("SUBMITREPORT"); + var datas = new List(); + request.data = datas; + + var now = DateTime.Now.ToStandardString(); + foreach (string barcode in submitReportRequest.barcodes) + { + var data = new SubmitReportData(); + datas.Add(data); + var report = new SubmitReport(); + data.report = report; + data.order = new List(); + data.file = new SubmitFile(); + data.item = new List(); + //data.bacterias = new List(); + + #region report + + string sql_report = $@"select ID, PatientName, PatientID, HisId, BirthDay, IDCardNo, Age, AgeClass, Sex, PatientClass, SpecimenCode, SpecimenName, SampleCode, ReportDate, Reporter, CheckDate, Checker, Description, TestDate from Rpt_Patient (NOLOCK) where barcode = '{barcode}'; "; + var dt_report = DBHelper.ExecuteDataTable(sql_report); + report.srclabcode = submitReportRequest.srclabcode; + report.srclabname = submitReportRequest.srclabname; + report.targetlabcode = ConfigHelper.HospitalCode; + report.targetlabname = ConfigHelper.HospitalName; + report.operatetime = now; + report.operatorcode = submitReportRequest.operatorcode; + report.operatorname = submitReportRequest.operatorname; + report.barcode = barcode; + report.reportno = dt_report.Rows[0]["ID"].ToString(); + report.patname = dt_report.Rows[0]["PatientName"].ToString(); + report.patientid = dt_report.Rows[0]["PatientID"].ToString(); + report.cureno = dt_report.Rows[0]["HisId"].ToString(); + report.hospno = dt_report.Rows[0]["HisId"].ToString(); + report.cardno = dt_report.Rows[0]["HisId"].ToString(); + report.cardtype = string.Empty; + report.birthday = DateTime.Parse(dt_report.Rows[0]["BirthDay"].ToString()).ToStandardString(); + report.idnum = dt_report.Rows[0]["IDCardNo"].ToString(); + report.age = dt_report.Rows[0]["Age"].ToString(); + report.ageunit = dt_report.Rows[0]["AgeClass"].ToString(); + report.sex = dt_report.Rows[0]["Sex"].ToString(); + report.wardorreg = string.Empty; + report.wardorregname = dt_report.Rows[0]["PatientClass"].ToString(); + report.samplecode = dt_report.Rows[0]["SpecimenCode"].ToString(); + report.samplename = dt_report.Rows[0]["SpecimenName"].ToString(); + report.sampledescode = string.Empty; + report.sampledescname = string.Empty; + report.sampleshapecode = string.Empty; + report.sampleshapename = string.Empty; + report.testinstid = string.Empty; + report.testinstcode = string.Empty; + report.testinstname = string.Empty; + report.testtechno = dt_report.Rows[0]["SampleCode"].ToString(); + report.exectime = dt_report.Rows[0]["ReportDate"].ToString(); + report.execdoccode = string.Empty; + report.execdocname = dt_report.Rows[0]["Reporter"].ToString(); + report.verifytime = dt_report.Rows[0]["CheckDate"].ToString(); + report.verifiercode = string.Empty; + report.verifiername = dt_report.Rows[0]["Checker"].ToString(); + report.reporttime = dt_report.Rows[0]["CheckDate"].ToString(); + report.pubtime = dt_report.Rows[0]["CheckDate"].ToString(); + report.pubdoccode = string.Empty; + report.pubdocname = dt_report.Rows[0]["Checker"].ToString(); + report.remark = dt_report.Rows[0]["Description"].ToString(); + report.examresult = string.Empty; + report.labdiagnosis = string.Empty; + report.redoflag = "0"; + report.redosample = string.Empty; + report.redoreason = string.Empty; + report.redosampledesc = string.Empty; + report.panicflag = "0"; + report.biohazardflag = "0"; + report.micflag = "0"; + report.finishflag = "1"; + + + //测试用 + //report.barcode = "260305000001"; + //report.patname = "铁扎啊"; + //report.birthday = "2002-12-10 00:00:00"; + //report.idnum = "5327295272544448"; + //report.age = "23"; + + #endregion + + #region order + string sql_order = $@"select ReqItemCode, ReqItemName, Cost, SerialNum, CostDate from Rpt_CheckCost where barcode = '{barcode}'; "; + var dt_order = DBHelper.ExecuteDataTable(sql_order); + foreach (DataRow dr in dt_order.Rows) + { + var order = new SubmitOrder(); + data.order.Add(order); + + order.itemcode = dr["ReqItemCode"].ToString(); + order.itemname = dr["ReqItemName"].ToString(); + order.itemtype = string.Empty; + order.itemqty = string.Empty; + order.itemunit = string.Empty; + order.price = dr["Cost"].ToString(); + order.hisapplyno = dr["SerialNum"].ToString(); + order.groupno = string.Empty; + order.logno = string.Empty; + order.specimencode = data.report.samplecode; + order.specimenname = data.report.samplename; + order.status = "1"; + order.chargeflag = dr["SerialNum"] == DBNull.Value ? "0" : "1"; + } + + + #endregion + + #region file + + var reportfiles = new List(); + data.file.reportfile = reportfiles; + string sql_file = $@"select Report from Rpt_ReportFile where Barcode = '{barcode}'; "; + var dt_file = DBHelper.ExecuteDataTable(sql_file); + foreach (DataRow dr in dt_file.Rows) + { + var reportfile = new ReportFile(); + reportfiles.Add(reportfile); + + reportfile.filename = "报告文件"; + reportfile.reportflag = "1"; + reportfile.filetype = "9"; + reportfile.filedata = dr["Report"].ToString(); + } + + var itemimgs = new List(); + data.file.itemimg = itemimgs; + string sql_img = $@"select RptItemCode, Img from Rpt_ImageResult where SampleCode='{dt_report.Rows[0]["SampleCode"]}' and TestDate = '{dt_report.Rows[0]["TestDate"]}'; "; + var dt_img = DBHelper.ExecuteDataTable(sql_img); + foreach (DataRow dr in dt_img.Rows) + { + var itemimg = new ItemImage(); + itemimgs.Add(itemimg); + + string[] imgcode = dr["RptItemCode"].ToString().Split(' ', StringSplitOptions.RemoveEmptyEntries); + itemimg.itemcode = imgcode[0]; + itemimg.filename = imgcode[1]; + itemimg.filetype = "1"; + itemimg.filedata = dr["Img"].ToString(); + } + + #endregion + + #region item + + string sql_item = $@"select C.RptItemCode, C.RptItemName, A.InTime, A.Result, A.ResultStr, A.Range, A.Unit, A.IsReview from Rpt_CheckResult A +join Rpt_Patient B on A.SampleCode=B.SampleCode and A.TestDate=B.TestDate +join Dict_ReportItem C on A.RptItemCode=C.RptItemCode +where B.Barcode = '{barcode}'; "; + var dt_item = DBHelper.ExecuteDataTable(sql_item); + foreach (DataRow dr in dt_item.Rows) + { + var item = new SubmitItem(); + data.item.Add(item); + + item.itemnum = dr["RptItemCode"].ToString(); + item.itemcode = dr["RptItemCode"].ToString(); + item.itemname = dr["RptItemName"].ToString(); + item.resulttime = DateTime.Parse(dr["InTime"].ToString()).ToStandardString(); + item.instid = string.Empty; + item.instcode = string.Empty; + item.instname = string.Empty; + item.resultvalue = dr["Result"].ToString(); + item.resultchar = dr["ResultStr"].ToString(); + item.result = dr["ResultStr"].ToString(); + item.hintinfo = string.Empty; + item.displayflag = "0"; + item.hideflag = "0"; + item.scientificflag = string.Empty; + item.odresult = string.Empty; + item.odresultchar = string.Empty; + item.cutoffvalue = string.Empty; + item.cutoffvaluechar = string.Empty; + item.scovalue = string.Empty; + item.scovaluechar = string.Empty; + item.testmethod = string.Empty; + item.printorder = string.Empty; + item.highlowflag = string.Empty; + item.referencerange = dr["Range"].ToString(); + item.unit = dr["Unit"].ToString(); + item.resulttype = string.Empty; + item.redo = dr["IsReview"].ToString() == "1" ? "1" : "0"; + item.panicflag = string.Empty; + item.panicreferencerange = string.Empty; + item.biohazardflag = string.Empty; + item.scopicflag = string.Empty; + } + + + + #endregion + } + LoggerHelper.Log.Info("【发送报告单】发送对象:" + JsonConvert.SerializeObject(request)); + var response = HttpClientHelper.Post(request); + LoggerHelper.Log.Info("【发送报告单】返回结果:" + JsonConvert.SerializeObject(response)); + return Result.Success(response); + //LoggerHelper.Log.Info("【发送报告单】发送对象:" + JsonConvert.SerializeObject(request)); + //return Result.Success(request); + } + catch (Exception ex) + { + LoggerHelper.Log.Error(ex); + return Result.Fail(ex.Message); + } + } + + public ActionResult CallbackReport(string jsonString) + { + throw new NotImplementedException(); + } + + public ActionResult ImportPDF(string jsonString) + { + throw new NotImplementedException(); + } + + public ActionResult QueryApplyByTime(string jsonString) + { + throw new NotImplementedException(); + } + } +} diff --git a/LIS-Platform-Linker/Services/SenderService.cs b/LIS-Platform-Linker/Services/SenderService.cs new file mode 100644 index 0000000..27ee8a8 --- /dev/null +++ b/LIS-Platform-Linker/Services/SenderService.cs @@ -0,0 +1,12 @@ +using LIS_Platform_Linker.Services.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Services +{ + public class SenderService : ISenderService + { + } +} diff --git a/LIS-Platform-Linker/Startup.cs b/LIS-Platform-Linker/Startup.cs new file mode 100644 index 0000000..e5b9a7d --- /dev/null +++ b/LIS-Platform-Linker/Startup.cs @@ -0,0 +1,85 @@ +using LIS_Platform_Linker.Services; +using LIS_Platform_Linker.Services.Interfaces; +using LIS_Platform_Linker.Tools; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + //ȡ + ConfigHelper.Initialize(Configuration); + + services.AddControllers(); + + //ע + services.AddTransient(); + services.AddTransient(); + + services.AddSwaggerGen(s => + { + //swagger ϢԶ壩 + //V1.0.0-->SwaggerEndpoint(url,name)-->url ʹ + s.SwaggerDoc("V1.0.0", new Microsoft.OpenApi.Models.OpenApiInfo + { + Title = "ƽ̨ӷ", + Version = "1.0.0", + }); + s.AddServer(new OpenApiServer + { + Url = "/LISPlatformLinker", + Description = "APIȫ·" + }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UsePathBase("/LISPlatformLinker"); + + app.UseSwagger(); + app.UseSwaggerUI(su => + { + //url[V1.0.0]ConfigureServices õSwaggerDoc("V1.0.0",..) һ + su.SwaggerEndpoint("/swagger/V1.0.0/swagger.json", null); + }); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/LIS-Platform-Linker/Tools/ConfigHelper.cs b/LIS-Platform-Linker/Tools/ConfigHelper.cs new file mode 100644 index 0000000..f926381 --- /dev/null +++ b/LIS-Platform-Linker/Tools/ConfigHelper.cs @@ -0,0 +1,30 @@ +using Microsoft.Extensions.Configuration; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Tools +{ + public static class ConfigHelper + { + private static IConfiguration _config; + + public static void Initialize(IConfiguration configuration) + { + _config = configuration; + } + + // LIS数据库连接字符串 + public static string ConnectionString => MySecurity.SDecryptString(_config.GetValue("ConnectionString")); + + // 检验平台接口地址 + public static string PlatformUrl => _config.GetValue("PlatformUrl"); + + // 医疗机构代码 + public static string HospitalCode => _config.GetValue("HospitalCode"); + + // 医疗机构名称 + public static string HospitalName => _config.GetValue("HospitalName"); + } +} diff --git a/LIS-Platform-Linker/Tools/DBHelper.cs b/LIS-Platform-Linker/Tools/DBHelper.cs new file mode 100644 index 0000000..6ba01c4 --- /dev/null +++ b/LIS-Platform-Linker/Tools/DBHelper.cs @@ -0,0 +1,109 @@ +using Microsoft.Data.SqlClient; +using System; +using System.Data; + +namespace LIS_Platform_Linker.Tools +{ + public static class DBHelper + { + private static readonly string _connectionString; + + static DBHelper() + { + _connectionString = ConfigHelper.ConnectionString; + if (string.IsNullOrEmpty(_connectionString)) + { + throw new ArgumentException($"连接字符串未找到或为空"); + } + } + + /// + /// 执行查询,返回结果的第一行第一列(字符串) + /// + /// SQL语句 + /// 参数列表 + /// 结果的第一行第一列 + public static string ExecuteScalarString(string sql, params SqlParameter[] parameters) + { + using (var connection = new SqlConnection(_connectionString)) + using (var command = new SqlCommand(sql, connection)) + { + command.CommandType = CommandType.Text; + if (parameters != null && parameters.Length > 0) + { + command.Parameters.AddRange(parameters); + } + + connection.Open(); + var result = command.ExecuteScalar(); + return result?.ToString() ?? string.Empty; + } + } + + /// + /// 执行查询,返回结果的第一行第一列(泛型版本) + /// + public static T ExecuteScalar(string sql, params SqlParameter[] parameters) + { + using (var connection = new SqlConnection(_connectionString)) + using (var command = new SqlCommand(sql, connection)) + { + command.CommandType = CommandType.Text; + if (parameters != null && parameters.Length > 0) + { + command.Parameters.AddRange(parameters); + } + + connection.Open(); + var result = command.ExecuteScalar(); + if (result == null || result == DBNull.Value) + { + return default(T); + } + return (T)Convert.ChangeType(result, typeof(T)); + } + } + + /// + /// 执行查询,返回DataTable + /// + public static DataTable ExecuteDataTable(string sql, params SqlParameter[] parameters) + { + using (var connection = new SqlConnection(_connectionString)) + using (var command = new SqlCommand(sql, connection)) + { + command.CommandType = CommandType.Text; + if (parameters != null && parameters.Length > 0) + { + command.Parameters.AddRange(parameters); + } + + var dataTable = new DataTable(); + using (var adapter = new SqlDataAdapter(command)) + { + adapter.Fill(dataTable); + } + return dataTable; + } + } + + /// + /// 执行非查询SQL,返回影响的行数 + /// + public static int ExecuteNonQuery(string sql, params SqlParameter[] parameters) + { + using (var connection = new SqlConnection(_connectionString)) + using (var command = new SqlCommand(sql, connection)) + { + command.CommandType = CommandType.Text; + if (parameters != null && parameters.Length > 0) + { + command.Parameters.AddRange(parameters); + } + + connection.Open(); + return command.ExecuteNonQuery(); + } + } + } +} \ No newline at end of file diff --git a/LIS-Platform-Linker/Tools/Extensions/DateTimeExtensions.cs b/LIS-Platform-Linker/Tools/Extensions/DateTimeExtensions.cs new file mode 100644 index 0000000..42fac26 --- /dev/null +++ b/LIS-Platform-Linker/Tools/Extensions/DateTimeExtensions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Tools.Extensions +{ + public static class DateTimeExtensions + { + public static string ToStandardString(this DateTime dt) + { + return dt.ToString("yyyy-MM-dd HH:mm:ss"); + } + } +} diff --git a/LIS-Platform-Linker/Tools/HttpClientHelper.cs b/LIS-Platform-Linker/Tools/HttpClientHelper.cs new file mode 100644 index 0000000..aba9b62 --- /dev/null +++ b/LIS-Platform-Linker/Tools/HttpClientHelper.cs @@ -0,0 +1,30 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Tools +{ + public static class HttpClientHelper + { + private static readonly string _url; + + static HttpClientHelper() + { + _url = ConfigHelper.PlatformUrl; + if (string.IsNullOrEmpty(_url)) + { + throw new ArgumentException($"平台URL未找到或为空"); + } + } + + public static string Post(object data) + { + using var client = new WebClient(); + client.Headers[HttpRequestHeader.ContentType] = "application/json"; + return client.UploadString(_url, "POST", JsonConvert.SerializeObject(data)); + } + } +} diff --git a/LIS-Platform-Linker/Tools/LoggerHelper.cs b/LIS-Platform-Linker/Tools/LoggerHelper.cs new file mode 100644 index 0000000..479747c --- /dev/null +++ b/LIS-Platform-Linker/Tools/LoggerHelper.cs @@ -0,0 +1,13 @@ +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Tools +{ + public static class LoggerHelper + { + public static readonly ILogger Log = LogManager.GetCurrentClassLogger(); + } +} diff --git a/LIS-Platform-Linker/Tools/MySecurity.cs b/LIS-Platform-Linker/Tools/MySecurity.cs new file mode 100644 index 0000000..2fe6472 --- /dev/null +++ b/LIS-Platform-Linker/Tools/MySecurity.cs @@ -0,0 +1,253 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Tools +{ + /// + /// MySecurity(安全类) 的摘要说明。 + /// + public class MySecurity + { + /// + /// 初始化安全类 + /// + public MySecurity() + { + ///默认密码 + key = "peis77911@*71"; + } + + private string key; //默认密钥 + + private byte[] sKey; + private byte[] sIV; + + #region 加密字符串 + + /// + /// 加密字符串 + /// + /// 输入字符串 + /// 密码,可以为“” + /// 输出加密后字符串 + static public string SEncryptString(string inputStr, string keyStr) + { + MySecurity ws = new MySecurity(); + return ws.EncryptString(inputStr, keyStr); + } + + /// + /// 加密字符串 + /// + /// 输入字符串 + /// 密码,可以为“” + /// 输出加密后字符串 + public string EncryptString(string inputStr, string keyStr) + { + DESCryptoServiceProvider des = new DESCryptoServiceProvider(); + if (keyStr == "") + keyStr = key; + byte[] inputByteArray = Encoding.Default.GetBytes(inputStr); + byte[] keyByteArray = Encoding.Default.GetBytes(keyStr); + SHA1 ha = new SHA1Managed(); + byte[] hb = ha.ComputeHash(keyByteArray); + sKey = new byte[8]; + sIV = new byte[8]; + for (int i = 0; i < 8; i++) + sKey[i] = hb[i]; + for (int i = 8; i < 16; i++) + sIV[i - 8] = hb[i]; + des.Key = sKey; + des.IV = sIV; + MemoryStream ms = new MemoryStream(); + CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write); + cs.Write(inputByteArray, 0, inputByteArray.Length); + cs.FlushFinalBlock(); + StringBuilder ret = new StringBuilder(); + foreach (byte b in ms.ToArray()) + { + ret.AppendFormat("{0:X2}", b); + } + cs.Close(); + ms.Close(); + return ret.ToString(); + } + + #endregion 加密字符串 + + #region 加密字符串 密钥为系统默认 0123456789 + + /// + /// 加密字符串 密钥为系统默认 + /// + /// 输入字符串 + /// 输出加密后字符串 + static public string SEncryptString(string inputStr) + { + MySecurity ws = new MySecurity(); + return ws.EncryptString(inputStr, ""); + } + + #endregion 加密字符串 密钥为系统默认 0123456789 + + #region 加密文件 + + /// + /// 加密文件 + /// + /// 输入文件路径 + /// 加密后输出文件路径 + /// 密码,可以为“” + /// + public bool EncryptFile(string filePath, string savePath, string keyStr) + { + DESCryptoServiceProvider des = new DESCryptoServiceProvider(); + if (keyStr == "") + keyStr = key; + FileStream fs = File.OpenRead(filePath); + byte[] inputByteArray = new byte[fs.Length]; + fs.Read(inputByteArray, 0, (int)fs.Length); + fs.Close(); + byte[] keyByteArray = Encoding.Default.GetBytes(keyStr); + SHA1 ha = new SHA1Managed(); + byte[] hb = ha.ComputeHash(keyByteArray); + sKey = new byte[8]; + sIV = new byte[8]; + for (int i = 0; i < 8; i++) + sKey[i] = hb[i]; + for (int i = 8; i < 16; i++) + sIV[i - 8] = hb[i]; + des.Key = sKey; + des.IV = sIV; + MemoryStream ms = new MemoryStream(); + CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write); + cs.Write(inputByteArray, 0, inputByteArray.Length); + cs.FlushFinalBlock(); + fs = File.OpenWrite(savePath); + foreach (byte b in ms.ToArray()) + { + fs.WriteByte(b); + } + fs.Close(); + cs.Close(); + ms.Close(); + return true; + } + + #endregion 加密文件 + + #region 解密字符串 + + /// + /// 解密字符串 + /// + /// 要解密的字符串 + /// 密钥 + /// 解密后的结果 + static public string SDecryptString(string inputStr, string keyStr) + { + MySecurity ws = new MySecurity(); + return ws.DecryptString(inputStr, keyStr); + } + + /// + /// 解密字符串 密钥为系统默认 + /// + /// 要解密的字符串 + /// 解密后的结果 + static public string SDecryptString(string inputStr) + { + MySecurity ws = new MySecurity(); + return ws.DecryptString(inputStr, ""); + } + + /// + /// 解密字符串 + /// + /// 要解密的字符串 + /// 密钥 + /// 解密后的结果 + public string DecryptString(string inputStr, string keyStr) + { + DESCryptoServiceProvider des = new DESCryptoServiceProvider(); + if (keyStr == "") + keyStr = key; + byte[] inputByteArray = new byte[inputStr.Length / 2]; + for (int x = 0; x < inputStr.Length / 2; x++) + { + int i = (Convert.ToInt32(inputStr.Substring(x * 2, 2), 16)); + inputByteArray[x] = (byte)i; + } + byte[] keyByteArray = Encoding.Default.GetBytes(keyStr); + SHA1 ha = new SHA1Managed(); + byte[] hb = ha.ComputeHash(keyByteArray); + sKey = new byte[8]; + sIV = new byte[8]; + for (int i = 0; i < 8; i++) + sKey[i] = hb[i]; + for (int i = 8; i < 16; i++) + sIV[i - 8] = hb[i]; + des.Key = sKey; + des.IV = sIV; + MemoryStream ms = new MemoryStream(); + CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write); + cs.Write(inputByteArray, 0, inputByteArray.Length); + cs.FlushFinalBlock(); + StringBuilder ret = new StringBuilder(); + return System.Text.Encoding.Default.GetString(ms.ToArray()); + } + + #endregion 解密字符串 + + #region 解密文件 + + /// + /// 解密文件 + /// + /// 输入文件路径 + /// 解密后输出文件路径 + /// 密码,可以为“” + /// + public bool DecryptFile(string filePath, string savePath, string keyStr) + { + DESCryptoServiceProvider des = new DESCryptoServiceProvider(); + if (keyStr == "") + keyStr = key; + FileStream fs = File.OpenRead(filePath); + byte[] inputByteArray = new byte[fs.Length]; + fs.Read(inputByteArray, 0, (int)fs.Length); + fs.Close(); + byte[] keyByteArray = Encoding.Default.GetBytes(keyStr); + SHA1 ha = new SHA1Managed(); + byte[] hb = ha.ComputeHash(keyByteArray); + sKey = new byte[8]; + sIV = new byte[8]; + for (int i = 0; i < 8; i++) + sKey[i] = hb[i]; + for (int i = 8; i < 16; i++) + sIV[i - 8] = hb[i]; + des.Key = sKey; + des.IV = sIV; + MemoryStream ms = new MemoryStream(); + CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write); + cs.Write(inputByteArray, 0, inputByteArray.Length); + cs.FlushFinalBlock(); + fs = File.OpenWrite(savePath); + foreach (byte b in ms.ToArray()) + { + fs.WriteByte(b); + } + fs.Close(); + cs.Close(); + ms.Close(); + return true; + } + + #endregion 解密文件 + } +} diff --git a/LIS-Platform-Linker/Tools/Nlog/CallsiteNamespaceLayoutRenderer.cs b/LIS-Platform-Linker/Tools/Nlog/CallsiteNamespaceLayoutRenderer.cs new file mode 100644 index 0000000..af81cec --- /dev/null +++ b/LIS-Platform-Linker/Tools/Nlog/CallsiteNamespaceLayoutRenderer.cs @@ -0,0 +1,30 @@ +using NLog; +using NLog.LayoutRenderers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Tools.Nlog +{ + /// + /// Nlog 日志调用方命名空间名称 + /// + [LayoutRenderer("callsite-namespace")] + public class CallsiteNamespaceLayoutRenderer : LayoutRenderer + { + protected override void Append(StringBuilder builder, LogEventInfo logEvent) + { + if (logEvent != null && !string.IsNullOrEmpty(logEvent.CallerClassName) && logEvent.CallerClassName.Contains(".")) + { + // 获取命名空间(如果类型在命名空间中) + var namespaceName = logEvent.CallerClassName.ToString().Split(".")[0]; + if (!string.IsNullOrEmpty(namespaceName)) + { + builder.Append(namespaceName); + } + } + } + } +} diff --git a/LIS-Platform-Linker/Tools/Nlog/LogHelper.cs b/LIS-Platform-Linker/Tools/Nlog/LogHelper.cs new file mode 100644 index 0000000..64906c7 --- /dev/null +++ b/LIS-Platform-Linker/Tools/Nlog/LogHelper.cs @@ -0,0 +1,21 @@ +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Tools.Nlog +{ + /// + /// 日志静态类 + /// + public class LogHelper + { + + /// + /// 日志调用对象 + /// + public static readonly NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + } +} diff --git a/LIS-Platform-Linker/Tools/Result.cs b/LIS-Platform-Linker/Tools/Result.cs new file mode 100644 index 0000000..2bb708b --- /dev/null +++ b/LIS-Platform-Linker/Tools/Result.cs @@ -0,0 +1,165 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Threading.Tasks; + +namespace LIS_Platform_Linker.Tools +{ + /// + /// 返回结果封装 + /// + public static class Result + { + /// + /// 响应枚举 + /// + public enum ResultType + { + [Description("成功")] + SUCCESS = 200, + + [Description("失败")] + ERROR = 500, + } + + /// + /// 获取枚举描述 + /// + /// + /// + public static string GetDescription(this Enum val) + { + var field = val.GetType().GetField(val.ToString()); + //自定义属性 + var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)); + return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description; + } + + /// + /// 获取枚举的值 + /// + /// + /// + public static int GetField(this Enum val) + { + var field = val.GetType().GetField(val.ToString()); + return field != null ? Convert.ToInt32(field.GetValue(val)) : 0; + } + + + /// + /// 通过code获取枚举描述 + /// + /// code + /// + public static string GetMessageByCode(int code) + { + // 获取枚举名称 + var name = Enum.GetName(typeof(ResultType), code); + // 获取ResultType中名称为name的对象 + var item = Enum.Parse(typeof(ResultType), name); + return GetDescription((Enum)item); + } + + /// + /// 响应返回(失败) + /// + /// 响应类型对象 + /// + /// + public static ActionResult Fail(ResultType resStatus, object data) + { + var code = GetField(resStatus); + var message = GetDescription(resStatus); + return new ObjectResult(new ResultModel(code, message, data)); + } + + public static ActionResult Fail(ResultType resStatus) + { + var code = GetField(resStatus); + var message = GetDescription(resStatus); + return new ObjectResult(new ResultModel(code, message, null)); + } + + /// + /// 响应返回(失败) + /// + /// 响应代码 + /// 响应数据 + /// + public static ActionResult Fail(int code, object data) + { + var message = GetMessageByCode(code); + return new ObjectResult(new ResultModel(code, message, data)); + } + + public static ActionResult Fail(string message) + { + return new ObjectResult(new ResultModel(500, message, null)); + } + + public static ActionResult Fail(string message, object data) + { + return new ObjectResult(new ResultModel(500, message, data)); + } + + public static ActionResult Fail() + { + return new ObjectResult(new ResultModel(500, "失败", null)); + } + + /// + /// 响应返回(成功) + /// + /// 响应数据 + /// + public static ActionResult Success(object data) + { + return new ObjectResult(new ResultModel(200, "成功", data)); + } + + /// + /// 响应返回(成功) + /// + /// + public static ActionResult Success() + { + return new ObjectResult(new ResultModel(200, "成功", null)); + } + } + + /// + /// 接口响应实体 + /// + public class ResultModel + { + /// + /// code + /// + public int code { get; set; } + /// + /// 响应信息 + /// + public string message { get; set; } + /// + /// 响应数据 + /// + public object data { get; set; } + + public ResultModel() + { + } + public ResultModel(int code, string message, object data) + { + this.code = code; + this.message = message; + this.data = data; + } + public override string ToString() + { + return $"code={this.code},message={this.message},data={this.data}"; + } + } +} diff --git a/LIS-Platform-Linker/appsettings.Development.json b/LIS-Platform-Linker/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/LIS-Platform-Linker/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/LIS-Platform-Linker/appsettings.json b/LIS-Platform-Linker/appsettings.json new file mode 100644 index 0000000..4674c12 --- /dev/null +++ b/LIS-Platform-Linker/appsettings.json @@ -0,0 +1,15 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + + "ConnectionString": "10C598E364BCAFCFDC6960B18CB026C75BD46245729DFD1D5BA71CC4E633BF9331462312CA70E7AAF675E8DF1A3F3D8BC9D22C1D1906F33A35CCAA2FBA518461F9EA2F0925C3F6B9A4019DAD079E279A175C0642D39D79126EC4BA2D83549E45B8D6257379A298386F60C60A0BF938CE", + "PlatformUrl": "http://127.0.0.1:5050", + "HospitalCode": "001", + "HospitalName": "测试医院" +} diff --git a/LIS-Platform-Linker/nlog.config b/LIS-Platform-Linker/nlog.config new file mode 100644 index 0000000..540f45d --- /dev/null +++ b/LIS-Platform-Linker/nlog.config @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file