ocr功能

booking_auth_dev
wanghaomei 2 years ago
parent c267b4eaa6
commit 672fe0665a

@ -4905,6 +4905,33 @@
<param name="carrierId">船公司ID</param>
<returns>返回适用的路由枚举</returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.OcrUpFile(Microsoft.AspNetCore.Http.IFormFile)">
<summary>
上传ocr文件
</summary>
<param name="file"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.OcrGetImg(System.String,System.Single)">
<summary>
获取图片
</summary>
<param name="fileName">文件名称</param>
<param name="scale">缩放比例默认为1.5</param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.OcrGetText(System.String,System.Single,System.Int32,System.Int32,System.Int32,System.Int32)">
<summary>
获取文字
</summary>
<param name="fileName">文件名称</param>
<param name="scale">缩放比例</param>
<param name="x">x坐标</param>
<param name="y">y坐标</param>
<param name="w">宽度</param>
<param name="h">高度</param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.GenReportJson(System.Int64)">
<summary>
获取用户报表的json

@ -51,6 +51,7 @@ using System.Threading;
using Furion.JsonSerialization;
using System.Xml.Linq;
using Myshipping.Application.Helper;
using System.Net;
namespace Myshipping.Application
{
@ -151,7 +152,7 @@ namespace Myshipping.Application
.WhereIF(!string.IsNullOrWhiteSpace(input.VESSELID), u => u.VESSELID.Contains(input.VESSELID))
.WhereIF(!string.IsNullOrWhiteSpace(input.VESSEL), u => u.VESSEL.ToLower().Contains(u.VESSEL.ToLower()))
.WhereIF(!string.IsNullOrWhiteSpace(input.VOYNO), u => u.VOYNO.Contains(input.VOYNO))
.WhereIF(!string.IsNullOrWhiteSpace(input.VOYNOINNER), u => u.VOYNOINNER.Contains(input.VOYNOINNER) )
.WhereIF(!string.IsNullOrWhiteSpace(input.VOYNOINNER), u => u.VOYNOINNER.Contains(input.VOYNOINNER))
.WhereIF(input.BETD != null, u => u.ETD >= input.BETD)
.WhereIF(input.EETD != null, u => u.ETD <= input.EETD)
.WhereIF(input.BATD != null, u => u.ATD >= input.BATD)
@ -166,9 +167,9 @@ namespace Myshipping.Application
.WhereIF(input.BETA != null, u => u.ETA >= input.BETA)
.WhereIF(input.EETA != null, u => u.ETA <= input.EETA)
.WhereIF(!string.IsNullOrWhiteSpace(input.PLACERECEIPT), u => u.PLACERECEIPT.Contains(input.PLACERECEIPT))
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTLOAD), u => u.PORTLOAD.Contains(input.PORTLOAD) )
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTLOADID), u => u.PORTLOADID== input.PORTLOADID)
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTDISCHARGEID), u => u.PORTDISCHARGEID==input.PORTDISCHARGEID)
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTLOAD), u => u.PORTLOAD.Contains(input.PORTLOAD))
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTLOADID), u => u.PORTLOADID == input.PORTLOADID)
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTDISCHARGEID), u => u.PORTDISCHARGEID == input.PORTDISCHARGEID)
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTDISCHARGE), u => u.PORTDISCHARGE.Contains(input.PORTDISCHARGE))
.WhereIF(!string.IsNullOrWhiteSpace(input.PLACEDELIVERY), u => u.PLACEDELIVERY.Contains(input.PLACEDELIVERY))
@ -193,7 +194,7 @@ namespace Myshipping.Application
.WhereIF(!string.IsNullOrWhiteSpace(input.PAYABLEATID), u => u.PAYABLEATID == input.PAYABLEATID)
.WhereIF(!string.IsNullOrWhiteSpace(input.SERVICE), u => u.SERVICE.Contains(input.SERVICE))
.WhereIF(!string.IsNullOrWhiteSpace(input.MARKS), u => u.MARKS.Contains(input.MARKS))
.WhereIF(!string.IsNullOrWhiteSpace(input.HSCODE), u => u.HSCODE.Contains(input.HSCODE) )
.WhereIF(!string.IsNullOrWhiteSpace(input.HSCODE), u => u.HSCODE.Contains(input.HSCODE))
.WhereIF(!string.IsNullOrWhiteSpace(input.DESCRIPTION), u => u.DESCRIPTION.Contains(input.DESCRIPTION))
.WhereIF(!string.IsNullOrWhiteSpace(input.KINDPKGS), u => u.KINDPKGS == input.KINDPKGS)
.WhereIF(!string.IsNullOrWhiteSpace(input.CNTRTOTAL), u => u.CNTRTOTAL == input.CNTRTOTAL)
@ -216,7 +217,7 @@ namespace Myshipping.Application
.WhereIF(!string.IsNullOrWhiteSpace(input.SIREMARK), u => u.SIREMARK.Contains(input.SIREMARK))
.WhereIF(!string.IsNullOrWhiteSpace(input.YARDREMARK), u => u.YARDREMARK.Contains(input.YARDREMARK))
.WhereIF(!string.IsNullOrWhiteSpace(input.COMPID), u => u.COMPID == input.COMPID)
.WhereIF(!string.IsNullOrWhiteSpace(input.COMPNAME), u => u.COMPNAME.Contains(input.COMPNAME) )
.WhereIF(!string.IsNullOrWhiteSpace(input.COMPNAME), u => u.COMPNAME.Contains(input.COMPNAME))
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERNAME), u => u.SHIPPERNAME.Contains(input.SHIPPERNAME))
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERCITY), u => u.SHIPPERCITY.Contains(input.SHIPPERCITY))
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERPROVINCE), u => u.SHIPPERPROVINCE == input.SHIPPERPROVINCE)
@ -248,7 +249,7 @@ namespace Myshipping.Application
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICEID), u => u.CUSTSERVICEID == input.CUSTSERVICEID)
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICE), u => u.CUSTSERVICE.Contains(input.CUSTSERVICE))
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMERNAME), u => u.CUSTOMERNAME.Contains(input.CUSTOMERNAME))
.WhereIF(input.CUSTOMERID != null&& input.CUSTOMERID!=0, u => u.CUSTOMERID == input.CUSTOMERID)
.WhereIF(input.CUSTOMERID != null && input.CUSTOMERID != 0, u => u.CUSTOMERID == input.CUSTOMERID)
.WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDER), u => u.FORWARDER.Contains(input.FORWARDER))
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICE), u => u.CUSTSERVICE == input.CUSTSERVICE)
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMERNAME), u => u.CUSTOMERNAME == input.CUSTOMERNAME)
@ -501,7 +502,7 @@ namespace Myshipping.Application
}
string _oldvalue = oldvalue != null ? oldvalue.ToString() : "";
string _value = value != null ? value.ToString() : "";
if (_oldvalue != _value&&!string.IsNullOrWhiteSpace(descriptor.Description))
if (_oldvalue != _value && !string.IsNullOrWhiteSpace(descriptor.Description))
{
if (flag)
{
@ -592,7 +593,7 @@ namespace Myshipping.Application
//检索EDI扩展
var ediExtEntity = await _bookingEDIExt.FirstOrDefaultAsync(u => u.BookingId == Id);
if(ediExtEntity != null)
if (ediExtEntity != null)
{
ordOut.BookingEDIExt = ediExtEntity.Adapt<BookingEDIExtDto>();
}
@ -784,7 +785,8 @@ namespace Myshipping.Application
{
_logger.LogInformation("提单号:" + MBLNO + " 调用运踪接口");
var key = _repWebAcc.FirstOrDefault(x => x.TenantId == Convert.ToInt64(UserManager.TENANT_ID) && x.TypeCode == "seae_billtraceurl");
if (key==null) {
if (key == null)
{
throw Oops.Bah("调用运踪接口相关账号未维护!");
}
@ -2196,6 +2198,122 @@ namespace Myshipping.Application
}
#endregion
#region ocr
/// <summary>
/// 上传ocr文件
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost("/BookingOrder/OcrUpFile")]
public async Task<string> OcrUpFile(IFormFile file)
{
//未上传文件
if (file == null || file.Length == 0)
{
throw Oops.Bah("未上传文件");
}
var originalFilename = file.FileName; // 文件原始名称
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
if (!serverUrl.EndsWith("/"))
{
serverUrl += "/";
}
var ms = new MemoryStream();
await file.CopyToAsync(ms);
_logger.LogInformation($"调用ocr处理文件{originalFilename}");
//Furion框架上传文件名称带有双引号导致上传失败
//var strRtn = await $"{serverUrl}pdf/upload"
// .SetContentType("multipart/form-data")
// .SetContentEncoding(Encoding.UTF8)
// .SetBodyBytes(("file", ms.GetBuffer(), "test.pdf"))
// .PostAsStringAsync();
//var jobj = strRtn.ToJObject();
//if (jobj.GetIntValue("code") == 0)
//{
// var fn = jobj.GetStringValue("data");
// return fn;
//}
//else
//{
// throw Oops.Bah(jobj.GetStringValue("message"));
//}
//使用HttpClient方式上传文件
ms.Position = 0;
var formData = new MultipartFormDataContent();
formData.Add(new StreamContent(ms, (int)ms.Length), "file", originalFilename);
var _httpclient = new HttpClient();
var response = await _httpclient.PostAsync($"{serverUrl}pdf/upload", formData);
if (response.IsSuccessStatusCode)
{
var strRtn = response.Content.ReadAsStringAsync().Result;
var jobj = strRtn.ToJObject();
if (jobj.GetIntValue("code") == 0)
{
var fn = jobj.GetStringValue("data");
return fn;
}
else
{
throw Oops.Bah(jobj.GetStringValue("message"));
}
}
throw Oops.Bah("文件上传失败");
}
/// <summary>
/// 获取图片
/// </summary>
/// <param name="fileName">文件名称</param>
/// <param name="scale">缩放比例默认为1.5</param>
/// <returns></returns>
[HttpPost("/BookingOrder/OcrGetImg")]
public async Task<IActionResult> OcrGetImg(string fileName, float scale = 1.5f)
{
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
if (!serverUrl.EndsWith("/"))
{
serverUrl += "/";
}
var bs = await $"{serverUrl}pdf/getCanvasImage?fileName={fileName}&scale={scale}"
.GetAsByteArrayAsync();
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = "ocr.jpg" };
return result;
}
/// <summary>
/// 获取文字
/// </summary>
/// <param name="fileName">文件名称</param>
/// <param name="scale">缩放比例</param>
/// <param name="x">x坐标</param>
/// <param name="y">y坐标</param>
/// <param name="w">宽度</param>
/// <param name="h">高度</param>
/// <returns></returns>
[HttpPost("/BookingOrder/OcrGetText")]
public async Task<string> OcrGetText(string fileName, float scale, int x, int y, int w, int h)
{
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
if (!serverUrl.EndsWith("/"))
{
serverUrl += "/";
}
var str = await $"{serverUrl}pdf/getRegionText?fileName={fileName}&scale={scale}&x={x}&y={y}&w={w}&h={h}"
.PostAsStringAsync();
return str;
}
#endregion
#region 其他
/// <summary>
/// 获取用户报表的json

@ -64,7 +64,7 @@ namespace Myshipping.Application
//未上传打印模板文件
if (file == null || file.Length == 0)
{
throw Oops.Oh(BookingErrorCode.BOOK113);
throw Oops.Bah(BookingErrorCode.BOOK113);
}
var opt = App.GetOptions<PrintTemplateOptions>();
@ -72,7 +72,7 @@ namespace Myshipping.Application
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
if (!opt.fileType.Contains(fileSuffix))
{
throw Oops.Oh(BookingErrorCode.BOOK114);
throw Oops.Bah(BookingErrorCode.BOOK114);
}
var dirAbs = string.Empty;
@ -124,7 +124,7 @@ namespace Myshipping.Application
//未上传打印模板文件
if (file == null || file.Length == 0)
{
throw Oops.Oh(BookingErrorCode.BOOK113);
throw Oops.Bah(BookingErrorCode.BOOK113);
}
var opt = App.GetOptions<PrintTemplateOptions>();
@ -132,14 +132,14 @@ namespace Myshipping.Application
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
if (!opt.fileType.Contains(fileSuffix))
{
throw Oops.Oh(BookingErrorCode.BOOK114);
throw Oops.Bah(BookingErrorCode.BOOK114);
}
_rep.Context.QueryFilter.Clear();
var entity = _rep.FirstOrDefault(x => x.Id == input.Id);
if (entity == null)
{
throw Oops.Oh(BookingErrorCode.BOOK112);
throw Oops.Bah(BookingErrorCode.BOOK112);
}
entity = input.Adapt(entity);
@ -219,7 +219,7 @@ namespace Myshipping.Application
var printFile = await _rep.FirstOrDefaultAsync(u => u.Id == id);
if (printFile == null)
{
throw Oops.Oh(BookingErrorCode.BOOK115);
throw Oops.Bah(BookingErrorCode.BOOK115);
}
@ -233,7 +233,7 @@ namespace Myshipping.Application
var fileFullPath = Path.Combine(dirAbs, printFile.FilePath);
if (!File.Exists(fileFullPath))
{
throw Oops.Oh(BookingErrorCode.BOOK115);
throw Oops.Bah(BookingErrorCode.BOOK115);
}
var fileName = HttpUtility.UrlEncode(printFile.FileName, Encoding.GetEncoding("UTF-8"));

Loading…
Cancel
Save