后台系统关联属性获取可关联属性

develop
ddyd 2 weeks ago
parent b2f984c991
commit cd100a43b1

@ -36,6 +36,7 @@ public class AttrGroupController {
@Autowired
private AttrService attrService;
//删除关联属性
///product/attrgroup/attr/relation/delete
@PostMapping("/attr/relation/delete")
//自定义数据必须加@RequestBody
@ -44,7 +45,7 @@ public class AttrGroupController {
return R.ok();
}
//查找有关联的属性
///product/attrgroup/{attrgroupId}/attr/relation
@GetMapping("/{attrgroupId}/attr/relation")
private R attrRelation(@PathVariable("attrgroupId") Long attrgroupId) {
@ -52,6 +53,14 @@ public class AttrGroupController {
return R.ok().put("data",entities);
}
//查找无关联属性
//product/attrgroup/{attrgroupId}/noattr/
@GetMapping("/{attrgroupId}/noattr/relation")
private R attrNoRelation(@PathVariable("attrgroupId") Long attrgroupId,
@RequestParam Map<String, Object> params /*这个是分页参数*/) {
PageUtils page = attrService.getNoRelationAttr(params, attrgroupId);
return R.ok().put("page",page);
}
/**
*

@ -29,6 +29,9 @@ public interface AttrService extends IService<AttrEntity> {
void updateAttr(AttrVo attrVo);
List<AttrEntity> getRelationAttr(Long attrgroupId);
PageUtils getNoRelationAttr(Map<String, Object> params, Long attrgroupId);
}

@ -201,6 +201,10 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
return attr.getAttrId();
}).collect(Collectors.toList());
if (attrIds==null || attrIds.size()==0) {
return null;
}
//查找返回同一组属性
Collection<AttrEntity> attrEntities = this.listByIds(attrIds);
@ -208,4 +212,52 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
}
/*
* @Description:
* @param:
* @return:
* @Author:
* @date:
*/
@Override
public PageUtils getNoRelationAttr(Map<String, Object> params, Long attrgroupId) {
//当前分组只能获取自己所属的分类里面所有属性
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrgroupId);
//获取分类id
Long catelogId = attrGroupEntity.getCatelogId();
//筛选出其他分组
List<AttrGroupEntity> groupEntities = attrGroupDao.selectList(
new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId).ne("attr_group_id", attrgroupId));
List<Long> collect = groupEntities.stream().map((entity) -> {
return entity.getAttrGroupId();
}).collect(Collectors.toList());
//这些分组的属性
List<AttrAttrgroupRelationEntity> relationEntities = RelationDao.selectList(
new QueryWrapper<AttrAttrgroupRelationEntity>().in("attr_group_id", collect));
List<Long> attrIds = relationEntities.stream().map((entity) -> {
return entity.getAttrId();
}).collect(Collectors.toList());
//从当前分类的所有属性中移除这些属性
//条件
QueryWrapper<AttrEntity> queryWrapper = new QueryWrapper<AttrEntity>().eq("catelog_id", catelogId).eq(
"attr_type",ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode() );
//关键字查找
String key = (String) params.get("key");
if (!StringUtils.isNullOrEmpty(key)) {
queryWrapper.and((wrapper)->{
wrapper.eq("attr_id", key).or().like("attr_name", key);
});
}
if (attrIds !=null && attrIds.size() > 0) {
queryWrapper.notIn("attr_id", attrIds);
}
//分页查询
IPage<AttrEntity> page = this.page(new Query<AttrEntity>().getPage(params), queryWrapper);
PageUtils pageUtils = new PageUtils(page);
return pageUtils;
}
}
Loading…
Cancel
Save