商品服务-平台属性
/**
* 10、获取属性分组的关联的所有属性
* /product/attrgroup/{attrgroupId}/attr/relation
* @return
*/
@GetMapping("/{attrgroupId}/attr/relation")
public R attrRelation(@PathVariable("attrgroupId") Long attrgroupId){
List<AttrEntity> entities = attrGroupService.getRelationAttr(attrgroupId);
return R.ok().put("data",entities);
}
/**
* 根据分组id查找关联的所有基本属性
* @param attrgroupId 分组id
* @return
*/
@Override
public List<AttrEntity> getRelationAttr(Long attrgroupId) {
List<AttrAttrgroupRelationEntity> enties = attrgroupRelationDao.selectList
(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_group_id", attrgroupId));
List<Long> attrIds = enties.stream().map((attr) -> {
return attr.getAttrId();
}).collect(Collectors.toList());
//非空判断
if (attrIds==null||attrIds.size()==0){
return null;
}
Collection<AttrEntity> attrEntities = attrService.listByIds(attrIds);
return (List<AttrEntity>) attrEntities;
}
=================================================================================
/**
* 13、获取属性分组没有关联的其他属性
* /product/attrgroup/{attrgroupId}/noattr/relation
* {
* page: 1,//当前页码
* limit: 10,//每页记录数
* sidx: 'id',//排序字段
* order: 'asc/desc',//排序方式
* key: '华为'//检索关键字
* }
*/
@GetMapping("/{attrgroupId}/noattr/relation")
public R attrNoRelation(@PathVariable("attrgroupId")Long attrgroupId,
@RequestParam Map<String,Object> parmas){
PageUtils page = attrService.getNoRelationAttr(parmas,attrgroupId);
return R.ok().put("page",page);
}
/**
* 获取属性分组没有关联的其他属性
* @param params 分页属性
* @param attrgroupId 当前的分组
* @return
*/
@Override
public PageUtils getNoRelationAttr(Map<String, Object> params, Long attrgroupId) {
//1、当前分组只能关联自己所属的分类里面的所有属性
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrgroupId);
Long catelogId = attrGroupEntity.getCatelogId();
//2、当前分组只能关联别的分组没有引用的属性
//2.1)、当前分类下的其他分组
List<AttrGroupEntity> group = attrGroupDao.selectList(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId));
List<Long> collect = group.stream().map(item -> {
return item.getAttrGroupId();
}).collect(Collectors.toList());
//2.2)、这些分组关联的属性
List<AttrAttrgroupRelationEntity> groupId = attrgroupRelationDao.selectList(new QueryWrapper<AttrAttrgroupRelationEntity>().in("attr_group_id", collect));
List<Long> attrIds = groupId.stream().map(item -> {
return item.getAttrId();
}).collect(Collectors.toList());
//2.3)、从当前分类的所有属性中移除这些属性;
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>().eq("catelog_id", catelogId).eq("attr_type",ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode());
if(attrIds!=null && attrIds.size()>0){
wrapper.notIn("attr_id", attrIds);
}
String key = (String) params.get("key");
if(!StringUtils.isEmpty(key)){
wrapper.and((w)->{
w.eq("attr_id",key).or().like("attr_name",key);
});
}
IPage<AttrEntity> page = this.page(new Query<AttrEntity>().getPage(params), wrapper);
PageUtils pageUtils = new PageUtils(page);
return pageUtils;
}
商品服务-新增商品
终端运行npm install --save pubsub-js
1.导入前端member模块
2.查看前端接口发送请求
3.添加商品属性测试数据