diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AttributeGroup.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AttributeGroup.java index 37b3276..a910a89 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AttributeGroup.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/AttributeGroup.java @@ -38,8 +38,6 @@ public class AttributeGroup extends BaseEntity private String name; private List attributeList; - private List checkedAttributeIds; - private List asAttributeIds; /** 状态 */ @Excel(name = "状态") @@ -76,11 +74,4 @@ public class AttributeGroup extends BaseEntity .build(); } - public void setCheckedAttributeIds(List checkedAttributeIds) { - this.checkedAttributeIds = checkedAttributeIds; - } - - public List getCheckedAttributeIds() { - return checkedAttributeIds; - } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/BrandCategory.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/BrandCategory.java index 229245d..c5d5063 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/BrandCategory.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/BrandCategory.java @@ -2,14 +2,16 @@ package com.muyu.product.domain; import com.muyu.common.core.annotation.Excel; import com.muyu.common.core.web.domain.BaseEntity; -import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.product.domain.model.CategoryInfoSaveModel; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; +import java.util.List; +import java.util.function.Supplier; /** * 品牌品类中间对象 brand_category @@ -38,4 +40,18 @@ public class BrandCategory extends BaseEntity private Long brandId; + public static List saveBuilderList(CategoryInfoSaveModel categoryReq, Supplier getUsername) { + return categoryReq.getCheckedBrandIds().stream().map( + brandId -> BrandCategory.saveBuilder(categoryReq.getId(),brandId,getUsername) + ).toList(); + } + + private static BrandCategory saveBuilder(Long categoryId, Long brandId, Supplier getUsername) { + return BrandCategory.builder() + .brandId(brandId) + .categoryId(categoryId) + .createBy(getUsername.get()) + .createTime(new Date()) + .build(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryAttribute.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryAttribute.java index 01a63c7..fc0df9d 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryAttribute.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryAttribute.java @@ -2,14 +2,16 @@ package com.muyu.product.domain; import com.muyu.common.core.annotation.Excel; import com.muyu.common.core.web.domain.BaseEntity; -import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.product.domain.model.CategoryInfoSaveModel; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; +import java.util.List; +import java.util.function.Supplier; /** * 品类属性中间对象 category_attribute @@ -37,10 +39,18 @@ public class CategoryAttribute extends BaseEntity @Excel(name = "品类编号") private Long categoryId; - public static CategoryAttribute categoryBuilder(Long id, Long attributeId) { + public static CategoryAttribute categoryBuilder(Long categoryId, Long attributeId, Supplier username) { return CategoryAttribute.builder() - .categoryId(id) + .categoryId(categoryId) .attributeId(attributeId) + .createBy(username.get()) + .createTime(new Date()) .build(); } + + public static List saveBuilder(CategoryInfoSaveModel categoryReq, Supplier username) { + return categoryReq.getCheckedAttributeIds().stream().map( + attributeId -> categoryBuilder(categoryReq.getId(),attributeId,username) + ).toList(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryAttributeGroup.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryAttributeGroup.java index 89b2267..b05397d 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryAttributeGroup.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryAttributeGroup.java @@ -2,14 +2,16 @@ package com.muyu.product.domain; import com.muyu.common.core.annotation.Excel; import com.muyu.common.core.web.domain.BaseEntity; -import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.product.domain.model.CategoryInfoSaveModel; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; +import java.util.List; +import java.util.function.Supplier; /** * 品类属性组中间对象 category_attribute_group @@ -22,33 +24,46 @@ import org.apache.commons.lang3.builder.ToStringStyle; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = true) -public class CategoryAttributeGroup extends BaseEntity -{ +public class CategoryAttributeGroup extends BaseEntity { private static final long serialVersionUID = 1L; - /** 主键 */ + /** + * 主键 + */ private Long id; - /** 属性组编号 */ + /** + * 属性组编号 + */ @Excel(name = "属性组编号") private Long attributeGroupId; - /** 品类编号 */ + /** + * 品类编号 + */ @Excel(name = "品类编号") private Long categoryId; /** * 品类属性组中间表构建体 * 作用:提供数组对象 + * * @param id * @param groupId * @return */ - public static CategoryAttributeGroup saveBuilder(Long id, Long groupId) { + public static CategoryAttributeGroup saveBuilder(Long id, Long groupId, Supplier username) { return CategoryAttributeGroup.builder() .attributeGroupId(groupId) .categoryId(id) + .createBy(username.get()) + .createTime(new Date()) .build(); + } + public static List saveBuilderList(CategoryInfoSaveModel categoryReq, Supplier username) { + return categoryReq.getCheckedAttributeGroupIds().stream().map( + groupId -> saveBuilder(categoryReq.getId(), groupId, username) + ).toList(); } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryInfo.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryInfo.java index ddd5abc..ad1f984 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryInfo.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/CategoryInfo.java @@ -51,6 +51,7 @@ public class CategoryInfo extends TreeEntity .image(req.getImage()) .status(req.getStatus()) .remark(req.getRemark()) + .parentId(req.getParentId()) .build(); } @@ -61,9 +62,24 @@ public class CategoryInfo extends TreeEntity .name(req.getName()) .status(req.getStatus()) .image(req.getImage()) + .parentId(req.getParentId()) .remark(req.getRemark()) .createBy(req.getCreateBy()) .createTime(req.getCreateTime()) .build(); } + + public static CategoryInfo saveBuilder(CategoryInfoSaveModel categoryReq) { + return CategoryInfo.builder() + .id(categoryReq.getId()) + .name(categoryReq.getName()) + .status(categoryReq.getStatus()) + .image(categoryReq.getImage()) + .parentId(categoryReq.getParentId()) + .status(categoryReq.getStatus()) + .remark(categoryReq.getRemark()) + .createBy(categoryReq.getCreateBy()) + .createTime(categoryReq.getCreateTime()) + .build(); + } } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/CategoryInfoSaveModel.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/CategoryInfoSaveModel.java index 5a0eaa3..94dfa23 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/CategoryInfoSaveModel.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/model/CategoryInfoSaveModel.java @@ -42,11 +42,19 @@ public class CategoryInfoSaveModel extends TreeEntity { private String createBy; private Date createTime; + /** + * 已选属性组集合 + */ + private List checkedAttributeGroupIds; + /** + * 已选属性集合 + */ private List checkedAttributeIds; + /** + * 已选品牌集合 + */ + private List checkedBrandIds; - private List attributeGroupIds; - - private List brandIds; /** * 保存构建体 @@ -54,13 +62,13 @@ public class CategoryInfoSaveModel extends TreeEntity { public static CategoryInfoSaveModel saveBuilder(CategoryReq req, Supplier username){ return CategoryInfoSaveModel.builder() .checkedAttributeIds(req.getCheckedAttributeIds()) - .attributeGroupIds(req.getAttributeGroupIds()) - .brandIds(req.getBrandIds()) + .checkedAttributeGroupIds(req.getCheckedAttributeGroupIds()) + .checkedBrandIds(req.getCheckedBrandIds()) .image(req.getImage()) .name(req.getName()) .parentId(req.getParentId()) .createBy(username.get()) - .createTime(req.getCreateTime()) + .createTime(new Date()) .status(req.getStatus()) .remark(req.getRemark()) .build(); diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryReq.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryReq.java index d38820e..e529fbe 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryReq.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryReq.java @@ -1,12 +1,12 @@ package com.muyu.product.domain.req; -import com.muyu.common.core.annotation.Excel; +import com.muyu.common.core.web.domain.BaseEntity; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import java.util.Date; import java.util.List; /** @@ -15,37 +15,60 @@ import java.util.List; * @Author SaiSai.Liu * @Date 2024/3/5/0005 12:35 */ + @Data @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class CategoryReq { - /** 主键 */ +@EqualsAndHashCode(callSuper = true) +public class CategoryReq extends BaseEntity { + /** + * 主键 + */ private Long id; - /** 品类名称 */ + /** + * 品类名称 + */ private String name; - /** 图片 */ + /** + * 图片 + */ private String image; - /** 父级品类 */ + /** + * 父级品类 + */ private Long parentId; - /** 是否启用 */ + /** + * 是否启用 + */ private String status; - /** 说明 */ + /** + * 说明 + */ private String remark; - private String createBy; - private Date createTime; - + /** + * 已选属性组集合 + */ + private List checkedAttributeGroupIds; + /** + * 已选属性集合 + */ private List checkedAttributeIds; - - private List attributeGroupIds; - - private List brandIds; - + /** + * 已选品牌集合 + */ + private List checkedBrandIds; } + + + + + + diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/AttributeGroupResp.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/AttributeGroupResp.java new file mode 100644 index 0000000..462f348 --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/AttributeGroupResp.java @@ -0,0 +1,85 @@ +package com.muyu.product.domain.resp; + +import com.muyu.common.core.annotation.Excel; +import com.muyu.common.core.web.domain.BaseEntity; +import com.muyu.product.domain.Attribute; +import com.muyu.product.domain.AttributeGroup; +import com.muyu.product.domain.req.AttributeGroupReq; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +/** + * @ClassName AttributeGroupResp + * @Description 描述 + * @Author SaiSai.Liu + * @Date 2024/3/14/0014 20:46 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class AttributeGroupResp extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private Long id; + + /** + * 组名 + */ + @Excel(name = "组名") + private String name; + + private List attributeList; + + private List getAsAttributeIds; + + /** + * 状态 + */ + @Excel(name = "状态") + private String states; + + //创建添加属性组构建体 + public static AttributeGroupResp saveBuilder(AttributeGroupReq attributeGroupReq) { + return AttributeGroupResp.builder() + .name(attributeGroupReq.getName()) + .states(attributeGroupReq.getStates()) + .build(); + } + + + //创建修改属性组构建体 + public static AttributeGroupResp editBuilder(AttributeGroupReq attributeGroupReq) { + return AttributeGroupResp.builder() + .id(attributeGroupReq.getId()) + .name(attributeGroupReq.getName()) + .states(attributeGroupReq.getStates()) + .build(); + } + + public static AttributeGroupResp createBuilder(AttributeGroupReq attributeGroupReq) { + return AttributeGroupResp.builder() + .name(attributeGroupReq.getName()) + .states(attributeGroupReq.getStates()) + .build(); + } + + public static AttributeGroupResp saveBuilder(AttributeGroup attributeGroup1, List attributes) { + return AttributeGroupResp.builder() + .name(attributeGroup1.getName()) + .states(attributeGroup1.getStates()) + .id(attributeGroup1.getId()) + .attributeList(attributes) + .build(); + } +} diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryResp.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryResp.java index 913233a..60c6d3e 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryResp.java +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/resp/CategoryResp.java @@ -2,6 +2,10 @@ package com.muyu.product.domain.resp; import com.muyu.common.core.web.domain.TreeEntity; import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.product.domain.Attribute; +import com.muyu.product.domain.AttributeGroup; +import com.muyu.product.domain.Brand; +import com.muyu.product.domain.CategoryInfo; import com.muyu.product.domain.req.CategoryReq; import lombok.AllArgsConstructor; import lombok.Data; @@ -9,6 +13,8 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; import java.util.Date; +import java.util.List; +import java.util.function.Supplier; /** * @ClassName CategoryResp @@ -33,11 +39,9 @@ public class CategoryResp extends TreeEntity { /** 是否启用 */ private String status; - - private String createBy; - private String updateBy; - private Date createTime; - private Date updateTime; + private List checkAttributeList; + private List checkedAttributeGroupList; + private List brandList; /** @@ -45,12 +49,12 @@ public class CategoryResp extends TreeEntity { * @param categoryReq * @return */ - public static CategoryResp saveBuilder(CategoryReq categoryReq){ + public static CategoryResp saveBuilder(CategoryReq categoryReq, Supplier username){ return CategoryResp.builder() .name(categoryReq.getName()) .image(categoryReq.getImage()) .status(categoryReq.getStatus()) - .createBy(SecurityUtils.getUsername()) + .createBy(username.get()) .createTime(new Date()) .build(); } @@ -61,12 +65,12 @@ public class CategoryResp extends TreeEntity { * @param categoryReq * @return */ - public static CategoryResp updateBuilder(CategoryReq categoryReq){ + public static CategoryResp updateBuilder(CategoryReq categoryReq,Supplier username){ return CategoryResp.builder() .name(categoryReq.getName()) .image(categoryReq.getImage()) .status(categoryReq.getStatus()) - .updateBy(SecurityUtils.getUsername()) + .updateBy(username.get()) .updateTime(new Date()) .build(); } diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/结构 b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/结构 index cd1cd76..5e4fbdb 100644 --- a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/结构 +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/结构 @@ -87,6 +87,26 @@ +{createBy: null, createTime: "2024-02-29 21:37:52", updateBy: null, updateTime: "2024-03-10 16:06:52",…} +ancestors:null +checkedAttributeGroupIds:[2] +checkedAttributeIds:[5, 3] +checkedBrandIds:[2] +children:[] +createBy:null +createTime:"2024-02-29 21:37:52" +id:1 +image:"http://127.0.0.1:9300/statics/2024/02/29/8000030_20240229213748A003.jpg" +name:"电子产品" +orderNum:null +parentId:0 +parentName:null +remark: null +status: "Y" +updateBy: null +updateTime: "2024-03-10 16:06:52" + + diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeGroupController.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeGroupController.java index 55e988d..0054b3f 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeGroupController.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/AttributeGroupController.java @@ -7,6 +7,7 @@ import javax.servlet.http.HttpServletResponse; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.muyu.product.domain.Attribute; import com.muyu.product.domain.req.AttributeGroupReq; +import com.muyu.product.domain.resp.AttributeGroupResp; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -44,10 +45,10 @@ public class AttributeGroupController extends BaseController */ @RequiresPermissions("product:group:list") @GetMapping("/list") - public Result> list(AttributeGroup attributeGroup) + public Result> list(AttributeGroup attributeGroup) { startPage(); - List list = attributeGroupService.selectAttributeGroupList(attributeGroup); + List list = attributeGroupService.selectAttributeGroupList(attributeGroup); return getDataTable(list); } @@ -59,8 +60,8 @@ public class AttributeGroupController extends BaseController @PostMapping("/export") public void export(HttpServletResponse response, AttributeGroup attributeGroup) { - List list = attributeGroupService.selectAttributeGroupList(attributeGroup); - ExcelUtil util = new ExcelUtil(AttributeGroup.class); + List list = attributeGroupService.selectAttributeGroupList(attributeGroup); + ExcelUtil util = new ExcelUtil(AttributeGroupResp.class); util.exportExcel(response, list, "属性组数据"); } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/CategoryInfoController.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/controller/CategoryInfoController.java index 19b6330..9aa950f 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 @@ -44,9 +44,9 @@ public class CategoryInfoController extends BaseController */ @RequiresPermissions("product:category_info:list") @GetMapping("/list") - public Result list(CategoryInfo categoryInfo) + public Result list(CategoryInfoSaveModel categoryInfoSaveModel) { - List list = categoryInfoService.selectCategoryInfoList(categoryInfo); + List list = categoryInfoService.selectCategoryInfoList(categoryInfoSaveModel); return success(list); } @@ -56,10 +56,10 @@ public class CategoryInfoController extends BaseController @RequiresPermissions("product:category_info:export") @Log(title = "品类信息", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, CategoryInfo categoryInfo) + public void export(HttpServletResponse response, CategoryInfoSaveModel categoryInfoSaveModel) { - List list = categoryInfoService.selectCategoryInfoList(categoryInfo); - ExcelUtil util = new ExcelUtil(CategoryInfo.class); + List list = categoryInfoService.selectCategoryInfoList(categoryInfoSaveModel); + ExcelUtil util = new ExcelUtil(CategoryResp.class); util.exportExcel(response, list, "品类信息数据"); } @@ -90,9 +90,9 @@ public class CategoryInfoController extends BaseController @RequiresPermissions("product:category_info:edit") @Log(title = "品类信息", businessType = BusinessType.UPDATE) @PutMapping - public Result edit(@RequestBody CategoryInfo categoryInfo) + public Result edit(@RequestBody CategoryInfoSaveModel categoryInfoSaveModel) { - return toAjax(categoryInfoService.updateCategoryInfo(categoryInfo)); + return toAjax(categoryInfoService.updateCategoryInfo(categoryInfoSaveModel)); } /** diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/IAttributeGroupService.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/IAttributeGroupService.java index d1bb525..116d9c2 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/IAttributeGroupService.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/IAttributeGroupService.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.muyu.product.domain.Address; import com.muyu.product.domain.AttributeGroup; import com.muyu.product.domain.req.AttributeGroupReq; +import com.muyu.product.domain.resp.AttributeGroupResp; /** * 属性组Service接口 @@ -29,7 +30,7 @@ public interface IAttributeGroupService extends IService * @param attributeGroup 属性组 * @return 属性组集合 */ - List selectAttributeGroupList(AttributeGroup attributeGroup); + List selectAttributeGroupList(AttributeGroup attributeGroup); /** * 新增属性组 diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/ICategoryInfoService.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/ICategoryInfoService.java index 90d1f8e..84f2c9d 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/ICategoryInfoService.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/ICategoryInfoService.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.muyu.product.domain.Address; import com.muyu.product.domain.CategoryInfo; import com.muyu.product.domain.model.CategoryInfoSaveModel; +import com.muyu.product.domain.req.CategoryReq; +import com.muyu.product.domain.resp.CategoryResp; /** * 品类信息Service接口 @@ -26,26 +28,26 @@ public interface ICategoryInfoService extends IService /** * 查询品类信息列表 * - * @param categoryInfo 品类信息 + * @param categoryInfoSaveModel 品类信息 * @return 品类信息集合 */ - List selectCategoryInfoList(CategoryInfo categoryInfo); + List selectCategoryInfoList(CategoryInfoSaveModel categoryInfoSaveModel); /** * 新增品类信息 * - * @param categoryInfo 品类信息 + * @param categoryInfoSaveModel 品类信息 * @return 结果 */ - int insertCategoryInfo(CategoryInfo categoryInfo); + int insertCategoryInfo(CategoryInfoSaveModel categoryInfoSaveModel); /** * 修改品类信息 * - * @param categoryInfo 品类信息 + * @param categoryInfoSaveModel 品类信息 * @return 结果 */ - int updateCategoryInfo(CategoryInfo categoryInfo); + boolean updateCategoryInfo(CategoryInfoSaveModel categoryInfoSaveModel); /** * 批量删除品类信息 diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AttributeGroupServiceImpl.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AttributeGroupServiceImpl.java index cb24c02..90cc992 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AttributeGroupServiceImpl.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/impl/AttributeGroupServiceImpl.java @@ -6,6 +6,7 @@ import com.muyu.product.domain.AsAttributeGroup; import com.muyu.product.domain.Attribute; import com.muyu.product.domain.AttributeGroup; import com.muyu.product.domain.req.AttributeGroupReq; +import com.muyu.product.domain.resp.AttributeGroupResp; import com.muyu.product.mapper.AsAttributeGroupMapper; import com.muyu.product.mapper.AttributeGroupMapper; import com.muyu.product.service.IAsAttributeGroupService; @@ -64,9 +65,9 @@ public class AttributeGroupServiceImpl extends ServiceImpl attributeLongs.add(attributeService.selectAttributeById(asAttributeGroup.getAttributeId()))); asAttributeGroups.forEach(asAttributeGroup -> longs.add(attributeService.selectAttributeById(asAttributeGroup.getAttributeId()).getId())); asAttributeGroups.forEach(asAttributeGroup -> asIds.add(asAttributeGroup.getId())); - group.setAttributeList(attributeLongs); - group.setCheckedAttributeIds(longs); - group.setAsAttributeIds(asIds); +// group.setAttributeList(attributeLongs); +// group.setCheckedAttributeIds(longs); +// group.setAsAttributeIds(asIds); } @@ -78,10 +79,16 @@ public class AttributeGroupServiceImpl extends ServiceImpl selectAttributeGroupList(AttributeGroup attributeGroup) { + public List selectAttributeGroupList(AttributeGroup attributeGroup) { List attributeGroups = attributeGroupMapper.selectAttributeGroupList(attributeGroup); attributeGroups.forEach(this::setAttributeList); - return attributeGroups; + List list = attributeGroups.stream().map(group -> + AttributeGroupResp.saveBuilder(group,attributeService.listByIds(asAttributeGroupService.list( + new LambdaQueryWrapper() + .eq(AsAttributeGroup::getGroupId, group.getId())) + .stream().map(AsAttributeGroup::getAttributeId).toList())) + ).toList(); + return list; } /** @@ -121,7 +128,11 @@ public class AttributeGroupServiceImpl extends ServiceImpl AsAttributeGroup .saveBuilder(attributeGroup.getId(), attributeId)) .toList(); - asAttributeGroupService.removeBatchByIds(attributeGroup.getAsAttributeIds()); +// attributeGroup.getAsAttributeIds() + asAttributeGroupService.removeBatchByIds(asAttributeGroupService.list(new LambdaQueryWrapper() + .eq(AsAttributeGroup::getGroupId,attributeGroup.getId())) + .stream().map(AsAttributeGroup::getId).toList() + ); asAttributeGroupService.saveBatch(asAttributeGroups); // asAttributeGroups.forEach(asAttributeGroup -> asAttributeGroupService.updateAsAttributeGroup(asAttributeGroup)); return asAttributeGroups.size(); 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 7681a3d..19d3f4b 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,19 +1,18 @@ package com.muyu.product.service.impl; -import java.util.List; - +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.muyu.common.core.utils.DateUtils; -import com.muyu.product.domain.CategoryAttribute; -import com.muyu.product.domain.CategoryAttributeGroup; +import com.muyu.common.security.utils.SecurityUtils; +import com.muyu.product.domain.*; import com.muyu.product.domain.model.CategoryInfoSaveModel; -import com.muyu.product.service.ICategoryAttributeService; +import com.muyu.product.domain.resp.CategoryResp; +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 com.muyu.product.mapper.CategoryInfoMapper; -import com.muyu.product.domain.CategoryInfo; -import com.muyu.product.service.ICategoryInfoService; + +import java.util.List; /** * 品类信息Service业务层处理 @@ -23,14 +22,22 @@ import com.muyu.product.service.ICategoryInfoService; */ @Slf4j @Service -public class CategoryInfoServiceImpl extends ServiceImpl implements ICategoryInfoService -{ +public class CategoryInfoServiceImpl extends ServiceImpl implements ICategoryInfoService { @Autowired private CategoryInfoMapper categoryInfoMapper; @Autowired private ICategoryAttributeService categoryAttributeService; @Autowired - private CategoryAttributeGroupServiceImpl categoryAttributeGroupService; + private ICategoryAttributeGroupService categoryAttributeGroupService; + @Autowired + private IBrandCategoryService brandCategoryService; + @Autowired + private IAttributeService attributeService; + @Autowired + private IAttributeGroupService groupService; + @Autowired + private IBrandService brandService; + /** * 查询品类信息 @@ -39,47 +46,100 @@ public class CategoryInfoServiceImpl extends ServiceImpl selectCategoryInfoList(CategoryInfo categoryInfo) - { - return categoryInfoMapper.selectCategoryInfoList(categoryInfo); + public List selectCategoryInfoList(CategoryInfoSaveModel categoryInfoSaveModel) { + //三大响应结果集 +// List categoryAttributes = CategoryAttribute.saveBuilder(categoryInfoSaveModel, SecurityUtils::getUsername); +// List categoryAttributeGroups = CategoryAttributeGroup.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername); +// List brandCategories = BrandCategory.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername); +// List categoryInfos = null; + + + List list = categoryInfoMapper.selectCategoryInfoList(CategoryInfo.saveBuilder(categoryInfoSaveModel)).stream().map(categoryInfo -> { + CategoryInfoSaveModel infoSaveModel = new CategoryInfoSaveModel(); + infoSaveModel.setId(categoryInfo.getId()); + List attrIds = categoryAttributeService.list(new LambdaQueryWrapper().eq(CategoryAttribute::getCategoryId, categoryInfo.getId())).stream().map(CategoryAttribute::getAttributeId).toList(); + List groupIds = categoryAttributeGroupService.list(new LambdaQueryWrapper().eq(CategoryAttributeGroup::getCategoryId, categoryInfo.getId())).stream().map(CategoryAttributeGroup::getAttributeGroupId).toList(); + List brandIds = brandCategoryService.list(new LambdaQueryWrapper().eq(BrandCategory::getCategoryId, categoryInfo.getId())).stream().map(BrandCategory::getBrandId).toList(); + CategoryResp build = CategoryResp.builder() + .id(categoryInfo.getId()) + .parentId(categoryInfo.getParentId()) + .name(categoryInfo.getName()) + .image(categoryInfo.getImage()) + .status(categoryInfo.getStatus()) + .brandList(brandIds.isEmpty() ? null : brandService.listByIds(brandIds)) + .checkAttributeList(attrIds.isEmpty() ? null : attributeService.listByIds(attrIds)) + .checkedAttributeGroupList(groupIds.isEmpty() ? null : groupService.listByIds(groupIds)) + .build(); + return build; + }).toList(); + + return list; } /** * 新增品类信息 * - * @param categoryInfo 品类信息 + * @param categoryInfoSaveModel 品类信息 * @return 结果 */ @Override - public int insertCategoryInfo(CategoryInfo categoryInfo) - { - categoryInfo.setCreateTime(DateUtils.getNowDate()); - return categoryInfoMapper.insertCategoryInfo(categoryInfo); + public int insertCategoryInfo(CategoryInfoSaveModel categoryInfoSaveModel) { + CategoryInfo categoryInfo = CategoryInfo.saveBuilder(categoryInfoSaveModel); + int i = categoryInfoMapper.insertCategoryInfo(categoryInfo); + categoryInfoSaveModel.setId(categoryInfo.getId()); + categoryAttributeService.saveBatch(CategoryAttribute.saveBuilder(categoryInfoSaveModel, SecurityUtils::getUsername)); + categoryAttributeGroupService.saveBatch(CategoryAttributeGroup.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername)); + brandCategoryService.saveBatch(BrandCategory.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername)); + return i; } /** * 修改品类信息 * - * @param categoryInfo 品类信息 + * @param categoryInfoSaveModel 品类信息 * @return 结果 */ @Override - public int updateCategoryInfo(CategoryInfo categoryInfo) - { - categoryInfo.setUpdateTime(DateUtils.getNowDate()); - return categoryInfoMapper.updateCategoryInfo(categoryInfo); + public boolean updateCategoryInfo(CategoryInfoSaveModel categoryInfoSaveModel) { + CategoryInfo categoryInfo = CategoryInfo.saveBuilder(categoryInfoSaveModel); + + boolean updated = this.update(new LambdaQueryWrapper().eq(CategoryInfo::getId, categoryInfo.getId())); +// LambdaQueryWrapper attributeWrapper = new LambdaQueryWrapper().eq(CategoryAttribute::getCategoryId,categoryInfoSaveModel.getId()); + //删除中间表数据 + categoryAttributeService.remove(new LambdaQueryWrapper() + .eq(CategoryAttribute::getCategoryId, categoryInfoSaveModel.getId()) + ); + //添加新数据 + categoryAttributeService.saveBatch(CategoryAttribute.saveBuilder(categoryInfoSaveModel, SecurityUtils::getUsername)); + //修改属性组中间表 +// LambdaQueryWrapper groupWrapper = new LambdaQueryWrapper(); + categoryAttributeGroupService.remove(new LambdaQueryWrapper() + .eq(CategoryAttributeGroup::getCategoryId, categoryInfoSaveModel.getId()) + ); + categoryAttributeGroupService.saveBatch( + CategoryAttributeGroup.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername) + ); +// LambdaQueryWrapper brandWrapper = new LambdaQueryWrapper(); + brandCategoryService.remove( + new LambdaQueryWrapper() + .eq(BrandCategory::getCategoryId, categoryInfoSaveModel.getId()) + ); + brandCategoryService.saveBatch( + BrandCategory.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername) + ); + + return updated; } /** @@ -89,8 +149,7 @@ public class CategoryInfoServiceImpl extends ServiceImpl().eq(CategoryAttribute::getCategoryId, id)); + categoryAttributeGroupService.remove(new LambdaQueryWrapper().eq(CategoryAttributeGroup::getCategoryId, id)); + brandCategoryService.remove(new LambdaQueryWrapper().eq(BrandCategory::getCategoryId, id)); return categoryInfoMapper.deleteCategoryInfoById(id); } + /** + * 品类数据添加 + * + * @param categoryInfoSaveModel + * @return + */ @Override public boolean save(CategoryInfoSaveModel categoryInfoSaveModel) { //通过品类信息构建体构建品类对象 @@ -117,17 +184,17 @@ public class CategoryInfoServiceImpl extends ServiceImpl checkedAttributeIds = categoryInfoSaveModel.getCheckedAttributeIds(); //判断已选属性集是否为空 - if (checkedAttributeIds != null && !checkedAttributeIds.isEmpty()){ + if (checkedAttributeIds != null && !checkedAttributeIds.isEmpty()) { categoryAttributeService.saveBatch( checkedAttributeIds.stream() - .map(attributeId -> CategoryAttribute.categoryBuilder(id,attributeId)).toList() + .map(attributeId -> CategoryAttribute.categoryBuilder(id, attributeId, SecurityUtils::getUsername)).toList() ); } - List attributeGroupIds = categoryInfoSaveModel.getAttributeGroupIds(); - if (attributeGroupIds != null && !attributeGroupIds.isEmpty()){ + List attributeGroupIds = categoryInfoSaveModel.getCheckedAttributeGroupIds(); + if (attributeGroupIds != null && !attributeGroupIds.isEmpty()) { categoryAttributeGroupService.saveBatch( attributeGroupIds.stream(). - map(groupId -> CategoryAttributeGroup.saveBuilder(id,groupId)).toList() + map(groupId -> CategoryAttributeGroup.saveBuilder(id, groupId, SecurityUtils::getUsername)).toList() ); } return save;