Authored by chenchao

adaptor deliver

... ... @@ -55,7 +55,7 @@
<foreach collection="statusList" item="status" open="(" close=")" separator=",">
#{status,jdbcType=TINYINT}
</foreach>
limit #{offset},#{limit}
order by id desc limit #{offset},#{limit}
</select>
... ...
... ... @@ -4,6 +4,8 @@ import com.yohobuy.ufo.model.order.req.*;
import com.yohobuy.ufo.model.order.resp.*;
import com.yohobuy.ufo.model.order.vo.ProductVo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.service.seller.deposit.SellerDepositOrderDetailService;
import com.yohoufo.order.service.seller.deposit.SellerDepositOrderListService;
import com.yohoufo.order.service.seller.deposit.SellerDepositOrderService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
... ... @@ -21,6 +23,12 @@ public class SellerDepositOrderController {
@Autowired
private SellerDepositOrderService sellerDepositOrderService;
@Autowired
private SellerDepositOrderDetailService sellerDepositOrderDetailService;
@Autowired
private SellerDepositOrderListService sellerDepositOrderListService;
@RequestMapping(params = "method=ufo.depositOrder.compute")
public ApiResponse compute(@RequestParam(name = "uid")int uid,
@RequestParam(name = "goodsList")String goodsList){
... ... @@ -84,7 +92,7 @@ public class SellerDepositOrderController {
.uid(uid).listType(listType).limit(limit).page(page).build();
logger.info("in ufo.depositOrder.list req {}", req);
PageResp<SellerDepositOrderListResp> resp = sellerDepositOrderService.getOrderList(req);
PageResp<SellerDepositOrderListResp> resp = sellerDepositOrderListService.getOrderList(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(resp)
... ... @@ -99,7 +107,7 @@ public class SellerDepositOrderController {
SellerDepositOrderDetailReq req = SellerDepositOrderDetailReq.builder()
.uid(uid).orderCode(orderCode).build();
logger.info("in ufo.depositOrder.detail req {}", req);
SellerDepositOrderDetailResp resp = sellerDepositOrderService.getOrderDetail(req);
SellerDepositOrderDetailResp resp = sellerDepositOrderDetailService.getOrderDetail(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(resp)
... ... @@ -130,13 +138,14 @@ public class SellerDepositOrderController {
.wayBillCode(wayBillCode)
.expressCompanyId(expressCompanyId)
.build();
sellerDepositOrderService.deliverToDepot(req);
sellerDepositOrderService.deliver2Depot(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.message("寄存订单发货录入成功")
.build();
}
@RequestMapping(params = "method=ufo.depositOrder.productList")
public ApiResponse getProductList(@RequestParam(name = "uid")int uid,
@RequestParam(name = "orderCode")long orderCode,
... ... @@ -148,7 +157,7 @@ public class SellerDepositOrderController {
.page(page)
.limit(limit).build();
logger.info("in method=ufo.depositOrder.skuList req {}", req);
PageResp<ProductVo> resp = sellerDepositOrderService.getSknList(req);
PageResp<ProductVo> resp = sellerDepositOrderListService.getSknList(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(resp)
... ... @@ -167,7 +176,7 @@ public class SellerDepositOrderController {
.page(page)
.limit(limit).build();
logger.info("in method=ufo.depositOrder.skuList req {}", req);
PageResp<ProductVo> resp = sellerDepositOrderService.getSkuList(req);
PageResp<ProductVo> resp = sellerDepositOrderListService.getSkuList(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(resp)
... ...
... ... @@ -3,10 +3,14 @@ package com.yohoufo.order.convert;
import com.yohobuy.ufo.model.order.bo.GoodsBo;
import com.yohobuy.ufo.model.order.bo.ProductBo;
import com.yohobuy.ufo.model.order.vo.GoodsVo;
import com.yohobuy.ufo.model.order.vo.ProductVo;
import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.dal.order.model.AppraiseOrderStorage;
import java.math.BigDecimal;
import java.util.Objects;
public final class ProductConvertor {
... ... @@ -41,4 +45,17 @@ public final class ProductConvertor {
aosc.setNum(goodsBo.getNum());
return aosc;
}
public static ProductVo convertProductVo(AppraiseOrderGoods paog, ProductVo temp){
ProductVo productVo = ProductVo.builder()
.imgUrl(ImageUrlAssist.getAllProductPicUrl(paog.getImageUrl(), "goodsimg", "center", "d2hpdGU="))
.productName(paog.getProductName())
.productId(paog.getProductId())
.total(paog.getNum()).build();
if (Objects.nonNull(temp)){
productVo.setSizeNum(temp.getSizeNum());
productVo.setGoodsList(temp.getGoodsList());
}
return productVo;
}
}
... ...
package com.yohoufo.order.service;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.req.DeliverToDepotReq;
public interface IGoodsService {
/**
* 发货
* @param req
*/
int deliver2Depot(DeliverToDepotReq req);
/**
* 平台收货
* @param orderCode
*/
void platformReceiveGoods(long orderCode);
/**
* 鉴定通过
* @param orderCode
*/
void appraisePass(long orderCode);
/**
* 鉴别为假
* @param orderCode
*/
void appraiseFake(long orderCode);
/**
* 无法鉴别
* @param orderCode
*/
void unsure(long orderCode);
OrderAttributes getOrderAttributes();
}
... ...
... ... @@ -58,7 +58,7 @@ public class OrderPaymentServiceFactory {
log.info("orderCode is {}, type is {}", orderCode, codeMeta.getType());
// 买家订单
if (codeMeta.getType() == OrderCodeType.BUYER_TYPE.getType()) {
paymentService = appraiseOrderService.isAppraiseOrder(orderCode) ? this.appraiseOrderPaymentService : this.buyerOrderPaymentService;
paymentService = appraiseOrderService.isAppraiseOrder(orderCode).isExisted() ? this.appraiseOrderPaymentService : this.buyerOrderPaymentService;
} else if (codeMeta.getType() == OrderCodeType.SELLER_TYPE.getType()) {
paymentService = this.sellerOrderPaymentService;
} else if (codeMeta.getType() == OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType()) {
... ...
... ... @@ -8,10 +8,7 @@ import com.yohobuy.ufo.model.order.bo.AppraiseOrderGoodsBo;
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.req.AppraiseOrderComputeReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderDetailReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderListReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderSubmitReq;
import com.yohobuy.ufo.model.order.req.*;
import com.yohobuy.ufo.model.order.resp.*;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.exception.UfoServiceException;
... ... @@ -29,6 +26,7 @@ import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.convert.AppraiseOrderGoodsConvertor;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.dto.AppraiseOrderContext;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
... ... @@ -49,7 +47,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class AppraiseOrderService {
public class AppraiseOrderService implements IGoodsService {
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
... ... @@ -159,7 +157,8 @@ public class AppraiseOrderService {
AppraiseOrderGoodsBo appraiseOrderGoodsBo;
}
OrderAttributes getOrderAttributes(){
@Override
public OrderAttributes getOrderAttributes(){
return OrderAttributes.APPRAISE;
}
... ... @@ -342,13 +341,21 @@ public class AppraiseOrderService {
* @param orderCode
* @return
*/
public boolean isAppraiseOrder(long orderCode){
public ExistenceNode isAppraiseOrder(long orderCode){
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
boolean flag = Objects.nonNull(pao);
Integer aoac = flag ? pao.getAttributes() : null;
logger.info("in isAppraiseOrder orderCode {} aoac {} flag {}",
orderCode, aoac, flag);
return flag;
return ExistenceNode.builder().isExisted(flag).appraiseOrder(pao).build();
}
@Data
@Builder
public static class ExistenceNode{
boolean isExisted;
AppraiseOrder appraiseOrder;
}
/**
... ... @@ -357,7 +364,7 @@ public class AppraiseOrderService {
* @param orderCode
* @return
*/
public boolean isPaidAppraiseOrder(int uid, long orderCode){
public ExistenceNode isPaidAppraiseOrder(int uid, long orderCode){
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
Integer aoac = null;
OrderAttributes oa = null;
... ... @@ -367,22 +374,24 @@ public class AppraiseOrderService {
&& Objects.equals(oa, OrderAttributes.APPRAISE);
logger.info("in isAppraiseOrder uid {} orderCode {} aoac {} oa {} flag {}",
uid, orderCode, aoac, oa, flag);
return flag;
return ExistenceNode.builder().isExisted(flag).appraiseOrder(pao).build();
}
/**
* 发货
* @param orderCode
* @param depotNum
* @param req
*/
public void deliver2Depot(long orderCode, int depotNum){
@Override
public int deliver2Depot(DeliverToDepotReq req){
return 0;
}
/**
* 平台收货
* @param orderCode
*/
@Override
public void platformReceiveGoods(long orderCode){
}
... ... @@ -391,6 +400,7 @@ public class AppraiseOrderService {
* 鉴定通过
* @param orderCode
*/
@Override
public void appraisePass(long orderCode){
}
... ... @@ -399,6 +409,7 @@ public class AppraiseOrderService {
* 鉴别为假
* @param orderCode
*/
@Override
public void appraiseFake(long orderCode){
}
... ... @@ -407,6 +418,7 @@ public class AppraiseOrderService {
* 无法鉴别
* @param orderCode
*/
@Override
public void unsure(long orderCode){
}
... ...
... ... @@ -12,6 +12,7 @@ import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.DepotType;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum;
import com.yohobuy.ufo.model.order.req.DeliverToDepotReq;
import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail;
import com.yohobuy.ufo.model.order.resp.ExpressInfoRespBo;
import com.yohobuy.ufo.model.order.resp.MiniFaultConfirm;
... ... @@ -37,6 +38,7 @@ 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.IGoodsService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.proxy.*;
... ... @@ -124,6 +126,9 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
@Autowired
private UserProxyService userProxyService;
@Autowired
private AppraiseOrderService appraiseOrderService;
private static String EXPRESS_MQ_SEND = "third.logistics.logistics_data";
//物流文案设置
... ... @@ -135,42 +140,26 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
@Autowired
private SkupService skupService;
/**
* @param sellerUid 卖家的uid
* @param expressCompanyId 快递公司id
* @param orderCode 订单号 :一定是买家订单编号
* @param wayBillCode 快递单号
* @param depotNum 鉴定中心id
*/
@Override
public void deliverToDepot(Integer sellerUid, Integer expressCompanyId, Long orderCode, String wayBillCode,
Integer depotNum) {
//用户扫描二维码,防止注入信息
if (StringUtils.isBlank(wayBillCode) || wayBillCode.toLowerCase().contains("http")) {
throw new UfoServiceException(400, "无效的快递单号");
}
wayBillCode = StringUtils.defaultString(wayBillCode).trim();
//保存物流信息+更新订单状态;
//本阶段的物流类型和订单状态
@Autowired
private ServiceOrderProcessor serviceOrderProcessor;
private int processBuyerOrder(BuyerOrder buyerOrder,
Integer expressCompanyId,
Integer expressType,
String wayBillCode,
Integer depotNum){
long orderCode = buyerOrder.getOrderCode();
Integer sellerUid = buyerOrder.getSellerUid();
final OrderStatus expectOrderStatus = OrderStatus.HAS_PAYED;
final OrderStatus targetOrderStatus = OrderStatus.SELLER_SEND_OUT;
Integer expressType = EnumExpressType.EXPRESS_TYPE_1.getCode();
LOGGER.info("deliverToDepot saveExpressAndUpdateBuyerOrderStatus sellerUid={} ,expressCompanyId = {}, orderCode = {}, wayBillCode = {} " +
",expressType = {} ,expectOrderStatus = {} ,targetOrderStatus = {} ,depotNum = {}", new Object[]{sellerUid, expressCompanyId, orderCode, wayBillCode, expressType, expectOrderStatus, targetOrderStatus, depotNum});
//TODO 应该将卖家的id带进去查询买家订单,防止操作别人卖的订单
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
if (buyerOrder == null) {
LOGGER.warn("deliverToDepot getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
",expressType = {} ,expectOrderStatus = {} ,targetOrderStatus = {} ,depotNum = {}",
new Object[]{sellerUid, expressCompanyId, orderCode, wayBillCode, expressType, expectOrderStatus, targetOrderStatus, depotNum});
Integer orderStatus = buyerOrder.getStatus();
if (orderStatus != expectOrderStatus.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);
... ... @@ -189,30 +178,11 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
// 更新买家订单状态
int updateBuyerCnt = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerOrder.getUid(),
expectOrderStatus.getCode(), targetOrderStatus.getCode(), DateUtil.getCurrentTimeSecond());
SellerOrderGoods psog;
if (updateBuyerCnt > 0) { // 更新买家订单成功之后,插入物流信息。防止并发、重复提交
// 保存订单物流信息
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.seller_send_out;
String mobile = "";
AppraiseAddressResp appraiseAddressResp = appraiseAddressService.queryInitAddressByDepotNum(depotNum);
if (appraiseAddressResp != null) {
mobile = appraiseAddressResp.getMobile();
}
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);
// 发送mq获取物流信息
sendExpressMQ(sellerUid, expressCompanyId, orderCode, wayBillCode, mobile);
psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
LOGGER.info("deliverToDepot end ! send express to erp ");
if (updateBuyerCnt>0){
//记录订单的状态变更信息
LOGGER.info("in deliverToDepot record status change, orderCode {},uid {} ,sellerUid {}", orderCode, buyerUid, sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetOrderStatus.getCode());
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
buyerNoticeFacade.sellerDeliver2Depot(buyerOrder, psog);
... ... @@ -234,10 +204,86 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
EventBusPublisher.publishEvent(event);
}
return updateBuyerCnt;
}
/**
* @param sellerUid 卖家的uid
* @param expressCompanyId 快递公司id
* @param orderCode 订单号 :一定是买家订单编号
* @param wayBillCode 快递单号
* @param depotNum 鉴定中心id
*/
@Override
public void deliverToDepot(Integer sellerUid,
Integer expressCompanyId,
Long orderCode,
String wayBillCode,
Integer depotNum) {
//用户扫描二维码,防止注入信息
if (StringUtils.isBlank(wayBillCode) || wayBillCode.toLowerCase().contains("http")) {
throw new UfoServiceException(400, "无效的快递单号");
}
wayBillCode = StringUtils.defaultString(wayBillCode).trim();
//保存物流信息+更新订单状态;
//本阶段的物流类型和订单状态
Integer expressType = EnumExpressType.EXPRESS_TYPE_1.getCode();
//TODO 应该将卖家的id带进去查询买家订单,防止操作别人卖的订单
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
int updateOrderCnt = 0;
if (buyerOrder == null) {
AppraiseOrderService.ExistenceNode existenceNode = appraiseOrderService.isAppraiseOrder(orderCode);
if (!existenceNode.isExisted) {
LOGGER.warn("deliverToDepot getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
AppraiseOrder appraiseOrder = existenceNode.appraiseOrder;
IGoodsService goodsService = serviceOrderProcessor.findGoodsSeriveInstance(appraiseOrder.getAttributes());
DeliverToDepotReq deliverToDepotReq = DeliverToDepotReq.builder().orderCode(orderCode)
.depotNum(depotNum).uid(sellerUid).build();
updateOrderCnt = goodsService.deliver2Depot(deliverToDepotReq);
}else {
updateOrderCnt = processBuyerOrder(buyerOrder, expressCompanyId, expressType, wayBillCode, depotNum);
}
if (updateOrderCnt > 0) { // 更新买家订单成功之后,插入物流信息。防止并发、重复提交
// 保存订单物流信息
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.seller_send_out;
String mobile = "";
AppraiseAddressResp appraiseAddressResp = appraiseAddressService.queryInitAddressByDepotNum(depotNum);
if (appraiseAddressResp != null) {
mobile = appraiseAddressResp.getMobile();
}
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);
// 发送mq获取物流信息
sendExpressMQ(sellerUid, expressCompanyId, orderCode, wayBillCode, mobile);
LOGGER.info("deliverToDepot end ! send express to erp ");
//记录订单的状态变更信息
LOGGER.info("in deliverToDepot record status change, orderCode {}, sellerUid {}", orderCode, sellerUid);
} else {
LOGGER.warn("deliverToDepot can not update order, orderCode {}", orderCode);
}
LOGGER.info("deliverToDepot update buyer order status, orderCode {} result {} ", orderCode, updateBuyerCnt);
LOGGER.info("deliverToDepot update buyer order status, orderCode {} result {} ", orderCode, updateOrderCnt);
}
@Override
... ...
package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.seller.deposit.SellerDepositOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ServiceOrderProcessor {
@Autowired
private AppraiseOrderService appraiseOrderService;
@Autowired
private SellerDepositOrderService sellerDepositOrderService;
public IGoodsService findGoodsSeriveInstance(int oac){
OrderAttributes oa = OrderAttributes.getOrderAttributes(oac);
IGoodsService goodsService = null;
switch (oa){
case APPRAISE:
goodsService = appraiseOrderService;
break;
case DEPOSITE:
goodsService = sellerDepositOrderService;
break;
default:
throw new UfoServiceException(500, "订单类型错误");
}
return goodsService;
}
}
... ...
package com.yohoufo.order.service.seller.deposit;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.constants.DepotType;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.SellerDepositOrderDetailReq;
import com.yohobuy.ufo.model.order.req.SellerDepositOrderPrdListReq;
import com.yohobuy.ufo.model.order.resp.AppraiseAddressInfo;
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.resp.SellerDepositOrderDetailResp;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohobuy.ufo.model.order.vo.ProductVo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.AppraiseOrderStorageMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.response.AppraiseAddressResp;
import com.yohoufo.order.service.impl.AbsOrderViewService;
import com.yohoufo.order.service.impl.AppraiseAddressService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
@Service
public class SellerDepositOrderDetailService extends AbsOrderViewService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private AppraiseOrderMapper appraiseOrderMapper;
@Autowired
private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
@Autowired
private AppraiseOrderStorageMapper appraiseOrderStorageMapper;
@Autowired
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
@Autowired
private AppraiseOrderMetaService appraiseOrderMetaService;
@Autowired
private AppraiseAddressService appraiseAddressService;
@Autowired
private SellerDepositOrderListService sellerDepositOrderListService;
private static final List<Integer> showEXpressInfoStatusList = Lists.newArrayList(AppraiseOrderStatus.SELLER_SEND_OUT.getCode(),
AppraiseOrderStatus.WAITING_RECEIVE.getCode(),
AppraiseOrderStatus.PLATFORM_RECEIVE.getCode(),
AppraiseOrderStatus.JUDGE_PASS.getCode(),
AppraiseOrderStatus.CHECKING_FAKE.getCode(),
AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode()
);
private static final List<Integer> showUserAddressStatusList = Lists.newArrayList(AppraiseOrderStatus.SELLER_SEND_OUT.getCode(),
AppraiseOrderStatus.WAITING_RECEIVE.getCode(),
AppraiseOrderStatus.PLATFORM_RECEIVE.getCode(),
AppraiseOrderStatus.JUDGE_PASS.getCode(),
AppraiseOrderStatus.CHECKING_FAKE.getCode(),
AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode()
);
private static final List<Integer> showAppraiseAddressStatusList = Lists.newArrayList(AppraiseOrderStatus.SELLER_SEND_OUT.getCode(),
AppraiseOrderStatus.WAITING_RECEIVE.getCode(),
AppraiseOrderStatus.PLATFORM_RECEIVE.getCode(),
AppraiseOrderStatus.JUDGE_PASS.getCode(),
AppraiseOrderStatus.CHECKING_FAKE.getCode(),
AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode()
);
private static final List<Integer> addressUpgradableStatusList = Lists.newArrayList(AppraiseOrderStatus.HAS_PAYED.getCode());
public SellerDepositOrderDetailResp getOrderDetail(SellerDepositOrderDetailReq req){
Long orderCode = req.getOrderCode();
int uid = req.getUid();
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
OrderAttributes oa = OrderAttributes.getOrderAttributes(pao.getAttributes());
//todo use another page list query
List<AppraiseOrderGoods> paogList = appraiseOrderGoodsMapper.selectByOrderCodes(Arrays.asList(orderCode));
//
TimeoutBo timeout = calTimeout(TabType.BUY, uid, orderCode, pao.getStatus(),
pao.getCreateTime(), oa);
boolean expressShow = showEXpressInfoStatusList.contains(pao.getStatus());
//
AppraiseOrderStatus aos = AppraiseOrderStatus.getByCode(pao.getStatus());
OrderDetailInfo.StatusDetail statusDetail = OrderDetailInfo.StatusDetail
.builder()
.statuStr(aos.statusStr(oa))
.detailDesc(aos.detailDesc(oa))
.expressShow(expressShow)
.build();
//
AppraiseAddressInfo appraiseAddressInfo = null;
if(showAppraiseAddressStatusList.contains(pao.getStatus())){
AppraiseAddressResp aaResp = appraiseAddressService.findByDepotType(DepotType.NJ.getCode());
appraiseAddressInfo = AppraiseAddressService.convert2AppraiseAddressInfo(aaResp);
}
AddressInfo userAddress = null;
if (showUserAddressStatusList.contains(pao.getStatus())){
userAddress = appraiseOrderMetaService.getHidderUserAddress(orderCode);
}
boolean addressUpgradable = addressUpgradableStatusList.contains(pao.getStatus());
SellerDepositOrderPrdListReq sknListReq = SellerDepositOrderPrdListReq.builder()
.orderCode(orderCode)
.page(1).limit(10).uid(uid).build();
PageResp<ProductVo> sknListPageResp = sellerDepositOrderListService.getSknList(sknListReq);
return SellerDepositOrderDetailResp.builder()
.orderCode(orderCode)
.uid(uid)
.earnestMoney(SellerOrderConvertor.formatFee(pao.getAmount()))
.createTime(DateUtil.formatDate(pao.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS))
.timeout(timeout)
.statusDetail(statusDetail)
.productList(sknListPageResp.getData())
.userAddress(userAddress)
.appraiseAddress(appraiseAddressInfo)
.addressUpgradable(addressUpgradable)
.build()
;
}
@Override
public Logger getLogger() {
return logger;
}
@Override
protected String buildOrderTypeTag(Integer orderAttr, SkupType skupType) {
return null;
}
}
... ...
package com.yohoufo.order.service.seller.deposit;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.constants.SellerDepositOrderListType;
import com.yohobuy.ufo.model.order.req.SellerDepositOrderListReq;
import com.yohobuy.ufo.model.order.req.SellerDepositOrderPrdListReq;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.resp.SellerDepositOrderListResp;
import com.yohobuy.ufo.model.order.vo.GoodsVo;
import com.yohobuy.ufo.model.order.vo.ProductVo;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.AppraiseOrderStorageMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.dal.order.model.AppraiseOrderMeta;
import com.yohoufo.dal.order.model.AppraiseOrderStorage;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.convert.ProductConvertor;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.Builder;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class SellerDepositOrderListService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
@Autowired
private AppraiseOrderStorageMapper appraiseOrderStorageMapper;
@Autowired
private AppraiseOrderMapper appraiseOrderMapper;
@Autowired
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
public PageResp<SellerDepositOrderListResp> getOrderList(SellerDepositOrderListReq req ){
PageResp.PageRespBuilder<SellerDepositOrderListResp> respBuilder = PageResp.builder();
SellerDepositOrderListType sellerDepositOrderListType = SellerDepositOrderListType.getByCode(req.getListType());
if (Objects.isNull(sellerDepositOrderListType)){
return respBuilder.build();
}
int uid = req.getUid();
OrderAttributes orderAttributes = getOrderAttributes();
final List<Integer> statusList = sellerDepositOrderListType.statusList();
int total = appraiseOrderMapper.selectCntByOrderType(uid, orderAttributes.getCode(), statusList);
int limit = req.getLimit();
if (total == 0){
return respBuilder
.pageSize(limit)
.total(total)
.page(req.getPage())
.build();
}
int offset = (req.getPage() - 1) * limit;
List<AppraiseOrder> orderList = appraiseOrderMapper.selectOrderListByOrderType(uid, orderAttributes.getCode(), statusList, offset, limit);
List<Long> orderCodes = orderList.stream().map(AppraiseOrder::getOrderCode).collect(Collectors.toList());
List<AppraiseOrderGoods> paogs = appraiseOrderGoodsMapper.selectByOrderCodes(orderCodes);
Map<Long,List<AppraiseOrderGoods>> orderCodeAOGMap = new HashMap<>(paogs.size());
for (AppraiseOrderGoods paog : paogs){
long orderCode;
List<AppraiseOrderGoods> list;
if (!orderCodeAOGMap.containsKey(orderCode=paog.getOrderCode())){
list = new ArrayList(16);
orderCodeAOGMap.put(orderCode, list);
}else{
list = orderCodeAOGMap.get(orderCode);
}
list.add(paog);
}
List<SellerDepositOrderListResp> aolrList = orderList.parallelStream()
.map(pao-> buildSellerDepositOrderListResp(pao, orderCodeAOGMap.get(pao.getOrderCode())))
.collect(Collectors.toList());
respBuilder.page(req.getPage())
.pageSize(limit)
.total(total)
.pagetotal((total % limit == 0) ? (total / limit) : (total / limit + 1))
.data(aolrList);
return respBuilder.build();
}
SellerDepositOrderListResp buildSellerDepositOrderListResp(AppraiseOrder pao, List<AppraiseOrderGoods> aogList){
int uid = pao.getUid();
long orderCode = pao.getOrderCode();
int status = pao.getStatus();
AppraiseOrderStatus appraiseOrderStatus = AppraiseOrderStatus.getByCode(status);
OrderAttributes oa = getOrderAttributes();
List<ProductVo> productList = aogList.parallelStream()
.sorted(Comparator.comparing(AppraiseOrderGoods::getOrderBy))
.map(paog -> ProductVo.builder()
.imgUrl(ImageUrlAssist.getAllProductPicUrl(paog.getImageUrl(), "goodsimg", "center", "d2hpdGU="))
.build())
.collect(Collectors.toCollection(()->new ArrayList<>(aogList.size())));
return SellerDepositOrderListResp.builder()
.uid(uid)
.orderCode(orderCode)
.status(status)
.statuStr(appraiseOrderStatus.statusStr(oa))
.buttons(appraiseOrderStatus.listButtons(oa))
.productList(productList)
.build();
}
OrderAttributes getOrderAttributes(){
return OrderAttributes.DEPOSITE;
}
public PageResp<ProductVo> getSknList(SellerDepositOrderPrdListReq req){
Long orderCode = req.getOrderCode();
int total = appraiseOrderGoodsMapper.selectCntByOrderCode(orderCode);
int limit = req.getLimit();
PageResp.PageRespBuilder<ProductVo> respBuilder = PageResp.builder();
respBuilder.page(req.getPage()).pageSize(limit).total(total);
if (total == 0){
return respBuilder.build();
}
int offset = (req.getPage() - 1) * limit;
List<AppraiseOrderGoods> paogs = appraiseOrderGoodsMapper.selectAllByOrderCode(orderCode, offset, limit);
List<ProductVo> productVoList = buildProductVoListWithSkuSummary(paogs);
respBuilder.data(productVoList);
return respBuilder.build();
}
List<ProductVo> buildProductVoListWithSkuSummary(List<AppraiseOrderGoods> paogs){
return paogs.parallelStream().map(paog-> ProductConvertor.convertProductVo(paog, null))
.collect(Collectors.toCollection(()->new ArrayList<>(paogs.size())));
}
public PageResp<ProductVo> getSkuList(SellerDepositOrderPrdListReq req){
final Long orderCode = req.getOrderCode();
int total = appraiseOrderGoodsMapper.selectCntByOrderCode(orderCode);
int limit = req.getLimit();
PageResp.PageRespBuilder<ProductVo> respBuilder = PageResp.builder();
respBuilder.page(req.getPage()).pageSize(limit).total(total);
if (total == 0){
return respBuilder.build();
}
int offset = (req.getPage() - 1) * limit;
List<AppraiseOrderGoods> paogs = appraiseOrderGoodsMapper.selectAllByOrderCode(orderCode, offset, limit);
OrderDataNode node = buildDataSourceOfParentOrder(orderCode, paogs);
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap = node.prdIdAOSListMap;
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap = node.storageIdSOCRMap;
List<ProductVo> productVoList = buildProductVoListWithSkuDetail(paogs, prdIdAOSListMap, storageIdSOCRMap);
respBuilder.data(productVoList);
return respBuilder.build();
}
List<ProductVo> buildProductVoListWithSkuDetail(List<AppraiseOrderGoods> paogs,
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap,
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap){
Map<Integer,ProductVo> tempProductMap = new HashMap<>(paogs.size());
for(Map.Entry<Integer,List<AppraiseOrderStorage>> prdIdAOSListEntry : prdIdAOSListMap.entrySet()){
Integer prdId = prdIdAOSListEntry.getKey();
List<AppraiseOrderStorage> aosList = prdIdAOSListEntry.getValue();
int sizeNum = aosList.size();
List<GoodsVo> goodsList = new ArrayList<>(sizeNum);
for (AppraiseOrderStorage aos : aosList){
Integer storageId;
SellerOrderComputeResult socr = storageIdSOCRMap.get(storageId=aos.getStorageId());
if (Objects.isNull(socr)){
logger.warn("in buildProductVoListWithSkuDetail ComputeResult null ,AppraiseOrderStorage {}", aos);
continue;
}
Integer storageNum;
BigDecimal emOfSku = socr.getEarnestMoney().getEarnestMoney().multiply(new BigDecimal(storageNum=aos.getNum()));
GoodsVo goodsVo = GoodsVo.builder().sizeName(aos.getSizeName()).num(storageNum)
.earnestMoney(SellerOrderConvertor.formatFee(emOfSku)).build();
goodsList.add(goodsVo);
}
tempProductMap.put(prdId, ProductVo.builder().sizeNum(sizeNum).goodsList(goodsList).build());
}
return paogs.parallelStream().map(paog-> ProductConvertor.convertProductVo(paog, tempProductMap.get(paog.getProductId())))
.collect(Collectors.toCollection(()->new ArrayList<>(paogs.size())));
}
@Builder
static class OrderDataNode{
int sknNum;
List<AppraiseOrderGoods> paogs;
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap;
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap;
Map<Integer, AppraiseOrderMeta> storageIdFeeMetaMap;
}
OrderDataNode buildDataSourceOfParentOrder(long orderCode, List<AppraiseOrderGoods> paogs){
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap = new HashMap<>(paogs.size());
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap = new HashMap<>(128);
Function<AppraiseOrderMeta, SellerOrderComputeResult> socrFunction = aom -> {
SellerOrderComputeResult socr = null;
String metaVal = null;
try {
socr = JSONObject.parseObject(metaVal=aom.getMetaValue(), SellerOrderComputeResult.class);
}catch (Exception ex){
logger.warn("in convert SellerOrderComputeResult fail, ordercode {} metaVal {}", orderCode, metaVal);
}finally {
return socr;
}
};
Map<Integer, AppraiseOrderMeta> storageIdFeeMetaMap = new HashMap<>(128);
for(AppraiseOrderGoods paog : paogs){
Integer prdId;
List<AppraiseOrderStorage> paosList = appraiseOrderStorageMapper.selectAllByOrderCodePrdId(orderCode, prdId=paog.getProductId());
prdIdAOSListMap.put(prdId, paosList);
List<Integer> storageIds = paosList.parallelStream().map(AppraiseOrderStorage::getStorageId).collect(Collectors.toList());
//
AppraiseOrderMeta aomc = new AppraiseOrderMeta();
aomc.setOrderCode(orderCode);
aomc.setMetaKey(MetaKey.SELLER_FEE);
List<AppraiseOrderMeta> paomList = appraiseOrderMetaMapper.selectByOrderCodeStorageIds(aomc, storageIds);
//
storageIdFeeMetaMap.putAll(paomList.parallelStream().collect(Collectors.toMap(AppraiseOrderMeta::getStorageId, Function.identity())));
storageIdSOCRMap.putAll(paomList.parallelStream().collect(Collectors.toMap(AppraiseOrderMeta::getStorageId, socrFunction::apply)));
}
return OrderDataNode.builder().paogs(paogs)
.prdIdAOSListMap(prdIdAOSListMap)
.storageIdFeeMetaMap(storageIdFeeMetaMap)
.storageIdSOCRMap(storageIdSOCRMap)
.build();
}
}
... ...
package com.yohoufo.order.service.seller.deposit;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.constants.DepotType;
import com.yohobuy.ufo.model.order.constants.SellerDepositOrderListType;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.*;
import com.yohobuy.ufo.model.order.resp.*;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohobuy.ufo.model.order.vo.GoodsVo;
import com.yohobuy.ufo.model.order.vo.ProductVo;
import com.yohoufo.common.helper.ImageUrlAssist;
... ... @@ -24,32 +16,28 @@ import com.yohoufo.dal.order.AppraiseOrderMetaMapper;
import com.yohoufo.dal.order.AppraiseOrderStorageMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.dal.order.model.AppraiseOrderMeta;
import com.yohoufo.dal.order.model.AppraiseOrderStorage;
import com.yohoufo.order.common.ClientType;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.dto.SellerDepositOrderContext;
import com.yohoufo.order.model.dto.SellerDepositSubOrderContext;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.response.AppraiseAddressResp;
import com.yohoufo.order.service.impl.AbsOrderViewService;
import com.yohoufo.order.service.IGoodsService;
import com.yohoufo.order.service.impl.AppraiseAddressService;
import com.yohoufo.order.service.impl.AppraiseOrderCreateService;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.Builder;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class SellerDepositOrderService extends AbsOrderViewService {
public class SellerDepositOrderService implements IGoodsService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
... ... @@ -79,30 +67,11 @@ public class SellerDepositOrderService extends AbsOrderViewService {
@Autowired
private AppraiseOrderMetaService appraiseOrderMetaService;
@Autowired
private SellerDepositOrderListService sellerDepositOrderListService;
private static final List<Integer> showEXpressInfoStatusList = Lists.newArrayList(AppraiseOrderStatus.SELLER_SEND_OUT.getCode(),
AppraiseOrderStatus.WAITING_RECEIVE.getCode(),
AppraiseOrderStatus.PLATFORM_RECEIVE.getCode(),
AppraiseOrderStatus.JUDGE_PASS.getCode(),
AppraiseOrderStatus.CHECKING_FAKE.getCode(),
AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode()
);
private static final List<Integer> showUserAddressStatusList = Lists.newArrayList(AppraiseOrderStatus.SELLER_SEND_OUT.getCode(),
AppraiseOrderStatus.WAITING_RECEIVE.getCode(),
AppraiseOrderStatus.PLATFORM_RECEIVE.getCode(),
AppraiseOrderStatus.JUDGE_PASS.getCode(),
AppraiseOrderStatus.CHECKING_FAKE.getCode(),
AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode()
);
private static final List<Integer> showAppraiseAddressStatusList = Lists.newArrayList(AppraiseOrderStatus.SELLER_SEND_OUT.getCode(),
AppraiseOrderStatus.WAITING_RECEIVE.getCode(),
AppraiseOrderStatus.PLATFORM_RECEIVE.getCode(),
AppraiseOrderStatus.JUDGE_PASS.getCode(),
AppraiseOrderStatus.CHECKING_FAKE.getCode(),
AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode()
);
private static final List<Integer> addressUpgradableStatusList = Lists.newArrayList(AppraiseOrderStatus.HAS_PAYED.getCode());
@Autowired
private OrderStatusFlowService orderStatusFlowService;
... ... @@ -140,8 +109,8 @@ public class SellerDepositOrderService extends AbsOrderViewService {
OrderAttributes getOrderAttributes(){
@Override
public OrderAttributes getOrderAttributes(){
return OrderAttributes.DEPOSITE;
}
... ... @@ -182,291 +151,35 @@ public class SellerDepositOrderService extends AbsOrderViewService {
}
public PageResp<SellerDepositOrderListResp> getOrderList(SellerDepositOrderListReq req ){
PageResp.PageRespBuilder<SellerDepositOrderListResp> respBuilder = PageResp.builder();
SellerDepositOrderListType sellerDepositOrderListType = SellerDepositOrderListType.getByCode(req.getListType());
if (Objects.isNull(sellerDepositOrderListType)){
return respBuilder.build();
}
int uid = req.getUid();
OrderAttributes orderAttributes = getOrderAttributes();
final List<Integer> statusList = sellerDepositOrderListType.statusList();
int total = appraiseOrderMapper.selectCntByOrderType(uid, orderAttributes.getCode(), statusList);
int limit = req.getLimit();
if (total == 0){
return respBuilder
.pageSize(limit)
.total(total)
.page(req.getPage())
.build();
}
int offset = (req.getPage() - 1) * limit;
List<AppraiseOrder> orderList = appraiseOrderMapper.selectOrderListByOrderType(uid, orderAttributes.getCode(), statusList, offset, limit);
List<Long> orderCodes = orderList.stream().map(AppraiseOrder::getOrderCode).collect(Collectors.toList());
List<AppraiseOrderGoods> paogs = appraiseOrderGoodsMapper.selectByOrderCodes(orderCodes);
Map<Long,List<AppraiseOrderGoods>> orderCodeAOGMap = new HashMap<>(paogs.size());
for (AppraiseOrderGoods paog : paogs){
long orderCode;
List<AppraiseOrderGoods> list;
if (!orderCodeAOGMap.containsKey(orderCode=paog.getOrderCode())){
list = new ArrayList(16);
orderCodeAOGMap.put(orderCode, list);
}else{
list = orderCodeAOGMap.get(orderCode);
}
list.add(paog);
}
List<SellerDepositOrderListResp> aolrList = orderList.parallelStream()
.map(pao-> buildSellerDepositOrderListResp(pao, orderCodeAOGMap.get(pao.getOrderCode())))
.collect(Collectors.toList());
respBuilder.page(req.getPage())
.pageSize(limit)
.total(total)
.pagetotal((total % limit == 0) ? (total / limit) : (total / limit + 1))
.data(aolrList);
return respBuilder.build();
}
SellerDepositOrderListResp buildSellerDepositOrderListResp(AppraiseOrder pao, List<AppraiseOrderGoods> aogList){
int uid = pao.getUid();
long orderCode = pao.getOrderCode();
int status = pao.getStatus();
AppraiseOrderStatus appraiseOrderStatus = AppraiseOrderStatus.getByCode(status);
OrderAttributes oa = getOrderAttributes();
List<ProductVo> productList = aogList.parallelStream()
.sorted(Comparator.comparing(AppraiseOrderGoods::getOrderBy))
.map(paog -> ProductVo.builder()
.imgUrl(ImageUrlAssist.getAllProductPicUrl(paog.getImageUrl(), "goodsimg", "center", "d2hpdGU="))
.build())
.collect(Collectors.toCollection(()->new ArrayList<>(aogList.size())));
return SellerDepositOrderListResp.builder()
.uid(uid)
.orderCode(orderCode)
.status(status)
.statuStr(appraiseOrderStatus.statusStr(oa))
.buttons(appraiseOrderStatus.listButtons(oa))
.productList(productList)
.build();
}
public SellerDepositOrderDetailResp getOrderDetail(SellerDepositOrderDetailReq req){
Long orderCode = req.getOrderCode();
int uid = req.getUid();
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
OrderAttributes oa = OrderAttributes.getOrderAttributes(pao.getAttributes());
//todo use another page list query
List<AppraiseOrderGoods> paogList = appraiseOrderGoodsMapper.selectByOrderCodes(Arrays.asList(orderCode));
//
TimeoutBo timeout = calTimeout(TabType.BUY, uid, orderCode, pao.getStatus(),
pao.getCreateTime(), oa);
boolean expressShow = showEXpressInfoStatusList.contains(pao.getStatus());
//
AppraiseOrderStatus aos = AppraiseOrderStatus.getByCode(pao.getStatus());
OrderDetailInfo.StatusDetail statusDetail = OrderDetailInfo.StatusDetail
.builder()
.statuStr(aos.statusStr(oa))
.detailDesc(aos.detailDesc(oa))
.expressShow(expressShow)
.build();
//
AppraiseAddressInfo appraiseAddressInfo = null;
if(showAppraiseAddressStatusList.contains(pao.getStatus())){
AppraiseAddressResp aaResp = appraiseAddressService.findByDepotType(DepotType.NJ.getCode());
appraiseAddressInfo = AppraiseAddressService.convert2AppraiseAddressInfo(aaResp);
}
AddressInfo userAddress = null;
if (showUserAddressStatusList.contains(pao.getStatus())){
userAddress = appraiseOrderMetaService.getHidderUserAddress(orderCode);
}
boolean addressUpgradable = addressUpgradableStatusList.contains(pao.getStatus());
SellerDepositOrderPrdListReq sknListReq = SellerDepositOrderPrdListReq.builder()
.orderCode(orderCode)
.page(1).limit(10).uid(uid).build();
PageResp<ProductVo> sknListPageResp = getSknList(sknListReq);
return SellerDepositOrderDetailResp.builder()
.orderCode(orderCode)
.uid(uid)
.earnestMoney(SellerOrderConvertor.formatFee(pao.getAmount()))
.createTime(DateUtil.formatDate(pao.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS))
.timeout(timeout)
.statusDetail(statusDetail)
.productList(sknListPageResp.getData())
.userAddress(userAddress)
.appraiseAddress(appraiseAddressInfo)
.addressUpgradable(addressUpgradable)
.build()
;
}
public PageResp<ProductVo> getSknList(SellerDepositOrderPrdListReq req){
Long orderCode = req.getOrderCode();
int total = appraiseOrderGoodsMapper.selectCntByOrderCode(orderCode);
int limit = req.getLimit();
PageResp.PageRespBuilder<ProductVo> respBuilder = PageResp.builder();
respBuilder.page(req.getPage()).pageSize(limit).total(total);
if (total == 0){
return respBuilder.build();
}
int offset = (req.getPage() - 1) * limit;
List<AppraiseOrderGoods> paogs = appraiseOrderGoodsMapper.selectAllByOrderCode(orderCode, offset, limit);
List<ProductVo> productVoList = buildProductVoListWithSkuSummary(paogs);
respBuilder.data(productVoList);
return respBuilder.build();
}
List<ProductVo> buildProductVoListWithSkuSummary(List<AppraiseOrderGoods> paogs){
return paogs.parallelStream().map(paog-> convertProductVo(paog, null))
.collect(Collectors.toCollection(()->new ArrayList<>(paogs.size())));
}
@Builder
private class OrderDataNode{
int sknNum;
List<AppraiseOrderGoods> paogs;
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap;
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap;
Map<Integer, AppraiseOrderMeta> storageIdFeeMetaMap;
}
OrderDataNode buildDataSourceOfParentOrder(long orderCode, List<AppraiseOrderGoods> paogs){
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap = new HashMap<>(paogs.size());
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap = new HashMap<>(128);
Function<AppraiseOrderMeta, SellerOrderComputeResult> socrFunction = aom -> {
SellerOrderComputeResult socr = null;
String metaVal = null;
try {
socr = JSONObject.parseObject(metaVal=aom.getMetaValue(), SellerOrderComputeResult.class);
}catch (Exception ex){
logger.warn("in convert SellerOrderComputeResult fail, ordercode {} metaVal {}", orderCode, metaVal);
}finally {
return socr;
}
};
Map<Integer, AppraiseOrderMeta> storageIdFeeMetaMap = new HashMap<>(128);
for(AppraiseOrderGoods paog : paogs){
Integer prdId;
List<AppraiseOrderStorage> paosList = appraiseOrderStorageMapper.selectAllByOrderCodePrdId(orderCode, prdId=paog.getProductId());
prdIdAOSListMap.put(prdId, paosList);
List<Integer> storageIds = paosList.parallelStream().map(AppraiseOrderStorage::getStorageId).collect(Collectors.toList());
//
AppraiseOrderMeta aomc = new AppraiseOrderMeta();
aomc.setOrderCode(orderCode);
aomc.setMetaKey(MetaKey.SELLER_FEE);
List<AppraiseOrderMeta> paomList = appraiseOrderMetaMapper.selectByOrderCodeStorageIds(aomc, storageIds);
//
storageIdFeeMetaMap.putAll(paomList.parallelStream().collect(Collectors.toMap(AppraiseOrderMeta::getStorageId, Function.identity())));
storageIdSOCRMap.putAll(paomList.parallelStream().collect(Collectors.toMap(AppraiseOrderMeta::getStorageId, socrFunction::apply)));
}
return OrderDataNode.builder().paogs(paogs)
.prdIdAOSListMap(prdIdAOSListMap)
.storageIdFeeMetaMap(storageIdFeeMetaMap)
.storageIdSOCRMap(storageIdSOCRMap)
.build();
}
public PageResp<ProductVo> getSkuList(SellerDepositOrderPrdListReq req){
final Long orderCode = req.getOrderCode();
int total = appraiseOrderGoodsMapper.selectCntByOrderCode(orderCode);
int limit = req.getLimit();
PageResp.PageRespBuilder<ProductVo> respBuilder = PageResp.builder();
respBuilder.page(req.getPage()).pageSize(limit).total(total);
if (total == 0){
return respBuilder.build();
}
int offset = (req.getPage() - 1) * limit;
List<AppraiseOrderGoods> paogs = appraiseOrderGoodsMapper.selectAllByOrderCode(orderCode, offset, limit);
OrderDataNode node = buildDataSourceOfParentOrder(orderCode, paogs);
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap = node.prdIdAOSListMap;
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap = node.storageIdSOCRMap;
List<ProductVo> productVoList = buildProductVoListWithSkuDetail(paogs, prdIdAOSListMap, storageIdSOCRMap);
respBuilder.data(productVoList);
return respBuilder.build();
public PageResp<DepositOrderInStorePrdListResp> getDepositOrderListInStore(SellerDepositOrderPrdListReq req){
return null;
}
List<ProductVo> buildProductVoListWithSkuDetail(List<AppraiseOrderGoods> paogs,
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap,
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap){
Map<Integer,ProductVo> tempProductMap = new HashMap<>(paogs.size());
for(Map.Entry<Integer,List<AppraiseOrderStorage>> prdIdAOSListEntry : prdIdAOSListMap.entrySet()){
Integer prdId = prdIdAOSListEntry.getKey();
List<AppraiseOrderStorage> aosList = prdIdAOSListEntry.getValue();
int sizeNum = aosList.size();
List<GoodsVo> goodsList = new ArrayList<>(sizeNum);
for (AppraiseOrderStorage aos : aosList){
Integer storageId;
SellerOrderComputeResult socr = storageIdSOCRMap.get(storageId=aos.getStorageId());
if (Objects.isNull(socr)){
logger.warn("in buildProductVoListWithSkuDetail ComputeResult null ,AppraiseOrderStorage {}", aos);
continue;
}
Integer storageNum;
BigDecimal emOfSku = socr.getEarnestMoney().getEarnestMoney().multiply(new BigDecimal(storageNum=aos.getNum()));
GoodsVo goodsVo = GoodsVo.builder().sizeName(aos.getSizeName()).num(storageNum)
.earnestMoney(SellerOrderConvertor.formatFee(emOfSku)).build();
goodsList.add(goodsVo);
}
tempProductMap.put(prdId, ProductVo.builder().sizeNum(sizeNum).goodsList(goodsList).build());
}
return paogs.parallelStream().map(paog-> convertProductVo(paog, tempProductMap.get(paog.getProductId())))
.collect(Collectors.toCollection(()->new ArrayList<>(paogs.size())));
}
public void cancel(SellerDepositOrderDetailReq req){
ProductVo convertProductVo(AppraiseOrderGoods paog, ProductVo temp){
ProductVo productVo = ProductVo.builder()
.imgUrl(ImageUrlAssist.getAllProductPicUrl(paog.getImageUrl(), "goodsimg", "center", "d2hpdGU="))
.productName(paog.getProductName())
.productId(paog.getProductId())
.total(paog.getNum()).build();
if (Objects.nonNull(temp)){
productVo.setSizeNum(temp.getSizeNum());
productVo.setGoodsList(temp.getGoodsList());
}
return productVo;
}
public PageResp<DepositOrderInStorePrdListResp> getDepositOrderListInStore(SellerDepositOrderPrdListReq req){
return null;
}
public void deliverToDepot(DeliverToDepotReq req){
@Override
public int deliver2Depot(DeliverToDepotReq req) {
//
Long orderCode = req.getOrderCode();
AppraiseOrderStatus targetStatus = AppraiseOrderStatus.SELLER_SEND_OUT,
expectedStatus = AppraiseOrderStatus.HAS_PAYED;
expectedStatus = AppraiseOrderStatus.HAS_PAYED;
int cdt = DateUtil.getCurrentTimeSecond();
int rows = appraiseOrderMapper.updateStatusByOrderCode(orderCode, targetStatus.getCode(), expectedStatus.getCode(), cdt);
if (rows==0){
logger.warn("appraise order deliverToDepot no need update status, req {}", req);
return;
return 0;
}
orderStatusFlowService.addAsy(orderCode, targetStatus.getCode());
//split sku 2 order
List<AppraiseOrderGoods> paogList = appraiseOrderGoodsMapper.selectByOrderCode(orderCode);
OrderDataNode node = buildDataSourceOfParentOrder(orderCode, paogList);
SellerDepositOrderListService.OrderDataNode node = sellerDepositOrderListService.buildDataSourceOfParentOrder(orderCode, paogList);
Map<Integer,List<AppraiseOrderStorage>> prdIdAOSListMap = node.prdIdAOSListMap;
Map<Integer,SellerOrderComputeResult> storageIdSOCRMap = node.storageIdSOCRMap;
... ... @@ -482,19 +195,42 @@ public class SellerDepositOrderService extends AbsOrderViewService {
//todo add express info
return rows;
}
/**
* 平台收货
* @param orderCode
*/
@Override
public void platformReceiveGoods(long orderCode){
public void cancel(SellerDepositOrderDetailReq req){
}
/**
* 鉴定通过
* @param orderCode
*/
@Override
public void appraisePass(long orderCode){
}
public Logger getLogger() {
return logger;
/**
* 鉴别为假
* @param orderCode
*/
@Override
public void appraiseFake(long orderCode){
}
/**
* 无法鉴别
* @param orderCode
*/
@Override
protected String buildOrderTypeTag(Integer orderAttr, SkupType skupType) {
return null;
public void unsure(long orderCode){
}
}
... ...