|
|
|
@ -1,14 +1,13 @@
|
|
|
|
|
package com.bookstore.bookmall.product.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
import com.bookstore.bookmall.product.constant.ProductConstant;
|
|
|
|
|
import com.bookstore.bookmall.product.dao.AttrAttrgroupRelationDao;
|
|
|
|
|
import com.bookstore.bookmall.product.dao.AttrGroupDao;
|
|
|
|
|
import com.bookstore.bookmall.product.dao.CategoryDao;
|
|
|
|
|
import com.bookstore.bookmall.product.entity.AttrAttrgroupRelationEntity;
|
|
|
|
|
import com.bookstore.bookmall.product.entity.AttrGroupEntity;
|
|
|
|
|
import com.bookstore.bookmall.product.entity.CategoryEntity;
|
|
|
|
|
import com.bookstore.bookmall.product.service.AttrAttrgroupRelationService;
|
|
|
|
|
import com.bookstore.bookmall.product.service.CategoryService;
|
|
|
|
|
import com.bookstore.bookmall.product.vo.AttrRespVo;
|
|
|
|
|
import com.bookstore.bookmall.product.vo.AttrVo;
|
|
|
|
@ -16,7 +15,6 @@ import com.mysql.cj.util.StringUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -65,18 +63,21 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
|
|
|
|
|
//保存基本数据
|
|
|
|
|
this.save(attrEntity);
|
|
|
|
|
//2、保存关联关系
|
|
|
|
|
AttrAttrgroupRelationEntity RelationEntity = new AttrAttrgroupRelationEntity();
|
|
|
|
|
RelationEntity.setAttrGroupId(attr.getAttrGroupId());
|
|
|
|
|
RelationEntity.setAttrId(attr.getAttrId());
|
|
|
|
|
RelationDao.insert(RelationEntity);
|
|
|
|
|
if (attr.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
|
|
|
|
|
AttrAttrgroupRelationEntity RelationEntity = new AttrAttrgroupRelationEntity();
|
|
|
|
|
RelationEntity.setAttrGroupId(attr.getAttrGroupId());
|
|
|
|
|
RelationEntity.setAttrId(attr.getAttrId());
|
|
|
|
|
RelationDao.insert(RelationEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//后台管理,查询基本内容和关联分组和关联属性
|
|
|
|
|
@Override
|
|
|
|
|
public PageUtils queryBasePage(Map<String, Object> params, Long cateLogId) {
|
|
|
|
|
public PageUtils queryBasePage(Map<String, Object> params, Long cateLogId, String attrType) {
|
|
|
|
|
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>();
|
|
|
|
|
if (cateLogId != 0) {
|
|
|
|
|
wrapper.eq("catelog_id", cateLogId);
|
|
|
|
|
wrapper.eq("catelog_id", cateLogId).eq("attr_name", "base".equalsIgnoreCase(attrType)?1:0);
|
|
|
|
|
}
|
|
|
|
|
String key = (String)params.get("key");
|
|
|
|
|
if (!StringUtils.isNullOrEmpty(key)) {
|
|
|
|
@ -94,14 +95,17 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
|
|
|
|
|
BeanUtils.copyProperties(attrEntity, attrRespVo);
|
|
|
|
|
//设置分组名字和分类名字
|
|
|
|
|
//在分组关系中查找id
|
|
|
|
|
AttrAttrgroupRelationEntity relationEntity = RelationDao.selectOne(
|
|
|
|
|
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrEntity.getAttrId()));
|
|
|
|
|
if (relationEntity!=null) {
|
|
|
|
|
// log.info("查询到relation");
|
|
|
|
|
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(relationEntity.getAttrGroupId());
|
|
|
|
|
attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
|
|
|
|
|
// log.info(attrGroupEntity.getAttrGroupName());
|
|
|
|
|
}
|
|
|
|
|
if ("base".equalsIgnoreCase(attrType)) {
|
|
|
|
|
AttrAttrgroupRelationEntity relationEntity = RelationDao.selectOne(
|
|
|
|
|
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrEntity.getAttrId()));
|
|
|
|
|
if (relationEntity!=null) {
|
|
|
|
|
// log.info("查询到relation");
|
|
|
|
|
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(relationEntity.getAttrGroupId());
|
|
|
|
|
attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
|
|
|
|
|
// log.info(attrGroupEntity.getAttrGroupName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
|
|
|
|
|
if (categoryEntity!=null) {
|
|
|
|
|
// log.info("查询到categoryEntity");
|
|
|
|
@ -122,20 +126,24 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
|
|
|
|
|
AttrRespVo respVo = new AttrRespVo();
|
|
|
|
|
AttrEntity attrEntity = this.getById(attrId);
|
|
|
|
|
|
|
|
|
|
//设置分组id
|
|
|
|
|
BeanUtils.copyProperties(attrEntity, respVo);
|
|
|
|
|
//如果是base
|
|
|
|
|
if (attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
|
|
|
|
|
//设置分组id
|
|
|
|
|
BeanUtils.copyProperties(attrEntity, respVo);
|
|
|
|
|
// log.info("beanutilzhengchang");
|
|
|
|
|
AttrAttrgroupRelationEntity RelationEntity = RelationDao.selectOne(
|
|
|
|
|
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrId));
|
|
|
|
|
AttrAttrgroupRelationEntity RelationEntity = RelationDao.selectOne(
|
|
|
|
|
new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attrId));
|
|
|
|
|
|
|
|
|
|
if (RelationEntity!=null) {
|
|
|
|
|
if (RelationEntity!=null) {
|
|
|
|
|
// log.info("查询属性,relation正常");
|
|
|
|
|
respVo.setAttrGroupId(RelationEntity.getAttrGroupId());
|
|
|
|
|
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(RelationEntity.getAttrGroupId());
|
|
|
|
|
if (attrGroupEntity!=null) {
|
|
|
|
|
respVo.setGroupName(attrGroupEntity.getAttrGroupName());
|
|
|
|
|
respVo.setAttrGroupId(RelationEntity.getAttrGroupId());
|
|
|
|
|
AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(RelationEntity.getAttrGroupId());
|
|
|
|
|
if (attrGroupEntity!=null) {
|
|
|
|
|
respVo.setGroupName(attrGroupEntity.getAttrGroupName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// log.info("设置分组");
|
|
|
|
|
//设置分类信息
|
|
|
|
|
Long catelogId = attrEntity.getCatelogId();
|
|
|
|
@ -149,5 +157,32 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
|
|
|
|
|
return respVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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());
|
|
|
|
|
|
|
|
|
|
if (attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
|
|
|
|
|
//如果一开始就没有分组属性,实际要做的就是新增操作,所以这里还要进行判断
|
|
|
|
|
Long 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|