Quellcode durchsuchen

Merge remote-tracking branch 'origin/sit-OrderFood' into sit-OrderFood

刘云鑫 vor 2 Monaten
Ursprung
Commit
f5751b9309

+ 24 - 4
alien-entity/src/main/java/shop/alien/entity/store/StoreCuisine.java

@@ -30,6 +30,14 @@ public class StoreCuisine {
     @TableField("store_id")
     private Integer storeId;
 
+    @ApiModelProperty(value = "美食类型: 1-单品,2-套餐")
+    @TableField("cuisine_type")
+    private Integer cuisineType;
+
+    @ApiModelProperty(value = "菜品分类ids(JSON数组,如:[1,2,3])")
+    @TableField("category_ids")
+    private String categoryIds;
+
     @ApiModelProperty(value = "菜名")
     @TableField("name")
     private String name;
@@ -38,6 +46,18 @@ public class StoreCuisine {
     @TableField("total_price")
     private BigDecimal totalPrice;
 
+    @ApiModelProperty(value = "首页展示(0:否, 1:是)")
+    @TableField("is_homepage_display")
+    private Integer isHomepageDisplay;
+
+    @ApiModelProperty(value = "菜品标签(JSON数组,如:[\"招牌菜\",\"推荐\"])")
+    @TableField("tags")
+    private String tags;
+
+    @ApiModelProperty(value = "菜品短评")
+    @TableField("dish_review")
+    private String dishReview;
+
     @ApiModelProperty(value = "图片列表,最多 9 张 URL")
     @TableField("images")
     private String images;
@@ -54,6 +74,10 @@ public class StoreCuisine {
     @TableField("detail_content")
     private String detailContent;
 
+    @ApiModelProperty(value = "菜品描述")
+    @TableField("description")
+    private String description;
+
     @ApiModelProperty(value = "补充说明")
     @TableField("extra_note")
     private String extraNote;
@@ -86,10 +110,6 @@ public class StoreCuisine {
     @TableField("rejection_reason")
     private String rejectionReason;
 
-    @ApiModelProperty(value = "美食类型: 1-单品,2-套餐")
-    @TableField("cuisine_type")
-    private Integer cuisineType;
-
     @ApiModelProperty(value = "删除标记, 0:未删除, 1:已删除")
     @TableField("delete_flag")
     @TableLogic

+ 20 - 0
alien-entity/src/main/java/shop/alien/entity/store/dto/CuisineComboDto.java

@@ -28,6 +28,10 @@ public class CuisineComboDto {
     @TableField("cuisine_type")
     private Integer cuisineType;
 
+    @ApiModelProperty(value = "菜品分类ids(JSON数组,如:[1,2,3])")
+    @TableField("category_ids")
+    private String categoryIds;
+
     @ApiModelProperty(value = "商户id")
     @TableField("store_id")
     private Integer storeId;
@@ -40,6 +44,18 @@ public class CuisineComboDto {
     @TableField("total_price")
     private BigDecimal totalPrice;
 
+    @ApiModelProperty(value = "首页展示(0:否, 1:是)")
+    @TableField("is_homepage_display")
+    private Integer isHomepageDisplay;
+
+    @ApiModelProperty(value = "菜品标签(JSON数组,如:[\"招牌菜\",\"推荐\"])")
+    @TableField("tags")
+    private String tags;
+
+    @ApiModelProperty(value = "菜品短评")
+    @TableField("dish_review")
+    private String dishReview;
+
     @ApiModelProperty(value = "图片列表,最多 9 张 URL")
     @TableField("images")
     private String images;
@@ -52,6 +68,10 @@ public class CuisineComboDto {
     @TableField("detail_content")
     private String detailContent;
 
+    @ApiModelProperty(value = "菜品描述")
+    @TableField("description")
+    private String description;
+
     @ApiModelProperty(value = "补充说明")
     @TableField("extra_note")
     private String extraNote;

+ 18 - 0
alien-entity/src/main/java/shop/alien/entity/store/dto/CuisineTypeResponseDto.java

@@ -38,6 +38,21 @@ public class CuisineTypeResponseDto {
         @ApiModelProperty(value = "总价")
         private BigDecimal totalPrice;
 
+        @ApiModelProperty(value = "菜品分类ids(JSON数组,如:[1,2,3])")
+        private String categoryIds;
+
+        @ApiModelProperty(value = "菜品分类名称(JSON数组,如:[\"热菜\",\"凉菜\"])")
+        private String categoryNames;
+
+        @ApiModelProperty(value = "首页展示(0:否, 1:是)")
+        private Integer isHomepageDisplay;
+
+        @ApiModelProperty(value = "菜品标签(JSON数组,如:[\"招牌菜\",\"推荐\"])")
+        private String tags;
+
+        @ApiModelProperty(value = "菜品短评")
+        private String dishReview;
+
         @ApiModelProperty(value = "图片列表,最多 9 张 URL,逗号分隔")
         private String images;
 
@@ -50,6 +65,9 @@ public class CuisineTypeResponseDto {
         @ApiModelProperty(value = "图文详情-文字")
         private String detailContent;
 
+        @ApiModelProperty(value = "菜品描述")
+        private String description;
+
         @ApiModelProperty(value = "补充说明")
         private String extraNote;
 

+ 6 - 4
alien-entity/src/main/java/shop/alien/entity/store/vo/PriceListVo.java

@@ -1,18 +1,14 @@
 package shop.alien.entity.store.vo;
 
 import com.baomidou.mybatisplus.annotation.*;
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
-import shop.alien.entity.store.StoreCuisine;
-import shop.alien.entity.store.StorePrice;
 
 import java.math.BigDecimal;
 import java.util.Date;
-import java.util.List;
 
 /**
  * 价目表通用VO
@@ -74,6 +70,12 @@ public class PriceListVo {
     @ApiModelProperty(value = "美食类型: 1-单品,2-套餐")
     private Integer cuisineType;
 
+    @ApiModelProperty(value = "菜品分类ids(JSON数组,如:[1,2,3])")
+    private String categoryIds;
+
+    @ApiModelProperty(value = "菜品分类名称(JSON数组,如:[\"热菜\",\"凉菜\"])")
+    private String categoryNames;
+
     @ApiModelProperty(value = "拒绝原因")
     private String rejectionReason;
 

+ 10 - 3
alien-entity/src/main/resources/mapper/StoreCuisineMapper.xml

@@ -8,12 +8,18 @@
     <resultMap id="BaseResultMap" type="shop.alien.entity.store.StoreCuisine">
         <id column="id" property="id" />
         <result column="store_id" property="storeId" />
+        <result column="cuisine_type" property="cuisineType" />
+        <result column="category_ids" property="categoryIds" />
         <result column="name" property="name" />
         <result column="total_price" property="totalPrice" />
+        <result column="is_homepage_display" property="isHomepageDisplay" />
+        <result column="tags" property="tags" />
+        <result column="dish_review" property="dishReview" />
         <result column="images" property="images" />
         <result column="image_content" property="imageContent" />
         <result column="raw_json" property="rawJson" />
         <result column="detail_content" property="detailContent" />
+        <result column="description" property="description" />
         <result column="extra_note" property="extraNote" />
         <result column="need_reserve" property="needReserve" />
         <result column="reserve_rule" property="reserveRule" />
@@ -31,9 +37,10 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, store_id, name, total_price, images, image_content, raw_json, detail_content,
-        extra_note, need_reserve, reserve_rule, people_limit, usage_rule, status, shelf_status,
-        rejection_reason, delete_flag, created_user_id, updated_user_id, created_time, updated_time
+        id, store_id, cuisine_type, category_ids, name, total_price, is_homepage_display, tags, dish_review,
+        images, image_content, raw_json, detail_content, description, extra_note, need_reserve, reserve_rule,
+        people_limit, usage_rule, status, shelf_status, rejection_reason, delete_flag, created_user_id,
+        updated_user_id, created_time, updated_time
     </sql>
 
 </mapper>

+ 2 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreCuisineController.java

@@ -181,6 +181,8 @@ public class StoreCuisineController {
                     PriceListVo vo = new PriceListVo();
 
                     BeanUtils.copyProperties(cuisine, vo);
+                    // 设置分类名称
+                    vo.setCategoryNames(storeCuisineService.getCategoryNames(cuisine.getCategoryIds()));
                     priceListVo.add(vo);
                 }
             }

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

@@ -42,6 +42,14 @@ public interface StoreCuisineService extends IService<StoreCuisine> {
      * 上下架操作:1-上架,2-下架
      */
     boolean changeShelfStatus(Integer id, Integer shelfStatus);
+
+    /**
+     * 根据分类ID字符串(JSON数组格式)查询分类名称
+     *
+     * @param categoryIds 分类ID字符串(JSON数组格式,如:"[1,2,3]")
+     * @return 分类名称JSON数组字符串(如:"[\"热菜\",\"凉菜\"]"),如果categoryIds为空则返回null
+     */
+    String getCategoryNames(String categoryIds);
 }
 
 

+ 108 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreCuisineServiceImpl.java

@@ -16,9 +16,11 @@ import shop.alien.entity.store.dto.CategoryGroupDto;
 import shop.alien.entity.store.dto.CuisineComboDto;
 import shop.alien.entity.store.dto.CuisineItemDto;
 import shop.alien.entity.store.dto.CuisineTypeResponseDto;
+import shop.alien.entity.store.StoreCuisineCategory;
 import shop.alien.mapper.StoreCuisineMapper;
 import shop.alien.mapper.StoreInfoMapper;
 import shop.alien.store.service.StoreCuisineComboService;
+import shop.alien.store.service.StoreCuisineCategoryService;
 import shop.alien.store.service.StoreCuisineService;
 
 import java.io.IOException;
@@ -44,6 +46,8 @@ public class StoreCuisineServiceImpl extends ServiceImpl<StoreCuisineMapper, Sto
 
     private final StoreInfoMapper storeInfoMapper;
 
+    private final StoreCuisineCategoryService storeCuisineCategoryService;
+
     /**
      * 新增美食(单品或套餐)
      */
@@ -59,6 +63,8 @@ public class StoreCuisineServiceImpl extends ServiceImpl<StoreCuisineMapper, Sto
         // 1. 保存主表信息到 store_cuisine
         StoreCuisine cuisine = new StoreCuisine();
         BeanUtils.copyProperties(cuisineComboDto, cuisine);
+        // 处理分类ID:将分类ID数组转换为JSON字符串格式存储
+        cuisine.setCategoryIds(formatCategoryIds(cuisineComboDto.getCategoryIds()));
         save(cuisine);
 
         // 单品:只写主表,不写中间表
@@ -90,6 +96,8 @@ public class StoreCuisineServiceImpl extends ServiceImpl<StoreCuisineMapper, Sto
         StoreCuisine cuisine = new StoreCuisine();
         BeanUtils.copyProperties(cuisineComboDto, cuisine);
         cuisine.setId(comboId);
+        // 处理分类ID:将分类ID数组转换为JSON字符串格式存储
+        cuisine.setCategoryIds(formatCategoryIds(cuisineComboDto.getCategoryIds()));
         updateById(cuisine);
 
         // 单品:只更新主表即可
@@ -150,9 +158,16 @@ public class StoreCuisineServiceImpl extends ServiceImpl<StoreCuisineMapper, Sto
         data.setStoreId(base.getStoreId());
         data.setName(base.getName());
         data.setTotalPrice(base.getTotalPrice());
+        data.setCategoryIds(base.getCategoryIds());
+        // 根据分类ID查询分类名称
+        data.setCategoryNames(getCategoryNames(base.getCategoryIds()));
+        data.setIsHomepageDisplay(base.getIsHomepageDisplay());
+        data.setTags(base.getTags());
+        data.setDishReview(base.getDishReview());
         data.setImages(base.getImages());
         data.setImageContent(base.getImageContent());
         data.setDetailContent(base.getDetailContent());
+        data.setDescription(base.getDescription());
         data.setExtraNote(base.getExtraNote());
         data.setNeedReserve(base.getNeedReserve());
         data.setReserveRule(base.getReserveRule());
@@ -278,6 +293,99 @@ public class StoreCuisineServiceImpl extends ServiceImpl<StoreCuisineMapper, Sto
         }
         return comboList;
     }
+
+    /**
+     * 格式化分类ID为JSON数组字符串
+     * 如果传入的是有效的JSON数组字符串,直接返回;如果是空或null,返回null
+     *
+     * @param categoryIds 分类ID字符串(JSON数组格式,如:"[1,2,3]")
+     * @return 格式化后的JSON数组字符串,如果为空则返回null
+     */
+    private String formatCategoryIds(String categoryIds) {
+        if (StringUtils.isBlank(categoryIds)) {
+            return null;
+        }
+        
+        // 去除首尾空格
+        String trimmed = categoryIds.trim();
+        
+        // 如果已经是有效的JSON数组格式(以[开头,]结尾),直接返回
+        if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
+            try {
+                // 验证是否为有效的JSON数组
+                objectMapper.readValue(trimmed, new TypeReference<List<Integer>>() {});
+                return trimmed;
+            } catch (IOException e) {
+                throw new IllegalArgumentException("分类ID格式不正确,应为JSON数组格式,如:[1,2,3]", e);
+            }
+        }
+        
+        // 如果不是JSON格式,尝试解析为逗号分隔的字符串并转换为JSON数组
+        try {
+            String[] ids = trimmed.split(",");
+            List<Integer> idList = new ArrayList<>();
+            for (String id : ids) {
+                String idStr = id.trim();
+                if (StringUtils.isNotBlank(idStr)) {
+                    idList.add(Integer.parseInt(idStr));
+                }
+            }
+            if (idList.isEmpty()) {
+                return null;
+            }
+            return objectMapper.writeValueAsString(idList);
+        } catch (NumberFormatException e) {
+            throw new IllegalArgumentException("分类ID格式不正确,应为数字数组", e);
+        } catch (IOException e) {
+            throw new RuntimeException("转换分类ID为JSON格式失败", e);
+        }
+    }
+
+    /**
+     * 根据分类ID字符串(JSON数组格式)查询分类名称
+     *
+     * @param categoryIds 分类ID字符串(JSON数组格式,如:"[1,2,3]")
+     * @return 分类名称JSON数组字符串(如:"[\"热菜\",\"凉菜\"]"),如果categoryIds为空则返回null
+     */
+    @Override
+    public String getCategoryNames(String categoryIds) {
+        if (StringUtils.isBlank(categoryIds)) {
+            return null;
+        }
+
+        try {
+            // 解析分类ID数组
+            List<Integer> idList = objectMapper.readValue(categoryIds, new TypeReference<List<Integer>>() {});
+            if (idList == null || idList.isEmpty()) {
+                return null;
+            }
+
+            // 批量查询分类信息
+            List<StoreCuisineCategory> categories = new ArrayList<>(storeCuisineCategoryService.listByIds(idList));
+            if (categories == null || categories.isEmpty()) {
+                return "[]";
+            }
+
+            // 构建ID到名称的映射
+            Map<Integer, String> idToNameMap = categories.stream()
+                    .collect(Collectors.toMap(StoreCuisineCategory::getId, StoreCuisineCategory::getCategoryName));
+
+            // 按照原始ID顺序构建名称列表
+            List<String> nameList = new ArrayList<>();
+            for (Integer id : idList) {
+                String name = idToNameMap.get(id);
+                if (name != null) {
+                    nameList.add(name);
+                }
+            }
+
+            // 转换为JSON数组字符串
+            return objectMapper.writeValueAsString(nameList);
+        } catch (IOException e) {
+            // 解析分类ID或构建分类名称失败时,返回null,不抛出异常
+            return null;
+        }
+    }
 }