Authored by sailing-PC\sailing

add cache

... ... @@ -2,20 +2,18 @@ package com.yohoufo.order.service.cache;
import com.alibaba.fastjson.JSON;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.vo.OrderListVo;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.common.cache.SnappyZipUtils;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by chenchao on 2018/10/16.
*/
... ... @@ -46,20 +44,22 @@ public class OrderCacheService {
return cacheClient.hashGet(key, hashKey, Integer.class);
}
public void cacheOrderList(OrderListRequest req, List<OrderListInfo> orderListInfos){
public void cacheOrderList(OrderListRequest req, OrderListVo orderListInfos){
String hashKey = CacheKeyBuilder.orderListHashKey(req);
String key = CacheKeyBuilder.orderListKey(req.getUid(), req.getTabType()).getKey();
try{
String hashValue = JSON.toJSONString(orderListInfos);
String compressHashValue = SnappyZipUtils.compress(hashValue);
cacheClient.hashPut(key, hashKey, compressHashValue, ExpiredTime.ORDER_LIST);
logger.info("put OrderList cache ,req {} key {} hashKey {}", req, key, hashKey);
}catch (Exception ex){
logger.warn("in cacheOrderList fail ,req {}", req);
}
}
public List<OrderListInfo> getOrderListInfos(OrderListRequest req){
public OrderListVo getOrderListInfos(OrderListRequest req){
logger.info("hit OrderList cache ,req {}", req);
String hashKey = CacheKeyBuilder.orderListHashKey(req);
try{
String key = CacheKeyBuilder.orderListKey(req.getUid(), req.getTabType()).getKey();
... ... @@ -67,7 +67,7 @@ public class OrderCacheService {
String uncompressHashValue = SnappyZipUtils.uncompress(hashVal);
if (StringUtils.isNotEmpty(uncompressHashValue)) {
return JSON.parseArray(uncompressHashValue, OrderListInfo.class);
return JSON.parseObject(uncompressHashValue, OrderListVo.class);
} else {
return null;
}
... ... @@ -81,10 +81,12 @@ public class OrderCacheService {
public void cacheOrderDetailInfo(int uid, long orderCode, OrderDetailInfo orderDetailInfo){
RedisKeyBuilder kb = CacheKeyBuilder.orderDetailKey(uid, orderCode);
cacheClient.set(kb.getKey(), ExpiredTime.ORDER_DETAIL , orderDetailInfo);
logger.info("put OrderDetail cache ,uid {} orderCode {}", uid, orderCode);
}
public OrderDetailInfo getOrderDetailInfo(int uid, long orderCode){
logger.info("hit OrderDetail cache ,uid {} orderCode {}", uid, orderCode);
RedisKeyBuilder kb = CacheKeyBuilder.orderDetailKey(uid, orderCode);
OrderDetailInfo orderDetailInfo = cacheClient.get(kb.getKey(), OrderDetailInfo.class);
return orderDetailInfo;
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
... ... @@ -27,6 +28,8 @@ import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.utils.SmsHelper;
import org.slf4j.Logger;
... ... @@ -35,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
/**
... ... @@ -74,6 +78,9 @@ public class AppraiseService {
@Autowired
private IBuyerOrderMetaService buyerOrderMetaService;
@Autowired
private CacheCleaner cacheCleaner;
public ApiResponse appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum){
ApiResponse apiResponse=new ApiResponse();
... ... @@ -175,6 +182,11 @@ public class AppraiseService {
apiResponse.setMessage(content);
}
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.orderDetailKey(sellerUid, orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid, orderCode)));
LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, sellerOrderCode, skup, earnestMoney );
... ... @@ -238,6 +250,10 @@ public class AppraiseService {
tso.setExceptStatus(expectSOStatus.getCode());
int soCnt = sellerOrderMapper.updateByOrderCode(tso);
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.orderDetailKey(sellerUid, orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid, orderCode)));
//将卖家的保证金分账给平台和买家
TransferCase transferCase = TransferCase.APPRAISE_FAIL;
... ...
... ... @@ -2,7 +2,9 @@ package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.vo.OrderListVo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
... ... @@ -21,6 +23,9 @@ import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.OrderDetailInfo;
import com.yohoufo.order.model.response.OrderSummaryResp;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.utils.SmsHelper;
... ... @@ -29,6 +34,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Objects;
@Service
... ... @@ -64,6 +70,12 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
@Autowired
private SellerAddressService sellerAddressService;
@Autowired
private OrderCacheService orderCacheService;
@Autowired
private CacheCleaner cacheCleaner;
/**
* 提交订单
* @param orderRequest
... ... @@ -72,12 +84,15 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
OrderStatus expectStatus = OrderStatus.WAITING_RECEIVE;
// 参数检查 ![待收货] 不合法
DataNode node = checkStatusAndRequest(orderRequest, expectStatus);
int uid;
long orderCode;
// TODO 更新状态为已收货、SKUP的状态应该还是已出售
if (1 == buyerOrderMapper.updateStatusByOrderCode(orderRequest.getOrderCode(), orderRequest.getUid(),
if (1 == buyerOrderMapper.updateStatusByOrderCode(orderCode=orderRequest.getOrderCode(), uid=orderRequest.getUid(),
expectStatus.getCode(),
OrderStatus.DONE.getCode(),
DateUtil.getCurrentTimeSecond())) {
// TODO 分账操作
cacheCleaner.cleanDetail(uid, orderCode);
} else {
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE); // 更新失败,可能是因为订单状态已经被并发修改
}
... ... @@ -112,15 +127,16 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
// 更新订单状态
final OrderStatus orderStatus = targetStatus;
final long orderCode;
final int buyerUid;
BuyerOrder tbo = new BuyerOrder();
tbo.setStatus(orderStatus.getCode());
tbo.setUid(orderRequest.getUid());
tbo.setOrderCode(orderRequest.getOrderCode());
tbo.setUid(buyerUid = orderRequest.getUid());
tbo.setOrderCode(orderCode = orderRequest.getOrderCode());
tbo.setUpdateTime(DateUtil.getCurrentTimeSecond());
buyerOrderMapper.updateByOrderCode(tbo);
// 更新skup的状态[出售中] 卖家订单为[可售]
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(), orderRequest.getOrderCode());
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(), orderCode);
int skup = bog.getSkup();
SellerOrderGoods psog= sellerOrderGoodsMapper.selectByPrimaryKey(skup);
Integer skupStatus = psog.getStatus();
... ... @@ -130,13 +146,22 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
tsog.setStatus(SkupStatus.CAN_SELL.getCode());
sellerOrderGoodsMapper.updateByPrimaryKeySelective(tsog);
// 恢复product skup的库存
boolean isReturnSuccess = productProxyService.returnStorage(skup);
//
int sellerUid = dataNode.buyerOrderInDB.getSellerUid();
AddressInfo addressInfo = sellerAddressService.getAddressInfo(sellerUid, skup);
inBoxFacade.noticSellerWhenBuyerCancel(sellerUid, psog.getProductName(), SmsHelper.getPhones(addressInfo));
inBoxFacade.buyerCancelOrder(orderRequest.getUid(), orderRequest.getOrderCode());
inBoxFacade.buyerCancelOrder(orderRequest.getUid(), orderCode);
//
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.orderDetailKey(sellerUid, orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid, orderCode)));
}
... ... @@ -181,12 +206,44 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
@Override
public OrderDetailInfo getOrderDetail(OrderRequest orderRequest) {
return buyerOrderDetailService.getOrderDetail(orderRequest);
int uid;
long orderCode;
OrderDetailInfo orderDetailInfo = orderCacheService.getOrderDetailInfo(uid = orderRequest.getUid(), orderCode=orderRequest.getOrderCode());
if(Objects.nonNull(orderDetailInfo)){
return orderDetailInfo;
}
orderDetailInfo = buyerOrderDetailService.getOrderDetail(orderRequest);
if(Objects.nonNull(orderDetailInfo)){
orderCacheService.cacheOrderDetailInfo(uid, orderCode, orderDetailInfo);
}
return orderDetailInfo;
}
@Override
public PageResp getOrderList(OrderListRequest request) {
return buyerOrderListService.getOrderList(request);
OrderListVo orderListVo = orderCacheService.getOrderListInfos(request);
PageResp.PageRespBuilder respBuilder;
if (Objects.nonNull(orderListVo)){
respBuilder = PageResp.builder()
.page(request.getPage())
.pageSize(orderListVo.getPageSize())
.total(orderListVo.getTotal())
.pagetotal(orderListVo.getPagetotal());;
return respBuilder.data(orderListVo.getOrderList()).build();
}
PageResp orderListInfoRsp = buyerOrderListService.getOrderList(request);
if (orderListInfoRsp != null){
orderListVo = OrderListVo.builder().page(orderListInfoRsp.getPage())
.pageSize(orderListInfoRsp.getPageSize())
.orderList(orderListInfoRsp.getData())
.total(orderListInfoRsp.getTotal())
.pagetotal(orderListInfoRsp.getPagetotal()).build();
orderCacheService.cacheOrderList(request, orderListVo);
}
return orderListInfoRsp;
}
... ... @@ -196,7 +253,14 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
* @return
*/
public OrderSummaryResp selectOrderNumByUid(int uid) {
Integer num = buyerOrderMapper.selectOrderNumByUid(uid);
Integer num =orderCacheService.getOrderSummary(uid, TabType.BUY);
if (num == null){
num = buyerOrderMapper.selectOrderNumByUid(uid);
}
if (num != null){
orderCacheService.cacheOrderSummary(uid, TabType.BUY, num);
}
return null == num ? new OrderSummaryResp("buy", 0) : new OrderSummaryResp("buy", num);
}
... ... @@ -220,7 +284,11 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
BuyerOrder target = new BuyerOrder();
target.setId(buyerOrder.getId());
target.setBuyerOrderStatus(DelStatus.IS_DEL.getCode());
return buyerOrderMapper.updateByPrimaryKeySelective(target) == 1;
boolean result = buyerOrderMapper.updateByPrimaryKeySelective(target) == 1;
if(result){
cacheCleaner.cleanList(uid, TabType.BUY.getValue());
}
return result;
}else{
logger.warn("buyer delete fail, order status {}", status);
}
... ...
... ... @@ -2,10 +2,7 @@ package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.common.*;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.utils.DateUtil;
... ... @@ -30,6 +27,7 @@ import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.mq.producer.TradeMqSender;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.impl.visitor.AutoCancelCase;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
... ... @@ -252,6 +250,9 @@ public class SellerOrderCancelService {
//TODO 1. cache goods 2. async execute msg
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.sellerPlaySelf(uid,psog.getProductName());
cacheCleaner.cleanList(uid, TabType.SELL.getValue());
cacheCleaner.cleanDetail(uid, orderCode);
}
return result;
... ... @@ -338,6 +339,11 @@ public class SellerOrderCancelService {
tbo.setUpdateTime(DateUtil.getCurrentTimeSecond());
result += buyerOrderMapper.updateByOrderCode(tbo);
if(result > 0) {
cacheCleaner.cleanList(buyerUid, TabType.BUY.getValue());
cacheCleaner.cleanList(sellerUid, TabType.SELL.getValue());
cacheCleaner.cleanDetail(buyerUid, buyerOrderCode);
cacheCleaner.cleanDetail(sellerUid, buyerOrderCode);
//update seller order
SellerOrderStatus targetSOStatus;
targetSOStatus = SellerOrderStatus.PLAY_BUYER;
... ... @@ -452,7 +458,8 @@ public class SellerOrderCancelService {
}
}
@Autowired
private CacheCleaner cacheCleaner;
/**
* 目前来看 只有支付过保证金的skup才有下架处理
* TODO 如何控制好并发,必须控制不能重复转账 退款
... ... @@ -496,19 +503,21 @@ public class SellerOrderCancelService {
}
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
Integer sellerUid = sellerOrder.getUid();
Long orderCode = sellerOrder.getOrderCode();
final Long orderCode = sellerOrder.getOrderCode();
//update
SellerOrder tso = new SellerOrder();
tso.setOrderCode(sellerOrder.getOrderCode());
tso.setOrderCode(orderCode);
tso.setExceptStatus(sellerOrder.getStatus());
tso.setStatus(targetSellerOrderStatus.getCode());
tso.setUid(sellerUid);
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
sellerOrderMapper.updateByOrderCode(tso);
//
cacheCleaner.cleanList(sellerUid, TabType.SELL.getValue());
cacheCleaner.cleanDetail(sellerUid, orderCode);
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
PaymentRequest refundReq = PaymentRequest.builder().uid(sellerOrder.getUid())
.orderCode(sellerOrder.getOrderCode())
.orderCode(orderCode)
.refundAmount(earnestMoney).build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
... ...
... ... @@ -8,6 +8,7 @@ import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.vo.OrderListVo;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
... ... @@ -55,15 +56,24 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
@Override
public PageResp<OrderListInfo> getOrderList(OrderListRequest request){
List<OrderListInfo> data = orderCacheService.getOrderListInfos(request);
OrderListVo orderListVo = orderCacheService.getOrderListInfos(request);
PageResp.PageRespBuilder respBuilder;
if (Objects.nonNull(orderListVo)){
respBuilder = PageResp.builder()
.page(request.getPage())
.pageSize(orderListVo.getPageSize())
.total(orderListVo.getTotal())
.pagetotal(orderListVo.getPagetotal());;
return respBuilder.data(orderListVo.getOrderList()).build();
}
PageResp orderListInfoRsp;
int type;
if ((type=request.getType()) == SellerOrderListType.IN_SALE.getType()){
List<Integer> statusList = initOrderListRequest(request);
int total = sellerOrderGoodsMapper.selectCntByUidStatusList(request.getUid(), statusList);
int limit = request.getLimit();
PageResp.PageRespBuilder respBuilder = PageResp.builder()
respBuilder = PageResp.builder()
.page(request.getPage())
.pageSize(limit)
.total(total)
... ... @@ -83,16 +93,28 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
.collect(Collectors.toMap(SellerOrderGoods::getId, (SellerOrderGoods sog) -> sog));
List<Integer> skupList = sogList.parallelStream().map(SellerOrderGoods::getId).collect(Collectors.toList());
List<SellerOrder> sellerOrders = sellerOrderMapper.selectBySkups(skupList);
List<OrderListInfo> data ;
data = sellerOrders.parallelStream()
.map(sellerOrder -> buildOrderListInfo(skupSellerOrderGoodsMap.get(sellerOrder.getSkup()), sellerOrder))
.filter(oli -> Objects.nonNull(oli))
.collect(Collectors.toList());
PageResp orderListInfoRsp = respBuilder.data(data).build();
return orderListInfoRsp;
orderListInfoRsp = respBuilder.data(data).build();
}else{
return super.getOrderList(request);
orderListInfoRsp = super.getOrderList(request);
}
//convert
if (orderListInfoRsp != null){
orderListVo = OrderListVo.builder().page(orderListInfoRsp.getPage())
.pageSize(orderListInfoRsp.getPageSize())
.orderList(orderListInfoRsp.getData())
.total(orderListInfoRsp.getTotal())
.pagetotal(orderListInfoRsp.getPagetotal()).build();
orderCacheService.cacheOrderList(request, orderListVo);
}
return orderListInfoRsp;
}
OrderListInfo buildOrderListInfo(SellerOrderGoods sellerOrderGoods,
... ...
... ... @@ -118,8 +118,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
throw new GatewayException(400, "storageId 错误");
}
/*商品鉴定费 ¥10.00
商品包装费 ¥10.00
平台服务费(5%,优惠期间0%) ¥0.00
... ... @@ -157,12 +155,12 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
BigDecimal maxPrice = productInfo.getMaxPrice();
if (prdPrice.subtract(minPrice).doubleValue() < 0D){
log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);
throw new GatewayException(501, "出售价格低于商品最低价:" + minPrice.toPlainString());
throw new GatewayException(501, "您的出价过低");
}
if (validateMaxPrice && prdPrice.subtract(maxPrice).doubleValue() > 0D){
log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);
throw new GatewayException(501, "出售价格大于商品最高价:" + maxPrice.toPlainString());
throw new GatewayException(501, "您的出价过高");
}
}
... ... @@ -304,7 +302,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
salePrice = new BigDecimal(req.getPrice());
}catch (Exception ex){
log.warn("storageId illegal , uid {}", uid);
throw new GatewayException(400, "售价错误");
throw new GatewayException(400, "售价格式错误");
}
int addressId = AddressUtil.getDecryptStr(req.getAddressId());
... ... @@ -445,6 +443,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
buyerOrderMapper.updateByPrimaryKeySelective(target);
}
cacheCleaner.cleanList(uid, TabType.SELL.getValue());
return true;
}
... ... @@ -505,22 +505,29 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
* @return
*/
public OrderSummaryResp selectOrderNumByUid(int uid) {
//todo add cache
Integer num = sellerOrderGoodsMapper.selectCntByUidStatusList(uid, Arrays.asList(SkupStatus.CAN_SELL.getCode()));
List<SellerOrderListType> types = Arrays.asList(SellerOrderListType.WAITING_SEND, SellerOrderListType.WAITING_PAY);
List<Integer> statusList = types.parallelStream().flatMap(solt -> solt.getStatus().parallelStream()).collect(Collectors.toList());
Integer buyerOrderNum = buyerOrderMapper.selectCntBySellerUid(uid, statusList);
log.info("in seller order count uid {}, num {}, buyerOrderNum {}", uid, num, buyerOrderNum);
int cnt;
if (num == null){
cnt = 0;
}else{
if (buyerOrderNum != null){
cnt = num + buyerOrderNum;
}else{
cnt = num;
Integer cnt = orderCacheService.getOrderSummary(uid, TabType.SELL);
if (cnt == null) {
//todo add cache
Integer num = sellerOrderGoodsMapper.selectCntByUidStatusList(uid, Arrays.asList(SkupStatus.CAN_SELL.getCode()));
List<SellerOrderListType> types = Arrays.asList(SellerOrderListType.WAITING_SEND, SellerOrderListType.WAITING_PAY);
List<Integer> statusList = types.parallelStream().flatMap(solt -> solt.getStatus().parallelStream()).collect(Collectors.toList());
Integer buyerOrderNum = buyerOrderMapper.selectCntBySellerUid(uid, statusList);
log.info("in seller order count uid {}, num {}, buyerOrderNum {}", uid, num, buyerOrderNum);
if (num == null) {
cnt = 0;
} else {
if (buyerOrderNum != null) {
cnt = num + buyerOrderNum;
} else {
cnt = num;
}
}
}
if (cnt != null){
orderCacheService.cacheOrderSummary(uid, TabType.SELL, cnt);
}
return new OrderSummaryResp("sell", cnt);
}
... ...
... ... @@ -21,6 +21,7 @@ import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.model.response.PaymentResponse;
import com.yohoufo.order.service.ISubmitOrderService;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.ShoppingSupport;
... ... @@ -68,6 +69,8 @@ public class ShoppingServiceImpl implements IShoppingService {
@Autowired
private SellerFeeService sellerFeeService;
@Autowired
private CacheCleaner cacheCleaner;
/**
* 结算页数据
* @param request
... ... @@ -155,8 +158,9 @@ public class ShoppingServiceImpl implements IShoppingService {
// 减库存,skup更新成不可售,入库
BigDecimal shipFee = new BigDecimal(delivery_way_sf_cost);
int uid;
OrderBuilder orderBuilder = OrderBuilder.builder()
.uid(shoppingRequest.getUid())
.uid(uid=shoppingRequest.getUid())
.skup(shoppingRequest.getSkup())
.orderCode(orderCode)
.productId(skup.getProductId())
... ... @@ -179,11 +183,16 @@ public class ShoppingServiceImpl implements IShoppingService {
//inBoxFacade.buyerOrderNotPayed(shoppingRequest.getUid(), orderCode);
if (submitResult != null){
//clean cache
//TODO merge clean key
cacheCleaner.cleanList(uid, TabType.BUY.getValue());
Integer sellerUid = submitResult.getSellerOrder().getUid();
cacheCleaner.cleanList(sellerUid, TabType.SELL.getValue());
NotPaidNoticeEvent notPaidNoticeEvent = NotPaidNoticeEvent.builder().actorType(TabType.BUY)
.uid(shoppingRequest.getUid()).orderCode(orderCode).build();
EventBusPublisher.publishEvent(notPaidNoticeEvent);
//
inBoxFacade.sellerSkupCreateOrderByBuyer(submitResult.getSellerOrder().getUid(), skup.getProductName());
inBoxFacade.sellerSkupCreateOrderByBuyer(sellerUid, skup.getProductName());
}
// 返回结果
return OrderSubmitResponse.builder().orderCode(orderCode).productId(skup.getProductId())
... ...