Authored by tanling

个人中心订单数量

package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.BuyOrderNums;
import com.yohoufo.dal.order.model.BuyerOrder;
import org.apache.ibatis.annotations.Param;
... ... @@ -16,6 +17,8 @@ public interface BuyerOrderMapper {
BuyerOrder selectByPrimaryKey(Integer id);
List<BuyOrderNums> selectCntByUidStatusAll(@Param("uid") Integer uid);
BuyerOrder selectByOrderCodeUid(@Param("orderCode") Long orderCode, @Param("uid") int uid);
BuyerOrder selectByOrderCodeSellerUid(@Param("orderCode") Long orderCode, @Param("sellerUid") int uid);
... ...
package com.yohoufo.dal.order.model;
import lombok.Data;
@Data
public class BuyOrderNums {
private Integer num;
private Integer status;
}
... ...
... ... @@ -109,6 +109,16 @@
limit 1
</select>
<select id="selectCntByUidStatusAll" resultType="com.yohoufo.dal.order.model.BuyOrderNums">
select
status, count(1) num
from buyer_order
where uid=#{uid,jdbcType=INTEGER}
and buyer_order_status = 1
GROUP BY status;
</select>
<select id="selectOnlyByOrderCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ...
... ... @@ -3,6 +3,7 @@ package com.yohoufo.order.controller;
import com.yohobuy.ufo.model.order.common.OrderListType;
import com.yohobuy.ufo.model.order.common.SellerOrderListType;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.BuyerOrderNums;
import com.yohobuy.ufo.model.order.resp.OrderCntResp;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
... ... @@ -10,6 +11,7 @@ import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.annotation.InnerApi;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.OrderDetailInfo;
... ... @@ -37,6 +39,18 @@ public class BuyerOrderController {
@Autowired
private SellerFeeService sellerFeeService;
@RequestMapping(params = "method=ufo.buyer.orderNums")
@ResponseBody
@IgnoreSession
@IgnoreSignature
// @InnerApi
public BuyerOrderNums getBuyerOrderNums(@RequestParam("uid") int uid){
BuyerOrderNums buyerOrderNums = buyerOrderService.getBuyerOrderNums(uid);
return buyerOrderNums;
}
/**
* [购买]订单列表
* 1:
... ...
... ... @@ -220,15 +220,16 @@ public class SellerOrderController {
@RequestParam(name = "skupList", required = true)String skupList
) throws GatewayException {
BatchChangePriceReq req = BatchChangePriceReq.builder()
.uid(uid).price(price)
.isShowPriceError(true)
.batchNo(batchNo).skupList(skupList)
.build();
logger.info("in ufo.sellerOrder.batchChangePrice, req {}", req);
BatchChangePriceResp result = sellerOrderService.batchChangePrice(req);
return new ApiResponse.ApiResponseBuilder().data(result).code(200).message(result.getTips()).build();
// BatchChangePriceReq req = BatchChangePriceReq.builder()
// .uid(uid).price(price)
// .isShowPriceError(true)
// .batchNo(batchNo).skupList(skupList)
// .build();
// logger.info("in ufo.sellerOrder.batchChangePrice, req {}", req);
// BatchChangePriceResp result = sellerOrderService.batchChangePrice(req);
//
// return new ApiResponse.ApiResponseBuilder().data(result).code(200).message(result.getTips()).build();
return null;
}
@RequestMapping(params = "method=ufo.sellerOrder.computeChangePrice")
... ... @@ -239,15 +240,16 @@ public class SellerOrderController {
@RequestParam(name = "batchNo", required = false)String batchNo,
@RequestParam(name = "skupList", required = false)String skupList,
@RequestParam(name="num", defaultValue = "1", required = false)int num) throws GatewayException {
BatchChangePriceReq req = BatchChangePriceReq.builder()
.storageId(storage_id)
.uid(uid).price(price)
.batchNo(batchNo).skupList(skupList)
.isShowPriceError(false)
.build();
logger.info("in ufo.sellerOrder.computeChangePrice, req {}", req);
SoldPrdComputeBo computeBo = sellerOrderService.computeChangePrice(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build();
// BatchChangePriceReq req = BatchChangePriceReq.builder()
// .storageId(storage_id)
// .uid(uid).price(price)
// .batchNo(batchNo).skupList(skupList)
// .isShowPriceError(false)
// .build();
// logger.info("in ufo.sellerOrder.computeChangePrice, req {}", req);
// SoldPrdComputeBo computeBo = sellerOrderService.computeChangePrice(req);
// return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build();
return null;
}
... ...
... ... @@ -111,7 +111,8 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
CacheKeyBuilder.orderListKey(uid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(uid, TabType.BUY.getValue(), orderInfo.getOrderCode())));
CacheKeyBuilder.orderDetailKey(uid, TabType.BUY.getValue(), orderInfo.getOrderCode()),
CacheKeyBuilder.buyerOrderNums(uid)));
}
... ...
package com.yohoufo.order.service;
import com.yohobuy.ufo.model.order.common.OrderListType;
import com.yohobuy.ufo.model.order.resp.BuyerOrderNums;
import com.yohobuy.ufo.model.order.resp.OrderCntResp;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.order.model.request.OrderRequest;
... ... @@ -9,8 +10,12 @@ import com.yohoufo.order.model.response.OrderSummaryResp;
public interface IBuyerOrderService extends IOrderListService, IOrderDetailService{
/**
* 查询待付款,待收货,待发货的订单数量
* @param uid
* @return
*/
BuyerOrderNums getBuyerOrderNums(int uid);
/**
* 取消订单
... ...
... ... @@ -52,7 +52,9 @@ public class CacheKeyBuilder {
ORDER_DETAIL("ufo:order:orderDetail:", "uid:{}:tabType:{}:orderCode:{}"),
SELLER_ORDER_DETAIL("ufo:order:orderDetail:", "uid:{}:tabType:{}:batchNo:{}:price{}:status{}");
SELLER_ORDER_DETAIL("ufo:order:orderDetail:", "uid:{}:tabType:{}:batchNo:{}:price{}:status{}"),
BUYER_ORDER_NUMS("ufo:order:buyer:nums", "uid:{}");
private String fix;
... ... @@ -87,6 +89,10 @@ public class CacheKeyBuilder {
return PatternKeyTemplate.ORDER_LIST_PAGE_LIMIT.getKey(req.getType(), req.getPage(), req.getLimit());
}
public static RedisKeyBuilder buyerOrderNums(int uid){
return KeyTemp.BUYER_ORDER_NUMS.builderKey(new Object[]{uid});
}
public static String skupListHashKey(OrderListRequest req){
return PatternKeyTemplate.SELLER_ORDER_LIST_PAGE_LIMIT.getKey(req.getType(), req.getSkupList(), req.getLimit());
}
... ...
... ... @@ -12,4 +12,6 @@ public interface ExpiredTime {
int ORDER_DETAIL = 300;
int ORDER_SUMMARY = 300;
int BUYER_ORDER_NUMS = 300;
}
... ...
... ... @@ -3,9 +3,11 @@ 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.resp.BuyerOrderNums;
import com.yohobuy.ufo.model.order.vo.OrderListVo;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.common.cache.SnappyZipUtils;
import com.yohoufo.dal.order.model.BuyOrderNums;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.response.OrderDetailInfo;
... ... @@ -96,6 +98,20 @@ public class OrderCacheService {
}
public BuyerOrderNums getBuyerOrderNums(int uid){
RedisKeyBuilder redisKeyBuilder = CacheKeyBuilder.buyerOrderNums(uid);
BuyerOrderNums buyerOrderNums = cacheClient.get(redisKeyBuilder.getKey(), BuyerOrderNums.class);
return buyerOrderNums;
}
public void saveBuyerOrderNums(int uid, BuyerOrderNums buyOrderNums){
RedisKeyBuilder redisKeyBuilder = CacheKeyBuilder.buyerOrderNums(uid);
cacheClient.set(redisKeyBuilder.getKey(), ExpiredTime.BUYER_ORDER_NUMS , buyOrderNums);
logger.info("saveBuyerOrderNums cache ,uid {} nums {}", uid, buyOrderNums);
}
public OrderListVo getOrderListInfos(OrderListRequest req){
logger.info("hit OrderList cache ,req {}", req);
... ...
... ... @@ -204,7 +204,8 @@ public class AppraiseService {
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid,TabType.BUY.getValue(), orderCode)));
CacheKeyBuilder.orderDetailKey(buyerUid,TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, sellerOrderCode, skup, earnestMoney );
... ... @@ -306,7 +307,8 @@ public class AppraiseService {
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), orderCode)));
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
//将卖家的保证金分账给平台和买家
TransferCase transferCase = TransferCase.APPRAISE_FAIL;
... ...
... ... @@ -122,7 +122,8 @@ public class BuyerOrderCancelService {
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(psog),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), orderCode)));
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
logger.info("use one thread to execute buyer cancel BeforeSellerDeliver buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, compensate, transferCase);
}
... ... @@ -172,7 +173,8 @@ public class BuyerOrderCancelService {
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(psog),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), orderCode)));
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
logger.info("use one thread to execute buyer cancel BeforeDepotReceive buyerUid {}, orderCode {}, skup {}, compensate {}, transferCase {}",
buyerUid, orderCode, skup, compensate, transferCase);
}
... ...
... ... @@ -85,7 +85,8 @@ public class BuyerOrderMetaServiceImpl implements IBuyerOrderMetaService {
//清地址缓存
cacheCleaner.delete(Arrays.asList(
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), req.getOrderCode())));
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), req.getOrderCode()),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
return rtn;
}
... ...
... ... @@ -9,6 +9,7 @@ import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.req.BuyerOrderMetaUpdateReq;
import com.yohobuy.ufo.model.order.resp.BuyerOrderNums;
import com.yohobuy.ufo.model.order.resp.OrderCntResp;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
... ... @@ -19,6 +20,7 @@ import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.BuyOrderNums;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrderGoods;
... ... @@ -38,6 +40,7 @@ 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 org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -46,7 +49,9 @@ import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class BuyerOrderServiceImpl implements IBuyerOrderService {
... ... @@ -111,7 +116,8 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
CacheKeyBuilder.orderListKey(uid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sog),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(uid, TabType.BUY.getValue(), orderCode)));
CacheKeyBuilder.orderDetailKey(uid, TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(uid)));
} else {
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE); // 更新失败,可能是因为订单状态已经被并发修改
}
... ... @@ -381,7 +387,8 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(psog),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), orderCode)));
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
}
... ... @@ -449,6 +456,58 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
return orderDetailInfo;
}
/**
* 查询订单数量
* @param uid
* @return
*/
public BuyerOrderNums getBuyerOrderNums(int uid){
if (uid < 0){
logger.warn("buyer delete, uid or orderCode empty, uid {}", uid);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
BuyerOrderNums buyerOrderNumsCache = orderCacheService.getBuyerOrderNums(uid);
if (buyerOrderNumsCache != null){
logger.info("getBuyerOrderNums result uid is {}, result is {}", uid, buyerOrderNumsCache);
return buyerOrderNumsCache;
}
List<BuyOrderNums> buyOrderNumList = buyerOrderMapper.selectCntByUidStatusAll(uid);
if (CollectionUtils.isEmpty(buyOrderNumList)){
return BuyerOrderNums.builder().build();
}
Map<Integer, Integer> buyOrderNumsMap = buyOrderNumList.stream().collect(Collectors.toMap(BuyOrderNums::getStatus, BuyOrderNums::getNum));
// 待付款
// 待发货
// 待收货
BuyerOrderNums buyerOrderNums = BuyerOrderNums.builder().uid(uid)
.waitingPayNum(getValueDefalutZero(buyOrderNumsMap, OrderListType.WAITING_PAY.getStatusQuery()))
.waitingSendNums(getValueDefalutZero(buyOrderNumsMap, OrderListType.WAITING_SEND.getStatusQuery()))
.waitingDeliveryNums(getValueDefalutZero(buyOrderNumsMap, OrderListType.WAITING_DELIVERY.getStatusQuery())).build();
orderCacheService.saveBuyerOrderNums(uid, buyerOrderNums);
return buyerOrderNums;
}
private int getValueDefalutZero(Map<Integer, Integer> map, List<Integer> status){
int sum = 0;
for(Integer key : status){
int num = Objects.isNull(map.get(key)) ? 0 : map.get(key);
sum+=num;
}
return sum;
}
@Override
public PageResp getOrderList(OrderListRequest request) {
... ...
... ... @@ -148,7 +148,8 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(psog),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid,TabType.BUY.getValue(), orderCode)));
CacheKeyBuilder.orderDetailKey(buyerUid,TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
}
LOGGER.info("deliverToDepot update buyer order status result {} ",updateBuyerCnt);
... ...
... ... @@ -384,7 +384,8 @@ public class SellerOrderCancelService {
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(psog),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), buyerOrderCode),
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), buyerOrderCode)));
CacheKeyBuilder.orderDetailKey(buyerUid, TabType.BUY.getValue(), buyerOrderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
//update seller order
SellerOrderStatus targetSOStatus;
... ...
... ... @@ -296,7 +296,8 @@ public class ShoppingServiceImpl implements IShoppingService {
//clean seller cache
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(psog),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), sellerOrderCode)
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), sellerOrderCode),
CacheKeyBuilder.buyerOrderNums(shoppingRequest.getUid())
));
NotPaidNoticeEvent notPaidNoticeEvent = NotPaidNoticeEvent.builder().actorType(TabType.BUY)
.uid(shoppingRequest.getUid()).orderCode(orderCode).build();
... ...
... ... @@ -18,7 +18,7 @@
<properties>
<qiniu.version>7.0.5</qiniu.version>
<project-name>yohoufo-fore</project-name>
<model.version>3.0-SNAPSHOT</model.version>
<model.version>4.0-SNAPSHOT</model.version>
</properties>
<dependencyManagement>
... ...
... ... @@ -2,6 +2,9 @@ package com.yohoufo.promotion.controller;
import com.yohobuy.ufo.model.promotion.response.CouponInfo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.annotation.InnerApi;
import com.yohoufo.promotion.service.ICouponService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -55,6 +58,25 @@ public class CouponController {
/**
* 个人中心优惠券数量,给内部用接口
* @param uid
* @return
*/
@RequestMapping(params = "method=ufo.coupons.innerCnt")
@ResponseBody
@IgnoreSession
@IgnoreSignature
// @InnerApi
public ApiResponse queryCouponInnerCnt(@RequestParam(value = "uid") Integer uid) {
logger.info("query user coupons cnt, uid: {}", uid);
int couponCnt = couponService.queryCouponCnt(uid);
logger.info("query user coupons cnt uid: {}, v: {}", uid, couponCnt);
return new ApiResponse.ApiResponseBuilder().code(200).data(couponCnt).build();
}
/**
* 领券接口
* @param uid
* @return
... ...