|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.AppraiseOrderGoodsBo;
|
|
|
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.resp.AppraiseOrderComputeResp;
|
|
|
import com.yohobuy.ufo.model.order.resp.AppraiseOrderDetailResp;
|
|
|
import com.yohobuy.ufo.model.order.resp.AppraiseOrderListResp;
|
|
|
import com.yohobuy.ufo.model.order.resp.AppraiseOrderSubmitResp;
|
|
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.utils.AddressUtil;
|
|
|
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.AppraiseOrderMapper;
|
|
|
import com.yohoufo.order.model.dto.AppraiseOrderContext;
|
|
|
import com.yohoufo.order.service.proxy.UserProxyService;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import com.yohoufo.order.utils.AddressHelper;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import lombok.Builder;
|
|
|
import lombok.Data;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -10,8 +34,127 @@ public class AppraiseOrderService { |
|
|
|
|
|
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderMapper appraiseOrderMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private UserProxyService userProxyService;
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderCreateService appraiseOrderCreateService;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
OrderCodeGenerator orderCodeGenerator;
|
|
|
|
|
|
|
|
|
public AppraiseOrderComputeResp compute(AppraiseOrderComputeReq req){
|
|
|
logger.info("in AppraiseOrderService.compute req {}", req);
|
|
|
int uid = req.getUid();
|
|
|
if (uid<=0){
|
|
|
throw new UfoServiceException(400, "uid错误");
|
|
|
}
|
|
|
int productId = req.getProductId();
|
|
|
if (productId <= 0){
|
|
|
throw new UfoServiceException(400, "商品ID错误");
|
|
|
}
|
|
|
|
|
|
double fee = 15D;
|
|
|
return AppraiseOrderComputeResp.builder().fee(String.valueOf(fee)).build();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AppraiseOrderSubmitResp submit(AppraiseOrderSubmitReq req){
|
|
|
//1. check
|
|
|
PreparedNode pn = checkAndAcquire(req);
|
|
|
// 生成订单号
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.BUYER_TYPE);
|
|
|
logger.info("AppraiseOrder.submit req {} ,generate new orderCode:{}", req, orderCode);
|
|
|
|
|
|
AppraiseOrderGoodsBo aog = new AppraiseOrderGoodsBo();
|
|
|
//TODO dependency product service support produce data
|
|
|
|
|
|
|
|
|
AppraiseOrderContext aoc = AppraiseOrderContext.builder()
|
|
|
.orderCode(orderCode)
|
|
|
.uid(pn.getUid())
|
|
|
.productId(pn.getProductId())
|
|
|
.backAddress(pn.getNoHiddenBackAddress())
|
|
|
.backHiddenAddress(pn.getHiddenBackAddress())
|
|
|
.goodsBo(aog)
|
|
|
.build();
|
|
|
|
|
|
//2 persistent key info
|
|
|
//2.1 appraise order
|
|
|
//2.2 appraise order goods
|
|
|
//2.3 address
|
|
|
AppraiseOrderCreateService.SubmitResult submitResult = appraiseOrderCreateService.create(aoc);
|
|
|
|
|
|
//todo notice by async
|
|
|
AppraiseOrderSubmitResp aosr = new AppraiseOrderSubmitResp();
|
|
|
aosr.setOrderCode(orderCode);
|
|
|
return aosr;
|
|
|
}
|
|
|
|
|
|
@Data
|
|
|
@Builder
|
|
|
private static class PreparedNode{
|
|
|
int uid;
|
|
|
int productId;
|
|
|
AddressInfo hiddenBackAddress;
|
|
|
AddressInfo noHiddenBackAddress;
|
|
|
}
|
|
|
|
|
|
private PreparedNode checkAndAcquire(AppraiseOrderSubmitReq req){
|
|
|
int uid = req.getUid();
|
|
|
if (uid<=0){
|
|
|
throw new UfoServiceException(400, "uid错误");
|
|
|
}
|
|
|
int productId = req.getProductId();
|
|
|
if (productId <= 0){
|
|
|
throw new UfoServiceException(400, "商品ID错误");
|
|
|
}
|
|
|
|
|
|
int addressId = AddressUtil.getDecryptStr(req.getAddressId());
|
|
|
if (addressId < 0){
|
|
|
logger.warn("submit appraise order addressId invalidate, uid {}, productId {}, addressId {}",
|
|
|
uid, productId, req.getAddressId());
|
|
|
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
|
|
|
}
|
|
|
|
|
|
//the address of send back 2 seller
|
|
|
AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
|
|
|
AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);
|
|
|
if(AddressHelper.isNeedUpdate(noHiddenBackAddress)){
|
|
|
logger.warn("submit appraise order addressId need update, uid {}, appraise {}, addressId {}",
|
|
|
uid, productId, addressId);
|
|
|
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
|
|
|
}
|
|
|
|
|
|
return PreparedNode.builder()
|
|
|
.uid(uid)
|
|
|
.productId(productId)
|
|
|
.hiddenBackAddress(hiddenBackAddress)
|
|
|
.noHiddenBackAddress(noHiddenBackAddress)
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AppraiseOrderListResp getOrderList(AppraiseOrderListReq req){
|
|
|
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
public AppraiseOrderDetailResp getOrderDetail(AppraiseOrderDetailReq req){
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
} |
...
|
...
|
|