Authored by chenchao

add limit check when change address

... ... @@ -10,6 +10,7 @@ import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.NonNull;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
... ... @@ -34,13 +35,14 @@ public class BuyerOrderMeta4PlatformController {
@RequestMapping(value="/updateDeliveryAddress")
@IgnoreSession
@IgnoreSignature
public ApiResponse updateDeliveryAddress(@RequestBody BuyerOrderMetaUpdateReq req) {
public ApiResponse updateDeliveryAddress(@NonNull @RequestBody BuyerOrderMetaUpdateReq req) {
logger.info("enter BuyerOrderMeta4PlatformController updateDeliveryAddress param req is {}", req);
int code = 200;
String message = "更新地址成功";
String result = buyerOrderMetaService.updateDeliveryAddressByErp(req);
String result = null;
try{
req.setFromPlatform(true);
result = buyerOrderMetaService.updateDeliveryAddressByErp(req);
}catch (Exception ex){
if (ex instanceof UfoServiceException){
code = ((UfoServiceException) ex).getCode();
... ...
... ... @@ -16,6 +16,7 @@ import com.yohoufo.order.service.impl.visitor.AuditCancelCase;
import com.yohoufo.order.service.seller.ImportPublishExcutor;
import com.yohoufo.order.service.seller.orderMeta.SellerAddressService;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.NonNull;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
... ... @@ -86,11 +87,15 @@ public class ErpSellerGoodsController {
@RequestMapping(value="/updateSellerDeliveryAddress")
@IgnoreSession
@IgnoreSignature
public ApiResponse updateSellerDeliveryAddress(@RequestBody OrderAddressReq req){
public ApiResponse updateSellerDeliveryAddress(@NonNull @RequestBody OrderAddressReq req){
logger.info("updateSellerDeliveryAddress req {}", req);
ApiResponse.ApiResponseBuilder response = new ApiResponse.ApiResponseBuilder();
try{
int rows = sellerAddressService.updateSellerDeliveryAddressByBuyerOrderCode(req, true);
req.setFromPlatform(true);
int rows = sellerAddressService.updateSellerDeliveryAddressByBuyerOrderCode(req);
if (rows>0){
response.code(200).message("update Seller Delivery Address success");
}else {
... ...
... ... @@ -599,9 +599,12 @@ public class SellerOrderController {
@RequestParam(name="mobile")String mobile
){
OrderAddressReq req = OrderAddressReq.builder().uid(uid).orderCode(orderCode).consignee(consignee)
.area(area).address(address).mobile(mobile).build();
.area(area).address(address)
.mobile(mobile)
.fromPlatform(false)
.build();
logger.info("ufo.sellerOrder.modifyDeliverAddress enter,req {}", req);
sellerAddressService.updateSellerDeliveryAddressByBuyerOrderCode(req, false);
sellerAddressService.updateSellerDeliveryAddressByBuyerOrderCode(req);
return new ApiResponse.ApiResponseBuilder().code(200).message("modify deliver address successfully").build();
}
... ...
... ... @@ -67,6 +67,7 @@ public class AddressInfoConvertor {
noHiddenAddress.setMobile(req.getMobile());
noHiddenAddress.setConsignee(req.getConsignee());
noHiddenAddress.setAddress(req.getAddress());
noHiddenAddress.setSelfModifyTimes(calSelfModifyTimes(req.isFromPlatform()));
}
... ... @@ -75,5 +76,10 @@ public class AddressInfoConvertor {
hiddenAddress.setMobile(hiddenAddressTemp.getMobile());
hiddenAddress.setConsignee(hiddenAddressTemp.getConsignee());
hiddenAddress.setAddress(hiddenAddressTemp.getAddress());
hiddenAddress.setSelfModifyTimes(calSelfModifyTimes(req.isFromPlatform()));
}
private static Integer calSelfModifyTimes(boolean isFromPlatform){
return isFromPlatform ? null : 1;
}
}
... ...
... ... @@ -54,6 +54,7 @@ public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService {
.address(str_address)
.consignee(str_consignee)
.mobile(str_mobile)
.fromPlatform(req.isFromPlatform())
.build();
commomAddressService.checkAddressContent(orderAddressReq);
... ...
... ... @@ -208,8 +208,9 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
*/
@Override
public boolean buyerModifyAddress(int uid, long orderCode,AddressInfo changedAddress){
final boolean fromPlatform = false;
//参数检查和状态检查
PreparedNode preparedNode = paramAndStatusCheck_BuyerModifyAddress(uid,orderCode,changedAddress);
PreparedNode preparedNode = paramAndStatusCheck4BuyerModifyAddress(uid,orderCode,changedAddress);
AddressInfo dbAddressInfo = buyerOrderMetaService.getAddressInfo(uid,orderCode);
if(dbAddressInfo==null){
... ... @@ -217,13 +218,13 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
throw new UfoServiceException(400,"找不到地址信息");
}
AddressInfo dbAddressInfo_hidden = buyerOrderMetaService.getHiddenAddressInfo(uid,orderCode);
if(dbAddressInfo_hidden==null){
logger.warn("dbAddressInfo_hidden is null ,uid {} ,orderCode {}",uid,orderCode);
AddressInfo hiddenAddressInDB = buyerOrderMetaService.getHiddenAddressInfo(uid,orderCode);
if(hiddenAddressInDB==null){
logger.warn("hiddenAddressInDB is null ,uid {} ,orderCode {}",uid,orderCode);
throw new UfoServiceException(400,"找不到地址信息");
}
boolean changed = commomAddressService.convertAddressInfoFrontRequest(uid,orderCode,dbAddressInfo,dbAddressInfo_hidden,changedAddress);
boolean changed = commomAddressService.convertAddressInfoFrontRequest(uid, orderCode, fromPlatform, dbAddressInfo,hiddenAddressInDB,changedAddress);
//至少有一个要更新,否则直接返回
if(!changed){
... ... @@ -253,8 +254,15 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
}
private PreparedNode paramAndStatusCheck_BuyerModifyAddress(int uid, long orderCode,AddressInfo changedAddress){
/**
* 基本参数检查
* 状态校验
* @param uid
* @param orderCode
* @param changedAddress
* @return
*/
private PreparedNode paramAndStatusCheck4BuyerModifyAddress(int uid, long orderCode, AddressInfo changedAddress){
//入参
if(uid <= 0){
throw new UfoServiceException(400,"参数错误:uid错误");
... ...
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, "地址只能修改一次");
}
}
}
... ...
... ... @@ -128,10 +128,10 @@ public class SellerAddressService {
/**
* 更新卖家地址
* @param req
* @param fromPlatform
* @return
*/
public int updateSellerDeliveryAddressByBuyerOrderCode(OrderAddressReq req,boolean fromPlatform){
public int updateSellerDeliveryAddressByBuyerOrderCode(OrderAddressReq req){
boolean fromPlatform = req.isFromPlatform();
Integer uid = req.getUid();
if (uid == null || uid < 0){
logger.warn("updateSellerDeliveryAddressByBuyerOrderCode uid is illegal");
... ... @@ -166,11 +166,12 @@ public class SellerAddressService {
//check change
AddressInfo changedAddress = AddressInfoConvertor.convertChangedAddress(req);
commomAddressService.convertAddressInfoFrontRequest(sellerUid, orderCode, noHiddenAddress, hiddenAddress, changedAddress);
commomAddressService.convertAddressInfoFrontRequest(sellerUid, orderCode, fromPlatform, noHiddenAddress, hiddenAddress, changedAddress);
AddressInfo hiddenAddressTemp = commomAddressService.buildHiddenAddress(req);
//hidden
AddressInfoConvertor.mergeChangedAddress4Hidden(hiddenAddress, req, hiddenAddressTemp);
rows += updateHiddenAddress(skup, hiddenAddress);
//no hidden
AddressInfoConvertor.mergeChangedAddress4NoHidden(noHiddenAddress, req);
... ...