Browse Source

新增 AsposeHelper

leiy 1 year ago
parent
commit
24b4c00699

+ 0 - 1
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -1,7 +1,6 @@
 using Microsoft.AspNetCore.Mvc;
 using Newtonsoft.Json.Serialization;
 using OASystem.API.OAMethodLib;
-using OASystem.API.OAMethodLibs;
 using OASystem.Domain.Dtos.Groups;
 using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.ViewModels.Groups;

+ 25 - 2
OASystem/OASystem.Api/Controllers/TencentOCRController.cs

@@ -1,8 +1,11 @@
-using OASystem.API.OAMethodLib.TencentCloudAPI;
+using OASystem.API.OAMethodLib.File;
+using OASystem.API.OAMethodLib.NPOI;
+using OASystem.API.OAMethodLib.TencentCloudAPI;
 using OASystem.Domain.Dtos.CRM;
 using OASystem.Domain.Dtos.Tencent;
 using OASystem.Domain.ViewModels.TencentOCR;
 using OASystem.Infrastructure.Repositories.CRM;
+using Org.BouncyCastle.Crypto;
 using StackExchange.Redis;
 using System.Net.NetworkInformation;
 using TencentCloud.Ocr.V20181119.Models;
@@ -107,7 +110,7 @@ namespace OASystem.API.Controllers
                     CerdAddress = idCardData.Data.Address,
                 });
 
-            IDCardOCRView iDCardOCRView = new IDCardOCRView()
+            IDCardOCRAndDownUrlView iDCardOCRView = new IDCardOCRAndDownUrlView()
             {
                 Status = cerdStatus,
                 Name = idCardData.Data.Name,
@@ -120,6 +123,26 @@ namespace OASystem.API.Controllers
                 ValidDate = idCardData.Data.ValidDate
             };
 
+            #region word生成 返回地址
+            string tempPath = string.Format("{0}", "C:\\Server\\File\\OA2023\\Office\\Word\\TencentOCR\\Template\\ocr_身份证(人像面).doc");
+
+            Dictionary<string, object> dic = new Dictionary<string, object>();
+            dic.Add("Name", iDCardOCRView.Name);
+            dic.Add("Sex", iDCardOCRView.Sex);
+            dic.Add("Nation", iDCardOCRView.Nation);
+            dic.Add("Birth", iDCardOCRView.Birth);
+            dic.Add("Address", iDCardOCRView.Address);
+            dic.Add("IdNum", iDCardOCRView.IdNum);
+            dic.Add("Authority", iDCardOCRView.Authority);
+            dic.Add("ValidDate", iDCardOCRView.ValidDate);
+
+            string downPath = string.Format("C:\\Server\\File\\OA2023\\Office\\Word\\TencentOCR\\Save\\{0}.doc",
+                dic["Name"].ToString() + "身份证(人像面)" + DateTime.Now.ToString("yyyyMMddHHmmss"));
+
+            string serverPathh = AsposeHelper.ExpertWordToModel(tempPath, downPath, dic, null);
+            iDCardOCRView.DownUrl = serverPathh.Replace("C:", "http:\\132.232.92.186");
+            #endregion
+
             return Ok(JsonView(iDCardOCRView));
         }
 

File diff suppressed because it is too large
+ 77 - 0
OASystem/OASystem.Api/OAMethodLib/File/AsposeHelper.cs


+ 146 - 0
OASystem/OASystem.Api/OAMethodLib/File/NPOIHelper.cs

@@ -0,0 +1,146 @@
+//using NPOI.XWPF.UserModel;
+
+namespace OASystem.API.OAMethodLib.NPOI
+{
+    /// <summary>
+    /// word / excel 
+    /// </summary>
+    public class NPOIHelper
+    {
+        //#region Word
+        ///// <summary>
+        ///// 输出模板docx文档(使用字典)
+        ///// </summary>
+        ///// <param name="tempFilePath">docx文件路径</param>
+        ///// <param name="outPath">输出文件路径</param>
+        ///// <param name="data">字典数据源</param>
+        //public static void Export(string tempFilePath, string outPath, Dictionary<string, string> data)
+        //{
+        //    try
+        //    {
+        //        using (FileStream stream = File.OpenRead(tempFilePath ))
+        //        {
+        //            XWPFDocument doc = new XWPFDocument(stream);
+        //            //遍历段落                  
+        //            foreach (var para in doc.Paragraphs)
+        //            {
+        //                ReplaceKey(para, data);
+        //            }
+
+        //            //遍历表格      
+        //            foreach (var table in doc.Tables)
+        //            {
+        //                foreach (var row in table.Rows)
+        //                {
+        //                    foreach (var cell in row.GetTableCells())
+        //                    {
+        //                        foreach (var para in cell.Paragraphs)
+        //                        {
+        //                            ReplaceKey(para, data);
+        //                        }
+        //                    }
+        //                }
+        //            }
+
+        //            //写文件
+        //            FileStream outFile = new FileStream(outPath, FileMode.Create);
+        //            doc.Write(outFile);
+        //            outFile.Close();
+        //        }
+        //    }
+        //    catch (Exception ex)
+        //    {
+
+        //        throw;
+        //    }
+            
+        //}
+        //private static void ReplaceKey(XWPFParagraph para, Dictionary<string, string> data)
+        //{
+        //    string text = "";
+        //    foreach (var run in para.Runs)
+        //    {
+        //        text = run.ToString();
+        //        foreach (var key in data.Keys)
+        //        {
+        //            //$$模板中数据占位符为$KEY$
+        //            if (text.Contains($"${key}$"))
+        //            {
+        //                text = text.Replace($"${key}$", data[key]);
+        //            }
+        //        }
+        //        run.SetText(text, 0);
+        //    }
+        //}
+
+        ///// <summary>
+        ///// 输出模板docx文档(使用反射)
+        ///// </summary>
+        ///// <param name="tempFilePath">docx文件路径</param>
+        ///// <param name="outPath">输出文件路径</param>
+        ///// <param name="data">对象数据源</param>
+        //public static void ExportObjet(string tempFilePath, string outPath, object data)
+        //{
+        //    using (FileStream stream = File.OpenRead(tempFilePath))
+        //    {
+        //        XWPFDocument doc = new XWPFDocument(stream);
+        //        //遍历段落                  
+        //        foreach (var para in doc.Paragraphs)
+        //        {
+        //            ReplaceKeyObjet(para, data);
+        //        }
+        //        //遍历表格      
+        //        foreach (var table in doc.Tables)
+        //        {
+        //            foreach (var row in table.Rows)
+        //            {
+        //                foreach (var cell in row.GetTableCells())
+        //                {
+        //                    foreach (var para in cell.Paragraphs)
+        //                    {
+        //                        ReplaceKeyObjet(para, data);
+        //                    }
+        //                }
+        //            }
+        //        }
+        //        //写文件
+        //        FileStream outFile = new FileStream(outPath, FileMode.Create);
+        //        doc.Write(outFile);
+        //        outFile.Close();
+        //    }
+        //}
+        //private static void ReplaceKeyObjet(XWPFParagraph para, object model)
+        //{
+        //    string text = "";
+        //    Type t = model.GetType();
+        //    PropertyInfo[] pi = t.GetProperties();
+        //    foreach (var run in para.Runs)
+        //    {
+        //        text = run.ToString();
+        //        foreach (PropertyInfo p in pi)
+        //        {
+        //            //$$模板中数据占位符为$KEY$
+        //            string key = $"${p.Name}$";
+        //            if (text.Contains(key))
+        //            {
+        //                try
+        //                {
+        //                    text = text.Replace(key, p.GetValue(model, null).ToString());
+        //                }
+        //                catch (Exception ex)
+        //                {
+        //                    //可能有空指针异常
+        //                    text = text.Replace(key, "");
+        //                }
+        //            }
+        //        }
+        //        run.SetText(text, 0);
+        //    }
+        //}
+        //#endregion
+
+
+
+
+    }
+}

+ 1 - 0
OASystem/OASystem.Api/OASystem.API.csproj

@@ -20,6 +20,7 @@
   </ItemGroup>
 
   <ItemGroup>
+    <PackageReference Include="Aspose.Words" Version="21.8.0" />
     <PackageReference Include="Autofac" Version="6.4.0" />
     <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
     <PackageReference Include="AutoMapper" Version="12.0.0" />

+ 8 - 0
OASystem/OASystem.Domain/ViewModels/TencentOCR/IDCardOCRView.cs

@@ -57,4 +57,12 @@ namespace OASystem.Domain.ViewModels.TencentOCR
         /// </summary>
         public string ValidDate { get; set; }
     }
+
+    public class IDCardOCRAndDownUrlView : IDCardOCRView
+    {
+        /// <summary>
+        /// 下载文档地址
+        /// </summary>
+        public string DownUrl { get; set; }
+    }
 }

+ 1 - 0
OASystem/OASystem.Infrastructure/Tools/CommonFun.cs

@@ -234,4 +234,5 @@ public static class CommonFun
     }
 
     #endregion
+
 }