|
|
@ -100,7 +100,9 @@ export default {
|
||||||
|
|
||||||
showBaseAttrs() {
|
showBaseAttrs() {
|
||||||
let _this = this;
|
let _this = this;
|
||||||
|
this.$modal.loading("请稍后...")
|
||||||
getAttrGroupWithAttrs(this.catalogId).then(res => {
|
getAttrGroupWithAttrs(this.catalogId).then(res => {
|
||||||
|
this.$modal.closeLoading()
|
||||||
//先对表单的baseAttrs进行初始化
|
//先对表单的baseAttrs进行初始化
|
||||||
res.data.forEach(item => {
|
res.data.forEach(item => {
|
||||||
let attrArray = [];
|
let attrArray = [];
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,16 @@
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.xjs.mall.product.controller.web;
|
||||||
|
|
||||||
|
import com.xjs.mall.product.entity.CategoryEntity;
|
||||||
|
import com.xjs.mall.product.service.CategoryService;
|
||||||
|
import com.xjs.mall.product.vo.Catelog2Vo;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首页控制器
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-04-07
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@Api(tags = "商城-商品-首页")
|
||||||
|
public class IndexController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CategoryService categoryService;
|
||||||
|
|
||||||
|
@GetMapping({"/", "index.html"})
|
||||||
|
public String indexPage(Model model) {
|
||||||
|
//查出所有一级分类
|
||||||
|
List<CategoryEntity> categoryEntityList=categoryService.getLevel1Categorys();
|
||||||
|
model.addAttribute("categorys", categoryEntityList);
|
||||||
|
return "index";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/index/json/catalog.json")
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation("获取三级分类")
|
||||||
|
public Map<String,List<Catelog2Vo>> getCatalogJson() {
|
||||||
|
return categoryService.getCatalogJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,8 +2,10 @@ package com.xjs.mall.product.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.xjs.mall.product.entity.CategoryEntity;
|
import com.xjs.mall.product.entity.CategoryEntity;
|
||||||
|
import com.xjs.mall.product.vo.Catelog2Vo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品三级分类
|
* 商品三级分类
|
||||||
|
|
@ -38,5 +40,18 @@ public interface CategoryService extends IService<CategoryEntity> {
|
||||||
* @param category 分类实体类
|
* @param category 分类实体类
|
||||||
*/
|
*/
|
||||||
void updateCascade(CategoryEntity category);
|
void updateCascade(CategoryEntity category);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有一级分类
|
||||||
|
* @return list
|
||||||
|
*/
|
||||||
|
List<CategoryEntity> getLevel1Categorys();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查出分类
|
||||||
|
* @return map
|
||||||
|
*/
|
||||||
|
Map<String, List<Catelog2Vo>> getCatalogJson();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package com.xjs.mall.product.service.impl;
|
package com.xjs.mall.product.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.xjs.mall.product.dao.CategoryDao;
|
import com.xjs.mall.product.dao.CategoryDao;
|
||||||
import com.xjs.mall.product.entity.CategoryEntity;
|
import com.xjs.mall.product.entity.CategoryEntity;
|
||||||
import com.xjs.mall.product.service.CategoryBrandRelationService;
|
import com.xjs.mall.product.service.CategoryBrandRelationService;
|
||||||
import com.xjs.mall.product.service.CategoryService;
|
import com.xjs.mall.product.service.CategoryService;
|
||||||
|
import com.xjs.mall.product.vo.Catelog2Vo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
@ -25,7 +27,6 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
|
||||||
private CategoryBrandRelationService categoryBrandRelationService;
|
private CategoryBrandRelationService categoryBrandRelationService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CategoryEntity> listWithTree() {
|
public List<CategoryEntity> listWithTree() {
|
||||||
//1、查询所有分类
|
//1、查询所有分类
|
||||||
|
|
@ -67,6 +68,52 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
|
||||||
categoryBrandRelationService.updateCategory(category.getCatId(), category.getName());
|
categoryBrandRelationService.updateCategory(category.getCatId(), category.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryEntity> getLevel1Categorys() {
|
||||||
|
LambdaQueryWrapper<CategoryEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(CategoryEntity::getParentCid, 0);
|
||||||
|
return super.list(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, List<Catelog2Vo>> getCatalogJson() {
|
||||||
|
//查出所有1级分类
|
||||||
|
List<CategoryEntity> level1Categorys = getLevel1Categorys();
|
||||||
|
|
||||||
|
//封装数据
|
||||||
|
return level1Categorys.stream().collect(Collectors.toMap(
|
||||||
|
k -> k.getCatId().toString(),
|
||||||
|
v -> {
|
||||||
|
//每一个的一级分类,查到这个一级分类的二级分类
|
||||||
|
List<CategoryEntity> categoryEntities = super.baseMapper.selectList(new LambdaQueryWrapper<CategoryEntity>().eq(CategoryEntity::getParentCid, v.getCatId()));
|
||||||
|
|
||||||
|
//封装上面的结果
|
||||||
|
List<Catelog2Vo> catelog2Vos = null;
|
||||||
|
if (categoryEntities != null) {
|
||||||
|
catelog2Vos = categoryEntities.stream().map(l2 -> {
|
||||||
|
Catelog2Vo catelog2Vo = new Catelog2Vo(v.getCatId().toString(), null, l2.getCatId().toString(), l2.getName());
|
||||||
|
|
||||||
|
// 找当前二级分类的三级分类封装成vo
|
||||||
|
List<CategoryEntity> level3Catelog = super.baseMapper.selectList(new LambdaQueryWrapper<CategoryEntity>().eq(CategoryEntity::getParentCid, l2.getCatId()));
|
||||||
|
if (level3Catelog != null) {
|
||||||
|
|
||||||
|
List<Catelog2Vo.Catelog3Vo> catelog3Vos = level3Catelog.stream().map(l3 -> {
|
||||||
|
//封装成指定格式
|
||||||
|
return new Catelog2Vo.Catelog3Vo(l2.getCatId().toString(), l3.getCatId().toString(), l3.getName());
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
catelog2Vo.setCatalog3List(catelog3Vos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return catelog2Vo;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return catelog2Vos;
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
//225,25,2
|
//225,25,2
|
||||||
private List<Long> findParentPath(Long catelogId, List<Long> paths) {
|
private List<Long> findParentPath(Long catelogId, List<Long> paths) {
|
||||||
//1、收集当前节点id
|
//1、收集当前节点id
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.xjs.mall.product.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2级分类vo
|
||||||
|
*
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-04-07
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Catelog2Vo {
|
||||||
|
/**
|
||||||
|
* 1级
|
||||||
|
*/
|
||||||
|
private String catalog1Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3级子分类
|
||||||
|
*/
|
||||||
|
private List<Catelog3Vo> catalog3List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class Catelog3Vo{
|
||||||
|
/**
|
||||||
|
* 父分类,2级分类id
|
||||||
|
*/
|
||||||
|
private String catalog2Id;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 8.7 KiB |
|
After Width: | Height: | Size: 202 B |
|
After Width: | Height: | Size: 166 B |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 139 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 105 KiB |