master
parent
0a68d33206
commit
0566acaf4d
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.product.domain.base.CategoryBase;
|
||||
import com.muyu.product.domain.model.RuleAttrAddModel;
|
||||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -13,6 +15,9 @@ import io.swagger.annotations.*;
|
|||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 品类属性中间对象 as_category_attribute
|
||||
*
|
||||
|
@ -53,6 +58,7 @@ public class AsCategoryAttribute extends BaseEntity implements CategoryBase {
|
|||
.build();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Long getBaseId () {
|
||||
return this.attributeId;
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.muyu.product.domain.AttributeInfo;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -40,5 +41,5 @@ public class AttributeGroupEditReq extends BaseEntity {
|
|||
*/
|
||||
@ApiModelProperty(name = "属性ID集合", value = "属性ID集合", required = true)
|
||||
|
||||
private List<Long> attributeIdList;
|
||||
private List<AttributeInfo> attributeIdList;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -43,14 +46,14 @@ public class CategoryInfoEditReq extends TreeEntity {
|
|||
/**
|
||||
* 商品属性组关联ID
|
||||
*/
|
||||
private List<Long> attributeGroupIdList;
|
||||
private List<AttributeGroup> attributeGroupIdList;
|
||||
/**
|
||||
* 商品属性关联ID
|
||||
*/
|
||||
private List<Long> attributeIdList;
|
||||
private List<AttributeInfo> attributeIdList;
|
||||
|
||||
/**
|
||||
* 商品品牌组关联ID
|
||||
*/
|
||||
private List<Long> brandIdList;
|
||||
private List<BrandInfo> brandIdList;
|
||||
}
|
||||
|
|
|
@ -77,8 +77,9 @@ public class CategoryInfoController extends BaseController {
|
|||
@RequiresPermissions("product:category:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<CategoryInfo> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(categoryInfoService.getById(id));
|
||||
public Result<CategoryParentCommonElementResp> getInfo(@PathVariable("id") Long id) {
|
||||
CategoryParentCommonElementResp categoryById = categoryInfoService.getCategoryById(id);
|
||||
return Result.success(categoryById);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,11 +123,11 @@ public class CategoryInfoController extends BaseController {
|
|||
*/
|
||||
@RequiresPermissions("product:category:remove")
|
||||
@Log(title = "品类信息", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@DeleteMapping("/{id}")
|
||||
@ApiOperation("删除品类信息")
|
||||
@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) {
|
||||
return toAjax(categoryInfoService.removeBatchByIds(ids));
|
||||
public Result remove(@PathVariable Long id) {
|
||||
return toAjax(categoryInfoService.removeCateByIds(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.muyu.product.mapper;
|
|||
|
||||
import java.util.List;
|
||||
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接口
|
||||
|
@ -10,6 +12,26 @@ import com.muyu.product.domain.CategoryInfo;
|
|||
* @author DongZeLiang
|
||||
* @date 2024-02-27
|
||||
*/
|
||||
@Mapper
|
||||
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);
|
||||
|
||||
}
|
||||
|
|
|
@ -79,4 +79,13 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
|
|||
CategoryParentCommonElementResp getCategoryById(Long id);
|
||||
|
||||
void updateCategoryById(Long id, CategoryInfoEditReq categoryInfoEditReq);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
int removeCateByIds(Long id);
|
||||
|
||||
}
|
||||
|
|
|
@ -144,6 +144,8 @@ public class AttributeGroupServiceImpl extends ServiceImpl<AttributeGroupMapper,
|
|||
//先删除中间表
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,8 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
|
||||
@Autowired
|
||||
private AttributeGroupService attributeGroupService;
|
||||
|
||||
@Autowired
|
||||
private CategoryInfoMapper categoryInfoMapper;
|
||||
/**
|
||||
* 查询品类信息列表
|
||||
*
|
||||
|
@ -284,29 +285,41 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AsCategoryAttribute::getCategoryId,id);
|
||||
List<AsCategoryAttribute> attributeList = asCategoryAttributeService.list(queryWrapper);
|
||||
List<Long> longs = attributeList.stream().map(AsCategoryAttribute::getCategoryId).toList();
|
||||
List<AttributeInfo> byIds = attributeInfoService.listByIds(longs);
|
||||
List<Long> longs = attributeList.stream().map(AsCategoryAttribute::getAttributeId).toList();
|
||||
ArrayList<AttributeInfo> arrayList = new ArrayList<>();
|
||||
for (Long aLong : longs) {
|
||||
AttributeInfo attribute=categoryInfoMapper.selectCateById(aLong);
|
||||
arrayList.add(attribute);
|
||||
}
|
||||
//品类属性组中间表
|
||||
LambdaQueryWrapper<AsCategoryAttributeGroup> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AsCategoryAttributeGroup::getCategoryId,id);
|
||||
List<AsCategoryAttributeGroup> list = asCategoryAttributeGroupService.list(wrapper);
|
||||
List<Long> toList = list.stream().map(AsCategoryAttributeGroup::getCategoryId).toList();
|
||||
List<AttributeGroup> attributeGroups = attributeGroupService.listByIds(toList);
|
||||
List<Long> toList = list.stream().map(AsCategoryAttributeGroup::getAttributeGroupId).toList();
|
||||
ArrayList<AttributeGroup> groupArrayList = new ArrayList<>();
|
||||
for (Long aLong : toList) {
|
||||
AttributeGroup attributeGroup= categoryInfoMapper.selectGroup(aLong);
|
||||
groupArrayList.add(attributeGroup);
|
||||
}
|
||||
//品类品牌中间表
|
||||
LambdaQueryWrapper<AsCategoryBrand> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(AsCategoryBrand::getCategoryId,id);
|
||||
List<AsCategoryBrand> asCategoryBrands = asCategoryBrandService.list(lambdaQueryWrapper);
|
||||
List<Long> longList = asCategoryBrands.stream().map(AsCategoryBrand::getCategoryId).toList();
|
||||
List<BrandInfo> brandInfos = brandInfoService.listByIds(longList);
|
||||
List<Long> longList = asCategoryBrands.stream().map(AsCategoryBrand::getBrandId).toList();
|
||||
ArrayList<BrandInfo> brandArrayList = new ArrayList<>();
|
||||
for (Long aLong : longList) {
|
||||
BrandInfo brands= categoryInfoMapper.seleteBrand(aLong);
|
||||
brandArrayList.add(brands);
|
||||
}
|
||||
return CategoryParentCommonElementResp.builder()
|
||||
.id(info.getId())
|
||||
.name(info.getName())
|
||||
.image(info.getImage())
|
||||
.start(info.getStart())
|
||||
.introduction(info.getIntroduction())
|
||||
.attributeInfoList(byIds)
|
||||
.attributeGroupList(attributeGroups)
|
||||
.brandInfoList(brandInfos).build();
|
||||
.attributeInfoList(arrayList)
|
||||
.attributeGroupList(groupArrayList)
|
||||
.brandInfoList(brandArrayList).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -316,7 +329,66 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
*/
|
||||
@Override
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,4 +21,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<sql id="selectCategoryInfoVo">
|
||||
select id, name, image, parent_id, start, introduction, remark, create_by, create_time, update_by, update_time from category_info
|
||||
</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>
|
||||
|
|
Loading…
Reference in New Issue