master
meng 2024-11-15 11:55:05 +08:00
parent 0a68d33206
commit 0566acaf4d
9 changed files with 154 additions and 22 deletions

View File

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.base.CategoryBase; import com.muyu.product.domain.base.CategoryBase;
import com.muyu.product.domain.model.RuleAttrAddModel;
import com.muyu.product.domain.req.CategoryInfoEditReq;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -13,6 +15,9 @@ import io.swagger.annotations.*;
import com.muyu.common.core.annotation.Excel; import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.common.core.web.domain.BaseEntity;
import java.util.Date;
import java.util.function.Supplier;
/** /**
* as_category_attribute * as_category_attribute
* *
@ -53,6 +58,7 @@ public class AsCategoryAttribute extends BaseEntity implements CategoryBase {
.build(); .build();
} }
@Override @Override
public Long getBaseId () { public Long getBaseId () {
return this.attributeId; return this.attributeId;

View File

@ -4,6 +4,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.product.domain.AttributeInfo;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -40,5 +41,5 @@ public class AttributeGroupEditReq extends BaseEntity {
*/ */
@ApiModelProperty(name = "属性ID集合", value = "属性ID集合", required = true) @ApiModelProperty(name = "属性ID集合", value = "属性ID集合", required = true)
private List<Long> attributeIdList; private List<AttributeInfo> attributeIdList;
} }

View File

@ -1,5 +1,8 @@
package com.muyu.product.domain.req; package com.muyu.product.domain.req;
import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.BrandInfo;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -43,14 +46,14 @@ public class CategoryInfoEditReq extends TreeEntity {
/** /**
* ID * ID
*/ */
private List<Long> attributeGroupIdList; private List<AttributeGroup> attributeGroupIdList;
/** /**
* ID * ID
*/ */
private List<Long> attributeIdList; private List<AttributeInfo> attributeIdList;
/** /**
* ID * ID
*/ */
private List<Long> brandIdList; private List<BrandInfo> brandIdList;
} }

View File

@ -77,8 +77,9 @@ public class CategoryInfoController extends BaseController {
@RequiresPermissions("product:category:query") @RequiresPermissions("product:category:query")
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class) @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
public Result<CategoryInfo> getInfo(@PathVariable("id") Long id) { public Result<CategoryParentCommonElementResp> getInfo(@PathVariable("id") Long id) {
return Result.success(categoryInfoService.getById(id)); CategoryParentCommonElementResp categoryById = categoryInfoService.getCategoryById(id);
return Result.success(categoryById);
} }
/** /**
@ -122,11 +123,11 @@ public class CategoryInfoController extends BaseController {
*/ */
@RequiresPermissions("product:category:remove") @RequiresPermissions("product:category:remove")
@Log(title = "品类信息", businessType = BusinessType.DELETE) @Log(title = "品类信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{id}")
@ApiOperation("删除品类信息") @ApiOperation("删除品类信息")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4") @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
public Result<String> remove(@PathVariable List<Long> ids) { public Result remove(@PathVariable Long id) {
return toAjax(categoryInfoService.removeBatchByIds(ids)); return toAjax(categoryInfoService.removeCateByIds(id));
} }
/** /**

View File

@ -2,7 +2,9 @@ package com.muyu.product.mapper;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.product.domain.CategoryInfo; import com.muyu.product.domain.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/** /**
* Mapper * Mapper
@ -10,6 +12,26 @@ import com.muyu.product.domain.CategoryInfo;
* @author DongZeLiang * @author DongZeLiang
* @date 2024-02-27 * @date 2024-02-27
*/ */
@Mapper
public interface CategoryInfoMapper extends BaseMapper<CategoryInfo> { public interface CategoryInfoMapper extends BaseMapper<CategoryInfo> {
/**
*
* @param parentId
* @return
*/
List<CategoryInfo> selByParentId(@Param("parentId") Long parentId);
/**
*
* @param id
* @return
*/
List<ProjectInfo> selectByProjectInfo(@Param("id") Long id);
//品类属性
AttributeInfo selectCateById(@Param("aLong") Long aLong);
//品类属性组
AttributeGroup selectGroup(@Param("aLong") Long aLong);
//品牌信息
BrandInfo seleteBrand(@Param("aLong") Long aLong);
} }

View File

@ -79,4 +79,13 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
CategoryParentCommonElementResp getCategoryById(Long id); CategoryParentCommonElementResp getCategoryById(Long id);
void updateCategoryById(Long id, CategoryInfoEditReq categoryInfoEditReq); void updateCategoryById(Long id, CategoryInfoEditReq categoryInfoEditReq);
/**
*
*
* @param id
* @return
*/
int removeCateByIds(Long id);
} }

View File

@ -144,6 +144,8 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
//先删除中间表 //先删除中间表
attributeGroupMapper.deleteAsAttributeGroup(id); attributeGroupMapper.deleteAsAttributeGroup(id);
//添加中间表 //添加中间表
attributeGroupMapper.addAsAttributeGroup(id,attributeGroupEditReq.getAttributeIdList()); List<AttributeInfo> list = attributeGroupEditReq.getAttributeIdList();
List<Long> longs = list.stream().map(AttributeInfo::getId).toList();
attributeGroupMapper.addAsAttributeGroup(id,longs);
} }
} }

View File

@ -58,7 +58,8 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
@Autowired @Autowired
private AttributeGroupService attributeGroupService; private AttributeGroupService attributeGroupService;
@Autowired
private CategoryInfoMapper categoryInfoMapper;
/** /**
* *
* *
@ -284,29 +285,41 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryAttribute::getCategoryId,id); queryWrapper.eq(AsCategoryAttribute::getCategoryId,id);
List<AsCategoryAttribute> attributeList = asCategoryAttributeService.list(queryWrapper); List<AsCategoryAttribute> attributeList = asCategoryAttributeService.list(queryWrapper);
List<Long> longs = attributeList.stream().map(AsCategoryAttribute::getCategoryId).toList(); List<Long> longs = attributeList.stream().map(AsCategoryAttribute::getAttributeId).toList();
List<AttributeInfo> byIds = attributeInfoService.listByIds(longs); ArrayList<AttributeInfo> arrayList = new ArrayList<>();
for (Long aLong : longs) {
AttributeInfo attribute=categoryInfoMapper.selectCateById(aLong);
arrayList.add(attribute);
}
//品类属性组中间表 //品类属性组中间表
LambdaQueryWrapper<AsCategoryAttributeGroup> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AsCategoryAttributeGroup> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AsCategoryAttributeGroup::getCategoryId,id); wrapper.eq(AsCategoryAttributeGroup::getCategoryId,id);
List<AsCategoryAttributeGroup> list = asCategoryAttributeGroupService.list(wrapper); List<AsCategoryAttributeGroup> list = asCategoryAttributeGroupService.list(wrapper);
List<Long> toList = list.stream().map(AsCategoryAttributeGroup::getCategoryId).toList(); List<Long> toList = list.stream().map(AsCategoryAttributeGroup::getAttributeGroupId).toList();
List<AttributeGroup> attributeGroups = attributeGroupService.listByIds(toList); ArrayList<AttributeGroup> groupArrayList = new ArrayList<>();
for (Long aLong : toList) {
AttributeGroup attributeGroup= categoryInfoMapper.selectGroup(aLong);
groupArrayList.add(attributeGroup);
}
//品类品牌中间表 //品类品牌中间表
LambdaQueryWrapper<AsCategoryBrand> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AsCategoryBrand> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(AsCategoryBrand::getCategoryId,id); lambdaQueryWrapper.eq(AsCategoryBrand::getCategoryId,id);
List<AsCategoryBrand> asCategoryBrands = asCategoryBrandService.list(lambdaQueryWrapper); List<AsCategoryBrand> asCategoryBrands = asCategoryBrandService.list(lambdaQueryWrapper);
List<Long> longList = asCategoryBrands.stream().map(AsCategoryBrand::getCategoryId).toList(); List<Long> longList = asCategoryBrands.stream().map(AsCategoryBrand::getBrandId).toList();
List<BrandInfo> brandInfos = brandInfoService.listByIds(longList); ArrayList<BrandInfo> brandArrayList = new ArrayList<>();
for (Long aLong : longList) {
BrandInfo brands= categoryInfoMapper.seleteBrand(aLong);
brandArrayList.add(brands);
}
return CategoryParentCommonElementResp.builder() return CategoryParentCommonElementResp.builder()
.id(info.getId()) .id(info.getId())
.name(info.getName()) .name(info.getName())
.image(info.getImage()) .image(info.getImage())
.start(info.getStart()) .start(info.getStart())
.introduction(info.getIntroduction()) .introduction(info.getIntroduction())
.attributeInfoList(byIds) .attributeInfoList(arrayList)
.attributeGroupList(attributeGroups) .attributeGroupList(groupArrayList)
.brandInfoList(brandInfos).build(); .brandInfoList(brandArrayList).build();
} }
/** /**
@ -316,7 +329,66 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
*/ */
@Override @Override
public void updateCategoryById(Long id, CategoryInfoEditReq categoryInfoEditReq) { public void updateCategoryById(Long id, CategoryInfoEditReq categoryInfoEditReq) {
//修改 //修改category_info品类修改
boolean b = this.updateById(CategoryInfo.editBuild(id, categoryInfoEditReq));
if (b){
updateCateInfo(id,categoryInfoEditReq);
updateCateGroup(id,categoryInfoEditReq);
updateCateBrand(id,categoryInfoEditReq);
}
}
/**
*
* @param id
* @return
*/
@Override
public int removeCateByIds(Long id) {
CategoryInfo categoryInfo = categoryInfoMapper.selectById(id);
List<CategoryInfo> categoryInfos=categoryInfoMapper.selByParentId(categoryInfo.getId());
if (categoryInfos.size()!=0){
throw new SecurityException("不能删除还有子集");
}
List<ProjectInfo> projectInfos=categoryInfoMapper.selectByProjectInfo(categoryInfo.getParentId());
if (projectInfos.size()!=0){
throw new SecurityException("不能删除与商品关联");
}
int res=categoryInfoMapper.deleteById(id);
return res;
}
private void updateCateBrand(Long id, CategoryInfoEditReq categoryInfoEditReq) {
//品类品牌中间表as_category_brand
LambdaQueryWrapper<AsCategoryBrand> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(AsCategoryBrand::getCategoryId,id);
asCategoryBrandService.remove(lambdaQueryWrapper);
List<Long> brandIdList = categoryInfoEditReq.getBrandIdList().stream().map(BrandInfo::getId).toList();
asCategoryBrandService.saveBatch(
brandIdList.stream().map(brandId ->AsCategoryBrand.categoryBuild(id,brandId)).toList()
);
}
private void updateCateGroup(Long id, CategoryInfoEditReq categoryInfoEditReq) {
//删除品类属性组中间表 as_category_attribute_group
LambdaQueryWrapper<AsCategoryAttributeGroup> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AsCategoryAttributeGroup::getCategoryId,id);
asCategoryAttributeGroupService.remove(wrapper);
List<Long> attributeGroupIdList = categoryInfoEditReq.getAttributeGroupIdList().stream().map(AttributeGroup::getId).toList();
asCategoryAttributeGroupService.saveBatch(
attributeGroupIdList.stream().map(aLong -> AsCategoryAttributeGroup.categoryBuild(id,aLong)).toList()
);
}
private void updateCateInfo(Long id, CategoryInfoEditReq categoryInfoEditReq) {
//删除品类属性中间表
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsCategoryAttribute::getCategoryId,id);
asCategoryAttributeService.remove(queryWrapper);
List<Long> longList = categoryInfoEditReq.getAttributeIdList().stream().map(AttributeInfo::getId).toList();
asCategoryAttributeService.saveBatch(
longList.stream().map(aLong -> AsCategoryAttribute.categoryBuild(id,aLong)).toList()
);
} }
/** /**

View File

@ -21,4 +21,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectCategoryInfoVo"> <sql id="selectCategoryInfoVo">
select id, name, image, parent_id, start, introduction, remark, create_by, create_time, update_by, update_time from category_info select id, name, image, parent_id, start, introduction, remark, create_by, create_time, update_by, update_time from category_info
</sql> </sql>
<select id="selByParentId" resultType="com.muyu.product.domain.CategoryInfo">
select * from category_info where category_info.parent_id=#{parentId}
</select>
<select id="selectByProjectInfo" resultType="com.muyu.product.domain.ProjectInfo">
select * from project_info where project_info.parent_type=#{id}
</select>
<select id="selectCateById" resultType="com.muyu.product.domain.AttributeInfo">
select *from attribute_info where attribute_info.id=#{aLong}
</select>
<select id="selectGroup" resultType="com.muyu.product.domain.AttributeGroup">
select * from attribute_group where attribute_group.id=#{aLong}
</select>
<select id="seleteBrand" resultType="com.muyu.product.domain.BrandInfo">
select *from brand_info where brand_info.id=#{aLong}
</select>
</mapper> </mapper>