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