|
|
|
@ -1,7 +1,27 @@
|
|
|
|
|
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.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.vo.AttrRespVo;
|
|
|
|
|
import com.bookstore.bookmall.product.vo.AttrVo;
|
|
|
|
|
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;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
@ -11,11 +31,19 @@ import com.bookstore.common.utils.Query;
|
|
|
|
|
import com.bookstore.bookmall.product.dao.AttrDao;
|
|
|
|
|
import com.bookstore.bookmall.product.entity.AttrEntity;
|
|
|
|
|
import com.bookstore.bookmall.product.service.AttrService;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service("attrService")
|
|
|
|
|
public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements AttrService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
AttrAttrgroupRelationDao RelationDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
CategoryDao categoryDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
AttrGroupDao attrGroupDao;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageUtils queryPage(Map<String, Object> params) {
|
|
|
|
|
IPage<AttrEntity> page = this.page(
|
|
|
|
@ -26,4 +54,64 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
|
|
|
|
|
return new PageUtils(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
@Override
|
|
|
|
|
public void saveAttr(AttrVo attr) {
|
|
|
|
|
AttrEntity attrEntity = new AttrEntity();
|
|
|
|
|
BeanUtils.copyProperties(attr, attrEntity); //复制属性,将attr复制到attrEntity,前提是属性名一一对应
|
|
|
|
|
//保存基本数据
|
|
|
|
|
this.save(attrEntity);
|
|
|
|
|
//2、保存关联关系
|
|
|
|
|
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) {
|
|
|
|
|
QueryWrapper<AttrEntity> wrapper = new QueryWrapper<AttrEntity>();
|
|
|
|
|
if (cateLogId != 0) {
|
|
|
|
|
wrapper.eq("catelog_id", cateLogId);
|
|
|
|
|
}
|
|
|
|
|
String key = (String)params.get("key");
|
|
|
|
|
if (!StringUtils.isNullOrEmpty(key)) {
|
|
|
|
|
wrapper.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);
|
|
|
|
|
List<AttrEntity> records = (List<AttrEntity>) pageUtils.getList();
|
|
|
|
|
List<AttrRespVo> respVos = records.stream().map((attrEntity) -> {
|
|
|
|
|
//拷贝基本属性
|
|
|
|
|
AttrRespVo attrRespVo = new AttrRespVo();
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
|
|
|
|
|
if (categoryEntity!=null) {
|
|
|
|
|
// log.info("查询到categoryEntity");
|
|
|
|
|
attrRespVo.setCatelogName(categoryEntity.getName());
|
|
|
|
|
// log.info(categoryEntity.getName());
|
|
|
|
|
}
|
|
|
|
|
return attrRespVo;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
pageUtils.setList(respVos);
|
|
|
|
|
return pageUtils;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|