Authored by chenchao

deptNO choose by area code of buyer address

... ... @@ -74,14 +74,16 @@ public class ExpressInfoController {
*/
@RequestMapping(params = "method=ufo.order.appraiseAddress")
@Cachable(expire = 300)
public ApiResponse queryAppraiseAddress(@RequestParam("uid") Integer uid, @RequestParam(value="skup", required=false)Integer skup) {
public ApiResponse queryAppraiseAddress(@RequestParam("uid") Integer uid,
@RequestParam(value="skup", required=false)Integer skup,
@RequestParam(value="orderCode", required=false)Long orderCode) {
LOG.info("method=ufo.order.appraiseAddress in, uid is {}, skup is {}", uid, skup);
if (null == uid) {
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
AppraiseAddressResp appraiseAddressResp = expressInfoService.queryAppraiseAddress(uid, skup);
AppraiseAddressResp appraiseAddressResp = expressInfoService.queryAppraiseAddress(uid, orderCode, skup);
return new ApiResponse.ApiResponseBuilder().code(200).data(appraiseAddressResp).build();
}
}
... ...
... ... @@ -75,7 +75,7 @@ public interface IExpressInfoService {
* @param uid
* @return
*/
AppraiseAddressResp queryAppraiseAddress(Integer uid, Integer skup);
AppraiseAddressResp queryAppraiseAddress(Integer uid, Long orderCode, Integer skup);
/**
... ...
... ... @@ -16,13 +16,12 @@ import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.BuyerOrderMeta;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.constants.ViewType;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.AppraiseAddressInfo;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.utils.BuyerOrderUtils;
... ... @@ -44,9 +43,11 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
@Autowired
protected IExpressInfoService expressInfoService;
@Autowired
protected IBuyerOrderMetaService buyerOrderMetaService;
abstract BuyerOrder getBuyerOrder(int uid, long orderCode);
abstract BuyerOrderMeta getBuyerOrderMeta(int uid, long orderCode, String metaKey);
abstract BuyerOrderGoods getBuyerOrderGoods(int uid, long orderCode);
... ... @@ -56,7 +57,6 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
abstract ExpressInfoDetail getExpressInfoDetail(OrderStatus orderStatus, long orderCode);
abstract AppraiseAddressInfo getAppraiseAddress(Integer depotNo, String areaCode);
abstract AddressInfo getHiddenAddressInfo(int uid, long orderCode, int skup);
... ... @@ -75,6 +75,12 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
*/
@Override
public OrderDetailInfo getOrderDetail(OrderRequest orderRequest){
BuildNode buildNode = prepareBuild(orderRequest);
OrderDetailInfo orderDetailInfo = buildOrderDetail(buildNode);
return orderDetailInfo;
}
protected BuildNode prepareBuild(OrderRequest orderRequest){
int uid;
long orderCode;
// 参数检查
... ... @@ -124,6 +130,7 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
ExpressInfoDetail lastEID = getExpressInfoDetail(orderStatus, orderCode);
BuildNode buildNode = BuildNode.builder()
.tabType(actor)
.buyerOrder(buyerOrder)
.orderStatus(orderStatus)
.buyerOrderGoods(buyerOrderGoods)
... ... @@ -132,17 +139,14 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
.lastEID(lastEID)
.appraiseVideoUrl(getAppraiseVideoUrl(buyerOrder))
.build();
return buildNode;
}
OrderDetailInfo orderDetailInfo = buildOrderDetail(buildNode, actor);
orderDetailInfo.setAppraiseAddress(getAppraiseAddress(sellerOrderGoods.getDepotNo(), userAddress.getAreaCode()));
return orderDetailInfo;
}
@Builder
static class BuildNode{
TabType tabType;
BuyerOrder buyerOrder;
OrderStatus orderStatus;
BuyerOrderGoods buyerOrderGoods;
... ... @@ -153,7 +157,8 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
String appraiseVideoUrl;
}
OrderDetailInfo buildOrderDetail(BuildNode buildNode, TabType tabType) {
OrderDetailInfo buildOrderDetail(BuildNode buildNode) {
TabType tabType = buildNode.tabType;
//fetch every data item
BuyerOrder buyerOrder = buildNode.buyerOrder;
OrderStatus orderStatus = buildNode.orderStatus;
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.core.cache.LocalCacheCallback;
import com.yoho.core.common.helpers.ImagesHelper;
import com.yohoufo.dal.order.AppraiseAddressMapper;
import com.yohoufo.dal.order.model.AppraiseAddress;
import com.yohoufo.order.model.response.AppraiseAddressInfo;
import com.yohoufo.order.model.response.AppraiseAddressResp;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -17,7 +18,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.security.SecureRandom;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
... ... @@ -123,4 +126,41 @@ public class AppraiseAddressService {
});
}
/**
* 根据指定的鉴定中心返回地址详情
* @param areaCode
* @return
*/
public AppraiseAddressInfo findAppraiseAddress(Integer depotno, String areaCode){
// 卖家已经发货选定了鉴定中心
if (depotno != null){
List<AppraiseAddressResp> addressRespList = queryAddressInfoList();
Map<Integer, AppraiseAddressResp> addressRespMap = addressRespList.stream()
.collect(Collectors.toMap(AppraiseAddressResp::getType, Function.identity(), (key1, key2)-> key1));
AppraiseAddressResp addressResp = addressRespMap.get(depotno);
if (addressResp != null){
return AppraiseAddressInfo.builder()
.address(addressResp.getAddress())
.addressName(addressResp.getAddressName())
.mobile(addressResp.getMobile()).build();
}
}
// 卖家未发货的情况,根据寄回地址就近选中一个鉴定中心
if (StringUtils.isNoneBlank(areaCode)){
AppraiseAddressResp addressResp = queryAddressByAreaCode(areaCode);
if (addressResp != null){
return AppraiseAddressInfo.builder()
.address(addressResp.getAddress())
.addressName(addressResp.getAddressName())
.mobile(addressResp.getMobile()).build();
}
}
return null;
}
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderStatus;
... ... @@ -14,11 +13,8 @@ import com.yohoufo.dal.order.BuyerOrderMetaMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.BuyerOrderMeta;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.model.response.AppraiseAddressInfo;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.service.handler.BuyerOrderButtonsHandler;
... ... @@ -67,13 +63,7 @@ public class BuyerOrderDetailService extends AbsOrderDetailService implements IO
return buyerOrder;
}
@Override
BuyerOrderMeta getBuyerOrderMeta(int uid, long orderCode, String metaKey) {
BuyerOrderMeta buyerOrderMeta = buyerOrderMetaMapper.selectByMetaKey(uid,
orderCode, metaKey);
return buyerOrderMeta;
}
@Override
BuyerOrderGoods getBuyerOrderGoods(int uid, long orderCode) {
... ... @@ -103,21 +93,11 @@ public class BuyerOrderDetailService extends AbsOrderDetailService implements IO
return lastEID;
}
@Override
AppraiseAddressInfo getAppraiseAddress(Integer depotNo, String areaCode) {
return null;
}
@Override
AddressInfo getHiddenAddressInfo(int uid, long orderCode, int skup) {
BuyerOrderMeta buyerOrderMeta = getBuyerOrderMeta(uid,
orderCode, MetaKey.BUYER_DELIVERY_HIDDEN_ADDRESS);
AddressInfo userAddress = null;
if ( null != buyerOrderMeta
&& StringUtils.isNotBlank(buyerOrderMeta.getMetaValue())){
userAddress = JSONObject.parseObject(buyerOrderMeta.getMetaValue(), AddressInfo.class);
}
AddressInfo userAddress = buyerOrderMetaService.getHiddenAddressInfo(uid, orderCode);
//门店订单特殊处理一下,收货人填写门店
dealConsigneeIfOffline(userAddress);
... ...
... ... @@ -27,6 +27,7 @@ import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.event.BuyerOrderSellerDeliveryCheckEvent;
import com.yohoufo.order.event.ErpBuyerOrderEvent;
import com.yohoufo.order.model.response.AppraiseAddressResp;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.service.IExpressCompanyService;
import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.cache.CacheCleaner;
... ... @@ -106,6 +107,9 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
@Autowired
UfoServiceCaller ufoServiceCaller;
@Autowired
private IBuyerOrderMetaService buyerOrderMetaService;
private static String EXPRESS_MQ_SEND = "third.logistics.logistics_data";
//物流文案设置
... ... @@ -142,6 +146,12 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
LOGGER.warn("deliverToDepot getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
Integer orderStatus = buyerOrder.getStatus();
if ( orderStatus != targetOrderStatus.getCode()){
LOGGER.warn("deliverToDepot order status changed , orderCode {} orderStatus {}", orderCode, orderStatus);
throw new UfoServiceException(400, "订单状态已变更,不能发货");
}
int buyerUid;
//获取skup
BuyerOrderGoods buyerOrderGoods= buyerOrderGoodsMapper.selectByOrderCode(buyerUid=buyerOrder.getUid(),orderCode);
... ... @@ -150,6 +160,7 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
throw new ServiceException(ServiceError.ORDER_NULL);
}
//根据skup ,更新鉴定中心
int skup;
SellerOrderGoods sellerOrderGoods=new SellerOrderGoods();
... ... @@ -173,8 +184,8 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
mobile = appraiseAddressResp.getMobile();
}
LOGGER.info("deliverToDepot saveExpress expressCompanyId = {}, orderCode = {}, wayBillCode = {} " +
",expressType = {},depotNum={},mobile={},expressDataType={},operateTransferCode={}",
LOGGER.info("deliverToDepot saveExpress expressCompanyId {}, orderCode {}, wayBillCode {} " +
",expressType {},depotNum {},mobile {},expressDataType {},operateTransferCode {}",
new Object[]{expressCompanyId, orderCode, wayBillCode,expressType,depotNum,mobile,expressDataType,operateTransferCode});
saveExpressRecordAndOperateTransferExpressInfo(sellerUid,expressCompanyId,orderCode,wayBillCode,expressType,expressDataType,operateTransferCode,depotNum);
... ... @@ -207,8 +218,10 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
EventBusPublisher.publishEvent(event);
}else{
LOGGER.warn("deliverToDepot can not update order, orderCode {}", orderCode);
}
LOGGER.info("deliverToDepot update buyer order status result {} ",updateBuyerCnt);
LOGGER.info("deliverToDepot update buyer order status, orderCode {} result {} ", orderCode, updateBuyerCnt);
}
@Override
... ... @@ -947,27 +960,61 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
}
}
private BuyerOrder findOrderCodeBySkup(int skup){
List<Integer> skups = new ArrayList<>(1);
skups.add(skup);
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectBySkups(skups);
List<BuyerOrder> buyerOrderList = null;
if (CollectionUtils.isNotEmpty(buyerOrderGoodsList)){
List<Long> orderCodeList = buyerOrderGoodsList.parallelStream()
.map(BuyerOrderGoods::getOrderCode).collect(Collectors.toList());
buyerOrderList = buyerOrderMapper.selectByOrderCodes(orderCodeList, Arrays.asList(OrderStatus.HAS_PAYED.getCode()));
}
int pboSize = 0;
boolean noPaidOrder;
if (noPaidOrder = (buyerOrderList == null) || (pboSize =buyerOrderList.size()) > 1){
LOGGER.warn("findOrderCodeBySkup skup {} noPaidOrder {} pboSize {}", skup, noPaidOrder, pboSize);
throw new UfoServiceException(400, "订单状态已变更,请刷新后操作");
}
return buyerOrderList.get(0);
}
/**
* 根据用户默认地址的省份定位到鉴定中心的地址返回
*
* 根据用户默认地址的省份定位到鉴定中心的地址返回 *
*
* @param uid
* @param orderCode from version 6.9.3
* @param skup
* @return
*/
public AppraiseAddressResp queryAppraiseAddress(Integer uid, Integer skup) {
if (null == skup) {
@Override
public AppraiseAddressResp queryAppraiseAddress(Integer uid, Long orderCode, Integer skup) {
boolean skupIsNull = (null == skup);
boolean orderCodeIsNull = (null == orderCode);
if (skupIsNull && orderCodeIsNull) {
LOGGER.warn("queryAppraiseAddress can not save back, all key info are null, uid {}", uid);
return appraiseAddressService.queryInitAddress();
}
BuyerOrder buyerOrder = null;
if (orderCodeIsNull){
//4 compatible before version 6.9.3(exclude), client transfer without order code
buyerOrder = findOrderCodeBySkup(skup);
orderCode = buyerOrder.getOrderCode();
LOGGER.info("in queryAppraiseAddress find buyer OrderCode By Skup , orderCode {} skup {}", orderCode, skup);
}
buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
AddressInfo buyerAddress = buyerOrderMetaService.getAddressInfo(buyerOrder.getUid(), orderCode);
LOGGER.info("in queryAppraiseAddress get buyerAddress orderCode {}, skup {}", orderCode, skup);
// 根据用户id查询默认地址的省份
SellerOrderMeta addressMeta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, MetaKey.BACK_2_SELLER_DELIVERY_ADDRESS);
if (null != addressMeta) {
LOGGER.info("addressMeta is not null uid is {}, skup is {}", uid, skup);
AddressInfo addressInfo = JSONObject.parseObject(addressMeta.getMetaValue(), AddressInfo.class);
AppraiseAddressResp resp = null;
if (null != buyerAddress ) {
// 根据产品给的哪些用户的省份匹配到对应的鉴定中心地址
return null == addressInfo ? appraiseAddressService.queryInitAddress() : appraiseAddressService.queryAddressByAreaCode(addressInfo.getAreaCode());
resp = appraiseAddressService.queryAddressByAreaCode(buyerAddress.getAreaCode());
}
// 匹配不了,给个娄底的
return appraiseAddressService.queryInitAddress();
return resp==null ? appraiseAddressService.queryInitAddress() : resp;
}
}
... ...
... ... @@ -14,15 +14,12 @@ import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.constants.ViewType;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.AppraiseAddressInfo;
import com.yohoufo.order.model.response.AppraiseAddressResp;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.service.IOrderDetailService;
... ... @@ -40,8 +37,6 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Created by chenchao on 2018/9/20.
... ... @@ -90,42 +85,7 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
@Autowired
private SellerOrderViewService sellerOrderViewService;
/**
* 根据指定的鉴定中心返回地址详情
* @param areaCode
* @return
*/
public AppraiseAddressInfo getAppraiseAddress(Integer depotno, String areaCode){
// 卖家已经发货选定了鉴定中心
if (depotno != null){
List<AppraiseAddressResp> addressRespList = appraiseAddressService.queryAddressInfoList();
Map<Integer, AppraiseAddressResp> addressRespMap = addressRespList.stream()
.collect(Collectors.toMap(AppraiseAddressResp::getType, Function.identity(), (key1, key2)-> key1));
AppraiseAddressResp addressResp = addressRespMap.get(depotno);
if (addressResp != null){
return AppraiseAddressInfo.builder()
.address(addressResp.getAddress())
.addressName(addressResp.getAddressName())
.mobile(addressResp.getMobile()).build();
}
}
// 卖家未发货的情况,根据寄回地址就近选中一个鉴定中心
if (StringUtils.isNoneBlank(areaCode)){
AppraiseAddressResp addressResp = appraiseAddressService.queryAddressByAreaCode(areaCode);
if (addressResp != null){
return AppraiseAddressInfo.builder()
.address(addressResp.getAddress())
.addressName(addressResp.getAddressName())
.mobile(addressResp.getMobile()).build();
}
}
return null;
}
... ... @@ -190,7 +150,14 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
orderDetailInfo = orderCacheService.getOrderDetailInfo(uid, orderCode, TabType.SELL);
if (Objects.isNull(orderDetailInfo)) {
fromCache = false;
orderDetailInfo = super.getOrderDetail(orderRequest);
BuildNode buildNode = super.prepareBuild(orderRequest);
orderDetailInfo = super.buildOrderDetail(buildNode);
BuyerOrder buyerOrder = buildNode.buyerOrder;
SellerOrderGoods sellerOrderGoods = buildNode.sellerOrderGoods;
AddressInfo buyerAddress = buyerOrderMetaService.getHiddenAddressInfo(buyerOrder.getUid(), orderCode);
//卖家订单详情里才会有,买家没有
orderDetailInfo.setAppraiseAddress(appraiseAddressService.findAppraiseAddress(sellerOrderGoods.getDepotNo(), buyerAddress.getAreaCode()));
//cache
orderCacheService.cacheOrderDetailInfo(uid, orderCode, TabType.SELL, orderDetailInfo);
}
}
... ... @@ -256,20 +223,7 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
return buyerOrder;
}
/**
* @see AbsOrderDetailService
* uid is buyer uid, this is very important point
* @param uid
* @param orderCode
* @param metaKey
* @return
*/
@Override
BuyerOrderMeta getBuyerOrderMeta(int uid, long orderCode, String metaKey) {
BuyerOrderMeta buyerOrderMeta = buyerOrderMetaMapper.selectByMetaKey(uid,
orderCode, metaKey);
return buyerOrderMeta;
}
/**
* @see AbsOrderDetailService
... ...