product
Yunfei Du 2024-03-06 20:04:27 +08:00
parent 17eee84e43
commit a516b738ca
32 changed files with 782 additions and 45 deletions

6
DirectoryV3.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<trees>
<tree path="/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/AttributeGroupSaveModel.java"
title="属性组添加模型" extension="" presentableText="" tooltipTitle="" icon="" textColor=""
backgroundColor=""/>
</trees>

View File

@ -19,6 +19,7 @@ import lombok.experimental.SuperBuilder;
* @author DongZeLiang
* @date 2024-02-27
*/
@Data
@SuperBuilder
@NoArgsConstructor
@ -52,4 +53,15 @@ public class AsCategoryAttribute extends BaseEntity {
.attributeId(attributeId)
.build();
}
public static AsCategoryAttribute buildCategoryAttribute(Long categoryInfoId,Long attributeId){
return AsCategoryAttribute.builder ()
.categoryId(categoryInfoId)
.attributeId(attributeId)
.build ();
}
public static AsCategoryAttribute buildCategoryAttribute(Long categoryInfoId){
return AsCategoryAttribute.builder ()
.categoryId(categoryInfoId)
.build ();
}
}

View File

@ -52,4 +52,11 @@ public class AsCategoryAttributeGroup extends BaseEntity {
.attributeGroupId(attributeGroupId)
.build();
}
public static AsCategoryAttributeGroup categoryAttributeGroup(Long categoryId){
return AsCategoryAttributeGroup.builder()
.categoryId(categoryId)
.build();
}
}

View File

@ -7,11 +7,9 @@ import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.springframework.beans.factory.annotation.Autowired;
/**
* as_category_brand
@ -30,11 +28,11 @@ public class AsCategoryBrand extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(value = "id",type = IdType.AUTO)
@ApiModelProperty(name = "主键", value = "主键")
private Long id;
/** 品类id */
@Excel(name = "品类id")
@ApiModelProperty(name = "品类id", value = "品类id", required = true)
@ -51,4 +49,10 @@ public class AsCategoryBrand extends BaseEntity {
.brandId(brandId)
.build();
}
public static AsCategoryBrand categoryBrand(Long categoryId){
return AsCategoryBrand.builder ()
.categoryId(categoryId)
.build ();
}
}

View File

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.model.TemplateAttributeModel;
import com.muyu.product.domain.req.AttributeInfoEditReq;
import com.muyu.product.domain.req.AttributeInfoQueryReq;
import com.muyu.product.domain.req.AttributeInfoSaveReq;
@ -49,6 +50,15 @@ public class AttributeInfo extends BaseEntity {
private String name;
public TemplateAttributeModel buildTemplateModel(){
return TemplateAttributeModel.builder()
.id(this.getId())
.code(this.getCode())
.name(this.getName())
.build();
}
/**
*
*/

View File

@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.model.RuleAttrAddModel;
import com.muyu.product.domain.model.RuleInfoAddModel;
import com.muyu.product.domain.req.RuleAttrInfoEditReq;
import com.muyu.product.domain.req.RuleAttrInfoQueryReq;
import com.muyu.product.domain.req.RuleAttrInfoSaveReq;
@ -16,6 +18,9 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.Date;
import java.util.function.Supplier;
/**
* rule_attr_info
*
@ -75,6 +80,7 @@ public class RuleAttrInfo extends BaseEntity {
.build();
}
/**
*
*/
@ -87,4 +93,13 @@ public class RuleAttrInfo extends BaseEntity {
.build();
}
public static RuleAttrInfo addModelBuild(RuleAttrAddModel ruleAttrAddModel, Long ruleId, Supplier<String> createBy) {
return RuleAttrInfo.builder()
.ruleId(ruleId)
.name(ruleAttrAddModel.getName())
.attrValue(String.join ( ",", ruleAttrAddModel.getValueList ()))
.createBy ( createBy.get ( ) )
.createTime ( new Date () )
.build();
}
}

View File

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.model.RuleInfoAddModel;
import com.muyu.product.domain.req.RuleInfoEditReq;
import com.muyu.product.domain.req.RuleInfoQueryReq;
import com.muyu.product.domain.req.RuleInfoSaveReq;
@ -16,6 +17,9 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.Date;
import java.util.function.Supplier;
/**
* rule_info
*
@ -79,4 +83,18 @@ public class RuleInfo extends BaseEntity {
.build();
}
/**
* @param ruleInfoAddModel
* @param supplier
* @return
*/
public static RuleInfo addModelBuild(RuleInfoAddModel ruleInfoAddModel, Supplier<String> supplier){
return RuleInfo.builder ()
.name( ruleInfoAddModel.getName ( ) )
.status( ruleInfoAddModel.getStatus ( ) )
.createBy ( supplier.get () )
.createTime ( new Date () )
.build ();
}
}

View File

@ -0,0 +1,17 @@
package com.muyu.product.domain.demo;
import lombok.Data;
/**
* @ClassName Attribute
* @Description
* @Author YunFei.Du
* @Date 2024/3/6 14:20
*/
@Data
public class Attribute {
private Long id;
private String code;
private String attributeName;
}

View File

@ -0,0 +1,18 @@
package com.muyu.product.domain.demo;
import com.muyu.product.domain.AttributeInfo;
import lombok.Data;
import java.util.List;
/**
* @ClassName Group
* @Description
* @Author YunFei.Du
* @Date 2024/3/6 14:19
*/
@Data
public class Group {
private String groupName;
private List< AttributeInfo > list;
}

View File

@ -0,0 +1,39 @@
package com.muyu.product.domain.demo;
import com.muyu.common.core.web.domain.TreeEntity;
import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.ProjectInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @ClassName AttributeGroup
* @Description
* @Author YunFei.Du
* @Date 2024/3/6 14:13
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Project extends TreeEntity {
/**
*
*/
private List< AttributeGroup > attributeGroupList;
/**
*
*/
private List< ProjectInfo > projectInfoList;
/**
*
*/
private Long id;
private String code;
private String attributeGroupName;
private List< AttributeInfo > attributeList;
}

View File

@ -0,0 +1,77 @@
package com.muyu.product.domain.model;
import com.muyu.common.core.web.domain.TreeEntity;
import com.muyu.product.domain.req.CategoryInfoEditReq;
import com.muyu.product.domain.req.CategoryInfoSaveReq;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.Date;
import java.util.List;
import java.util.function.Supplier;
/**
* @ClassName CategoryInfoSaveModel
* @Description
* @Author Xin.Yao
* @Date 2024/3/3 8:52
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class CategoryInfoEditModel extends TreeEntity {
private Long id;
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 CategoryInfoEditModel editBuild(Long id,CategoryInfoEditReq categoryInfoEditReq, Supplier<String> supplier){
return CategoryInfoEditModel.builder()
.id ( id )
.name(categoryInfoEditReq.getName())
.image(categoryInfoEditReq.getImage())
.start(categoryInfoEditReq.getStart())
.introduction(categoryInfoEditReq.getIntroduction())
.parentId(categoryInfoEditReq.getParentId())
.attributeGroupIdList(categoryInfoEditReq.getAttributeGroupIdList())
.attributeIdList(categoryInfoEditReq.getAttributeIdList())
.brandIdList(categoryInfoEditReq.getBrandIdList())
.createBy(supplier.get())
.createTime(new Date())
.build();
}
public static CategoryInfoEditReq editBuild1(CategoryInfoEditReq categoryInfoEditReq,Supplier<String> supplier){
return CategoryInfoEditReq.builder ()
.name ( categoryInfoEditReq.getName () )
.image ( categoryInfoEditReq.getImage ( ) )
.start ( categoryInfoEditReq.getStart () )
.introduction ( categoryInfoEditReq.getIntroduction () )
.parentId ( categoryInfoEditReq.getParentId () )
.createBy ( supplier.get () )
.createTime ( new Date () )
.build ();
}
}

View File

@ -0,0 +1,46 @@
package com.muyu.product.domain.model;
import com.muyu.common.core.web.domain.TreeEntity;
import com.muyu.product.domain.RuleAttrInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.Arrays;
import java.util.List;
/**
* @ClassName RuleAttrAddModel
* @Description ,
* @Author YunFei.Du
* @Date 2024/3/4 14:41
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public class RuleAttrAddModel extends TreeEntity {
/**
*
*/
private String name;
private Long ruleId;
/**
*
*/
private List<String> valueList;
public static RuleAttrAddModel infoBuild (RuleAttrInfo ruleAttrInfo) {
return RuleAttrAddModel.builder()
.name(ruleAttrInfo.getName())
.ruleId( ruleAttrInfo.getRuleId ( ) )
.valueList( Arrays.stream(ruleAttrInfo.getAttrValue().split(",")).toList())
.build();
}
}

View File

@ -0,0 +1,52 @@
package com.muyu.product.domain.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.TreeEntity;
import com.muyu.product.domain.RuleAttrInfo;
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;
/**
* @ClassName RuleInfoAddModel
* @Description
* @Author YunFei.Du
* @Date 2024/3/4 16:29
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("rule_info")
@EqualsAndHashCode(callSuper = true)
public class RuleInfoAddModel extends TreeEntity {
/** 规格名称 */
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.baomidou.mybatisplus.annotation.TableName;
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;
/**
* @ClassName
* @Description
* @Author YunFei.Du
* @Date 2024/3/6 14:31
*/
@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,38 @@
package com.muyu.product.domain.model;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @ClassName
* @Description
* @Author YunFei.Du
* @Date 2024/3/6 14:31
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class TemplateAttributeModel extends BaseEntity {
/**
*
*/
private Long id;
/**
*
*/
private String name;
/**
*
*/
private String code;
}

View File

@ -8,6 +8,8 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* category_info
*
@ -39,4 +41,8 @@ public class CategoryInfoEditReq extends TreeEntity {
@ApiModelProperty(name = "介绍", value = "介绍")
private String introduction;
private List<Long> attributeGroupIdList;
private List<Long> attributeIdList;
private List<Long> brandIdList;
}

View File

@ -1,6 +1,7 @@
package com.muyu.product.domain.req;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.model.RuleAttrAddModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
@ -8,6 +9,8 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* rule_info
*
@ -38,4 +41,8 @@ public class RuleInfoSaveReq extends BaseEntity {
@ApiModelProperty(name = "规格状态", value = "规格状态")
private String status;
/**
*
*/
private List< RuleAttrAddModel > ruleAttrList;
}

View File

@ -0,0 +1,38 @@
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;
/**
* @ClassName CategoryCommonElementReq
* @Description
* @Author YunFei.Du
* @Date 2024/3/6 14:26
*/
@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

@ -1,12 +1,10 @@
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 com.muyu.product.domain.BrandInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;
import java.util.List;
@ -20,7 +18,8 @@ import java.util.List;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CategoryParentCommonElementResp {
@EqualsAndHashCode(callSuper = true)
public class CategoryParentCommonElementResp extends BaseEntity {
/**
*

View File

@ -0,0 +1,44 @@
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;
/**
* @ClassName RuleInfoResp
* @Description
* @Author YunFei.Du
* @Date 2024/3/4 18:02
*/
@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,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) {
startPage();
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

@ -4,7 +4,9 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.muyu.common.security.utils.SecurityUtils;
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;
@ -76,6 +78,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));
}
/**
*
*/
@ -95,7 +108,8 @@ public class CategoryInfoController extends BaseController {
@PutMapping("/{id}")
@ApiOperation("修改品类信息")
public Result<String> edit(@PathVariable Long id, @RequestBody CategoryInfoEditReq categoryInfoEditReq) {
return toAjax(categoryInfoService.updateById(CategoryInfo.editBuild(id,categoryInfoEditReq)));
categoryInfoService.updateCategory(id,categoryInfoEditReq);
return toAjax(categoryInfoService.updateById( CategoryInfo.editBuild(id,categoryInfoEditReq)));
}
/**

View File

@ -3,6 +3,10 @@ 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.RuleAttrAddModel;
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 +49,14 @@ public class RuleInfoController extends BaseController {
@ApiOperation("获取商品规格列表")
@RequiresPermissions("product:rule:list")
@GetMapping("/list")
public Result<TableDataInfo<RuleInfo>> list(RuleInfoQueryReq ruleInfoQueryReq) {
startPage();
List<RuleInfo> list = ruleInfoService.list(RuleInfo.queryBuild(ruleInfoQueryReq));
return getDataTable(list);
public Result<TableDataInfo<RuleInfoResp>> list(RuleInfoQueryReq ruleInfoQueryReq) {
boolean isPage = ruleInfoQueryReq.getParams ( ).get ( "isPage" )==null || Convert.toBool ( ruleInfoQueryReq.getParams ().get ( "isPage" ),true );
if (isPage){
startPage();
}
TableDataInfo< RuleInfoResp > tableDataInfo = ruleInfoService.queryList(ruleInfoQueryReq);
return Result.success ( tableDataInfo );
}
/**
@ -59,6 +67,7 @@ public class RuleInfoController extends BaseController {
@Log(title = "商品规格", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, RuleInfo ruleInfo) {
List<RuleInfo> list = ruleInfoService.list(ruleInfo);
ExcelUtil<RuleInfo> util = new ExcelUtil<RuleInfo>(RuleInfo.class);
util.exportExcel(response, list, "商品规格数据");
@ -72,6 +81,7 @@ public class RuleInfoController extends BaseController {
@GetMapping(value = "/{id}")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
public Result<RuleInfo> getInfo(@PathVariable("id") Long id) {
return Result.success(ruleInfoService.getById(id));
}
@ -83,7 +93,8 @@ 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

@ -8,6 +8,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.req.CategoryInfoEditReq;
import com.muyu.product.domain.resp.CategoryCommonElementResp;
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
/**
@ -60,4 +62,22 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
* @return ,,
*/
CategoryParentCommonElementResp parentCommonElement(Long categoryId);
/**
*
* @param id
* @param categoryInfoEditReq
*/
void updateCategory(Long id, CategoryInfoEditReq categoryInfoEditReq);
/**
* 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,10 @@ public interface RuleInfoService extends IService<RuleInfo> {
*/
public List<RuleInfo> list(RuleInfo ruleInfo);
public boolean save(RuleInfoAddModel ruleInfoAddModel);
TableDataInfo< RuleInfoResp > queryList (RuleInfoQueryReq ruleInfoQueryReq);
}

View File

@ -47,7 +47,6 @@ public class AsAttributeGroupServiceImpl extends ServiceImpl<AsAttributeGroupMap
return list(queryWrapper);
}
@Override
public void deleteAsAttributeGroupByIds(List< Long > ids) {
asAttributeGroupMapper.deleteAsAttributeGroupByIds ( ids );

View File

@ -39,11 +39,6 @@ public class AsBrandProjectServiceImpl extends ServiceImpl<AsBrandProjectMapper,
if (ObjUtils.notNull(asBrandProject.getProjectId())){
queryWrapper.eq(AsBrandProject::getProjectId, asBrandProject.getProjectId());
}
return list(queryWrapper);
}
}

View File

@ -40,10 +40,6 @@ public class AsCategoryAttributeGroupServiceImpl extends ServiceImpl<AsCategoryA
queryWrapper.eq(AsCategoryAttributeGroup::getAttributeGroupId, asCategoryAttributeGroup.getAttributeGroupId());
}
return list(queryWrapper);
}
}

View File

@ -41,9 +41,6 @@ public class AsCategoryAttributeServiceImpl extends ServiceImpl<AsCategoryAttrib
}
return list(queryWrapper);
}
}

View File

@ -35,11 +35,11 @@ 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())){
queryWrapper.eq(BrandInfo::getLogo, brandInfo.getLogo());
queryWrapper.eq (BrandInfo::getLogo, brandInfo.getLogo());
}
if (ObjUtils.notNull(brandInfo.getStart())){

View File

@ -10,6 +10,10 @@ 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.req.CategoryInfoEditReq;
import com.muyu.product.domain.resp.CategoryCommonElementResp;
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
import com.muyu.product.service.*;
import lombok.extern.slf4j.Slf4j;
@ -43,6 +47,10 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
private BrandInfoService brandInfoService;
@Autowired
private AttributeInfoService attributeInfoService;
@Autowired
private AsAttributeGroupService asAttributeGroupService;
/**
*
*
@ -91,51 +99,123 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
.build ();
}
/**
*
* @param id
* @param categoryInfoEditReq
*/
@Override
public void updateCategory(Long id, CategoryInfoEditReq categoryInfoEditReq) {
// 查询符合条件的列表 AsCategoryAttribute
AsCategoryAttribute asCategoryAttribute = AsCategoryAttribute.buildCategoryAttribute ( id );
List< AsCategoryAttribute > list = asCategoryAttributeService.list ( asCategoryAttribute );
ArrayList< Long > asCategoryIds = new ArrayList<> ( );
for (AsCategoryAttribute categoryAttribute : list) {
asCategoryIds.add ( categoryAttribute.getId () );
}
// 批量删除
asCategoryAttributeService.removeBatchByIds ( asCategoryIds );
List< Long > attributeIdList = categoryInfoEditReq.getAttributeIdList ( );
asCategoryAttributeService.saveBatch (
attributeIdList.stream( )
.map ( attributeId-> AsCategoryAttribute.buildCategoryAttribute ( id, attributeId ) )
.toList ()
);
AsCategoryAttributeGroup asCategoryAttributeGroup = AsCategoryAttributeGroup.categoryAttributeGroup ( id );
List< AsCategoryAttributeGroup > list1 = asCategoryAttributeGroupService.list ( asCategoryAttributeGroup );
ArrayList< Long > asCategoryIds1 = new ArrayList<> ( );
for (AsCategoryAttributeGroup categoryAttributeGroup : list1) {
asCategoryIds1.add ( categoryAttributeGroup.getId () );
}
// 批量删除
asCategoryAttributeGroupService.removeBatchByIds ( asCategoryIds1 );
List< Long > attributeGroupIdList = categoryInfoEditReq.getAttributeGroupIdList ();
asCategoryAttributeGroupService.saveBatch (
attributeGroupIdList.stream ()
.map ( attributeGroupId->AsCategoryAttributeGroup.categoryAttributeGroup ( id,attributeGroupId ) )
.toList ()
);
AsCategoryBrand asCategoryBrand = AsCategoryBrand.categoryBrand ( id );
List< AsCategoryBrand > list2 = asCategoryBrandService.list ( asCategoryBrand );
ArrayList< Long > asCategoryIds2 = new ArrayList<> ( );
for (AsCategoryBrand categoryBrand : list2) {
asCategoryIds2.add ( categoryBrand.getId () );
}
asCategoryBrandService.removeBatchByIds ( asCategoryIds2 );
List< Long > brandIdList = categoryInfoEditReq.getBrandIdList ( );
asCategoryBrandService.saveBatch (
brandIdList.stream ()
.map ( brandId->AsCategoryBrand.categoryBrand ( id,brandId ) )
.toList ()
);
}
@Override
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel) {
// 根据 CategoryInfoSaveModel 构建 categoryInfo 对象
CategoryInfo categoryInfo = CategoryInfo.saveModelBuild(categoryInfoSaveModel);
// 保存 CateGoryInfo,对象到数据库中
boolean save = this.save(categoryInfo);
// 获取保存后的CateGoryINfo 对象 的 Id
Long categoryInfoId = categoryInfo.getId();
// 处理属性列表
List<Long> attributeIdList = categoryInfoSaveModel.getAttributeIdList();
// 批量保存属性关联关系
// 是否为 null 是否为空
if (attributeIdList != null && !attributeIdList.isEmpty()){
asCategoryAttributeService.saveBatch(
attributeIdList.stream()
.map(attributeId -> AsCategoryAttribute.categoryBuild(categoryInfoId, attributeId))
.toList()
// 将 attributeIdList 转换为流,以便后续进行流式操作。
attributeIdList.stream()
// 使用 map 操作将流中的每个 attributeId 转换为相应的 AsCategoryAttribute 对象,这些对象表示类别和属性之间的关联关系。
.map(attributeId -> AsCategoryAttribute.categoryBuild(categoryInfoId, attributeId))
// 将流中的元素收集到一个新的列表中。
.toList()
);
}
// 处理属性分组列表
List<Long> attributeGroupIdList = categoryInfoSaveModel.getAttributeGroupIdList();
if (attributeGroupIdList != null && !attributeGroupIdList.isEmpty()){
// 批量保存属性分组关联关系
asCategoryAttributeGroupService.saveBatch(
attributeGroupIdList.stream()
.map(attributeGroupId -> AsCategoryAttributeGroup.categoryAttributeGroup(categoryInfoId, attributeGroupId))
.toList()
);
}
// 处理品牌列表
List<Long> brandIdList = categoryInfoSaveModel.getBrandIdList();
if (brandIdList != null && !brandIdList.isEmpty()){
// 批量保存品牌关联关系
asCategoryBrandService.saveBatch(
brandIdList.stream()
.map(brandId -> AsCategoryBrand.categoryBrand (categoryInfoId, brandId))
.toList()
);
}
// 返回保存结果
return save;
}
/**
*
* @param categoryId
* @return
*/
public <T,AS> List<T> getCommon(Long categoryId, IService<AS> iService, IService<T> bsiService){
List<T> list = new ArrayList();
QueryWrapper<AS> asQueryWrapper = new QueryWrapper<> ();
@ -192,6 +272,52 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
}
return attributeGroupList;
}
/**
* ID
*
* @param cateGoryId ID
*
* @return
*/
@Override
public CategoryCommonElementResp getTemplateAttributeByCateGoryId(Long cateGoryId) {
// 取出和品类相关联的属性组关系 - 中间表
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{
eq(AsCategoryAttributeGroup::getCategoryId, cateGoryId);
}};
List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper);
List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream()
.map(asCategoryAttributeGroup -> TemplateAttributeGroupModel.attributeGroupBuild(
attributeGroupService.getById(asCategoryAttributeGroup.getAttributeGroupId()),
attributeGroupId -> attributeInfoService.listByIds(
asAttributeGroupService.list(
new LambdaQueryWrapper<>(){{
eq(AsAttributeGroup::getGroupId, asCategoryAttributeGroup.getAttributeGroupId());
}}
).stream().map(AsAttributeGroup::getAttributeId).toList()
).stream()
.map(AttributeInfo::buildTemplateModel)
.toList()
))
.filter(TemplateAttributeGroupModel::isEffective)
.toList();
List< TemplateAttributeModel > templateAttributeModelList = new ArrayList<>();
List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
return CategoryCommonElementResp.builder()
.templateAttributeGroupList(attributeGroupModelList)
.templateAttributeList(templateAttributeModelList)
.attributeList(attributeModelList)
.build();
}
@Override
public List< BrandInfo > getBrand(Long categoryId) {
return null;

View File

@ -2,8 +2,19 @@ package com.muyu.product.service.impl;
import java.util.List;
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 +32,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 +60,41 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo>
return list(queryWrapper);
}
@Override
public boolean save(RuleInfoAddModel ruleInfoAddModel) {
// 调用添加模型构建
RuleInfo ruleInfo = RuleInfo.addModelBuild(ruleInfoAddModel, SecurityUtils::getUsername);
// 调用当前对象的save 方法保存 ruleInfo 对象,并获取保存的结果
boolean save = this.save(ruleInfo);
// if 保存成功 则继续 保存规则属性消息
if (save){
// 批量保存规则消息
ruleAttrInfoService.saveBatch(
ruleInfoAddModel.getRuleAttrList().stream()
// 将每个规则添加转换为 RuleAttrInfo 对象 并保存到列表中
.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();
}
}