一 API
1 请求
GET /product/attrgroup/{catelogId}/withattr
2 响应数据
- {
- "msg":"success",
- "code":0,
- "data":[
- {
- "attrGroupId":1, # 第1个分组
- "attrGroupName":"主体",
- "sort":0,
- "descript":"主体",
- "icon":"dd",
- "catelogId":225,
- "attrs":[ # 第1个分组下的两个属性
- {
- "attrId":7,
- "attrName":"入网型号",
- "searchType":1,
- "valueType":0,
- "icon":"xxx",
- "valueSelect":"aaa;bb",
- "attrType":1,
- "enable":1,
- "catelogId":225,
- "showDesc":1,
- "attrGroupId":null
- },
- {
- "attrId":8,
- "attrName":"上市年份",
- "searchType":0,
- "valueType":0,
- "icon":"xxx",
- "valueSelect":"2018;2019",
- "attrType":1,
- "enable":1,
- "catelogId":225,
- "showDesc":0,
- "attrGroupId":null
- }
- ]
- },
- {
- "attrGroupId":2, # 第2个分组
- "attrGroupName":"基本信息",
- "sort":0,
- "descript":"基本信息",
- "icon":"xx",
- "catelogId":225,
- "attrs":[ # 第2个分组下的1个属性
- {
- "attrId":11,
- "attrName":"机身颜色",
- "searchType":0,
- "valueType":0,
- "icon":"xxx",
- "valueSelect":"黑色;白色",
- "attrType":1,
- "enable":1,
- "catelogId":225,
- "showDesc":1,
- "attrGroupId":null
- }
- ]
- }
- ]
- }
二 控制器
- /**
- * 功能描述:获取分类的分组以及分组下的属性
- *
- * @author cakin
- * @date 2020/11/7
- * @param catelogId 分类Id
- * @return R 返回给前端的数据
- * @description:
- */
- @GetMapping("/{catelogId}/withattr")
- public R getAttrGroupWithAttrs(@PathVariable("catelogId") Long catelogId) {
- // 1、查出当前分类下的所有属性分组,
- // 2、查出每个属性分组的所有属性
- List
vos = attrGroupService.getAttrGroupWithAttrsByCatelogId(catelogId); - return R.ok().put("data", vos);
- }
三 服务层
- /**
- * 根据分类id查出所有的分组以及这些组里面的属性
- *
- * @param catelogId
- * @return List
分组以及分组下的所有属性列表 - */
- @Override
- public List
getAttrGroupWithAttrsByCatelogId(Long catelogId) { - // 1、查询分组信息
- List
attrGroupEntities = this.list(new QueryWrapper().eq("catelog_id", catelogId)); - // 2、查询分组下所有属性
- List
collect = attrGroupEntities.stream().map(group -> { - AttrGroupWithAttrsVo attrsVo = new AttrGroupWithAttrsVo();
- BeanUtils.copyProperties(group, attrsVo);
- List
attrs = attrService.getRelationAttr(attrsVo.getAttrGroupId()); - attrsVo.setAttrs(attrs);
- return attrsVo;
- }).collect(Collectors.toList());
- return collect;
- }
四 VO
- /**
- * @className: AttrGroupWithAttrsVo
- * @description: 分组以及分组下的所有属性
- * @date: 2020/11/7
- * @author: cakin
- */
- @Data
- public class AttrGroupWithAttrsVo {
- /**
- * 分组id
- */
- private Long attrGroupId;
- /**
- * 组名
- */
- private String attrGroupName;
- /**
- * 排序
- */
- private Integer sort;
- /**
- * 描述
- */
- private String descript;
- /**
- * 组图标
- */
- private String icon;
- /**
- * 所属分类id
- */
- private Long catelogId;
- /**
- * 分组下的所有属性
- */
- private List
attrs; - }