Authored by LUOXC

refactor

  1 +package com.yohoufo.common.utils;
  2 +
  3 +import org.apache.commons.lang3.StringUtils;
  4 +
  5 +public class IntegerUtils {
  6 +
  7 + public static Integer toInteger(String value) {
  8 + return toInteger(value, null);
  9 + }
  10 +
  11 + public static Integer toInteger(String value, Integer defaultValue) {
  12 + if (StringUtils.isBlank(value)) {
  13 + return defaultValue;
  14 + }
  15 + try {
  16 + return Integer.valueOf(value);
  17 + } catch (RuntimeException re) {
  18 + return defaultValue;
  19 + }
  20 + }
  21 +
  22 +}
1 package com.yohoufo.order.controller; 1 package com.yohoufo.order.controller;
2 2
3 -import com.yoho.error.ServiceError;  
4 -import com.yoho.error.exception.ServiceException;  
5 import com.yohobuy.ufo.model.order.common.TabType; 3 import com.yohobuy.ufo.model.order.common.TabType;
6 import com.yohobuy.ufo.model.order.resp.ExpressInfoRespBo; 4 import com.yohobuy.ufo.model.order.resp.ExpressInfoRespBo;
7 import com.yohoufo.common.ApiResponse; 5 import com.yohoufo.common.ApiResponse;
8 import com.yohoufo.common.utils.AppVersion; 6 import com.yohoufo.common.utils.AppVersion;
  7 +import com.yohoufo.common.utils.IntegerUtils;
9 import com.yohoufo.order.model.response.AppraiseAddressResp; 8 import com.yohoufo.order.model.response.AppraiseAddressResp;
10 import com.yohoufo.order.service.IExpressInfoService; 9 import com.yohoufo.order.service.IExpressInfoService;
11 import org.apache.commons.lang3.StringUtils; 10 import org.apache.commons.lang3.StringUtils;
12 -import org.apache.commons.lang3.math.NumberUtils;  
13 import org.slf4j.Logger; 11 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 12 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,7 +48,7 @@ public class ExpressInfoController { @@ -50,7 +48,7 @@ public class ExpressInfoController {
50 @RequestParam(value = "depotNum", required = false) String depotNum, 48 @RequestParam(value = "depotNum", required = false) String depotNum,
51 @RequestParam(value = "app_version") String appVersion) { 49 @RequestParam(value = "app_version") String appVersion) {
52 50
53 - Integer depotNumInt = parseDepotNum(depotNum); 51 + Integer depotNumInt = IntegerUtils.toInteger(depotNum);
54 if (Objects.isNull(depotNumInt)) { 52 if (Objects.isNull(depotNumInt)) {
55 // 大于6.9.3 版本 53 // 大于6.9.3 版本
56 if (AppVersion.of(appVersion).greaterThan(AppVersion.of("6.9.3"))) { 54 if (AppVersion.of(appVersion).greaterThan(AppVersion.of("6.9.3"))) {
@@ -65,16 +63,6 @@ public class ExpressInfoController { @@ -65,16 +63,6 @@ public class ExpressInfoController {
65 return new ApiResponse(); 63 return new ApiResponse();
66 } 64 }
67 65
68 - private Integer parseDepotNum(String depotNum) {  
69 - if (StringUtils.isBlank(depotNum)) {  
70 - return null;  
71 - }  
72 - try {  
73 - return Integer.valueOf(depotNum);  
74 - } catch (RuntimeException re) {  
75 - return null;  
76 - }  
77 - }  
78 66
79 67
80 68