From f3e3037d6685501065fbac5f55466b4770e43e36 Mon Sep 17 00:00:00 2001 From: ddyd <2073699128@qq.com> Date: Mon, 25 Aug 2025 23:03:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=95=86=E5=93=81=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E4=B8=AD=E7=9A=84=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=B0=86=E5=85=B6=E4=B8=AD=E7=9A=84bug?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=AE=8C=E6=88=90=EF=BC=9A1=E3=80=81?= =?UTF-8?q?=E8=B0=83=E7=94=A8feign=E6=9C=8D=E5=8A=A1=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=90=8D=E5=AD=97=E9=94=99=E8=AF=AF=202?= =?UTF-8?q?=E3=80=81=20BeanUtils.copyProperties(item,=20skuReductionTo)?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E9=9C=80=E8=A6=81=E4=BF=9D=E8=AF=81=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E7=B1=BB=E5=86=85=E6=89=80=E6=9C=89=E6=88=90=E5=91=98?= =?UTF-8?q?=E4=B8=80=E6=A0=B7=EF=BC=8C=E5=8C=85=E6=8B=AC=E7=B1=BB=E6=88=90?= =?UTF-8?q?=E5=91=98=E6=89=80=E5=9C=A8=E7=9A=84=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SkuFullReductionController.java | 21 +++++-- .../service/SkuFullReductionService.java | 3 + .../impl/SkuFullReductionServiceImpl.java | 58 +++++++++++++++++++ .../src/main/resources/application.properties | 2 +- .../src/main/resources/bootstrap.properties | 2 - book-product/pom.xml | 5 ++ .../product/entity/SpuInfoDescEntity.java | 3 +- .../product/feign/CouponFeignService.java | 6 +- .../product/service/impl/AttrServiceImpl.java | 2 +- .../service/impl/SpuImagesServiceImpl.java | 2 +- .../service/impl/SpuInfoServiceImpl.java | 24 ++++++-- .../bookmall/product/vo/MemberPrice.java | 23 -------- .../bookstore/bookmall/product/vo/Skus.java | 1 + mall-common/pom.xml | 2 + .../bookstore/common/to/SkuReductionTo.java | 6 +- .../java/com/bookstore/common/utils/R.java | 4 ++ .../src/views/modules/product/spuadd.vue | 15 ++--- 17 files changed, 132 insertions(+), 47 deletions(-) delete mode 100644 book-product/src/main/java/com/bookstore/bookmall/product/vo/MemberPrice.java diff --git a/book-coupon/src/main/java/com/bookstore/bookmall/coupon/controller/SkuFullReductionController.java b/book-coupon/src/main/java/com/bookstore/bookmall/coupon/controller/SkuFullReductionController.java index 17c19fc..3b747b3 100644 --- a/book-coupon/src/main/java/com/bookstore/bookmall/coupon/controller/SkuFullReductionController.java +++ b/book-coupon/src/main/java/com/bookstore/bookmall/coupon/controller/SkuFullReductionController.java @@ -4,12 +4,10 @@ import java.util.Arrays; import java.util.Map; +import com.bookstore.common.to.SkuReductionTo; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.bookstore.bookmall.coupon.entity.SkuFullReductionEntity; import com.bookstore.bookmall.coupon.service.SkuFullReductionService; @@ -25,12 +23,25 @@ import com.bookstore.common.utils.R; * @email 2073699128@qq.com * @date 2025-07-10 22:58:13 */ +@Slf4j @RestController @RequestMapping("coupon/skufullreduction") public class SkuFullReductionController { @Autowired private SkuFullReductionService skuFullReductionService; + + @PostMapping("/saveinfo") + public R saveInfo(@RequestBody SkuReductionTo to){ + log.info("Received saveInfo request: {}", to); + try { + skuFullReductionService.saveSkuReduction(to); + return R.ok(); + } catch (Exception e) { + log.error("Failed to save SKU reduction: {}", e.getMessage(), e); + return R.error(500, "保存优惠信息失败: " + e.getMessage()); + } + } /** * 列表 */ diff --git a/book-coupon/src/main/java/com/bookstore/bookmall/coupon/service/SkuFullReductionService.java b/book-coupon/src/main/java/com/bookstore/bookmall/coupon/service/SkuFullReductionService.java index cdc72d7..8444836 100644 --- a/book-coupon/src/main/java/com/bookstore/bookmall/coupon/service/SkuFullReductionService.java +++ b/book-coupon/src/main/java/com/bookstore/bookmall/coupon/service/SkuFullReductionService.java @@ -1,6 +1,7 @@ package com.bookstore.bookmall.coupon.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.bookstore.common.to.SkuReductionTo; import com.bookstore.common.utils.PageUtils; import com.bookstore.bookmall.coupon.entity.SkuFullReductionEntity; @@ -16,5 +17,7 @@ import java.util.Map; public interface SkuFullReductionService extends IService { PageUtils queryPage(Map params); + + void saveSkuReduction(SkuReductionTo to); } diff --git a/book-coupon/src/main/java/com/bookstore/bookmall/coupon/service/impl/SkuFullReductionServiceImpl.java b/book-coupon/src/main/java/com/bookstore/bookmall/coupon/service/impl/SkuFullReductionServiceImpl.java index e33c267..eebcb75 100644 --- a/book-coupon/src/main/java/com/bookstore/bookmall/coupon/service/impl/SkuFullReductionServiceImpl.java +++ b/book-coupon/src/main/java/com/bookstore/bookmall/coupon/service/impl/SkuFullReductionServiceImpl.java @@ -1,7 +1,19 @@ package com.bookstore.bookmall.coupon.service.impl; +import com.bookstore.bookmall.coupon.entity.MemberPriceEntity; +import com.bookstore.bookmall.coupon.entity.SkuLadderEntity; +import com.bookstore.bookmall.coupon.service.MemberPriceService; +import com.bookstore.bookmall.coupon.service.SkuLadderService; +import com.bookstore.common.to.MemberPrice; +import com.bookstore.common.to.SkuReductionTo; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -16,6 +28,11 @@ import com.bookstore.bookmall.coupon.service.SkuFullReductionService; @Service("skuFullReductionService") public class SkuFullReductionServiceImpl extends ServiceImpl implements SkuFullReductionService { + @Autowired + SkuLadderService skuLadderService; + @Autowired + MemberPriceService memberPriceService; + @Override public PageUtils queryPage(Map params) { IPage page = this.page( @@ -26,4 +43,45 @@ public class SkuFullReductionServiceImpl extends ServiceImpl memberPrice = to.getMemberPrice(); + if (memberPrice == null || memberPrice.isEmpty()) { + log.warn("memberPrice为空"); + } + if (memberPrice != null && !memberPrice.isEmpty()) { + List collect = memberPrice.stream().map(item -> { + if (item.getId() == null || item.getPrice() == null) { + log.error("Invalid MemberPrice: {}"); + throw new IllegalArgumentException("会员价格信息不完整"); + } + MemberPriceEntity priceEntity = new MemberPriceEntity(); + priceEntity.setSkuId(to.getSkuId()); + priceEntity.setMemberLevelId(item.getId()); + priceEntity.setMemberLevelName(item.getName()); + priceEntity.setMemberPrice(item.getPrice()); + priceEntity.setAddOther(1); + return priceEntity; + }).collect(Collectors.toList()); + memberPriceService.saveBatch(collect); + } + + } + } \ No newline at end of file diff --git a/book-coupon/src/main/resources/application.properties b/book-coupon/src/main/resources/application.properties index 6820a96..000e742 100644 --- a/book-coupon/src/main/resources/application.properties +++ b/book-coupon/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.application.name=book-coupon + coupon.user.name = zhangsna coupon.user.age = 18 diff --git a/book-coupon/src/main/resources/bootstrap.properties b/book-coupon/src/main/resources/bootstrap.properties index 5a6d8ae..86b1a4f 100644 --- a/book-coupon/src/main/resources/bootstrap.properties +++ b/book-coupon/src/main/resources/bootstrap.properties @@ -19,5 +19,3 @@ spring.cloud.nacos.config.extension-configs[2].group=dev spring.cloud.nacos.config.extension-configs[2].refresh=true -# 应用名称 -spring.application.name=book-coupon \ No newline at end of file diff --git a/book-product/pom.xml b/book-product/pom.xml index 332bfca..b419522 100644 --- a/book-product/pom.xml +++ b/book-product/pom.xml @@ -46,6 +46,11 @@ org.springframework.cloud spring-cloud-starter-openfeign + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + org.springframework.boot diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/entity/SpuInfoDescEntity.java b/book-product/src/main/java/com/bookstore/bookmall/product/entity/SpuInfoDescEntity.java index 6563708..bf5b831 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/entity/SpuInfoDescEntity.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/entity/SpuInfoDescEntity.java @@ -1,5 +1,6 @@ package com.bookstore.bookmall.product.entity; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -22,7 +23,7 @@ public class SpuInfoDescEntity implements Serializable { /** * 商品id */ - @TableId + @TableId(type = IdType.INPUT) private Long spuId; /** * 商品介绍 diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/feign/CouponFeignService.java b/book-product/src/main/java/com/bookstore/bookmall/product/feign/CouponFeignService.java index c37e6de..e1f5c47 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/feign/CouponFeignService.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/feign/CouponFeignService.java @@ -1,14 +1,18 @@ package com.bookstore.bookmall.product.feign; +import com.bookstore.common.to.SkuReductionTo; import com.bookstore.common.to.SpuBoundsTo; import com.bookstore.common.utils.R; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -@FeignClient("book-coupon") +@FeignClient("mall-coupon") public interface CouponFeignService { @PostMapping("/coupon/spubounds/save") R saveSpuBounds(@RequestBody SpuBoundsTo spuBoundsTo); + + @PostMapping("/coupon/skufullreduction/saveinfo") + R saveSkuReduction(@RequestBody SkuReductionTo skuReductionTo); } diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/AttrServiceImpl.java b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/AttrServiceImpl.java index 9a1aaa7..d19a6e8 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/AttrServiceImpl.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/AttrServiceImpl.java @@ -70,7 +70,7 @@ public class AttrServiceImpl extends ServiceImpl implements && attr.getAttrGroupId()!=null) { AttrAttrgroupRelationEntity RelationEntity = new AttrAttrgroupRelationEntity(); RelationEntity.setAttrGroupId(attr.getAttrGroupId()); - RelationEntity.setAttrId(attr.getAttrId()); + RelationEntity.setAttrId(attrEntity.getAttrId()); RelationDao.insert(RelationEntity); } diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/SpuImagesServiceImpl.java b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/SpuImagesServiceImpl.java index 5af3b9b..88c52d2 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/SpuImagesServiceImpl.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/SpuImagesServiceImpl.java @@ -36,7 +36,7 @@ public class SpuImagesServiceImpl extends ServiceImpl 0) { List collect = images.stream().map((image) -> { SpuImagesEntity ImagesEntity = new SpuImagesEntity(); - ImagesEntity.setId(id); + ImagesEntity.setSpuId(id); ImagesEntity.setImgUrl(image); return ImagesEntity; diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/SpuInfoServiceImpl.java b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/SpuInfoServiceImpl.java index 61f1f97..05fa058 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/SpuInfoServiceImpl.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/service/impl/SpuInfoServiceImpl.java @@ -4,8 +4,11 @@ import com.bookstore.bookmall.product.entity.*; import com.bookstore.bookmall.product.feign.CouponFeignService; import com.bookstore.bookmall.product.service.*; import com.bookstore.bookmall.product.vo.*; +import com.bookstore.common.to.SkuReductionTo; import com.bookstore.common.to.SpuBoundsTo; +import com.bookstore.common.utils.R; import com.fasterxml.jackson.databind.annotation.JsonAppend; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -26,7 +29,7 @@ import com.bookstore.common.utils.Query; import com.bookstore.bookmall.product.dao.SpuInfoDao; import org.springframework.transaction.annotation.Transactional; - +@Slf4j @Service("spuInfoService") public class SpuInfoServiceImpl extends ServiceImpl implements SpuInfoService { @@ -61,7 +64,7 @@ public class SpuInfoServiceImpl extends ServiceImpl i //基本信息在pms_spu_info //描述信息在pms_spu_info_desc //sku: spu销售属性笛卡尔积得出了sku - @Transactional + @Override public void saveSpuInfo(SpuSaveVo vo) { //1、保存基本信息 pms_spu_info @@ -102,7 +105,11 @@ public class SpuInfoServiceImpl extends ServiceImpl i SpuBoundsTo spuBoundsTo = new SpuBoundsTo(); BeanUtils.copyProperties(bounds, spuBoundsTo); spuBoundsTo.setSpuId(spuInfoEntity.getId()); - couponFeignService.saveSpuBounds(spuBoundsTo); + R r = couponFeignService.saveSpuBounds(spuBoundsTo); + log.debug("远程保存spu积分信息"); + if (r.getCode() != 0) { + log.error("远程保存spu积分信息失败"); + } //5、保存当前spu对应的所有sku信息 List skus = vo.getSkus(); @@ -140,6 +147,7 @@ public class SpuInfoServiceImpl extends ServiceImpl i return skuImagesEntity; }).collect(Collectors.toList()); + //todo 没有图片路径的无需保存 skuImagesService.saveBatch(skuImagesEntities); //5.3 sku的销售属性信息 pms_sku_sale_attr_value @@ -153,9 +161,17 @@ public class SpuInfoServiceImpl extends ServiceImpl i skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities); //5.4 sku的优惠满减信息 - + SkuReductionTo skuReductionTo = new SkuReductionTo(); + BeanUtils.copyProperties(item, skuReductionTo); + skuReductionTo.setSkuId(skuId); + R r1 = couponFeignService.saveSkuReduction(skuReductionTo); + if (r1.getCode() != 0) { + log.error("远程保存sku优惠满减信息失败"); + } }); + log.info("保存完毕"); + } diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/vo/MemberPrice.java b/book-product/src/main/java/com/bookstore/bookmall/product/vo/MemberPrice.java deleted file mode 100644 index d049787..0000000 --- a/book-product/src/main/java/com/bookstore/bookmall/product/vo/MemberPrice.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright 2019 bejson.com - */ -package com.bookstore.bookmall.product.vo; - -import lombok.Data; - -import java.math.BigDecimal; - -/** - * Auto-generated: 2019-11-26 10:50:34 - * - * @author bejson.com (i@bejson.com) - * @website http://www.bejson.com/java2pojo/ - */ -@Data -public class MemberPrice { - - private Long id; - private String name; - private BigDecimal price; - -} \ No newline at end of file diff --git a/book-product/src/main/java/com/bookstore/bookmall/product/vo/Skus.java b/book-product/src/main/java/com/bookstore/bookmall/product/vo/Skus.java index 3680e24..ca40ea1 100644 --- a/book-product/src/main/java/com/bookstore/bookmall/product/vo/Skus.java +++ b/book-product/src/main/java/com/bookstore/bookmall/product/vo/Skus.java @@ -2,6 +2,7 @@ * Copyright 2019 bejson.com */ package com.bookstore.bookmall.product.vo; +import com.bookstore.common.to.MemberPrice; import lombok.Data; import java.math.BigDecimal; diff --git a/mall-common/pom.xml b/mall-common/pom.xml index efd6ccb..dd9fa07 100644 --- a/mall-common/pom.xml +++ b/mall-common/pom.xml @@ -89,6 +89,8 @@ + + diff --git a/mall-common/src/main/java/com/bookstore/common/to/SkuReductionTo.java b/mall-common/src/main/java/com/bookstore/common/to/SkuReductionTo.java index b7770a5..951c037 100644 --- a/mall-common/src/main/java/com/bookstore/common/to/SkuReductionTo.java +++ b/mall-common/src/main/java/com/bookstore/common/to/SkuReductionTo.java @@ -4,13 +4,17 @@ package com.bookstore.common.to; import lombok.Data; import java.math.BigDecimal; +import java.util.List; @Data -public class skuReductionTo { +public class SkuReductionTo { + + private Long skuId; private int fullCount; private BigDecimal discount; private int countStatus; private BigDecimal fullPrice; private BigDecimal reducePrice; private int priceStatus; + private List memberPrice; } diff --git a/mall-common/src/main/java/com/bookstore/common/utils/R.java b/mall-common/src/main/java/com/bookstore/common/utils/R.java index db45256..50fbf0b 100644 --- a/mall-common/src/main/java/com/bookstore/common/utils/R.java +++ b/mall-common/src/main/java/com/bookstore/common/utils/R.java @@ -61,4 +61,8 @@ public class R extends HashMap { super.put(key, value); return this; } + + public Integer getCode() { + return (Integer) this.get("code"); + } } diff --git a/renren-fast-vue/src/views/modules/product/spuadd.vue b/renren-fast-vue/src/views/modules/product/spuadd.vue index 2aef84d..3ab0cff 100644 --- a/renren-fast-vue/src/views/modules/product/spuadd.vue +++ b/renren-fast-vue/src/views/modules/product/spuadd.vue @@ -128,13 +128,14 @@ v-show="false" > - + v-model="dataResp.tempSaleAttrs[aidx].attrValues"> +
+ +