|
|
|
@ -5,8 +5,6 @@ import cn.iocoder.yudao.module.promotion.controller.app.banner.vo.AppBannerRespV
|
|
|
|
import cn.iocoder.yudao.module.promotion.convert.banner.BannerConvert;
|
|
|
|
import cn.iocoder.yudao.module.promotion.convert.banner.BannerConvert;
|
|
|
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.banner.BannerDO;
|
|
|
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.banner.BannerDO;
|
|
|
|
import cn.iocoder.yudao.module.promotion.service.banner.BannerService;
|
|
|
|
import cn.iocoder.yudao.module.promotion.service.banner.BannerService;
|
|
|
|
import com.google.common.cache.CacheLoader;
|
|
|
|
|
|
|
|
import com.google.common.cache.LoadingCache;
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
@ -14,11 +12,9 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/promotion/banner")
|
|
|
|
@RequestMapping("/promotion/banner")
|
|
|
|
@ -26,20 +22,6 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync
|
|
|
|
@Validated
|
|
|
|
@Validated
|
|
|
|
public class AppBannerController {
|
|
|
|
public class AppBannerController {
|
|
|
|
|
|
|
|
|
|
|
|
// TODO @puhui999:这个目前不缓存,也没问题,因为首页没用到。
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* {@link AppBannerRespVO} 缓存,通过它异步刷新 {@link #getBannerList0(Integer)} 所要的首页数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private final LoadingCache<Integer, List<AppBannerRespVO>> bannerListCache = buildAsyncReloadingCache(Duration.ofSeconds(10L),
|
|
|
|
|
|
|
|
new CacheLoader<Integer, List<AppBannerRespVO>>() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<AppBannerRespVO> load(Integer position) {
|
|
|
|
|
|
|
|
return getBannerList0(position);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private BannerService bannerService;
|
|
|
|
private BannerService bannerService;
|
|
|
|
|
|
|
|
|
|
|
|
@ -47,12 +29,8 @@ public class AppBannerController {
|
|
|
|
@Operation(summary = "获得 banner 列表")
|
|
|
|
@Operation(summary = "获得 banner 列表")
|
|
|
|
@Parameter(name = "position", description = "Banner position", example = "1")
|
|
|
|
@Parameter(name = "position", description = "Banner position", example = "1")
|
|
|
|
public CommonResult<List<AppBannerRespVO>> getBannerList(@RequestParam("position") Integer position) {
|
|
|
|
public CommonResult<List<AppBannerRespVO>> getBannerList(@RequestParam("position") Integer position) {
|
|
|
|
return success(bannerListCache.getUnchecked(position));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<AppBannerRespVO> getBannerList0(Integer position) {
|
|
|
|
|
|
|
|
List<BannerDO> bannerList = bannerService.getBannerListByPosition(position);
|
|
|
|
List<BannerDO> bannerList = bannerService.getBannerListByPosition(position);
|
|
|
|
return BannerConvert.INSTANCE.convertList01(bannerList);
|
|
|
|
return success(BannerConvert.INSTANCE.convertList01(bannerList));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping("/add-browse-count")
|
|
|
|
@PutMapping("/add-browse-count")
|
|
|
|
|