From 6844012e52912b53d2739759d7b9f5591ac21f24 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Mon, 16 May 2022 19:29:55 +0800 Subject: [PATCH] fix goods edit --- src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java | 50 +++++++++++++++++++++++++++++++++----------------- 1 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java index d742db5..0ebb028 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java @@ -8,6 +8,7 @@ import cc.mrbird.febs.mall.mapper.*; import cc.mrbird.febs.mall.service.IAdminMallGoodsService; import cc.mrbird.febs.mall.vo.*; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -146,7 +147,6 @@ } } - if (CollUtil.isNotEmpty(addMallGoodsSkuDtos)) { for (AddMallGoodsSkuDto addMallGoodsSkuDto : addMallGoodsSkuDtos) { MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addMallGoodsSkuDto.getStyleName(), mallGoods.getId()); @@ -233,6 +233,17 @@ } @Override + public MallGoods selectGoodsById(long id) { + MallGoods mallGoods = mallGoodsMapper.selectById(id); + + List<MallGoodsSku> skus = mallGoodsSkuMapper.selectSkuByGoodsId(mallGoods.getId()); + List<String> thumbs = mallGoodsImagesMapper.selectByGoodId(mallGoods.getId()); + mallGoods.setImages(thumbs); + mallGoods.setSkus(skus); + return mallGoods; + } + + @Override @Transactional public FebsResponse updateMallGoods(MallGoodsUpdateDto mallGoodsUpdateDto) { String goodsName = mallGoodsUpdateDto.getGoodsName(); @@ -288,21 +299,10 @@ } //新增商品 MallGoods mallGoods = mallGoodsMapper.selectById(mallGoodsUpdateDto.getId()); - mallGoods.setGoodsNo(mallGoodsUpdateDto.getGoodsNo()); - mallGoods.setGoodsName(mallGoodsUpdateDto.getGoodsName()); - mallGoods.setGoodsIntrodution(mallGoodsUpdateDto.getGoodsIntrodution()); - mallGoods.setUnit(mallGoodsUpdateDto.getUnit()); - mallGoods.setThumb(mallGoodsUpdateDto.getThumb()); - mallGoods.setGoodsDetails(mallGoodsUpdateDto.getGoodsDetails()); - mallGoods.setOriginalPrice(mallGoodsUpdateDto.getOriginalPrice()); - mallGoods.setCategoryId(mallGoodsUpdateDto.getCategoryId()); - mallGoods.setPresentPrice(mallGoodsUpdateDto.getPresentPrice()); - mallGoods.setIsHot(mallGoodsUpdateDto.getIsHot()); -// mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED); + BeanUtil.copyProperties(mallGoodsUpdateDto, mallGoods); mallGoodsMapper.updateById(mallGoods); mallGoodsImagesMapper.deleteByGoodsId(mallGoodsUpdateDto.getId()); - String thumbs = mallGoodsUpdateDto.getThumbs(); if (StrUtil.isNotEmpty(thumbs)) { List<String> imgs = StrUtil.splitTrim(thumbs, ","); @@ -319,15 +319,29 @@ } } + // 删除已存在sku + List<Long> delSkuIds = mallGoodsUpdateDto.getDelSkuId(); + if (CollUtil.isNotEmpty(delSkuIds)) { + mallGoodsSkuMapper.delSkuByIds(delSkuIds); + + // 如果该样式下sku全删除,则删除该样式 + List<MallGoodsStyle> styles = mallGoodsStyleMapper.selectByGoodsId(mallGoods.getId()); + for (MallGoodsStyle style : styles) { + if (CollUtil.isEmpty(style.getSkus())) { + mallGoodsStyleMapper.deleteById(style.getId()); + } + } + } + List<MailGoodsSkuDto> mailGoodsSkuDto = mallGoodsUpdateDto.getMailGoodsSkuDto(); Set<String> styles = new HashSet<>(); if (CollUtil.isNotEmpty(mailGoodsSkuDto)) { for (MailGoodsSkuDto addStyleDto : mailGoodsSkuDto) { - if (ObjectUtil.isNotEmpty(addStyleDto.getDelLog())) { - mallGoodsSkuMapper.deleteById(addStyleDto.getId()); +// if (ObjectUtil.isNotEmpty(addStyleDto.getDelLog())) { +// mallGoodsSkuMapper.deleteById(addStyleDto.getId()); +// mallShoppingCartMapper.deleteByGoodsIdAndSkuId(addStyleDto.getId(), addStyleDto.getGoodsId()); +// } - mallShoppingCartMapper.deleteByGoodsIdAndSkuId(addStyleDto.getId(), addStyleDto.getGoodsId()); - } if (ObjectUtil.isEmpty(addStyleDto.getStyleId())) { MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addStyleDto.getStyleName(), mallGoods.getId()); if (ObjectUtil.isEmpty(mallGoodsStyleSku)) { @@ -359,6 +373,7 @@ mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice()); mallGoodsSku.setStyleId(addMallGoodsSkuDto.getStyleId()); mallGoodsSku.setGoodsId(mallGoods.getId()); + mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice()); mallGoodsSkuMapper.updateById(mallGoodsSku); } else { //新增商品规格 @@ -371,6 +386,7 @@ mallGoodsSku.setOriginalPrice(addMallGoodsSkuDto.getOriginalPrice()); mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice()); mallGoodsSku.setStyleId(mallGoodsStyleSku.getId()); + mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice()); mallGoodsSku.setGoodsId(mallGoods.getId()); mallGoodsSkuMapper.insert(mallGoodsSku); } -- Gitblit v1.9.1