@@ -15,24 +15,31 @@
*/
package cn.ysk.cashier.service.impl.order ;
import cn.ysk.cashier.dto.product.TbProductDto ;
import cn.ysk.cashier.pojo.order.TbCashierCart ;
import cn.ysk.cashier.utils.ValidationUtil ;
import cn.ysk.cashier.utils.FileUtil ;
import cn.ysk.cashier.pojo.product.TbProduct ;
import cn.ysk.cashier.repository.product.TbProductRepository ;
import cn.ysk.cashier.repository.product.TbProductSkuRepository ;
import cn.ysk.cashier.service.product.TbProductService ;
import cn.ysk.cashier.utils.* ;
import lombok.RequiredArgsConstructor ;
import cn.ysk.cashier.repository.order.TbCashierCartRepository ;
import cn.ysk.cashier.service.order.TbCashierCartService ;
import cn.ysk.cashier.dto.order.TbCashierCartDto ;
import cn.ysk.cashier.dto.order.TbCashierCartQueryCriteria ;
import cn.ysk.cashier.mapper.order.TbCashierCartMapper ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.data.jpa.domain.Specification ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.data.domain.Page ;
import org.springframework.data.domain.Pageable ;
import cn.ysk.cashier.utils.PageUtil ;
import cn.ysk.cashier.utils.QueryHelp ;
import java.util.List ;
import java.util.Map ;
import java.io.IOException ;
import javax.persistence.criteria.* ;
import javax.servlet.http.HttpServletResponse ;
import java.util.ArrayList ;
import java.util.LinkedHashMap ;
@@ -47,8 +54,14 @@ import java.util.LinkedHashMap;
@RequiredArgsConstructor
public class TbCashierCartServiceImpl implements TbCashierCartService {
private static final Logger log = LoggerFactory . getLogger ( TbCashierCartServiceImpl . class ) ;
private final TbCashierCartRepository tbCashierCartRepository ;
private final TbCashierCartMapper tbCashierCartMapper ;
private final TbProductService tbproductService ;
private final TbProductSkuRepository skuRepository ;
private final RedisUtils redisUtils ;
private final TbProductRepository tbProductRepository ;
@Override
public Map < String , Object > queryAll ( TbCashierCartQueryCriteria criteria , Pageable pageable ) {
@@ -127,4 +140,25 @@ public class TbCashierCartServiceImpl implements TbCashierCartService {
}
FileUtil . downloadExcel ( list , response ) ;
}
@Override
public void clearExpireOrder ( TbCashierCart cart ) {
String key = CacheKey . PRODUCT + cart . getShopId ( ) + " :product " + cart . getProductId ( ) ;
TbProduct tbProduct = tbProductRepository . findById ( Integer . valueOf ( cart . getProductId ( ) ) ) . orElse ( null ) ;
if ( tbProduct = = null ) {
log . warn ( " 清空购物车查询订单失败, product id: {} " , cart . getProductId ( ) ) ;
return ;
}
if ( tbProduct . getIsDistribute ( ) = = 1 ) {
tbproductService . incrStockNumber ( cart . getProductId ( ) , cart . getNumber ( ) ) ;
} else {
key = CacheKey . PRODUCT + cart . getShopId ( ) + " : " + cart . getId ( ) ;
skuRepository . updateStockNumber ( Integer . valueOf ( cart . getSkuId ( ) ) , cart . getNumber ( ) . doubleValue ( ) ) ;
}
// 减去销量
if ( cart . getNumber ( ) > 0 ) {
redisUtils . decrBy ( key , cart . getNumber ( ) ) ;
}
}
}