| GasolineBlend.BLL/GasolineBlend.BLL.csproj | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| GasolineBlend.BLL/ResultsIdentifyBLL.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| GasolineBlend.BLL/packages.config | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| GasolineBlend/Controllers/FRMReportInfoController.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
GasolineBlend.BLL/GasolineBlend.BLL.csproj
@@ -57,6 +57,12 @@ <SpecificVersion>False</SpecificVersion> <HintPath>..\GasolineBlend\bin\CalculusWY.dll</HintPath> </Reference> <Reference Include="Flurl, Version=3.0.6.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\packages\Flurl.3.0.6\lib\net461\Flurl.dll</HintPath> </Reference> <Reference Include="Flurl.Http, Version=3.2.4.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\packages\Flurl.Http.3.2.4\lib\net461\Flurl.Http.dll</HintPath> </Reference> <Reference Include="LinqToExcel, Version=1.11.0.0, Culture=neutral, PublicKeyToken=9c8ea65a58f03f1f, processorArchitecture=MSIL"> <HintPath>..\packages\LinqToExcel.1.11.0\lib\LinqToExcel.dll</HintPath> </Reference> @@ -111,6 +117,9 @@ <Reference Include="System.Runtime.Serialization" /> <Reference Include="System.ServiceModel" /> <Reference Include="System.ServiceModel.Web" /> <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath> </Reference> <Reference Include="System.Web" /> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" /> GasolineBlend.BLL/ResultsIdentifyBLL.cs
@@ -1,5 +1,6 @@ using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.IO; using System.Linq; @@ -8,6 +9,9 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using CommonHelper; using Flurl.Http; using Newtonsoft.Json.Linq; namespace GasolineBlend.BLL { @@ -131,6 +135,100 @@ return content; } #endregion #region 阿里云OcrTable public static async Task<DataTable> AliOcrTable(string base64Str) { var sysUrl = "https://analysis.market.alicloudapi.com/ocrservice/table"; var sysAppcode = "b77bcd5d997f47ecaee28e359fbcd605"; var body = new {img = base64Str, rotate = false}; var res = await sysUrl .AllowAnyHttpStatus() .WithHeader("Authorization", "APPCODE "+sysAppcode) .PostJsonAsync(body) .ReceiveString(); var obj = res.ToObject<JObject>(); if (obj["error_code"] != null) throw new Exception(obj["error_msg"].ToString()); var result = res.ToObject<AliOcrTableResult>(); var table = new DataTable(); foreach (var cols in result.tableInfo.items) { for (var colIndex = 0; colIndex < cols.value.Count; colIndex++) { var col = cols.value[colIndex]; table.Columns.Add($"col{colIndex}"); var row0Txt = col.key.name; if (colIndex == 0) { DataRow dr0 = table.NewRow(); dr0[colIndex] = row0Txt; table.Rows.Add(dr0); } else { table.Rows[0][colIndex] = row0Txt; } for (var rowIndex = 0; rowIndex < col.value.Count; rowIndex++) { var row = col.value[rowIndex]; if (colIndex == 0) { DataRow dr = table.NewRow(); dr[colIndex] = row.text; table.Rows.Add(dr); } else table.Rows[rowIndex+1][colIndex] = row.text; } } } return table; } public class AliOcrTableResult { public AliOcrTableResultTableInfo tableInfo { get; set; } public class AliOcrTableResultTableInfo { public List<AliOcrTableResultItem> items { get; set; } } public class AliOcrTableResultItem { /// <summary> /// 是否在表格内 /// </summary> public bool whether_in_form { get; set; } public List<AliOcrTableResultItemValue> value { get; set; } } public class AliOcrTableResultItemValue { public AliOcrTableResultItemValueKey key { get; set; } public List<AliOcrTableResultItemValueValue> value { get; set; } } public class AliOcrTableResultItemValueKey { public string name { get; set; } } public class AliOcrTableResultItemValueValue { public string text { get; set; } } } #endregion } GasolineBlend.BLL/packages.config
@@ -1,5 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Flurl" version="3.0.6" targetFramework="net461" /> <package id="Flurl.Http" version="3.2.4" targetFramework="net461" /> <package id="LinqToExcel" version="1.11.0" targetFramework="net461" /> <package id="MathNet.Numerics" version="4.15.0" targetFramework="net461" /> <package id="Microsoft.Office.Interop.Word" version="15.0.4797.1003" targetFramework="net461" /> @@ -7,4 +9,5 @@ <package id="NPOI" version="2.3.0" targetFramework="net461" /> <package id="Portable.BouncyCastle" version="1.8.6" targetFramework="net461" /> <package id="SharpZipLib" version="0.86.0" targetFramework="net461" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" /> </packages> GasolineBlend/Controllers/FRMReportInfoController.cs
@@ -10,6 +10,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; using System.Web.Mvc; @@ -186,6 +187,35 @@ return Error(); } } [HttpPost] public async Task<ActionResult> AliOcrTable() { if (HttpContext.Request.Files.Count == 0) return Error("上传请求文件为0!"); if (HttpContext.Request.Files.Count != 1) return Error("只能上次一张图片!"); var uploadFile = HttpContext.Request.Files[0]; //上传文件 if (uploadFile == null) return Error("图片为空!请重新上传!"); FileInfo file = new FileInfo(uploadFile.FileName); if (file.Extension != ".jpg" && file.Extension != ".jpeg" && file.Extension != ".png") return Error("只能上传图片!请重新上传!"); if (uploadFile.InputStream.Length > 4 * 1024 * 1024) //1024*1024*100=100M--前端验证 return Error("文件大小已经超过4M!请重新上传!"); byte[] bytes; using (var memoryStream = new MemoryStream()) { uploadFile.InputStream.CopyTo(memoryStream); bytes = memoryStream.ToArray(); } var base64Str = Convert.ToBase64String(bytes); var table = await ResultsIdentifyBLL.AliOcrTable(base64Str); return Success(data: table); } /// <summary> ///获取登陆UserId /// </summary>