修复商品多规格的bug
This commit is contained in:
@@ -110,6 +110,7 @@ public class GoodsController extends BaseController {
|
|||||||
@ApiOperation("修改商品记录表")
|
@ApiOperation("修改商品记录表")
|
||||||
@PutMapping()
|
@PutMapping()
|
||||||
public ApiResult<?> update(@RequestBody Goods goods) {
|
public ApiResult<?> update(@RequestBody Goods goods) {
|
||||||
|
System.out.println("getGoodsSpec = " + goods.getGoodsSpec());
|
||||||
if (goodsService.updateById(goods)) {
|
if (goodsService.updateById(goods)) {
|
||||||
// 删除旧信息
|
// 删除旧信息
|
||||||
goodsSpecService.remove(new LambdaQueryWrapper<GoodsSpec>().eq(GoodsSpec::getGoodsId, goods.getGoodsId()));
|
goodsSpecService.remove(new LambdaQueryWrapper<GoodsSpec>().eq(GoodsSpec::getGoodsId, goods.getGoodsId()));
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
package com.gxwebsoft.shop.controller;
|
package com.gxwebsoft.shop.controller;
|
||||||
|
|
||||||
import com.gxwebsoft.common.core.web.BaseController;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.gxwebsoft.shop.service.GoodsSkuService;
|
|
||||||
import com.gxwebsoft.shop.entity.GoodsSku;
|
|
||||||
import com.gxwebsoft.shop.param.GoodsSkuParam;
|
|
||||||
import com.gxwebsoft.common.core.web.ApiResult;
|
import com.gxwebsoft.common.core.web.ApiResult;
|
||||||
import com.gxwebsoft.common.core.web.PageResult;
|
import com.gxwebsoft.common.core.web.BaseController;
|
||||||
import com.gxwebsoft.common.core.web.PageParam;
|
|
||||||
import com.gxwebsoft.common.core.web.BatchParam;
|
import com.gxwebsoft.common.core.web.BatchParam;
|
||||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
import com.gxwebsoft.common.core.web.PageResult;
|
||||||
import com.gxwebsoft.common.system.entity.User;
|
import com.gxwebsoft.shop.entity.GoodsSku;
|
||||||
|
import com.gxwebsoft.shop.entity.GoodsSkuVO;
|
||||||
|
import com.gxwebsoft.shop.param.GoodsSkuParam;
|
||||||
|
import com.gxwebsoft.shop.service.GoodsSkuService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品sku列表控制器
|
* 商品sku列表控制器
|
||||||
@@ -31,6 +31,52 @@ public class GoodsSkuController extends BaseController {
|
|||||||
@Resource
|
@Resource
|
||||||
private GoodsSkuService goodsSkuService;
|
private GoodsSkuService goodsSkuService;
|
||||||
|
|
||||||
|
@ApiOperation("根据商品spec生成SKU列表")
|
||||||
|
@PostMapping("/generateGoodsSku")
|
||||||
|
public ApiResult<List<GoodsSku>> generateGoodsSku(@RequestBody List<GoodsSkuVO> voList) {
|
||||||
|
List<List<String>> resultList = new ArrayList<>();
|
||||||
|
voList.forEach(d -> {
|
||||||
|
resultList.add(d.getDetail());
|
||||||
|
});
|
||||||
|
System.out.println("resultList = " + resultList);
|
||||||
|
List<String> combine = generateSku(resultList,0,"",new ArrayList<>());
|
||||||
|
|
||||||
|
List<GoodsSku> goodsSkuList = new ArrayList<>();
|
||||||
|
for (String sku : combine) {
|
||||||
|
System.out.println(sku);
|
||||||
|
GoodsSku goodsSku = new GoodsSku();
|
||||||
|
goodsSku.setSku(sku);
|
||||||
|
goodsSku.setUnique(UUID.randomUUID().toString());
|
||||||
|
goodsSku.setImages(new ArrayList<>());
|
||||||
|
goodsSkuList.add(goodsSku);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(goodsSkuList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据属性值生成sku
|
||||||
|
*
|
||||||
|
* @param list 属性值列表
|
||||||
|
* @param index 下标
|
||||||
|
* @param str 初始化数据
|
||||||
|
* @param newObjs 新obj
|
||||||
|
*/
|
||||||
|
public static List<String> generateSku(List<List<String>> list, int index, String str, List<String> newObjs) {
|
||||||
|
if (index == list.size()) {
|
||||||
|
newObjs.add(str);
|
||||||
|
return newObjs;
|
||||||
|
}
|
||||||
|
for (String dataStr : list.get(index)) {
|
||||||
|
if (StringUtils.isBlank(str)) {
|
||||||
|
generateSku(list, index + 1, str + dataStr, newObjs);
|
||||||
|
} else {
|
||||||
|
generateSku(list, index + 1, str + "," + dataStr, newObjs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newObjs;
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation("分页查询商品sku列表")
|
@ApiOperation("分页查询商品sku列表")
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
public ApiResult<PageResult<GoodsSku>> page(GoodsSkuParam param) {
|
public ApiResult<PageResult<GoodsSku>> page(GoodsSkuParam param) {
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public class Goods implements Serializable {
|
|||||||
|
|
||||||
@ApiModelProperty(value = "商品规格")
|
@ApiModelProperty(value = "商品规格")
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<GoodsSpec> goodsSpecs;
|
private GoodsSpec goodsSpec;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品sku列表")
|
@ApiModelProperty(value = "商品sku列表")
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package com.gxwebsoft.shop.entity;
|
package com.gxwebsoft.shop.entity;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
@@ -33,20 +36,8 @@ public class GoodsSku implements Serializable {
|
|||||||
@ApiModelProperty(value = "商品ID")
|
@ApiModelProperty(value = "商品ID")
|
||||||
private Integer goodsId;
|
private Integer goodsId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格组ID")
|
@ApiModelProperty(value = "商品属性索引值")
|
||||||
private Integer specId;
|
private String sku;
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值ID")
|
|
||||||
private Integer specValueId;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值0")
|
|
||||||
private String specValue0;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值1")
|
|
||||||
private String specValue1;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值2")
|
|
||||||
private String specValue2;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品图片")
|
@ApiModelProperty(value = "商品图片")
|
||||||
private String image;
|
private String image;
|
||||||
@@ -63,6 +54,21 @@ public class GoodsSku implements Serializable {
|
|||||||
@ApiModelProperty(value = "sku编码")
|
@ApiModelProperty(value = "sku编码")
|
||||||
private String skuNo;
|
private String skuNo;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "唯一值")
|
||||||
|
private String unique;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "成本价")
|
||||||
|
private BigDecimal cost;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品条码")
|
||||||
|
private String barCode;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "重量")
|
||||||
|
private BigDecimal weight;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "体积")
|
||||||
|
private BigDecimal volume;
|
||||||
|
|
||||||
@ApiModelProperty(value = "状态, 0正常, 1异常")
|
@ApiModelProperty(value = "状态, 0正常, 1异常")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@@ -75,4 +81,8 @@ public class GoodsSku implements Serializable {
|
|||||||
@ApiModelProperty(value = "创建时间")
|
@ApiModelProperty(value = "创建时间")
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品图片对象")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<Object> images;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.gxwebsoft.shop.entity;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class GoodsSkuVO implements Serializable {
|
||||||
|
|
||||||
|
@ApiModelProperty("规格名称")
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
@ApiModelProperty("规格值")
|
||||||
|
private List<String> detail;
|
||||||
|
@Data
|
||||||
|
public static class Payload {
|
||||||
|
private String value;
|
||||||
|
private List<String> detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,23 +31,6 @@ public class GoodsSkuParam extends BaseParam {
|
|||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer goodsId;
|
private Integer goodsId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格组ID")
|
|
||||||
@QueryField(type = QueryType.EQ)
|
|
||||||
private Integer specId;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值ID")
|
|
||||||
@QueryField(type = QueryType.EQ)
|
|
||||||
private Integer specValueId;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值0")
|
|
||||||
private String specValue0;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值1")
|
|
||||||
private String specValue1;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "规格值2")
|
|
||||||
private String specValue2;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品图片")
|
@ApiModelProperty(value = "商品图片")
|
||||||
private String image;
|
private String image;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.gxwebsoft.common.core.web.PageResult;
|
|||||||
import com.gxwebsoft.shop.entity.GoodsSku;
|
import com.gxwebsoft.shop.entity.GoodsSku;
|
||||||
import com.gxwebsoft.shop.param.GoodsSkuParam;
|
import com.gxwebsoft.shop.param.GoodsSkuParam;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,5 +39,4 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
|||||||
* @return GoodsSku
|
* @return GoodsSku
|
||||||
*/
|
*/
|
||||||
GoodsSku getByIdRel(Integer id);
|
GoodsSku getByIdRel(Integer id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
final Map<Integer, List<GoodsSpec>> collectSpecs = specs.stream().collect(Collectors.groupingBy(GoodsSpec::getGoodsId));
|
final Map<Integer, List<GoodsSpec>> collectSpecs = specs.stream().collect(Collectors.groupingBy(GoodsSpec::getGoodsId));
|
||||||
final Map<Integer, List<GoodsSku>> collectSkus = skus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId));
|
final Map<Integer, List<GoodsSku>> collectSkus = skus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId));
|
||||||
list.forEach(d -> {
|
list.forEach(d -> {
|
||||||
d.setGoodsSpecs(collectSpecs.get(d.getGoodsId()));
|
// d.setGoodsSpec(collectSpecs.get(d.getGoodsId()).get(0));
|
||||||
d.setGoodsSkus(collectSkus.get(d.getGoodsId()));
|
d.setGoodsSkus(collectSkus.get(d.getGoodsId()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -76,24 +76,9 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
@Override
|
@Override
|
||||||
public void saveBatchByAsync(Goods goods) {
|
public void saveBatchByAsync(Goods goods) {
|
||||||
// 保存商品规格
|
// 保存商品规格
|
||||||
final List<GoodsSpec> goodsSpecs = goods.getGoodsSpecs();
|
final GoodsSpec goodsSpec = goods.getGoodsSpec();
|
||||||
if (!CollectionUtils.isEmpty(goodsSpecs)) {
|
goodsSpec.setGoodsId(goods.getGoodsId());
|
||||||
goodsSpecs.forEach(d -> {
|
goodsSpecService.save(goodsSpec);
|
||||||
d.setGoodsId(goods.getGoodsId());
|
|
||||||
});
|
|
||||||
goodsSpecService.saveBatch(goodsSpecs);
|
|
||||||
// final GoodsSpec spec = goodsSpecs.get(0);
|
|
||||||
// if (spec != null) {
|
|
||||||
// final GoodsSpec goodsSpec = new GoodsSpec();
|
|
||||||
// goodsSpec.setGoodsId(goods.getGoodsId());
|
|
||||||
// goodsSpec.setSpecId(spec.getSpecId());
|
|
||||||
// goodsSpec.setSpecName(spec.getSpecName());
|
|
||||||
// goodsSpec.setSpecValue(spec.getSpecValue());
|
|
||||||
// goodsSpec.setTenantId(goods.getTenantId());
|
|
||||||
// System.out.println("goodsSpec = " + goodsSpec);
|
|
||||||
// goodsSpecService.save(goodsSpec);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存商品sku表
|
// 保存商品sku表
|
||||||
final List<GoodsSku> goodsSkus = goods.getGoodsSkus();
|
final List<GoodsSku> goodsSkus = goods.getGoodsSkus();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.gxwebsoft.shop.service.impl;
|
package com.gxwebsoft.shop.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.gxwebsoft.shop.mapper.GoodsSkuMapper;
|
import com.gxwebsoft.shop.mapper.GoodsSkuMapper;
|
||||||
import com.gxwebsoft.shop.service.GoodsSkuService;
|
import com.gxwebsoft.shop.service.GoodsSkuService;
|
||||||
@@ -9,6 +10,7 @@ import com.gxwebsoft.common.core.web.PageParam;
|
|||||||
import com.gxwebsoft.common.core.web.PageResult;
|
import com.gxwebsoft.common.core.web.PageResult;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user