You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
msb_mall_project/01-课件资料/01-基础课件/07-业务开发-基础业务-规格参数和销售属性.md

183 lines
8.2 KiB

2 years ago
# 规格参数
## 1.基础页面
  基础页面和属性组的页面非常类似,所以我们先创建了该页面,直接使用
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/cbe5390a467c460b8bdc43eb6f9ca213.png)
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/ca0248843c294eaeb3cc2f836543721f.png)
## 2.添加规格参数
  规格数据需要绑定对应的属性组所以我们在后台通过VO对象来接收信息
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/6821b5bcdf874f369ea28be261980c4e.png)
在后端处理添加的逻辑就需要调整
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/bab2957bc59749068a276c5aadf9d743.png)
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/31b4628883f64504bf2f4717933b31d3.png)
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/0dc734a4c23c481c9941e9a3b1956f4c.png)
保存成功,后台可以看到相关的信息
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/d01003e3787840759dac80b8770d85fc.png)
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/de64fff20bac41eb8db26a7478b22a00.png)
## 3.查询规格参数
  我们需要在后台添加一个查询规格参数的接口方法。
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/0303d561c7ba48d8906e766836ae0b07.png)
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/dfb42104c76344b5bca4503e73dcd183.png)
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/a226c9eed9124258843367959ec4b00a.png)
## 4.展示对应信息
  上面的规格数据对应的所属分类和所属属性组名没有很好的展示,这时我们可以对应的查询处理。
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/35ec8cc434fb4e7386f4e97db013b4df.png)
后台代码处理
```java
@Override
public PageUtils queryBasePage(Map<String, Object> params, Long catelogId) {
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<>();
// 1.根据类别编号查询
if(catelogId != 0 ){
wrapper.eq("catelog_id",catelogId);
}
// 2.根据key 模糊查询
String key = (String) params.get("key");
if(!StringUtils.isEmpty(key)){
wrapper.and((w)->{
w.eq("attr_id",key).or().like("attr_name",key);
});
}
// 3.分页查询
IPage<AttrEntity> page = this.page(
new Query<AttrEntity>().getPage(params),
wrapper
);
PageUtils pageUtils = new PageUtils(page);
// 4. 关联的我们需要查询出类别名称和属性组的名称
List<AttrEntity> records = page.getRecords();
List<AttrResponseVo> list = records.stream().map((attrEntity) -> {
AttrResponseVo responseVo = new AttrResponseVo();
BeanUtils.copyProperties(attrEntity, responseVo);
// 查询每一条结果对应的 类别名称和属性组的名称
CategoryEntity categoryEntity = categoryService.getById(attrEntity.getCatelogId());
if (categoryEntity != null) {
responseVo.setCatelogName(categoryEntity.getName());
}
// 设置属性组的名称
AttrAttrgroupRelationEntity entity = new AttrAttrgroupRelationEntity();
entity.setAttrId(attrEntity.getAttrId());
// 去关联表中找到对应的属性组ID
//attrAttrgroupRelationService.query(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrEntity.getAttrId()));
AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = attrAttrgroupRelationDao
.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrEntity.getAttrId()));
if (attrAttrgroupRelationEntity != null && attrAttrgroupRelationEntity.getAttrGroupId() != null) {
// 获取到属性组的ID然后根据属性组的ID我们来查询属性组的名称
AttrGroupEntity attrGroupEntity = attrGroupService.getById(attrAttrgroupRelationEntity.getAttrGroupId());
responseVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
return responseVo;
}).collect(Collectors.toList());
pageUtils.setList(list);
return pageUtils;
}
```
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/7b8c495c70a84039bbc0c04cf8f9639c.png)
## 5.更新数据
&emsp;&emsp;在规格参数修改中默认会回写基础的信息,但是对应的类别和属性组的信息不会回写。
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/b935151c1bca4a2a87aba620f04c791b.png)
这时我们需要更新后台的获取更新数据的方法
```java
/**
* 根据规格参数ID查询对应的详细信息
* 1.规格参数的具体信息
* 2.关联的属性组信息
* 3.关联的类别信息
* @param attrId
* @return
*/
@Override
public AttrResponseVo getAttrInfo(Long attrId) {
// 声明返回的对象
AttrResponseVo responseVo = new AttrResponseVo();
// 1.根据ID查询规格参数的基本信息
AttrEntity attrEntity = this.getById(attrId);
BeanUtils.copyProperties(attrEntity,responseVo);
// 2.查询关联的属性组信息 中间表
AttrAttrgroupRelationEntity relationEntity = attrAttrgroupRelationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrId));
if(relationEntity != null){
AttrGroupEntity attrGroupEntity = attrGroupService.getById(relationEntity.getAttrGroupId());
responseVo.setAttrGroupId(attrGroupEntity.getAttrGroupId());
if(attrGroupEntity != null){
responseVo.setGroupName(attrGroupEntity.getAttrGroupName());
}
}
// 3.查询关联的类别信息
Long catelogId = attrEntity.getCatelogId();
Long[] catelogPath = categoryService.findCatelogPath(catelogId);
responseVo.setCatelogPath(catelogPath);
CategoryEntity categoryEntity = categoryService.getById(catelogId);
if(categoryEntity!=null){
responseVo.setCatelogName(categoryEntity.getName());
}
return responseVo;
}
```
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/2b291ba41c0345748164302c11966aca.png)
然后就是提交更新数据的时候,默认只会更新主表的数据,这时我们还需要调整逻辑来更新管理的属性组的数据。
```java
@Transactional
@Override
public void updateBaseAttr(AttrVO attr) {
AttrEntity entity = new AttrEntity();
BeanUtils.copyProperties(attr,entity);
// 1.更新基本数据
this.updateById(entity);
// 2.修改分组关联的关系
AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
relationEntity.setAttrId(entity.getAttrId());
relationEntity.setAttrGroupId(attr.getAttrGroupId());
// 判断是否存在对应的数据
Integer count = attrAttrgroupRelationDao.selectCount(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attr.getAttrId()));
if(count > 0){
// 说明有记录,直接更新
attrAttrgroupRelationDao.update(relationEntity,new UpdateWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attr.getAttrId()));
}else{
// 说明没有记录,直接插入
attrAttrgroupRelationDao.insert(relationEntity);
}
}
```
# 销售属性
## 1.销售属性展示
&emsp;&emsp;和基本属性的内容是一致的,所以将基本属性的页面作为一个子组件引用,然后通过传值来区别
![image.png](https://fynotefile.oss-cn-zhangjiakou.aliyuncs.com/fynote/1462/1640689924000/bdcf76e1983c4b3c9f7ff0e36ea3b4e7.png)