From f2b327c811ad14ad170dd1ba3b353adb277adcb2 Mon Sep 17 00:00:00 2001 From: paulGao Date: Thu, 19 May 2022 17:34:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E7=A7=8D=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=95=86=E5=93=81sku=E7=9A=84=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E3=80=82mysql=20replace=20into(=E5=85=88=E6=9F=A5=E6=89=BE?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E5=AD=98=E5=9C=A8=E5=88=99=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E3=80=82=E5=A6=82=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=96=B0=E5=A2=9E)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/goods/mapper/GoodsSkuMapper.java | 76 +++++++++++++++++++ .../goods/service/GoodsSkuService.java | 2 + .../serviceimpl/GoodsSkuServiceImpl.java | 21 ++++- 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/mapper/GoodsSkuMapper.java b/framework/src/main/java/cn/lili/modules/goods/mapper/GoodsSkuMapper.java index 62f65589..db3e0a58 100644 --- a/framework/src/main/java/cn/lili/modules/goods/mapper/GoodsSkuMapper.java +++ b/framework/src/main/java/cn/lili/modules/goods/mapper/GoodsSkuMapper.java @@ -2,6 +2,8 @@ package cn.lili.modules.goods.mapper; import cn.lili.modules.goods.entity.dos.GoodsSku; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; @@ -23,4 +25,78 @@ public interface GoodsSkuMapper extends BaseMapper { @Select("SELECT id FROM li_goods_sku WHERE goods_id = #{goodsId}") List getGoodsSkuIdByGoodsId(String goodsId); + + @Insert("replace into li_goods_sku (\n" + + "\tid,\n" + + "\tgoods_id,\n" + + "\tspecs,\n" + + "\tsimple_specs,\n" + + "\tfreight_template_id,\n" + + "\tgoods_name,\n" + + "\tsn,\n" + + "\tbrand_id,\n" + + "\tcategory_path,\n" + + "\tgoods_unit,\n" + + "\tselling_point,\n" + + "\tweight,\n" + + "\tmarket_enable,\n" + + "\tintro,\n" + + "\tprice,\n" + + "\tcost,\n" + + "\tquantity,\n" + + "\tgrade,\n" + + "\tthumbnail,\n" + + "\tsmall,\n" + + "\tstore_category_path,\n" + + "\tstore_id,\n" + + "\tstore_name,\n" + + "\tauth_flag,\n" + + "\tself_operated,\n" + + "\tmobile_intro,\n" + + "\trecommend,\n" + + "\tsales_model,\n" + + "\tgoods_type,\n" + + "\tcreate_by,\n" + + "\tcreate_time,\n" + + "\tupdate_time,\n" + + "\tdelete_flag \n" + + ")\n" + + " VALUES\n" + + "(\n" + + "\t#{goodsSku.id},\n" + + "\t#{goodsSku.goodsId},\n" + + "\t#{goodsSku.specs},\n" + + "\t#{goodsSku.simpleSpecs},\n" + + "\t#{goodsSku.freightTemplateId},\n" + + "\t#{goodsSku.goodsName},\n" + + "\t#{goodsSku.sn},\n" + + "\t#{goodsSku.brandId},\n" + + "\t#{goodsSku.categoryPath},\n" + + "\t#{goodsSku.goodsUnit},\n" + + "\t#{goodsSku.sellingPoint},\n" + + "\t#{goodsSku.weight},\n" + + "\t#{goodsSku.marketEnable},\n" + + "\t#{goodsSku.intro},\n" + + "\t#{goodsSku.price},\n" + + "\t#{goodsSku.cost},\n" + + "\t#{goodsSku.quantity},\n" + + "\t#{goodsSku.grade},\n" + + "\t#{goodsSku.thumbnail},\n" + + "\t#{goodsSku.small},\n" + + "\t#{goodsSku.storeCategoryPath},\n" + + "\t#{goodsSku.storeId},\n" + + "\t#{goodsSku.storeName},\n" + + "\t#{goodsSku.authFlag},\n" + + "\t#{goodsSku.selfOperated},\n" + + "\t#{goodsSku.mobileIntro},\n" + + "\t#{goodsSku.recommend},\n" + + "\t#{goodsSku.salesModel},\n" + + "\t#{goodsSku.goodsType},\n" + + "\t#{goodsSku.createBy},\n" + + "\t#{goodsSku.createTime},\n" + + "\t#{goodsSku.updateTime},\n" + + "\t#{goodsSku.deleteFlag}\n" + + ")") + int replaceGoodsSku(@Param("goodsSku") GoodsSku goodsSku); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java index b723f936..4babd511 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java @@ -211,4 +211,6 @@ public interface GoodsSkuService extends IService { * @return 全部skuId的集合 */ List getSkuIdsByGoodsId(String goodsId); + + boolean deleteAndInsertGoodsSkus(List goodsSkus); } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 00cbe0b0..4957ec16 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -13,6 +13,7 @@ import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.common.security.context.UserContext; +import cn.lili.common.utils.SnowFlake; import cn.lili.modules.goods.entity.dos.Goods; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsSearchParams; @@ -149,9 +150,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl i oldSkuIds.add(goodsSkuVO.getId()); cache.remove(GoodsSkuService.getCacheKeys(goodsSkuVO.getId())); } - this.removeByIds(oldSkuIds); + + this.remove(new LambdaQueryWrapper().eq(GoodsSku::getGoodsId, goods.getId())); //删除sku相册 goodsGalleryService.removeByGoodsId(goods.getId()); + getGoodsListByGoodsId(goods.getId()); // 添加商品sku newSkuList = this.addGoodsSku(skuList, goods); @@ -179,6 +182,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i this.clearCache(sku.getId()); } } + this.remove(new LambdaQueryWrapper().eq(GoodsSku::getGoodsId, goods.getId())); this.saveOrUpdateBatch(newSkuList); } this.updateStock(newSkuList); @@ -393,7 +397,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i @Override public List getGoodsListByGoodsId(String goodsId) { - List list = this.list(new LambdaQueryWrapper().eq(GoodsSku::getGoodsId, goodsId)); + List list = this.list(new LambdaQueryWrapper().eq(GoodsSku::getGoodsId, goodsId).orderByAsc(GoodsSku::getGoodsName)); return this.getGoodsSkuVOList(list); } @@ -597,6 +601,19 @@ public class GoodsSkuServiceImpl extends ServiceImpl i applicationEventPublisher.publishEvent(new GeneratorEsGoodsIndexEvent("生成商品", GoodsTagsEnum.GENERATOR_GOODS_INDEX.name(), goods.getId())); } + @Override + @Transactional(rollbackFor = Exception.class) + public boolean deleteAndInsertGoodsSkus(List goodsSkus) { + int count = 0; + for (GoodsSku skus : goodsSkus) { + if (CharSequenceUtil.isEmpty(skus.getId())) { + skus.setId(SnowFlake.getIdStr()); + } + count = this.baseMapper.replaceGoodsSku(skus); + } + return count > 0; + } + /** * 修改库存 *