|
|
package com.yohoufo.order.service.handler;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrder;
|
|
|
import com.yohoufo.order.model.response.OrderDetailInfo;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by chao.chen on 2019/1/21.
|
|
|
*/
|
|
|
public class BuyerOrderButtonsHandler {
|
|
|
private List<OrderListInfo> orderListInfos;
|
|
|
|
|
|
OrderDetailInfo orderDetailInfo;
|
|
|
|
|
|
private BiFunction<List<Long>, List<Integer>, List<BuyerOrder>> buyerOrderDS;
|
|
|
|
|
|
public BuyerOrderButtonsHandler(List<OrderListInfo> orderListInfos){
|
|
|
this.orderListInfos = orderListInfos;
|
|
|
}
|
|
|
|
|
|
public BuyerOrderButtonsHandler(OrderDetailInfo orderDetailInfo){
|
|
|
this.orderDetailInfo = orderDetailInfo;
|
|
|
}
|
|
|
|
|
|
|
|
|
public BuyerOrderButtonsHandler loadBuyerOrderDS(BiFunction<List<Long>, List<Integer>, List<BuyerOrder>> buyerOrderDS){
|
|
|
this.buyerOrderDS = buyerOrderDS;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
BiFunction<BuyerOrder,List<ButtonShowBo>,List<ButtonShowBo>> fmtBtnFunc;
|
|
|
|
|
|
public BuyerOrderButtonsHandler loadFmtBtnFunc(BiFunction<BuyerOrder,List<ButtonShowBo>,List<ButtonShowBo>> fmtBtnFunc){
|
|
|
this.fmtBtnFunc = fmtBtnFunc;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
public void processDetail(){
|
|
|
if (Objects.isNull(orderDetailInfo)){
|
|
|
return;
|
|
|
}
|
|
|
final OrderStatus npos = OrderStatus.HAS_PAYED;
|
|
|
boolean isNeedProcess = Objects.equals(orderDetailInfo.getStatusDetail().getStatus(), npos.getCode());
|
|
|
if (!isNeedProcess){
|
|
|
return;
|
|
|
}
|
|
|
List<BuyerOrder> pbos;
|
|
|
List<Long> paidOrderCodes = new ArrayList<>(1);
|
|
|
paidOrderCodes.add(orderDetailInfo.getOrderCode());
|
|
|
List<Integer> statusList = Lists.newArrayList(npos.getCode());
|
|
|
pbos = buyerOrderDS.apply(paidOrderCodes, statusList);
|
|
|
if (CollectionUtils.isNotEmpty(pbos)){
|
|
|
BuyerOrder pbo = pbos.get(0);
|
|
|
List<ButtonShowBo> fbsbs = fmtBtnFunc.apply(pbo, orderDetailInfo.getButtons());
|
|
|
orderDetailInfo.setButtons(fbsbs);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void process(){
|
|
|
if (CollectionUtils.isEmpty(orderListInfos)){
|
|
|
return;
|
|
|
}
|
|
|
Predicate<OrderListInfo> olip = oli -> Objects.equals(oli.getStatus(), OrderStatus.HAS_PAYED.getCode());
|
|
|
List<Long> paidOrderCodes = orderListInfos.parallelStream()
|
|
|
.filter(olip)
|
|
|
.map(OrderListInfo::getOrderCode).collect(Collectors.toList());
|
|
|
List<BuyerOrder> pbos = null;
|
|
|
if (CollectionUtils.isNotEmpty(paidOrderCodes)){
|
|
|
List<Integer> statusList = Lists.newArrayList(OrderStatus.HAS_PAYED.getCode());
|
|
|
pbos = buyerOrderDS.apply(paidOrderCodes, statusList);
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(pbos)){
|
|
|
Map<Long, BuyerOrder> codeBuyorderMap = pbos.parallelStream()
|
|
|
.collect(Collectors.toMap(BuyerOrder::getOrderCode, Function.identity()));
|
|
|
for(OrderListInfo oli : orderListInfos){
|
|
|
if(olip.test(oli)) {
|
|
|
Long orderCode = oli.getOrderCode();
|
|
|
BuyerOrder pbo = codeBuyorderMap.get(orderCode);
|
|
|
List<ButtonShowBo> fbsbs = fmtBtnFunc.apply(pbo, oli.getButtons());
|
|
|
oli.setButtons(fbsbs);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|