|
@@ -41,162 +41,177 @@ namespace OASystem.API.Controllers
|
|
|
{
|
|
|
return Ok(JsonView("请上传图片base64编码数据!"));
|
|
|
}
|
|
|
-
|
|
|
|
|
|
JsonView jw = new JsonView();
|
|
|
- string api_Response = BaiduApiHelper._apiTableV2(dto.base64img);
|
|
|
- JObject json = JObject.Parse(api_Response);
|
|
|
- if (json["tables_result"][0]["body"] != null)
|
|
|
+ try
|
|
|
{
|
|
|
-
|
|
|
- List<BaiduOCR_TableV2> sourceList = JsonConvert.DeserializeObject<List<BaiduOCR_TableV2>>(json["tables_result"][0]["body"].ToString());
|
|
|
- List<BaiduOCR_TableV2> headerList = sourceList.Where(s => s.row_start == 0).OrderBy(s => s.col_start).ToList();
|
|
|
- List<BaiduOCR_TableV2> dataList = sourceList.Where(s => s.row_start != 0).ToList();
|
|
|
- int maxRowIndex = dataList.Max(s => s.row_start);
|
|
|
- int maxColIndex = headerList.Max(s => s.col_start) + 1;
|
|
|
- Dictionary<int, string> dicHeader = new Dictionary<int, string>();
|
|
|
- List<string> listNameStr = new List<string>() { "姓名", "Name" };
|
|
|
- List<string> listSexStr = new List<string>() { "性别", "Gender" };
|
|
|
- List<string> listDOBStr = new List<string>() { "D.O.B", "出生年月","生日" };
|
|
|
- List<string> listIdCard = new List<string>() { "身份证号码", "身份证" };
|
|
|
- List<string> listOrganizationStr = new List<string>() { "工作单位", "Organization", "单位" };
|
|
|
- List<string> listJobStr = new List<string>() { "职务", "Title", "职位" };
|
|
|
- List<string> listMobileStr = new List<string>() { "联系电话", "Mobile" };
|
|
|
- List<string> listAgeStr = new List<string>() { "年龄", "Age" };
|
|
|
- for (int i = 0; i < headerList.Count; i++)
|
|
|
+ string api_Response = BaiduApiHelper._apiTableV2(dto.base64img);
|
|
|
+ JObject json = JObject.Parse(api_Response);
|
|
|
+ if (json["tables_result"][0]["body"] != null)
|
|
|
{
|
|
|
- string words = headerList[i].words.Trim();
|
|
|
- if (listNameStr.Exists(s => s == words))
|
|
|
- {
|
|
|
- dicHeader.Add(i, "Name");
|
|
|
- }
|
|
|
- else if (listSexStr.Exists(s => s == words))
|
|
|
- {
|
|
|
- dicHeader.Add(i, "Sex");
|
|
|
- }
|
|
|
- else if (listDOBStr.Exists(s => s == words))
|
|
|
- {
|
|
|
- dicHeader.Add(i, "DOB");
|
|
|
- }
|
|
|
- else if (listIdCard.Exists(s => s == words))
|
|
|
- {
|
|
|
- dicHeader.Add(i, "IdCard");
|
|
|
- }
|
|
|
- else if (listOrganizationStr.Exists(s => s == words))
|
|
|
- {
|
|
|
- dicHeader.Add(i, "Organization");
|
|
|
- }
|
|
|
- else if (listJobStr.Exists(s => s == words))
|
|
|
- {
|
|
|
- dicHeader.Add(i, "Job");
|
|
|
- }
|
|
|
- else if (listMobileStr.Exists(s => s == words))
|
|
|
+
|
|
|
+ List<BaiduOCR_TableV2> sourceList = JsonConvert.DeserializeObject<List<BaiduOCR_TableV2>>(json["tables_result"][0]["body"].ToString());
|
|
|
+ List<BaiduOCR_TableV2> headerList = sourceList.Where(s => s.row_start == 0).OrderBy(s => s.col_start).Select(x => new BaiduOCR_TableV2
|
|
|
{
|
|
|
- dicHeader.Add(i, "Mobile");
|
|
|
- }
|
|
|
- else if (listAgeStr.Exists(s => s == words))
|
|
|
+ col_end = x.col_end,
|
|
|
+ col_start = x.col_start,
|
|
|
+ row_end = x.row_end,
|
|
|
+ row_start = x.row_start,
|
|
|
+ words = Regex.Replace(x.words, "[`~!@#$%^&*()_\\-+=<>?:\"{}|,.\\/;'\\\\[\\]·!#¥(——):;“”‘、,|《。》?、【】[\\]]", string.Empty)
|
|
|
+ }).ToList();
|
|
|
+ List<BaiduOCR_TableV2> dataList = sourceList.Where(s => s.row_start != 0).ToList();
|
|
|
+ int maxRowIndex = dataList.Max(s => s.row_start);
|
|
|
+ int maxColIndex = headerList.Max(s => s.col_start) + 1;
|
|
|
+ Dictionary<int, string> dicHeader = new Dictionary<int, string>();
|
|
|
+ List<string> listNameStr = new List<string>() { "姓名", "Name" };
|
|
|
+ List<string> listSexStr = new List<string>() { "性别", "Gender" };
|
|
|
+ List<string> listDOBStr = new List<string>() { "D.O.B", "出生年月", "生日" };
|
|
|
+ List<string> listIdCard = new List<string>() { "身份证号码", "身份证" };
|
|
|
+ List<string> listOrganizationStr = new List<string>() { "工作单位", "Organization", "单位" };
|
|
|
+ List<string> listJobStr = new List<string>() { "职务", "Title", "职位" };
|
|
|
+ List<string> listMobileStr = new List<string>() { "联系电话", "Mobile" };
|
|
|
+ List<string> listAgeStr = new List<string>() { "年龄", "Age" };
|
|
|
+ for (int i = 0; i < headerList.Count; i++)
|
|
|
{
|
|
|
- dicHeader.Add(i, "Age");
|
|
|
- }
|
|
|
+ string words = headerList[i].words.Trim();
|
|
|
+ if (listNameStr.Exists(s => s == words))
|
|
|
+ {
|
|
|
+ dicHeader.Add(i, "Name");
|
|
|
+ }
|
|
|
+ else if (listSexStr.Exists(s => s == words))
|
|
|
+ {
|
|
|
+ dicHeader.Add(i, "Sex");
|
|
|
+ }
|
|
|
+ else if (listDOBStr.Exists(s => s == words))
|
|
|
+ {
|
|
|
+ dicHeader.Add(i, "DOB");
|
|
|
+ }
|
|
|
+ else if (listIdCard.Exists(s => s == words))
|
|
|
+ {
|
|
|
+ dicHeader.Add(i, "IdCard");
|
|
|
+ }
|
|
|
+ else if (listOrganizationStr.Exists(s => s == words))
|
|
|
+ {
|
|
|
+ dicHeader.Add(i, "Organization");
|
|
|
+ }
|
|
|
+ else if (listJobStr.Exists(s => s == words))
|
|
|
+ {
|
|
|
+ dicHeader.Add(i, "Job");
|
|
|
+ }
|
|
|
+ else if (listMobileStr.Exists(s => s == words))
|
|
|
+ {
|
|
|
+ dicHeader.Add(i, "Mobile");
|
|
|
+ }
|
|
|
+ else if (listAgeStr.Exists(s => s == words))
|
|
|
+ {
|
|
|
+ dicHeader.Add(i, "Age");
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- List<BaiduClientOCRView> ClientArr = new List<BaiduClientOCRView>();
|
|
|
- for (int i = 1; i <= maxRowIndex; i++)
|
|
|
- {
|
|
|
- BaiduClientOCRView client = new BaiduClientOCRView();
|
|
|
- for (int j = 0; j < maxColIndex; j++)
|
|
|
+ List<BaiduClientOCRView> ClientArr = new List<BaiduClientOCRView>();
|
|
|
+ for (int i = 1; i <= maxRowIndex; i++)
|
|
|
{
|
|
|
- var item = dataList.First(s => s.row_start == i && s.col_start == j);
|
|
|
- string words = item.words.Replace("\\n", "");
|
|
|
- string values = dicHeader[j];
|
|
|
-
|
|
|
- if (values.Equals("Name"))
|
|
|
+ BaiduClientOCRView client = new BaiduClientOCRView();
|
|
|
+ for (int j = 0; j < maxColIndex; j++)
|
|
|
{
|
|
|
- if (Regex.Matches(words, "[a-zA-Z]").Count < 1)
|
|
|
+ var item = dataList.First(s => s.row_start == i && s.col_start == j);
|
|
|
+ string words = item.words.Replace("\\n", "");
|
|
|
+ string values = dicHeader[j];
|
|
|
+
|
|
|
+ if (values.Equals("Name"))
|
|
|
{
|
|
|
- string lastName = words.Substring(0, 1);
|
|
|
- string name = words.Substring(1);
|
|
|
- client.LastName = lastName;
|
|
|
- client.FirstName = name;
|
|
|
- string lastNamePinYin = lastName.GetTotalPingYin()[0].ToUpper();
|
|
|
- string firstNamePinYin = "";
|
|
|
-
|
|
|
- for (int n = 0; n < name.Length; n++)
|
|
|
+ if (Regex.Matches(words, "[a-zA-Z]").Count < 1)
|
|
|
{
|
|
|
- firstNamePinYin += name[n].ToString().GetTotalPingYin()[0].ToUpper() + " ";
|
|
|
+ string lastName = words.Substring(0, 1);
|
|
|
+ string name = words.Substring(1);
|
|
|
+ client.LastName = lastName;
|
|
|
+ client.FirstName = name;
|
|
|
+ string lastNamePinYin = lastName.GetTotalPingYin()[0].ToUpper();
|
|
|
+ string firstNamePinYin = "";
|
|
|
+
|
|
|
+ for (int n = 0; n < name.Length; n++)
|
|
|
+ {
|
|
|
+ firstNamePinYin += name[n].ToString().GetTotalPingYin()[0].ToUpper() + " ";
|
|
|
+ }
|
|
|
+
|
|
|
+ client.Pinyin = lastNamePinYin + "/" + firstNamePinYin;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Regex regForeign = new Regex("[a-zA-Z]+[\\s][a-zA-Z]+");
|
|
|
+ if (regForeign.IsMatch(words))
|
|
|
+ {
|
|
|
+ string[] names = words.Split(' ');
|
|
|
+ client.LastName = names[1];
|
|
|
+ client.FirstName = names[0];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ client.FirstName = words;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- client.Pinyin = lastNamePinYin + "/"+ firstNamePinYin;
|
|
|
}
|
|
|
- else
|
|
|
+ else if (values.Equals("Sex"))
|
|
|
{
|
|
|
- Regex regForeign = new Regex("[a-zA-Z]+[\\s][a-zA-Z]+");
|
|
|
- if (regForeign.IsMatch(words))
|
|
|
+ client.Sex = words == "男" ? 0 : 1;
|
|
|
+ }
|
|
|
+ else if (values.Equals("DOB"))
|
|
|
+ {
|
|
|
+ client.Birthday = words;
|
|
|
+ DateTime time = new DateTime();
|
|
|
+ if (DateTime.TryParse(client.Birthday, out time))
|
|
|
{
|
|
|
- string[] names = words.Split(' ');
|
|
|
- client.LastName = names[1];
|
|
|
- client.FirstName = names[0];
|
|
|
+ client.Birthday = time.ToString("yyyy-MM-dd");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- client.FirstName = words;
|
|
|
+ client.Birthday = "";
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
- }
|
|
|
- else if (values.Equals("Sex"))
|
|
|
- {
|
|
|
- client.Sex = words;
|
|
|
- }
|
|
|
- else if (values.Equals("DOB"))
|
|
|
- {
|
|
|
- client.Birthday = words;
|
|
|
- DateTime time = new DateTime();
|
|
|
- if (DateTime.TryParse(client.Birthday, out time))
|
|
|
+ else if (values.Equals("IdCard"))
|
|
|
{
|
|
|
- client.Birthday = time.ToString("yyyy-MM-dd");
|
|
|
+ client.IDcard = words;
|
|
|
}
|
|
|
- else
|
|
|
+ else if (values.Equals("Organization"))
|
|
|
{
|
|
|
- client.Birthday = "";
|
|
|
+ client.CompanyFullName = words;
|
|
|
+ }
|
|
|
+ else if (values.Equals("Job"))
|
|
|
+ {
|
|
|
+ client.Job = words;
|
|
|
+ }
|
|
|
+ else if (values.Equals("Mobile"))
|
|
|
+ {
|
|
|
+ client.Phone = words;
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- else if (values.Equals("IdCard"))
|
|
|
- {
|
|
|
- client.IDcard = words;
|
|
|
- }
|
|
|
- else if (values.Equals("Organization"))
|
|
|
- {
|
|
|
- client.CompanyFullName = words;
|
|
|
- }
|
|
|
- else if (values.Equals("Job"))
|
|
|
- {
|
|
|
- client.Job = words;
|
|
|
- }
|
|
|
- else if (values.Equals("Mobile"))
|
|
|
- {
|
|
|
- client.Phone = words;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- ClientArr.Add(client);
|
|
|
- }
|
|
|
+ ClientArr.Add(client);
|
|
|
+ }
|
|
|
|
|
|
- jw.Code = 200;
|
|
|
- jw.Msg = "获取成功!";
|
|
|
- jw.Data = ClientArr;
|
|
|
+ jw.Code = 200;
|
|
|
+ jw.Msg = "获取成功!";
|
|
|
+ jw.Data = ClientArr;
|
|
|
|
|
|
+ }
|
|
|
+ else if (json["error_code"] != null)
|
|
|
+ {
|
|
|
+ jw.Data = new string[0];
|
|
|
+ jw.Msg = "百度接口异常!";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ jw.Data = new string[0];
|
|
|
+ jw.Msg = "百度接口异常!";
|
|
|
+ }
|
|
|
}
|
|
|
- else if (json["error_code"] != null)
|
|
|
- {
|
|
|
- jw.Data = new string[0];
|
|
|
- jw.Msg = "百度接口异常!";
|
|
|
- }
|
|
|
- else
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
+ jw.Code = 400;
|
|
|
+ jw.Msg = "base64数据有误!";
|
|
|
jw.Data = new string[0];
|
|
|
- jw.Msg = "百度接口异常!";
|
|
|
}
|
|
|
|
|
|
return Ok(jw);
|