Authored by tanling

买家地址不能是鉴定中心

... ... @@ -49,15 +49,10 @@ public class StringSimilarity {
* 获取两字符串的相似度
*/
public static float compute(String str, String target) {
return 1 - (float) compare(str, target) / Math.max(str.length(), target.length());
public static float getSimilarityRatio(String str, String target) {
int max = Math.max(str.length(), target.length());
return 1 - (float) compare(str, target) / max;
}
public static void main(String[] args) {
long start=System.currentTimeMillis();
for (int i=0;i<10000;i++) {
compute("大大所大萨达所大所多大大所大所多安达市多大声道","大大所大萨达所大所多大大所大所多安达市多大声道");
}
System.out.println(System.currentTimeMillis()-start);
}
}
... ...
... ... @@ -432,6 +432,9 @@ public class ShoppingServiceImpl implements IShoppingService {
}
public static final String KEY_AREA_STR = "区";
public static final String[] REPLACE_STR = {"鉴定中心", "UFO"};
/**
* 查询并校验用户地址(left: 用户地址; right: 脱敏的用户地址)
... ... @@ -456,9 +459,23 @@ public class ShoppingServiceImpl implements IShoppingService {
// 检查地址是否是鉴定中心的地址
List<AppraiseAddressResp> appraiseAddressRespList = appraiseAddressService.queryAddressInfoList();
List<String> appraiseAddressStrList = appraiseAddressRespList.stream().map(AppraiseAddressResp::getAddress).distinct().collect(Collectors.toList());
List<String> appraiseAddressStrList = appraiseAddressRespList.stream().map(AppraiseAddressResp::getAddress).distinct().map(address->{
// 为了提高相似字符串的匹配程度,截掉区之前的字符串以及鉴定中心字符串
String str = address;
int index = str.indexOf(KEY_AREA_STR);
if (index != -1){
str = str.substring(index+1, str.length());
}
for (String replace : REPLACE_STR){
str = str.replaceAll(replace, "");
}
return str;
}).distinct().collect(Collectors.toList());
// 存在和鉴定中心相同的地址
if (appraiseAddressStrList.stream().filter(x->StringSimilarity.compute(x, addressInfo.getAddress())>0.5).findFirst().isPresent()){
if (appraiseAddressStrList.stream().filter(x->StringSimilarity.getSimilarityRatio(x, addressInfo.getAddress())>0.5).findFirst().isPresent()
|| addressInfo.getAddress().contains(REPLACE_STR[0])){
logger.warn("submit address can not appraiseAddress, uid is {}, address is {}",shoppingRequest.getUid(), addressInfo.getAddress() );
throw new ServiceException(ServiceError.BUY_ADDRESS_CAN_NOT_APPRAISE_ADDRESS);
}
... ...