Forráskód Böngészése

三方lis 代码开发完毕

zackhua 7 hónapja
szülő
commit
e82644ec55

+ 7 - 5
LisPacsDataUpload/App.config

@@ -6,23 +6,25 @@
   <appSettings>
 	  
     <!--定时轮询时间(单位:分钟)-->
-    <add key="time" value="120" />
+    <add key="time" value="60" />
     <!--数据上传开始时间点(值域:0-23)-->
-    <add key="start_time" value="9" />
+    <add key="start_time" value="7" />
     <!--是否上传检查数据,1:上传,0不上传-->
     <add key="pacs" value="0" />
     <!--清除多久以前已上传的数据(单位:月),整数,小于1不删除-->
     <add key="upload_time" value="1" />
 
-	  <add key="UserName" value="zlhis"/>
-	  <add key="PasWord" value="aqa"/>
-	  <add key="Server" value="orcl"/>
+	<add key="UserName" value="zlhis"/>
+	<add key="PasWord" value="aqa"/>
+	<add key="Server" value="orcl"/>
 	  
   </appSettings>
   <connectionStrings>
     <add name="conn" connectionString="data source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.0.1)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = his)));user id=ZLLPMR;password=ZLLPMR;Persist Security Info=True;Enlist=true;Pooling=true;Max Pool Size=300;Min Pool Size=0;Connection Lifetime=300;" />
     <!--<add name="conn" connectionString="data source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.181)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = orcl)));user id=ZLDSTX;password=ZLDSTX;Persist Security Info=True;Enlist=true;Pooling=true;Max Pool Size=300;Min Pool Size=0;Connection Lifetime=300;"/>-->
     <add name="pgConn" connectionString="Server=localhost;Port=5432;User Id=your_username;Password=your_password;Database=your_database;" providerName="Npgsql" />
+	  <add name="SqlServerConnection" connectionString="Data Source=19.2.168.0.229;Initial Catalog=LIS4_FYBJY;User ID=u_jpg;Password=u_jpg"/>
+  
   </connectionStrings>
   <system.data>
     <DbProviderFactories>

+ 15 - 2
LisPacsDataUpload/Form1.cs

@@ -49,7 +49,6 @@ namespace LisPacsDataUpload
             timer1.Tick += new EventHandler(DataUpload);//添加事件
             timer1.Start();
         }
-
         private void Form1_Load(object sender, EventArgs e)
         {
             ShowLog = "启动正常。";
@@ -414,7 +413,17 @@ namespace LisPacsDataUpload
                                 DataTable dt_lis = OracleHelper<object>.PgQueryDS(sql_zlhr);
                                 string reportId = dt_lis.Rows[0]["id"].ToString();
                                 GeneratePdfUrl = PdfUtils.GeneratePdf(lisSource, reportId, reportId);
-
+                            }
+                            else if(lisSource==3){
+                                string requestId = dt.Rows[i]["requestId"].ToString(); // 申请id
+                                GeneratePdfUrl = PdfUtils.GeneratePdf(lisSource, requestId, requestId);
+                                if (!GeneratePdfUrl.Contains(".pdf"))
+                                {
+                                    LogHelper.Info("生成pdf失败,原因是 = " + GeneratePdfUrl);
+                                    ShowLog = "生成pdf失败,原因是 =" + GeneratePdfUrl;
+                                    this.SetText(ShowLog);
+                                    continue;
+                                }
                             }
                             else
                             {
@@ -425,6 +434,8 @@ namespace LisPacsDataUpload
                                 if (!GeneratePdfUrl.Contains(".pdf"))
                                 {
                                     LogHelper.Info("生成pdf失败,原因是 = " + GeneratePdfUrl);
+                                    ShowLog = "生成pdf失败,原因是 =" + GeneratePdfUrl;
+                                    this.SetText(ShowLog);
                                     continue;
                                 }
                                 LogHelper.Info("生成pdf成功,地址为 = " + GeneratePdfUrl);
@@ -497,6 +508,8 @@ namespace LisPacsDataUpload
                             }
 
                             //最新调整  需要获取 原始pdf 文件  存在场景  有三方lis、中联lis 、 以及专业版临生免 的报告 三种  
+
+                            LogHelper.Info("最后GeneratePdfUrl= " + GeneratePdfUrl);
                             string attachmentFile = "";
                             if (zlhr == zlhrConstant_true)
                             {

+ 72 - 0
LisPacsDataUpload/SqlServerHelper.cs

@@ -0,0 +1,72 @@
+using System;
+using System.Configuration;
+using System.Data.SqlClient;
+using System.Data;
+using Common;
+
+
+namespace LisPacsDataUpload
+{
+    public class SqlServerHelper
+    {
+
+        public static string GetConnStr()
+        {
+            return ConfigurationManager.ConnectionStrings["SqlServerConnection"].ConnectionString;
+
+        }
+
+        public static DataTable ExecuteQuery(string query)
+        {
+            using (SqlConnection connection = new SqlConnection(GetConnStr()))
+            {
+                SqlCommand command = new SqlCommand(query, connection);
+                try
+                {
+                    connection.Open();
+                    SqlDataAdapter adapter = new SqlDataAdapter(command);
+                    DataTable dataTable = new DataTable();
+                    adapter.Fill(dataTable);
+                    return dataTable;
+                }
+                catch (Exception ex)
+                {
+                    Console.WriteLine("查询数据时出现错误:" + ex.Message);
+                    return null;
+                }
+            }
+        }
+
+        public static DataRow ExecuteSingleRowQuery(string query)
+        {
+
+            try
+            {
+                using (SqlConnection connection = new SqlConnection(GetConnStr()))
+                {
+                    SqlCommand command = new SqlCommand(query, connection);
+                
+                        connection.Open();
+                        SqlDataAdapter adapter = new SqlDataAdapter(command);
+                        DataTable dataTable = new DataTable();
+                        adapter.Fill(dataTable);
+                        LogHelper.Info("dataTable.Rows.Count"+ dataTable.Rows.Count);
+                        if (dataTable.Rows.Count > 0)
+                        {
+                            return dataTable.Rows[0];
+                        }
+                        else
+                        {
+                            return null;
+                        }
+               
+                }
+            }
+            catch (Exception ex)
+            {
+                LogHelper.Info("查询数据时出现错误:" + ex.Message);
+                return null;
+            }
+        }
+    }
+}

+ 46 - 5
LisPacsDataUpload/business/PdfUtils.cs

@@ -1,16 +1,16 @@
 using Common;
-using LisPacsDataUpload.Models;
+using iTextSharp.text;
+using iTextSharp.text.pdf;
 using LisPacsDataUpload.Models.Report;
 using Newtonsoft.Json;
 using System;
-using System.Collections.Generic;
 using System.Configuration;
 using System.Data;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Reflection;
-using System.Text;
+
 
 namespace LisPacsDataUpload.business
 {
@@ -94,16 +94,57 @@ namespace LisPacsDataUpload.business
                 }
                 return zlsoftOutVO.input.file_info.rpt_content;
             }
-            else
+            else if(lisVersion == 3)
             {
                 // 三方lis
+                string three_sql = @"select pdfUrl from three_lis_pdf where yzid =" + bbid;
+                LogHelper.Info("three_sql  "+ three_sql);
+                DataRow data = SqlServerHelper.ExecuteSingleRowQuery(three_sql);
+                if (data!=null)
+                {
+                    string jpgUrl = data["pdfUrl"].ToString();
+                    LogHelper.Info("三方原始jpgUrl" + jpgUrl);
+                    GetPdfFromJpg(jpgUrl, path);
+                    return path;
+                }
+                return "三方lispdf报告获取失败";
             }
             return "失败";
         }
 
+
+        public static void GetPdfFromJpg(string jpgUrl,string pdfUrl)
+        {
+            LogHelper.Info("开始从jpg转换pdf");
+            //string jpgFilePath = "path_to_your_jpg.jpg";
+            //string pdfFilePath = "output.pdf";
+
+            using (FileStream fs = new FileStream(pdfUrl, FileMode.Create))
+            {
+                // 创建一个文档对象
+                Document document = new Document();
+                // 创建一个 PDF 写入器,将文档写入文件流
+                PdfWriter writer = PdfWriter.GetInstance(document, fs);
+
+                document.Open();
+
+                // 创建一个图像对象并加载 JPG 文件
+                Image image = Image.GetInstance(jpgUrl);
+                // 设置图像在 PDF 中的尺寸(可以根据需要调整)
+                image.ScaleToFit(document.PageSize.Width - 20, document.PageSize.Height - 20);
+
+                // 将图像添加到 PDF 文档中
+                document.Add(image);
+                document.Close();
+            }
+            LogHelper.Info("JPG 转换为 PDF 成功!");
+        }
+
         public static string GeneratePdf(int lisVersion, string reportNumber, string bbid)
         {
-            return getPdfParamByLisVersion(lisVersion, reportNumber, bbid);
+            string pdfUrl = getPdfParamByLisVersion(lisVersion, reportNumber, bbid);
+            LogHelper.Info("GeneratePdf==" + pdfUrl);
+            return pdfUrl;
         }