Authored by Lixiaodi

修改缓存可以删除

package com.yohoufo.product.controller;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -13,8 +18,11 @@ import com.yoho.tools.docs.ApiOperation;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.common.cache.ControllerCacheAop;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.UfoJsonUtil;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.request.StoragePriceBo;
import com.yohoufo.product.response.ProductDetailResp;
import com.yohoufo.product.response.ProductSeriesTemplateResp;
... ... @@ -38,7 +46,7 @@ public class ProductController {
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.data")
//@Cachable(expire=600)
@Cachable(expire=600)
public ApiResponse queryProductDetailById(
@RequestParam(value = "product_id", required = false) Integer productId) {
... ... @@ -78,8 +86,6 @@ public class ProductController {
@ApiOperation(name = "ufo.product.storage.leastprice", desc="sku的最低价")
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.storage.leastprice")
//@Cachable(expire=600)
public ApiResponse queryStorageLeastprice(
... ... @@ -96,8 +102,6 @@ public class ProductController {
}
@ApiOperation(name = "ufo.product.storage.data", desc="sku信息")
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.storage.data")
//@Cachable(expire=600)
public ApiResponse queryStorageInfo(
... ... @@ -113,8 +117,7 @@ public class ProductController {
return resp;
}
@IgnoreSignature
@IgnoreSession
// 增加库存
@RequestMapping(params = "method=ufo.product.createSkup")
public ApiResponse createSkup(@RequestBody StoragePriceBo skupBo) {
try {
... ... @@ -127,8 +130,7 @@ public class ProductController {
}
}
@IgnoreSignature
@IgnoreSession
// 售卖
@RequestMapping(params = "method=ufo.product.saleSkup")
public ApiResponse saleSkup(
@RequestParam(value = "product_id", required = false) Integer productId,
... ... @@ -143,13 +145,13 @@ public class ProductController {
}
}
@IgnoreSignature
@IgnoreSession
// 取消售卖
@RequestMapping(params = "method=ufo.product.cancelSaleSkup")
public ApiResponse cancelSaleSkup(
@RequestParam(value = "skup", required = false) Integer skup) {
try {
productService.cancelSaleSkup(skup);
clearProductCache(skup);
return new ApiResponse(200, "取消卖出成功!", Boolean.TRUE);
} catch (Exception e) {
LOG.error("取消卖出SKUP失败!", e);
... ... @@ -157,5 +159,24 @@ public class ProductController {
return new ApiResponse(code, e.getMessage(), Boolean.FALSE);
}
}
@Autowired
private ControllerCacheAop cacheAop;
private ExecutorService executors = Executors.newFixedThreadPool(1);
private void clearProductCache(Integer skup) {
executors.execute(() -> {
try {
StoragePrice sp = productService.getStoragePriceBySkup(skup);
if (sp != null) {
Integer storageId = sp.getStorageId();
cacheAop.clearCache(
ProductController.class.getMethod("queryStorageInfo", new Class[] { Integer.class }),
new Object[] { storageId });
}
} catch (Exception e) {
LOG.error("删除商品缓存失败!", e);
}
});
}
}
\ No newline at end of file
... ...
package com.yohoufo.product.service;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.request.StoragePriceBo;
import com.yohoufo.product.response.ProductDetailResp;
... ... @@ -14,6 +15,8 @@ public interface ProductService {
void saleSkup(Integer productId, Integer skup);
void cancelSaleSkup(Integer skup);
StoragePrice getStoragePriceBySkup(Integer skup);
}
... ...
... ... @@ -34,6 +34,11 @@ public class ProductServiceImpl implements ProductService{
return null;
}
@Override
public StoragePrice getStoragePriceBySkup(Integer skup) {
return storagePriceMapper.selectBySkup(skup);
}
@Override
public void createSkup(StoragePriceBo skupBo) {
storagePriceMapper.insert(exchangeCreateSkupBo(skupBo));
... ... @@ -160,4 +165,5 @@ public class ProductServiceImpl implements ProductService{
sp.setStatus(1);
return sp;
}
}
... ...