diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryAttribute.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryAttribute.java index eaf121d..6d5e730 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryAttribute.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryAttribute.java @@ -45,4 +45,10 @@ public class AsCategoryAttribute extends BaseEntity { private Long attributeId; + public static AsCategoryAttribute categoryBuild(Long categoryInfoId,Long attributeId){ + return AsCategoryAttribute.builder() + .categoryId(categoryInfoId) + .attributeId(attributeId) + .build(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryAttributeGroup.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryAttributeGroup.java index 7e27dce..9429705 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryAttributeGroup.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryAttributeGroup.java @@ -45,4 +45,10 @@ public class AsCategoryAttributeGroup extends BaseEntity { private Long attributeGroupId; + public static AsCategoryAttributeGroup categoryAttributeGroup(Long categoryId,Long attributeGroupId){ + return AsCategoryAttributeGroup.builder() + .categoryId(categoryId) + .attributeGroupId(attributeGroupId) + .build(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryBrand.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryBrand.java index bc52a80..a22df64 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryBrand.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsCategoryBrand.java @@ -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(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryInfo.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryInfo.java index c4450c6..27a9e9e 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryInfo.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryInfo.java @@ -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 * @@ -72,13 +76,27 @@ public class CategoryInfo extends TreeEntity { /** * 添加构造器 */ - public static CategoryInfo saveBuild(CategoryInfoSaveReq categoryInfoSaveReq){ + public static CategoryInfo saveBuild(CategoryInfoSaveReq categoryInfoSaveReq, Supplier 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(); } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/CategoryInfoSaveModel.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/CategoryInfoSaveModel.java new file mode 100644 index 0000000..355d2fa --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/CategoryInfoSaveModel.java @@ -0,0 +1,63 @@ +package com.muyu.product.domain.model; + +import com.muyu.common.core.web.domain.TreeEntity; +import com.muyu.product.domain.req.CategoryInfoSaveReq; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.Date; +import java.util.List; +import java.util.function.Supplier; + +/** + * @ClassName CategoryInfoSaveModel + * @Description 描述 + * @Author Xin.Yao + * @Date 2024/3/3 8:52 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class CategoryInfoSaveModel extends TreeEntity { + private String name; + private String image; + private String start; + private String introduction; + + /** + * 商品属性组关联ID + */ + private List attributeGroupIdList; + /** + * 商品属性关联ID + */ + private List attributeIdList; + + /** + * 商品品牌组关联ID + */ + private List brandIdList; + + /** + * 添加构造器 + */ + public static CategoryInfoSaveModel saveBuild(CategoryInfoSaveReq categoryInfoSaveReq, Supplier supplier){ + return CategoryInfoSaveModel.builder() + .name(categoryInfoSaveReq.getName()) + .image(categoryInfoSaveReq.getImage()) + .start(categoryInfoSaveReq.getStart()) + .introduction(categoryInfoSaveReq.getIntroduction()) + .parentId(categoryInfoSaveReq.getParentId()) + .attributeGroupIdList(categoryInfoSaveReq.getAttributeGroupIdList()) + .attributeIdList(categoryInfoSaveReq.getAttributeIdList()) + .brandIdList(categoryInfoSaveReq.getBrandIdList()) + .createBy(supplier.get()) + .createTime(new Date()) + .build(); + } +} diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryInfoSaveReq.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryInfoSaveReq.java index 4c60f1b..04c1191 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryInfoSaveReq.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryInfoSaveReq.java @@ -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 attributeGroupIdList; + private List attributeIdList; + private List brandIdList; } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryParentCommonElementResp.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryParentCommonElementResp.java new file mode 100644 index 0000000..4641669 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryParentCommonElementResp.java @@ -0,0 +1,37 @@ +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; + +/** + * @ClassName CategoryParentCommonElementResp + * @Description 描述 + * @Author Xin.Yao + * @Date 2024/3/3 8:15 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CategoryParentCommonElementResp { + + /** + * 属性集合 + */ + private List attributeInfoList; + /** + * 属性组集合 + */ + private List attributeGroupList; + /** + * 品牌集合 + */ + private List brandInfoList; +} diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeGroupController.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeGroupController.java index ec1266d..ebc4d9f 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeGroupController.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeGroupController.java @@ -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 remove(@PathVariable List ids) { + System.out.println(); return toAjax(attributeGroupService.removeBatchByIds(ids)); } } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/CategoryInfoController.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/CategoryInfoController.java index db83452..189cdbe 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/CategoryInfoController.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/CategoryInfoController.java @@ -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; @@ -81,7 +83,8 @@ public class CategoryInfoController extends BaseController { @PostMapping @ApiOperation("新增品类信息") public Result add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) { - return toAjax(categoryInfoService.save(CategoryInfo.saveBuild(categoryInfoSaveReq))); + return toAjax(categoryInfoService.save( + CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername))); } /** @@ -106,4 +109,15 @@ public class CategoryInfoController extends BaseController { public Result remove(@PathVariable List 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); + } + } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/CategoryInfoService.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/CategoryInfoService.java index cd306e0..02073d9 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/CategoryInfoService.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/CategoryInfoService.java @@ -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接口 @@ -19,4 +25,31 @@ public interface CategoryInfoService extends IService { */ public List list(CategoryInfo categoryInfo); + /** + *通过品类id查找包括父级属性集合,属性组集合以及品牌集合 + * @param categoryId + * @return 父级以上属性,属性组,品牌集合 + */ + Result parentCommonElement(Long categoryId); + + /** + * 通过品类id获取属性组集合 + * @param categoryId + * @return 属性组集合 + */ + List getAttributeGroupList(Long categoryId); + /** + * 通过品类id获取属性集合 + * @param categoryId + * @return 属性集合 + */ + List getAttributeInfoList(Long categoryId); + /** + * 通过品类id获取品牌集合 + * @param categoryId + * @return 品牌集合 + */ + List getBrandInfoList(Long categoryId); + + public boolean save(CategoryInfoSaveModel categoryInfoSaveModel); } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AttributeInfoServiceImpl.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AttributeInfoServiceImpl.java index 6795bea..3899b47 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AttributeInfoServiceImpl.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AttributeInfoServiceImpl.java @@ -68,12 +68,11 @@ public class AttributeInfoServiceImpl extends ServiceImpl longs = asAttributeGroupService.list(queryWrapper).stream() .map(AsAttributeGroup::getAttributeId) .toList(); - System.out.println("====="+longs.toString()); - List longs1 = new ArrayList<>(); + if(longs ==null || longs.isEmpty()){ + return null; + } return this.listByIds( - asAttributeGroupService.list(queryWrapper).stream() - .map(AsAttributeGroup::getAttributeId) - .toList() + longs ); } } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/CategoryInfoServiceImpl.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/CategoryInfoServiceImpl.java index ebaebe9..6148c22 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/CategoryInfoServiceImpl.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/CategoryInfoServiceImpl.java @@ -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,6 +26,25 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @Service public class CategoryInfoServiceImpl extends ServiceImpl 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; + + /** * 查询品类信息列表 * @@ -58,4 +82,91 @@ public class CategoryInfoServiceImpl extends ServiceImpl getAttributeGroupList(Long categoryId) { + return null; + } + + /** + * 通过品类id获取属性集合 + * @param categoryId + * @return 属性集合 + */ + @Override + public List getAttributeInfoList(Long categoryId) { + ArrayList attributeInfoList = new ArrayList<>(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(AsCategoryAttribute::getCategoryId,categoryId); + List asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper); + if (asCategoryAttributeList != null && asCategoryAttributeList.isEmpty()){ + List 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 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 attributeIdList = categoryInfoSaveModel.getAttributeIdList(); + if (attributeIdList != null && !attributeIdList.isEmpty()){ + asCategoryAttributeService.saveBatch( + attributeIdList.stream() + .map(attributeId -> AsCategoryAttribute.categoryBuild(categoryInfoId,attributeId)) + .toList() + ); + } + List attributeGroupIdList = categoryInfoSaveModel.getAttributeGroupIdList(); + if (attributeGroupIdList != null && !attributeGroupIdList.isEmpty()){ + asCategoryAttributeGroupService.saveBatch( + attributeGroupIdList.stream() + .map(attributeGrooupId -> AsCategoryAttributeGroup.categoryAttributeGroup(categoryInfoId,attributeGrooupId)) + .toList() + ); + } + List brandIdList = categoryInfoSaveModel.getBrandIdList(); + if (brandIdList != null && !brandIdList.isEmpty()){ + asCategoryBrandService.saveBatch( + brandIdList.stream() + .map(brandId -> AsCategoryBrand.categoryBrand(categoryInfoId,brandId)) + .toList() + ); + } + return save; + } }