Skip to content

Commit

Permalink
fix: 商品服务-商品新增spuinfo调试
Browse files Browse the repository at this point in the history
  • Loading branch information
zsy0216 committed Mar 12, 2021
1 parent fa6d9a3 commit 3fca28e
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

/**
* @author ZSY
*/
@EnableFeignClients
@MapperScan("com.zsy.product.dao")
@EnableDiscoveryClient
@SpringBootApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.zsy.common.utils.PageUtils;
import com.zsy.common.utils.R;



/**
* spu信息
*
Expand All @@ -36,7 +34,7 @@ public class SpuInfoController {
*/
@RequestMapping("/list")
//@RequiresPermissions("product:spuinfo:list")
public R list(@RequestParam Map<String, Object> params){
public R list(@RequestParam Map<String, Object> params) {
PageUtils page = spuInfoService.queryPageByCondition(params);

return R.ok().put("page", page);
Expand All @@ -48,8 +46,8 @@ public R list(@RequestParam Map<String, Object> params){
*/
@RequestMapping("/info/{id}")
//@RequiresPermissions("product:spuinfo:info")
public R info(@PathVariable("id") Long id){
SpuInfoEntity spuInfo = spuInfoService.getById(id);
public R info(@PathVariable("id") Long id) {
SpuInfoEntity spuInfo = spuInfoService.getById(id);

return R.ok().put("spuInfo", spuInfo);
}
Expand All @@ -59,8 +57,8 @@ public R info(@PathVariable("id") Long id){
*/
@RequestMapping("/save")
//@RequiresPermissions("product:spuinfo:save")
public R save(@RequestBody SpuSaveVo vo){
//spuInfoService.save(spuInfo);
public R save(@RequestBody SpuSaveVo vo) {
//spuInfoService.save(spuInfo);

spuInfoService.saveSpuInfo(vo);

Expand All @@ -72,8 +70,8 @@ public R save(@RequestBody SpuSaveVo vo){
*/
@RequestMapping("/update")
//@RequiresPermissions("product:spuinfo:update")
public R update(@RequestBody SpuInfoEntity spuInfo){
spuInfoService.updateById(spuInfo);
public R update(@RequestBody SpuInfoEntity spuInfo) {
spuInfoService.updateById(spuInfo);

return R.ok();
}
Expand All @@ -83,8 +81,8 @@ public R update(@RequestBody SpuInfoEntity spuInfo){
*/
@RequestMapping("/delete")
//@RequiresPermissions("product:spuinfo:delete")
public R delete(@RequestBody Long[] ids){
spuInfoService.removeByIds(Arrays.asList(ids));
public R delete(@RequestBody Long[] ids) {
spuInfoService.removeByIds(Arrays.asList(ids));

return R.ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient("gulimall-coupon")
@FeignClient("mall-coupon")
public interface CouponFeignService {


/**
* 1、CouponFeignService.saveSpuBounds(spuBoundTo);
* 1)、@RequestBody将这个对象转为json。
* 2)、找到gulimall-coupon服务,给/coupon/spubounds/save发送请求。
* 将上一步转的json放在请求体位置,发送请求;
* 3)、对方服务收到请求。请求体里有json数据。
* (@RequestBody SpuBoundsEntity spuBounds);将请求体的json转为SpuBoundsEntity;
* 1)、@RequestBody将这个对象转为json。
* 2)、找到gulimall-coupon服务,给/coupon/spubounds/save发送请求。
* 将上一步转的json放在请求体位置,发送请求;
* 3)、对方服务收到请求。请求体里有json数据。
* (@RequestBody SpuBoundsEntity spuBounds);将请求体的json转为SpuBoundsEntity;
* 只要json数据模型是兼容的。双方服务无需使用同一个to
*
* @param spuBoundTo
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsy.common.to.SkuReductionTo;
import com.zsy.common.to.SpuBoundTo;
import com.zsy.common.utils.PageUtils;
import com.zsy.common.utils.Query;
import com.zsy.common.utils.R;
import com.zsy.product.dao.SpuInfoDao;
import com.zsy.product.entity.SpuInfoEntity;
import com.zsy.product.entity.*;
import com.zsy.product.feign.CouponFeignService;
import com.zsy.product.service.*;
import com.zsy.product.vo.SpuSaveVo;
import com.zsy.product.vo.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author ZSY
Expand Down Expand Up @@ -42,8 +51,8 @@ public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> i
@Autowired
SkuSaleAttrValueService skuSaleAttrValueService;

// @Autowired
// CouponFeignService couponFeignService;
@Autowired
CouponFeignService couponFeignService;

@Override
public PageUtils queryPage(Map<String, Object> params) {
Expand All @@ -64,118 +73,112 @@ public PageUtils queryPage(Map<String, Object> params) {
@Override
public void saveSpuInfo(SpuSaveVo vo) {

// //1、保存spu基本信息 pms_spu_info
// SpuInfoEntity infoEntity = new SpuInfoEntity();
// BeanUtils.copyProperties(vo,infoEntity);
// infoEntity.setCreateTime(new Date());
// infoEntity.setUpdateTime(new Date());
// this.saveBaseSpuInfo(infoEntity);
//
// //2、保存Spu的描述图片 pms_spu_info_desc
// List<String> decript = vo.getDecript();
// SpuInfoDescEntity descEntity = new SpuInfoDescEntity();
// descEntity.setSpuId(infoEntity.getId());
// descEntity.setDecript(String.join(",",decript));
// spuInfoDescService.saveSpuInfoDesc(descEntity);
//
//
//
// //3、保存spu的图片集 pms_spu_images
// List<String> images = vo.getImages();
// imagesService.saveImages(infoEntity.getId(),images);
//
//
// //4、保存spu的规格参数;pms_product_attr_value
// List<BaseAttrs> baseAttrs = vo.getBaseAttrs();
// List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
// ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
// valueEntity.setAttrId(attr.getAttrId());
// AttrEntity id = attrService.getById(attr.getAttrId());
// valueEntity.setAttrName(id.getAttrName());
// valueEntity.setAttrValue(attr.getAttrValues());
// valueEntity.setQuickShow(attr.getShowDesc());
// valueEntity.setSpuId(infoEntity.getId());
//
// return valueEntity;
// }).collect(Collectors.toList());
// attrValueService.saveProductAttr(collect);
//
//
// //5、保存spu的积分信息;gulimall_sms->sms_spu_bounds
// Bounds bounds = vo.getBounds();
// SpuBoundTo spuBoundTo = new SpuBoundTo();
// BeanUtils.copyProperties(bounds,spuBoundTo);
// spuBoundTo.setSpuId(infoEntity.getId());
// R r = couponFeignService.saveSpuBounds(spuBoundTo);
// if(r.getCode() != 0){
// log.error("远程保存spu积分信息失败");
// }
//
//
// //5、保存当前spu对应的所有sku信息;
//
// List<Skus> skus = vo.getSkus();
// if(skus!=null && skus.size()>0){
// skus.forEach(item->{
// String defaultImg = "";
// for (Images image : item.getImages()) {
// if(image.getDefaultImg() == 1){
// defaultImg = image.getImgUrl();
// }
// }
// // private String skuName;
// // private BigDecimal price;
// // private String skuTitle;
// // private String skuSubtitle;
// SkuInfoEntity skuInfoEntity = new SkuInfoEntity();
// BeanUtils.copyProperties(item,skuInfoEntity);
// skuInfoEntity.setBrandId(infoEntity.getBrandId());
// skuInfoEntity.setCatalogId(infoEntity.getCatalogId());
// skuInfoEntity.setSaleCount(0L);
// skuInfoEntity.setSpuId(infoEntity.getId());
// skuInfoEntity.setSkuDefaultImg(defaultImg);
// //5.1)、sku的基本信息;pms_sku_info
// skuInfoService.saveSkuInfo(skuInfoEntity);
//
// Long skuId = skuInfoEntity.getSkuId();
//
// List<SkuImagesEntity> imagesEntities = item.getImages().stream().map(img -> {
// SkuImagesEntity skuImagesEntity = new SkuImagesEntity();
// skuImagesEntity.setSkuId(skuId);
// skuImagesEntity.setImgUrl(img.getImgUrl());
// skuImagesEntity.setDefaultImg(img.getDefaultImg());
// return skuImagesEntity;
// }).filter(entity->{
// //返回true就是需要,false就是剔除
// return !StringUtils.isEmpty(entity.getImgUrl());
// }).collect(Collectors.toList());
// //5.2)、sku的图片信息;pms_sku_image
// skuImagesService.saveBatch(imagesEntities);
// //TODO 没有图片路径的无需保存
//
// List<Attr> attr = item.getAttr();
// List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = attr.stream().map(a -> {
// SkuSaleAttrValueEntity attrValueEntity = new SkuSaleAttrValueEntity();
// BeanUtils.copyProperties(a, attrValueEntity);
// attrValueEntity.setSkuId(skuId);
//
// return attrValueEntity;
// }).collect(Collectors.toList());
// //5.3)、sku的销售属性信息:pms_sku_sale_attr_value
// skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);
//
// // //5.4)、sku的优惠、满减等信息;gulimall_sms->sms_sku_ladder\sms_sku_full_reduction\sms_member_price
// SkuReductionTo skuReductionTo = new SkuReductionTo();
// BeanUtils.copyProperties(item,skuReductionTo);
// skuReductionTo.setSkuId(skuId);
// if(skuReductionTo.getFullCount() >0 || skuReductionTo.getFullPrice().compareTo(new BigDecimal("0")) == 1){
// R r1 = couponFeignService.saveSkuReduction(skuReductionTo);
// if(r1.getCode() != 0){
// log.error("远程保存sku优惠信息失败");
// }
// }
// });
// }
//1、保存spu基本信息 pms_spu_info
SpuInfoEntity infoEntity = new SpuInfoEntity();
BeanUtils.copyProperties(vo, infoEntity);
infoEntity.setCreateTime(new Date());
infoEntity.setUpdateTime(new Date());
this.saveBaseSpuInfo(infoEntity);

//2、保存Spu的描述图片 pms_spu_info_desc
List<String> decript = vo.getDecript();
SpuInfoDescEntity descEntity = new SpuInfoDescEntity();
descEntity.setSpuId(infoEntity.getId());
descEntity.setDecript(String.join(",", decript));
spuInfoDescService.saveSpuInfoDesc(descEntity);

//3、保存spu的图片集 pms_spu_images
List<String> images = vo.getImages();
imagesService.saveImages(infoEntity.getId(), images);

//4、保存spu的规格参数;pms_product_attr_value
List<BaseAttrs> baseAttrs = vo.getBaseAttrs();
List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
valueEntity.setAttrId(attr.getAttrId());
AttrEntity id = attrService.getById(attr.getAttrId());
valueEntity.setAttrName(id.getAttrName());
valueEntity.setAttrValue(attr.getAttrValues());
valueEntity.setQuickShow(attr.getShowDesc());
valueEntity.setSpuId(infoEntity.getId());

return valueEntity;
}).collect(Collectors.toList());
attrValueService.saveProductAttr(collect);

//5、保存spu的积分信息;gulimall_sms->sms_spu_bounds
Bounds bounds = vo.getBounds();
SpuBoundTo spuBoundTo = new SpuBoundTo();
BeanUtils.copyProperties(bounds, spuBoundTo);
spuBoundTo.setSpuId(infoEntity.getId());
R r = couponFeignService.saveSpuBounds(spuBoundTo);
if (r.getCode() != 0) {
log.error("远程保存spu积分信息失败");
}

//5、保存当前spu对应的所有sku信息;
List<Skus> skus = vo.getSkus();
if (skus != null && skus.size() > 0) {
skus.forEach(item -> {
String defaultImg = "";
for (Images image : item.getImages()) {
if (image.getDefaultImg() == 1) {
defaultImg = image.getImgUrl();
}
}
// private String skuName;
// private BigDecimal price;
// private String skuTitle;
// private String skuSubtitle;
SkuInfoEntity skuInfoEntity = new SkuInfoEntity();
BeanUtils.copyProperties(item, skuInfoEntity);
skuInfoEntity.setBrandId(infoEntity.getBrandId());
skuInfoEntity.setCatalogId(infoEntity.getCatalogId());
skuInfoEntity.setSaleCount(0L);
skuInfoEntity.setSpuId(infoEntity.getId());
skuInfoEntity.setSkuDefaultImg(defaultImg);
//5.1)、sku的基本信息;pms_sku_info
skuInfoService.saveSkuInfo(skuInfoEntity);

Long skuId = skuInfoEntity.getSkuId();

List<SkuImagesEntity> imagesEntities = item.getImages().stream().map(img -> {
SkuImagesEntity skuImagesEntity = new SkuImagesEntity();
skuImagesEntity.setSkuId(skuId);
skuImagesEntity.setImgUrl(img.getImgUrl());
skuImagesEntity.setDefaultImg(img.getDefaultImg());
return skuImagesEntity;
}).filter(entity -> {
//返回true就是需要,false就是剔除
return !StringUtils.isEmpty(entity.getImgUrl());
}).collect(Collectors.toList());
//5.2)、sku的图片信息;pms_sku_image
skuImagesService.saveBatch(imagesEntities);
//TODO 没有图片路径的无需保存

List<Attr> attr = item.getAttr();
List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = attr.stream().map(a -> {
SkuSaleAttrValueEntity attrValueEntity = new SkuSaleAttrValueEntity();
BeanUtils.copyProperties(a, attrValueEntity);
attrValueEntity.setSkuId(skuId);

return attrValueEntity;
}).collect(Collectors.toList());
//5.3)、sku的销售属性信息:pms_sku_sale_attr_value
skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);

// //5.4)、sku的优惠、满减等信息;gulimall_sms->sms_sku_ladder\sms_sku_full_reduction\sms_member_price
SkuReductionTo skuReductionTo = new SkuReductionTo();
BeanUtils.copyProperties(item, skuReductionTo);
skuReductionTo.setSkuId(skuId);
if (skuReductionTo.getFullCount() > 0 || skuReductionTo.getFullPrice().compareTo(new BigDecimal("0")) == 1) {
R r1 = couponFeignService.saveSkuReduction(skuReductionTo);
if (r1.getCode() != 0) {
log.error("远程保存sku优惠信息失败");
}
}
});
}
}

@Override
Expand Down
14 changes: 8 additions & 6 deletions renren-fast-vue/src/views/modules/product/spuadd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,15 @@ export default {
//先对表单的baseAttrs进行初始化
data.data.forEach(item => {
let attrArray = [];
item.attrs.forEach(attr => {
attrArray.push({
attrId: attr.attrId,
attrValues: "",
showDesc: attr.showDesc
if (item.attrs) {
item.attrs.forEach(attr => {
attrArray.push({
attrId: attr.attrId,
attrValues: "",
showDesc: attr.showDesc
});
});
});
}
this.dataResp.baseAttrs.push(attrArray);
});
this.dataResp.steped[0] = 0;
Expand Down

0 comments on commit 3fca28e

Please sign in to comment.