收音机 / 客户端 商品列表
This commit is contained in:
@@ -27,10 +27,8 @@ import com.czg.service.product.mapper.*;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.row.DbChain;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -46,7 +44,6 @@ import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.TextStyle;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.czg.constant.CacheConstant.ADMIN_CLIENT_PRODUCT_LIST;
|
||||
import static com.czg.product.entity.table.ProductTableDef.PRODUCT;
|
||||
@@ -172,9 +169,20 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
@Override
|
||||
public List<ProductDTO> getProductList(ProductDTO param) {
|
||||
QueryWrapper queryWrapper = buildFullQueryWrapper(param);
|
||||
//queryWrapper.eq(Product::getIsSale, SystemConstants.OneZero.ONE);
|
||||
List<ProductDTO> records = super.listAs(queryWrapper, ProductDTO.class);
|
||||
buildProductExtInfo(records);
|
||||
records.forEach(record -> {
|
||||
record.setProGroupVo(JSONArray.parseArray(record.getGroupSnap().toString(), ProductGroupVo.class));
|
||||
List<ProdSkuDTO> skuList = prodSkuMapper.selectListByQueryAs(query().eq(ProdSku::getProductId, record.getId()).eq(ProdSku::getIsDel, SystemConstants.OneZero.ZERO), ProdSkuDTO.class);
|
||||
if (CollUtil.isNotEmpty(skuList)) {
|
||||
Optional<BigDecimal> lowPriceIsPresent = skuList.stream().map(obj -> NumberUtil.nullToZero(obj.getSalePrice())).min(BigDecimal::compareTo);
|
||||
lowPriceIsPresent.ifPresent(record::setLowPrice);
|
||||
|
||||
Optional<BigDecimal> lowMemberPriceIsPresent = skuList.stream().map(obj -> NumberUtil.nullToZero(obj.getMemberPrice())).min(BigDecimal::compareTo);
|
||||
lowMemberPriceIsPresent.ifPresent(record::setLowMemberPrice);
|
||||
}
|
||||
record.setSkuList(skuList);
|
||||
record.setProdConsRelations(prodConsRelationMapper.selectListByQuery(query().eq(ProdConsRelation::getProductId, record.getId()).eq(ProdConsRelation::getShopId, record.getShopId())));
|
||||
});
|
||||
return records;
|
||||
}
|
||||
|
||||
@@ -326,27 +334,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductDTO> getProductCacheList(ProductDTO param) {
|
||||
Long shopId = param.getShopId();
|
||||
initProductCache(shopId);
|
||||
String prefix = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::";
|
||||
public List<ProductDTO> getProductCacheList(Long shopId, Long categoryId) {
|
||||
String key = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::" + categoryId;
|
||||
List<ProductDTO> list;
|
||||
if (param.getCategoryId() == null) {
|
||||
list = new ArrayList<>();
|
||||
Set<String> keys = redisService.rightLikeKey(prefix);
|
||||
for (String key : keys) {
|
||||
List<ProductDTO> prodList = redisService.getJsonToBeanList(key, ProductDTO.class);
|
||||
if(CollUtil.isNotEmpty(prodList)) {
|
||||
list.addAll(prodList);
|
||||
}
|
||||
}
|
||||
if (!redisService.hasKey(key)) {
|
||||
list = initProductCacheByCategoryId(shopId, categoryId);
|
||||
} else {
|
||||
String key = prefix + param.getCategoryId();
|
||||
list = redisService.getJsonToBeanList(key, ProductDTO.class);
|
||||
}
|
||||
if (StrUtil.isNotEmpty(param.getName())) {
|
||||
list = list.stream().filter(obj -> StrUtil.contains(obj.getName(), param.getName())).toList();
|
||||
}
|
||||
// 重新进行排序
|
||||
list = list.stream()
|
||||
.sorted(Comparator.comparingInt(ProductDTO::getIsSoldStock))
|
||||
@@ -360,28 +355,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
/**
|
||||
* 初始化商品缓存数据
|
||||
*/
|
||||
private void initProductCache(Long shopId) {
|
||||
private List<ProductDTO> initProductCacheByCategoryId(Long shopId, Long categoryId) {
|
||||
ProductDTO param = new ProductDTO();
|
||||
param.setShopId(shopId);
|
||||
param.setCategoryId(categoryId);
|
||||
List<ProductDTO> productList = getProductList(param);
|
||||
Map<Long, List<ProductDTO>> categoryMap = productList.stream().filter(item -> item.getCategoryId() != null).collect(Collectors.groupingBy(ProductDTO::getCategoryId));
|
||||
ShopProdCategoryDTO dto = new ShopProdCategoryDTO();
|
||||
dto.setShopId(shopId);
|
||||
List<ShopProdCategoryDTO> categoryList = shopProdCategoryService.getShopProdCategoryList(dto);
|
||||
String prefix = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::";
|
||||
for (ShopProdCategoryDTO category : categoryList) {
|
||||
String key = prefix + category.getId();
|
||||
boolean b = redisService.hasKey(key);
|
||||
if (!b) {
|
||||
List<ProductDTO> list = categoryMap.get(category.getId());
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
redisService.setJsonStr(key, list);
|
||||
} else {
|
||||
List<ProductDTO> empty = new ArrayList<>();
|
||||
redisService.setJsonStr(key, empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
String key = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::" + categoryId;
|
||||
redisService.setJsonStr(key, productList);
|
||||
return productList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,23 +377,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统启动会一次性加载商品缓存数据,防止首次访问时加载缓慢的问题
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initProductListCache() {
|
||||
log.info("系统启动后初始化商品列表缓存,开始...");
|
||||
List<Long> shopIdList = DbChain.table("tb_shop_info").select("id").listAs(Long.class);
|
||||
for (Long shopId : shopIdList) {
|
||||
log.info("商品列表缓存>>当前店铺:{}", shopId);
|
||||
ProductDTO dto = new ProductDTO();
|
||||
dto.setShopId(shopId);
|
||||
getProductCacheList(dto);
|
||||
log.info("商品列表缓存>>当前店铺:{},初始化结束", shopId);
|
||||
}
|
||||
log.info("系统启动后初始化商品列表缓存,结束。");
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算是否在可售时间内
|
||||
*
|
||||
@@ -625,7 +589,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.eq(Product::getId, prodSku.getProductId())
|
||||
.eq(Product::getShopId, shopId)
|
||||
.update();
|
||||
}else if(normalCount > 0 && product.getIsSale() == SystemConstants.OneZero.ZERO) {
|
||||
} else if (normalCount > 0 && product.getIsSale() == SystemConstants.OneZero.ZERO) {
|
||||
UpdateChain.of(Product.class)
|
||||
.set(Product::getIsSale, SystemConstants.OneZero.ONE)
|
||||
.eq(Product::getId, prodSku.getProductId())
|
||||
@@ -634,7 +598,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
sensitiveOperation = sensitiveOperation + "商品:" + product.getName() + " 规格:" + prodSku.getSpecInfo();
|
||||
} else if (ProductIsSaleTypeEnum.PRODUCT.value().equals(type)) {
|
||||
if("sale".equals(param.getOptType())){
|
||||
if ("sale".equals(param.getOptType())) {
|
||||
UpdateChain.of(Product.class)
|
||||
.set(Product::getIsSale, isSale)
|
||||
.eq(Product::getId, id)
|
||||
|
||||
Reference in New Issue
Block a user