品类组件响应,属性组bug修改

day-06
Saisai Liu 2024-03-14 21:22:49 +08:00
parent ababc20a27
commit 007aa4c276
16 changed files with 389 additions and 119 deletions

View File

@ -38,8 +38,6 @@ public class AttributeGroup extends BaseEntity
private String name;
private List<Attribute> attributeList;
private List<Long> checkedAttributeIds;
private List<Long> asAttributeIds;
/** 状态 */
@Excel(name = "状态")
@ -76,11 +74,4 @@ public class AttributeGroup extends BaseEntity
.build();
}
public void setCheckedAttributeIds(List<Long> checkedAttributeIds) {
this.checkedAttributeIds = checkedAttributeIds;
}
public List<Long> getCheckedAttributeIds() {
return checkedAttributeIds;
}
}

View File

@ -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<BrandCategory> saveBuilderList(CategoryInfoSaveModel categoryReq, Supplier<String> getUsername) {
return categoryReq.getCheckedBrandIds().stream().map(
brandId -> BrandCategory.saveBuilder(categoryReq.getId(),brandId,getUsername)
).toList();
}
private static BrandCategory saveBuilder(Long categoryId, Long brandId, Supplier<String> getUsername) {
return BrandCategory.builder()
.brandId(brandId)
.categoryId(categoryId)
.createBy(getUsername.get())
.createTime(new Date())
.build();
}
}

View File

@ -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<String> username) {
return CategoryAttribute.builder()
.categoryId(id)
.categoryId(categoryId)
.attributeId(attributeId)
.createBy(username.get())
.createTime(new Date())
.build();
}
public static List<CategoryAttribute> saveBuilder(CategoryInfoSaveModel categoryReq, Supplier<String> username) {
return categoryReq.getCheckedAttributeIds().stream().map(
attributeId -> categoryBuilder(categoryReq.getId(),attributeId,username)
).toList();
}
}

View File

@ -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<String> username) {
return CategoryAttributeGroup.builder()
.attributeGroupId(groupId)
.categoryId(id)
.createBy(username.get())
.createTime(new Date())
.build();
}
public static List<CategoryAttributeGroup> saveBuilderList(CategoryInfoSaveModel categoryReq, Supplier<String> username) {
return categoryReq.getCheckedAttributeGroupIds().stream().map(
groupId -> saveBuilder(categoryReq.getId(), groupId, username)
).toList();
}
}

View File

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

View File

@ -42,11 +42,19 @@ public class CategoryInfoSaveModel extends TreeEntity {
private String createBy;
private Date createTime;
/**
*
*/
private List<Long> checkedAttributeGroupIds;
/**
*
*/
private List<Long> checkedAttributeIds;
/**
*
*/
private List<Long> checkedBrandIds;
private List<Long> attributeGroupIds;
private List<Long> brandIds;
/**
*
@ -54,13 +62,13 @@ public class CategoryInfoSaveModel extends TreeEntity {
public static CategoryInfoSaveModel saveBuilder(CategoryReq req, Supplier<String> 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();

View File

@ -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<Long> checkedAttributeGroupIds;
/**
*
*/
private List<Long> checkedAttributeIds;
private List<Long> attributeGroupIds;
private List<Long> brandIds;
/**
*
*/
private List<Long> checkedBrandIds;
}

View File

@ -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<Attribute> attributeList;
private List<Long> 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<Attribute> attributes) {
return AttributeGroupResp.builder()
.name(attributeGroup1.getName())
.states(attributeGroup1.getStates())
.id(attributeGroup1.getId())
.attributeList(attributes)
.build();
}
}

View File

@ -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<Attribute> checkAttributeList;
private List<AttributeGroup> checkedAttributeGroupList;
private List<Brand> 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<String> 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<String> username){
return CategoryResp.builder()
.name(categoryReq.getName())
.image(categoryReq.getImage())
.status(categoryReq.getStatus())
.updateBy(SecurityUtils.getUsername())
.updateBy(username.get())
.updateTime(new Date())
.build();
}

View File

@ -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"

View File

@ -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<TableDataInfo<AttributeGroup>> list(AttributeGroup attributeGroup)
public Result<TableDataInfo<AttributeGroupResp>> list(AttributeGroup attributeGroup)
{
startPage();
List<AttributeGroup> list = attributeGroupService.selectAttributeGroupList(attributeGroup);
List<AttributeGroupResp> 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<AttributeGroup> list = attributeGroupService.selectAttributeGroupList(attributeGroup);
ExcelUtil<AttributeGroup> util = new ExcelUtil<AttributeGroup>(AttributeGroup.class);
List<AttributeGroupResp> list = attributeGroupService.selectAttributeGroupList(attributeGroup);
ExcelUtil<AttributeGroupResp> util = new ExcelUtil<AttributeGroupResp>(AttributeGroupResp.class);
util.exportExcel(response, list, "属性组数据");
}

View File

@ -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<CategoryInfo> list = categoryInfoService.selectCategoryInfoList(categoryInfo);
List<CategoryResp> 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<CategoryInfo> list = categoryInfoService.selectCategoryInfoList(categoryInfo);
ExcelUtil<CategoryInfo> util = new ExcelUtil<CategoryInfo>(CategoryInfo.class);
List<CategoryResp> list = categoryInfoService.selectCategoryInfoList(categoryInfoSaveModel);
ExcelUtil<CategoryResp> util = new ExcelUtil<CategoryResp>(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));
}
/**

View File

@ -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<AttributeGroup>
* @param attributeGroup
* @return
*/
List<AttributeGroup> selectAttributeGroupList(AttributeGroup attributeGroup);
List<AttributeGroupResp> selectAttributeGroupList(AttributeGroup attributeGroup);
/**
*

View File

@ -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<CategoryInfo>
/**
*
*
* @param categoryInfo
* @param categoryInfoSaveModel
* @return
*/
List<CategoryInfo> selectCategoryInfoList(CategoryInfo categoryInfo);
List<CategoryResp> 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);
/**
*

View File

@ -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<AttributeGroupMapper,
asAttributeGroups.forEach(asAttributeGroup -> 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<AttributeGroupMapper,
* @return
*/
@Override
public List<AttributeGroup> selectAttributeGroupList(AttributeGroup attributeGroup) {
public List<AttributeGroupResp> selectAttributeGroupList(AttributeGroup attributeGroup) {
List<AttributeGroup> attributeGroups = attributeGroupMapper.selectAttributeGroupList(attributeGroup);
attributeGroups.forEach(this::setAttributeList);
return attributeGroups;
List<AttributeGroupResp> list = attributeGroups.stream().map(group ->
AttributeGroupResp.saveBuilder(group,attributeService.listByIds(asAttributeGroupService.list(
new LambdaQueryWrapper<AsAttributeGroup>()
.eq(AsAttributeGroup::getGroupId, group.getId()))
.stream().map(AsAttributeGroup::getAttributeId).toList()))
).toList();
return list;
}
/**
@ -121,7 +128,11 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
.map(attributeId -> AsAttributeGroup
.saveBuilder(attributeGroup.getId(), attributeId))
.toList();
asAttributeGroupService.removeBatchByIds(attributeGroup.getAsAttributeIds());
// attributeGroup.getAsAttributeIds()
asAttributeGroupService.removeBatchByIds(asAttributeGroupService.list(new LambdaQueryWrapper<AsAttributeGroup>()
.eq(AsAttributeGroup::getGroupId,attributeGroup.getId()))
.stream().map(AsAttributeGroup::getId).toList()
);
asAttributeGroupService.saveBatch(asAttributeGroups);
// asAttributeGroups.forEach(asAttributeGroup -> asAttributeGroupService.updateAsAttributeGroup(asAttributeGroup));
return asAttributeGroups.size();

View File

@ -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<CategoryInfoMapper,CategoryInfo> implements ICategoryInfoService
{
public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, CategoryInfo> 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<CategoryInfoMapper,Cate
* @return
*/
@Override
public CategoryInfo selectCategoryInfoById(Long id)
{
public CategoryInfo selectCategoryInfoById(Long id) {
return categoryInfoMapper.selectCategoryInfoById(id);
}
/**
*
*
* @param categoryInfo
* @param categoryInfoSaveModel
* @return
*/
@Override
public List<CategoryInfo> selectCategoryInfoList(CategoryInfo categoryInfo)
{
return categoryInfoMapper.selectCategoryInfoList(categoryInfo);
public List<CategoryResp> selectCategoryInfoList(CategoryInfoSaveModel categoryInfoSaveModel) {
//三大响应结果集
// List<CategoryAttribute> categoryAttributes = CategoryAttribute.saveBuilder(categoryInfoSaveModel, SecurityUtils::getUsername);
// List<CategoryAttributeGroup> categoryAttributeGroups = CategoryAttributeGroup.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername);
// List<BrandCategory> brandCategories = BrandCategory.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername);
// List<CategoryInfo> categoryInfos = null;
List<CategoryResp> list = categoryInfoMapper.selectCategoryInfoList(CategoryInfo.saveBuilder(categoryInfoSaveModel)).stream().map(categoryInfo -> {
CategoryInfoSaveModel infoSaveModel = new CategoryInfoSaveModel();
infoSaveModel.setId(categoryInfo.getId());
List<Long> attrIds = categoryAttributeService.list(new LambdaQueryWrapper<CategoryAttribute>().eq(CategoryAttribute::getCategoryId, categoryInfo.getId())).stream().map(CategoryAttribute::getAttributeId).toList();
List<Long> groupIds = categoryAttributeGroupService.list(new LambdaQueryWrapper<CategoryAttributeGroup>().eq(CategoryAttributeGroup::getCategoryId, categoryInfo.getId())).stream().map(CategoryAttributeGroup::getAttributeGroupId).toList();
List<Long> brandIds = brandCategoryService.list(new LambdaQueryWrapper<BrandCategory>().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<CategoryInfo>().eq(CategoryInfo::getId, categoryInfo.getId()));
// LambdaQueryWrapper<CategoryAttribute> attributeWrapper = new LambdaQueryWrapper<CategoryAttribute>().eq(CategoryAttribute::getCategoryId,categoryInfoSaveModel.getId());
//删除中间表数据
categoryAttributeService.remove(new LambdaQueryWrapper<CategoryAttribute>()
.eq(CategoryAttribute::getCategoryId, categoryInfoSaveModel.getId())
);
//添加新数据
categoryAttributeService.saveBatch(CategoryAttribute.saveBuilder(categoryInfoSaveModel, SecurityUtils::getUsername));
//修改属性组中间表
// LambdaQueryWrapper<CategoryAttributeGroup> groupWrapper = new LambdaQueryWrapper<CategoryAttributeGroup>();
categoryAttributeGroupService.remove(new LambdaQueryWrapper<CategoryAttributeGroup>()
.eq(CategoryAttributeGroup::getCategoryId, categoryInfoSaveModel.getId())
);
categoryAttributeGroupService.saveBatch(
CategoryAttributeGroup.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername)
);
// LambdaQueryWrapper<BrandCategory> brandWrapper = new LambdaQueryWrapper<BrandCategory>();
brandCategoryService.remove(
new LambdaQueryWrapper<BrandCategory>()
.eq(BrandCategory::getCategoryId, categoryInfoSaveModel.getId())
);
brandCategoryService.saveBatch(
BrandCategory.saveBuilderList(categoryInfoSaveModel, SecurityUtils::getUsername)
);
return updated;
}
/**
@ -89,8 +149,7 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper,Cate
* @return
*/
@Override
public int deleteCategoryInfoByIds(Long[] ids)
{
public int deleteCategoryInfoByIds(Long[] ids) {
return categoryInfoMapper.deleteCategoryInfoByIds(ids);
}
@ -101,11 +160,19 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper,Cate
* @return
*/
@Override
public int deleteCategoryInfoById(Long id)
{
public int deleteCategoryInfoById(Long id) {
categoryAttributeService.remove(new LambdaQueryWrapper<CategoryAttribute>().eq(CategoryAttribute::getCategoryId, id));
categoryAttributeGroupService.remove(new LambdaQueryWrapper<CategoryAttributeGroup>().eq(CategoryAttributeGroup::getCategoryId, id));
brandCategoryService.remove(new LambdaQueryWrapper<BrandCategory>().eq(BrandCategory::getCategoryId, id));
return categoryInfoMapper.deleteCategoryInfoById(id);
}
/**
*
*
* @param categoryInfoSaveModel
* @return
*/
@Override
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel) {
//通过品类信息构建体构建品类对象
@ -120,14 +187,14 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper,Cate
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<Long> attributeGroupIds = categoryInfoSaveModel.getAttributeGroupIds();
List<Long> 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;