1./product/attrgroup/list/{catelogId}
请求参数:
{
page: 1,//当前页码
limit: 10,//每页记录数
sidx: 'id',//排序字段
order: 'asc/desc',//排序方式
key: '华为'//检索关键字
}
响应数据:{
"msg": "success",
"code": 0,
"page": {
"totalCount": 0,
"pageSize": 10,
"totalPage": 0,
"currPage": 1,
"list": [{
"attrGroupId": 0, //分组id
"attrGroupName": "string", //分组名
"catelogId": 0, //所属分类
"descript": "string", //描述
"icon": "string", //图标
"sort": 0 //排序
"catelogPath": [2,45,225] //分类完整路径
}]
}
}
@Override
public PageUtils queryPage(Map<String, Object> params, Long catelogId) {
String key = (String) params.get("key");
//前端默认catelogId为0时 展示全部的分组id,所以先判断是否为0
if(catelogId==0){
QueryWrapper<AttrGroupEntity> wapper = new QueryWrapper<>();
IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params), wapper);
return new PageUtils(page);
}
else {
//select * from table where catelog_id=?
QueryWrapper<AttrGroupEntity> catelogId1 = new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId);
//判断key是否存在 简历查询的功能
//select * from pms attr group where catelog id=? and (attr groupid=key or attr group name like key);
if(!StringUtils.isEmpty(key)){
catelogId1.and(obj->obj.eq("attr_group_id",key).or().like("attr_group_name",key));
}
IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params), catelogId1);
return new PageUtils(page);
}
}
这个接口的功能是根据请求的分页请求和key(查询搜索框上用)来返回属性分组的信息(包括属性分组的id,name,和对应的catelogid),显示的界面就是点击到第三级分类时自动显示出该catelogid对应的所有属性分组信息,使用搜索框查询时能够查询出对应的attr_group id和name。并将查询的结果进行分页显示。
2./product/attrgroup/info/{attrGroupId}
响应数据:
{
"code": 0,
"msg": "success",
"attrGroup": {
"attrGroupId": 1,
"attrGroupName": "主体",
"sort": 0,
"descript": null,
"icon": null,
"catelogId": 225,
"catelogPath": [
2,
34,
225
] //完整分类路径
}
}
@Override
public Long[] findCatelogPath(Long catelogId) {
ArrayList<Long> paths = new ArrayList<>();
List<Long> parentPath=findParentPath(catelogId,paths);
Collections.reverse(parentPath);
return parentPath.toArray(new Long[parentPath.size()]);
}
List<Long> findParentPath(Long catelogId,List<Long> paths){
paths.add(catelogId);
CategoryEntity byId = this.getById(catelogId);
if(byId.getParentCid()!=0){
findParentPath(byId.getParentCid(),paths);
}
return paths;
}
这个接口的功能时根据第三级的catelogid能够得到它的所有父类的id,就好比第三级的catelogid是225,得到的就是[2,34,225],这个用于那个属性分组修改时catelogid这栏的信息回显。