Authored by tanling

买家地址不能是鉴定中心

@@ -49,15 +49,10 @@ public class StringSimilarity { @@ -49,15 +49,10 @@ public class StringSimilarity {
49 * 获取两字符串的相似度 49 * 获取两字符串的相似度
50 */ 50 */
51 51
52 - public static float compute(String str, String target) {  
53 - return 1 - (float) compare(str, target) / Math.max(str.length(), target.length()); 52 + public static float getSimilarityRatio(String str, String target) {
  53 + int max = Math.max(str.length(), target.length());
  54 + return 1 - (float) compare(str, target) / max;
54 } 55 }
55 56
56 - public static void main(String[] args) {  
57 - long start=System.currentTimeMillis();  
58 - for (int i=0;i<10000;i++) {  
59 - compute("大大所大萨达所大所多大大所大所多安达市多大声道","大大所大萨达所大所多大大所大所多安达市多大声道");  
60 - }  
61 - System.out.println(System.currentTimeMillis()-start);  
62 - } 57 +
63 } 58 }
@@ -432,6 +432,9 @@ public class ShoppingServiceImpl implements IShoppingService { @@ -432,6 +432,9 @@ public class ShoppingServiceImpl implements IShoppingService {
432 432
433 } 433 }
434 434
  435 + public static final String KEY_AREA_STR = "区";
  436 +
  437 + public static final String[] REPLACE_STR = {"鉴定中心", "UFO"};
435 438
436 /** 439 /**
437 * 查询并校验用户地址(left: 用户地址; right: 脱敏的用户地址) 440 * 查询并校验用户地址(left: 用户地址; right: 脱敏的用户地址)
@@ -456,9 +459,23 @@ public class ShoppingServiceImpl implements IShoppingService { @@ -456,9 +459,23 @@ public class ShoppingServiceImpl implements IShoppingService {
456 459
457 // 检查地址是否是鉴定中心的地址 460 // 检查地址是否是鉴定中心的地址
458 List<AppraiseAddressResp> appraiseAddressRespList = appraiseAddressService.queryAddressInfoList(); 461 List<AppraiseAddressResp> appraiseAddressRespList = appraiseAddressService.queryAddressInfoList();
459 - List<String> appraiseAddressStrList = appraiseAddressRespList.stream().map(AppraiseAddressResp::getAddress).distinct().collect(Collectors.toList()); 462 + List<String> appraiseAddressStrList = appraiseAddressRespList.stream().map(AppraiseAddressResp::getAddress).distinct().map(address->{
  463 + // 为了提高相似字符串的匹配程度,截掉区之前的字符串以及鉴定中心字符串
  464 + String str = address;
  465 + int index = str.indexOf(KEY_AREA_STR);
  466 + if (index != -1){
  467 + str = str.substring(index+1, str.length());
  468 + }
  469 +
  470 + for (String replace : REPLACE_STR){
  471 + str = str.replaceAll(replace, "");
  472 + }
  473 +
  474 + return str;
  475 + }).distinct().collect(Collectors.toList());
460 // 存在和鉴定中心相同的地址 476 // 存在和鉴定中心相同的地址
461 - if (appraiseAddressStrList.stream().filter(x->StringSimilarity.compute(x, addressInfo.getAddress())>0.5).findFirst().isPresent()){ 477 + if (appraiseAddressStrList.stream().filter(x->StringSimilarity.getSimilarityRatio(x, addressInfo.getAddress())>0.5).findFirst().isPresent()
  478 + || addressInfo.getAddress().contains(REPLACE_STR[0])){
462 logger.warn("submit address can not appraiseAddress, uid is {}, address is {}",shoppingRequest.getUid(), addressInfo.getAddress() ); 479 logger.warn("submit address can not appraiseAddress, uid is {}, address is {}",shoppingRequest.getUid(), addressInfo.getAddress() );
463 throw new ServiceException(ServiceError.BUY_ADDRESS_CAN_NOT_APPRAISE_ADDRESS); 480 throw new ServiceException(ServiceError.BUY_ADDRESS_CAN_NOT_APPRAISE_ADDRESS);
464 } 481 }