Commit b63d2a01cea96437fa56a0b539778c2ae7fd6390
Exists in
master
.
Showing
6 changed files
with
130 additions
and
47 deletions
 
Show diff stats
build.gradle
gradle.properties
| 1 | 1 | #Maven Repo URL | 
| 2 | -MAVEN_REPO_RELEASE_URL=http://47.93.122.69:9001/repository/maven-releases/ | |
| 3 | -MAVEN_REPO_SNAPSHOT_URL=http://47.93.122.69:9001/repository/maven-snapshots/ | |
| 2 | +MAVEN_REPO_RELEASE_URL=http://nexus.taover.com:9001/repository/maven-releases/ | |
| 3 | +MAVEN_REPO_SNAPSHOT_URL=http://nexus.taover.com:9001/repository/maven-snapshots/ | |
| 4 | 4 | |
| 5 | 5 | #maven GroupId | 
| 6 | 6 | GROUP=com.taover | ... | ... | 
src/main/java/com/taover/util/UtilExcel.java
| ... | ... | @@ -10,7 +10,6 @@ import java.util.HashMap; | 
| 10 | 10 | import java.util.List; | 
| 11 | 11 | import java.util.Map; | 
| 12 | 12 | |
| 13 | -import org.apache.poi.hssf.usermodel.HSSFCell; | |
| 14 | 13 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | 
| 15 | 14 | import org.apache.poi.hssf.util.HSSFColor; | 
| 16 | 15 | import org.apache.poi.ss.usermodel.Cell; | 
| ... | ... | @@ -290,20 +289,21 @@ public class UtilExcel { | 
| 290 | 289 | for(int j=0; j<lastCellNum; ++j){ | 
| 291 | 290 | Cell cell = row.getCell(j); | 
| 292 | 291 | if(cell != null){ | 
| 293 | - if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING){ | |
| 294 | - dataRow.add(cell.getStringCellValue()); | |
| 295 | - }else if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){ | |
| 292 | + CellType currCellType = cell.getCellTypeEnum(); | |
| 293 | + | |
| 294 | + if(currCellType.compareTo(CellType.STRING) == 0){ | |
| 295 | + dataRow.add(UtilString.trimCodePage(cell.getRichStringCellValue().getString())); | |
| 296 | + }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ | |
| 296 | 297 | dataRow.add(df.format(cell.getNumericCellValue())); | 
| 297 | - }else if(cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN){ | |
| 298 | - dataRow.add(Boolean.valueOf(cell.getBooleanCellValue())); | |
| 299 | - }else if(cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA){ | |
| 300 | - dataRow.add(""+cell.getCellFormula()); | |
| 301 | - //dataRow.add(cell.getNumericCellValue()); | |
| 302 | - }else if(cell.getCellType() == HSSFCell.CELL_TYPE_ERROR){ | |
| 303 | - dataRow.add(""+cell.getErrorCellValue()); | |
| 304 | - }else{ | |
| 305 | - dataRow.add(cell.getStringCellValue()); | |
| 306 | - } | |
| 298 | + | |
| 299 | + }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ | |
| 300 | + dataRow.add(cell.getBooleanCellValue()); | |
| 301 | + }else if(currCellType.compareTo(CellType.FORMULA) == 0 | |
| 302 | + || currCellType.compareTo(CellType.BLANK) == 0 | |
| 303 | + || currCellType.compareTo(CellType.ERROR) == 0){ | |
| 304 | + dataRow.add(""); | |
| 305 | + } | |
| 306 | + | |
| 307 | 307 | }else{ | 
| 308 | 308 | dataRow.add(""); | 
| 309 | 309 | } | ... | ... | 
src/main/java/com/taover/util/UtilHttpByOkHttp.java
| ... | ... | @@ -34,72 +34,106 @@ public class UtilHttpByOkHttp { | 
| 34 | 34 | public static final String METHOD_POST = "POST"; | 
| 35 | 35 | public static final String METHOD_DELETE = "DELETE"; | 
| 36 | 36 | public static final String METHOD_PUT = "PUT"; | 
| 37 | + | |
| 38 | + public static String sendGet(String url, final Map<String, String> headers) throws Exception { | |
| 39 | + return sendGet(url, headers, 60); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public static String sendPostForm(String url, final Map<String, String> headers, final Map<String, Object> params) throws Exception { | |
| 43 | + return sendPostForm(url, headers, params, 60); | |
| 44 | + } | |
| 45 | + | |
| 46 | + public static String sendPutForm(String url, final Map<String, String> headers, final Map<String, Object> params) throws Exception { | |
| 47 | + return sendPutForm(url, headers, params, 60); | |
| 48 | + } | |
| 49 | + | |
| 50 | + public static String sendPostString(String url, final Map<String, String> headers, final String content) throws Exception{ | |
| 51 | + return sendPostString(url, headers, content, 60); | |
| 52 | + } | |
| 53 | + | |
| 54 | + public static String sendPostJson(String url, final Map<String, String> headers, String jsonStr) throws Exception{ | |
| 55 | + return sendPostJson(url, headers, jsonStr, 60); | |
| 56 | + } | |
| 37 | 57 | |
| 38 | - public static String sendGet(String url, final Map<String, String> headers) throws Exception { | |
| 58 | + public static String sendDelete(String url, final Map<String, String> headers) throws Exception { | |
| 59 | + return sendDelete(url, headers, 60); | |
| 60 | + } | |
| 61 | + | |
| 62 | + public static byte[] downloadFile(String url, final Map<String, String> headers) throws Exception{ | |
| 63 | + return downloadFile(url, headers, 60); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public static String sendGet(String url, final Map<String, String> headers, int timeoutInSecond) throws Exception { | |
| 39 | 67 | //http头信息拼装 | 
| 40 | 68 | Request request = getRequestBuilder(url, headers).get().build(); | 
| 41 | 69 | |
| 42 | - return getHttpClient(url).newCall(request).execute().body().string(); | |
| 70 | + return getHttpClient(url, timeoutInSecond).newCall(request).execute().body().string(); | |
| 43 | 71 | } | 
| 44 | 72 | |
| 45 | - public static String sendPostForm(String url, final Map<String, String> headers, final Map<String, Object> params) throws Exception { | |
| 73 | + public static String sendPostForm(String url, final Map<String, String> headers, final Map<String, Object> params, int timeoutInSecond) throws Exception { | |
| 46 | 74 | //请求体信息 | 
| 47 | 75 | RequestBody requestBody = getReqeustBody(params); | 
| 48 | 76 | |
| 49 | 77 | //http头信息拼装 | 
| 50 | 78 | Request request = getRequestBuilder(url, headers).post(requestBody).build(); | 
| 51 | 79 | |
| 52 | - return getHttpClient(url).newCall(request).execute().body().string(); | |
| 80 | + return getHttpClient(url, timeoutInSecond).newCall(request).execute().body().string(); | |
| 53 | 81 | } | 
| 54 | 82 | |
| 55 | - public static String sendPutForm(String url, final Map<String, String> headers, final Map<String, Object> params) throws Exception { | |
| 83 | + public static String sendPutForm(String url, final Map<String, String> headers, final Map<String, Object> params, int timeoutInSecond) throws Exception { | |
| 56 | 84 | //请求体信息 | 
| 57 | 85 | RequestBody requestBody = getReqeustBody(params); | 
| 58 | 86 | |
| 59 | 87 | //http头信息拼装 | 
| 60 | 88 | Request request = getRequestBuilder(url, headers).put(requestBody).build(); | 
| 61 | 89 | |
| 62 | - return getHttpClient(url).newCall(request).execute().body().string(); | |
| 90 | + return getHttpClient(url, timeoutInSecond).newCall(request).execute().body().string(); | |
| 63 | 91 | } | 
| 64 | 92 | |
| 65 | - public static String sendPostString(String url, final Map<String, String> headers, final String content) throws Exception{ | |
| 93 | + public static String sendPostString(String url, final Map<String, String> headers, final String content, int timeoutInSecond) throws Exception{ | |
| 66 | 94 | //请求体 | 
| 67 | - RequestBody requestBody = getReqeustBody(content); | |
| 95 | + RequestBody requestBody = getReqeustBodyTextPlain(content); | |
| 68 | 96 | |
| 69 | 97 | //http头信息拼装 | 
| 70 | 98 | Request request = getRequestBuilder(url, headers).post(requestBody).build(); | 
| 71 | 99 | |
| 72 | - return getHttpClient(url).newCall(request).execute().body().string(); | |
| 100 | + return getHttpClient(url, timeoutInSecond).newCall(request).execute().body().string(); | |
| 73 | 101 | } | 
| 74 | 102 | |
| 75 | - public static String sendPostJson(String url, final Map<String, String> headers, String jsonStr) throws Exception{ | |
| 103 | + public static String sendPostJson(String url, final Map<String, String> headers, String jsonStr, int timeoutInSecond) throws Exception{ | |
| 76 | 104 | //请求体 | 
| 77 | - RequestBody requestBody = getReqeustBodyJson(jsonStr); | |
| 105 | + RequestBody requestBody = getReqeustBodyApplicationJson(jsonStr); | |
| 78 | 106 | |
| 79 | 107 | //http头信息拼装 | 
| 80 | 108 | Request request = getRequestBuilder(url, headers).post(requestBody).build(); | 
| 81 | 109 | |
| 82 | - return getHttpClient(url).newCall(request).execute().body().string(); | |
| 110 | + return getHttpClient(url, timeoutInSecond).newCall(request).execute().body().string(); | |
| 83 | 111 | } | 
| 84 | 112 | |
| 85 | - public static String sendDelete(String url, final Map<String, String> headers) throws Exception { | |
| 113 | + public static String sendDelete(String url, final Map<String, String> headers, int timeoutInSecond) throws Exception { | |
| 86 | 114 | //http头信息拼装 | 
| 87 | 115 | Request request = getRequestBuilder(url, headers).delete().build(); | 
| 88 | 116 | |
| 89 | - return getHttpClient(url).newCall(request).execute().body().string(); | |
| 117 | + return getHttpClient(url, timeoutInSecond).newCall(request).execute().body().string(); | |
| 90 | 118 | } | 
| 91 | 119 | |
| 92 | - public static byte[] downloadFile(String url, final Map<String, String> headers) throws Exception{ | |
| 120 | + public static byte[] downloadFile(String url, final Map<String, String> headers, int timeoutInSecond) throws Exception{ | |
| 93 | 121 | Request request = getRequestBuilder(url, headers).get().build(); | 
| 94 | 122 | |
| 95 | - return getHttpClient(url).newCall(request).execute().body().bytes(); | |
| 123 | + return getHttpClient(url, timeoutInSecond).newCall(request).execute().body().bytes(); | |
| 96 | 124 | } | 
| 97 | 125 | |
| 98 | - public static OkHttpClient getHttpClient(String url){ | |
| 126 | + | |
| 127 | + public static OkHttpClient getHttpClient(String url, int timeoutInSecond){ | |
| 99 | 128 | if(url.trim().toLowerCase().startsWith("https")){ | 
| 100 | - return buildOkHttpClientForHttps(); | |
| 129 | + return buildOkHttpClientForHttps(timeoutInSecond); | |
| 101 | 130 | }else{ | 
| 102 | - return new OkHttpClient(); | |
| 131 | + OkHttpClient.Builder builder = new OkHttpClient.Builder(); | |
| 132 | + builder.connectTimeout(timeoutInSecond, TimeUnit.SECONDS) | |
| 133 | + .readTimeout(timeoutInSecond, TimeUnit.SECONDS) | |
| 134 | + .writeTimeout(timeoutInSecond,TimeUnit.SECONDS) | |
| 135 | + .retryOnConnectionFailure(true); | |
| 136 | + return builder.build(); | |
| 103 | 137 | } | 
| 104 | 138 | } | 
| 105 | 139 | |
| ... | ... | @@ -114,7 +148,7 @@ public class UtilHttpByOkHttp { | 
| 114 | 148 | */ | 
| 115 | 149 | public static String sendPostJson(OkHttpClient okHttpClient,String url, final Map<String, String> headers, String jsonStr) throws Exception{ | 
| 116 | 150 | //请求体 | 
| 117 | - RequestBody requestBody = getReqeustBodyJson(jsonStr); | |
| 151 | + RequestBody requestBody = getReqeustBodyApplicationJson(jsonStr); | |
| 118 | 152 | |
| 119 | 153 | //http头信息拼装 | 
| 120 | 154 | Request request = getRequestBuilder(url, headers).post(requestBody).build(); | 
| ... | ... | @@ -141,11 +175,11 @@ public class UtilHttpByOkHttp { | 
| 141 | 175 | return builder.build(); | 
| 142 | 176 | } | 
| 143 | 177 | |
| 144 | - private static RequestBody getReqeustBody(String content){ | |
| 178 | + private static RequestBody getReqeustBodyTextPlain(String content){ | |
| 145 | 179 | return RequestBody.create(MediaType.parse("text/plain;charse=utf-8"), content); | 
| 146 | 180 | } | 
| 147 | 181 | |
| 148 | - private static RequestBody getReqeustBodyJson(String jsonStr){ | |
| 182 | + private static RequestBody getReqeustBodyApplicationJson(String jsonStr){ | |
| 149 | 183 | return RequestBody.create(MediaType.parse("application/json;charse=utf-8"), jsonStr); | 
| 150 | 184 | } | 
| 151 | 185 | |
| ... | ... | @@ -160,11 +194,11 @@ public class UtilHttpByOkHttp { | 
| 160 | 194 | return requestBuilder; | 
| 161 | 195 | } | 
| 162 | 196 | |
| 163 | - private static OkHttpClient buildOkHttpClientForHttps() { | |
| 197 | + private static OkHttpClient buildOkHttpClientForHttps(int timeoutInSecond) { | |
| 164 | 198 | OkHttpClient.Builder builder = new OkHttpClient.Builder(); | 
| 165 | - builder.connectTimeout(30, TimeUnit.SECONDS) | |
| 166 | - .readTimeout(30, TimeUnit.SECONDS) | |
| 167 | - .writeTimeout(30,TimeUnit.SECONDS) | |
| 199 | + builder.connectTimeout(timeoutInSecond, TimeUnit.SECONDS) | |
| 200 | + .readTimeout(timeoutInSecond, TimeUnit.SECONDS) | |
| 201 | + .writeTimeout(timeoutInSecond,TimeUnit.SECONDS) | |
| 168 | 202 | .retryOnConnectionFailure(true) | 
| 169 | 203 | .sslSocketFactory(getTrustedSSLSocketFactory()) | 
| 170 | 204 | .hostnameVerifier(DO_NOT_VERIFY); | 
| ... | ... | @@ -281,7 +315,8 @@ public class UtilHttpByOkHttp { | 
| 281 | 315 | |
| 282 | 316 | try { | 
| 283 | 317 | //System.out.println(UtilHttpByOkHttp.sendPostForm(url, headerData, paramData)); | 
| 284 | - System.out.println(UtilHttpByOkHttp.sendGet("https://ssep.umsapi.com/api/v2/openapi/querycontacts?appid=songshuyun-ifun×tamp=1562239191&signature=967fd77a24cbbce872bc1506a0187983", null)); | |
| 318 | + System.out.println( | |
| 319 | + UtilHttpByOkHttp.sendGet("http://localhost/login/checkLogin.htm?appid=songshuyun-ifun×tamp=1562239191&signature=967fd77a24cbbce872bc1506a0187983", null, 0)); | |
| 285 | 320 | } catch (Exception e) { | 
| 286 | 321 | // TODO Auto-generated catch block | 
| 287 | 322 | e.printStackTrace(); | ... | ... | 
src/main/java/com/taover/util/UtilHttpRequestMap.java
| ... | ... | @@ -109,6 +109,9 @@ public class UtilHttpRequestMap { | 
| 109 | 109 | } | 
| 110 | 110 | String colName = UtilString.underscoreName(keyName).toLowerCase(); | 
| 111 | 111 | if(data.length == 1){ | 
| 112 | + if(data[0] == null || "".equals(data[0].trim())){ | |
| 113 | + throw new Exception("data[0] is empty"); | |
| 114 | + } | |
| 112 | 115 | String typeName = camelField.getType().getSimpleName(); | 
| 113 | 116 | if(typeName.equals("String")){ | 
| 114 | 117 | return new Object[]{colName, "like", "%"+data[0]+"%"}; | ... | ... | 
src/main/java/com/taover/util/UtilString.java
| ... | ... | @@ -4,8 +4,46 @@ import java.text.SimpleDateFormat; | 
| 4 | 4 | import java.util.ArrayList; | 
| 5 | 5 | import java.util.Date; | 
| 6 | 6 | import java.util.List; | 
| 7 | +import java.util.regex.Matcher; | |
| 8 | +import java.util.regex.Pattern; | |
| 7 | 9 | |
| 8 | 10 | public class UtilString { | 
| 11 | + public static String trimByRegexW(String pattern){ | |
| 12 | + Matcher m = Pattern.compile("\\w+").matcher(pattern); | |
| 13 | + String result = ""; | |
| 14 | + while(m.find()){ | |
| 15 | + String currGroup = m.group(); | |
| 16 | + result += currGroup; | |
| 17 | + } | |
| 18 | + return result; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public static String trimLeftByRegexW(String pattern){ | |
| 22 | + String tempPattern = new String(pattern); | |
| 23 | + Pattern p = Pattern.compile("\\w+"); | |
| 24 | + for(int i=0; i<tempPattern.length(); ++i){ | |
| 25 | + if(p.matcher(tempPattern.charAt(i)+"").matches()){ | |
| 26 | + return tempPattern.substring(i); | |
| 27 | + } | |
| 28 | + } | |
| 29 | + return ""; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public static String trimRightByRegexW(String pattern){ | |
| 33 | + String tempPattern = new String(pattern); | |
| 34 | + Pattern p = Pattern.compile("\\w+"); | |
| 35 | + for(int i=tempPattern.length()-1; i>=0; --i){ | |
| 36 | + if(p.matcher(tempPattern.charAt(i)+"").matches()){ | |
| 37 | + return tempPattern.substring(0, i+1); | |
| 38 | + } | |
| 39 | + } | |
| 40 | + return ""; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public static String trimCodePage(String data){ | |
| 44 | + return data.replaceAll(new String(new byte[]{-30, -128, -83}), ""); | |
| 45 | + } | |
| 46 | + | |
| 9 | 47 | /** | 
| 10 | 48 | * 在compares字符数组查找pattern字符串,找到则返回字串在数组中的索引,未找到返回-1 | 
| 11 | 49 | * @param pattern | 
| ... | ... | @@ -171,10 +209,17 @@ public class UtilString { | 
| 171 | 209 | // System.out.println(getBeanNameFormTableName("asdf_asdf")); | 
| 172 | 210 | // System.out.println(System.currentTimeMillis()); | 
| 173 | 211 | // System.out.println(getCodeWithPreffix(1231212, 10, '-')); | 
| 174 | - String dd = "\"{\"success\":true,\"code\":1,\"printedorder_id\":\"1654\",\"error_message\":\"\"}\""; | |
| 175 | - dd = dd.substring(1, dd.length()-1); | |
| 176 | - System.out.println(dd); | |
| 212 | +// String dd = "\"{\"success\":true,\"code\":1,\"printedorder_id\":\"1654\",\"error_message\":\"\"}\""; | |
| 213 | +// dd = dd.substring(1, dd.length()-1); | |
| 214 | +// System.out.println(dd); | |
| 177 | 215 | //JSONObject temp = JSONObject.fromObject(dd); | 
| 178 | 216 | //System.out.println(temp.getInt("code")); | 
| 217 | + | |
| 218 | + String trim = " sd ds sd "; | |
| 219 | + String trimLeft = " ds sd "; | |
| 220 | + String trimRight = " ds es &**^"; | |
| 221 | + System.out.println(trimByRegexW(trim)); | |
| 222 | + System.out.println(trimLeftByRegexW(trimLeft)); | |
| 223 | + System.out.println(trimRightByRegexW(trimRight)); | |
| 179 | 224 | } | 
| 180 | 225 | } | 
| 181 | 226 | \ No newline at end of file | ... | ... |