Bladeren bron

feat(applet): 新增首页Banner列表接口功能

- 在AppletHomeController中添加/getBannerList接口,支持获取首页Banner列表
- 在AppletHomeService接口中定义获取启用状态Banner列表方法getBannerList
- 实现AppletHomeServiceImpl的getBannerList方法,按排序字段降序查询启用Banner
- 新增BannerInfoConverter,支持BannerInfo与BannerInfoVO的相互转换
- 引入BannerInfoMapper进行Banner信息的数据访问操作
- Banner相关类统一使用BannerInfo、BannerInfoVO,支持批量转换功能
SheepHy 14 uur geleden
bovenliggende
commit
9eba56b5ed

+ 13 - 0
src/main/java/com/zsElectric/boot/business/controller/applet/AppletHomeController.java

@@ -3,6 +3,7 @@ package com.zsElectric.boot.business.controller.applet;
 import io.swagger.v3.oas.annotations.Operation;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.zsElectric.boot.business.model.query.StationInfoQuery;
+import com.zsElectric.boot.business.model.vo.BannerInfoVO;
 import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
 import com.zsElectric.boot.business.service.AppletHomeService;
@@ -12,6 +13,7 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 @Tag(name = "小程序主页相关接口")
 @RestController
@@ -48,4 +50,15 @@ public class AppletHomeController {
             @RequestParam BigDecimal latitude) {
         return appletHomeService.getStationInfoMap(longitude, latitude);
     }
+
+    /**
+     * 获取首页Banner列表
+     *
+     * @return Banner列表
+     */
+    @Operation(summary = "获取首页Banner列表")
+    @GetMapping("/getBannerList")
+    public List<BannerInfoVO> getBannerList() {
+        return appletHomeService.getBannerList();
+    }
 }

+ 7 - 0
src/main/java/com/zsElectric/boot/business/converter/BannerInfoConverter.java

@@ -4,6 +4,9 @@ import org.mapstruct.Mapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zsElectric.boot.business.model.entity.BannerInfo;
 import com.zsElectric.boot.business.model.form.BannerInfoForm;
+import com.zsElectric.boot.business.model.vo.BannerInfoVO;
+
+import java.util.List;
 
 /**
  * 小程序banner图对象转换器
@@ -17,4 +20,8 @@ public interface BannerInfoConverter{
     BannerInfoForm toForm(BannerInfo entity);
 
     BannerInfo toEntity(BannerInfoForm formData);
+
+    BannerInfoVO toVO(BannerInfo entity);
+
+    List<BannerInfoVO> toVO(List<BannerInfo> entityList);
 }

+ 7 - 0
src/main/java/com/zsElectric/boot/business/service/AppletHomeService.java

@@ -2,6 +2,7 @@ package com.zsElectric.boot.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.zsElectric.boot.business.model.query.StationInfoQuery;
+import com.zsElectric.boot.business.model.vo.BannerInfoVO;
 import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -19,4 +20,10 @@ public interface AppletHomeService {
      * 首页地图模式
      * */
     StationInfoMapVO getStationInfoMap(BigDecimal longitude, BigDecimal latitude);
+
+    /**
+     * 获取启用状态的Banner列表
+     * @return Banner列表
+     */
+    java.util.List<BannerInfoVO> getBannerList();
 }

+ 18 - 0
src/main/java/com/zsElectric/boot/business/service/impl/AppletHomeServiceImpl.java

@@ -3,13 +3,17 @@ package com.zsElectric.boot.business.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zsElectric.boot.business.mapper.BannerInfoMapper;
 import com.zsElectric.boot.business.mapper.ThirdPartyStationInfoMapper;
 import com.zsElectric.boot.business.mapper.UserFirmMapper;
+import com.zsElectric.boot.business.model.entity.BannerInfo;
 import com.zsElectric.boot.business.model.entity.UserFirm;
 import com.zsElectric.boot.business.model.query.StationInfoQuery;
+import com.zsElectric.boot.business.model.vo.BannerInfoVO;
 import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
 import com.zsElectric.boot.business.service.AppletHomeService;
+import com.zsElectric.boot.business.converter.BannerInfoConverter;
 import com.zsElectric.boot.security.util.SecurityUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -18,6 +22,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
+import java.util.List;
 
 @Slf4j
 @Service
@@ -26,6 +31,8 @@ public class AppletHomeServiceImpl implements AppletHomeService {
 
     private final ThirdPartyStationInfoMapper thirdPartyStationInfoMapper;
     private final UserFirmMapper userFirmMapper;
+    private final BannerInfoMapper bannerInfoMapper;
+    private final BannerInfoConverter bannerInfoConverter;
 
     /**
      * 时间格式化器 HHmmss
@@ -78,4 +85,15 @@ public class AppletHomeServiceImpl implements AppletHomeService {
                 longitude, latitude, currentTime, null
         );
     }
+
+    @Override
+    public List<BannerInfoVO> getBannerList() {
+        // 查询启用状态的Banner,按排序字段降序
+        List<BannerInfo> bannerList = bannerInfoMapper.selectList(
+                new LambdaQueryWrapper<BannerInfo>()
+                        .eq(BannerInfo::getStatus, 1)
+                        .orderByDesc(BannerInfo::getSort)
+        );
+        return bannerInfoConverter.toVO(bannerList);
+    }
 }