品类添加及查询父类属性,属性组,品牌

product
yaoxin 2024-03-05 21:10:23 +08:00
parent e8392009d0
commit 59f3687b47
7 changed files with 81 additions and 18 deletions

View File

@ -112,7 +112,7 @@ public class AttributeGroupController extends BaseController {
@ApiOperation("删除属性组") @ApiOperation("删除属性组")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4") @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
public Result<String> remove(@PathVariable List<Long> ids) { public Result<String> remove(@PathVariable List<Long> ids) {
System.out.println(); attributeGroupService.deleteAsAttributeGroup(ids);
return toAjax(attributeGroupService.removeBatchByIds(ids)); return toAjax(attributeGroupService.removeBatchByIds(ids));
} }
} }

View File

@ -19,6 +19,6 @@ public interface AsAttributeGroupService extends IService<AsAttributeGroup> {
*/ */
public List<AsAttributeGroup> list(AsAttributeGroup asAttributeGroup); public List<AsAttributeGroup> list(AsAttributeGroup asAttributeGroup);
void deleteAsAttributeGroup(List<Long> attributeId); void deleteAsAttributeGroup(List<Long> groupId);
} }

View File

@ -41,4 +41,6 @@ public interface AttributeGroupService extends IService<AttributeGroup> {
public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel); public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel);
void updateAsAttributeGrop(AttributeGroupEditReq attributeGroupEditReq,Long groupId); void updateAsAttributeGrop(AttributeGroupEditReq attributeGroupEditReq,Long groupId);
void deleteAsAttributeGroup(List<Long> ids);
} }

View File

@ -1,6 +1,7 @@
package com.muyu.product.service.impl; package com.muyu.product.service.impl;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import com.muyu.common.core.utils.ObjUtils; import com.muyu.common.core.utils.ObjUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -44,15 +45,18 @@ public class AsAttributeGroupServiceImpl extends ServiceImpl<AsAttributeGroupMap
queryWrapper.eq(AsAttributeGroup::getAttributeId, asAttributeGroup.getAttributeId()); queryWrapper.eq(AsAttributeGroup::getAttributeId, asAttributeGroup.getAttributeId());
} }
return list(queryWrapper); return list(queryWrapper);
} }
@Override @Override
public void deleteAsAttributeGroup(List<Long> attributeId) { public void deleteAsAttributeGroup(List<Long> groupId) {
asAttributeGroupMapper.deleteAsAttributeGroup(attributeId); List<List<AsAttributeGroup>> lists = groupId.stream()
.map(id -> this.list(new AsAttributeGroup(null, id, null)))
.toList();
List<AsAttributeGroup> collect = lists.stream().flatMap(List::stream).collect(Collectors.toList());
List<Long> longs = collect.stream()
.map(asAttributeGroup -> asAttributeGroup.getId())
.toList();
this.removeBatchByIds(longs);
} }
} }

View File

@ -3,6 +3,7 @@ package com.muyu.product.service.impl;
import java.util.List; import java.util.List;
import com.muyu.common.core.utils.ObjUtils; import com.muyu.common.core.utils.ObjUtils;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.muyu.product.mapper.AsBrandProjectMapper; import com.muyu.product.mapper.AsBrandProjectMapper;
@ -19,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
*/ */
@Slf4j @Slf4j
@Service @Service
@Log4j2
public class AsBrandProjectServiceImpl extends ServiceImpl<AsBrandProjectMapper, AsBrandProject> implements AsBrandProjectService { public class AsBrandProjectServiceImpl extends ServiceImpl<AsBrandProjectMapper, AsBrandProject> implements AsBrandProjectService {
/** /**
@ -40,10 +42,6 @@ public class AsBrandProjectServiceImpl extends ServiceImpl<AsBrandProjectMapper,
queryWrapper.eq(AsBrandProject::getProjectId, asBrandProject.getProjectId()); queryWrapper.eq(AsBrandProject::getProjectId, asBrandProject.getProjectId());
} }
return list(queryWrapper); return list(queryWrapper);
} }
} }

View File

@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@ -129,4 +130,9 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
.toList() .toList()
); );
} }
@Override
public void deleteAsAttributeGroup(List<Long> ids) {
asAttributeGroupService.deleteAsAttributeGroup(ids);
}
} }

View File

@ -39,7 +39,7 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
private AttributeInfoService attributeInfoService; private AttributeInfoService attributeInfoService;
@Autowired @Autowired
private AsAttributeGroupService asAttributeGroupService; private AttributeGroupService attributeGroupService;
@Autowired @Autowired
private BrandInfoService brandInfoService; private BrandInfoService brandInfoService;
@ -99,7 +99,30 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
*/ */
@Override @Override
public List<AttributeGroup> getAttributeGroupList(Long categoryId) { public List<AttributeGroup> getAttributeGroupList(Long categoryId) {
return null; ArrayList<AttributeGroup> attributeGroups = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryAttributeGroup::getCategoryId,categoryId);
List<AsCategoryAttributeGroup> asCategoryAttributeGroups = asCategoryAttributeGroupService.list(queryWrapper);
if (asCategoryAttributeGroups != null && !asCategoryAttributeGroups.isEmpty()){
List<Long> attributeGroupIdList = asCategoryAttributeGroups.stream()
.map(AsCategoryAttributeGroup::getAttributeGroupId)
.toList();
attributeGroups.addAll(attributeGroupService.listByIds(attributeGroupIdList));
}
CategoryInfo categoryInfo = this.getById(categoryId);
if (categoryInfo.getParentId() !=0){
if (attributeGroups.isEmpty()){
attributeGroups.addAll(getAttributeGroupList(categoryInfo.getParentId()));
}else{
List<AttributeGroup> attributeGroupList = getAttributeGroupList(categoryInfo.getParentId());
for (AttributeGroup attributeGroup : attributeGroupList) {
if (!attributeGroups.contains(attributeGroup)){
attributeGroups.add(attributeGroup);
}
}
}
}
return attributeGroups;
} }
/** /**
@ -113,7 +136,7 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryAttribute::getCategoryId,categoryId); queryWrapper.eq(AsCategoryAttribute::getCategoryId,categoryId);
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper); List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper);
if (asCategoryAttributeList != null && asCategoryAttributeList.isEmpty()){ if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()){
List<Long> attributeIdList = asCategoryAttributeList.stream() List<Long> attributeIdList = asCategoryAttributeList.stream()
.map(AsCategoryAttribute::getAttributeId) .map(AsCategoryAttribute::getAttributeId)
.toList(); .toList();
@ -122,10 +145,17 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
CategoryInfo categoryInfo = this.getById(categoryId); CategoryInfo categoryInfo = this.getById(categoryId);
if (categoryInfo.getParentId() !=0){ if (categoryInfo.getParentId() !=0){
if (attributeInfoList.isEmpty()){ if (attributeInfoList.isEmpty()){
attributeInfoList.addAll(getAttributeInfoList(categoryInfo.getParentId()));
}else{
List<AttributeInfo> attributeList = getAttributeInfoList(categoryInfo.getParentId());
for (AttributeInfo attribute : attributeList) {
if (!attributeInfoList.contains(attribute)){
attributeInfoList.add(attribute);
}
}
} }
} }
return null; return attributeInfoList;
} }
/** /**
@ -135,7 +165,30 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
*/ */
@Override @Override
public List<BrandInfo> getBrandInfoList(Long categoryId) { public List<BrandInfo> getBrandInfoList(Long categoryId) {
return null; ArrayList<BrandInfo> brandInfos = new ArrayList<>();
LambdaQueryWrapper<AsCategoryBrand> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryBrand::getCategoryId,categoryId);
List<AsCategoryBrand> asCategoryBrands = asCategoryBrandService.list(queryWrapper);
if (asCategoryBrands != null && !asCategoryBrands.isEmpty()){
List<Long> brandIdList = asCategoryBrands.stream()
.map(AsCategoryBrand::getBrandId)
.toList();
brandInfos.addAll(brandInfoService.listByIds(brandIdList));
}
CategoryInfo categoryInfo = this.getById(categoryId);
if (categoryInfo.getParentId() !=0){
if (brandInfos.isEmpty()){
brandInfos.addAll(getBrandInfoList(categoryInfo.getParentId()));
}else{
List<BrandInfo> brandInfoList = getBrandInfoList(categoryInfo.getParentId());
for (BrandInfo brandInfo : brandInfoList) {
if (!brandInfos.contains(brandInfo)){
brandInfos.add(brandInfo);
}
}
}
}
return brandInfos;
} }
@Override @Override