|
@@ -2,18 +2,23 @@ package cn.iocoder.yudao.module.promotion.controller.app.banner;
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.module.promotion.controller.app.banner.vo.AppBannerRespVO;
|
|
|
+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.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.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.Duration;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/promotion/banner")
|
|
@@ -21,22 +26,39 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
@Validated
|
|
|
public class AppBannerController {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private BannerService bannerService;
|
|
|
+ /**
|
|
|
+ * {@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);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
@GetMapping("/list")
|
|
|
@Operation(summary = "获得 banner 列表")
|
|
|
- // todo @芋艿:swagger 注解,待补全
|
|
|
- // TODO @芋艿:可以增加缓存,提升性能
|
|
|
- // TODO @芋艿:position = 1 时,首页;position = 10 时,拼团活动页
|
|
|
+ @Parameter(name = "position", description = "Banner position", example = "1")
|
|
|
public CommonResult<List<AppBannerRespVO>> getBannerList(@RequestParam("position") Integer position) {
|
|
|
- List<AppBannerRespVO> bannerList = new ArrayList<>();
|
|
|
- AppBannerRespVO banner1 = new AppBannerRespVO();
|
|
|
- banner1.setUrl("https://www.example.com/link1");
|
|
|
- banner1.setPicUrl("https://api.java.crmeb.net/crmebimage/public/content/2022/08/04/0f78716213f64bfa83f191d51a832cbf73f6axavoy.jpg");
|
|
|
- bannerList.add(banner1);
|
|
|
- AppBannerRespVO banner2 = new AppBannerRespVO();
|
|
|
- banner2.setUrl("https://www.example.com/link2");
|
|
|
- banner2.setPicUrl("https://api.java.crmeb.net/crmebimage/public/content/2023/01/11/be09e755268b43ee90b0db3a3e1b7132r7a6t2wvsm.jpg");
|
|
|
- bannerList.add(banner2);
|
|
|
- return success(bannerList);
|
|
|
+ return success(bannerListCache.getUnchecked(position));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AppBannerRespVO> getBannerList0(Integer position) {
|
|
|
+ List<BannerDO> bannerList = bannerService.getBannerListByPosition(position);
|
|
|
+ return BannerConvert.INSTANCE.convertList01(bannerList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/add-browse-count")
|
|
|
+ @Operation(summary = "增加 Banner 点击量")
|
|
|
+ @Parameter(name = "id", description = "Banner 编号", example = "1024")
|
|
|
+ public CommonResult<Boolean> addBrowseCount(@RequestParam("id") Long id) {
|
|
|
+ bannerService.addBannerBrowseCount(id);
|
|
|
+ return success(true);
|
|
|
}
|
|
|
|
|
|
}
|