diff --git a/muyu-common/muyu-common-datascope/src/main/java/com/muyu/common/datascope/aspect/DataScopeAspect.java b/muyu-common/muyu-common-datascope/src/main/java/com/muyu/common/datascope/aspect/DataScopeAspect.java index 3d66b0d..65331d7 100644 --- a/muyu-common/muyu-common-datascope/src/main/java/com/muyu/common/datascope/aspect/DataScopeAspect.java +++ b/muyu-common/muyu-common-datascope/src/main/java/com/muyu/common/datascope/aspect/DataScopeAspect.java @@ -109,8 +109,7 @@ public class DataScopeAspect { if (StringUtils.isNotBlank(sqlString.toString())) { Object params = joinPoint.getArgs()[0]; - if (StringUtils.isNotNull(params) && params instanceof BaseEntity) { - BaseEntity baseEntity = (BaseEntity) params; + if (StringUtils.isNotNull(params) && params instanceof BaseEntity baseEntity) { baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsAttributeGroup.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsAttributeGroup.java index ab07e23..d3d6cff 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsAttributeGroup.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AsAttributeGroup.java @@ -45,4 +45,11 @@ public class AsAttributeGroup extends BaseEntity { private Long attributeId; + public static AsAttributeGroup buildGroup (Long attributeGroupId, + Long attributeId) { + return AsAttributeGroup.builder() + .groupId(attributeGroupId) + .attributeId(attributeId) + .build(); + } } 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..1423b22 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 @@ -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.base.CategoryBase; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -25,7 +26,7 @@ import com.muyu.common.core.web.domain.BaseEntity; @TableName("as_category_attribute") @EqualsAndHashCode(callSuper = true) @ApiModel(value = "AsCategoryAttribute", description = "品类属性中间") -public class AsCategoryAttribute extends BaseEntity { +public class AsCategoryAttribute extends BaseEntity implements CategoryBase { private static final long serialVersionUID = 1L; @@ -45,4 +46,15 @@ public class AsCategoryAttribute extends BaseEntity { private Long attributeId; + public static AsCategoryAttribute categoryBuild(Long categoryInfoId, Long attributeId) { + return AsCategoryAttribute.builder() + .categoryId(categoryInfoId) + .attributeId(attributeId) + .build(); + } + + @Override + public Long getBaseId () { + return this.attributeId; + } } 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..1dd2789 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 @@ -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.base.CategoryBase; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -25,7 +26,7 @@ import com.muyu.common.core.web.domain.BaseEntity; @TableName("as_category_attribute_group") @EqualsAndHashCode(callSuper = true) @ApiModel(value = "AsCategoryAttributeGroup", description = "品类属性组中间") -public class AsCategoryAttributeGroup extends BaseEntity { +public class AsCategoryAttributeGroup extends BaseEntity implements CategoryBase { private static final long serialVersionUID = 1L; @@ -45,4 +46,15 @@ public class AsCategoryAttributeGroup extends BaseEntity { private Long attributeGroupId; + public static AsCategoryAttributeGroup categoryBuild(Long categoryInfoId, Long attributeGroupId) { + return AsCategoryAttributeGroup.builder() + .attributeGroupId(attributeGroupId) + .categoryId(categoryInfoId) + .build(); + } + + @Override + public Long getBaseId () { + return this.attributeGroupId; + } } 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..e40bb11 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 @@ -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.base.CategoryBase; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -25,7 +26,7 @@ import com.muyu.common.core.web.domain.BaseEntity; @TableName("as_category_brand") @EqualsAndHashCode(callSuper = true) @ApiModel(value = "AsCategoryBrand", description = "品类品牌中间") -public class AsCategoryBrand extends BaseEntity { +public class AsCategoryBrand extends BaseEntity implements CategoryBase { private static final long serialVersionUID = 1L; @@ -44,4 +45,15 @@ public class AsCategoryBrand extends BaseEntity { @ApiModelProperty(name = "品牌id", value = "品牌id", required = true) private Long brandId; + public static AsCategoryBrand categoryBuild(Long categoryInfoId, Long brandId) { + return AsCategoryBrand.builder() + .brandId(brandId) + .categoryId(categoryInfoId) + .build(); + } + + @Override + public Long getBaseId () { + return this.brandId; + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AttributeInfo.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AttributeInfo.java index 745bfa6..2071ddc 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AttributeInfo.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AttributeInfo.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.muyu.product.domain.model.TemplateAttributeModel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -39,18 +40,32 @@ public class AttributeInfo extends BaseEntity { @ApiModelProperty(name = "属性编号", value = "属性编号") private Long id; + /** 属性编码 */ + @Excel(name = "属性编码") + @ApiModelProperty(name = "属性编码", value = "属性编码", required = true) + private String code; + /** 属性名 */ @Excel(name = "属性名") @ApiModelProperty(name = "属性名", value = "属性名", required = true) private String name; + public TemplateAttributeModel buildTemplateModel(){ + return TemplateAttributeModel.builder() + .id(this.getId()) + .code(this.getCode()) + .name(this.getName()) + .build(); + } + /** * 查询构造器 */ public static AttributeInfo queryBuild( AttributeInfoQueryReq attributeInfoQueryReq){ return AttributeInfo.builder() .name(attributeInfoQueryReq.getName()) + .code(attributeInfoQueryReq.getCode()) .build(); } @@ -60,6 +75,7 @@ public class AttributeInfo extends BaseEntity { public static AttributeInfo saveBuild(AttributeInfoSaveReq attributeInfoSaveReq){ return AttributeInfo.builder() .name(attributeInfoSaveReq.getName()) + .code(attributeInfoSaveReq.getCode()) .build(); } @@ -70,6 +86,7 @@ public class AttributeInfo extends BaseEntity { return AttributeInfo.builder() .id(id) .name(attributeInfoEditReq.getName()) + .code(attributeInfoEditReq.getCode()) .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 dc06d43..918b02c 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,10 @@ 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.Function; +import java.util.function.Supplier; + /** * 品类信息对象 category_info * @@ -72,12 +77,15 @@ 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(); } @@ -94,4 +102,15 @@ public class CategoryInfo extends TreeEntity { .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/RuleAttrInfo.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/RuleAttrInfo.java index b6c6edd..131611e 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/RuleAttrInfo.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/RuleAttrInfo.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.RuleAttrAddModel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -15,6 +16,9 @@ import com.muyu.product.domain.req.RuleAttrInfoSaveReq; import com.muyu.product.domain.req.RuleAttrInfoEditReq; import com.muyu.common.core.web.domain.BaseEntity; +import java.util.Date; +import java.util.function.Supplier; + /** * 规格详情对象 rule_attr_info * @@ -86,4 +90,13 @@ public class RuleAttrInfo extends BaseEntity { .build(); } + public static RuleAttrInfo addModelBuild (RuleAttrAddModel ruleAttrAddModel, Supplier ruleId, Supplier createBy) { + return RuleAttrInfo.builder() + .ruleId(ruleId.get()) + .name(ruleAttrAddModel.getName()) + .attrValue(String.join(",", ruleAttrAddModel.getValueList())) + .createBy(createBy.get()) + .createTime(new Date()) + .build(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/RuleInfo.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/RuleInfo.java index b4827e4..454cbad 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/RuleInfo.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/RuleInfo.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.RuleInfoAddModel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -15,6 +16,9 @@ import com.muyu.product.domain.req.RuleInfoSaveReq; import com.muyu.product.domain.req.RuleInfoEditReq; import com.muyu.common.core.web.domain.BaseEntity; +import java.util.Date; +import java.util.function.Supplier; + /** * 商品规格对象 rule_info * @@ -78,4 +82,18 @@ public class RuleInfo extends BaseEntity { .build(); } + /** + * + * @param ruleInfoAddModel 添加模型 + * @param createBy 创建者 + * @return 规格对象 + */ + public static RuleInfo addModelBuild (RuleInfoAddModel ruleInfoAddModel, Supplier createBy) { + return RuleInfo.builder() + .name(ruleInfoAddModel.getName()) + .status(ruleInfoAddModel.getStatus()) + .createBy(createBy.get()) + .createTime(new Date()) + .build(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/base/CategoryBase.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/base/CategoryBase.java new file mode 100644 index 0000000..ae3b33c --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/base/CategoryBase.java @@ -0,0 +1,11 @@ +package com.muyu.product.domain.base; + +/** + * @author DongZl + * @description: attribute基础方法 + * @Date 2024-3-1 下午 02:28 + */ +public interface CategoryBase { + + public Long getBaseId(); +} diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/AttributeGroupSaveModel.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/AttributeGroupSaveModel.java new file mode 100644 index 0000000..eecfb3f --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/AttributeGroupSaveModel.java @@ -0,0 +1,55 @@ +package com.muyu.product.domain.model; + +import com.muyu.common.core.web.domain.BaseEntity; +import com.muyu.product.domain.AttributeGroup; +import com.muyu.product.domain.req.AttributeGroupSaveReq; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; + + + +/** + * @author DongZl + * @description: 属性组添加模型 + * @Date 2024-2-28 下午 03:16 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class AttributeGroupSaveModel extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** 组名称 */ + private String name; + + /** 状态 */ + private String states; + + /** + * 属性ID集合 + */ + private List attributeIdList; + + public static AttributeGroupSaveModel saveReqBuild (AttributeGroupSaveReq req){ + return AttributeGroupSaveModel.builder() + .name(req.getName()) + .states(req.getStates()) + .attributeIdList(req.getAttributeIdList()) + .build(); + } + + public AttributeGroup buildAttributeGroup () { + return AttributeGroup.builder() + .name(this.getName()) + .states(this.getStates()) + .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..8a77303 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/CategoryInfoSaveModel.java @@ -0,0 +1,78 @@ +package com.muyu.product.domain.model; + +import com.muyu.common.core.web.domain.TreeEntity; +import com.muyu.product.domain.CategoryInfo; +import com.muyu.product.domain.req.CategoryInfoSaveReq; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +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; + +/** + * 品类信息对象 category_info + * + * @author DongZeLiang + * @date 2024-02-27 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class CategoryInfoSaveModel extends TreeEntity { + + private static final long serialVersionUID = 1L; + + + /** 品类名称 */ + 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/model/RuleAttrAddModel.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/RuleAttrAddModel.java new file mode 100644 index 0000000..e293352 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/RuleAttrAddModel.java @@ -0,0 +1,44 @@ +package com.muyu.product.domain.model; + +import com.muyu.common.core.web.domain.BaseEntity; +import com.muyu.product.domain.RuleAttrInfo; +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.Arrays; +import java.util.List; + + +/** + * @author DongZl + * @description: 规格属性,添加模型 + * @Date 2024-3-4 下午 02:28 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class RuleAttrAddModel extends BaseEntity { + + /** + * 规格属性名称 + */ + private String name; + + /** + * 规格属性值集合 + */ + private List valueList; + + public static RuleAttrAddModel infoBuild (RuleAttrInfo ruleAttrInfo) { + return RuleAttrAddModel.builder() + .name(ruleAttrInfo.getName()) + .valueList(Arrays.stream(ruleAttrInfo.getAttrValue().split(",")).toList()) + .build(); + } +} diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/RuleInfoAddModel.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/RuleInfoAddModel.java new file mode 100644 index 0000000..d2742b3 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/RuleInfoAddModel.java @@ -0,0 +1,44 @@ +package com.muyu.product.domain.model; + +import com.muyu.common.core.web.domain.BaseEntity; +import com.muyu.product.domain.req.RuleInfoSaveReq; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +/** + * @author DongZl + * @description: 规格保存模型 + * @Date 2024-3-4 下午 02:33 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class RuleInfoAddModel extends BaseEntity { + + /** 规格名称 */ + private String name; + + /** 规格状态 */ + private String status; + + /** + * 规格属性集合 + */ + private List ruleAttrList; + + public static RuleInfoAddModel saveReqBuild(RuleInfoSaveReq req){ + return RuleInfoAddModel.builder() + .name(req.getName()) + .status(req.getStatus()) + .ruleAttrList(req.getRuleAttrList()) + .build(); + } +} diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/TemplateAttributeGroupModel.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/TemplateAttributeGroupModel.java new file mode 100644 index 0000000..3258cc8 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/TemplateAttributeGroupModel.java @@ -0,0 +1,60 @@ +package com.muyu.product.domain.model; + +import com.muyu.common.core.utils.StringUtils; +import com.muyu.common.core.web.domain.BaseEntity; +import com.muyu.product.domain.AttributeGroup; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * @author DongZl + * @description: 共有属性组 + * @Date 2024-3-6 下午 02:29 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class TemplateAttributeGroupModel extends BaseEntity { + + /** + * 组名称 + */ + private String groupName; + + /** + * 属性组下属性集合 + */ + private List attributeList; + + /** + * 是否有效 + * @return + */ + public boolean isEffective(){ + return StringUtils.isNotEmpty(groupName) && attributeList != null && !attributeList.isEmpty(); + } + + /** + * + * @param attributeGroup + * @param attributeList + * @return + */ + public static TemplateAttributeGroupModel attributeGroupBuild(AttributeGroup attributeGroup, + Function> attributeList){ + return TemplateAttributeGroupModel.builder() + .groupName(attributeGroup.getName()) + .attributeList(attributeList.apply(attributeGroup.getId())) + .build(); + + } +} diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/TemplateAttributeModel.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/TemplateAttributeModel.java new file mode 100644 index 0000000..8cbeb02 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/TemplateAttributeModel.java @@ -0,0 +1,36 @@ +package com.muyu.product.domain.model; + +import com.muyu.common.core.web.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +/** + * @author DongZl + * @description: 共有属性 + * @Date 2024-3-6 下午 02:30 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class TemplateAttributeModel extends BaseEntity { + + /** + * 主键 + */ + private Long id; + + /** + * 属性名称 + */ + private String name; + + /** + * 编码 + */ + private String code; +} diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeGroupSaveReq.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeGroupSaveReq.java index 3fd9a5a..609dbab 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeGroupSaveReq.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeGroupSaveReq.java @@ -1,6 +1,8 @@ package com.muyu.product.domain.req; import java.util.Date; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -26,19 +28,21 @@ public class AttributeGroupSaveReq extends BaseEntity { private static final long serialVersionUID = 1L; /** 属性组编号 */ - @ApiModelProperty(name = "属性组编号", value = "属性组编号") private Long id; /** 组名称 */ - @ApiModelProperty(name = "组名称", value = "组名称", required = true) private String name; /** 状态 */ - @ApiModelProperty(name = "状态", value = "状态", required = true) private String states; + /** + * 属性ID集合 + */ + @ApiModelProperty(name = "属性ID集合", value = "属性ID集合", required = true) + private List attributeIdList; } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoEditReq.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoEditReq.java index b5af71e..20d95cd 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoEditReq.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoEditReq.java @@ -33,5 +33,8 @@ public class AttributeInfoEditReq extends BaseEntity { @ApiModelProperty(name = "分组", value = "分组") private Long groupId; + @ApiModelProperty(name = "属性编码", value = "属性编码") + private String code; + } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoQueryReq.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoQueryReq.java index 83604b6..aba8144 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoQueryReq.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoQueryReq.java @@ -29,5 +29,8 @@ public class AttributeInfoQueryReq extends BaseEntity { @ApiModelProperty(name = "属性名", value = "属性名") private String name; + @ApiModelProperty(name = "属性编码", value = "属性编码") + private String code; + } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoSaveReq.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoSaveReq.java index 0b50da1..893ddba 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoSaveReq.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/AttributeInfoSaveReq.java @@ -35,4 +35,7 @@ public class AttributeInfoSaveReq extends BaseEntity { @ApiModelProperty(name = "属性名", value = "属性名", required = true) private String name; + @ApiModelProperty(name = "属性编码", value = "属性编码") + private String code; + } 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 62f78e9..f65452b 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 * @@ -48,4 +50,18 @@ public class CategoryInfoSaveReq extends TreeEntity { @ApiModelProperty(name = "介绍", value = "介绍") private String introduction; + /** + * 商品属性组关联ID + */ + private List attributeGroupIdList; + /** + * 商品属性关联ID + */ + private List attributeIdList; + + /** + * 商品品牌组关联ID + */ + private List brandIdList; + } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/RuleInfoSaveReq.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/RuleInfoSaveReq.java index c68e0c8..c6ef9ff 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/RuleInfoSaveReq.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/RuleInfoSaveReq.java @@ -1,5 +1,6 @@ package com.muyu.product.domain.req; +import com.muyu.product.domain.model.RuleAttrAddModel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -8,6 +9,8 @@ import lombok.experimental.SuperBuilder; import io.swagger.annotations.*; import com.muyu.common.core.web.domain.BaseEntity; +import java.util.List; + /** * 商品规格对象 rule_info * @@ -23,19 +26,16 @@ public class RuleInfoSaveReq extends BaseEntity { private static final long serialVersionUID = 1L; - /** 主键 */ - - @ApiModelProperty(name = "主键", value = "主键") - private Long id; - /** 规格名称 */ - @ApiModelProperty(name = "规格名称", value = "规格名称") private String name; /** 规格状态 */ - @ApiModelProperty(name = "规格状态", value = "规格状态") private String status; + /** + * 规格属性集合 + */ + private List ruleAttrList; } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/AttributeGroupPageResp.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/AttributeGroupPageResp.java new file mode 100644 index 0000000..7936caf --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/AttributeGroupPageResp.java @@ -0,0 +1,59 @@ +package com.muyu.product.domain.resp; + +import com.muyu.common.core.web.domain.BaseEntity; +import com.muyu.product.domain.AttributeGroup; +import com.muyu.product.domain.AttributeInfo; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; +import java.util.function.Function; + +/** + * @author DongZl + * @description: 属性组列表对象 + * @Date 2024-2-28 下午 04:15 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class AttributeGroupPageResp extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** 属性组编号 */ + private Long id; + + /** 组名称 */ + private String name; + + /** 状态 */ + private String states; + + /** + * 属性对象集合 + */ + private List attributeInfoList; + + public static AttributeGroupPageResp groupBuild (AttributeGroup attributeGroup, List attributeInfos) { + return AttributeGroupPageResp.builder() + .id(attributeGroup.getId()) + .name(attributeGroup.getName()) + .states(attributeGroup.getStates()) + .attributeInfoList(attributeInfos) + .build(); + } + public static AttributeGroupPageResp groupFunBuild (AttributeGroup attributeGroup, Function > function) { + return AttributeGroupPageResp.builder() + .id(attributeGroup.getId()) + .name(attributeGroup.getName()) + .states(attributeGroup.getStates()) + .attributeInfoList(function.apply(attributeGroup.getId())) + .build(); + } +} diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryCommonElementResp.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryCommonElementResp.java new file mode 100644 index 0000000..b69efda --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryCommonElementResp.java @@ -0,0 +1,39 @@ +package com.muyu.product.domain.resp; + +import com.muyu.common.core.web.domain.BaseEntity; +import com.muyu.product.domain.model.TemplateAttributeGroupModel; +import com.muyu.product.domain.model.TemplateAttributeModel; +import lombok.*; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +/** + * @author DongZl + * @description: 商品类别公共元素 + * @Date 2024-3-6 下午 02:25 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class CategoryCommonElementResp extends BaseEntity { + + /** + * 共有属性组 + */ + private List templateAttributeGroupList; + + /** + * 共有属性 + */ + private List templateAttributeList; + + /** + * 自有属性(所有未包含属性) + */ + private List attributeList; + + +} 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..ba5576a --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryParentCommonElementResp.java @@ -0,0 +1,39 @@ +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; + +/** + * @author DongZl + * @description: 类别父通用元素 + * @Date 2024-3-1 上午 11:02 + */ +@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-common/src/main/java/com/muyu/product/domain/resp/RuleInfoResp.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/RuleInfoResp.java new file mode 100644 index 0000000..8596383 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/RuleInfoResp.java @@ -0,0 +1,48 @@ +package com.muyu.product.domain.resp; + +import com.muyu.common.core.web.domain.BaseEntity; +import com.muyu.product.domain.RuleInfo; +import com.muyu.product.domain.model.RuleAttrAddModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; +import java.util.function.Function; + +/** + * @author DongZl + * @description: 规格返回结果集 + * @Date 2024-3-4 下午 04:08 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class RuleInfoResp extends BaseEntity { + + private Long id; + + /** 规格名称 */ + private String name; + + /** 规格状态 */ + private String status; + + /** + * 规格属性集合 + */ + private List ruleAttrList; + + public static RuleInfoResp infoBuild (RuleInfo ruleInfo, Function> ruleAttrList) { + return RuleInfoResp.builder() + .id(ruleInfo.getId()) + .name(ruleInfo.getName()) + .status(ruleInfo.getStatus()) + .ruleAttrList(ruleAttrList.apply(ruleInfo.getId())) + .build(); + } +} 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 c662351..bd489a0 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 @@ -3,6 +3,8 @@ package com.muyu.product.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.muyu.product.domain.model.AttributeGroupSaveModel; +import com.muyu.product.domain.resp.AttributeGroupPageResp; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -45,10 +47,11 @@ public class AttributeGroupController extends BaseController { @ApiOperation("获取属性组列表") @RequiresPermissions("product:attributeGroup:list") @GetMapping("/list") - public Result> list(AttributeGroupQueryReq attributeGroupQueryReq) { + public Result> list(AttributeGroupQueryReq attributeGroupQueryReq) { startPage(); - List list = attributeGroupService.list(AttributeGroup.queryBuild(attributeGroupQueryReq)); - return getDataTable(list); + TableDataInfo tableDataInfo = + attributeGroupService.page(AttributeGroup.queryBuild(attributeGroupQueryReq)); + return Result.success(tableDataInfo); } /** @@ -83,7 +86,9 @@ public class AttributeGroupController extends BaseController { @PostMapping @ApiOperation("新增属性组") public Result add(@RequestBody AttributeGroupSaveReq attributeGroupSaveReq) { - return toAjax(attributeGroupService.save(AttributeGroup.saveBuild(attributeGroupSaveReq))); + return toAjax( + attributeGroupService.save(AttributeGroupSaveModel.saveReqBuild(attributeGroupSaveReq)) + ); } /** @@ -102,7 +107,7 @@ public class AttributeGroupController extends BaseController { */ @RequiresPermissions("product:attributeGroup:remove") @Log(title = "属性组", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") + @DeleteMapping("/{ids}") @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) { diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeInfoController.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeInfoController.java index 6f59dcb..4b09002 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeInfoController.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeInfoController.java @@ -36,6 +36,8 @@ import com.muyu.common.core.web.page.TableDataInfo; @RestController @RequestMapping("/attribute") public class AttributeInfoController extends BaseController { + + @Autowired private AttributeInfoService attributeInfoService; @@ -83,7 +85,8 @@ public class AttributeInfoController extends BaseController { @PostMapping @ApiOperation("新增商品属性") public Result add(@RequestBody AttributeInfoSaveReq attributeInfoSaveReq) { - return toAjax(attributeInfoService.save(AttributeInfo.saveBuild(attributeInfoSaveReq))); + AttributeInfo attributeInfo = AttributeInfo.saveBuild(attributeInfoSaveReq); + return attributeInfoService.save(attributeInfo) ? success(attributeInfo.getId()) : error(); } /** diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/BrandInfoController.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/BrandInfoController.java index 80dac39..29d4305 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/BrandInfoController.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/BrandInfoController.java @@ -3,6 +3,7 @@ package com.muyu.product.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.muyu.common.core.text.Convert; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -45,10 +46,13 @@ public class BrandInfoController extends BaseController { @ApiOperation("获取品牌信息列表") @RequiresPermissions("product:brand:list") @GetMapping("/list") - public Result> list(BrandInfoQueryReq brandInfoQueryReq) { - startPage(); + public Result list(BrandInfoQueryReq brandInfoQueryReq) { + boolean isPage = brandInfoQueryReq.getParams().get("isPage") == null || Convert.toBool(brandInfoQueryReq.getParams().get("isPage"), true); + if (isPage){ + startPage(); + } List list = brandInfoService.list(BrandInfo.queryBuild(brandInfoQueryReq)); - return getDataTable(list); + return isPage ? getDataTable(list) : Result.success(list); } /** 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..55dbaef 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 @@ -1,8 +1,16 @@ package com.muyu.product.controller; import java.util.List; +import java.util.function.Supplier; import javax.servlet.http.HttpServletResponse; +import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.product.domain.AttributeGroup; +import com.muyu.product.domain.AttributeInfo; +import com.muyu.product.domain.BrandInfo; +import com.muyu.product.domain.model.CategoryInfoSaveModel; +import com.muyu.product.domain.resp.CategoryCommonElementResp; +import com.muyu.product.domain.resp.CategoryParentCommonElementResp; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -73,6 +81,17 @@ public class CategoryInfoController extends BaseController { return Result.success(categoryInfoService.getById(id)); } + /** + * 获取品类信息详细信息 + */ + @ApiOperation("获取品类信息共有属性信息") + @RequiresPermissions("product:category:query") + @GetMapping(value = "/getTemplateAttribute/{cateGoryId}") + @ApiImplicitParam(name = "cateGoryId", value = "cateGoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class) + public Result getTemplateAttributeByCateGoryId(@PathVariable("cateGoryId") Long cateGoryId) { + return Result.success(categoryInfoService.getTemplateAttributeByCateGoryId(cateGoryId)); + } + /** * 新增品类信息 */ @@ -81,7 +100,9 @@ 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 +127,18 @@ public class CategoryInfoController extends BaseController { public Result remove(@PathVariable List ids) { return toAjax(categoryInfoService.removeBatchByIds(ids)); } + + /** + * 通过品类ID获取父级以上的属性、属性组、品牌集合 + * @param categoryId 品类ID + * @return 父级以上的属性、属性组、品牌集合 + */ + @GetMapping("/parentCommonElement/{categoryId}") + @ApiOperation("通过品类ID获取父级以上的属性集合") + @ApiImplicitParam(name = "categoryId", value = "categoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class, example = "1") + public Result parentCommonElement( + @PathVariable(value = "categoryId") Long categoryId + ) { + return Result.success(categoryInfoService.parentCommonElement(categoryId)); + } } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/RuleInfoController.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/RuleInfoController.java index c9e9f1c..b6a9c73 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/RuleInfoController.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/RuleInfoController.java @@ -3,6 +3,9 @@ package com.muyu.product.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.muyu.common.core.text.Convert; +import com.muyu.product.domain.model.RuleInfoAddModel; +import com.muyu.product.domain.resp.RuleInfoResp; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -45,10 +48,13 @@ public class RuleInfoController extends BaseController { @ApiOperation("获取商品规格列表") @RequiresPermissions("product:rule:list") @GetMapping("/list") - public Result> list(RuleInfoQueryReq ruleInfoQueryReq) { - startPage(); - List list = ruleInfoService.list(RuleInfo.queryBuild(ruleInfoQueryReq)); - return getDataTable(list); + public Result list(RuleInfoQueryReq ruleInfoQueryReq) { + boolean isPage = ruleInfoQueryReq.getParams().get("isPage") == null || Convert.toBool(ruleInfoQueryReq.getParams().get("isPage"), true); + if (isPage){ + startPage(); + } + TableDataInfo tableDataInfo = ruleInfoService.queryList(ruleInfoQueryReq); + return isPage ? Result.success(tableDataInfo) : Result.success(tableDataInfo.getRows()); } /** @@ -83,7 +89,7 @@ public class RuleInfoController extends BaseController { @PostMapping @ApiOperation("新增商品规格") public Result add(@RequestBody RuleInfoSaveReq ruleInfoSaveReq) { - return toAjax(ruleInfoService.save(RuleInfo.saveBuild(ruleInfoSaveReq))); + return toAjax(ruleInfoService.save(RuleInfoAddModel.saveReqBuild(ruleInfoSaveReq))); } /** diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/AttributeGroupService.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/AttributeGroupService.java index bd30e8f..9527f88 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/AttributeGroupService.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/AttributeGroupService.java @@ -1,8 +1,13 @@ package com.muyu.product.service; import java.util.List; + +import com.muyu.common.core.web.page.TableDataInfo; import com.muyu.product.domain.AttributeGroup; import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.product.domain.AttributeInfo; +import com.muyu.product.domain.model.AttributeGroupSaveModel; +import com.muyu.product.domain.resp.AttributeGroupPageResp; /** * 属性组Service接口 @@ -11,6 +16,14 @@ import com.baomidou.mybatisplus.extension.service.IService; * @date 2024-02-27 */ public interface AttributeGroupService extends IService { + + /** + * 分页查询 + * @param attributeGroup 分组对象 + * @return 返回结果 + */ + public TableDataInfo page(AttributeGroup attributeGroup); + /** * 查询属性组列表 * @@ -19,4 +32,11 @@ public interface AttributeGroupService extends IService { */ public List list(AttributeGroup attributeGroup); + /** + * 保存 + * @param attributeGroupSaveModel 属性组保存模型 + * @return 是否成功 + */ + public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel); + } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/AttributeInfoService.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/AttributeInfoService.java index ae1811a..14d9431 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/AttributeInfoService.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/AttributeInfoService.java @@ -19,4 +19,10 @@ public interface AttributeInfoService extends IService { */ public List list(AttributeInfo attributeInfo); + /** + * 通过groupId查询属性集合 + * @param groupId 属性组Id + * @return 属性集合 + */ + public List attributeListByGroupId(Long groupId); } 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..f2661ae 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,15 @@ package com.muyu.product.service; import java.util.List; + +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; +import com.muyu.product.domain.resp.CategoryCommonElementResp; +import com.muyu.product.domain.resp.CategoryParentCommonElementResp; /** * 品类信息Service接口 @@ -19,4 +26,45 @@ public interface CategoryInfoService extends IService { */ public List list(CategoryInfo categoryInfo); + /** + * 保存 + * @param categoryInfoSaveModel 保存品类模型 + * @return 是否成功 + */ + public boolean save(CategoryInfoSaveModel categoryInfoSaveModel); + + /** + * 通过品类ID获取父级以上的属性组集合 + * @param categoryId 品类ID + * @return 父级以上的属性组集合 + */ + List getAttributeGroup (Long categoryId); + + /** + * 通过品类ID获取父级以上的品牌集合 + * @param categoryId 品类ID + * @return 父级以上的品牌集合 + */ + List getBrand (Long categoryId); + + /** + * 通过品类ID获取父级以上的属性集合 + * @param categoryId 品类ID + * @return 父级以上的属性集合 + */ + List getAttribute (Long categoryId); + + /** + * 通过品类ID获取父级以上的属性、属性组、品牌集合 + * @param categoryId 品类ID + * @return 父级以上的属性、属性组、品牌集合 + */ + CategoryParentCommonElementResp parentCommonElement (Long categoryId); + + /** + * 通过品类ID获取品类共有属性 + * @param cateGoryId 品类ID + * @return 品类共有属性 + */ + CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId); } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/RuleInfoService.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/RuleInfoService.java index 4ad218e..54c5b08 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/RuleInfoService.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/RuleInfoService.java @@ -1,8 +1,13 @@ package com.muyu.product.service; import java.util.List; + +import com.muyu.common.core.web.page.TableDataInfo; import com.muyu.product.domain.RuleInfo; import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.product.domain.model.RuleInfoAddModel; +import com.muyu.product.domain.req.RuleInfoQueryReq; +import com.muyu.product.domain.resp.RuleInfoResp; /** * 商品规格Service接口 @@ -19,4 +24,12 @@ public interface RuleInfoService extends IService { */ public List list(RuleInfo ruleInfo); + /** + * 添加规格信息 + * @param ruleInfoAddModel 规格添加模型 + * @return 时候成功 + */ + public boolean save(RuleInfoAddModel ruleInfoAddModel); + + TableDataInfo queryList (RuleInfoQueryReq ruleInfoQueryReq); } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AsAttributeGroupServiceImpl.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AsAttributeGroupServiceImpl.java index 62e469e..7e2e186 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AsAttributeGroupServiceImpl.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AsAttributeGroupServiceImpl.java @@ -40,10 +40,6 @@ public class AsAttributeGroupServiceImpl extends ServiceImpl implements AttributeGroupService { +public class AttributeGroupServiceImpl extends ServiceImpl implements AttributeGroupService { + + @Autowired + private AsAttributeGroupService attributeGroupService; + + @Autowired + private AttributeInfoService attributeInfoService; + + /** + * 分页查询 + * + * @param attributeGroupQuery 分组对象 + * + * @return 返回结果 + */ + @Override + public TableDataInfo page (AttributeGroup attributeGroupQuery) { + List list = this.list(attributeGroupQuery); + List pageRespList = list.stream() + .map(attributeGroup -> + AttributeGroupPageResp.groupFunBuild( + attributeGroup, groupId -> attributeInfoService.attributeListByGroupId(groupId) + ) + ) + .toList(); + return TableDataInfo.builder() + .total(new PageInfo(list).getTotal()) + .rows(pageRespList) + .build(); + } /** * 查询属性组列表 * * @param attributeGroup 属性组 + * * @return 属性组 */ @Override - public List list(AttributeGroup attributeGroup) { + public List list (AttributeGroup attributeGroup) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - - if (ObjUtils.notNull(attributeGroup.getName())){ + if (ObjUtils.notNull(attributeGroup.getName())) { queryWrapper.like(AttributeGroup::getName, attributeGroup.getName()); } - if (ObjUtils.notNull(attributeGroup.getStates())){ + if (ObjUtils.notNull(attributeGroup.getStates())) { queryWrapper.eq(AttributeGroup::getStates, attributeGroup.getStates()); } return list(queryWrapper); } + + /** + * 保存 + * + * @param attributeGroupSaveModel 属性组保存模型 + * + * @return 是否成功 + */ + @Override + @Transactional + public Boolean save (AttributeGroupSaveModel attributeGroupSaveModel) { + AttributeGroup attributeGroup = attributeGroupSaveModel.buildAttributeGroup(); + boolean save = this.save(attributeGroup); + // 处理属性ID + Long attributeGroupId = attributeGroup.getId(); + List attributeIdList = attributeGroupSaveModel.getAttributeIdList(); + + attributeGroupService.saveBatch( + attributeIdList.stream() + .map(attributeId -> AsAttributeGroup.buildGroup(attributeGroupId, attributeId)) + .toList() + ); + return save; + } } 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 42364b1..0da9ac8 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 @@ -2,8 +2,12 @@ package com.muyu.product.service.impl; import java.util.List; +import com.muyu.common.core.exception.ServiceException; import com.muyu.common.core.utils.ObjUtils; +import com.muyu.product.domain.AsAttributeGroup; +import com.muyu.product.service.AsAttributeGroupService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.muyu.product.mapper.AttributeInfoMapper; import com.muyu.product.domain.AttributeInfo; @@ -21,6 +25,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @Service public class AttributeInfoServiceImpl extends ServiceImpl implements AttributeInfoService { + @Autowired + private AsAttributeGroupService asAttributeGroupService; + /** * 查询商品属性列表 * @@ -36,6 +43,35 @@ public class AttributeInfoServiceImpl extends ServiceImpl attributeListByGroupId (Long groupId) { + if (groupId == null){ + throw new ServiceException("查询商品属性组,属性组ID不可为空"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(AsAttributeGroup::getGroupId, groupId); + List list = asAttributeGroupService.list(queryWrapper).stream() + .map(AsAttributeGroup::getAttributeId) + .toList(); + if (list == null || list.isEmpty()){ + return null; + } + return this.listByIds( + list + ); + } } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/BrandInfoServiceImpl.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/BrandInfoServiceImpl.java index 5159f78..3c2f6c9 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/BrandInfoServiceImpl.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/BrandInfoServiceImpl.java @@ -35,7 +35,7 @@ public class BrandInfoServiceImpl extends ServiceImpl implements CategoryInfoService { +public class CategoryInfoServiceImpl extends ServiceImpl implements CategoryInfoService { + + + @Autowired + private AsCategoryAttributeService asCategoryAttributeService; + + @Autowired + private AsCategoryAttributeGroupService asCategoryAttributeGroupService; + + @Autowired + private AsCategoryBrandService asCategoryBrandService; + + @Autowired + private AsAttributeGroupService asAttributeGroupService; + + @Autowired + private AttributeInfoService attributeInfoService; + + @Autowired + private BrandInfoService brandInfoService; + + @Autowired + private AttributeGroupService attributeGroupService; /** * 查询品类信息列表 * * @param categoryInfo 品类信息 + * * @return 品类信息 */ @Override - public List list(CategoryInfo categoryInfo) { + public List list (CategoryInfo categoryInfo) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (ObjUtils.notNull(categoryInfo.getName())){ + if (ObjUtils.notNull(categoryInfo.getName())) { queryWrapper.like(CategoryInfo::getName, categoryInfo.getName()); } - if (ObjUtils.notNull(categoryInfo.getImage())){ + if (ObjUtils.notNull(categoryInfo.getImage())) { queryWrapper.eq(CategoryInfo::getImage, categoryInfo.getImage()); } - if (ObjUtils.notNull(categoryInfo.getParentId())){ + if (ObjUtils.notNull(categoryInfo.getParentId())) { queryWrapper.eq(CategoryInfo::getParentId, categoryInfo.getParentId()); } - if (ObjUtils.notNull(categoryInfo.getStart())){ + if (ObjUtils.notNull(categoryInfo.getStart())) { queryWrapper.eq(CategoryInfo::getStart, categoryInfo.getStart()); } - if (ObjUtils.notNull(categoryInfo.getIntroduction())){ + if (ObjUtils.notNull(categoryInfo.getIntroduction())) { queryWrapper.eq(CategoryInfo::getIntroduction, categoryInfo.getIntroduction()); } - - - - return list(queryWrapper); } + + @Override + @Transactional + 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(attributeGroupId -> AsCategoryAttributeGroup.categoryBuild(categoryInfoId, attributeGroupId)) + .toList() + ); + } + List brandIdList = categoryInfoSaveModel.getBrandIdList(); + if (brandIdList != null && !brandIdList.isEmpty()) { + asCategoryBrandService.saveBatch( + brandIdList.stream() + .map(brandId -> AsCategoryBrand.categoryBuild(categoryInfoId, brandId)) + .toList() + ); + } + return save; + } + + /** + * 通过品类ID获取父级以上的属性组集合 + * + * @param categoryId 品类ID + * + * @return 父级以上的属性组集合 + */ + @Override + public List getAttributeGroup (Long categoryId) { + List attributeGroupList = new ArrayList<>(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(AsCategoryAttributeGroup::getCategoryId, categoryId); + List asCategoryAttributeGroupList = asCategoryAttributeGroupService.list(queryWrapper); + if (asCategoryAttributeGroupList != null && !asCategoryAttributeGroupList.isEmpty()) { + List attributeGroupIdList = asCategoryAttributeGroupList.stream() + .map(AsCategoryAttributeGroup::getAttributeGroupId) + .toList(); + attributeGroupList.addAll(attributeGroupService.listByIds(attributeGroupIdList)); + } + CategoryInfo categoryInfo = this.getById(categoryId); + if (categoryInfo.getParentId() != 0) { + if (attributeGroupList.isEmpty()) { + attributeGroupList.addAll(getAttributeGroup(categoryInfo.getParentId())); + } else { + List attributeGroups = getAttributeGroup(categoryInfo.getParentId()); + attributeGroups.forEach(attributeGroup -> { + if (!attributeGroupList.contains(attributeGroup)) { + attributeGroupList.add(attributeGroup); + } + }); + } + } + return attributeGroupList; + } + + /** + * 通过品类ID获取父级以上的品牌集合 + * + * @param categoryId 品类ID + * + * @return 父级以上的品牌集合 + */ + @Override + public List getBrand (Long categoryId) { + List brandInfoList = new ArrayList<>(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(AsCategoryBrand::getCategoryId, categoryId); + List asCategoryBrandList = asCategoryBrandService.list(queryWrapper); + if (asCategoryBrandList != null && !asCategoryBrandList.isEmpty()) { + List brandIdList = asCategoryBrandList.stream() + .map(AsCategoryBrand::getBrandId) + .toList(); + brandInfoList.addAll(brandInfoService.listByIds(brandIdList)); + } + CategoryInfo categoryInfo = this.getById(categoryId); + if (categoryInfo.getParentId() != 0) { + if (brandInfoList.isEmpty()) { + brandInfoList.addAll(getBrand(categoryInfo.getParentId())); + } else { + List brandInfos = getBrand(categoryInfo.getParentId()); + brandInfos.forEach(brandInfo -> { + if (!brandInfoList.contains(brandInfo)) { + brandInfoList.add(brandInfo); + } + }); + } + + } + return brandInfoList; + } + + /** + * 通过品类ID获取父级以上的属性集合 + * + * @param categoryId 品类ID + * + * @return 父级以上的属性集合 + */ + @Override + public List getAttribute (Long categoryId) { + List 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()) { + attributeInfoList.addAll(getAttribute(categoryInfo.getParentId())); + } else { + List attributeInfos = getAttribute(categoryInfo.getParentId()); + attributeInfos.forEach(attributeInfoQuery -> { + if (!attributeInfoList.contains(attributeInfoQuery)) { + attributeInfoList.add(attributeInfoQuery); + } + }); + } + } + return attributeInfoList; + } + + + public List getCommon (Long categoryId, IService iService, IService bsiService) { + List list = new ArrayList(); + QueryWrapper asQueryWrapper = new QueryWrapper<>(); + asQueryWrapper.eq("category_id", categoryId); + List asList = iService.list(asQueryWrapper); + if (asList != null && !asList.isEmpty()) { + List baseIdList = asList.stream() + .map(as -> { + if (as instanceof CategoryBase categoryBase) { + return categoryBase.getBaseId(); + } + return null; + }) + .toList(); + list.addAll(bsiService.listByIds(baseIdList)); + } + CategoryInfo categoryInfo = this.getById(categoryId); + if (categoryInfo.getParentId() != 0) { + if (list.isEmpty()) { + list.addAll(getCommon(categoryInfo.getParentId(), iService, bsiService)); + } else { + List commonList = getCommon(categoryInfo.getParentId(), iService, bsiService); + commonList.forEach(common -> { + if (!list.contains(common)) { + list.add(common); + } + }); + } + } + return list; + } + + /** + * 通过品类ID获取父级以上的属性、属性组、品牌集合 + * + * @param categoryId 品类ID + * + * @return 父级以上的属性、属性组、品牌集合 + */ + @Override + public CategoryParentCommonElementResp parentCommonElement (Long categoryId) { + return CategoryParentCommonElementResp.builder() + .attributeInfoList(getCommon(categoryId, asCategoryAttributeService, attributeInfoService)) + .attributeGroupList(getCommon(categoryId, asCategoryAttributeGroupService, attributeGroupService)) + .brandInfoList(getCommon(categoryId, asCategoryBrandService, brandInfoService)) + .build(); + } + + private void getParentIdListByCateGoryId(List parentIdList, Long cateGoryId){ + if (cateGoryId.equals(0L)){ + return; + } + CategoryInfo categoryInfo = this.getById(cateGoryId); + parentIdList.add(categoryInfo.getId()); + getParentIdListByCateGoryId(parentIdList, categoryInfo.getParentId()); + } + + /** + * 通过品类ID获取品类共有属性 + * + * @param cateGoryId 品类ID + * + * @return 品类共有属性 + */ + @Override + public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) { + List cateGoryIdList = new ArrayList<>(); + getParentIdListByCateGoryId(cateGoryIdList, cateGoryId); + // 取出和品类相关联的属性组关系 - 中间表 + LambdaQueryWrapper asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{ + in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList); + }}; + List categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper); + List attributeGroupModelList = categoryAttributeGroupList.stream() + .map(asCategoryAttributeGroup -> TemplateAttributeGroupModel.attributeGroupBuild( + attributeGroupService.getById(asCategoryAttributeGroup.getAttributeGroupId()), + attributeGroupId -> { + LambdaQueryWrapper asAttributeGroupQueryWrapper = new LambdaQueryWrapper<>() {{ + eq(AsAttributeGroup::getGroupId, asCategoryAttributeGroup.getAttributeGroupId()); + }}; + List attributeIdList = asAttributeGroupService.list(asAttributeGroupQueryWrapper).stream() + .map(AsAttributeGroup::getAttributeId) + .toList(); + if (attributeIdList.isEmpty()){ + return new ArrayList<>(); + } + return attributeInfoService.listByIds(attributeIdList).stream() + .map(AttributeInfo::buildTemplateModel) + .toList(); + } + )) + .filter(TemplateAttributeGroupModel::isEffective) + .toList(); + // 查重集合 + Set attributeIdSet = new HashSet<>(); + // 获取组内所有的属性Id + if (!attributeGroupModelList.isEmpty()){ + attributeIdSet.addAll( + attributeGroupModelList.stream() + .flatMap((Function>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream()) + .map(TemplateAttributeModel::getId) + .toList() + ); + } + + List templateAttributeModelList = new ArrayList<>(); + LambdaQueryWrapper categoryAttributeQueryWrapper = new LambdaQueryWrapper<>(); + categoryAttributeQueryWrapper.in(AsCategoryAttribute::getCategoryId, cateGoryIdList); + List asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper); + if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()){ + List templateAttributeIdList = asCategoryAttributeList.stream() + .map(AsCategoryAttribute::getAttributeId) + .filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId)) + .toList(); + templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream() + .map(AttributeInfo::buildTemplateModel) + .toList(); + } + + List attributeModelList = new ArrayList<>(); + + if (!templateAttributeModelList.isEmpty()){ + attributeIdSet.addAll( + templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList() + ); + } + + LambdaQueryWrapper attributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>(); + attributeInfoLambdaQueryWrapper.notIn(!attributeIdSet.isEmpty(), AttributeInfo::getId, attributeIdSet); + attributeModelList = attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList(); + + return CategoryCommonElementResp.builder() + .templateAttributeGroupList(attributeGroupModelList) + .templateAttributeList(templateAttributeModelList) + .attributeList(attributeModelList) + .build(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/RuleInfoServiceImpl.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/RuleInfoServiceImpl.java index 3d180d5..3018b05 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/RuleInfoServiceImpl.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/RuleInfoServiceImpl.java @@ -1,9 +1,25 @@ package com.muyu.product.service.impl; +import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.muyu.common.core.text.Convert; import com.muyu.common.core.utils.ObjUtils; +import com.muyu.common.core.web.page.TableDataInfo; +import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.product.domain.RuleAttrInfo; +import com.muyu.product.domain.model.RuleAttrAddModel; +import com.muyu.product.domain.model.RuleInfoAddModel; +import com.muyu.product.domain.req.RuleInfoQueryReq; +import com.muyu.product.domain.resp.RuleInfoResp; +import com.muyu.product.service.RuleAttrInfoService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.muyu.product.mapper.RuleInfoMapper; import com.muyu.product.domain.RuleInfo; @@ -21,6 +37,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @Service public class RuleInfoServiceImpl extends ServiceImpl implements RuleInfoService { + @Autowired + private RuleAttrInfoService ruleAttrInfoService; + /** * 查询商品规格列表 * @@ -46,4 +65,41 @@ public class RuleInfoServiceImpl extends ServiceImpl return list(queryWrapper); } + + /** + * 添加规格信息 + * + * @param ruleInfoAddModel 规格添加模型 + * + * @return 时候成功 + */ + @Override + public boolean save (RuleInfoAddModel ruleInfoAddModel) { + RuleInfo ruleInfo = RuleInfo.addModelBuild(ruleInfoAddModel, SecurityUtils::getUsername); + boolean save = this.save(ruleInfo); + ruleAttrInfoService.saveBatch( + ruleInfoAddModel.getRuleAttrList().stream() + .map(ruleAttrAddModel -> RuleAttrInfo.addModelBuild(ruleAttrAddModel, ruleInfo::getId, SecurityUtils::getUsername)) + .toList() + ); + return save; + } + + @Override + public TableDataInfo queryList (RuleInfoQueryReq ruleInfoQueryReq) { + List list = this.list(RuleInfo.queryBuild(ruleInfoQueryReq)); + List ruleInfoRespList = list.stream() + .map(ruleInfo -> RuleInfoResp.infoBuild(ruleInfo, ruleId -> { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(RuleAttrInfo::getRuleId, ruleId); + return ruleAttrInfoService.list(queryWrapper).stream().map(RuleAttrAddModel::infoBuild).toList(); + })) + .toList(); + boolean isPage = ruleInfoQueryReq.getParams().get("isPage") == null || Convert.toBool(ruleInfoQueryReq.getParams().get("isPage"), true); + + return TableDataInfo.builder() + .rows(ruleInfoRespList) + .total(isPage ? new PageInfo<>(list).getTotal() : 0) + .build(); + } }