|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.base.Throwables;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.CustomsClearanceResult;
|
|
|
import com.yohobuy.ufo.model.order.common.TabType;
|
|
|
import com.yohobuy.ufo.model.order.req.BuyerOrderMetaUpdateReq;
|
...
|
...
|
@@ -14,6 +16,7 @@ import com.yohoufo.dal.order.model.BuyerOrder; |
|
|
import com.yohoufo.dal.order.model.BuyerOrderMeta;
|
|
|
import com.yohoufo.order.common.ActionStatusHold;
|
|
|
import com.yohoufo.order.constants.MetaKey;
|
|
|
import com.yohoufo.order.convert.AddressInfoConvertor;
|
|
|
import com.yohoufo.order.service.IBuyerOrderMetaService;
|
|
|
import com.yohoufo.order.service.cache.CacheCleaner;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
...
|
...
|
@@ -42,44 +45,133 @@ public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService { |
|
|
@Autowired
|
|
|
private BuyerOrderMapper buyerOrderMapper;
|
|
|
|
|
|
@Override
|
|
|
public String updateDeliveryAddress(BuyerOrderMetaUpdateReq req,BuyerOrder pbo){
|
|
|
String noHiddenAddressStr = req.getAddress();
|
|
|
logger.info("BuyerOrderMetaServiceImpl updateDeliveryAddress parse address {} ", noHiddenAddressStr);
|
|
|
JSONObject jsonObject = JSON.parseObject(noHiddenAddressStr);
|
|
|
logger.info("BuyerOrderMetaServiceImpl updateDeliveryAddress parse json address {} ",jsonObject);
|
|
|
|
|
|
String str_address=jsonObject.getString("address");
|
|
|
String str_consignee=jsonObject.getString("consignee");
|
|
|
String str_mobile=jsonObject.getString("mobile");
|
|
|
OrderAddressReq orderAddressReq = OrderAddressReq.builder()
|
|
|
.address(str_address)
|
|
|
.consignee(str_consignee)
|
|
|
.mobile(str_mobile)
|
|
|
.fromPlatform(req.isFromPlatform())
|
|
|
.build();
|
|
|
commomAddressService.checkAddressContent(orderAddressReq);
|
|
|
private static class PreparedNode{
|
|
|
BuyerOrder buyerOrder;
|
|
|
|
|
|
}
|
|
|
|
|
|
public boolean buyerSelfModifyAddress(int uid, long orderCode,
|
|
|
AddressInfo changedAddress,
|
|
|
final boolean fromPlatform){
|
|
|
|
|
|
//参数检查和状态检查
|
|
|
PreparedNode preparedNode = paramAndStatusCheck4BuyerModifyAddress(uid,orderCode,changedAddress);
|
|
|
|
|
|
AddressInfo dbAddressInfo = getAddressInfo(uid,orderCode);
|
|
|
if(dbAddressInfo==null){
|
|
|
logger.warn("dbAddressInfo is null ,uid {} ,orderCode {}",uid,orderCode);
|
|
|
throw new UfoServiceException(400,"找不到地址信息");
|
|
|
}
|
|
|
|
|
|
AddressInfo hiddenAddressInDB = 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, fromPlatform, dbAddressInfo,hiddenAddressInDB,changedAddress);
|
|
|
|
|
|
//至少有一个要更新,否则直接返回
|
|
|
if(!changed){
|
|
|
logger.warn("buyer self ModifyAddress no change address return now! uid {} orderCode {} changeAddress {} fromPlatform {}",
|
|
|
uid, orderCode, changedAddress, fromPlatform);
|
|
|
//throw new UfoServiceException(400,"地址信息无变化");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
logger.info("buyerModifyAddress begin update address,uid {},orderCode {},update address info {}",
|
|
|
uid, orderCode ,changedAddress);
|
|
|
|
|
|
|
|
|
updateDeliveryAddress(uid,orderCode,changedAddress, dbAddressInfo, hiddenAddressInDB, fromPlatform);
|
|
|
//clean cache of seller and buyer order detail
|
|
|
cacheCleaner.cleanDetail(uid, orderCode, TabType.BUY);
|
|
|
return true;
|
|
|
}
|
|
|
/**
|
|
|
* 基本参数检查
|
|
|
* 状态校验
|
|
|
* @param uid
|
|
|
* @param orderCode
|
|
|
* @param changedAddress
|
|
|
* @return
|
|
|
*/
|
|
|
private PreparedNode paramAndStatusCheck4BuyerModifyAddress(int uid, long orderCode, AddressInfo changedAddress){
|
|
|
//入参
|
|
|
if(uid <= 0){
|
|
|
throw new UfoServiceException(400,"参数错误:uid错误");
|
|
|
}
|
|
|
if(orderCode <= 0L){
|
|
|
throw new UfoServiceException(400,"参数错误:订单号错误");
|
|
|
}
|
|
|
|
|
|
///// 检查隐藏的内容是否有变化,带*
|
|
|
if(StringUtils.isBlank(changedAddress.getAddress())||StringUtils.isBlank(changedAddress.getConsignee())
|
|
|
||StringUtils.isBlank(changedAddress.getMobile())
|
|
|
||StringUtils.isBlank(changedAddress.getArea())
|
|
|
||StringUtils.isBlank(changedAddress.getAreaCode())){
|
|
|
throw new UfoServiceException(400,"地址信息填写错误");
|
|
|
}
|
|
|
|
|
|
//检查订单
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode,uid);
|
|
|
if(buyerOrder==null){
|
|
|
logger.warn("buyerModifyAddress check orderCode exist, uid is {}, orderCode is {}",
|
|
|
uid, orderCode );
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
if(buyerOrder.getStatus()==null){
|
|
|
logger.warn("buyerModifyAddress check orderCode status is null, uid is {}, orderCode is {} ,status is {}",
|
|
|
uid, orderCode,buyerOrder.getStatus() );
|
|
|
throw new UfoServiceException(400,"订单状态已变,不允许修改地址");
|
|
|
}
|
|
|
|
|
|
//买家已付款,卖家已发货,只有这两种状态的情况下,才允许改地址
|
|
|
boolean allowChange = ActionStatusHold.buyerCanModifyAddress(buyerOrder.getStatus());
|
|
|
if(!allowChange){
|
|
|
logger.warn("buyerModifyAddress check orderCode status not invalid, uid is {}, orderCode is {} ,status is {}",
|
|
|
uid, orderCode,buyerOrder.getStatus() );
|
|
|
throw new UfoServiceException(400,"订单状态变更,不允许修改地址");
|
|
|
}
|
|
|
PreparedNode preparedNode = new PreparedNode();
|
|
|
preparedNode.buyerOrder = buyerOrder;
|
|
|
return preparedNode;
|
|
|
}
|
|
|
|
|
|
private String updateDeliveryAddress(int buyerUid, long orderCode,
|
|
|
AddressInfo changedAddressFromReq,
|
|
|
AddressInfo noHiddenAddress,
|
|
|
AddressInfo hiddenAddress,
|
|
|
boolean isFromPlatform){
|
|
|
Integer selfModifyTimes = AddressInfoConvertor.calSelfModifyTimes(isFromPlatform);
|
|
|
//set noHiddenAddress in no hidden
|
|
|
if (!isFromPlatform){
|
|
|
noHiddenAddress.setSelfModifyTimes(selfModifyTimes);
|
|
|
}
|
|
|
AddressInfoConvertor.mergeChangedAddress4NoHidden(noHiddenAddress, changedAddressFromReq, isFromPlatform);
|
|
|
|
|
|
String str_address = noHiddenAddress.getAddress();
|
|
|
String str_consignee = noHiddenAddress.getConsignee();
|
|
|
String str_mobile = noHiddenAddress.getMobile();
|
|
|
|
|
|
AddressInfo changedAddress = new AddressInfo();
|
|
|
changedAddress.setAddress(str_address);
|
|
|
changedAddress.setConsignee(str_consignee);
|
|
|
changedAddress.setMobile(str_mobile);
|
|
|
AddressInfo hiddenAddress = commomAddressService.buildHiddenAddress(changedAddress);
|
|
|
|
|
|
AddressInfo hiddenAddressOfChanged = commomAddressService.buildHiddenAddress(changedAddress);
|
|
|
AddressInfoConvertor.mergeChangedAddress4Hidden(hiddenAddress, isFromPlatform, hiddenAddressOfChanged);
|
|
|
String rtn="";
|
|
|
int updateRowNum=0;
|
|
|
jsonObject.put("address", hiddenAddress.getAddress());
|
|
|
jsonObject.put("consignee", hiddenAddress.getConsignee());
|
|
|
jsonObject.put("mobile", hiddenAddress.getMobile());
|
|
|
if (Objects.nonNull(req.getSelfModifyTimes())){
|
|
|
jsonObject.put("selfModifyTimes", req.getSelfModifyTimes());
|
|
|
if (Objects.nonNull(selfModifyTimes)){
|
|
|
hiddenAddress.setSelfModifyTimes(selfModifyTimes);
|
|
|
}
|
|
|
int buyerUid;
|
|
|
//hidden address
|
|
|
BuyerOrderMeta meta_hiddenAddress=new BuyerOrderMeta();
|
|
|
meta_hiddenAddress.setUid(buyerUid=req.getUid());
|
|
|
meta_hiddenAddress.setOrderCode(req.getOrderCode());
|
|
|
BuyerOrderMeta meta_hiddenAddress = new BuyerOrderMeta();
|
|
|
meta_hiddenAddress.setUid(buyerUid);
|
|
|
meta_hiddenAddress.setOrderCode(orderCode);
|
|
|
meta_hiddenAddress.setMetaKey(MetaKey.BUYER_DELIVERY_HIDDEN_ADDRESS);
|
|
|
meta_hiddenAddress.setMetaValue(jsonObject.toJSONString());
|
|
|
meta_hiddenAddress.setMetaValue(JSONObject.toJSONString(hiddenAddress));
|
|
|
logger.info("BuyerOrderMetaServiceImpl updateDeliveryAddress_hidden meta param {} begin ",meta_hiddenAddress);
|
|
|
updateRowNum = buyerOrderMetaMapper.updateMetaValueByUidAndOrderCodeAndMetaKey(meta_hiddenAddress);
|
|
|
logger.info("BuyerOrderMetaServiceImpl updateDeliveryAddress_hidden meta param {} end, updateRowNum {} ",meta_hiddenAddress,updateRowNum);
|
...
|
...
|
@@ -87,39 +179,69 @@ public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService { |
|
|
//no hidden address
|
|
|
BuyerOrderMeta meta=new BuyerOrderMeta();
|
|
|
meta.setUid(buyerUid);
|
|
|
meta.setOrderCode(req.getOrderCode());
|
|
|
meta.setOrderCode(orderCode);
|
|
|
meta.setMetaKey(MetaKey.BUYER_DELIVERY_ADDRESS);
|
|
|
meta.setMetaValue(req.getAddress());
|
|
|
meta.setMetaValue(JSONObject.toJSONString(noHiddenAddress));
|
|
|
logger.info("BuyerOrderMetaServiceImpl updateDeliveryAddress meta param {} begin ",meta);
|
|
|
updateRowNum = buyerOrderMetaMapper.updateMetaValueByUidAndOrderCodeAndMetaKey(meta);
|
|
|
logger.info("BuyerOrderMetaServiceImpl updateDeliveryAddress meta param {} end, updateRowNum {} ",meta,updateRowNum);
|
|
|
rtn += (" address update:" + updateRowNum);
|
|
|
//clean cache of seller and buyer order detail
|
|
|
cacheCleaner.cleanDetail(buyerUid, req.getOrderCode(), TabType.BUY);
|
|
|
Integer sellerUid = pbo.getSellerUid();
|
|
|
cacheCleaner.cleanSellerAndBuyerOrderDetailAndList(sellerUid, buyerUid, req.getOrderCode());
|
|
|
cacheCleaner.cleanBuyerOrderDetailAndList(buyerUid, orderCode);
|
|
|
return rtn;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String updateDeliveryAddressByErp(BuyerOrderMetaUpdateReq req) {
|
|
|
int buyerUid;
|
|
|
long orderCode;
|
|
|
String addressOfJson;
|
|
|
//检查
|
|
|
if(req.getUid()<=0||req.getOrderCode()<=0|| StringUtils.isBlank(req.getAddress())){
|
|
|
if((buyerUid=req.getUid())<=0
|
|
|
||(orderCode=req.getOrderCode())<=0
|
|
|
|| StringUtils.isBlank(addressOfJson=req.getAddress())){
|
|
|
throw new UfoServiceException(400, "参数校验不通过");
|
|
|
}
|
|
|
// check status
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(req.getOrderCode());
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
|
|
|
if(buyerOrder==null){
|
|
|
throw new UfoServiceException(400, "订单不存在");
|
|
|
}
|
|
|
Integer status;
|
|
|
|
|
|
if((status=buyerOrder.getStatus())==null
|
|
|
||!ActionStatusHold.erpCanModifyBuyerAddress(status.intValue())){
|
|
|
logger.warn("BuyerOrderMeta4PlatformController updateDeliveryAddress not allow status {} param req is {}",buyerOrder.getStatus(), req);
|
|
|
throw new UfoServiceException(400, "订单状态不允许变更地址");
|
|
|
}
|
|
|
return updateDeliveryAddress(req, buyerOrder);
|
|
|
try {
|
|
|
|
|
|
AddressInfo changedAddress = JSONObject.parseObject(addressOfJson, AddressInfo.class);
|
|
|
|
|
|
OrderAddressReq orderAddressReq = OrderAddressReq.builder()
|
|
|
.address(changedAddress.getAddress())
|
|
|
.consignee(changedAddress.getConsignee())
|
|
|
.mobile(changedAddress.getMobile())
|
|
|
.fromPlatform(req.isFromPlatform())
|
|
|
.build();
|
|
|
commomAddressService.checkAddressContent(orderAddressReq);
|
|
|
AddressInfo dbAddressInfo = getAddressInfo(buyerUid,orderCode);
|
|
|
if(dbAddressInfo==null){
|
|
|
logger.warn("dbAddressInfo is null ,uid {} ,orderCode {}",buyerUid,orderCode);
|
|
|
throw new UfoServiceException(400,"找不到地址信息");
|
|
|
}
|
|
|
|
|
|
AddressInfo hiddenAddressInDB = getHiddenAddressInfo(buyerUid,orderCode);
|
|
|
if(hiddenAddressInDB==null){
|
|
|
logger.warn("hiddenAddressInDB is null ,uid {} ,orderCode {}",buyerUid,orderCode);
|
|
|
throw new UfoServiceException(400,"找不到地址信息");
|
|
|
}
|
|
|
|
|
|
return updateDeliveryAddress(buyerUid,orderCode,changedAddress,dbAddressInfo, hiddenAddressInDB, req.isFromPlatform());
|
|
|
}catch (Exception ex){
|
|
|
logger.warn("updateDeliveryAddressByErp occur exception req {} error {}", req, Throwables.getStackTraceAsString(ex));
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
BuyerOrderMeta getBuyerOrderMeta(int uid, long orderCode, String metaKey) {
|
...
|
...
|
|