|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.google.common.base.Splitter;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.req.OrderAddressReq;
|
|
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
...
|
...
|
@@ -10,36 +11,39 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
public class CommomAddressService {
|
|
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
public void checkAddressContent(OrderAddressReq orderAddressReq){
|
|
|
String str_address = orderAddressReq.getAddress();
|
|
|
String str_consignee= orderAddressReq.getConsignee();
|
|
|
String str_mobile = orderAddressReq.getMobile();
|
|
|
if(StringUtils.isBlank(str_address)){
|
|
|
String address = orderAddressReq.getAddress();
|
|
|
if(StringUtils.isBlank(address)){
|
|
|
logger.warn("checkAddressContent address empty, req {}", orderAddressReq);
|
|
|
throw new ServiceException(400,"参数错误,地址不能为空");
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isBlank(str_consignee)){
|
|
|
String consignee = orderAddressReq.getConsignee();
|
|
|
if(StringUtils.isBlank(consignee)){
|
|
|
logger.warn("checkAddressContent consignee empty,req {} ", orderAddressReq);
|
|
|
throw new ServiceException(400,"参数错误,收货人不能为空");
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isBlank(str_mobile)){
|
|
|
String mobile = orderAddressReq.getMobile();
|
|
|
if(StringUtils.isBlank(mobile)){
|
|
|
logger.warn("checkAddressContent mobile empty,req {} ", orderAddressReq);
|
|
|
throw new ServiceException(400,"参数错误,手机号不能为空");
|
|
|
}
|
|
|
|
|
|
str_mobile = str_mobile.trim();
|
|
|
if(!UserInfoHiddenHelper.isPhone(str_mobile)){
|
|
|
mobile = mobile.trim();
|
|
|
if(!UserInfoHiddenHelper.isPhone(mobile)){
|
|
|
logger.warn("checkAddressContent mobile not correct, req {}", orderAddressReq);
|
|
|
throw new ServiceException(400,"参数错误,手机号不合法");
|
|
|
}
|
|
|
|
|
|
orderAddressReq.setMobile(str_mobile);
|
|
|
orderAddressReq.setMobile(mobile);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -54,41 +58,65 @@ public class CommomAddressService { |
|
|
return addressInfo;
|
|
|
}
|
|
|
|
|
|
|
|
|
static boolean isSameProvince(String sourceArea, String area){
|
|
|
final String separator = " ";
|
|
|
List<String> changedUnionAreas = Splitter.on(separator).splitToList(area);
|
|
|
List<String> sourceUnionAreas = Splitter.on(separator).splitToList(sourceArea);
|
|
|
return changedUnionAreas.get(0).equals(sourceUnionAreas.get(0));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 把变的信息项更新
|
|
|
*/
|
|
|
public boolean convertAddressInfoFrontRequest(int uid,
|
|
|
long orderCode,
|
|
|
boolean fromPlatform,
|
|
|
AddressInfo dbAddressInfo,
|
|
|
AddressInfo dbAddressInfo_hidden,
|
|
|
AddressInfo hiddenAddressInDB,
|
|
|
AddressInfo changedAddress){
|
|
|
|
|
|
chkSelfChangeTimes(fromPlatform, dbAddressInfo.getSelfModifyTimes());
|
|
|
boolean changed = false;
|
|
|
String area;
|
|
|
//控制省级不能修改
|
|
|
//极端情况 dbAddressInfo 没有area时,使用现在的数据作为补充
|
|
|
if(StringUtils.isNotBlank(dbAddressInfo.getArea())
|
|
|
&& StringUtils.isNotBlank(area=changedAddress.getArea())
|
|
|
&& !StringUtils.equals(area=area.trim(),dbAddressInfo.getArea())){
|
|
|
if (!isSameProvince(dbAddressInfo.getArea(), area)){
|
|
|
logger.warn("in convertAddressInfoFrontRequest province changed ");
|
|
|
throw new UfoServiceException(400, "不允许修改省份");
|
|
|
}
|
|
|
}
|
|
|
//前提条件:没有修改的信息 依旧使用了包含隐藏位的数据
|
|
|
//所以才有一开始的校验:使用隐藏的地址和请求体比对
|
|
|
//详细地址没有变化
|
|
|
if(StringUtils.equals(dbAddressInfo_hidden.getAddress(),changedAddress.getAddress())){
|
|
|
if(StringUtils.equals(hiddenAddressInDB.getAddress(),changedAddress.getAddress())){
|
|
|
changedAddress.setAddress(dbAddressInfo.getAddress());
|
|
|
}else{
|
|
|
if(changedAddress.getAddress().contains("*")){
|
|
|
logger.warn("dbAddressInfo_hidden is null ,uid {} ,orderCode {} , invalid address with * {}",uid,orderCode,changedAddress.getAddress());
|
|
|
logger.warn("hiddenAddressInDB is null ,uid {} ,orderCode {} , invalid address with * {}",uid,orderCode,changedAddress.getAddress());
|
|
|
throw new UfoServiceException(400,"详细地址不支持特殊符号");
|
|
|
}
|
|
|
changed = true;
|
|
|
}
|
|
|
//收货人没有变化
|
|
|
if(StringUtils.equals(dbAddressInfo_hidden.getConsignee(),changedAddress.getConsignee())){
|
|
|
if(StringUtils.equals(hiddenAddressInDB.getConsignee(), changedAddress.getConsignee())){
|
|
|
changedAddress.setConsignee(dbAddressInfo.getConsignee());
|
|
|
}else{
|
|
|
if(changedAddress.getConsignee().contains("*")){
|
|
|
logger.warn("dbAddressInfo_hidden is null ,uid {} ,orderCode {} , invalid consignee with * {}",uid,orderCode,changedAddress.getConsignee());
|
|
|
logger.warn("hiddenAddressInDB is null ,uid {} ,orderCode {} , invalid consignee with * {}",uid,orderCode,changedAddress.getConsignee());
|
|
|
throw new UfoServiceException(400,"收货人不支持特殊符号");
|
|
|
}
|
|
|
changed = true;
|
|
|
}
|
|
|
//手机号没有变化
|
|
|
if(StringUtils.equals(dbAddressInfo_hidden.getMobile(),changedAddress.getMobile())){
|
|
|
if(StringUtils.equals(hiddenAddressInDB.getMobile(),changedAddress.getMobile())){
|
|
|
changedAddress.setMobile(dbAddressInfo.getMobile());
|
|
|
}else{
|
|
|
if(!UserInfoHiddenHelper.isPhone(changedAddress.getMobile())){
|
|
|
logger.warn("dbAddressInfo_hidden is null ,uid {} ,orderCode {} , invalid mobile {}",uid,orderCode,changedAddress.getMobile());
|
|
|
logger.warn("hiddenAddressInDB is null ,uid {} ,orderCode {} , invalid mobile {}",uid,orderCode,changedAddress.getMobile());
|
|
|
throw new UfoServiceException(400,"请填写正确的手机号码");
|
|
|
}
|
|
|
changed = true;
|
...
|
...
|
@@ -106,11 +134,7 @@ public class CommomAddressService { |
|
|
changed = true;
|
|
|
dbAddressInfo.setAreaCode(changedAddress.getAreaCode());
|
|
|
}
|
|
|
String area;
|
|
|
if(!StringUtils.equals(area=changedAddress.getArea(),dbAddressInfo.getArea())){
|
|
|
changed = true;
|
|
|
dbAddressInfo.setArea(area);
|
|
|
}
|
|
|
|
|
|
if(!StringUtils.equals(changedAddress.getMobile(),dbAddressInfo.getMobile())){
|
|
|
changed = true;
|
|
|
dbAddressInfo.setMobile(changedAddress.getMobile());
|
...
|
...
|
@@ -130,4 +154,12 @@ public class CommomAddressService { |
|
|
}
|
|
|
return changed;
|
|
|
}
|
|
|
|
|
|
|
|
|
public void chkSelfChangeTimes(boolean fromPlatform, Integer times){
|
|
|
boolean isSelfChange = !fromPlatform;
|
|
|
if (isSelfChange && Objects.nonNull(times) && times > 0){
|
|
|
throw new UfoServiceException(400, "地址只能修改一次");
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|