品类信息

master
Jiang Peng 2024-03-03 16:53:32 +08:00
parent 508569cf08
commit 9e72e8a3cb
11 changed files with 291 additions and 45 deletions

View File

@ -44,5 +44,11 @@ public class AsCategoryAttribute extends BaseEntity {
@ApiModelProperty(name = "属性id", value = "属性id", required = true)
private Long attributeId;
public static AsCategoryAttribute categoryBuild(Long categoryInfoId,Long attributeId){
return AsCategoryAttribute.builder()
.categoryId(categoryInfoId)
.attributeId(attributeId)
.build();
}
}

View File

@ -44,5 +44,11 @@ public class AsCategoryAttributeGroup extends BaseEntity {
@ApiModelProperty(name = "属性组", value = "属性组", required = true)
private Long attributeGroupId;
public static AsCategoryAttributeGroup categoryAttributeGroup(Long categoryId,Long attributeGroupId){
return AsCategoryAttributeGroup.builder()
.categoryId(categoryId)
.attributeGroupId(attributeGroupId)
.build();
}
}

View File

@ -44,4 +44,10 @@ public class AsCategoryBrand extends BaseEntity {
@ApiModelProperty(name = "品牌id", value = "品牌id", required = true)
private Long brandId;
public static AsCategoryBrand categoryBrand(Long categoryId,Long brandId){
return AsCategoryBrand.builder()
.categoryId(categoryId)
.brandId(brandId)
.build();
}
}

View File

@ -3,6 +3,7 @@ package com.muyu.product.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.CategoryInfoSaveModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@ -15,6 +16,9 @@ import com.muyu.product.domain.req.CategoryInfoSaveReq;
import com.muyu.product.domain.req.CategoryInfoEditReq;
import com.muyu.common.core.web.domain.TreeEntity;
import java.util.Date;
import java.util.function.Supplier;
/**
* category_info
*
@ -58,8 +62,8 @@ public class CategoryInfo extends TreeEntity {
private String introduction;
/**
*
*/
*
*/
public static CategoryInfo queryBuild( CategoryInfoQueryReq categoryInfoQueryReq){
return CategoryInfo.builder()
.name(categoryInfoQueryReq.getName())
@ -70,24 +74,38 @@ public class CategoryInfo extends TreeEntity {
}
/**
*
*/
public static CategoryInfo saveBuild(CategoryInfoSaveReq categoryInfoSaveReq){
*
*/
public static CategoryInfo saveBuild(CategoryInfoSaveReq categoryInfoSaveReq, Supplier<String> supplier){
return CategoryInfo.builder()
.name(categoryInfoSaveReq.getName())
.image(categoryInfoSaveReq.getImage())
.start(categoryInfoSaveReq.getStart())
.introduction(categoryInfoSaveReq.getIntroduction())
.parentId(categoryInfoSaveReq.getParentId())
.createBy(supplier.get())
.createTime(new Date())
.build();
}
public static CategoryInfo saveModelBuild(CategoryInfoSaveModel categoryInfoSaveModel){
return CategoryInfo.builder()
.name(categoryInfoSaveModel.getName())
.image(categoryInfoSaveModel.getImage())
.start(categoryInfoSaveModel.getStart())
.introduction(categoryInfoSaveModel.getIntroduction())
.parentId(categoryInfoSaveModel.getParentId())
.createBy(categoryInfoSaveModel.getCreateBy())
.createTime(new Date())
.build();
}
/**
*
*/
*
*/
public static CategoryInfo editBuild(Long id, CategoryInfoEditReq categoryInfoEditReq){
return CategoryInfo.builder()
.id(id)
.id(id)
.name(categoryInfoEditReq.getName())
.image(categoryInfoEditReq.getImage())
.start(categoryInfoEditReq.getStart())

View File

@ -8,6 +8,8 @@ import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.web.domain.TreeEntity;
import java.util.List;
/**
* category_info
*
@ -49,4 +51,7 @@ public class CategoryInfoSaveReq extends TreeEntity {
private String introduction;
private List<Long> attributeGroupIdList;
private List<Long> attributeIdList;
private List<Long> brandIdList;
}

View File

@ -0,0 +1,32 @@
package com.muyu.product.domain.resp;
import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.BrandInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CategoryParentCommonElementResp {
/**
*
*/
private List<AttributeInfo> attributeInfoList;
/**
*
*/
private List<AttributeGroup> attributeGroupList;
/**
*
*/
private List<BrandInfo> brandInfoList;
}

View File

@ -112,6 +112,7 @@ public class AttributeGroupController extends BaseController {
@ApiOperation("删除属性组")
@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) {
System.out.println();
return toAjax(attributeGroupService.removeBatchByIds(ids));
}
}

View File

@ -3,6 +3,8 @@ package com.muyu.product.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.model.CategoryInfoSaveModel;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -35,17 +37,16 @@ import com.muyu.product.service.CategoryInfoService;
@RestController
@RequestMapping("/category")
public class CategoryInfoController extends BaseController {
@Autowired
private CategoryInfoService categoryInfoService;
/**
*
*/
@ApiOperation("获取品类信息")
@ApiOperation("获取品类信息列表")
@RequiresPermissions("product:category:list")
@GetMapping("/list")
public Result<List<CategoryInfo>> list(CategoryInfo categoryInfo){
public Result<List<CategoryInfo>> list(CategoryInfo categoryInfo) {
List<CategoryInfo> list = categoryInfoService.list(categoryInfo);
return Result.success(list);
}
@ -55,7 +56,7 @@ public class CategoryInfoController extends BaseController {
*/
@ApiOperation("导出品类信息列表")
@RequiresPermissions("product:category:export")
@Log(title = "品类信息",businessType = BusinessType.EXPORT)
@Log(title = "品类信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, CategoryInfo categoryInfo) {
List<CategoryInfo> list = categoryInfoService.list(categoryInfo);
@ -82,7 +83,8 @@ public class CategoryInfoController extends BaseController {
@PostMapping
@ApiOperation("新增品类信息")
public Result<String> add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) {
return toAjax(categoryInfoService.save(CategoryInfo.saveBuild(categoryInfoSaveReq)));
return toAjax(categoryInfoService.save(
CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername)));
}
/**
@ -107,4 +109,15 @@ public class CategoryInfoController extends BaseController {
public Result<String> remove(@PathVariable List<Long> ids) {
return toAjax(categoryInfoService.removeBatchByIds(ids));
}
/**
* id,
*/
@GetMapping("/parentCommonElement/{categoryId}")
@ApiOperation("通过品类id查找包括父级属性集合,属性组集合以及品牌集合")
@ApiImplicitParam(name = "categoryId", value = "categoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1")
public Result parentCommonElement(@PathVariable(value = "categoryId") Long categoryId){
return categoryInfoService.parentCommonElement(categoryId);
}
}

View File

@ -1,8 +1,14 @@
package com.muyu.product.service;
import java.util.List;
import com.muyu.common.core.domain.Result;
import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.BrandInfo;
import com.muyu.product.domain.CategoryInfo;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.product.domain.model.CategoryInfoSaveModel;
/**
* Service
@ -17,4 +23,27 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
*/
public List<CategoryInfo> list(CategoryInfo categoryInfo);
/**
* id
*/
Result parentCommonElement(Long categoryId);
/**
* id
*/
List<AttributeGroup> getAttributeGroupList(Long categoryId);
/**
* id
*/
List<AttributeInfo> getAttributeInfoList(Long categoryId);
/**
* id
*/
List<BrandInfo> getBrandInfoList(Long categoryId);
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel);
}

View File

@ -2,7 +2,6 @@ package com.muyu.product.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import com.muyu.common.core.exception.ServiceException;
import com.muyu.common.core.utils.ObjUtils;
@ -27,20 +26,26 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@Service
public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, AttributeInfo> implements AttributeInfoService {
// @Autowired
// private AsAttributeGroupService asAttributeGroupService;
@Autowired
private AsAttributeGroupService asAttributeGroupService;
/**
*
*
* @param attributeInfo
* @return
*/
@Override
public List<AttributeInfo> list(AttributeInfo attributeInfo) {
LambdaQueryWrapper<AttributeInfo> queryWrapper = new LambdaQueryWrapper<>();
if(ObjUtils.notNull(attributeInfo.getName())){
queryWrapper.like(AttributeInfo::getName,attributeInfo.getName());
if (ObjUtils.notNull(attributeInfo.getName())){
queryWrapper.like(AttributeInfo::getName, attributeInfo.getName());
}
if(ObjUtils.notNull(attributeInfo.getCode())){
queryWrapper.like(AttributeInfo::getCode,attributeInfo.getCode());
if (ObjUtils.notNull(attributeInfo.getCode())){
queryWrapper.like(AttributeInfo::getCode, attributeInfo.getCode());
}
return list(queryWrapper);
@ -48,25 +53,26 @@ public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, A
/**
* groupId
*
* @param groupId Id
*
* @return
*/
@Override
public List<AttributeInfo> attributeListByGroupId(Long groupId) {
if(groupId == null){
public List<AttributeInfo> attributeListByGroupId (Long groupId) {
if (groupId == null){
throw new ServiceException("查询商品属性组属性组ID不可为空");
}
LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsAttributeGroup::getGroupId,groupId);
queryWrapper.eq(AsAttributeGroup::getGroupId, groupId);
List<Long> longs = asAttributeGroupService.list(queryWrapper).stream()
.map(AsAttributeGroup::getAttributeId)
.toList();
System.out.println("===="+longs.toString());
List<Long> longs1 = new ArrayList<>();
if(longs ==null || longs.isEmpty()){
return null;
}
return this.listByIds(
asAttributeGroupService.list(queryWrapper).stream()
.map(AsAttributeGroup::getAttributeId)
.toList()
longs
);
}
}

View File

@ -1,13 +1,18 @@
package com.muyu.product.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.ObjUtils;
import com.muyu.product.domain.*;
import com.muyu.product.domain.model.CategoryInfoSaveModel;
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
import com.muyu.product.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.product.mapper.CategoryInfoMapper;
import com.muyu.product.domain.CategoryInfo;
import com.muyu.product.service.CategoryInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -21,28 +26,147 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@Service
public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, CategoryInfo> implements CategoryInfoService {
@Autowired
private AsCategoryAttributeService asCategoryAttributeService;
@Autowired
private AsCategoryAttributeGroupService asCategoryAttributeGroupService;
@Autowired
private AsCategoryBrandService asCategoryBrandService;
@Autowired
private AttributeInfoService attributeInfoService;
@Autowired
private AsAttributeGroupService asAttributeGroupService;
@Autowired
private BrandInfoService brandInfoService;
/**
*
*
*
* @param categoryInfo
* @return
*/
@Override
public List<CategoryInfo> list(CategoryInfo categoryInfo){
public List<CategoryInfo> list(CategoryInfo categoryInfo) {
LambdaQueryWrapper<CategoryInfo> queryWrapper = new LambdaQueryWrapper<>();
if(ObjUtils.notNull(categoryInfo.getName())){
queryWrapper.like(CategoryInfo::getName,categoryInfo.getName());
if (ObjUtils.notNull(categoryInfo.getName())){
queryWrapper.like(CategoryInfo::getName, categoryInfo.getName());
}
if(ObjUtils.notNull(categoryInfo.getImage())){
queryWrapper.eq(CategoryInfo::getImage,categoryInfo.getImage());
if (ObjUtils.notNull(categoryInfo.getImage())){
queryWrapper.eq(CategoryInfo::getImage, categoryInfo.getImage());
}
if(ObjUtils.notNull(categoryInfo.getParentId())){
queryWrapper.eq(CategoryInfo::getParentId,categoryInfo.getParentId());
if (ObjUtils.notNull(categoryInfo.getParentId())){
queryWrapper.eq(CategoryInfo::getParentId, categoryInfo.getParentId());
}
if(ObjUtils.notNull(categoryInfo.getStart())){
queryWrapper.eq(CategoryInfo::getStart,categoryInfo.getStart());
if (ObjUtils.notNull(categoryInfo.getStart())){
queryWrapper.eq(CategoryInfo::getStart, categoryInfo.getStart());
}
if(ObjUtils.notNull(categoryInfo.getIntroduction())){
queryWrapper.eq(CategoryInfo::getIntroduction,categoryInfo.getIntroduction());
if (ObjUtils.notNull(categoryInfo.getIntroduction())){
queryWrapper.eq(CategoryInfo::getIntroduction, categoryInfo.getIntroduction());
}
return list(queryWrapper);
}
@Override
public Result parentCommonElement(Long categoryId) {
return Result.success(CategoryParentCommonElementResp.builder()
.attributeGroupList(getAttributeGroupList(categoryId))
.attributeInfoList(getAttributeInfoList(categoryId))
.brandInfoList(getBrandInfoList(categoryId))
.build());
}
/**
* id
* @param categoryId
* @return
*/
@Override
public List<AttributeGroup> getAttributeGroupList(Long categoryId) {
return null;
}
/**
* id
* @param categoryId
* @return
*/
@Override
public List<AttributeInfo> getAttributeInfoList(Long categoryId) {
ArrayList<AttributeInfo> attributeInfoList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryAttribute::getCategoryId,categoryId);
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper);
if (asCategoryAttributeList != null && asCategoryAttributeList.isEmpty()){
List<Long> attributeIdList = asCategoryAttributeList.stream()
.map(AsCategoryAttribute::getAttributeId)
.toList();
attributeInfoList.addAll(attributeInfoService.listByIds(attributeIdList));
}
CategoryInfo categoryInfo = this.getById(categoryId);
if (categoryInfo.getParentId() !=0){
if (attributeInfoList.isEmpty()){
}
}
return null;
}
/**
* id
* @param categoryId
* @return
*/
@Override
public List<BrandInfo> getBrandInfoList(Long categoryId) {
return null;
}
@Override
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel) {
CategoryInfo categoryInfo = CategoryInfo.saveModelBuild(categoryInfoSaveModel);
boolean save = this.save(categoryInfo);
Long categoryInfoId = categoryInfo.getId();
List<Long> attributeIdList = categoryInfoSaveModel.getAttributeIdList();
if (attributeIdList != null && !attributeIdList.isEmpty()){
asCategoryAttributeService.saveBatch(
attributeIdList.stream()
.map(attributeId -> AsCategoryAttribute.categoryBuild(categoryInfoId,attributeId))
.toList()
);
}
List<Long> attributeGroupIdList = categoryInfoSaveModel.getAttributeGroupIdList();
if (attributeGroupIdList != null && !attributeGroupIdList.isEmpty()){
asCategoryAttributeGroupService.saveBatch(
attributeGroupIdList.stream()
.map(attributeGrooupId -> AsCategoryAttributeGroup.categoryAttributeGroup(categoryInfoId,attributeGrooupId))
.toList()
);
}
List<Long> brandIdList = categoryInfoSaveModel.getBrandIdList();
if (brandIdList != null && !brandIdList.isEmpty()){
asCategoryBrandService.saveBatch(
brandIdList.stream()
.map(brandId -> AsCategoryBrand.categoryBrand(categoryInfoId,brandId))
.toList()
);
}
return save;
}
}