Explorar o código

首页-拍品分类菜单

jintao.geng hai 1 semana
pai
achega
e3d920beb0

+ 26 - 1
bid/src/main/java/cn/hobbystocks/auc/web/LotController.java

@@ -3,7 +3,10 @@ package cn.hobbystocks.auc.web;
 import cn.hobbystocks.auc.common.core.controller.BaseController;
 import cn.hobbystocks.auc.common.core.domain.AjaxResult;
 import cn.hobbystocks.auc.domain.Lot;
+import cn.hobbystocks.auc.request.CategoryQueryRequest;
+import cn.hobbystocks.auc.response.SpuMainCategoryResponse;
 import cn.hobbystocks.auc.service.ILotService;
+import cn.hobbystocks.auc.service.SpuCategoryService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -12,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 @Api(tags = "移动端拍品查询")
@@ -19,8 +23,13 @@ import java.util.List;
 @RestController
 public class LotController extends BaseController {
 
-    @Autowired
+    @Resource
     ILotService lotService;
+
+    @Resource
+    SpuCategoryService spuCategoryService;
+
+
     /**
      * 热门拍品查询:查询正在竞拍中的拍品
      */
@@ -49,4 +58,20 @@ public class LotController extends BaseController {
         List<Lot> lots = lotService.queryLotByCategory(lot);
         return AjaxResult.success(lots);
     }
+
+
+    /**
+     * 根据分类查询拍品
+     */
+    @PostMapping("/category/query")
+    @ApiOperation("资产·珍品-拍品分类")
+    public AjaxResult queryAllCategory(@RequestBody CategoryQueryRequest request){
+        List<SpuMainCategoryResponse> allCategoryList = spuCategoryService.queryAllCategory(request);
+        return AjaxResult.success(allCategoryList);
+    }
+
+
+
+
+
 }

+ 34 - 0
lot/src/main/java/cn/hobbystocks/auc/convert/SpuCategoryConvert.java

@@ -0,0 +1,34 @@
+package cn.hobbystocks.auc.convert;
+
+
+import cn.hobbystocks.auc.domain.DiamondPosition;
+import cn.hobbystocks.auc.domain.SpuCategory;
+import cn.hobbystocks.auc.response.DiamondPositionResponse;
+import cn.hobbystocks.auc.response.SpuChildCategoryResponse;
+import cn.hobbystocks.auc.response.SpuMainCategoryResponse;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+
+/**
+ * 金刚位转换器
+ *
+ * @author: gengjintao
+ * @date: 2026/01/20
+ */
+@Mapper
+public interface SpuCategoryConvert {
+
+    SpuCategoryConvert INSTANCE = Mappers.getMapper(SpuCategoryConvert.class);
+
+
+    @Mapping(source = "id", target = "categoryId")
+    SpuMainCategoryResponse toSpuMainCategoryResponse(SpuCategory po);
+
+    @Mapping(source = "id", target = "categoryId")
+    SpuChildCategoryResponse toSpuChildCategoryResponse(SpuCategory po);
+
+
+
+}

+ 71 - 0
lot/src/main/java/cn/hobbystocks/auc/domain/SpuCategory.java

@@ -0,0 +1,71 @@
+package cn.hobbystocks.auc.domain;
+
+import cn.hobbystocks.auc.annotation.Sensitive;
+import cn.hobbystocks.auc.annotation.View;
+import cn.hobbystocks.auc.common.core.domain.BaseEntity;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.*;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.Locale;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class SpuCategory extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    private Long id;
+
+    /**
+     * 分类名称
+     */
+    private String categoryName;
+
+    /**
+     * 是否级联 0-否 1-是
+     */
+    private Integer isCascade;
+
+    /**
+     * 子标签/扩展标签(JSON/文本存储)
+     */
+    private String subLabel;
+
+    /**
+     * 排序号(数字越小越靠前)
+     */
+    private Integer sort;
+
+    /**
+     * 父分类ID(顶级分类为0)
+     */
+    private Long parentId;
+
+    /**
+     * 分类图标URL
+     */
+    private String iconUrl;
+
+    /**
+     * 状态 0-禁用 1-启用(默认1)
+     */
+    private Integer status;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+
+
+}

+ 19 - 0
lot/src/main/java/cn/hobbystocks/auc/mapper/SpuCategoryMapper.java

@@ -0,0 +1,19 @@
+package cn.hobbystocks.auc.mapper;
+
+import cn.hobbystocks.auc.domain.DiamondPosition;
+import cn.hobbystocks.auc.domain.SpuCategory;
+import cn.hobbystocks.auc.request.DiamondPositionPageRequest;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface SpuCategoryMapper {
+
+
+    List<SpuCategory> selectAllMainCategory();
+
+
+    List<SpuCategory> selectChildCategoryByParentIds(List<Long> mainCategoryIds);
+}

+ 16 - 0
lot/src/main/java/cn/hobbystocks/auc/request/CategoryQueryRequest.java

@@ -0,0 +1,16 @@
+package cn.hobbystocks.auc.request;
+
+import cn.hobbystocks.auc.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel("分类菜单查询条件对象")
+public class CategoryQueryRequest extends BaseEntity{
+
+
+    @ApiModelProperty("状态:0-禁用,1-启用")
+    private Integer status;
+
+}

+ 34 - 0
lot/src/main/java/cn/hobbystocks/auc/response/SpuChildCategoryResponse.java

@@ -0,0 +1,34 @@
+package cn.hobbystocks.auc.response;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Data
+@ApiModel("子分类VO")
+public class SpuChildCategoryResponse {
+
+    /**
+     * 子分类ID
+     */
+    @ApiModelProperty("子分类ID")
+    private Long categoryId; // 子分类ID
+    /**
+     * 子分类名称
+     */
+    @ApiModelProperty("子分类名称")
+    private String categoryName; // 子分类名称
+    /**
+     * 子分类图标
+     */
+    @ApiModelProperty("子分类图标")
+    private String iconUrl; // 子分类图标
+    /**
+     * 排序号
+     */
+    @ApiModelProperty("排序号")
+    private Integer sort; // 排序号
+}

+ 40 - 0
lot/src/main/java/cn/hobbystocks/auc/response/SpuMainCategoryResponse.java

@@ -0,0 +1,40 @@
+package cn.hobbystocks.auc.response;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Data
+@ApiModel("主分类VO")
+public class SpuMainCategoryResponse {
+
+    /**
+     * 主分类ID
+     */
+    @ApiModelProperty("主分类ID")
+    private Long categoryId; // 主分类ID
+    /**
+     * 主分类名称
+     */
+    @ApiModelProperty("主分类名称")
+    private String categoryName; // 主分类名称
+    /**
+     * 主分类图标
+     */
+    @ApiModelProperty("主分类图标")
+    private String iconUrl; // 主分类图标
+    /**
+     * 排序号
+     */
+    @ApiModelProperty("排序号")
+    private Integer sort; // 排序号
+    /**
+     * 子分类列表
+     */
+    @ApiModelProperty("子分类列表")
+    private List<SpuChildCategoryResponse> childCategoryList;
+}

+ 22 - 0
lot/src/main/java/cn/hobbystocks/auc/service/SpuCategoryService.java

@@ -0,0 +1,22 @@
+package cn.hobbystocks.auc.service;
+
+import cn.hobbystocks.auc.domain.DiamondPosition;
+import cn.hobbystocks.auc.domain.SpuCategory;
+import cn.hobbystocks.auc.request.CategoryQueryRequest;
+import cn.hobbystocks.auc.request.DiamondPositionPageRequest;
+import cn.hobbystocks.auc.request.DiamondPositionSaveRequest;
+import cn.hobbystocks.auc.response.DiamondPositionResponse;
+import cn.hobbystocks.auc.response.SpuMainCategoryResponse;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+
+public interface SpuCategoryService {
+
+    /**
+     * 查询所有分类
+     * @param request
+     * @return
+     */
+    List<SpuMainCategoryResponse> queryAllCategory(CategoryQueryRequest request);
+}

+ 76 - 0
lot/src/main/java/cn/hobbystocks/auc/service/impl/SpuCategoryServiceImpl.java

@@ -0,0 +1,76 @@
+package cn.hobbystocks.auc.service.impl;
+
+import cn.hobbystocks.auc.common.utils.DateUtils;
+import cn.hobbystocks.auc.convert.DiamondPositionConvert;
+import cn.hobbystocks.auc.convert.SpuCategoryConvert;
+import cn.hobbystocks.auc.domain.DiamondPosition;
+import cn.hobbystocks.auc.domain.SpuCategory;
+import cn.hobbystocks.auc.mapper.DiamondPositionMapper;
+import cn.hobbystocks.auc.mapper.SpuCategoryMapper;
+import cn.hobbystocks.auc.request.CategoryQueryRequest;
+import cn.hobbystocks.auc.request.DiamondPositionPageRequest;
+import cn.hobbystocks.auc.request.DiamondPositionSaveRequest;
+import cn.hobbystocks.auc.response.DiamondPositionResponse;
+import cn.hobbystocks.auc.response.SpuChildCategoryResponse;
+import cn.hobbystocks.auc.response.SpuMainCategoryResponse;
+import cn.hobbystocks.auc.service.IDiamondPositionService;
+import cn.hobbystocks.auc.service.SpuCategoryService;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@Service
+@Slf4j
+public class SpuCategoryServiceImpl implements SpuCategoryService {
+
+    @Resource
+    private DiamondPositionMapper diamondPositionMapper;
+
+    @Resource
+    private SpuCategoryMapper spuCategoryMapper;
+
+    @Override
+    public List<SpuMainCategoryResponse> queryAllCategory(CategoryQueryRequest request) {
+        // 1. 查询所有启用的主分类
+        List<SpuCategory> mainCategoryList = spuCategoryMapper.selectAllMainCategory();
+        if (CollectionUtils.isEmpty(mainCategoryList)) {
+            return Lists.newArrayList();
+        }
+        List<SpuMainCategoryResponse> spuMainCategoryResponses = mainCategoryList.stream().map(SpuCategoryConvert.INSTANCE::toSpuMainCategoryResponse).collect(Collectors.toList());
+
+        // 2. 提取所有主分类ID,批量查询子分类
+        List<Long> mainCategoryIds = spuMainCategoryResponses.stream()
+            .map(SpuMainCategoryResponse::getCategoryId)
+            .collect(Collectors.toList());
+        List<SpuCategory> allChildCategoryList = spuCategoryMapper.selectChildCategoryByParentIds(mainCategoryIds);
+
+        // 3. 按主分类ID分组子分类
+        Map<Long, List<SpuCategory>> childCategoryMap = allChildCategoryList.stream()
+            .collect(Collectors.groupingBy(SpuCategory::getParentId)); // 注意:子分类VO需加parentId字段
+
+        // 4. 嵌套子分类到对应主分类
+        spuMainCategoryResponses.forEach(main -> {
+            List<SpuCategory> childList = childCategoryMap.getOrDefault(main.getCategoryId(), Lists.newArrayList());
+            // 子分类按排序号升序
+            childList.sort(Comparator.comparingInt(SpuCategory::getSort));
+            List<SpuChildCategoryResponse> spuChildCategoryResponses = childList.stream().map(SpuCategoryConvert.INSTANCE::toSpuChildCategoryResponse).collect(Collectors.toList());
+
+            main.setChildCategoryList(spuChildCategoryResponses);
+        });
+
+        // 5. 主分类按排序号升序
+        spuMainCategoryResponses.sort(Comparator.comparingInt(SpuMainCategoryResponse::getSort));
+        return spuMainCategoryResponses;
+    }
+}