提交修改
This commit is contained in:
parent
fd960804e8
commit
372e2990fd
@ -5,6 +5,7 @@ package com.heyu.api.data.utils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
@ -19,12 +20,15 @@ import java.util.regex.Pattern;
|
||||
* @author linzi
|
||||
*/
|
||||
@Slf4j
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
{
|
||||
/** 空字符串 */
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 空字符串
|
||||
*/
|
||||
private static final String NULLSTR = "";
|
||||
|
||||
/** 下划线 */
|
||||
/**
|
||||
* 下划线
|
||||
*/
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
/**
|
||||
@ -33,8 +37,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param value defaultValue 要判断的value
|
||||
* @return value 返回值
|
||||
*/
|
||||
public static <T> T nvl(T value, T defaultValue)
|
||||
{
|
||||
public static <T> T nvl(T value, T defaultValue) {
|
||||
return value != null ? value : defaultValue;
|
||||
}
|
||||
|
||||
@ -44,8 +47,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> coll)
|
||||
{
|
||||
public static boolean isEmpty(Collection<?> coll) {
|
||||
return isNull(coll) || coll.isEmpty();
|
||||
}
|
||||
|
||||
@ -55,8 +57,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Collection<?> coll)
|
||||
{
|
||||
public static boolean isNotEmpty(Collection<?> coll) {
|
||||
return !isEmpty(coll);
|
||||
}
|
||||
|
||||
@ -64,10 +65,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* * 判断一个对象数组是否为空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
** @return true:为空 false:非空
|
||||
* * @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Object[] objects)
|
||||
{
|
||||
public static boolean isEmpty(Object[] objects) {
|
||||
return isNull(objects) || (objects.length == 0);
|
||||
}
|
||||
|
||||
@ -77,8 +77,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param objects 要判断的对象数组
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Object[] objects)
|
||||
{
|
||||
public static boolean isNotEmpty(Object[] objects) {
|
||||
return !isEmpty(objects);
|
||||
}
|
||||
|
||||
@ -88,8 +87,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param map 要判断的Map
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Map<?, ?> map)
|
||||
{
|
||||
public static boolean isEmpty(Map<?, ?> map) {
|
||||
return isNull(map) || map.isEmpty();
|
||||
}
|
||||
|
||||
@ -99,8 +97,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param map 要判断的Map
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Map<?, ?> map)
|
||||
{
|
||||
public static boolean isNotEmpty(Map<?, ?> map) {
|
||||
return !isEmpty(map);
|
||||
}
|
||||
|
||||
@ -110,8 +107,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param str String
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(String str)
|
||||
{
|
||||
public static boolean isEmpty(String str) {
|
||||
return isNull(str) || NULLSTR.equals(str.trim());
|
||||
}
|
||||
|
||||
@ -121,8 +117,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param str String
|
||||
* @return true:非空串 false:空串
|
||||
*/
|
||||
public static boolean isNotEmpty(String str)
|
||||
{
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !isEmpty(str);
|
||||
}
|
||||
|
||||
@ -132,13 +127,12 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param object Object
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isNull(Object object)
|
||||
{
|
||||
public static boolean isNull(Object object) {
|
||||
return object == null;
|
||||
}
|
||||
|
||||
/**
|
||||
*校验是否为数字
|
||||
* 校验是否为数字
|
||||
*/
|
||||
public static boolean checkStrIsNum(String str) {
|
||||
Matcher isNum = NUMBER_PATTERN.matcher(str);
|
||||
@ -147,19 +141,18 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 判断整数数字的正则表达式
|
||||
private static Pattern NUMBER_PATTERN = Pattern.compile("^[-\\+]?[\\d]*$");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否非空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotNull(Object object)
|
||||
{
|
||||
public static boolean isNotNull(Object object) {
|
||||
return !isNull(object);
|
||||
}
|
||||
|
||||
@ -169,44 +162,37 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param object 对象
|
||||
* @return true:是数组 false:不是数组
|
||||
*/
|
||||
public static boolean isArray(Object object)
|
||||
{
|
||||
public static boolean isArray(Object object) {
|
||||
return isNotNull(object) && object.getClass().isArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 去空格
|
||||
*/
|
||||
public static String trim(String str)
|
||||
{
|
||||
public static String trim(String str) {
|
||||
return (str == null ? "" : str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param str 字符串
|
||||
* @param start 开始
|
||||
* @return 结果
|
||||
*/
|
||||
public static String substring(final String str, int start)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
public static String substring(final String str, int start) {
|
||||
if (str == null) {
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
if (start < 0) {
|
||||
start = str.length() + start;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
if (start > str.length())
|
||||
{
|
||||
if (start > str.length()) {
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
@ -216,43 +202,35 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param str 字符串
|
||||
* @param start 开始
|
||||
* @param end 结束
|
||||
* @param end 结束
|
||||
* @return 结果
|
||||
*/
|
||||
public static String substring(final String str, int start, int end)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
public static String substring(final String str, int start, int end) {
|
||||
if (str == null) {
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (end < 0)
|
||||
{
|
||||
if (end < 0) {
|
||||
end = str.length() + end;
|
||||
}
|
||||
if (start < 0)
|
||||
{
|
||||
if (start < 0) {
|
||||
start = str.length() + start;
|
||||
}
|
||||
|
||||
if (end > str.length())
|
||||
{
|
||||
if (end > str.length()) {
|
||||
end = str.length();
|
||||
}
|
||||
|
||||
if (start > end)
|
||||
{
|
||||
if (start > end) {
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
if (end < 0)
|
||||
{
|
||||
if (end < 0) {
|
||||
end = 0;
|
||||
}
|
||||
|
||||
@ -263,10 +241,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
/**
|
||||
* 下划线转驼峰命名
|
||||
*/
|
||||
public static String toUnderScoreCase(String str)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
public static String toUnderScoreCase(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@ -276,31 +252,23 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
boolean curreCharIsUpperCase = true;
|
||||
// 下一字符是否大写
|
||||
boolean nexteCharIsUpperCase = true;
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
if (i > 0)
|
||||
{
|
||||
if (i > 0) {
|
||||
preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
preCharIsUpperCase = false;
|
||||
}
|
||||
|
||||
curreCharIsUpperCase = Character.isUpperCase(c);
|
||||
|
||||
if (i < (str.length() - 1))
|
||||
{
|
||||
if (i < (str.length() - 1)) {
|
||||
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
|
||||
}
|
||||
|
||||
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase)
|
||||
{
|
||||
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
|
||||
sb.append(SEPARATOR);
|
||||
}
|
||||
else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
|
||||
{
|
||||
} else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
|
||||
sb.append(SEPARATOR);
|
||||
}
|
||||
sb.append(Character.toLowerCase(c));
|
||||
@ -312,18 +280,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
/**
|
||||
* 是否包含字符串
|
||||
*
|
||||
* @param str 验证字符串
|
||||
* @param str 验证字符串
|
||||
* @param strs 字符串组
|
||||
* @return 包含返回true
|
||||
*/
|
||||
public static boolean inStringIgnoreCase(String str, String... strs)
|
||||
{
|
||||
if (str != null && strs != null)
|
||||
{
|
||||
for (String s : strs)
|
||||
{
|
||||
if (str.equalsIgnoreCase(trim(s)))
|
||||
{
|
||||
public static boolean inStringIgnoreCase(String str, String... strs) {
|
||||
if (str != null && strs != null) {
|
||||
for (String s : strs) {
|
||||
if (str.equalsIgnoreCase(trim(s))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -337,27 +301,21 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* @param name 转换前的下划线大写方式命名的字符串
|
||||
* @return 转换后的驼峰式命名的字符串
|
||||
*/
|
||||
public static String convertToCamelCase(String name)
|
||||
{
|
||||
public static String convertToCamelCase(String name) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
// 快速检查
|
||||
if (name == null || name.isEmpty())
|
||||
{
|
||||
if (name == null || name.isEmpty()) {
|
||||
// 没必要转换
|
||||
return "";
|
||||
}
|
||||
else if (!name.contains("_"))
|
||||
{
|
||||
} else if (!name.contains("_")) {
|
||||
// 不含下划线,仅将首字母大写
|
||||
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
}
|
||||
// 用下划线将原始字符串分割
|
||||
String[] camels = name.split("_");
|
||||
for (String camel : camels)
|
||||
{
|
||||
for (String camel : camels) {
|
||||
// 跳过原始字符串中开头、结尾的下换线或双重下划线
|
||||
if (camel.isEmpty())
|
||||
{
|
||||
if (camel.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
// 首字母大写
|
||||
@ -370,30 +328,22 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
/**
|
||||
* 驼峰式命名法 例如:user_name->userName
|
||||
*/
|
||||
public static String toCamelCase(String s)
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
public static String toCamelCase(String s) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
s = s.toLowerCase();
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
boolean upperCase = false;
|
||||
for (int i = 0; i < s.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
|
||||
if (c == SEPARATOR)
|
||||
{
|
||||
if (c == SEPARATOR) {
|
||||
upperCase = true;
|
||||
}
|
||||
else if (upperCase)
|
||||
{
|
||||
} else if (upperCase) {
|
||||
sb.append(Character.toUpperCase(c));
|
||||
upperCase = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
@ -401,8 +351,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T cast(Object obj)
|
||||
{
|
||||
public static <T> T cast(Object obj) {
|
||||
return (T) obj;
|
||||
}
|
||||
|
||||
@ -448,4 +397,86 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 文件名:URIEncode.java 描述: 修改人:gogym 修改时间:2018年11月16日 跟踪单号: 修改单号: 修改内容:
|
||||
*/
|
||||
|
||||
|
||||
public static final String ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()";
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see
|
||||
*/
|
||||
public static String encodeURI(String str)
|
||||
throws UnsupportedEncodingException {
|
||||
String isoStr = new String(str.getBytes("UTF8"), "ISO-8859-1");
|
||||
char[] chars = isoStr.toCharArray();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if ((chars[i] <= 'z' && chars[i] >= 'a') || (chars[i] <= 'Z' && chars[i] >= 'A')
|
||||
|| chars[i] == '-' || chars[i] == '_' || chars[i] == '.' || chars[i] == '!'
|
||||
|| chars[i] == '~' || chars[i] == '*' || chars[i] == '\'' || chars[i] == '('
|
||||
|| chars[i] == ')' || chars[i] == ';' || chars[i] == '/' || chars[i] == '?'
|
||||
|| chars[i] == ':' || chars[i] == '@' || chars[i] == '&' || chars[i] == '='
|
||||
|| chars[i] == '+' || chars[i] == '$' || chars[i] == ',' || chars[i] == '#'
|
||||
|| (chars[i] <= '9' && chars[i] >= '0')) {
|
||||
sb.append(chars[i]);
|
||||
} else {
|
||||
sb.append("%");
|
||||
sb.append(Integer.toHexString(chars[i]));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
* @see
|
||||
*/
|
||||
public static String encodeURIComponent(String input) {
|
||||
if (null == input || "".equals(input.trim())) {
|
||||
return input;
|
||||
}
|
||||
|
||||
int l = input.length();
|
||||
StringBuilder o = new StringBuilder(l * 3);
|
||||
try {
|
||||
for (int i = 0; i < l; i++) {
|
||||
String e = input.substring(i, i + 1);
|
||||
if (ALLOWED_CHARS.indexOf(e) == -1) {
|
||||
byte[] b = e.getBytes("utf-8");
|
||||
o.append(getHex(b));
|
||||
continue;
|
||||
}
|
||||
o.append(e);
|
||||
}
|
||||
return o.toString();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
private static String getHex(byte buf[]) {
|
||||
StringBuilder o = new StringBuilder(buf.length * 3);
|
||||
for (int i = 0; i < buf.length; i++) {
|
||||
int n = (int) buf[i] & 0xff;
|
||||
o.append("%");
|
||||
if (n < 0x10) {
|
||||
o.append("0");
|
||||
}
|
||||
o.append(Long.toString(n, 16).toUpperCase());
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import com.heyu.api.data.annotation.EbAuthentication;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.R;
|
||||
import com.heyu.api.data.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -42,6 +43,17 @@ public class GeneralBasicOcrController extends BaseController {
|
||||
public R recognize(GeneralBasicOcrRequest generalBasicOcrRequest) throws Exception {
|
||||
|
||||
|
||||
//String base64 = Base64Utils.encodeImageToBase64("/Users/quyixiao/Desktop/ocr/testxxx.jpg");
|
||||
|
||||
//log.info("base64 :{}",base64);
|
||||
|
||||
//String xx = StringUtils.encodeURIComponent(base64);
|
||||
|
||||
//log.info("xx :{}",xx);
|
||||
|
||||
|
||||
|
||||
|
||||
//读取文件内容到Stream流中,按行读取
|
||||
//Stream<String> lines = Files.lines(Paths.get("/Users/quyixiao/gitb/eb-service-api/api-web/api-interface/src/main/resources/filebase64.txt"));
|
||||
|
||||
@ -71,6 +83,24 @@ public class GeneralBasicOcrController extends BaseController {
|
||||
//generalBasicOcrRequest.setImageBase64(null);
|
||||
//generalBasicOcrRequest.setPdfFile("xxxxxx");
|
||||
|
||||
|
||||
if(StringUtils.isNotBlank(generalBasicOcrRequest.getImageBase64())){
|
||||
String imageBase64 = StringUtils.encodeURIComponent(generalBasicOcrRequest.getImageBase64());
|
||||
generalBasicOcrRequest.setImageBase64(imageBase64);
|
||||
}
|
||||
|
||||
|
||||
if(StringUtils.isNotBlank(generalBasicOcrRequest.getPdfFile())){
|
||||
String pdfFile = StringUtils.encodeURIComponent(generalBasicOcrRequest.getPdfFile());
|
||||
generalBasicOcrRequest.setPdfFile(pdfFile);
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(generalBasicOcrRequest.getOfdFile())){
|
||||
String ofdFile = StringUtils.encodeURIComponent(generalBasicOcrRequest.getOfdFile());
|
||||
generalBasicOcrRequest.setOfdFile(ofdFile);
|
||||
}
|
||||
|
||||
|
||||
BGeneralBasicRequest bGeneralBasicRequest = new BGeneralBasicRequest();
|
||||
bGeneralBasicRequest.setImageBase64(generalBasicOcrRequest.getImageBase64());
|
||||
bGeneralBasicRequest.setImageUrl(generalBasicOcrRequest.getImageUrl());
|
||||
|
||||
@ -12,6 +12,7 @@ import com.heyu.api.data.annotation.EbAuthentication;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.R;
|
||||
import com.heyu.api.data.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -48,6 +49,26 @@ public class HighPrecisionOcrController {
|
||||
//generalBasicOcrRequest.setImageUrl("https://heyuoss.oss-cn-shanghai.aliyuncs.com/prd/testxxx.jpg");
|
||||
|
||||
|
||||
if(StringUtils.isNotBlank(generalBasicOcrRequest.getImageBase64())){
|
||||
String imageBase64 = StringUtils.encodeURIComponent(generalBasicOcrRequest.getImageBase64());
|
||||
generalBasicOcrRequest.setImageBase64(imageBase64);
|
||||
}
|
||||
|
||||
|
||||
if(StringUtils.isNotBlank(generalBasicOcrRequest.getPdfFile())){
|
||||
String pdfFile = StringUtils.encodeURIComponent(generalBasicOcrRequest.getPdfFile());
|
||||
generalBasicOcrRequest.setPdfFile(pdfFile);
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(generalBasicOcrRequest.getOfdFile())){
|
||||
String ofdFile = StringUtils.encodeURIComponent(generalBasicOcrRequest.getOfdFile());
|
||||
generalBasicOcrRequest.setOfdFile(ofdFile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BDocAnalysisOfficeRequest bGeneralBasicRequest = new BDocAnalysisOfficeRequest();
|
||||
bGeneralBasicRequest.setImageBase64(generalBasicOcrRequest.getImageBase64());
|
||||
bGeneralBasicRequest.setImageUrl(generalBasicOcrRequest.getImageUrl());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user