diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
index 42b9e3f..9474d4f 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
@@ -107,6 +107,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
"/**/*.js",
"/profile/**"
).permitAll()
+ .antMatchers("/no-auth/**").permitAll()
.antMatchers("/common/download**").anonymous()
.antMatchers("/common/download/resource**").anonymous()
.antMatchers("/swagger-ui.html").anonymous()
diff --git a/ruoyi-mall/pom.xml b/ruoyi-mall/pom.xml
index 4d20b28..38db63a 100644
--- a/ruoyi-mall/pom.xml
+++ b/ruoyi-mall/pom.xml
@@ -18,6 +18,11 @@
ruoyi-common
${ruoyi.version}
+
+ com.ruoyi
+ ruoyi-system
+ ${ruoyi.version}
+
com.baomidou
mybatis-plus-boot-starter
diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/controller/HomeController.java b/ruoyi-mall/src/main/java/com/cyl/h5/controller/HomeController.java
new file mode 100644
index 0000000..e9732c3
--- /dev/null
+++ b/ruoyi-mall/src/main/java/com/cyl/h5/controller/HomeController.java
@@ -0,0 +1,32 @@
+package com.cyl.h5.controller;
+
+import com.cyl.h5.pojo.vo.HomeConfigVO;
+import com.cyl.pms.service.ProductCategoryService;
+import com.ruoyi.system.service.ISysConfigService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/no-auth/home")
+public class HomeController {
+ @Autowired
+ private ISysConfigService sysConfigService;
+ @Autowired
+ private ProductCategoryService categoryService;
+
+ /**
+ * 首页配置
+ *
+ * @return 首页配置
+ */
+ @GetMapping("/home-cfg")
+ public ResponseEntity getHomeConfig() {
+ HomeConfigVO res = new HomeConfigVO();
+ res.setBanners(sysConfigService.selectConfigByKey("h5.home.banner"));
+ res.setCategoryList(categoryService.queryCategoryWithProductsForH5());
+ return ResponseEntity.ok(res);
+ }
+}
diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/pojo/dto/CategoryDTO.java b/ruoyi-mall/src/main/java/com/cyl/h5/pojo/dto/CategoryDTO.java
new file mode 100644
index 0000000..bd8386b
--- /dev/null
+++ b/ruoyi-mall/src/main/java/com/cyl/h5/pojo/dto/CategoryDTO.java
@@ -0,0 +1,14 @@
+package com.cyl.h5.pojo.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CategoryDTO {
+ private Long id;
+ private Integer sort;
+ private String name;
+ private String icon;
+ private List productList;
+}
diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/pojo/dto/ProductDTO.java b/ruoyi-mall/src/main/java/com/cyl/h5/pojo/dto/ProductDTO.java
new file mode 100644
index 0000000..5a2e6a9
--- /dev/null
+++ b/ruoyi-mall/src/main/java/com/cyl/h5/pojo/dto/ProductDTO.java
@@ -0,0 +1,12 @@
+package com.cyl.h5.pojo.dto;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+@Data
+public class ProductDTO {
+ private Long id;
+ private String pic;
+ private String name;
+ private BigDecimal price;
+}
diff --git a/ruoyi-mall/src/main/java/com/cyl/h5/pojo/vo/HomeConfigVO.java b/ruoyi-mall/src/main/java/com/cyl/h5/pojo/vo/HomeConfigVO.java
new file mode 100644
index 0000000..7d81087
--- /dev/null
+++ b/ruoyi-mall/src/main/java/com/cyl/h5/pojo/vo/HomeConfigVO.java
@@ -0,0 +1,14 @@
+package com.cyl.h5.pojo.vo;
+
+import com.cyl.h5.pojo.dto.CategoryDTO;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class HomeConfigVO {
+ // 头部广告栏
+ private String banners;
+ // 品类列表
+ private List categoryList;
+}
diff --git a/ruoyi-mall/src/main/java/com/cyl/pms/convert/ProductCategoryConvert.java b/ruoyi-mall/src/main/java/com/cyl/pms/convert/ProductCategoryConvert.java
index 8665933..d92457f 100644
--- a/ruoyi-mall/src/main/java/com/cyl/pms/convert/ProductCategoryConvert.java
+++ b/ruoyi-mall/src/main/java/com/cyl/pms/convert/ProductCategoryConvert.java
@@ -1,5 +1,6 @@
package com.cyl.pms.convert;
+import com.cyl.h5.pojo.dto.CategoryDTO;
import org.mapstruct.Mapper;
import com.cyl.pms.domain.ProductCategory;
import com.cyl.pms.pojo.vo.ProductCategoryVO;
@@ -13,4 +14,6 @@ import java.util.List;
public interface ProductCategoryConvert {
List dos2vos(List list);
+
+ CategoryDTO do2dto(ProductCategory it);
}
diff --git a/ruoyi-mall/src/main/java/com/cyl/pms/convert/ProductConvert.java b/ruoyi-mall/src/main/java/com/cyl/pms/convert/ProductConvert.java
index a050a4a..4754f63 100644
--- a/ruoyi-mall/src/main/java/com/cyl/pms/convert/ProductConvert.java
+++ b/ruoyi-mall/src/main/java/com/cyl/pms/convert/ProductConvert.java
@@ -1,5 +1,6 @@
package com.cyl.pms.convert;
+import com.cyl.h5.pojo.dto.ProductDTO;
import org.mapstruct.Mapper;
import com.cyl.pms.domain.Product;
import com.cyl.pms.pojo.vo.ProductVO;
@@ -15,4 +16,6 @@ public interface ProductConvert {
List dos2vos(List list);
Product vo2do(ProductVO productVO);
ProductVO do2vo(Product product);
+
+ List dos2dtos(List products);
}
diff --git a/ruoyi-mall/src/main/java/com/cyl/pms/service/ProductCategoryService.java b/ruoyi-mall/src/main/java/com/cyl/pms/service/ProductCategoryService.java
index d2f31a9..a67f1d2 100644
--- a/ruoyi-mall/src/main/java/com/cyl/pms/service/ProductCategoryService.java
+++ b/ruoyi-mall/src/main/java/com/cyl/pms/service/ProductCategoryService.java
@@ -1,24 +1,29 @@
package com.cyl.pms.service;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.time.LocalDateTime;
-
-import cn.hutool.core.lang.tree.Tree;
-import cn.hutool.core.lang.tree.TreeNodeConfig;
-import cn.hutool.core.lang.tree.TreeUtil;
+import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.cyl.h5.pojo.dto.CategoryDTO;
import com.cyl.pms.convert.ProductCategoryConvert;
+import com.cyl.pms.convert.ProductConvert;
+import com.cyl.pms.domain.Product;
+import com.cyl.pms.domain.ProductCategory;
+import com.cyl.pms.mapper.ProductCategoryMapper;
+import com.cyl.pms.mapper.ProductMapper;
+import com.cyl.pms.pojo.query.ProductCategoryQuery;
import com.cyl.pms.pojo.vo.ProductCategoryVO;
import com.github.pagehelper.PageHelper;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
-import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
-import com.cyl.pms.mapper.ProductCategoryMapper;
-import com.cyl.pms.domain.ProductCategory;
-import com.cyl.pms.pojo.query.ProductCategoryQuery;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
/**
* 商品分类Service业务层处理
@@ -31,7 +36,11 @@ public class ProductCategoryService {
@Autowired
private ProductCategoryMapper productCategoryMapper;
@Autowired
+ private ProductMapper productMapper;
+ @Autowired
private ProductCategoryConvert convert;
+ @Autowired
+ private ProductConvert productConvert;
/**
* 查询商品分类
@@ -152,4 +161,51 @@ public class ProductCategoryService {
public int deleteById(Long id) {
return productCategoryMapper.deleteById(id);
}
+
+ public List queryCategoryWithProductsForH5() {
+ QueryWrapper qw1 = new QueryWrapper<>();
+ qw1.eq("level", 0);
+ qw1.eq("show_status", 1);
+ Page pageReq = new Page<>();
+ pageReq.setCurrent(1L)
+ .setSize(10)
+ .setOrders(Collections.singletonList(OrderItem.desc("sort")));
+ List categories = productCategoryMapper.selectPage(pageReq, qw1).getRecords();
+ if (CollUtil.isEmpty(categories)) {
+ return Collections.emptyList();
+ };
+ return categories.stream().map(it -> {
+ CategoryDTO dto = convert.do2dto(it);
+ // 寻找该分类下的所有子类
+ List allChildCate = queryAllChildCate(Collections.singletonList(it.getId()), 0);
+ QueryWrapper qw = new QueryWrapper<>();
+ qw.select("id", "pic", "name", "price", "category_id");
+ qw.in("category_id", allChildCate);
+ qw.le("sort", 100);
+ List categoryId2List = productMapper.selectList(qw);
+ dto.setProductList(productConvert.dos2dtos(categoryId2List));
+ return dto;
+ }).collect(Collectors.toList());
+ }
+
+ private List queryAllChildCate(List categoryIds, int level) {
+ List res = new ArrayList<>();
+ QueryWrapper qw = new QueryWrapper<>();
+ qw.select("id");
+ List ids = categoryIds;
+ while (true) {
+ qw.clear();
+ qw.in("parent_id", ids);
+ qw.eq("level", level + 1);
+ qw.eq("show_status", 1);
+ ids = productCategoryMapper.selectList(qw).stream().map(ProductCategory::getId).collect(Collectors.toList());
+ if (CollUtil.isEmpty(ids)) {
+ break;
+ }
+ res.addAll(ids);
+ level ++;
+ }
+ res.addAll(categoryIds);
+ return res;
+ }
}
diff --git a/sql/若依基础数据.sql b/sql/若依基础数据.sql
index 8cbceea..32a49c6 100644
--- a/sql/若依基础数据.sql
+++ b/sql/若依基础数据.sql
@@ -198,6 +198,11 @@ INSERT INTO `sys_dict_data` VALUES (27, 1, '成功', '0', 'sys_common_status', '
INSERT INTO `sys_dict_data` VALUES (28, 2, '失败', '1', 'sys_common_status', '', 'danger', 'N', '0', 1, '2022-06-17 17:20:29.000', NULL, NULL, '停用状态');
# 新增字典
+insert into sys_dict_type(dict_name, dict_type) values ('系统展示状态', 'sys_show_status');
+insert into sys_dict_data(dict_sort, dict_label, dict_value, dict_type)
+values (1, '展示', '1', 'sys_show_status'),
+ (2, '隐藏', '0', 'sys_show_status');
+
insert into sys_dict_type(dict_name, dict_type) values ('规格类型', 'sku_sort_list');
insert into sys_dict_data(dict_sort, dict_label, dict_value, dict_type)
values (1, '尺寸', 'sku_sort_list_1', 'sku_sort_list'),