|
|
|
@ -1,60 +1,79 @@
|
|
|
|
|
package com.xjs.mall.product.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.xjs.mall.product.dao.AttrGroupDao;
|
|
|
|
|
import com.xjs.mall.product.entity.AttrGroupEntity;
|
|
|
|
|
import com.xjs.mall.product.entity.CategoryEntity;
|
|
|
|
|
import com.xjs.mall.product.service.AttrGroupService;
|
|
|
|
|
import com.xjs.mall.product.service.CategoryService;
|
|
|
|
|
import com.xjs.mall.product.vo.AttrGroupResponseVo;
|
|
|
|
|
import com.xjs.utils.PageUtils;
|
|
|
|
|
import com.xjs.utils.Query;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service("attrGroupService")
|
|
|
|
|
@Transactional
|
|
|
|
|
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEntity> implements AttrGroupService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageUtils queryPage(Map<String, Object> params) {
|
|
|
|
|
IPage<AttrGroupEntity> page = this.page(
|
|
|
|
|
new Query<AttrGroupEntity>().getPage(params),
|
|
|
|
|
new QueryWrapper<>()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return new PageUtils(page);
|
|
|
|
|
}
|
|
|
|
|
@Autowired
|
|
|
|
|
private CategoryService categoryService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageUtils queryPage(Map<String, Object> params, Long categoryId) {
|
|
|
|
|
String key = (String) params.get(Query.KEY_NAME);
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<AttrGroupEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
if(!StringUtils.isEmpty(key)){
|
|
|
|
|
wrapper.and((obj)->{
|
|
|
|
|
obj.eq(AttrGroupEntity::getAttrGroupId,key)
|
|
|
|
|
.or().like(AttrGroupEntity::getDescript,key)
|
|
|
|
|
.or().like(AttrGroupEntity::getAttrGroupName,key);
|
|
|
|
|
if (!StringUtils.isEmpty(key)) {
|
|
|
|
|
wrapper.and((obj) -> {
|
|
|
|
|
obj.eq(AttrGroupEntity::getAttrGroupId, key)
|
|
|
|
|
.or().like(AttrGroupEntity::getDescript, key)
|
|
|
|
|
.or().like(AttrGroupEntity::getAttrGroupName, key);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( categoryId == 0){
|
|
|
|
|
if (categoryId == 0) {
|
|
|
|
|
IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),
|
|
|
|
|
wrapper);
|
|
|
|
|
return new PageUtils(page);
|
|
|
|
|
}else {
|
|
|
|
|
wrapper.eq(AttrGroupEntity::getCatelogId,categoryId);
|
|
|
|
|
|
|
|
|
|
List<AttrGroupResponseVo> responseVoList = this.setList(page.getRecords());
|
|
|
|
|
PageUtils pageUtils = new PageUtils(page);
|
|
|
|
|
pageUtils.setList(responseVoList);
|
|
|
|
|
return pageUtils;
|
|
|
|
|
} else {
|
|
|
|
|
wrapper.eq(AttrGroupEntity::getCatelogId, categoryId);
|
|
|
|
|
IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),
|
|
|
|
|
wrapper);
|
|
|
|
|
return new PageUtils(page);
|
|
|
|
|
|
|
|
|
|
List<AttrGroupResponseVo> responseVoList = this.setList(page.getRecords());
|
|
|
|
|
PageUtils pageUtils = new PageUtils(page);
|
|
|
|
|
pageUtils.setList(responseVoList);
|
|
|
|
|
return pageUtils;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<AttrGroupResponseVo> setList(List<AttrGroupEntity> records) {
|
|
|
|
|
return records.stream().map(attrGroupEntity -> {
|
|
|
|
|
AttrGroupResponseVo attrGroupResponseVo = new AttrGroupResponseVo();
|
|
|
|
|
BeanUtils.copyProperties(attrGroupEntity, attrGroupResponseVo);
|
|
|
|
|
//获取分类实体类,主要为了获取分类名称给vo
|
|
|
|
|
CategoryEntity categoryEntity = categoryService.getById(attrGroupEntity.getCatelogId());
|
|
|
|
|
attrGroupResponseVo.setCategoryName(categoryEntity.getName());
|
|
|
|
|
return attrGroupResponseVo;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|