|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
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.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.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.resp.*;
|
|
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.utils.AddressUtil;
|
|
|
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.model.AppraiseOrder;
|
|
|
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.AppraiseOrderMeta;
|
|
|
import com.yohoufo.dal.order.model.QiniuLiveRecord;
|
|
|
import com.yohoufo.order.common.ClientType;
|
|
|
import com.yohoufo.order.constants.MetaKey;
|
|
|
import com.yohoufo.order.convert.AppraiseOrderGoodsConvertor;
|
|
|
import com.yohoufo.order.model.dto.AppraiseOrderContext;
|
|
|
import com.yohoufo.order.service.proxy.UserProxyService;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
...
|
...
|
@@ -31,7 +39,10 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class AppraiseOrderService {
|
...
|
...
|
@@ -51,7 +62,13 @@ public class AppraiseOrderService { |
|
|
|
|
|
|
|
|
@Autowired
|
|
|
OrderCodeGenerator orderCodeGenerator;
|
|
|
private OrderCodeGenerator orderCodeGenerator;
|
|
|
|
|
|
@Autowired
|
|
|
private AppraiseOrderMetaMapper appraiseOrderMetaMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private QiniuLiveRecordService qiniuLiveRecordService;
|
|
|
|
|
|
|
|
|
public AppraiseOrderComputeResp compute(AppraiseOrderComputeReq req){
|
...
|
...
|
@@ -64,24 +81,7 @@ public class AppraiseOrderService { |
|
|
if (productId <= 0){
|
|
|
throw new UfoServiceException(400, "商品ID错误");
|
|
|
}
|
|
|
int orderType = req.getOrderType();
|
|
|
OrderAttributes orderAttributes = checkOrderType(orderType);
|
|
|
double fee = 0D;
|
|
|
switch (orderAttributes){
|
|
|
case DEPOSITE:{
|
|
|
fee = 15D;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case APPRAISE:{
|
|
|
fee = 31D;
|
|
|
break;
|
|
|
}
|
|
|
default:{
|
|
|
throw new UfoServiceException(400, "orderType错误");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
double fee = 15D;
|
|
|
return AppraiseOrderComputeResp.builder().fee(String.valueOf(fee)).build();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -91,6 +91,7 @@ public class AppraiseOrderService { |
|
|
add(OrderAttributes.APPRAISE);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
private OrderAttributes checkOrderType(int orderType){
|
|
|
OrderAttributes oa = OrderAttributes.getOrderAttributes(orderType);
|
|
|
if (Objects.isNull(oa) || !legalOrderTypes.contains(oa)){
|
...
|
...
|
@@ -110,8 +111,6 @@ public class AppraiseOrderService { |
|
|
|
|
|
AppraiseOrderGoodsBo aog = new AppraiseOrderGoodsBo();
|
|
|
//TODO dependency product service support produce data
|
|
|
|
|
|
|
|
|
AppraiseOrderContext aoc = AppraiseOrderContext.builder()
|
|
|
.orderCode(orderCode)
|
|
|
.uid(pn.getUid())
|
...
|
...
|
@@ -119,6 +118,8 @@ public class AppraiseOrderService { |
|
|
.backAddress(pn.getNoHiddenBackAddress())
|
|
|
.backHiddenAddress(pn.getHiddenBackAddress())
|
|
|
.goodsBo(aog)
|
|
|
.channelNo(req.getChannelNo())
|
|
|
.clientType(ClientType.getClientType(req.getClientType()))
|
|
|
.build();
|
|
|
|
|
|
//2 persistent key info
|
...
|
...
|
@@ -128,6 +129,8 @@ public class AppraiseOrderService { |
|
|
AppraiseOrderCreateService.SubmitResult submitResult = appraiseOrderCreateService.create(aoc);
|
|
|
|
|
|
//todo notice by async
|
|
|
|
|
|
//resp
|
|
|
AppraiseOrderSubmitResp aosr = new AppraiseOrderSubmitResp();
|
|
|
aosr.setOrderCode(orderCode);
|
|
|
return aosr;
|
...
|
...
|
@@ -143,6 +146,10 @@ public class AppraiseOrderService { |
|
|
OrderAttributes orderAttributes;
|
|
|
}
|
|
|
|
|
|
OrderAttributes getOrderAttributes(){
|
|
|
return OrderAttributes.APPRAISE;
|
|
|
}
|
|
|
|
|
|
private PreparedNode checkAndAcquire(AppraiseOrderSubmitReq req){
|
|
|
int uid = req.getUid();
|
|
|
if (uid<=0){
|
...
|
...
|
@@ -152,7 +159,7 @@ public class AppraiseOrderService { |
|
|
if (productId <= 0){
|
|
|
throw new UfoServiceException(400, "商品ID错误");
|
|
|
}
|
|
|
OrderAttributes orderAttributes = OrderAttributes.APPRAISE;
|
|
|
final OrderAttributes orderAttributes = getOrderAttributes();
|
|
|
|
|
|
int addressId = AddressUtil.getDecryptStr(req.getAddressId());
|
|
|
if (addressId < 0){
|
...
|
...
|
@@ -179,23 +186,151 @@ public class AppraiseOrderService { |
|
|
.build();
|
|
|
}
|
|
|
|
|
|
List<Integer> getLegalStatus(){
|
|
|
|
|
|
return new ArrayList<Integer>(){
|
|
|
{
|
|
|
add(AppraiseOrderStatus.HAS_PAYED.getCode());
|
|
|
add(AppraiseOrderStatus.SELLER_SEND_OUT.getCode());
|
|
|
add(AppraiseOrderStatus.PLATFORM_RECEIVE.getCode());
|
|
|
add(AppraiseOrderStatus.JUDGE_PASS.getCode());
|
|
|
add(AppraiseOrderStatus.WAITING_RECEIVE.getCode());
|
|
|
add(AppraiseOrderStatus.CHECKING_FAKE.getCode());
|
|
|
add(AppraiseOrderStatus.SHAM_SEND_OUT.getCode());
|
|
|
add(AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE.getCode());
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
public PageResp<AppraiseOrderListResp> getOrderList(AppraiseOrderListReq req){
|
|
|
PageResp.PageRespBuilder respBuilder = PageResp.builder();
|
|
|
int uid = req.getUid();
|
|
|
OrderAttributes orderAttributes = getOrderAttributes();
|
|
|
final List<Integer> statusList = getLegalStatus();
|
|
|
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();
|
|
|
}
|
|
|
|
|
|
public AppraiseOrderListResp getOrderList(AppraiseOrderListReq req){
|
|
|
int offset = (req.getPage() - 1) * limit;
|
|
|
|
|
|
List<AppraiseOrder> orderList = appraiseOrderMapper.selectOrderListByOrderType(uid, orderAttributes.getCode(), statusList, offset, limit);
|
|
|
|
|
|
return null;
|
|
|
List<Long> orderCodes = orderList.stream().map(AppraiseOrder::getOrderCode).collect(Collectors.toList());
|
|
|
List<AppraiseOrderGoods> paogs = appraiseOrderGoodsMapper.selectByOrderCodes(orderCodes);
|
|
|
Map<Long,AppraiseOrderGoods> orderCodeAOGMap = paogs.stream().collect(Collectors.toMap(AppraiseOrderGoods::getOrderCode, Function.identity()));
|
|
|
List<AppraiseOrderListResp> aolrList = orderList.parallelStream()
|
|
|
.map(pao-> buildAppraiseOrderListResp(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();
|
|
|
}
|
|
|
|
|
|
AppraiseOrderListResp buildAppraiseOrderListResp(AppraiseOrder pao, AppraiseOrderGoods paog){
|
|
|
Integer uid = pao.getUid();
|
|
|
Long orderCode = pao.getOrderCode();
|
|
|
Integer status = pao.getStatus();
|
|
|
|
|
|
AppraiseOrderStatus aos = AppraiseOrderStatus.getByCode(status);
|
|
|
|
|
|
|
|
|
|
|
|
AppraiseOrderListResp resp = AppraiseOrderListResp.builder()
|
|
|
.uid(uid)
|
|
|
.orderCode(orderCode)
|
|
|
.goodsInfo(AppraiseOrderGoodsConvertor.do2Bo(paog))
|
|
|
.buttons(Objects.nonNull(aos) ? aos.listButtons() : null)
|
|
|
.statuStr(Objects.nonNull(aos) ? aos.statusStr() : "")
|
|
|
.status(status)
|
|
|
.build();
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AppraiseOrderDetailResp getOrderDetail(AppraiseOrderDetailReq req){
|
|
|
int uid = req.getUid();
|
|
|
long orderCode = req.getOrderCode();
|
|
|
|
|
|
return null;
|
|
|
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
|
|
|
if (Objects.isNull(pao)){
|
|
|
logger.warn("in getOrderDetail of appraise order null ,req {}", req);
|
|
|
return null;
|
|
|
}
|
|
|
Integer aoac = pao.getAttributes();
|
|
|
OrderAttributes oa = OrderAttributes.getOrderAttributes(aoac);
|
|
|
if (Objects.isNull(oa) || !getOrderAttributes().equals(oa)){
|
|
|
logger.warn("in getOrderDetail of appraise order attr is null ,req {}", req);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
AppraiseOrderGoods paog = appraiseOrderGoodsMapper.selectByOrderCode(orderCode);
|
|
|
|
|
|
|
|
|
Integer status = pao.getStatus();
|
|
|
AppraiseOrderStatus aos = AppraiseOrderStatus.getByCode(status);
|
|
|
//
|
|
|
OrderDetailInfo.StatusDetail statusDetail = OrderDetailInfo.StatusDetail
|
|
|
.builder().status(status)
|
|
|
.statuStr(aos.statusStr())
|
|
|
.detailDesc(aos.detailDesc()).build();
|
|
|
//
|
|
|
String hidden_key = MetaKey.BUYER_DELIVERY_HIDDEN_ADDRESS;
|
|
|
AppraiseOrderMeta aomc = new AppraiseOrderMeta();
|
|
|
aomc.setOrderCode(orderCode);
|
|
|
aomc.setMetaKey(hidden_key);
|
|
|
AppraiseOrderMeta paom = appraiseOrderMetaMapper.selectByOrderCode(aomc);
|
|
|
AppraiseAddressInfo appraiseAddressInfo = null;
|
|
|
if (Objects.nonNull(paom)){
|
|
|
try {
|
|
|
appraiseAddressInfo = JSONObject.parseObject(paom.getMetaValue(), AppraiseAddressInfo.class);
|
|
|
}catch (Exception ex){
|
|
|
logger.warn("in get detail of appraise order ");
|
|
|
}
|
|
|
}
|
|
|
String appraiseVideoUrl = null;
|
|
|
QiniuLiveRecord qiniuLiveRecord = qiniuLiveRecordService.getByOrderCode(orderCode);
|
|
|
if (Objects.nonNull(qiniuLiveRecord)){
|
|
|
appraiseVideoUrl = qiniuLiveRecord.getVideoUrl();
|
|
|
}
|
|
|
AppraiseOrderDetailResp aodResp = AppraiseOrderDetailResp.builder()
|
|
|
.uid(uid).orderCode(orderCode)
|
|
|
.statusDetail(statusDetail)
|
|
|
.createTime(DateUtil.formatDate(pao.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS))
|
|
|
.goodsInfo(AppraiseOrderGoodsConvertor.do2Bo(paog))
|
|
|
.appraiseAddress(appraiseAddressInfo)
|
|
|
.appraiseVideoUrl(appraiseVideoUrl)
|
|
|
.build();
|
|
|
return aodResp;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否付费鉴定订单
|
|
|
* @param uid
|
|
|
* @param orderCode
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isAppraiseOrder(int uid, long orderCode){
|
|
|
|
|
|
return false;
|
|
|
AppraiseOrder pao = appraiseOrderMapper.selectByOrderCode(orderCode);
|
|
|
Integer aoac = null;
|
|
|
OrderAttributes oa = null;
|
|
|
boolean flag = Objects.nonNull(pao)
|
|
|
&& Objects.nonNull(aoac=pao.getAttributes())
|
|
|
&& Objects.nonNull(oa = OrderAttributes.getOrderAttributes(aoac))
|
|
|
&& Objects.equals(oa, OrderAttributes.APPRAISE);
|
|
|
logger.info("in isAppraiseOrder uid {} orderCode {} aoac {} oa {} flag {}",
|
|
|
uid, orderCode, aoac, oa, flag);
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -208,7 +343,7 @@ public class AppraiseOrderService { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* 平台收货
|
|
|
* @param orderCode
|
|
|
*/
|
|
|
public void platformReceiveGoods(long orderCode){
|
...
|
...
|
@@ -216,7 +351,7 @@ public class AppraiseOrderService { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* 鉴定通过
|
|
|
* @param orderCode
|
|
|
*/
|
|
|
public void appraisePass(long orderCode){
|
...
|
...
|
|