修复商品多规格的bug
This commit is contained in:
@@ -11,6 +11,7 @@ import com.gxwebsoft.shop.param.GoodsSkuParam;
|
|||||||
import com.gxwebsoft.shop.service.GoodsSkuService;
|
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;
|
||||||
@@ -22,7 +23,7 @@ import java.util.UUID;
|
|||||||
* 商品sku列表控制器
|
* 商品sku列表控制器
|
||||||
*
|
*
|
||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-04-03 16:06:23
|
* @since 2024-07-26 10:49:02
|
||||||
*/
|
*/
|
||||||
@Api(tags = "商品sku列表管理")
|
@Api(tags = "商品sku列表管理")
|
||||||
@RestController
|
@RestController
|
||||||
@@ -46,7 +47,7 @@ public class GoodsSkuController extends BaseController {
|
|||||||
System.out.println(sku);
|
System.out.println(sku);
|
||||||
GoodsSku goodsSku = new GoodsSku();
|
GoodsSku goodsSku = new GoodsSku();
|
||||||
goodsSku.setSku(sku);
|
goodsSku.setSku(sku);
|
||||||
goodsSku.setUnique(UUID.randomUUID().toString());
|
goodsSku.setUuid(UUID.randomUUID().toString());
|
||||||
goodsSku.setImages(new ArrayList<>());
|
goodsSku.setImages(new ArrayList<>());
|
||||||
goodsSkuList.add(goodsSku);
|
goodsSkuList.add(goodsSku);
|
||||||
}
|
}
|
||||||
@@ -91,6 +92,7 @@ public class GoodsSkuController extends BaseController {
|
|||||||
return success(goodsSkuService.listRel(param));
|
return success(goodsSkuService.listRel(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('shop:goodsSku:list')")
|
||||||
@ApiOperation("根据id查询商品sku列表")
|
@ApiOperation("根据id查询商品sku列表")
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ApiResult<GoodsSku> get(@PathVariable("id") Integer id) {
|
public ApiResult<GoodsSku> get(@PathVariable("id") Integer id) {
|
||||||
@@ -101,11 +103,6 @@ public class GoodsSkuController extends BaseController {
|
|||||||
@ApiOperation("添加商品sku列表")
|
@ApiOperation("添加商品sku列表")
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public ApiResult<?> save(@RequestBody GoodsSku goodsSku) {
|
public ApiResult<?> save(@RequestBody GoodsSku goodsSku) {
|
||||||
// 记录当前登录用户id
|
|
||||||
// User loginUser = getLoginUser();
|
|
||||||
// if (loginUser != null) {
|
|
||||||
// goodsSku.setUserId(loginUser.getUserId());
|
|
||||||
// }
|
|
||||||
if (goodsSkuService.save(goodsSku)) {
|
if (goodsSkuService.save(goodsSku)) {
|
||||||
return success("添加成功");
|
return success("添加成功");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
* 商品sku列表
|
* 商品sku列表
|
||||||
*
|
*
|
||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-04-03 16:06:23
|
* @since 2024-07-26 10:49:02
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@@ -36,7 +36,7 @@ public class GoodsSku implements Serializable {
|
|||||||
@ApiModelProperty(value = "商品ID")
|
@ApiModelProperty(value = "商品ID")
|
||||||
private Integer goodsId;
|
private Integer goodsId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品属性索引值")
|
@ApiModelProperty(value = "商品属性索引值 (attr_value|attr_value[|....])")
|
||||||
private String sku;
|
private String sku;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品图片")
|
@ApiModelProperty(value = "商品图片")
|
||||||
@@ -48,6 +48,9 @@ public class GoodsSku implements Serializable {
|
|||||||
@ApiModelProperty(value = "市场价格")
|
@ApiModelProperty(value = "市场价格")
|
||||||
private BigDecimal salePrice;
|
private BigDecimal salePrice;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "成本价")
|
||||||
|
private BigDecimal cost;
|
||||||
|
|
||||||
@ApiModelProperty(value = "库存")
|
@ApiModelProperty(value = "库存")
|
||||||
private Integer stock;
|
private Integer stock;
|
||||||
|
|
||||||
@@ -55,10 +58,7 @@ public class GoodsSku implements Serializable {
|
|||||||
private String skuNo;
|
private String skuNo;
|
||||||
|
|
||||||
@ApiModelProperty(value = "唯一值")
|
@ApiModelProperty(value = "唯一值")
|
||||||
private String unique;
|
private String uuid;
|
||||||
|
|
||||||
@ApiModelProperty(value = "成本价")
|
|
||||||
private BigDecimal cost;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品条码")
|
@ApiModelProperty(value = "商品条码")
|
||||||
private String barCode;
|
private String barCode;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
* 商品sku列表Mapper
|
* 商品sku列表Mapper
|
||||||
*
|
*
|
||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-04-03 16:06:23
|
* @since 2024-07-26 10:49:02
|
||||||
*/
|
*/
|
||||||
public interface GoodsSkuMapper extends BaseMapper<GoodsSku> {
|
public interface GoodsSkuMapper extends BaseMapper<GoodsSku> {
|
||||||
|
|
||||||
|
|||||||
@@ -13,20 +13,8 @@
|
|||||||
<if test="param.goodsId != null">
|
<if test="param.goodsId != null">
|
||||||
AND a.goods_id = #{param.goodsId}
|
AND a.goods_id = #{param.goodsId}
|
||||||
</if>
|
</if>
|
||||||
<if test="param.specId != null">
|
<if test="param.sku != null">
|
||||||
AND a.spec_id = #{param.specId}
|
AND a.sku LIKE CONCAT('%', #{param.sku}, '%')
|
||||||
</if>
|
|
||||||
<if test="param.specValueId != null">
|
|
||||||
AND a.spec_value_id = #{param.specValueId}
|
|
||||||
</if>
|
|
||||||
<if test="param.specValue0 != null">
|
|
||||||
AND a.spec_value_0 LIKE CONCAT('%', #{param.specValue0}, '%')
|
|
||||||
</if>
|
|
||||||
<if test="param.specValue1 != null">
|
|
||||||
AND a.spec_value_1 LIKE CONCAT('%', #{param.specValue1}, '%')
|
|
||||||
</if>
|
|
||||||
<if test="param.specValue2 != null">
|
|
||||||
AND a.spec_value_2 LIKE CONCAT('%', #{param.specValue2}, '%')
|
|
||||||
</if>
|
</if>
|
||||||
<if test="param.image != null">
|
<if test="param.image != null">
|
||||||
AND a.image LIKE CONCAT('%', #{param.image}, '%')
|
AND a.image LIKE CONCAT('%', #{param.image}, '%')
|
||||||
@@ -37,12 +25,24 @@
|
|||||||
<if test="param.salePrice != null">
|
<if test="param.salePrice != null">
|
||||||
AND a.sale_price = #{param.salePrice}
|
AND a.sale_price = #{param.salePrice}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="param.cost != null">
|
||||||
|
AND a.cost = #{param.cost}
|
||||||
|
</if>
|
||||||
<if test="param.stock != null">
|
<if test="param.stock != null">
|
||||||
AND a.stock = #{param.stock}
|
AND a.stock = #{param.stock}
|
||||||
</if>
|
</if>
|
||||||
<if test="param.skuNo != null">
|
<if test="param.skuNo != null">
|
||||||
AND a.sku_no LIKE CONCAT('%', #{param.skuNo}, '%')
|
AND a.sku_no LIKE CONCAT('%', #{param.skuNo}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="param.uuid != null">
|
||||||
|
AND a.uuid LIKE CONCAT('%', #{param.uuid}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="param.weight != null">
|
||||||
|
AND a.weight = #{param.weight}
|
||||||
|
</if>
|
||||||
|
<if test="param.volume != null">
|
||||||
|
AND a.volume = #{param.volume}
|
||||||
|
</if>
|
||||||
<if test="param.status != null">
|
<if test="param.status != null">
|
||||||
AND a.status = #{param.status}
|
AND a.status = #{param.status}
|
||||||
</if>
|
</if>
|
||||||
@@ -57,6 +57,9 @@
|
|||||||
</if>
|
</if>
|
||||||
<if test="param.keywords != null">
|
<if test="param.keywords != null">
|
||||||
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
|
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
|
||||||
|
OR a.goods_id = #{param.keywords}
|
||||||
|
OR a.uuid = #{param.keywords}
|
||||||
|
OR a.sku_no = #{param.keywords}
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
* 商品sku列表查询参数
|
* 商品sku列表查询参数
|
||||||
*
|
*
|
||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-04-03 16:06:23
|
* @since 2024-07-26 10:49:02
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@@ -31,6 +31,9 @@ public class GoodsSkuParam extends BaseParam {
|
|||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer goodsId;
|
private Integer goodsId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品属性索引值 (attr_value|attr_value[|....])")
|
||||||
|
private String sku;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品图片")
|
@ApiModelProperty(value = "商品图片")
|
||||||
private String image;
|
private String image;
|
||||||
|
|
||||||
@@ -42,6 +45,10 @@ public class GoodsSkuParam extends BaseParam {
|
|||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private BigDecimal salePrice;
|
private BigDecimal salePrice;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "成本价")
|
||||||
|
@QueryField(type = QueryType.EQ)
|
||||||
|
private BigDecimal cost;
|
||||||
|
|
||||||
@ApiModelProperty(value = "库存")
|
@ApiModelProperty(value = "库存")
|
||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer stock;
|
private Integer stock;
|
||||||
@@ -49,6 +56,17 @@ public class GoodsSkuParam extends BaseParam {
|
|||||||
@ApiModelProperty(value = "sku编码")
|
@ApiModelProperty(value = "sku编码")
|
||||||
private String skuNo;
|
private String skuNo;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "唯一值")
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "重量")
|
||||||
|
@QueryField(type = QueryType.EQ)
|
||||||
|
private BigDecimal weight;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "体积")
|
||||||
|
@QueryField(type = QueryType.EQ)
|
||||||
|
private BigDecimal volume;
|
||||||
|
|
||||||
@ApiModelProperty(value = "状态, 0正常, 1异常")
|
@ApiModelProperty(value = "状态, 0正常, 1异常")
|
||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品sku列表Service
|
* 商品sku列表Service
|
||||||
*
|
*
|
||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-04-03 16:06:23
|
* @since 2024-07-26 10:49:02
|
||||||
*/
|
*/
|
||||||
public interface GoodsSkuService extends IService<GoodsSku> {
|
public interface GoodsSkuService extends IService<GoodsSku> {
|
||||||
|
|
||||||
@@ -39,4 +38,5 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
|||||||
* @return GoodsSku
|
* @return GoodsSku
|
||||||
*/
|
*/
|
||||||
GoodsSku getByIdRel(Integer id);
|
GoodsSku getByIdRel(Integer id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ 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.setGoodsSpec(collectSpecs.get(d.getGoodsId()).get(0));
|
final List<GoodsSpec> goodsSpecs = collectSpecs.get(d.getGoodsId());
|
||||||
|
if (!CollectionUtils.isEmpty(goodsSpecs)) {
|
||||||
|
d.setGoodsSpec(goodsSpecs.get(0));
|
||||||
|
}
|
||||||
d.setGoodsSkus(collectSkus.get(d.getGoodsId()));
|
d.setGoodsSkus(collectSkus.get(d.getGoodsId()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -75,18 +78,19 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveBatchByAsync(Goods goods) {
|
public void saveBatchByAsync(Goods goods) {
|
||||||
// 保存商品规格
|
// 保存商品多规格
|
||||||
final GoodsSpec goodsSpec = goods.getGoodsSpec();
|
if (goods.getSpecs().equals(1)) {
|
||||||
goodsSpec.setGoodsId(goods.getGoodsId());
|
final GoodsSpec goodsSpec = goods.getGoodsSpec();
|
||||||
goodsSpecService.save(goodsSpec);
|
goodsSpec.setGoodsId(goods.getGoodsId());
|
||||||
|
goodsSpecService.save(goodsSpec);
|
||||||
// 保存商品sku表
|
// 保存商品sku表
|
||||||
final List<GoodsSku> goodsSkus = goods.getGoodsSkus();
|
final List<GoodsSku> goodsSkus = goods.getGoodsSkus();
|
||||||
if (!CollectionUtils.isEmpty(goodsSkus)) {
|
if (!CollectionUtils.isEmpty(goodsSkus)) {
|
||||||
goodsSkus.forEach(d -> {
|
goodsSkus.forEach(d -> {
|
||||||
d.setGoodsId(goods.getGoodsId());
|
d.setGoodsId(goods.getGoodsId());
|
||||||
});
|
});
|
||||||
goodsSkuService.saveBatch(goodsSkus);
|
goodsSkuService.saveBatch(goodsSkus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@@ -10,14 +9,13 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品sku列表Service实现
|
* 商品sku列表Service实现
|
||||||
*
|
*
|
||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-04-03 16:06:23
|
* @since 2024-07-26 10:49:02
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> implements GoodsSkuService {
|
public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> implements GoodsSkuService {
|
||||||
|
|||||||
@@ -50,9 +50,9 @@ public class ShopGenerator {
|
|||||||
private static final String[] TABLE_NAMES = new String[]{
|
private static final String[] TABLE_NAMES = new String[]{
|
||||||
// "shop_spec",
|
// "shop_spec",
|
||||||
// "shop_spec_value",
|
// "shop_spec_value",
|
||||||
"shop_goods",
|
// "shop_goods",
|
||||||
// "shop_goods_spec",
|
// "shop_goods_spec",
|
||||||
// "shop_goods_sku",
|
"shop_goods_sku",
|
||||||
// "shop_goods_category",
|
// "shop_goods_category",
|
||||||
// "shop_goods_coupon",
|
// "shop_goods_coupon",
|
||||||
// "shop_goods_description",
|
// "shop_goods_description",
|
||||||
|
|||||||
Reference in New Issue
Block a user