diff --git a/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryInfoUpdEditReq.java b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryInfoUpdEditReq.java new file mode 100644 index 0000000..0081e4d --- /dev/null +++ b/muyu-modules/muyu-product/muyu-product-common/src/main/java/com/muyu/product/domain/req/CategoryInfoUpdEditReq.java @@ -0,0 +1,67 @@ +package com.muyu.product.domain.req; + +import com.muyu.product.domain.AttributeInfo; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +/** + * @Author:尚志豪 + * @Package:com.muyu.product.domain.req + * @Project:cloud-server + * @name:CategoryInfoUpdEditReq + * @Date:2024/11/14 20:20 + * TODO + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@ApiModel(value = "CategoryInfoUpdEditReq", description = "品类修改信息") +public class CategoryInfoUpdEditReq { + private static final long serialVersionUID = 1L; + + /** 主键 */ + + @ApiModelProperty(name = "主键", value = "主键") + private Long id; + + /** 品类名称 */ + + @ApiModelProperty(name = "品类名称", value = "品类名称", required = true) + private String name; + + /** 图片 */ + + @ApiModelProperty(name = "图片", value = "图片", required = true) + private String image; + + /** 是否启用 */ + + @ApiModelProperty(name = "是否启用", value = "是否启用", required = true) + private String start; + + /** 介绍 */ + + @ApiModelProperty(name = "介绍", value = "介绍") + private String introduction; + + /** + * 商品属性组关联ID + */ + private List attributeGroupIdList; + /** + * 商品属性关联ID + */ + private List attributeIdList; + + /** + * 商品品牌组关联ID + */ + private List brandIdList; +} 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 55dbaef..553494d 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 @@ -9,10 +9,13 @@ import com.muyu.product.domain.AttributeGroup; import com.muyu.product.domain.AttributeInfo; import com.muyu.product.domain.BrandInfo; import com.muyu.product.domain.model.CategoryInfoSaveModel; +import com.muyu.product.domain.req.CategoryInfoUpdEditReq; import com.muyu.product.domain.resp.CategoryCommonElementResp; import com.muyu.product.domain.resp.CategoryParentCommonElementResp; import io.swagger.annotations.*; +import org.aspectj.weaver.Lint; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -112,9 +115,18 @@ public class CategoryInfoController extends BaseController { @Log(title = "品类信息", businessType = BusinessType.UPDATE) @PutMapping("/{id}") @ApiOperation("修改品类信息") - public Result edit(@PathVariable Long id, @RequestBody CategoryInfoEditReq categoryInfoEditReq) { - return toAjax(categoryInfoService.updateById(CategoryInfo.editBuild(id,categoryInfoEditReq))); - } + @Transactional + public Result edit(@PathVariable Long id, @RequestBody CategoryInfoSaveReq categoryInfoSaveReq) { + // 删除品类属性中间表 + categoryInfoService.asCategoryAttributeDel(id); + // 删除品类属性组中间表 + categoryInfoService.asCategoryAttributeGroupDel(id); + // 删除品类品牌中间表 + categoryInfoService.asCategoryBrandDel(id); + + return toAjax(categoryInfoService.save( + CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername) + )); } /** * 删除品类信息 @@ -124,8 +136,16 @@ public class CategoryInfoController extends BaseController { @DeleteMapping("/{ids}") @ApiOperation("删除品类信息") @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4") - public Result remove(@PathVariable List ids) { - return toAjax(categoryInfoService.removeBatchByIds(ids)); + public Result remove(@PathVariable Long ids) { + System.out.println("参数:"+ids); + // 判断是否存在下一级 + CategoryInfo categoryInfo = categoryInfoService.QueryBelowOneLevel(ids); + System.out.println("否存在下一级:"+categoryInfo); + // 判断没有下一删除 + if (null == categoryInfo){ + return toAjax(categoryInfoService.removeById(ids)); + } + return Result.error("含有子集不能进行删除"); } /** diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/mapper/CategoryInfoMapper.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/mapper/CategoryInfoMapper.java index 6ed8f75..e150784 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/mapper/CategoryInfoMapper.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/mapper/CategoryInfoMapper.java @@ -3,6 +3,7 @@ package com.muyu.product.mapper; import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.muyu.product.domain.CategoryInfo; +import org.apache.ibatis.annotations.Param; /** * 品类信息Mapper接口 @@ -12,4 +13,28 @@ import com.muyu.product.domain.CategoryInfo; */ public interface CategoryInfoMapper extends BaseMapper { + /** + * 删除品类属性中间表 + * @param id + */ + void asCategoryAttributeDel(@Param("id") Long id); + + /** + * 品类属性组中间表 + * @param id + */ + void asCategoryAttributeGroupDel(@Param("id") Long id); + + /** + * 品类品牌中间表 + * @param id + */ + void asCategoryBrandDel(@Param("id") Long id); + /** + * 判断是否存在下一级 + * @param ids + * @return + */ + CategoryInfo QueryBelowOneLevel(@Param("ids") Long ids); + } diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/CategoryInfoService.java b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/CategoryInfoService.java index 9b99d9d..f3630af 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/CategoryInfoService.java +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/java/com/muyu/product/service/CategoryInfoService.java @@ -69,4 +69,29 @@ public interface CategoryInfoService extends IService { CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId); public List getCommon (Long categoryId, IService iService, IService bsiService); + + /** + * 删除品类属性中间表 + * @param id + */ + void asCategoryAttributeDel(Long id); + + /** + * 删除品类属性组中间表 + * @param id + */ + void asCategoryAttributeGroupDel(Long id); + + /** + * 删除品类品牌中间表 + * @param id + */ + void asCategoryBrandDel(Long id); + + /** + * 判断是否存在下一级 + * @param ids + * @return + */ + CategoryInfo QueryBelowOneLevel(Long ids); } 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 ffd6b69..a21647e 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 @@ -11,6 +11,7 @@ import com.muyu.product.domain.AttributeGroup; import com.muyu.product.domain.AttributeInfo; import com.muyu.product.domain.model.AttributeGroupSaveModel; import com.muyu.product.domain.model.Ids; +import com.muyu.product.domain.req.AttributeGroupEditReq; import com.muyu.product.domain.req.AttributeGroupSaveReq; import com.muyu.product.domain.req.AttributeInfoEditReq; import com.muyu.product.domain.resp.AttributeGroupPageResp; @@ -140,6 +141,25 @@ public class AttributeGroupServiceImpl extends ServiceImpl attributeList = attributeGroupEditReq.getAttributeList(); +// for (AttributeInfo attributeInfo : attributeList) { +// +// attributeGroupMapper.insertbatch(id,attributeInfo.getId()); +// } +// attributeGroupMapper.insertbatch(id,attributeGroupEditReq.getAttributeList()); +// attributeList.forEach(attributeInfo -> { +// attributeGroupMapper.insertbatch(attributeInfo.getId(),attributeGroupEditReq); +// }); +// +// +// } + + /** * 获取属性组详细信息 */ 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 2d6b4d5..0696dbd 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 @@ -39,6 +39,8 @@ public class CategoryInfoServiceImpl extends ServiceImpl List list = ruleAttrInfos.stream().map(RuleAttrInfo::getAttrValue).toList(); ruleAttrAddModel.setValueList(list); arrayList.add(ruleAttrAddModel); + RuleInfoAddModel resp = new RuleInfoAddModel(); resp.setId(byId.getId()); resp.setName(byId.getName()); diff --git a/muyu-modules/muyu-product/muyu-product-server/src/main/resources/mapper/product/CategoryInfoMapper.xml b/muyu-modules/muyu-product/muyu-product-server/src/main/resources/mapper/product/CategoryInfoMapper.xml index 99be65b..e8cd625 100644 --- a/muyu-modules/muyu-product/muyu-product-server/src/main/resources/mapper/product/CategoryInfoMapper.xml +++ b/muyu-modules/muyu-product/muyu-product-server/src/main/resources/mapper/product/CategoryInfoMapper.xml @@ -21,4 +21,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select id, name, image, parent_id, start, introduction, remark, create_by, create_time, update_by, update_time from category_info + + + delete from as_category_attribute where category_id = #{id} + + + + delete from as_category_attribute_group where category_id = #{id} + + + + delete from as_category_brand where category_id = #{id} + + +