完成商品发布中的保存功能,并将其中的bug处理完成:1、调用feign服务时,路径名字错误 2、 BeanUtils.copyProperties(item, skuReductionTo)时,需要保证两个类内所有成员一样,包括类成员所在的包

develop
ddyd 1 week ago
parent 0f5db1893a
commit f3e3037d66

@ -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());
}
}
/**
*
*/

@ -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<SkuFullReductionEntity> {
PageUtils queryPage(Map<String, Object> params);
void saveSkuReduction(SkuReductionTo to);
}

@ -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<SkuFullReductionDao, SkuFullReductionEntity> implements SkuFullReductionService {
@Autowired
SkuLadderService skuLadderService;
@Autowired
MemberPriceService memberPriceService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<SkuFullReductionEntity> page = this.page(
@ -26,4 +43,45 @@ public class SkuFullReductionServiceImpl extends ServiceImpl<SkuFullReductionDao
return new PageUtils(page);
}
@Override
public void saveSkuReduction(SkuReductionTo to) {
//sku的优惠满减 1、sms_sku_ladder 2、sku_full_reduction 3、sms_member_price
//sms_sku_ladder
SkuLadderEntity skuLadderEntity = new SkuLadderEntity();
skuLadderEntity.setSkuId(to.getSkuId());
skuLadderEntity.setAddOther(to.getCountStatus());
skuLadderEntity.setDiscount(to.getDiscount());
skuLadderEntity.setFullCount(to.getFullCount());
skuLadderService.save(skuLadderEntity);
//sku_full_reduction
SkuFullReductionEntity skuFullReductionEntity = new SkuFullReductionEntity();
BeanUtils.copyProperties(to, skuFullReductionEntity);
this.save(skuFullReductionEntity);
//sms_member_price
List<MemberPrice> memberPrice = to.getMemberPrice();
if (memberPrice == null || memberPrice.isEmpty()) {
log.warn("memberPrice为空");
}
if (memberPrice != null && !memberPrice.isEmpty()) {
List<MemberPriceEntity> 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);
}
}
}

@ -1,4 +1,4 @@
spring.application.name=book-coupon
coupon.user.name = zhangsna
coupon.user.age = 18

@ -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

@ -46,6 +46,11 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

@ -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;
/**
*

@ -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);
}

@ -70,7 +70,7 @@ public class AttrServiceImpl extends ServiceImpl<AttrDao, AttrEntity> implements
&& attr.getAttrGroupId()!=null) {
AttrAttrgroupRelationEntity RelationEntity = new AttrAttrgroupRelationEntity();
RelationEntity.setAttrGroupId(attr.getAttrGroupId());
RelationEntity.setAttrId(attr.getAttrId());
RelationEntity.setAttrId(attrEntity.getAttrId());
RelationDao.insert(RelationEntity);
}

@ -36,7 +36,7 @@ public class SpuImagesServiceImpl extends ServiceImpl<SpuImagesDao, SpuImagesEnt
if (images != null && images.size() > 0) {
List<SpuImagesEntity> collect = images.stream().map((image) -> {
SpuImagesEntity ImagesEntity = new SpuImagesEntity();
ImagesEntity.setId(id);
ImagesEntity.setSpuId(id);
ImagesEntity.setImgUrl(image);
return ImagesEntity;

@ -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<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {
@ -61,7 +64,7 @@ public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> 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<SpuInfoDao, SpuInfoEntity> 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> skus = vo.getSkus();
@ -140,6 +147,7 @@ public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> 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<SpuInfoDao, SpuInfoEntity> 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("保存完毕");
}

@ -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;
}

@ -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;

@ -89,6 +89,8 @@
</dependency>
<!--&lt;!&ndash; oss对象存储服务&ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->

@ -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> memberPrice;
}

@ -61,4 +61,8 @@ public class R extends HashMap<String, Object> {
super.put(key, value);
return this;
}
public Integer getCode() {
return (Integer) this.get("code");
}
}

@ -128,13 +128,14 @@
v-show="false"
></el-input>
<el-checkbox-group
v-model="dataResp.tempSaleAttrs[aidx].attrValues"
v-if="dataResp.saleAttrs[aidx].valueSelect != ''">
<el-checkbox
:label="val"
v-for="val in dataResp.saleAttrs[aidx].valueSelect.split(';')"
:key="val"
></el-checkbox>
v-model="dataResp.tempSaleAttrs[aidx].attrValues">
<div v-if="dataResp.saleAttrs[aidx].valueSelect != ''">
<el-checkbox
:label="val"
v-for="val in dataResp.saleAttrs[aidx].valueSelect.split(';')"
:key="val"
></el-checkbox>
</div>
<div style="margin-left:20px;display:inline">
<el-button
v-show="!inputVisible[aidx].view"

Loading…
Cancel
Save