首页查询修改

pull/1/head
feijinping 3 years ago
parent 300d68938e
commit 78e3fbef8f

@ -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()

@ -18,6 +18,11 @@
<artifactId>ruoyi-common</artifactId>
<version>${ruoyi.version}</version>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId>
<version>${ruoyi.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>

@ -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<HomeConfigVO> getHomeConfig() {
HomeConfigVO res = new HomeConfigVO();
res.setBanners(sysConfigService.selectConfigByKey("h5.home.banner"));
res.setCategoryList(categoryService.queryCategoryWithProductsForH5());
return ResponseEntity.ok(res);
}
}

@ -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<ProductDTO> productList;
}

@ -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;
}

@ -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<CategoryDTO> categoryList;
}

@ -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<ProductCategoryVO> dos2vos(List<ProductCategory> list);
CategoryDTO do2dto(ProductCategory it);
}

@ -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<ProductVO> dos2vos(List<Product> list);
Product vo2do(ProductVO productVO);
ProductVO do2vo(Product product);
List<ProductDTO> dos2dtos(List<Product> products);
}

@ -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<CategoryDTO> queryCategoryWithProductsForH5() {
QueryWrapper<ProductCategory> qw1 = new QueryWrapper<>();
qw1.eq("level", 0);
qw1.eq("show_status", 1);
Page<ProductCategory> pageReq = new Page<>();
pageReq.setCurrent(1L)
.setSize(10)
.setOrders(Collections.singletonList(OrderItem.desc("sort")));
List<ProductCategory> categories = productCategoryMapper.selectPage(pageReq, qw1).getRecords();
if (CollUtil.isEmpty(categories)) {
return Collections.emptyList();
};
return categories.stream().map(it -> {
CategoryDTO dto = convert.do2dto(it);
// 寻找该分类下的所有子类
List<Long> allChildCate = queryAllChildCate(Collections.singletonList(it.getId()), 0);
QueryWrapper<Product> qw = new QueryWrapper<>();
qw.select("id", "pic", "name", "price", "category_id");
qw.in("category_id", allChildCate);
qw.le("sort", 100);
List<Product> categoryId2List = productMapper.selectList(qw);
dto.setProductList(productConvert.dos2dtos(categoryId2List));
return dto;
}).collect(Collectors.toList());
}
private List<Long> queryAllChildCate(List<Long> categoryIds, int level) {
List<Long> res = new ArrayList<>();
QueryWrapper<ProductCategory> qw = new QueryWrapper<>();
qw.select("id");
List<Long> 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;
}
}

@ -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'),

Loading…
Cancel
Save