商品管理

dev
rouchen 2024-03-09 14:59:32 +08:00
parent 75b24524ae
commit d1a7a6d94c
41 changed files with 1326 additions and 70 deletions

View File

@ -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) + ")");
}
}

View File

@ -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();
}
}

View File

@ -3,6 +3,7 @@ package com.muyu.product.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.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;
}
}

View File

@ -3,6 +3,7 @@ package com.muyu.product.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.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;
}
}

View File

@ -3,6 +3,7 @@ package com.muyu.product.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.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;
}
}

View File

@ -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();
}

View File

@ -3,6 +3,7 @@ package com.muyu.product.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.CategoryInfoSaveModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@ -15,6 +16,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<String> supplier){
return CategoryInfo.builder()
.name(categoryInfoSaveReq.getName())
.image(categoryInfoSaveReq.getImage())
.start(categoryInfoSaveReq.getStart())
.introduction(categoryInfoSaveReq.getIntroduction())
.parentId(categoryInfoSaveReq.getParentId())
.createBy(supplier.get())
.createTime(new Date())
.build();
}
@ -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();
}
}

View File

@ -3,6 +3,7 @@ package com.muyu.product.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.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<Long> ruleId, Supplier<String> createBy) {
return RuleAttrInfo.builder()
.ruleId(ruleId.get())
.name(ruleAttrAddModel.getName())
.attrValue(String.join(",", ruleAttrAddModel.getValueList()))
.createBy(createBy.get())
.createTime(new Date())
.build();
}
}

View File

@ -3,6 +3,7 @@ package com.muyu.product.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.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<String> createBy) {
return RuleInfo.builder()
.name(ruleInfoAddModel.getName())
.status(ruleInfoAddModel.getStatus())
.createBy(createBy.get())
.createTime(new Date())
.build();
}
}

View File

@ -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();
}

View File

@ -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<Long> 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();
}
}

View File

@ -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<Long> attributeGroupIdList;
/**
* ID
*/
private List<Long> attributeIdList;
/**
* ID
*/
private List<Long> brandIdList;
/**
*
*/
public static CategoryInfoSaveModel saveBuild(CategoryInfoSaveReq categoryInfoSaveReq, Supplier<String> 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();
}
}

View File

@ -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<String> valueList;
public static RuleAttrAddModel infoBuild (RuleAttrInfo ruleAttrInfo) {
return RuleAttrAddModel.builder()
.name(ruleAttrInfo.getName())
.valueList(Arrays.stream(ruleAttrInfo.getAttrValue().split(",")).toList())
.build();
}
}

View File

@ -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<RuleAttrAddModel> ruleAttrList;
public static RuleInfoAddModel saveReqBuild(RuleInfoSaveReq req){
return RuleInfoAddModel.builder()
.name(req.getName())
.status(req.getStatus())
.ruleAttrList(req.getRuleAttrList())
.build();
}
}

View File

@ -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<TemplateAttributeModel> 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<Long, List<TemplateAttributeModel>> attributeList){
return TemplateAttributeGroupModel.builder()
.groupName(attributeGroup.getName())
.attributeList(attributeList.apply(attributeGroup.getId()))
.build();
}
}

View File

@ -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;
}

View File

@ -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<Long> attributeIdList;
}

View File

@ -33,5 +33,8 @@ public class AttributeInfoEditReq extends BaseEntity {
@ApiModelProperty(name = "分组", value = "分组")
private Long groupId;
@ApiModelProperty(name = "属性编码", value = "属性编码")
private String code;
}

View File

@ -29,5 +29,8 @@ public class AttributeInfoQueryReq extends BaseEntity {
@ApiModelProperty(name = "属性名", value = "属性名")
private String name;
@ApiModelProperty(name = "属性编码", value = "属性编码")
private String code;
}

View File

@ -35,4 +35,7 @@ public class AttributeInfoSaveReq extends BaseEntity {
@ApiModelProperty(name = "属性名", value = "属性名", required = true)
private String name;
@ApiModelProperty(name = "属性编码", value = "属性编码")
private String code;
}

View File

@ -8,6 +8,8 @@ import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.web.domain.TreeEntity;
import java.util.List;
/**
* category_info
*
@ -48,4 +50,18 @@ public class CategoryInfoSaveReq extends TreeEntity {
@ApiModelProperty(name = "介绍", value = "介绍")
private String introduction;
/**
* ID
*/
private List<Long> attributeGroupIdList;
/**
* ID
*/
private List<Long> attributeIdList;
/**
* ID
*/
private List<Long> brandIdList;
}

View File

@ -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<RuleAttrAddModel> ruleAttrList;
}

View File

@ -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<AttributeInfo> attributeInfoList;
public static AttributeGroupPageResp groupBuild (AttributeGroup attributeGroup, List<AttributeInfo> attributeInfos) {
return AttributeGroupPageResp.builder()
.id(attributeGroup.getId())
.name(attributeGroup.getName())
.states(attributeGroup.getStates())
.attributeInfoList(attributeInfos)
.build();
}
public static AttributeGroupPageResp groupFunBuild (AttributeGroup attributeGroup, Function<Long,List<AttributeInfo> > function) {
return AttributeGroupPageResp.builder()
.id(attributeGroup.getId())
.name(attributeGroup.getName())
.states(attributeGroup.getStates())
.attributeInfoList(function.apply(attributeGroup.getId()))
.build();
}
}

View File

@ -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<TemplateAttributeGroupModel> templateAttributeGroupList;
/**
*
*/
private List<TemplateAttributeModel> templateAttributeList;
/**
*
*/
private List<TemplateAttributeModel> attributeList;
}

View File

@ -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<AttributeInfo> attributeInfoList;
/**
*
*/
private List<AttributeGroup> attributeGroupList;
/**
*
*/
private List<BrandInfo> brandInfoList;
}

View File

@ -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<RuleAttrAddModel> ruleAttrList;
public static RuleInfoResp infoBuild (RuleInfo ruleInfo, Function<Long, List<RuleAttrAddModel>> ruleAttrList) {
return RuleInfoResp.builder()
.id(ruleInfo.getId())
.name(ruleInfo.getName())
.status(ruleInfo.getStatus())
.ruleAttrList(ruleAttrList.apply(ruleInfo.getId()))
.build();
}
}

View File

@ -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<TableDataInfo<AttributeGroup>> list(AttributeGroupQueryReq attributeGroupQueryReq) {
public Result<TableDataInfo<AttributeGroupPageResp>> list(AttributeGroupQueryReq attributeGroupQueryReq) {
startPage();
List<AttributeGroup> list = attributeGroupService.list(AttributeGroup.queryBuild(attributeGroupQueryReq));
return getDataTable(list);
TableDataInfo<AttributeGroupPageResp> tableDataInfo =
attributeGroupService.page(AttributeGroup.queryBuild(attributeGroupQueryReq));
return Result.success(tableDataInfo);
}
/**
@ -83,7 +86,9 @@ public class AttributeGroupController extends BaseController {
@PostMapping
@ApiOperation("新增属性组")
public Result<String> add(@RequestBody AttributeGroupSaveReq attributeGroupSaveReq) {
return toAjax(attributeGroupService.save(AttributeGroup.saveBuild(attributeGroupSaveReq)));
return toAjax(
attributeGroupService.save(AttributeGroupSaveModel.saveReqBuild(attributeGroupSaveReq))
);
}
/**

View File

@ -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<String> add(@RequestBody AttributeInfoSaveReq attributeInfoSaveReq) {
return toAjax(attributeInfoService.save(AttributeInfo.saveBuild(attributeInfoSaveReq)));
AttributeInfo attributeInfo = AttributeInfo.saveBuild(attributeInfoSaveReq);
return attributeInfoService.save(attributeInfo) ? success(attributeInfo.getId()) : error();
}
/**

View File

@ -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<TableDataInfo<BrandInfo>> list(BrandInfoQueryReq brandInfoQueryReq) {
public Result list(BrandInfoQueryReq brandInfoQueryReq) {
boolean isPage = brandInfoQueryReq.getParams().get("isPage") == null || Convert.toBool(brandInfoQueryReq.getParams().get("isPage"), true);
if (isPage){
startPage();
}
List<BrandInfo> list = brandInfoService.list(BrandInfo.queryBuild(brandInfoQueryReq));
return getDataTable(list);
return isPage ? getDataTable(list) : Result.success(list);
}
/**

View File

@ -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<CategoryCommonElementResp> getTemplateAttributeByCateGoryId(@PathVariable("cateGoryId") Long cateGoryId) {
return Result.success(categoryInfoService.getTemplateAttributeByCateGoryId(cateGoryId));
}
/**
*
*/
@ -81,7 +100,9 @@ public class CategoryInfoController extends BaseController {
@PostMapping
@ApiOperation("新增品类信息")
public Result<String> add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) {
return toAjax(categoryInfoService.save(CategoryInfo.saveBuild(categoryInfoSaveReq)));
return toAjax(categoryInfoService.save(
CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername)
));
}
/**
@ -106,4 +127,18 @@ public class CategoryInfoController extends BaseController {
public Result<String> remove(@PathVariable List<Long> 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<CategoryParentCommonElementResp> parentCommonElement(
@PathVariable(value = "categoryId") Long categoryId
) {
return Result.success(categoryInfoService.parentCommonElement(categoryId));
}
}

View File

@ -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<TableDataInfo<RuleInfo>> list(RuleInfoQueryReq ruleInfoQueryReq) {
public Result list(RuleInfoQueryReq ruleInfoQueryReq) {
boolean isPage = ruleInfoQueryReq.getParams().get("isPage") == null || Convert.toBool(ruleInfoQueryReq.getParams().get("isPage"), true);
if (isPage){
startPage();
List<RuleInfo> list = ruleInfoService.list(RuleInfo.queryBuild(ruleInfoQueryReq));
return getDataTable(list);
}
TableDataInfo<RuleInfoResp> 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<String> add(@RequestBody RuleInfoSaveReq ruleInfoSaveReq) {
return toAjax(ruleInfoService.save(RuleInfo.saveBuild(ruleInfoSaveReq)));
return toAjax(ruleInfoService.save(RuleInfoAddModel.saveReqBuild(ruleInfoSaveReq)));
}
/**

View File

@ -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<AttributeGroup> {
/**
*
* @param attributeGroup
* @return
*/
public TableDataInfo<AttributeGroupPageResp> page(AttributeGroup attributeGroup);
/**
*
*
@ -19,4 +32,11 @@ public interface AttributeGroupService extends IService<AttributeGroup> {
*/
public List<AttributeGroup> list(AttributeGroup attributeGroup);
/**
*
* @param attributeGroupSaveModel
* @return
*/
public Boolean save(AttributeGroupSaveModel attributeGroupSaveModel);
}

View File

@ -19,4 +19,10 @@ public interface AttributeInfoService extends IService<AttributeInfo> {
*/
public List<AttributeInfo> list(AttributeInfo attributeInfo);
/**
* groupId
* @param groupId Id
* @return
*/
public List<AttributeInfo> attributeListByGroupId(Long groupId);
}

View File

@ -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<CategoryInfo> {
*/
public List<CategoryInfo> list(CategoryInfo categoryInfo);
/**
*
* @param categoryInfoSaveModel
* @return
*/
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel);
/**
* ID
* @param categoryId ID
* @return
*/
List<AttributeGroup> getAttributeGroup (Long categoryId);
/**
* ID
* @param categoryId ID
* @return
*/
List<BrandInfo> getBrand (Long categoryId);
/**
* ID
* @param categoryId ID
* @return
*/
List<AttributeInfo> getAttribute (Long categoryId);
/**
* ID
* @param categoryId ID
* @return
*/
CategoryParentCommonElementResp parentCommonElement (Long categoryId);
/**
* ID
* @param cateGoryId ID
* @return
*/
CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId);
}

View File

@ -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<RuleInfo> {
*/
public List<RuleInfo> list(RuleInfo ruleInfo);
/**
*
* @param ruleInfoAddModel
* @return
*/
public boolean save(RuleInfoAddModel ruleInfoAddModel);
TableDataInfo<RuleInfoResp> queryList (RuleInfoQueryReq ruleInfoQueryReq);
}

View File

@ -40,10 +40,6 @@ public class AsAttributeGroupServiceImpl extends ServiceImpl<AsAttributeGroupMap
queryWrapper.eq(AsAttributeGroup::getAttributeId, asAttributeGroup.getAttributeId());
}
return list(queryWrapper);
}
}

View File

@ -1,15 +1,27 @@
package com.muyu.product.service.impl;
import java.util.List;
import com.muyu.common.core.utils.ObjUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.muyu.product.mapper.AttributeGroupMapper;
import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.service.AttributeGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.utils.ObjUtils;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.product.domain.AsAttributeGroup;
import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.model.AttributeGroupSaveModel;
import com.muyu.product.domain.resp.AttributeGroupPageResp;
import com.muyu.product.mapper.AttributeGroupMapper;
import com.muyu.product.service.AsAttributeGroupService;
import com.muyu.product.service.AttributeGroupService;
import com.muyu.product.service.AttributeInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* Service
@ -21,17 +33,46 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@Service
public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper, AttributeGroup> implements AttributeGroupService {
@Autowired
private AsAttributeGroupService attributeGroupService;
@Autowired
private AttributeInfoService attributeInfoService;
/**
*
*
* @param attributeGroupQuery
*
* @return
*/
@Override
public TableDataInfo<AttributeGroupPageResp> page (AttributeGroup attributeGroupQuery) {
List<AttributeGroup> list = this.list(attributeGroupQuery);
List<AttributeGroupPageResp> pageRespList = list.stream()
.map(attributeGroup ->
AttributeGroupPageResp.groupFunBuild(
attributeGroup, groupId -> attributeInfoService.attributeListByGroupId(groupId)
)
)
.toList();
return TableDataInfo.<AttributeGroupPageResp>builder()
.total(new PageInfo(list).getTotal())
.rows(pageRespList)
.build();
}
/**
*
*
* @param attributeGroup
*
* @return
*/
@Override
public List<AttributeGroup> list (AttributeGroup attributeGroup) {
LambdaQueryWrapper<AttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
if (ObjUtils.notNull(attributeGroup.getName())) {
queryWrapper.like(AttributeGroup::getName, attributeGroup.getName());
}
@ -42,4 +83,28 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
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<Long> attributeIdList = attributeGroupSaveModel.getAttributeIdList();
attributeGroupService.saveBatch(
attributeIdList.stream()
.map(attributeId -> AsAttributeGroup.buildGroup(attributeGroupId, attributeId))
.toList()
);
return save;
}
}

View File

@ -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<AttributeInfoMapper, AttributeInfo> implements AttributeInfoService {
@Autowired
private AsAttributeGroupService asAttributeGroupService;
/**
*
*
@ -36,6 +43,35 @@ public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, A
queryWrapper.like(AttributeInfo::getName, attributeInfo.getName());
}
if (ObjUtils.notNull(attributeInfo.getCode())){
queryWrapper.like(AttributeInfo::getCode, attributeInfo.getCode());
}
return list(queryWrapper);
}
/**
* groupId
*
* @param groupId Id
*
* @return
*/
@Override
public List<AttributeInfo> attributeListByGroupId (Long groupId) {
if (groupId == null){
throw new ServiceException("查询商品属性组属性组ID不可为空");
}
LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsAttributeGroup::getGroupId, groupId);
List<Long> list = asAttributeGroupService.list(queryWrapper).stream()
.map(AsAttributeGroup::getAttributeId)
.toList();
if (list == null || list.isEmpty()){
return null;
}
return this.listByIds(
list
);
}
}

View File

@ -35,7 +35,7 @@ public class BrandInfoServiceImpl extends ServiceImpl<BrandInfoMapper, BrandInfo
if (ObjUtils.notNull(brandInfo.getNam())){
queryWrapper.eq(BrandInfo::getNam, brandInfo.getNam());
queryWrapper.like(BrandInfo::getNam, brandInfo.getNam());
}
if (ObjUtils.notNull(brandInfo.getLogo())){

View File

@ -1,15 +1,30 @@
package com.muyu.product.service.impl;
import java.util.List;
import com.muyu.common.core.utils.ObjUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.muyu.product.mapper.CategoryInfoMapper;
import com.muyu.product.domain.CategoryInfo;
import com.muyu.product.service.CategoryInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.mapper.CategoryInfoMapper;
import com.muyu.product.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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;
/**
* Service
@ -21,10 +36,33 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@Service
public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, CategoryInfo> implements CategoryInfoService {
@Autowired
private AsCategoryAttributeService asCategoryAttributeService;
@Autowired
private AsCategoryAttributeGroupService asCategoryAttributeGroupService;
@Autowired
private AsCategoryBrandService asCategoryBrandService;
@Autowired
private AsAttributeGroupService asAttributeGroupService;
@Autowired
private AttributeInfoService attributeInfoService;
@Autowired
private BrandInfoService brandInfoService;
@Autowired
private AttributeGroupService attributeGroupService;
/**
*
*
* @param categoryInfo
*
* @return
*/
@Override
@ -52,10 +90,284 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
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<Long> attributeIdList = categoryInfoSaveModel.getAttributeIdList();
if (attributeIdList != null && !attributeIdList.isEmpty()) {
asCategoryAttributeService.saveBatch(
attributeIdList.stream()
.map(attributeId -> AsCategoryAttribute.categoryBuild(categoryInfoId, attributeId))
.toList()
);
}
List<Long> attributeGroupIdList = categoryInfoSaveModel.getAttributeGroupIdList();
if (attributeGroupIdList != null && !attributeGroupIdList.isEmpty()) {
asCategoryAttributeGroupService.saveBatch(
attributeGroupIdList.stream()
.map(attributeGroupId -> AsCategoryAttributeGroup.categoryBuild(categoryInfoId, attributeGroupId))
.toList()
);
}
List<Long> 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<AttributeGroup> getAttributeGroup (Long categoryId) {
List<AttributeGroup> attributeGroupList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryAttributeGroup::getCategoryId, categoryId);
List<AsCategoryAttributeGroup> asCategoryAttributeGroupList = asCategoryAttributeGroupService.list(queryWrapper);
if (asCategoryAttributeGroupList != null && !asCategoryAttributeGroupList.isEmpty()) {
List<Long> 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<AttributeGroup> attributeGroups = getAttributeGroup(categoryInfo.getParentId());
attributeGroups.forEach(attributeGroup -> {
if (!attributeGroupList.contains(attributeGroup)) {
attributeGroupList.add(attributeGroup);
}
});
}
}
return attributeGroupList;
}
/**
* ID
*
* @param categoryId ID
*
* @return
*/
@Override
public List<BrandInfo> getBrand (Long categoryId) {
List<BrandInfo> brandInfoList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryBrand> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryBrand::getCategoryId, categoryId);
List<AsCategoryBrand> asCategoryBrandList = asCategoryBrandService.list(queryWrapper);
if (asCategoryBrandList != null && !asCategoryBrandList.isEmpty()) {
List<Long> 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<BrandInfo> brandInfos = getBrand(categoryInfo.getParentId());
brandInfos.forEach(brandInfo -> {
if (!brandInfoList.contains(brandInfo)) {
brandInfoList.add(brandInfo);
}
});
}
}
return brandInfoList;
}
/**
* ID
*
* @param categoryId ID
*
* @return
*/
@Override
public List<AttributeInfo> getAttribute (Long categoryId) {
List<AttributeInfo> attributeInfoList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryAttribute::getCategoryId, categoryId);
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper);
if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()) {
List<Long> attributeIdList = asCategoryAttributeList.stream()
.map(AsCategoryAttribute::getAttributeId)
.toList();
attributeInfoList.addAll(attributeInfoService.listByIds(attributeIdList));
}
CategoryInfo categoryInfo = this.getById(categoryId);
if (categoryInfo.getParentId() != 0) {
if (attributeInfoList.isEmpty()) {
attributeInfoList.addAll(getAttribute(categoryInfo.getParentId()));
} else {
List<AttributeInfo> attributeInfos = getAttribute(categoryInfo.getParentId());
attributeInfos.forEach(attributeInfoQuery -> {
if (!attributeInfoList.contains(attributeInfoQuery)) {
attributeInfoList.add(attributeInfoQuery);
}
});
}
}
return attributeInfoList;
}
public <T, AS> List<T> getCommon (Long categoryId, IService<AS> iService, IService<T> bsiService) {
List<T> list = new ArrayList();
QueryWrapper<AS> asQueryWrapper = new QueryWrapper<>();
asQueryWrapper.eq("category_id", categoryId);
List<AS> asList = iService.list(asQueryWrapper);
if (asList != null && !asList.isEmpty()) {
List<Long> 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<T> 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<Long> 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<Long> cateGoryIdList = new ArrayList<>();
getParentIdListByCateGoryId(cateGoryIdList, cateGoryId);
// 取出和品类相关联的属性组关系 - 中间表
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{
in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList);
}};
List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper);
List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream()
.map(asCategoryAttributeGroup -> TemplateAttributeGroupModel.attributeGroupBuild(
attributeGroupService.getById(asCategoryAttributeGroup.getAttributeGroupId()),
attributeGroupId -> {
LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupQueryWrapper = new LambdaQueryWrapper<>() {{
eq(AsAttributeGroup::getGroupId, asCategoryAttributeGroup.getAttributeGroupId());
}};
List<Long> 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<Long> attributeIdSet = new HashSet<>();
// 获取组内所有的属性Id
if (!attributeGroupModelList.isEmpty()){
attributeIdSet.addAll(
attributeGroupModelList.stream()
.flatMap((Function<TemplateAttributeGroupModel, Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
.map(TemplateAttributeModel::getId)
.toList()
);
}
List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>();
categoryAttributeQueryWrapper.in(AsCategoryAttribute::getCategoryId, cateGoryIdList);
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper);
if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()){
List<Long> templateAttributeIdList = asCategoryAttributeList.stream()
.map(AsCategoryAttribute::getAttributeId)
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId))
.toList();
templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream()
.map(AttributeInfo::buildTemplateModel)
.toList();
}
List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
if (!templateAttributeModelList.isEmpty()){
attributeIdSet.addAll(
templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList()
);
}
LambdaQueryWrapper<AttributeInfo> 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();
}
}

View File

@ -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<RuleInfoMapper, RuleInfo> implements RuleInfoService {
@Autowired
private RuleAttrInfoService ruleAttrInfoService;
/**
*
*
@ -46,4 +65,41 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo>
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<RuleInfoResp> queryList (RuleInfoQueryReq ruleInfoQueryReq) {
List<RuleInfo> list = this.list(RuleInfo.queryBuild(ruleInfoQueryReq));
List<RuleInfoResp> ruleInfoRespList = list.stream()
.map(ruleInfo -> RuleInfoResp.infoBuild(ruleInfo, ruleId -> {
LambdaQueryWrapper<RuleAttrInfo> 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.<RuleInfoResp>builder()
.rows(ruleInfoRespList)
.total(isPage ? new PageInfo<>(list).getTotal() : 0)
.build();
}
}