接口文档:
@Override
public AttrRespVo getAttrInfo(Long attrId) {
AttrRespVo attrRespVo = new AttrRespVo();
AttrEntity attrEntity = this.getById(attrId);
BeanUtils.copyProperties(attrEntity,attrRespVo);
// attrRespVo.setAttrGroupId();
AttrAttrgroupRelationEntity relationEntity = relationDao.selectOne(
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrId));
if (relationEntity != null) {
attrRespVo.setAttrGroupId(relationEntity.getAttrGroupId());
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(relationEntity.getAttrGroupId());
if (attrGroupEntity != null){
attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
}
// attrRespVo.setCatelogPath();
Long catelogId = attrEntity.getCatelogId();
Long[] catelogPath = categoryService.findCatelogPath(catelogId);
attrRespVo.setCatelogPath(catelogPath);
CategoryEntity categoryEntity = categoryDao.selectById(catelogId);
if (categoryEntity != null ){
attrRespVo.setCatelogName(categoryEntity.getName());
}
return attrRespVo;
}
}
测试:
@Transactional
@Override
public void updateAttr(AttrVo attrVo) {
AttrEntity attrEntity = new AttrEntity();
BeanUtils.copyProperties(attrVo,attrEntity);
this.updateById(attrEntity);
// 修改关联
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
relationEntity.setAttrGroupId(attrVo.getAttrGroupId());
relationEntity.setAttrId(attrVo.getAttrId());
Integer count = relationDao.selectCount(
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrVo.getAttrId()));
if (count > 0){
relationDao.update(relationEntity,
new UpdateWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrVo.getAttrId()));
}else {
relationDao.insert(relationEntity);
}