|
|
@@ -15,22 +15,22 @@ public class PpointService {
|
|
|
private ProductPpointMapper productPpointMapper;
|
|
|
|
|
|
/**
|
|
|
- * 获取产品当前生效的P-point值
|
|
|
- * 查询 date-valid 记录(startDate <= now <= endDate),按 ppoint DESC 取第一条
|
|
|
- * 如果没有生效记录返回 0
|
|
|
+ * 获取商品当前生效的 P-point(利润点数)
|
|
|
+ * 从 product_ppoint 表查询日期范围内有效的配置,未配置则返回 0
|
|
|
*/
|
|
|
public int getEffectivePpoint(Long productId) {
|
|
|
if (productId == null) {
|
|
|
return 0;
|
|
|
}
|
|
|
Date now = new Date();
|
|
|
- LambdaQueryWrapper<ProductPpoint> wrapper = new LambdaQueryWrapper<ProductPpoint>()
|
|
|
- .eq(ProductPpoint::getProductId, productId)
|
|
|
- .le(ProductPpoint::getStartDate, now)
|
|
|
- .ge(ProductPpoint::getEndDate, now)
|
|
|
- .orderByDesc(ProductPpoint::getPpoint)
|
|
|
- .last("LIMIT 1");
|
|
|
- ProductPpoint record = productPpointMapper.selectOne(wrapper);
|
|
|
- return record != null && record.getPpoint() != null ? record.getPpoint() : 0;
|
|
|
+ ProductPpoint pp = productPpointMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<ProductPpoint>()
|
|
|
+ .eq(ProductPpoint::getProductId, productId)
|
|
|
+ .le(ProductPpoint::getStartDate, now)
|
|
|
+ .ge(ProductPpoint::getEndDate, now)
|
|
|
+ .orderByDesc(ProductPpoint::getCreatedAt)
|
|
|
+ .last("LIMIT 1")
|
|
|
+ );
|
|
|
+ return pp != null ? pp.getPpoint() : 0;
|
|
|
}
|
|
|
-}
|
|
|
+}
|