From 0d3d7254854ea98c1bf2577121e1c071622449ce Mon Sep 17 00:00:00 2001 From: Yen Date: Fri, 4 Nov 2022 10:11:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/controller/GoodsSpuController.java | 7 +++- .../serve/modules/goods/entity/GoodsSpu.java | 12 ++---- .../goods/entity/bo/GoodsSpuTasteBo.java | 10 +---- .../modules/goods/entity/vo/GoodsSpuVo.java | 16 ++++--- .../modules/goods/mapper/GoodsSpuMapper.java | 5 +++ .../goods/service/GoodsSpuService.java | 3 ++ .../service/impl/GoodsSpuServiceImpl.java | 42 ++++++++++++------- .../resources/mapper/bms/GoodsSpuMapper.xml | 21 +++++----- 8 files changed, 65 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java b/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java index b8be3276..663d1304 100644 --- a/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java +++ b/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java @@ -19,6 +19,7 @@ import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo; import com.qs.serve.modules.goods.service.GoodsSkuService; import com.qs.serve.modules.goods.service.GoodsSkuSpecValueService; import com.qs.serve.modules.goods.service.GoodsSpuSpecService; +import io.netty.util.internal.StringUtil; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; @@ -55,8 +56,7 @@ public class GoodsSpuController { @PreAuthorize("hasRole('goods:spu:query')") public R> getPage(GoodsSpu param){ PageUtil.startPage(); - LambdaQueryWrapper spuWrapper = new LambdaQueryWrapper<>(param); - List list = goodsSpuService.list(spuWrapper); + List list = goodsSpuService.selectSpuList(param); return R.byPageHelperList(list); } @@ -124,6 +124,9 @@ public class GoodsSpuController { @PreAuthorize("hasRole('goods:spu:insert')") public R saveTasteSpu(@RequestBody @Valid GoodsSpuBo param){ param.setId(null); + if(StringUtil.isNullOrEmpty(param.getCategoryId())){ + return R.error("参数缺少"); + } goodsSpuService.editTasteSpu(param); return R.ok(); } diff --git a/src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java b/src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java index 972e9079..71bad93c 100644 --- a/src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java +++ b/src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java @@ -41,20 +41,14 @@ public class GoodsSpu implements Serializable { @Length(max = 200,message = "商品名字长度不能超过200字") private String name; - /** 品牌id */ - private Long brandId; - - /** 系列id */ - private Long seriesId; - - /** 一级分类ID */ + /** 一级分类、品牌ID */ @NotNull(message = "一级分类ID不能为空") private String categoryFirst; - /** 二级分类ID */ + /** 二级分类、类目ID */ private String categorySecond; - /** 三级分类ID */ + /** 三级分类、系列ID */ private String categoryThird; /** 最后一级分类 */ diff --git a/src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsSpuTasteBo.java b/src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsSpuTasteBo.java index 0219d0e4..fd8e9a9a 100644 --- a/src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsSpuTasteBo.java +++ b/src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsSpuTasteBo.java @@ -30,18 +30,10 @@ public class GoodsSpuTasteBo { @Length(max = 200,message = "商品名字长度不能超过200字") private String name; - /** 分类编码 */ + /** 分类编码(系列编码) */ @NotNull(message = "分类编码不能为空") private String categoryCode; - /** 品牌编码 */ - @NotNull(message = "品牌编码不能为空") - private String brandCode; - - /** 系列编码 */ - @NotNull(message = "系列编码不能为空") - private String seriesCode; - /** 商品组图片 */ private String[] picUrls; diff --git a/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java b/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java index 3a573ea5..9589ef7d 100644 --- a/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java +++ b/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java @@ -1,5 +1,6 @@ package com.qs.serve.modules.goods.entity.vo; +import com.baomidou.mybatisplus.annotation.TableField; import com.qs.serve.modules.goods.entity.GoodsSku; import lombok.Data; @@ -20,12 +21,6 @@ public class GoodsSpuVo { /** 商品名字 */ private String name; - /** 品牌id */ - private Long brandId; - - /** 系列id */ - private Long seriesId; - /** 一级分类ID */ private String categoryFirst; @@ -56,4 +51,13 @@ public class GoodsSpuVo { /** sku与规格 关联列表 */ private List skuSpecValueList; + /** 一级类目:品牌名称 */ + private String cateFirstLabel; + + /** 二级类目:类目名称 */ + private String cateSecondLabel; + + /** 三级类目:系列名称 */ + private String cateThirdLabel; + } diff --git a/src/main/java/com/qs/serve/modules/goods/mapper/GoodsSpuMapper.java b/src/main/java/com/qs/serve/modules/goods/mapper/GoodsSpuMapper.java index cb0dc6f9..48fb951f 100644 --- a/src/main/java/com/qs/serve/modules/goods/mapper/GoodsSpuMapper.java +++ b/src/main/java/com/qs/serve/modules/goods/mapper/GoodsSpuMapper.java @@ -2,6 +2,9 @@ package com.qs.serve.modules.goods.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.qs.serve.modules.goods.entity.GoodsSpu; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * spu Mapper @@ -10,5 +13,7 @@ import com.qs.serve.modules.goods.entity.GoodsSpu; */ public interface GoodsSpuMapper extends BaseMapper { + List selectSpuList(@Param("query") GoodsSpu goodsSpu); + } diff --git a/src/main/java/com/qs/serve/modules/goods/service/GoodsSpuService.java b/src/main/java/com/qs/serve/modules/goods/service/GoodsSpuService.java index 07ac508e..05df48a5 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/GoodsSpuService.java +++ b/src/main/java/com/qs/serve/modules/goods/service/GoodsSpuService.java @@ -8,6 +8,7 @@ import com.qs.serve.modules.goods.entity.bo.GoodsSpuEditBo; import com.qs.serve.modules.goods.entity.bo.GoodsSpuTasteBo; import com.qs.serve.modules.goods.entity.vo.GoodSkuBatchResult; import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -18,6 +19,8 @@ import java.util.List; */ public interface GoodsSpuService extends IService { + List selectSpuList(GoodsSpu goodsSpu); + GoodsSpuVo getVoById(Long id); GoodsSpu getByCode(String code); diff --git a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java index 04dda5c5..7003afc7 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java @@ -31,8 +31,6 @@ import java.util.List; @AllArgsConstructor public class GoodsSpuServiceImpl extends ServiceImpl implements GoodsSpuService { - private GoodsSeriesService goodsSeriesService; - private GoodsBrandService goodsBrandService; private GoodsUnitService goodsUnitService; private GoodsSkuService goodsSkuService; private GoodsSpuSpecService goodsSpuSpecService; @@ -41,6 +39,11 @@ public class GoodsSpuServiceImpl extends ServiceImpl im private GoodsCategoryService goodsCategoryService; private BmsFactoryService bmsFactoryService; + @Override + public List selectSpuList(GoodsSpu goodsSpu) { + return baseMapper.selectSpuList(goodsSpu); + } + @Override public GoodsSpu getByCode(String code) { LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); @@ -55,6 +58,7 @@ public class GoodsSpuServiceImpl extends ServiceImpl im List skuList = goodsSkuService.getBySpuId(id); goodsSpuVo.setSkuList(skuList); List skuSpecValueList = goodsSkuSpecValueService.listSpecValueBySpuId(id); + goodsSpuVo.setSkuSpecValueList(skuSpecValueList); List specList = goodsSpuSpecService.listSpuSpecs(id); //封装规格的值 for (GoodsSpuSpecVo specVo : specList) { @@ -80,6 +84,24 @@ public class GoodsSpuServiceImpl extends ServiceImpl im } } goodsSpuVo.setSpecList(specList); + List categoryIds = new ArrayList<>(); + categoryIds.add(goodsSpuVo.getCategoryFirst()); + categoryIds.add(goodsSpuVo.getCategorySecond()); + categoryIds.add(goodsSpuVo.getCategoryThird()); + List categories = goodsCategoryService.listByIds(categoryIds); + for (GoodsCategory category : categories) { + if(goodsSpuVo.getCategoryFirst().equals(category.getId().toString())){ + goodsSpuVo.setCateFirstLabel(category.getName()); + continue; + } + if(goodsSpuVo.getCategorySecond().equals(category.getId().toString())){ + goodsSpuVo.setCateSecondLabel(category.getName()); + continue; + } + if(goodsSpuVo.getCategoryThird().equals(category.getId().toString())){ + goodsSpuVo.setCateThirdLabel(category.getName()); + } + } return goodsSpuVo; } @@ -105,8 +127,10 @@ public class GoodsSpuServiceImpl extends ServiceImpl im if(param.getId()!=null){ spu.setSpuCode(null); } - GoodsCategory category = goodsCategoryService.getById(param.getCategoryId()); - relateCate(spu,category); + if(StringUtils.hasText(param.getCategoryId())){ + GoodsCategory category = goodsCategoryService.getById(param.getCategoryId()); + relateCate(spu,category); + } this.saveOrUpdate(spu); insertSpuSpec(spu.getId()); } @@ -150,16 +174,6 @@ public class GoodsSpuServiceImpl extends ServiceImpl im skuBatchResult.setErrorCode(1); return skuBatchResult; } - //设置品牌 - GoodsBrand goodsBrand = goodsBrandService.getByCode(tasteProduct.getBrandCode()); - if(goodsBrand!=null){ - spu.setBrandId(goodsBrand.getId()); - } - //设置系列 - GoodsSeries goodsSeries = goodsSeriesService.getByCode(tasteProduct.getSeriesCode()); - if(goodsSeries!=null){ - spu.setSeriesId(goodsSeries.getId()); - } spu.setTasteValue(tasteProduct.getProductTasteValue()); if(spu.getId()==null){ this.save(spu); diff --git a/src/main/resources/mapper/bms/GoodsSpuMapper.xml b/src/main/resources/mapper/bms/GoodsSpuMapper.xml index 7b7b941c..71dea681 100644 --- a/src/main/resources/mapper/bms/GoodsSpuMapper.xml +++ b/src/main/resources/mapper/bms/GoodsSpuMapper.xml @@ -8,8 +8,6 @@ - - @@ -25,6 +23,9 @@ + + + @@ -32,8 +33,6 @@ goods_spu.`id`, goods_spu.`spu_code`, goods_spu.`name`, - goods_spu.`brand_id`, - goods_spu.`series_id`, goods_spu.`category_first`, goods_spu.`category_second`, goods_spu.`category_third`, @@ -51,19 +50,20 @@ goods_spu.`tenant_id`, goods_spu.`del_flag` - SELECT - `goods_brand`.`name` AS `brand_name`, - `goods_series`.`name` AS `series_name`, + `cate1`.`name` AS `cate_first_label`, + `cate2`.`name` AS `cate_second_label`, + `cate3`.`name` AS `cate_third_label`, FROM `goods_spu` `goods_spu` - + LEFT JOIN `goods_category` `cate1` ON `cate1`.`id` = `goods_spu`.`category_first` + LEFT JOIN `goods_category` `cate2` ON `cate2`.`id` = `goods_spu`.`category_second` + LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third` and `goods_spu`.`id` = #{query.id} and `goods_spu`.`spu_code` = #{query.spuCode} and `goods_spu`.`name` = #{query.name} - and `goods_spu`.`brand_id` = #{query.brandId} - and `goods_spu`.`series_id` = #{query.seriesId} and `goods_spu`.`category_first` = #{query.categoryFirst} and `goods_spu`.`category_second` = #{query.categorySecond} and `goods_spu`.`category_third` = #{query.categoryThird} @@ -71,7 +71,6 @@ and `goods_spu`.`shelf` = #{query.shelf} and `goods_spu`.`sort` = #{query.sort} and `goods_spu`.`sale_num` = #{query.saleNum} - and `goods_spu`.`spec_type` = #{query.specType} and `goods_spu`.`taste_value` = #{query.tasteValue} and `goods_spu`.`create_time` = #{query.createTime} and `goods_spu`.`update_time` = #{query.updateTime}