1、商城商品服务新增前端页面

2、实现获取首页获取三级分类
pull/254/head
xjs 4 years ago
parent bc81cc344a
commit 09132426e4

@ -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;
/**
* 2vo
*
* @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{
/**
* 2id
*/
private String catalog2Id;
private String id;
private String name;
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save