Parcourir la source

新增用户端菜单详情,新增用户端官方相册名称列表及图片列表接口

zhangchen il y a 2 semaines
Parent
commit
a3758f4f5a

+ 53 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreAlbumDetailVo.java

@@ -0,0 +1,53 @@
+package shop.alien.entity.store.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 官方相册详情VO(包含相册名称、图片列表和数量)
+ *
+ * @author zhangchen
+ * @since 2025-01-16
+ */
+@Data
+@JsonInclude
+@ApiModel(value = "StoreAlbumDetailVo", description = "官方相册详情VO")
+public class StoreAlbumDetailVo {
+
+    @ApiModelProperty(value = "相册名称")
+    private String albumName;
+
+    @ApiModelProperty(value = "该相册下的图片数量")
+    private Integer imgCount;
+
+    @ApiModelProperty(value = "该相册下的图片列表")
+    private List<StoreImgInfo> imgList;
+
+    /**
+     * 图片信息
+     */
+    @Data
+    @JsonInclude
+    @ApiModel(value = "StoreImgInfo", description = "图片信息")
+    public static class StoreImgInfo {
+        @ApiModelProperty(value = "图片ID")
+        private Integer id;
+
+        @ApiModelProperty(value = "图片链接")
+        private String imgUrl;
+
+        @ApiModelProperty(value = "图片描述")
+        private String imgDescription;
+
+        @ApiModelProperty(value = "图片排序")
+        private Integer imgSort;
+
+        @ApiModelProperty(value = "图片类型")
+        private Integer imgType;
+    }
+}
+

+ 25 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreAlbumNameVo.java

@@ -0,0 +1,25 @@
+package shop.alien.entity.store.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 官方相册名称VO
+ *
+ * @author zhangchen
+ * @since 2025-01-16
+ */
+@Data
+@JsonInclude
+@ApiModel(value = "StoreAlbumNameVo", description = "官方相册名称VO")
+public class StoreAlbumNameVo {
+
+    @ApiModelProperty(value = "相册名称")
+    private String albumName;
+
+    @ApiModelProperty(value = "该相册下的图片数量")
+    private Integer imgCount;
+}
+

+ 29 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreOfficialAlbumImgVo.java

@@ -0,0 +1,29 @@
+package shop.alien.entity.store.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import shop.alien.entity.store.StoreImg;
+
+import java.util.List;
+
+/**
+ * 官方相册图片列表返回VO
+ *
+ * @author zhangchen
+ * @since 2025-01-16
+ */
+@Data
+@JsonInclude
+@ApiModel(value = "StoreOfficialAlbumImgVo", description = "官方相册图片列表返回VO")
+public class StoreOfficialAlbumImgVo {
+
+    @ApiModelProperty(value = "图片列表")
+    private List<StoreImg> imgList;
+
+    @ApiModelProperty(value = "图片总数")
+    private Integer totalCount;
+
+}
+

+ 5 - 0
alien-entity/src/main/java/shop/alien/mapper/StoreMenuMapper.java

@@ -71,4 +71,9 @@ public interface StoreMenuMapper extends BaseMapper<StoreMenu> {
     List<StoreMenuVo> getClientMenuByStoreId(@Param("storeId") Integer storeId, 
                                              @Param("dishType") Integer dishType, 
                                              @Param("dishMenuType") Integer dishMenuType);
+
+    @Select("select a.*, b.img_url, b.img_sort, b.img_description from store_menu a " +
+            "left join store_img b on a.img_id = b.id where a.delete_flag = 0 and b.delete_flag = 0 " +
+            "and a.id = #{id}")
+    StoreMenuVo getClientMenuInfoById(@Param("id") Integer id);
 }

+ 9 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreMenuController.java

@@ -175,4 +175,13 @@ public class StoreMenuController {
             return R.fail("获取菜单失败:" + e.getMessage());
         }
     }
+
+    @ApiOperation("获取门店菜单详情(用户端)")
+    @ApiOperationSupport(order = 4)
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "菜单ID", dataType = "Integer", paramType = "query")})
+    @GetMapping("/getClientMenuInfoById")
+    public R<StoreMenuVo> getClientMenuInfoById(Integer id) {
+        log.info("StoreRecommendController.getClientMenuInfoById?id={}", id);
+        return R.data(storeMenuService.getClientMenuInfoById(id));
+    }
 }

+ 92 - 5
alien-store/src/main/java/shop/alien/store/controller/StoreOfficialAlbumController.java

@@ -1,14 +1,13 @@
 package shop.alien.store.controller;
 
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiOperationSupport;
-import io.swagger.annotations.ApiSort;
+import io.swagger.annotations.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.StoreOfficialAlbum;
+import shop.alien.entity.store.vo.StoreAlbumNameVo;
+import shop.alien.entity.store.vo.StoreOfficialAlbumImgVo;
 import shop.alien.entity.store.vo.StoreOfficialAlbumVo;
 import shop.alien.store.service.StoreOfficialAlbumService;
 
@@ -51,7 +50,7 @@ public class StoreOfficialAlbumController {
     @ApiOperation("删除官方相册")
     @ApiOperationSupport(order = 3)
     @PostMapping("/deleteOfficialAlbum")
-    public  R<Boolean> deleteOfficialAlbum(@RequestBody List<StoreOfficialAlbum> storeOfficialAlbumList) {
+    public R<Boolean> deleteOfficialAlbum(@RequestBody List<StoreOfficialAlbum> storeOfficialAlbumList) {
         log.info("StoreOfficialAlbumController.deleteOfficialAlbum");
         int result = storeOfficialAlbumService.deleteOfficialAlbum(storeOfficialAlbumList);
         if (result > 0) {
@@ -59,4 +58,92 @@ public class StoreOfficialAlbumController {
         }
         return R.fail("失败");
     }
+
+    /**
+     * 获取官方相册图片列表(客户端)
+     * <p>
+     * 根据门店ID和相册名称查询官方相册中的图片列表
+     * 查询条件:imgType = 2(官方相册),通过 business_id 关联到 store_official_album 表,按 albumName 筛选
+     * </p>
+     *
+     * @param storeId   门店ID,必填,必须大于0
+     * @param albumName 相册名称,可选。例如:酒水、餐食、环境、全部等。当为null或空字符串时,查询全部
+     * @return 统一返回结果,包含图片列表和总数
+     * @throws IllegalArgumentException 当门店ID为空或小于等于0时抛出
+     */
+    @ApiOperation("获取官方相册图片列表(客户端)")
+    @ApiOperationSupport(order = 4)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "门店ID", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "albumName", value = "相册名称,例如:酒水、餐食、环境、全部等。不传或传空字符串时查询全部", dataType = "String", paramType = "query")
+    })
+    @GetMapping("/getOfficialAlbumImgList")
+    public R<StoreOfficialAlbumImgVo> getOfficialAlbumImgList(
+            @RequestParam(value = "storeId", required = true) Integer storeId,
+            @RequestParam(value = "albumName", required = false) String albumName) {
+        // 记录请求入参
+        log.info("获取官方相册图片列表,入参:storeId={}, albumName={}", storeId, albumName);
+
+        // 参数校验
+        if (storeId == null || storeId <= 0) {
+            log.warn("获取官方相册图片列表失败,门店ID无效:storeId={}", storeId);
+            return R.fail("门店ID不能为空且必须大于0");
+        }
+
+        try {
+            // 调用服务层获取图片列表
+            StoreOfficialAlbumImgVo result = storeOfficialAlbumService.getOfficialAlbumImgList(storeId, albumName);
+
+            // 记录返回结果
+            log.info("获取官方相册图片列表成功,门店ID:{},相册名称:{},返回图片数量:{}", 
+                    storeId, albumName, result.getTotalCount());
+
+            return R.data(result);
+        } catch (Exception e) {
+            log.error("获取官方相册图片列表异常,门店ID:{},异常信息:{}", storeId, e.getMessage(), e);
+            return R.fail("获取图片列表失败:" + e.getMessage());
+        }
+    }
+
+    /**
+     * 获取官方相册名称列表(客户端)
+     * <p>
+     * 根据门店ID查询所有可用的相册名称列表,用于前端展示筛选选项
+     * 返回每个相册名称及其对应的图片数量
+     * </p>
+     *
+     * @param storeId 门店ID,必填,必须大于0
+     * @return 统一返回结果,包含相册名称列表和每个相册的图片数量
+     * @throws IllegalArgumentException 当门店ID为空或小于等于0时抛出
+     */
+    @ApiOperation("获取官方相册名称列表(客户端)")
+    @ApiOperationSupport(order = 5)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "门店ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/getAlbumNameList")
+    public R<List<StoreAlbumNameVo>> getAlbumNameList(
+            @RequestParam(value = "storeId", required = true) Integer storeId) {
+        // 记录请求入参
+        log.info("获取官方相册名称列表,入参:storeId={}", storeId);
+
+        // 参数校验
+        if (storeId == null || storeId <= 0) {
+            log.warn("获取官方相册名称列表失败,门店ID无效:storeId={}", storeId);
+            return R.fail("门店ID不能为空且必须大于0");
+        }
+
+        try {
+            // 调用服务层获取相册名称列表
+            List<StoreAlbumNameVo> result = storeOfficialAlbumService.getAlbumNameList(storeId);
+
+            // 记录返回结果
+            log.info("获取官方相册名称列表成功,门店ID:{},返回相册数量:{}", storeId, result.size());
+
+            return R.data(result);
+        } catch (Exception e) {
+            log.error("获取官方相册名称列表异常,门店ID:{},异常信息:{}", storeId, e.getMessage(), e);
+            return R.fail("获取相册名称列表失败:" + e.getMessage());
+        }
+    }
 }

+ 8 - 0
alien-store/src/main/java/shop/alien/store/service/StoreMenuService.java

@@ -96,5 +96,13 @@ public interface StoreMenuService extends IService<StoreMenu> {
      * @throws IllegalArgumentException 当门店ID为空或小于等于0时抛出
      */
     List<StoreMenuVo> getClientMenuByStoreId(Integer storeId, Integer dishType, String phoneId, Integer dishMenuType);
+
+    /**
+     * 获取菜品详情
+     *
+     * @param id 菜品id
+     * @return StoreMenuVo
+     */
+    StoreMenuVo getClientMenuInfoById(Integer id);
 }
 

+ 24 - 0
alien-store/src/main/java/shop/alien/store/service/StoreOfficialAlbumService.java

@@ -13,4 +13,28 @@ public interface StoreOfficialAlbumService extends IService<StoreOfficialAlbum>
     StoreOfficialAlbum createOrUpdateOfficialAlbum(StoreOfficialAlbum storeOfficialAlbum);
     List<StoreOfficialAlbumVo> getOfficialAlbumList(String storeId);
     int deleteOfficialAlbum(List<StoreOfficialAlbum> storeOfficialAlbumList);
+    
+    /**
+     * 获取官方相册图片列表(客户端)
+     * <p>
+     * 根据门店ID和相册名称查询官方相册中的图片列表
+     * 查询条件:imgType = 2(官方相册),通过 business_id 关联到 store_official_album 表,按 albumName 筛选
+     * </p>
+     *
+     * @param storeId   门店ID,必填
+     * @param albumName 相册名称,可选。例如:酒水、餐食、环境、全部等。当为null或空字符串时,查询全部
+     * @return 图片列表和总数
+     */
+    shop.alien.entity.store.vo.StoreOfficialAlbumImgVo getOfficialAlbumImgList(Integer storeId, String albumName);
+
+    /**
+     * 获取官方相册名称列表(客户端)
+     * <p>
+     * 根据门店ID查询所有可用的相册名称列表,用于前端展示筛选选项
+     * </p>
+     *
+     * @param storeId 门店ID,必填
+     * @return 相册名称列表,包含相册名称和图片数量
+     */
+    List<shop.alien.entity.store.vo.StoreAlbumNameVo> getAlbumNameList(Integer storeId);
 }

+ 11 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreMenuServiceImpl.java

@@ -439,4 +439,15 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
             }
         });
     }
+
+    /**
+     * 获取菜品详情
+     *
+     * @param id 菜品id
+     * @return StoreMenuVo
+     */
+    @Override
+    public StoreMenuVo getClientMenuInfoById(Integer id) {
+        return storeMenuMapper.getClientMenuInfoById(id);
+    }
 }

+ 181 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreOfficialAlbumServiceImpl.java

@@ -1,14 +1,19 @@
 package shop.alien.store.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import shop.alien.entity.store.StoreImg;
 import shop.alien.entity.store.StoreOfficialAlbum;
+import shop.alien.entity.store.vo.StoreAlbumDetailVo;
+import shop.alien.entity.store.vo.StoreAlbumNameVo;
+import shop.alien.entity.store.vo.StoreOfficialAlbumImgVo;
 import shop.alien.entity.store.vo.StoreOfficialAlbumVo;
 import shop.alien.mapper.StoreImgMapper;
 import shop.alien.mapper.StoreOfficialAlbumMapper;
@@ -16,8 +21,10 @@ import shop.alien.store.service.StoreOfficialAlbumService;
 import shop.alien.store.util.CommonConstant;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Transactional
 @Service
 @RequiredArgsConstructor
@@ -97,4 +104,178 @@ public class StoreOfficialAlbumServiceImpl extends ServiceImpl<StoreOfficialAlbu
         storeImgMapper.delete(wrapper);
         return CommonConstant.ERROR_CODE_VALID_PARAMS;
     }
+
+    /**
+     * 获取官方相册图片列表(客户端)
+     * <p>
+     * 根据门店ID和相册名称查询官方相册中的图片列表
+     * 查询条件:imgType = 2(官方相册),通过 business_id 关联到 store_official_album 表,按 albumName 筛选
+     * </p>
+     *
+     * @param storeId   门店ID,必填
+     * @param albumName 相册名称,可选。例如:酒水、餐食、环境、全部等。当为null或空字符串时,查询全部
+     * @return 图片列表和总数
+     */
+    @Override
+    public StoreOfficialAlbumImgVo getOfficialAlbumImgList(Integer storeId, String albumName) {
+        log.info("开始获取官方相册图片列表,门店ID:{},相册名称:{}", storeId, albumName);
+
+        // 参数校验
+        if (storeId == null || storeId <= 0) {
+            log.warn("获取官方相册图片列表失败,门店ID无效:{}", storeId);
+            throw new IllegalArgumentException("门店ID不能为空且必须大于0");
+        }
+
+        // 先查询符合条件的官方相册ID列表
+        LambdaQueryWrapper<StoreOfficialAlbum> albumQueryWrapper = new LambdaQueryWrapper<>();
+        albumQueryWrapper.eq(StoreOfficialAlbum::getStoreId, storeId)
+                .eq(StoreOfficialAlbum::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE);
+
+        // 如果指定了相册名称,添加筛选条件
+        if (StringUtils.isNotBlank(albumName)) {
+            albumQueryWrapper.eq(StoreOfficialAlbum::getAlbumName, albumName);
+        }
+
+        List<StoreOfficialAlbum> albumList = storeOfficialAlbumMapper.selectList(albumQueryWrapper);
+
+        // 如果相册列表为空,直接返回空结果
+        if (CollectionUtils.isEmpty(albumList)) {
+            log.info("获取官方相册图片列表,门店ID:{},未查询到符合条件的相册", storeId);
+            StoreOfficialAlbumImgVo result = new StoreOfficialAlbumImgVo();
+            result.setImgList(Collections.emptyList());
+            result.setTotalCount(0);
+            return result;
+        }
+
+        // 提取相册ID列表
+        List<Integer> albumIds = albumList.stream()
+                .map(StoreOfficialAlbum::getId)
+                .collect(Collectors.toList());
+
+        log.debug("查询到符合条件的相册数量:{},相册ID列表:{}", albumList.size(), albumIds);
+
+        // 查询这些相册下的所有图片(imgType = 2 表示官方相册)
+        LambdaQueryWrapper<StoreImg> imgQueryWrapper = new LambdaQueryWrapper<>();
+        imgQueryWrapper.eq(StoreImg::getStoreId, storeId)
+                .eq(StoreImg::getImgType, CommonConstant.STORE_IMG_ALBUM) // imgType = 2 表示官方相册
+                .in(StoreImg::getBusinessId, albumIds) // business_id 关联到相册ID
+                .eq(StoreImg::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE)
+                .orderByAsc(StoreImg::getImgSort);
+
+        List<StoreImg> imgList = storeImgMapper.selectList(imgQueryWrapper);
+
+        // 构建返回结果
+        StoreOfficialAlbumImgVo result = new StoreOfficialAlbumImgVo();
+        result.setImgList(imgList);
+        result.setTotalCount(imgList.size());
+
+        log.info("获取官方相册图片列表完成,门店ID:{},相册名称:{},返回图片数量:{}", 
+                storeId, albumName, result.getTotalCount());
+
+        return result;
+    }
+
+    /**
+     * 获取官方相册名称列表(客户端)
+     * <p>
+     * 根据门店ID查询所有可用的相册名称列表,用于前端展示筛选选项
+     * 返回每个相册名称及其对应的图片数量
+     * </p>
+     *
+     * @param storeId 门店ID,必填
+     * @return 相册名称列表,包含相册名称和图片数量
+     */
+    @Override
+    public List<StoreAlbumNameVo> getAlbumNameList(Integer storeId) {
+        log.info("开始获取官方相册名称列表,门店ID:{}", storeId);
+
+        // 参数校验
+        if (storeId == null || storeId <= 0) {
+            log.warn("获取官方相册名称列表失败,门店ID无效:{}", storeId);
+            throw new IllegalArgumentException("门店ID不能为空且必须大于0");
+        }
+
+        // 查询该门店下所有未删除的官方相册
+        LambdaQueryWrapper<StoreOfficialAlbum> albumQueryWrapper = new LambdaQueryWrapper<>();
+        albumQueryWrapper.eq(StoreOfficialAlbum::getStoreId, storeId)
+                .eq(StoreOfficialAlbum::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE)
+                .isNotNull(StoreOfficialAlbum::getAlbumName)
+                .ne(StoreOfficialAlbum::getAlbumName, "");
+
+        List<StoreOfficialAlbum> albumList = storeOfficialAlbumMapper.selectList(albumQueryWrapper);
+
+        // 如果相册列表为空,直接返回空列表
+        if (CollectionUtils.isEmpty(albumList)) {
+            log.info("获取官方相册名称列表,门店ID:{},未查询到相册", storeId);
+            return Collections.emptyList();
+        }
+
+        // 提取相册ID列表
+        List<Integer> albumIds = albumList.stream()
+                .map(StoreOfficialAlbum::getId)
+                .collect(Collectors.toList());
+
+        // 查询这些相册下的所有图片(imgType = 2 表示官方相册)
+        LambdaQueryWrapper<StoreImg> imgQueryWrapper = new LambdaQueryWrapper<>();
+        imgQueryWrapper.eq(StoreImg::getStoreId, storeId)
+                .eq(StoreImg::getImgType, CommonConstant.STORE_IMG_ALBUM) // imgType = 2 表示官方相册
+                .in(StoreImg::getBusinessId, albumIds) // business_id 关联到相册ID
+                .eq(StoreImg::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE);
+
+        List<StoreImg> imgList = storeImgMapper.selectList(imgQueryWrapper);
+
+        // 构建相册ID到相册名称的映射
+        Map<Integer, String> albumIdToNameMap = albumList.stream()
+                .collect(Collectors.toMap(
+                        StoreOfficialAlbum::getId,
+                        StoreOfficialAlbum::getAlbumName,
+                        (existing, replacement) -> existing // 如果有重复的ID,保留第一个
+                ));
+
+        // 按相册名称分组统计图片数量
+        Map<String, Long> albumNameCountMap = imgList.stream()
+                .filter(img -> img.getBusinessId() != null && albumIdToNameMap.containsKey(img.getBusinessId()))
+                .collect(Collectors.groupingBy(
+                        img -> albumIdToNameMap.get(img.getBusinessId()),
+                        Collectors.counting()
+                ));
+
+        // 转换为返回VO列表
+        List<StoreAlbumNameVo> result = albumNameCountMap.entrySet().stream()
+                .map(entry -> {
+                    StoreAlbumNameVo vo = new StoreAlbumNameVo();
+                    vo.setAlbumName(entry.getKey());
+                    vo.setImgCount(entry.getValue().intValue());
+                    return vo;
+                })
+                .sorted((a, b) -> {
+                    // 按图片数量降序排序,如果数量相同则按名称排序
+                    int countCompare = Integer.compare(b.getImgCount(), a.getImgCount());
+                    if (countCompare != 0) {
+                        return countCompare;
+                    }
+                    return a.getAlbumName().compareTo(b.getAlbumName());
+                })
+                .collect(Collectors.toList());
+
+        log.info("获取官方相册名称列表完成,门店ID:{},返回相册数量:{}", storeId, result.size());
+
+        return result;
+    }
+
+    /**
+     * 将StoreImg转换为StoreImgInfo
+     *
+     * @param img 图片实体
+     * @return 图片信息VO
+     */
+    private StoreAlbumDetailVo.StoreImgInfo convertToImgInfo(StoreImg img) {
+        StoreAlbumDetailVo.StoreImgInfo info = new StoreAlbumDetailVo.StoreImgInfo();
+        info.setId(img.getId());
+        info.setImgUrl(img.getImgUrl());
+        info.setImgDescription(img.getImgDescription());
+        info.setImgSort(img.getImgSort());
+        info.setImgType(img.getImgType());
+        return info;
+    }
 }