diff --git a/muyu-auth/src/main/resources/bootstrap.yml b/muyu-auth/src/main/resources/bootstrap.yml index 1deffc4..8b5278e 100644 --- a/muyu-auth/src/main/resources/bootstrap.yml +++ b/muyu-auth/src/main/resources/bootstrap.yml @@ -18,6 +18,7 @@ spring: config: # 配置中心地址 server-addr: 101.34.248.9:8848 + namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/muyu-gateway/src/main/resources/bootstrap.yml b/muyu-gateway/src/main/resources/bootstrap.yml index aeb3037..9219669 100644 --- a/muyu-gateway/src/main/resources/bootstrap.yml +++ b/muyu-gateway/src/main/resources/bootstrap.yml @@ -18,6 +18,7 @@ spring: config: # 配置中心地址 server-addr: 101.34.248.9:8848 + namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/muyu-modules/muyu-file/src/main/resources/bootstrap.yml b/muyu-modules/muyu-file/src/main/resources/bootstrap.yml index eee7c97..9f5ba3f 100644 --- a/muyu-modules/muyu-file/src/main/resources/bootstrap.yml +++ b/muyu-modules/muyu-file/src/main/resources/bootstrap.yml @@ -18,6 +18,7 @@ spring: config: # 配置中心地址 server-addr: 101.34.248.9:8848 + namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/muyu-modules/muyu-gen/src/main/resources/bootstrap.yml b/muyu-modules/muyu-gen/src/main/resources/bootstrap.yml index 73bdfff..3b5beed 100644 --- a/muyu-modules/muyu-gen/src/main/resources/bootstrap.yml +++ b/muyu-modules/muyu-gen/src/main/resources/bootstrap.yml @@ -18,6 +18,7 @@ spring: config: # 配置中心地址 server-addr: 101.34.248.9:8848 + namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/muyu-modules/muyu-job/src/main/resources/bootstrap.yml b/muyu-modules/muyu-job/src/main/resources/bootstrap.yml index f94cd7e..779de83 100644 --- a/muyu-modules/muyu-job/src/main/resources/bootstrap.yml +++ b/muyu-modules/muyu-job/src/main/resources/bootstrap.yml @@ -18,6 +18,7 @@ spring: config: # 配置中心地址 server-addr: 101.34.248.9:8848 + namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74 # 配置文件格式 file-extension: yml # 共享配置 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 6cc0ebf..313079f 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; @@ -44,11 +45,16 @@ public class AsCategoryAttributeGroup extends BaseEntity { @ApiModelProperty(name = "属性组", value = "属性组", required = true) private Long attributeGroupId; - public static AsCategoryAttributeGroup categoryAttributeGroup(Long categoryId,Long attributeGroupId){ + public static AsCategoryAttributeGroup categoryBuild(Long categoryId,Long attributeGroupId){ return AsCategoryAttributeGroup.builder() .categoryId(categoryId) .attributeGroupId(attributeGroupId) .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 a22df64..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,10 +45,15 @@ public class AsCategoryBrand extends BaseEntity { @ApiModelProperty(name = "品牌id", value = "品牌id", required = true) private Long brandId; - public static AsCategoryBrand categoryBrand(Long categoryId,Long brandId){ + public static AsCategoryBrand categoryBuild(Long categoryInfoId, Long brandId) { return AsCategoryBrand.builder() - .categoryId(categoryId) .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 5175d8d..30e6f9c 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; @@ -49,6 +50,13 @@ public class AttributeInfo extends BaseEntity { @ApiModelProperty(name = "属性名", value = "属性名", required = true) private String name; + public TemplateAttributeModel buildTemplateModel(){ + return TemplateAttributeModel.builder() + .id(this.getId()) + .code(this.getCode()) + .name(this.getName()) + .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 b10bbb9..bae961b 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 @@ -101,4 +101,5 @@ public class RuleAttrInfo extends BaseEntity { .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..370ec51 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/base/CategoryBase.java @@ -0,0 +1,7 @@ +package com.muyu.product.domain.base; + +public interface CategoryBase { + + public Long getBaseId(); + +} 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 index c08435c..aca295e 100644 --- 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 @@ -35,4 +35,5 @@ public class RuleAttrAddModel extends BaseEntity { .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 index 4bde0c9..347f7d7 100644 --- 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 @@ -39,4 +39,6 @@ public class RuleInfoAddModel extends BaseEntity { .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..3154a51 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/TemplateAttributeGroupModel.java @@ -0,0 +1,47 @@ +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; + +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class TemplateAttributeGroupModel extends BaseEntity { + + /** + * 组名称 + */ + private String groupName; + + /** + * 属性组下属性集合 + */ + private List attributeList; + + /** + * 是否有效 + */ + public boolean isEffective(){ + return StringUtils.isNotEmpty(groupName) && attributeList != null && attributeList.isEmpty(); + } + + 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..0f97b24 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/TemplateAttributeModel.java @@ -0,0 +1,32 @@ +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; + +@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/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..91d7dbe --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryCommonElementResp.java @@ -0,0 +1,36 @@ +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.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +@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/RuleInfoResp.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/RuleInfoResp.java index b09e59b..91c9bb4 100644 --- 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 @@ -27,7 +27,7 @@ public class RuleInfoResp extends BaseEntity { private List ruleAttrList; - public static RuleInfoResp infoBuild(RuleInfo ruleInfo, Function> ruleAttrList){ + public static RuleInfoResp infoBuild(RuleInfo ruleInfo,Function> ruleAttrList){ return RuleInfoResp.builder() .id(ruleInfo.getId()) .name(ruleInfo.getName()) @@ -35,4 +35,5 @@ public class RuleInfoResp extends BaseEntity { .ruleAttrList(ruleAttrList.apply(ruleInfo.getId())) .build(); } + } 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 0ddbff2..6dfad2d 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 @@ -7,6 +7,8 @@ import com.muyu.common.security.utils.SecurityUtils; import com.muyu.product.domain.AttributeGroup; import com.muyu.product.domain.model.CategoryInfoSaveModel; import com.muyu.product.domain.req.AttributeGroupEditReq; +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; @@ -77,6 +79,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)); + } + /** * 新增品类信息 */ @@ -86,7 +99,8 @@ public class CategoryInfoController extends BaseController { @ApiOperation("新增品类信息") public Result add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) { return toAjax(categoryInfoService.save( - CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername))); + CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername) + )); } /** @@ -113,13 +127,16 @@ public class CategoryInfoController extends BaseController { } /** - * 通过品类id查找包括父级属性集合,属性组集合以及品牌集合 + * 通过品类ID获取父级以上的属性、属性组、品牌集合 + * @param categoryId 品类ID + * @return 父级以上的属性、属性组、品牌集合 */ @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); + @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 48dda4f..dee4e29 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 @@ -110,4 +110,5 @@ public class RuleInfoController extends BaseController { public Result remove(@PathVariable List ids) { return toAjax(ruleInfoService.removeBatchByIds(ids)); } + } 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 c45abec..88f33e3 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 @@ -9,6 +9,8 @@ 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接口 @@ -24,26 +26,56 @@ public interface CategoryInfoService extends IService { public List list(CategoryInfo categoryInfo); /** - * 通过品类id查找包括父级属性集合,属性组集合,品牌集合 + * 保存品类模型 */ - Result parentCommonElement(Long categoryId); - - /** - * 通过品类id获取属性组集合 - */ - List getAttributeGroupList(Long categoryId); - - /** - * 通过品类id获取属性集合 - */ - List getAttributeInfoList(Long categoryId); - - - /** - * 通过品类id获取品牌集合 - */ - List getBrandInfoList(Long categoryId); - public boolean save(CategoryInfoSaveModel categoryInfoSaveModel); + /** + * 通过品类id获取父级以上的属性集合 + */ + List getAttributeGroup(Long categoryId); + + /** + * 通过品类id获取父级以上的品牌集合 + */ + List getBrand(Long categoryId); + + List getAttribute(Long categoryId); + + CategoryParentCommonElementResp parentCommonElement(Long categoryId); + + CategoryCommonElementResp getTemplateAttributeByCateGoryId(Long cateGoryId); + + + +// /** +// * 通过品类id查找包括父级属性集合,属性组集合,品牌集合 +// */ +// Result parentCommonElement(Long categoryId); +// +// /** +// * 通过品类id获取属性组集合 +// */ +// List getAttributeGroupList(Long categoryId); +// +// /** +// * 通过品类id获取属性集合 +// */ +// List getAttributeInfoList(Long categoryId); +// +// +// /** +// * 通过品类id获取品牌集合 +// */ +// List getBrandInfoList(Long categoryId); +// +// public boolean save(CategoryInfoSaveModel categoryInfoSaveModel); +// +// /** +// * 通过品类id过去父级以上的属性、属性组、品牌集合 +// */ +// CategoryParentCommonElementResp parentCommonElement(Long categoryId); +// +// 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 a9e9708..4a57a09 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 @@ -8,6 +8,8 @@ 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; +import com.mysql.cj.xdevapi.Table; +import org.apache.tomcat.util.digester.Rule; /** * 商品规格Service接口 @@ -31,5 +33,4 @@ public interface RuleInfoService extends IService { TableDataInfo queryList(RuleInfoQueryReq ruleInfoQueryReq); - } 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 1ea9d99..9e3872e 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,12 +1,23 @@ package com.muyu.product.service.impl; +import java.sql.Array; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Stream; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.IService; import com.muyu.common.core.domain.Result; import com.muyu.common.core.utils.ObjUtils; import com.muyu.product.domain.*; +import com.muyu.product.domain.base.CategoryBase; import com.muyu.product.domain.model.CategoryInfoSaveModel; +import com.muyu.product.domain.model.TemplateAttributeGroupModel; +import com.muyu.product.domain.model.TemplateAttributeModel; +import com.muyu.product.domain.resp.CategoryCommonElementResp; import com.muyu.product.domain.resp.CategoryParentCommonElementResp; import com.muyu.product.service.*; import lombok.extern.slf4j.Slf4j; @@ -15,6 +26,7 @@ import org.springframework.stereotype.Service; import com.muyu.product.mapper.CategoryInfoMapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.transaction.annotation.Transactional; /** * 品类信息Service业务层处理 @@ -24,7 +36,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; */ @Slf4j @Service -public class CategoryInfoServiceImpl extends ServiceImpl implements CategoryInfoService { +public class CategoryInfoServiceImpl extends ServiceImpl implements CategoryInfoService { + @Autowired private AsCategoryAttributeService asCategoryAttributeService; @@ -35,118 +48,328 @@ public class CategoryInfoServiceImpl extends ServiceImpl 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 - public Result parentCommonElement(Long categoryId) { - return Result.success(CategoryParentCommonElementResp.builder() - .attributeGroupList(getAttributeGroupList(categoryId)) - .attributeInfoList(getAttributeInfoList(categoryId)) - .brandInfoList(getBrandInfoList(categoryId)) - .build()); + @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获取属性组集合 + * 通过品类ID获取父级以上的属性组集合 + * + * @param categoryId 品类ID + * + * @return 父级以上的属性组集合 */ @Override - public List getAttributeGroupList(Long categoryId){ - return null; + 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获取属性集合 + * 通过品类ID获取父级以上的品牌集合 + * + * @param categoryId 品类ID + * + * @return 父级以上的品牌集合 */ @Override - public List getAttributeInfoList(Long categoryId) { - ArrayList attributeInfoList = new ArrayList<>(); + 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); + queryWrapper.eq(AsCategoryAttribute::getCategoryId, categoryId); List asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper); - if (asCategoryAttributeList != null && asCategoryAttributeList.isEmpty()){ + 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()){ - + 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 null; + 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获取品牌集合 + * 通过品类ID获取父级以上的属性、属性组、品牌集合 + * + * @param categoryId 品类ID + * + * @return 父级以上的属性、属性组、品牌集合 */ @Override - public List getBrandInfoList(Long categoryId) { - return null; + 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 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)) + 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 attributeGroupIdList = categoryInfoSaveModel.getAttributeGroupIdList(); - if (attributeGroupIdList != null && !attributeGroupIdList.isEmpty()){ - asCategoryAttributeGroupService.saveBatch( - attributeGroupIdList.stream() - .map(attributeGrooupId -> AsCategoryAttributeGroup.categoryAttributeGroup(categoryInfoId,attributeGrooupId)) - .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() ); } - List brandIdList = categoryInfoSaveModel.getBrandIdList(); - if (brandIdList != null && !brandIdList.isEmpty()){ - asCategoryBrandService.saveBatch( - brandIdList.stream() - .map(brandId -> AsCategoryBrand.categoryBrand(categoryInfoId,brandId)) - .toList() - ); - } - return save; + + 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 95d5e4f..7dc220c 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 @@ -92,4 +92,5 @@ public class RuleInfoServiceImpl extends ServiceImpl .total(new PageInfo<>(list).getTotal()) .build(); } + } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/resources/bootstrap.yml b/muyu-modules/muyu-product/muyu-product-server/src/main/resources/bootstrap.yml index 1fb8448..7c76e35 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/resources/bootstrap.yml +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/resources/bootstrap.yml @@ -18,6 +18,7 @@ spring: config: # 配置中心地址 server-addr: 101.34.248.9 + namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/muyu-modules/muyu-system/src/main/resources/bootstrap.yml b/muyu-modules/muyu-system/src/main/resources/bootstrap.yml index abca4cf..e4c4b9d 100644 --- a/muyu-modules/muyu-system/src/main/resources/bootstrap.yml +++ b/muyu-modules/muyu-system/src/main/resources/bootstrap.yml @@ -18,6 +18,7 @@ spring: config: # 配置中心地址 server-addr: 101.34.248.9:8848 + namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/muyu-visual/muyu-monitor/src/main/resources/bootstrap.yml b/muyu-visual/muyu-monitor/src/main/resources/bootstrap.yml index a6e56d5..fefb3ae 100644 --- a/muyu-visual/muyu-monitor/src/main/resources/bootstrap.yml +++ b/muyu-visual/muyu-monitor/src/main/resources/bootstrap.yml @@ -18,6 +18,7 @@ spring: config: # 配置中心地址 server-addr: 43.142.44.217:8848 + namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74 # 配置文件格式 file-extension: yml # 共享配置