Authored by LUOXC

refactor

package com.yohoufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.common.EnumExpressType;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.ExpressInfoRespBo;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.order.utils.BuyerOrderUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.function.Consumer;
class ExpressInfoResponseDateBuilder {
final Integer scene;
final BuyerOrder buyerOrder;
final boolean isBuyer;
final boolean isSeller;
ExpressInfoRespBo expressInfoRespBo;
ExpressInfoResponseDateBuilder(TabType actor, Integer scene, BuyerOrder buyerOrder) {
this.scene = scene;
this.buyerOrder = buyerOrder;
isBuyer = actor == TabType.BUY;
isSeller = actor == TabType.SELL;
}
public ExpressInfoResponseDateBuilder init() {
expressInfoRespBo = new ExpressInfoRespBo();
expressInfoRespBo.setExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setJudgeExpressInfoDetailTitle("平台鉴定");
expressInfoRespBo.setSupplementExpressInfoDetailTitle("卖家发往平台");
expressInfoRespBo.setExpressInfoDetailList(Lists.newArrayList());
expressInfoRespBo.setJudgeExpressInfoDetailList(Lists.newArrayList());
expressInfoRespBo.setSupplementExpressInfoDetailList(Lists.newArrayList());
return this;
}
public ExpressInfoResponseDateBuilder handler(Consumer<ExpressInfoRespBo> handler) {
handler.accept(expressInfoRespBo);
return this;
}
public ExpressInfoResponseDateBuilder wash() {
// 快速发货
if (ExpressScene.QUICK_SHIP.equals(scene) && isBuyer) {
expressInfoRespBo.setSupplementExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setSupplementExpressInfoDetailList(Lists.newArrayList());
expressInfoRespBo.setJudgeExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setJudgeExpressInfoDetailList(Lists.newArrayList());
}
//鉴定阶段的物流仍然属于卖家
if (expressInfoRespBo.getExpressType() != null
&& EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode() == expressInfoRespBo.getExpressType().intValue()) {
expressInfoRespBo.setExpressType(EnumExpressType.EXPRESS_TYPE_1.getCode().byteValue());
}
// 隐藏闪购订单中卖家发往平台的物流
if (BuyerOrderUtils.isQuickDeliver(buyerOrder)) {
expressInfoRespBo.setSupplementExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setSupplementExpressInfoDetailList(Collections.emptyList());
}
//买家不能看到卖家的物流单号
if (isBuyer && expressInfoRespBo.getExpressType() != null
&& expressInfoRespBo.getExpressType().intValue() == EnumExpressType.EXPRESS_TYPE_1.getCode().intValue()) {
expressInfoRespBo.setWayBillCode(StringUtils.EMPTY);
}
return this;
}
public ExpressInfoRespBo build() {
return expressInfoRespBo;
}
}
... ...
... ... @@ -54,6 +54,8 @@ import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceExceptionIf;
/**
* @author kun.wang
* @date 2018/9/25
... ... @@ -398,33 +400,91 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
*/
@Override
public ExpressInfoRespBo queryExpressDetailInfo(Integer uid, Long orderCode, TabType actor, Integer scene) {
LOGGER.info("queryExpressDetailInfo uid={}, orderCode = {},actor = {} ", uid, orderCode, actor);
String logTag = String.format("query express detail %s", orderCode);
LOGGER.info("{}, uid is {} actor is {} and scene is {}", logTag, uid, actor, scene);
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if (buyerOrder == null) {
LOGGER.warn("queryExpressDetailInfo getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
//验证订单和tabType匹配
if (actor != null) {
switch (actor) {
case BUY:
if (!uid.equals(buyerOrder.getUid())) {
//验证是买家
LOGGER.warn("queryExpressDetailInfo check order not match buyer , uid = {} ,order is {} ", orderCode, JSON.toJSONString(buyerOrder));
throw new UfoServiceException(400, "订单物流不允许买家用户查询");
throwServiceExceptionIf(Objects.isNull(buyerOrder), "订单不存在");
boolean isBuyer = actor == TabType.BUY;
boolean isSeller = actor == TabType.SELL;
throwServiceExceptionIf(isBuyer && !uid.equals(buyerOrder.getUid()), "订单物流不允许买家用户查询");
throwServiceExceptionIf(isSeller && !uid.equals(buyerOrder.getSellerUid()), "订单物流不允许卖家用户查询");
ExpressInfoRespBo result = new ExpressInfoResponseDateBuilder(actor, scene, buyerOrder)
.init()
.handler(expressInfoRespBo -> {
List<Integer> expressTypeList = getCurrentExpressType4ExpressRecord(buyerOrder.getStatus(), actor);
if (CollectionUtils.isEmpty(expressTypeList)) {
LOGGER.info("{}, expressTypeList is empty", logTag);
return;
}
break;
case SELL:
if (!uid.equals(buyerOrder.getSellerUid())) {
//验证是卖家
LOGGER.warn("queryExpressDetailInfo check order not match seller , uid = {} ,order is {} ", orderCode, JSON.toJSONString(buyerOrder));
throw new UfoServiceException(400, "订单物流不允许卖家用户查询");
//1.物流单号信息
constructWayBillInfo(orderCode, expressTypeList, expressInfoRespBo);
// 构造物流信息
if (expressTypeList.size() == 1) {
//设定最近一个阶段的物流
List<ExpressInfo> expressInfoList = getExpressInfoListByStage(actor, orderCode, expressTypeList.get(0));
constructExpressInfo(actor, expressInfoList, expressInfoRespBo.getExpressInfoDetailList());
expressInfoRespBo.setExpressInfoDetailTitle("卖家发往平台");
} else if (expressTypeList.size() == 2) {
if (EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode().intValue() == expressTypeList.get(0)) {
//设定鉴定的物流调拨信息
List<ExpressInfo> judgeExpressInfoList = getExpressInfoListByStage(actor, orderCode, EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode());
constructExpressInfo(actor, judgeExpressInfoList, expressInfoRespBo.getJudgeExpressInfoDetailList());
//获取上一阶段的辅助物流信息
constructSupplementExpress(actor, orderCode, expressTypeList.get(0), expressInfoRespBo);
} else {
//设定最近一个阶段的物流
List<ExpressInfo> expressInfoList = getExpressInfoListByStage(actor, orderCode, expressTypeList.get(0));
constructExpressInfo(actor, expressInfoList, expressInfoRespBo.getExpressInfoDetailList());
if (EnumExpressType.EXPRESS_TYPE_2.getCode().equals(expressTypeList.get(0))) {
expressInfoRespBo.setExpressInfoDetailTitle("平台发往买家");
} else {
expressInfoRespBo.setExpressInfoDetailTitle("平台发往卖家");
}
//获取上一阶段的辅助物流信息
constructSupplementExpress(actor, orderCode, expressTypeList.get(0), expressInfoRespBo);
}
} else if (expressTypeList.size() == 3) {
//设定最近一个阶段的物流
List<ExpressInfo> expressInfoList = getExpressInfoListByStage(actor, orderCode, expressTypeList.get(0));
constructExpressInfo(actor, expressInfoList, expressInfoRespBo.getExpressInfoDetailList());
if (EnumExpressType.EXPRESS_TYPE_2.getCode().equals(expressTypeList.get(0))) {
expressInfoRespBo.setExpressInfoDetailTitle("平台发往买家");
} else {
expressInfoRespBo.setExpressInfoDetailTitle("平台发往卖家");
}
//设定鉴定的物流调拨信息
List<ExpressInfo> judgeExpressInfoList = getExpressInfoListByStage(actor, orderCode, EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode());
constructExpressInfo(actor, judgeExpressInfoList, expressInfoRespBo.getJudgeExpressInfoDetailList());
//获取上一阶段的辅助物流信息
constructSupplementExpress(actor, orderCode, expressTypeList.get(0), expressInfoRespBo);
}
break;
}
}
})
.handler(expressInfoRespBo -> {
//5.设定阶段的信息
expressInfoRespBo.setStage(new ExpressStageBuilder(actor, buyerOrder)
.scene(scene)
.isQuickShipDone(() -> Optional.ofNullable(storageDepositMapper.selectByOrderCode(orderCode))
.filter(e -> Objects.equals(e.getStatus(), StorageDepositStatusEnum.HAS_END.getCode()))
.isPresent())
.build());
})
.wash()
.build();
LOGGER.info("{}, result is {}",logTag, JSON.toJSONString(result));
return result;
}
private ExpressInfoRespBo createExpressInfoResponseDate() {
ExpressInfoRespBo expressInfoRespBo = new ExpressInfoRespBo();
expressInfoRespBo.setExpressInfoDetailTitle("");
expressInfoRespBo.setJudgeExpressInfoDetailTitle("平台鉴定");
... ... @@ -432,91 +492,30 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
expressInfoRespBo.setExpressInfoDetailList(Lists.newArrayList());
expressInfoRespBo.setJudgeExpressInfoDetailList(Lists.newArrayList());
expressInfoRespBo.setSupplementExpressInfoDetailList(Lists.newArrayList());
return expressInfoRespBo;
}
List<Integer> expressTypeList = getCurrentExpressType4ExpressRecord(buyerOrder.getStatus(), actor);
LOGGER.info("queryExpressDetailInfo getExpressType expressTypeList result = {}, uid={}, orderCode = {},actor = {} ", expressTypeList, uid, orderCode, actor);
if (CollectionUtils.isEmpty(expressTypeList)) {
LOGGER.info("queryExpressDetailInfo getExpressType expressTypeList return empty result = {}, uid={}, orderCode = {},actor = {} ", expressTypeList, uid, orderCode, actor);
return expressInfoRespBo;
}
//1.物流单号信息
constructWayBillInfo(orderCode, expressTypeList, expressInfoRespBo);
if (TabType.BUY == actor && expressInfoRespBo.getExpressType() != null
&& expressInfoRespBo.getExpressType().intValue() == EnumExpressType.EXPRESS_TYPE_1.getCode().intValue()) {
//买家不能看到卖家的物流单号
expressInfoRespBo.setWayBillCode("");
}
// 构造物流信息
if (expressTypeList.size() == 1) {
//设定最近一个阶段的物流
List<ExpressInfo> expressInfoList = getExpressInfoListByStage(actor, orderCode, expressTypeList.get(0));
constructExpressInfo(actor, expressInfoList, expressInfoRespBo.getExpressInfoDetailList());
expressInfoRespBo.setExpressInfoDetailTitle("卖家发往平台");
} else if (expressTypeList.size() == 2) {
if (EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode().intValue() == expressTypeList.get(0)) {
//设定鉴定的物流调拨信息
List<ExpressInfo> judgeExpressInfoList = getExpressInfoListByStage(actor, orderCode, EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode());
constructExpressInfo(actor, judgeExpressInfoList, expressInfoRespBo.getJudgeExpressInfoDetailList());
//获取上一阶段的辅助物流信息
constructSupplementExpress(actor, orderCode, expressTypeList.get(0), expressInfoRespBo);
} else {
//设定最近一个阶段的物流
List<ExpressInfo> expressInfoList = getExpressInfoListByStage(actor, orderCode, expressTypeList.get(0));
constructExpressInfo(actor, expressInfoList, expressInfoRespBo.getExpressInfoDetailList());
if (EnumExpressType.EXPRESS_TYPE_2.getCode().equals(expressTypeList.get(0))) {
expressInfoRespBo.setExpressInfoDetailTitle("平台发往买家");
} else {
expressInfoRespBo.setExpressInfoDetailTitle("平台发往卖家");
}
//获取上一阶段的辅助物流信息
constructSupplementExpress(actor, orderCode, expressTypeList.get(0), expressInfoRespBo);
}
} else if (expressTypeList.size() == 3) {
//设定最近一个阶段的物流
List<ExpressInfo> expressInfoList = getExpressInfoListByStage(actor, orderCode, expressTypeList.get(0));
constructExpressInfo(actor, expressInfoList, expressInfoRespBo.getExpressInfoDetailList());
if (EnumExpressType.EXPRESS_TYPE_2.getCode().equals(expressTypeList.get(0))) {
expressInfoRespBo.setExpressInfoDetailTitle("平台发往买家");
} else {
expressInfoRespBo.setExpressInfoDetailTitle("平台发往卖家");
}
//设定鉴定的物流调拨信息
List<ExpressInfo> judgeExpressInfoList = getExpressInfoListByStage(actor, orderCode, EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode());
constructExpressInfo(actor, judgeExpressInfoList, expressInfoRespBo.getJudgeExpressInfoDetailList());
private void washExpressInfoResponseDate(Integer scene, TabType actor, BuyerOrder buyerOrder, ExpressInfoRespBo expressInfoRespBo) {
//获取上一阶段的辅助物流信息
constructSupplementExpress(actor, orderCode, expressTypeList.get(0), expressInfoRespBo);
// 快速发货
if (ExpressScene.QUICK_SHIP.equals(scene) && actor == TabType.BUY) {
expressInfoRespBo.setSupplementExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setSupplementExpressInfoDetailList(Lists.newArrayList());
expressInfoRespBo.setJudgeExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setJudgeExpressInfoDetailList(Lists.newArrayList());
}
//5.设定阶段的信息
expressInfoRespBo.setStage(new ExpressStageBuilder(actor, buyerOrder)
.scene(scene)
.expressInfoRespBo(expressInfoRespBo)
.isQuickShipDone(() -> Optional.ofNullable(storageDepositMapper.selectByOrderCode(orderCode))
.filter(e -> Objects.equals(e.getStatus(), StorageDepositStatusEnum.HAS_END.getCode()))
.isPresent())
.build());
//鉴定阶段的物流仍然属于卖家
if (expressInfoRespBo.getExpressType() != null && EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode() == expressInfoRespBo.getExpressType().intValue()) {
if (expressInfoRespBo.getExpressType() != null
&& EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER.getCode() == expressInfoRespBo.getExpressType().intValue()) {
expressInfoRespBo.setExpressType(EnumExpressType.EXPRESS_TYPE_1.getCode().byteValue());
}
// 隐藏闪购订单中卖家发往平台的物流
if (BuyerOrderUtils.isQuickDeliver(buyerOrder)) {
expressInfoRespBo.setSupplementExpressInfoDetailTitle("");
expressInfoRespBo.setSupplementExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setSupplementExpressInfoDetailList(Collections.emptyList());
}
LOGGER.info("queryExpressDetailInfo result = {}", JSON.toJSONString(expressInfoRespBo));
return expressInfoRespBo;
}
private void constructSupplementExpress(TabType actor, Long orderCode, Integer expressType, ExpressInfoRespBo expressInfoRespBo) {
... ...
package com.yohoufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.common.EnumExpressType;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
import com.yohobuy.ufo.model.order.resp.ExpressInfoRespBo;
import com.yohoufo.common.constant.ExpressInfoConstant;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.order.utils.BuyerOrderUtils;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import java.util.Objects;
import java.util.function.Supplier;
@Setter
... ... @@ -63,11 +56,10 @@ public class ExpressStageBuilder {
/**
* 9 平台鉴定 == 交易成功 ,全部点亮
*/
private static final int DEPOSIT_DONE = 9;
private static final int DEPOSIT_DONE = 9;
final TabType actor;
final BuyerOrder buyerOrder;
ExpressInfoRespBo expressInfoRespBo;
Integer scene;
Supplier<Boolean> isQuickShipDone;
... ... @@ -88,7 +80,6 @@ public class ExpressStageBuilder {
* @see #QUICK_SHIP_DONE
* @see #DEPOSIT_BEFORE_DONE
* @see #DEPOSIT_DONE
*
*/
public int build() {
... ... @@ -97,10 +88,6 @@ public class ExpressStageBuilder {
// 快速发货
if (ExpressScene.QUICK_SHIP.equals(scene)) {
if (isBuyer) {
expressInfoRespBo.setSupplementExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setSupplementExpressInfoDetailList(Lists.newArrayList());
expressInfoRespBo.setJudgeExpressInfoDetailTitle(StringUtils.EMPTY);
expressInfoRespBo.setJudgeExpressInfoDetailList(Lists.newArrayList());
return isQuickShipDone.get() ? QUICK_SHIP_DONE : QUICK_SHIP_DEPOT_SENT;
} else {
return DONE;
... ...