mirror of
https://github.com/kirklin/kkmall.git
synced 2024-09-20 06:46:15 +08:00
商品服务API属性分组功能
This commit is contained in:
parent
fd838498a3
commit
519c8ab16b
|
@ -1,20 +1,16 @@
|
|||
package name.lkk.kkmall.product.controller;
|
||||
|
||||
import name.lkk.common.utils.PageUtils;
|
||||
import name.lkk.common.utils.R;
|
||||
import name.lkk.kkmall.product.entity.AttrGroupEntity;
|
||||
import name.lkk.kkmall.product.service.AttrGroupService;
|
||||
import name.lkk.kkmall.product.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import name.lkk.kkmall.product.entity.AttrGroupEntity;
|
||||
import name.lkk.kkmall.product.service.AttrGroupService;
|
||||
import name.lkk.common.utils.PageUtils;
|
||||
import name.lkk.common.utils.R;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -30,6 +26,9 @@ public class AttrGroupController {
|
|||
@Autowired
|
||||
private AttrGroupService attrGroupService;
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
|
@ -41,6 +40,15 @@ public class AttrGroupController {
|
|||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表的属性分组
|
||||
* http://127.0.0.1:88/api/product/attrgroup/list/1?page=1&key=aa
|
||||
*/
|
||||
@RequestMapping("/list/{catelogId}")
|
||||
public R list(@RequestParam Map<String, Object> params, @PathVariable("catelogId") Long catelogId){
|
||||
PageUtils page = attrGroupService.queryPage(params, catelogId);
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
|
@ -48,8 +56,9 @@ public class AttrGroupController {
|
|||
@RequestMapping("/info/{attrGroupId}")
|
||||
//@RequiresPermissions("product:attrgroup:info")
|
||||
public R info(@PathVariable("attrGroupId") Long attrGroupId){
|
||||
AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);
|
||||
|
||||
AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);
|
||||
// 用当前当前分类id查询完整路径并写入 attrGroup
|
||||
attrGroup.setCatelogPath(categoryService.findCateLogPath(attrGroup.getCatelogId()));
|
||||
return R.ok().put("attrGroup", attrGroup);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package name.lkk.kkmall.product.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 属性分组
|
||||
|
@ -45,4 +45,9 @@ public class AttrGroupEntity implements Serializable {
|
|||
*/
|
||||
private Long catelogId;
|
||||
|
||||
/**
|
||||
* 三级分类修改的时候回显路径
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private Long[] catelogPath;
|
||||
}
|
||||
|
|
|
@ -4,13 +4,12 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 商品三级分类
|
||||
*
|
||||
|
@ -64,7 +63,9 @@ public class CategoryEntity implements Serializable {
|
|||
private Integer productCount;
|
||||
/**
|
||||
* 商品子分类
|
||||
* 为空的数据就不查询了
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@TableField(exist = false)
|
||||
private List<CategoryEntity> children;
|
||||
|
||||
|
|
|
@ -16,5 +16,8 @@ import java.util.Map;
|
|||
public interface AttrGroupService extends IService<AttrGroupEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params, Long catelogId);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -34,5 +34,10 @@ public interface CategoryService extends IService<CategoryEntity> {
|
|||
List<CategoryEntity> getChildrens(CategoryEntity root, List<CategoryEntity> all);
|
||||
|
||||
void removeMenuByIds(List<Long> asList);
|
||||
/**
|
||||
* 找到catalogId 完整路径
|
||||
*/
|
||||
Long[] findCateLogPath(Long catelogId);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package name.lkk.kkmall.product.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import name.lkk.common.utils.PageUtils;
|
||||
import name.lkk.common.utils.Query;
|
||||
|
||||
import name.lkk.kkmall.product.dao.AttrGroupDao;
|
||||
import name.lkk.kkmall.product.entity.AttrGroupEntity;
|
||||
import name.lkk.kkmall.product.service.AttrGroupService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service("attrGroupService")
|
||||
|
@ -26,4 +27,26 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEnt
|
|||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params, Long catelogId) {
|
||||
String key = (String) params.get("key");
|
||||
QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<>();
|
||||
if(!ObjectUtils.isEmpty(key)){
|
||||
wrapper.and((obj)->
|
||||
obj.eq("attr_group_id", key).or().like("attr_group_name", key)
|
||||
);
|
||||
}
|
||||
if(catelogId == 0){
|
||||
IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),
|
||||
wrapper);
|
||||
return new PageUtils(page);
|
||||
}else {
|
||||
wrapper.eq("catelog_id",catelogId);
|
||||
IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),
|
||||
wrapper);
|
||||
return new PageUtils(page);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,21 +1,17 @@
|
|||
package name.lkk.kkmall.product.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import name.lkk.common.utils.PageUtils;
|
||||
import name.lkk.common.utils.Query;
|
||||
|
||||
import name.lkk.kkmall.product.dao.CategoryDao;
|
||||
import name.lkk.kkmall.product.entity.CategoryEntity;
|
||||
import name.lkk.kkmall.product.service.CategoryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service("categoryService")
|
||||
|
@ -72,4 +68,26 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
|
|||
// TODO 检查当前节点是否被别的地方引用
|
||||
baseMapper.deleteBatchIds(asList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long[] findCateLogPath(Long catelogId) {
|
||||
List<Long> paths = new ArrayList<>();
|
||||
paths = findParentPath(catelogId, paths);
|
||||
// 收集的时候是顺序 前端是逆序显示的 所以用集合工具类给它逆序一下
|
||||
Collections.reverse(paths);
|
||||
return paths.toArray(new Long[paths.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归收集所有节点
|
||||
*/
|
||||
private List<Long> findParentPath(Long catlogId, List<Long> paths) {
|
||||
// 1、收集当前节点id
|
||||
paths.add(catlogId);
|
||||
CategoryEntity byId = this.getById(catlogId);
|
||||
if (byId.getParentCid() != 0) {
|
||||
findParentPath(byId.getParentCid(), paths);
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
}
|
|
@ -21,5 +21,7 @@ mybatis-plus:
|
|||
# 配置逻辑删除 1代表删除 0代表已删除
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
server:
|
||||
port: 10000
|
Loading…
Reference in a new issue