Commit b8b53e1d27e391218eb5fcb853550ab0bf25445f

Authored by qinkelan@diligrp.com
1 parent 18855c0e

首页图片小程序接口

etrade-admin/src/main/java/com/diligrp/etrade/admin/api/BannerApi.java
... ... @@ -6,14 +6,14 @@ import com.diligrp.etrade.admin.service.BannerService;
6 6 import com.diligrp.etrade.admin.type.BannerDeleted;
7 7 import com.diligrp.etrade.admin.type.BannerState;
8 8 import com.diligrp.etrade.core.domain.Message;
  9 +import kotlin.collections.EmptyList;
9 10 import org.slf4j.Logger;
10 11 import org.slf4j.LoggerFactory;
11 12 import org.springframework.beans.factory.annotation.Autowired;
12   -import org.springframework.web.bind.annotation.GetMapping;
13   -import org.springframework.web.bind.annotation.PathVariable;
14   -import org.springframework.web.bind.annotation.RequestMapping;
15   -import org.springframework.web.bind.annotation.RestController;
  13 +import org.springframework.util.CollectionUtils;
  14 +import org.springframework.web.bind.annotation.*;
16 15  
  16 +import java.util.Collections;
17 17 import java.util.List;
18 18  
19 19 /** 【小程序/APP】--轮播图接口
... ... @@ -30,24 +30,53 @@ public class BannerApi {
30 30 private BannerService bannerService;
31 31  
32 32 /**
33   - * 通过【市场ID】查询状态是【可用】的轮播图
  33 + * 通过【市场ID】和【轮播图类型】查询状态是【可用】的轮播图
34 34 * @date: 2023/9/4 11:02
35   - * @param: [marketId]
  35 + * @param: [marketId 市场ID, bannerTypeId 轮播图类型]
36 36 * @return: com.diligrp.etrade.core.domain.Message<?>
37 37 **/
38   - @GetMapping(value = "/listByMarketId/{marketId}")
39   - public Message<List<Banner>> listByMarketId(@PathVariable Long marketId) {
40   - List<Banner> bannerList ;
  38 + @GetMapping(value = "/listByMarketId.api")
  39 + public Message<List<Banner>> listByMarketId(@RequestParam Long marketId, Long bannerTypeId) {
41 40 try {
42 41 BannerQuery bannerQuery = new BannerQuery();
43 42 bannerQuery.setMarketId(marketId);
44 43 bannerQuery.setState(BannerState.ENABLE.getCode());
45 44 bannerQuery.setDeleted(BannerDeleted.NO.getCode());
46   - bannerList = bannerService.listByMarketId(bannerQuery);
  45 + bannerQuery.setBannerTypeId(bannerTypeId);
  46 + List<Banner> bannerList = bannerService.listByMarketId(bannerQuery);
  47 + return Message.success(bannerList);
  48 + }catch (Exception e){
  49 + LOG.error("获取轮播图失败:{}", e.getMessage());
  50 + return Message.failure("获取轮播图失败!");
  51 + }
  52 +
  53 + }
  54 +
  55 + /**
  56 + * 【限制最多2条】通过【市场ID】和【轮播图类型】查询状态是【可用】的轮播图。
  57 + * @date: 2023/9/4 11:02
  58 + * @param: [marketId 市场ID, bannerTypeId 轮播图类型]
  59 + * @return: com.diligrp.etrade.core.domain.Message<?>
  60 + **/
  61 + @GetMapping(value = "/listByMarketIdLimitTwo.api")
  62 + public Message<List<Banner>> listByMarketIdLimitTwo(@RequestParam Long marketId, Long bannerTypeId) {
  63 + try {
  64 + BannerQuery bannerQuery = new BannerQuery();
  65 + bannerQuery.setMarketId(marketId);
  66 + bannerQuery.setState(BannerState.ENABLE.getCode());
  67 + bannerQuery.setDeleted(BannerDeleted.NO.getCode());
  68 + bannerQuery.setBannerTypeId(bannerTypeId);
  69 + List<Banner> bannerList = bannerService.listByMarketId(bannerQuery);
  70 + if (!CollectionUtils.isEmpty(bannerList) && bannerList.size()>2){
  71 + //如果轮播图大于2张,就取前2张;
  72 + List<Banner> bannerTwo = bannerList.subList(0, 2);
  73 + return Message.success(bannerTwo);
  74 + }else {
  75 + return Message.success(bannerList);
  76 + }
47 77 }catch (Exception e){
48 78 LOG.error("获取轮播图失败:{}", e.getMessage());
49 79 return Message.failure("获取轮播图失败!");
50 80 }
51   - return Message.success(bannerList);
52 81 }
53 82 }
54 83 \ No newline at end of file
... ...
etrade-admin/src/main/resources/com/diligrp/etrade/dao/mapper/BannerMapper.xml
... ... @@ -267,6 +267,9 @@
267 267 <if test="deleted != null">
268 268 and deleted = #{deleted}
269 269 </if>
  270 + <if test="bannerTypeId != null">
  271 + and banner_type_id = #{bannerTypeId}
  272 + </if>
270 273 and market_id=#{marketId,jdbcType=BIGINT}
271 274 ORDER BY sort DESC
272 275 </select>
... ...