热门产品销售看板
This commit is contained in:
@@ -14,6 +14,12 @@ import com.klp.domain.vo.WmsProductSalesScriptVo;
|
||||
import com.klp.domain.WmsProductSalesScript;
|
||||
import com.klp.mapper.WmsProductSalesScriptMapper;
|
||||
import com.klp.service.IWmsProductSalesScriptService;
|
||||
import com.klp.domain.vo.HotProductVO;
|
||||
import com.klp.common.utils.redis.RedisUtils;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Comparator;
|
||||
import com.klp.domain.WmsProduct;
|
||||
import com.klp.mapper.WmsProductMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -30,6 +36,7 @@ import java.util.Collection;
|
||||
public class WmsProductSalesScriptServiceImpl implements IWmsProductSalesScriptService {
|
||||
|
||||
private final WmsProductSalesScriptMapper baseMapper;
|
||||
private final WmsProductMapper wmsProductMapper;
|
||||
|
||||
/**
|
||||
* 查询产品销售话术
|
||||
@@ -117,4 +124,44 @@ public class WmsProductSalesScriptServiceImpl implements IWmsProductSalesScriptS
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门产品排行(基于访问频率)
|
||||
*/
|
||||
@Override
|
||||
public List<HotProductVO> getHotProducts(Integer limit) {
|
||||
// 获取所有产品访问频率的key
|
||||
Collection<String> keys = RedisUtils.keys("product:visit:frequency:*");
|
||||
|
||||
List<HotProductVO> hotProducts = keys.stream()
|
||||
.map(key -> {
|
||||
String productIdStr = key.replace("product:visit:frequency:", "");
|
||||
Long productId = Long.valueOf(productIdStr);
|
||||
Long visitCount = RedisUtils.getAtomicValue(key);
|
||||
|
||||
// 查询产品信息
|
||||
WmsProduct product = wmsProductMapper.selectById(productId);
|
||||
if (product == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HotProductVO vo = new HotProductVO();
|
||||
vo.setProductId(productId);
|
||||
vo.setProductName(product.getProductName());
|
||||
vo.setProductCode(product.getProductCode());
|
||||
vo.setVisitCount(visitCount);
|
||||
return vo;
|
||||
})
|
||||
.filter(vo -> vo != null)
|
||||
.sorted(Comparator.comparing(HotProductVO::getVisitCount).reversed())
|
||||
.limit(limit)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 设置排名
|
||||
for (int i = 0; i < hotProducts.size(); i++) {
|
||||
hotProducts.get(i).setRank(i + 1);
|
||||
}
|
||||
|
||||
return hotProducts;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import com.klp.domain.WmsProduct;
|
||||
import com.klp.mapper.WmsProductMapper;
|
||||
import com.klp.service.IWmsProductService;
|
||||
import com.klp.domain.vo.OrderSummaryVO;
|
||||
import com.klp.domain.vo.HotProductVO;
|
||||
import com.klp.service.IWmsProductSalesScriptService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,6 +34,7 @@ import java.util.Collection;
|
||||
public class WmsProductServiceImpl implements IWmsProductService {
|
||||
|
||||
private final WmsProductMapper baseMapper;
|
||||
private final IWmsProductSalesScriptService iWmsProductSalesScriptService;
|
||||
|
||||
/**
|
||||
* 查询产品
|
||||
@@ -149,6 +152,8 @@ public class WmsProductServiceImpl implements IWmsProductService {
|
||||
vo.setProductRank(baseMapper.selectProductRank());
|
||||
vo.setOrderMaterial(baseMapper.selectOrderMaterial());
|
||||
vo.setCustomerRegion(baseMapper.selectCustomerRegion());
|
||||
// 添加热门产品数据
|
||||
vo.setHotProducts(iWmsProductSalesScriptService.getHotProducts(10));
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user