|
@@ -142,63 +142,65 @@ public class LiveGoodsController extends AppBaseController
|
|
|
@GetMapping("/liveGoodsDetail/{productId}")
|
|
@GetMapping("/liveGoodsDetail/{productId}")
|
|
|
public R liveGoodsDetail(@PathVariable Long productId)
|
|
public R liveGoodsDetail(@PathVariable Long productId)
|
|
|
{
|
|
{
|
|
|
- // 先从缓存中获取商品详情
|
|
|
|
|
- String cacheKey = String.format(LiveKeysConstant.PRODUCT_DETAIL_CACHE, productId);
|
|
|
|
|
- Map<String, Object> cachedData = redisCache.getCacheObject(cacheKey);
|
|
|
|
|
-
|
|
|
|
|
- FsStoreProduct product;
|
|
|
|
|
- List<FsStoreProductAttr> productAttr;
|
|
|
|
|
- List<FsStoreProductAttrValue> productValues;
|
|
|
|
|
-
|
|
|
|
|
- if (cachedData != null) {
|
|
|
|
|
- // 从缓存中获取数据
|
|
|
|
|
- product = (FsStoreProduct) cachedData.get("product");
|
|
|
|
|
- productAttr = (List<FsStoreProductAttr>) cachedData.get("productAttr");
|
|
|
|
|
- productValues = (List<FsStoreProductAttrValue>) cachedData.get("productValues");
|
|
|
|
|
- } else {
|
|
|
|
|
- // 缓存中没有,从数据库查询
|
|
|
|
|
- product = fsStoreProductService.selectFsStoreProductById(productId);
|
|
|
|
|
- if(product==null){
|
|
|
|
|
- return R.error("商品不存在或已下架");
|
|
|
|
|
- }
|
|
|
|
|
- productAttr = attrService.selectFsStoreProductAttrByProductId(productId);
|
|
|
|
|
- productValues = attrValueService.selectFsStoreProductAttrValueByProductId(productId);
|
|
|
|
|
-
|
|
|
|
|
- // 将数据存入缓存
|
|
|
|
|
- Map<String, Object> cacheData = new HashMap<>();
|
|
|
|
|
- cacheData.put("product", product);
|
|
|
|
|
- cacheData.put("productAttr", productAttr);
|
|
|
|
|
- cacheData.put("productValues", productValues);
|
|
|
|
|
- redisCache.setCacheObject(cacheKey, cacheData, LiveKeysConstant.PRODUCT_DETAIL_CACHE_EXPIRE, TimeUnit.SECONDS);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 获取用户的TOKEN写入足迹
|
|
|
|
|
- String userId=getUserId();
|
|
|
|
|
- if(userId!=null){
|
|
|
|
|
- FsStoreProductRelation productRelation=new FsStoreProductRelation();
|
|
|
|
|
- productRelation.setIsDel(0);
|
|
|
|
|
- productRelation.setUserId(Long.parseLong(userId));
|
|
|
|
|
- productRelation.setProductId(product.getProductId());
|
|
|
|
|
- productRelation.setType("foot");
|
|
|
|
|
- List<FsStoreProductRelation> productRelations=productRelationService.selectFsStoreProductRelationList(productRelation);
|
|
|
|
|
- if(productRelations!=null&&productRelations.size()>0){
|
|
|
|
|
- FsStoreProductRelation relation=productRelations.get(0);
|
|
|
|
|
- relation.setUpdateTime(new Date());
|
|
|
|
|
- productRelationService.updateFsStoreProductRelation(relation);
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- FsStoreProductRelation relation=new FsStoreProductRelation();
|
|
|
|
|
- relation.setUserId(Long.parseLong(userId));
|
|
|
|
|
- relation.setIsDel(0);
|
|
|
|
|
- relation.setProductId(product.getProductId());
|
|
|
|
|
- relation.setUpdateTime(new Date());
|
|
|
|
|
- relation.setType("foot");
|
|
|
|
|
- relation.setCreateTime(new Date());
|
|
|
|
|
- relation.setUpdateTime(new Date());
|
|
|
|
|
- productRelationService.insertFsStoreProductRelation(relation);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return R.ok().put("product",product).put("productAttr",productAttr).put("productValues",productValues);
|
|
|
|
|
|
|
+ return R.ok().put("data",fsStoreProductService.selectFsStoreProductById(productId));
|
|
|
|
|
+
|
|
|
|
|
+// // 先从缓存中获取商品详情
|
|
|
|
|
+// String cacheKey = String.format(LiveKeysConstant.PRODUCT_DETAIL_CACHE, productId);
|
|
|
|
|
+// Map<String, Object> cachedData = redisCache.getCacheObject(cacheKey);
|
|
|
|
|
+//
|
|
|
|
|
+// FsStoreProduct product;
|
|
|
|
|
+// List<FsStoreProductAttr> productAttr;
|
|
|
|
|
+// List<FsStoreProductAttrValue> productValues;
|
|
|
|
|
+//
|
|
|
|
|
+// if (cachedData != null) {
|
|
|
|
|
+// // 从缓存中获取数据
|
|
|
|
|
+// product = (FsStoreProduct) cachedData.get("product");
|
|
|
|
|
+// productAttr = (List<FsStoreProductAttr>) cachedData.get("productAttr");
|
|
|
|
|
+// productValues = (List<FsStoreProductAttrValue>) cachedData.get("productValues");
|
|
|
|
|
+// } else {
|
|
|
|
|
+// // 缓存中没有,从数据库查询
|
|
|
|
|
+// product = fsStoreProductService.selectFsStoreProductById(productId);
|
|
|
|
|
+// if(product==null){
|
|
|
|
|
+// return R.error("商品不存在或已下架");
|
|
|
|
|
+// }
|
|
|
|
|
+// productAttr = attrService.selectFsStoreProductAttrByProductId(productId);
|
|
|
|
|
+// productValues = attrValueService.selectFsStoreProductAttrValueByProductId(productId);
|
|
|
|
|
+//
|
|
|
|
|
+// // 将数据存入缓存
|
|
|
|
|
+// Map<String, Object> cacheData = new HashMap<>();
|
|
|
|
|
+// cacheData.put("product", product);
|
|
|
|
|
+// cacheData.put("productAttr", productAttr);
|
|
|
|
|
+// cacheData.put("productValues", productValues);
|
|
|
|
|
+// redisCache.setCacheObject(cacheKey, cacheData, LiveKeysConstant.PRODUCT_DETAIL_CACHE_EXPIRE, TimeUnit.SECONDS);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// // 获取用户的TOKEN写入足迹
|
|
|
|
|
+// String userId=getUserId();
|
|
|
|
|
+// if(userId!=null){
|
|
|
|
|
+// FsStoreProductRelation productRelation=new FsStoreProductRelation();
|
|
|
|
|
+// productRelation.setIsDel(0);
|
|
|
|
|
+// productRelation.setUserId(Long.parseLong(userId));
|
|
|
|
|
+// productRelation.setProductId(product.getProductId());
|
|
|
|
|
+// productRelation.setType("foot");
|
|
|
|
|
+// List<FsStoreProductRelation> productRelations=productRelationService.selectFsStoreProductRelationList(productRelation);
|
|
|
|
|
+// if(productRelations!=null&&productRelations.size()>0){
|
|
|
|
|
+// FsStoreProductRelation relation=productRelations.get(0);
|
|
|
|
|
+// relation.setUpdateTime(new Date());
|
|
|
|
|
+// productRelationService.updateFsStoreProductRelation(relation);
|
|
|
|
|
+// }
|
|
|
|
|
+// else{
|
|
|
|
|
+// FsStoreProductRelation relation=new FsStoreProductRelation();
|
|
|
|
|
+// relation.setUserId(Long.parseLong(userId));
|
|
|
|
|
+// relation.setIsDel(0);
|
|
|
|
|
+// relation.setProductId(product.getProductId());
|
|
|
|
|
+// relation.setUpdateTime(new Date());
|
|
|
|
|
+// relation.setType("foot");
|
|
|
|
|
+// relation.setCreateTime(new Date());
|
|
|
|
|
+// relation.setUpdateTime(new Date());
|
|
|
|
|
+// productRelationService.insertFsStoreProductRelation(relation);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// return R.ok().put("product",product).put("productAttr",productAttr).put("productValues",productValues);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|