From 862b7d542749816c63b74dc1964748b97637d636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98mahaoran=E2=80=99?= <2570310046@qq.com> Date: Sun, 17 Nov 2024 20:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=93=81=E7=B1=BB=E4=BF=A1=E6=81=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CategoryInfoController.java | 4 +- .../product/mapper/CategoryInfoMapper.java | 13 ---- .../service/impl/CategoryInfoServiceImpl.java | 61 +++++++++++++------ .../mapper/product/CategoryInfoMapper.xml | 26 -------- 4 files changed, 44 insertions(+), 60 deletions(-) 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 d00afb8..1cc780e 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 @@ -78,7 +78,6 @@ public class CategoryInfoController extends BaseController { @GetMapping(value = "/{id}") @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class) public Result getInfo(@PathVariable("id") Long id) { - return Result.success(categoryInfoService.getById(id)); } @@ -90,7 +89,8 @@ public class CategoryInfoController extends BaseController { @GetMapping(value = "/getTemplateAttribute/{cateGoryId}") @ApiImplicitParam(name = "cateGoryId", value = "cateGoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class) public Result getTemplateAttributeByCateGoryId(@PathVariable("cateGoryId") Long cateGoryId) { - return Result.success(categoryInfoService.getTemplateAttributeByCateGoryId(cateGoryId)); + CategoryCommonElementResp templateAttributeByCateGoryId = categoryInfoService.getTemplateAttributeByCateGoryId(cateGoryId); + return Result.success(templateAttributeByCateGoryId); } /** 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 0483fba..9d88db9 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 @@ -15,19 +15,6 @@ import org.apache.ibatis.annotations.Param; @Mapper public interface CategoryInfoMapper extends BaseMapper { - void delAttributeGroupId(Long id); - - void delAttributeIdList(Long id); - - void delArandIdList(Long id); - -// void addAttributeGroupId(@Param("id") Long id, @Param("attributeGroupId") Long attributeGroupId); - void attributeGroupIdList(@Param("id") Long id, @Param("aLong") Long aLong); - - void addAttributeIdList(@Param("id") Long id, @Param("attributeId") Long attributeId); - - void addArandIdList(@Param("id") Long id, @Param("brandId") Long brandId); - Integer selectByPid(String ids); Integer selectAsCategoryBrand(String ids); 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 cb20013..f772429 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 @@ -20,11 +20,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.function.Function; import java.util.stream.Stream; @@ -280,24 +278,49 @@ public class CategoryInfoServiceImpl extends ServiceImpl attributeIdList = categoryInfoEditReq.getAttributeIdList(); - for (Long aLong : attributeIdList) { - categoryInfoMapper.addAttributeIdList(id,aLong); + if(!CollectionUtils.isEmpty(categoryInfoEditReq.getAttributeIdList()) && categoryInfoEditReq.getAttributeIdList()!=null){ + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(AsCategoryAttribute::getCategoryId,id); + asCategoryAttributeService.remove(queryWrapper); + List asCategoryAttributeList = categoryInfoEditReq.getAttributeIdList().stream().map(aLong -> { + AsCategoryAttribute asCategoryAttribute = new AsCategoryAttribute(); + asCategoryAttribute.setCategoryId(id); + asCategoryAttribute.setAttributeId(aLong); + return asCategoryAttribute; + }).toList(); + asCategoryAttributeService.saveBatch(asCategoryAttributeList); + + } + + if(!CollectionUtils.isEmpty(categoryInfoEditReq.getBrandIdList()) && categoryInfoEditReq.getBrandIdList()!=null){ + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(AsCategoryBrand::getCategoryId,id); + asCategoryBrandService.remove(queryWrapper); + + List asCategoryBrandList = categoryInfoEditReq.getBrandIdList().stream().map(aLong -> { + AsCategoryBrand asCategoryBrand = new AsCategoryBrand(); + asCategoryBrand.setCategoryId(id); + asCategoryBrand.setBrandId(aLong); + return asCategoryBrand; + }).toList(); + + asCategoryBrandService.saveBatch(asCategoryBrandList); + + } + if(!CollectionUtils.isEmpty(categoryInfoEditReq.getAttributeGroupIdList()) && categoryInfoEditReq.getAttributeGroupIdList()!=null){ + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(AsCategoryAttributeGroup::getCategoryId, id); + asCategoryAttributeGroupService.remove(queryWrapper); + + List groupStream = categoryInfoEditReq.getAttributeGroupIdList().stream().map(aLong -> { + AsCategoryAttributeGroup asCategoryAttributeGroup = new AsCategoryAttributeGroup(); + asCategoryAttributeGroup.setCategoryId(id); + asCategoryAttributeGroup.setAttributeGroupId(aLong); + return asCategoryAttributeGroup; + }).toList(); + asCategoryAttributeGroupService.saveBatch(groupStream); + } - categoryInfoMapper.delArandIdList(id); - List brandIdList = categoryInfoEditReq.getBrandIdList(); - for (Long aLong : brandIdList) { - categoryInfoMapper.addArandIdList(id,aLong); - } - - categoryInfoMapper.delAttributeGroupId(id); - List attributeGroupIdList = categoryInfoEditReq.getAttributeGroupIdList(); - for (Long aLong : attributeGroupIdList) { - categoryInfoMapper.attributeGroupIdList(id,aLong); - } return Result.success(0,"修改成功"); } 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 880ad9b..1ee49db 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 @@ -22,32 +22,6 @@ 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 - - INSERT INTO `as_category_attribute` ( `category_id`, `attribute_id`) - VALUES (#{id},#{attributeId}); - - - - INSERT INTO `as_category_brand` (`category_id`, `brand_id`) values - (#{id},#{brandId}) - - - INSERT INTO `as_category_attribute_group` ( `category_id`, `attribute_group_id`) - VALUES (#{id},#{aLong}); - - - - delete from as_category_attribute where category_id = #{id} - - - - delete from as_category_brand where category_id = #{id} - - - - delete from as_category_attribute_group where category_id = #{id} - -