|
|
@@ -8,6 +8,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import com.fs.common.constant.LiveKeysConstant;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.core.redis.RedisCacheT;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.hisStore.domain.FsStoreProductAttrScrm;
|
|
|
import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
|
|
|
@@ -28,14 +29,15 @@ import org.springframework.stereotype.Service;
|
|
|
* @date 2024-01-01
|
|
|
*/
|
|
|
@Service
|
|
|
-public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProductPurchaseLimitScrmService
|
|
|
-{
|
|
|
+public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProductPurchaseLimitScrmService {
|
|
|
@Autowired
|
|
|
private FsStoreProductPurchaseLimitScrmMapper fsStoreProductPurchaseLimitMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
@Autowired
|
|
|
+ private RedisCacheT<FsStoreProductPurchaseLimitScrm> redisCacheT;
|
|
|
+ @Autowired
|
|
|
private FsStoreProductScrmMapper fsStoreProductScrmMapper;
|
|
|
@Autowired
|
|
|
private FsStoreProductAttrScrmMapper fsStoreProductAttrScrmMapper;
|
|
|
@@ -50,8 +52,7 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* @return 商品限购
|
|
|
*/
|
|
|
@Override
|
|
|
- public FsStoreProductPurchaseLimitScrm selectFsStoreProductPurchaseLimitById(Long id)
|
|
|
- {
|
|
|
+ public FsStoreProductPurchaseLimitScrm selectFsStoreProductPurchaseLimitById(Long id) {
|
|
|
return fsStoreProductPurchaseLimitMapper.selectFsStoreProductPurchaseLimitById(id);
|
|
|
}
|
|
|
|
|
|
@@ -62,8 +63,7 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* @return 商品限购
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<FsStoreProductPurchaseLimitScrm> selectFsStoreProductPurchaseLimitList(FsStoreProductPurchaseLimitScrm fsStoreProductPurchaseLimit)
|
|
|
- {
|
|
|
+ public List<FsStoreProductPurchaseLimitScrm> selectFsStoreProductPurchaseLimitList(FsStoreProductPurchaseLimitScrm fsStoreProductPurchaseLimit) {
|
|
|
return fsStoreProductPurchaseLimitMapper.selectFsStoreProductPurchaseLimitList(fsStoreProductPurchaseLimit);
|
|
|
}
|
|
|
|
|
|
@@ -71,13 +71,19 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* 根据商品ID和用户ID查询限购记录
|
|
|
*
|
|
|
* @param productId 商品ID
|
|
|
- * @param userId 用户ID
|
|
|
+ * @param userId 用户ID
|
|
|
* @return 商品限购
|
|
|
*/
|
|
|
@Override
|
|
|
- public FsStoreProductPurchaseLimitScrm selectByProductIdAndUserId(Long productId, Long userId)
|
|
|
- {
|
|
|
- return fsStoreProductPurchaseLimitMapper.selectByProductIdAndUserId(productId, userId);
|
|
|
+ public FsStoreProductPurchaseLimitScrm selectByProductIdAndUserId(Long productId, Long userId) {
|
|
|
+ String key = "live:order:limit:" + productId + ":" + userId;
|
|
|
+ FsStoreProductPurchaseLimitScrm scrm = redisCacheT.getCacheObject(key);
|
|
|
+ if(scrm != null){
|
|
|
+ return scrm;
|
|
|
+ }
|
|
|
+ scrm = fsStoreProductPurchaseLimitMapper.selectByProductIdAndUserId(productId, userId);
|
|
|
+ redisCacheT.setCacheObject(key, scrm);
|
|
|
+ return scrm;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -87,8 +93,7 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertFsStoreProductPurchaseLimit(FsStoreProductPurchaseLimitScrm fsStoreProductPurchaseLimit)
|
|
|
- {
|
|
|
+ public int insertFsStoreProductPurchaseLimit(FsStoreProductPurchaseLimitScrm fsStoreProductPurchaseLimit) {
|
|
|
fsStoreProductPurchaseLimit.setCreateTime(DateUtils.getNowDate());
|
|
|
return fsStoreProductPurchaseLimitMapper.insertFsStoreProductPurchaseLimit(fsStoreProductPurchaseLimit);
|
|
|
}
|
|
|
@@ -100,8 +105,7 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateFsStoreProductPurchaseLimit(FsStoreProductPurchaseLimitScrm fsStoreProductPurchaseLimit)
|
|
|
- {
|
|
|
+ public int updateFsStoreProductPurchaseLimit(FsStoreProductPurchaseLimitScrm fsStoreProductPurchaseLimit) {
|
|
|
fsStoreProductPurchaseLimit.setUpdateTime(DateUtils.getNowDate());
|
|
|
return fsStoreProductPurchaseLimitMapper.updateFsStoreProductPurchaseLimit(fsStoreProductPurchaseLimit);
|
|
|
}
|
|
|
@@ -113,8 +117,7 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteFsStoreProductPurchaseLimitByIds(Long[] ids)
|
|
|
- {
|
|
|
+ public int deleteFsStoreProductPurchaseLimitByIds(Long[] ids) {
|
|
|
return fsStoreProductPurchaseLimitMapper.deleteFsStoreProductPurchaseLimitByIds(ids);
|
|
|
}
|
|
|
|
|
|
@@ -125,8 +128,7 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteFsStoreProductPurchaseLimitById(Long id)
|
|
|
- {
|
|
|
+ public int deleteFsStoreProductPurchaseLimitById(Long id) {
|
|
|
return fsStoreProductPurchaseLimitMapper.deleteFsStoreProductPurchaseLimitById(id);
|
|
|
}
|
|
|
|
|
|
@@ -134,13 +136,12 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* 增加用户限购数量
|
|
|
*
|
|
|
* @param productId 商品ID
|
|
|
- * @param userId 用户ID
|
|
|
- * @param num 增加的数量
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @param num 增加的数量
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int increasePurchaseLimit(Long productId, Long userId, Integer num)
|
|
|
- {
|
|
|
+ public int increasePurchaseLimit(Long productId, Long userId, Integer num) {
|
|
|
String cacheKey = String.format(LiveKeysConstant.PRODUCT_DETAIL_CACHE, productId);
|
|
|
Map<String, Object> cachedData = redisCache.getCacheObject(cacheKey);
|
|
|
|
|
|
@@ -154,7 +155,7 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
} else {
|
|
|
// 缓存中没有,从数据库查询
|
|
|
product = fsStoreProductScrmMapper.selectFsStoreProductById(productId);
|
|
|
- if(product==null){
|
|
|
+ if (product == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
productAttr = fsStoreProductAttrScrmMapper.selectFsStoreProductAttrByProductId(productId);
|
|
|
@@ -167,18 +168,22 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
cacheData.put("productValues", productValues);
|
|
|
redisCache.setCacheObject(cacheKey, cacheData, LiveKeysConstant.PRODUCT_DETAIL_CACHE_EXPIRE, TimeUnit.SECONDS);
|
|
|
}
|
|
|
+
|
|
|
if (product != null && product.getPurchaseLimit() != null && product.getPurchaseLimit() > 0) {
|
|
|
FsStoreProductPurchaseLimitScrm limit = selectByProductIdAndUserId(productId, userId);
|
|
|
+ String key = "live:order:limit:" + productId + ":" + userId;
|
|
|
if (limit == null) {
|
|
|
// 创建新记录
|
|
|
limit = new FsStoreProductPurchaseLimitScrm();
|
|
|
limit.setProductId(productId);
|
|
|
limit.setUserId(userId);
|
|
|
limit.setNum(num);
|
|
|
+ redisCacheT.setCacheObject(key, limit);
|
|
|
return insertFsStoreProductPurchaseLimit(limit);
|
|
|
} else {
|
|
|
// 更新现有记录
|
|
|
limit.setNum(limit.getNum() + num);
|
|
|
+ redisCacheT.setCacheObject(key, limit);
|
|
|
return updateFsStoreProductPurchaseLimit(limit);
|
|
|
}
|
|
|
}
|
|
|
@@ -189,13 +194,12 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
* 减少用户限购数量
|
|
|
*
|
|
|
* @param productId 商品ID
|
|
|
- * @param userId 用户ID
|
|
|
- * @param num 减少的数量
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @param num 减少的数量
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int decreasePurchaseLimit(Long productId, Long userId, Integer num)
|
|
|
- {
|
|
|
+ public int decreasePurchaseLimit(Long productId, Long userId, Integer num) {
|
|
|
String cacheKey = String.format(LiveKeysConstant.PRODUCT_DETAIL_CACHE, productId);
|
|
|
Map<String, Object> cachedData = redisCache.getCacheObject(cacheKey);
|
|
|
|
|
|
@@ -209,7 +213,7 @@ public class FsStoreProductPurchaseLimitScrmServiceImpl implements IFsStoreProdu
|
|
|
} else {
|
|
|
// 缓存中没有,从数据库查询
|
|
|
product = fsStoreProductScrmMapper.selectFsStoreProductById(productId);
|
|
|
- if(product==null){
|
|
|
+ if (product == null) {
|
|
|
return -1;
|
|
|
}
|
|
|
productAttr = fsStoreProductAttrScrmMapper.selectFsStoreProductAttrByProductId(productId);
|