mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 17:42:20 +08:00
Merge pull request #55 from gadfly3173/array
refactor: 商品图片List换String[]
This commit is contained in:
commit
bad732ee75
@ -17,7 +17,7 @@ public class GoodsFormDTO {
|
|||||||
private Long originPrice;
|
private Long originPrice;
|
||||||
private Long price;
|
private Long price;
|
||||||
private String picUrl;
|
private String picUrl;
|
||||||
private List<String> subPicUrls;
|
private String[] subPicUrls;
|
||||||
private String description;
|
private String description;
|
||||||
private String detail;
|
private String detail;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class PmsSpu extends BaseEntity {
|
|||||||
private Long price;
|
private Long price;
|
||||||
private Integer sales;
|
private Integer sales;
|
||||||
private String picUrl;
|
private String picUrl;
|
||||||
private String album;
|
private String[] album;
|
||||||
private String unit;
|
private String unit;
|
||||||
private String description;
|
private String description;
|
||||||
private String detail;
|
private String detail;
|
||||||
|
@ -30,7 +30,7 @@ public class GoodsDetailVO {
|
|||||||
|
|
||||||
private String picUrl;
|
private String picUrl;
|
||||||
|
|
||||||
private List<String> subPicUrls;
|
private String[] subPicUrls;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import com.youlai.mall.pms.pojo.dto.app.LockStockDTO;
|
|||||||
import com.youlai.mall.pms.service.IPmsSkuService;
|
import com.youlai.mall.pms.service.IPmsSkuService;
|
||||||
import com.youlai.mall.pms.tcc.service.SeataTccSkuService;
|
import com.youlai.mall.pms.tcc.service.SeataTccSkuService;
|
||||||
import io.seata.spring.annotation.GlobalTransactional;
|
import io.seata.spring.annotation.GlobalTransactional;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.redisson.api.RLock;
|
import org.redisson.api.RLock;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
|
@ -122,13 +122,6 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
|
|||||||
|
|
||||||
BeanUtil.copyProperties(spu, goodsDetailVO);
|
BeanUtil.copyProperties(spu, goodsDetailVO);
|
||||||
|
|
||||||
// 商品图册JSON字符串转集合
|
|
||||||
String album = spu.getAlbum();
|
|
||||||
if (StrUtil.isNotBlank(album)) {
|
|
||||||
List<String> picUrls = JSONUtil.toList(album, String.class);
|
|
||||||
goodsDetailVO.setSubPicUrls(picUrls);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 商品属性列表
|
// 商品属性列表
|
||||||
List<PmsSpuAttributeValue> attrList = iPmsSpuAttributeValueService.list(new LambdaQueryWrapper<PmsSpuAttributeValue>()
|
List<PmsSpuAttributeValue> attrList = iPmsSpuAttributeValueService.list(new LambdaQueryWrapper<PmsSpuAttributeValue>()
|
||||||
.eq(PmsSpuAttributeValue::getSpuId, id)
|
.eq(PmsSpuAttributeValue::getSpuId, id)
|
||||||
@ -185,7 +178,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
|
|||||||
PmsSpu pmsSpu = new PmsSpu();
|
PmsSpu pmsSpu = new PmsSpu();
|
||||||
BeanUtil.copyProperties(goods, pmsSpu);
|
BeanUtil.copyProperties(goods, pmsSpu);
|
||||||
// 商品图册
|
// 商品图册
|
||||||
pmsSpu.setAlbum(JSONUtil.toJsonStr(goods.getSubPicUrls()));
|
pmsSpu.setAlbum(goods.getSubPicUrls());
|
||||||
boolean result = this.saveOrUpdate(pmsSpu);
|
boolean result = this.saveOrUpdate(pmsSpu);
|
||||||
return result ? pmsSpu.getId() : 0;
|
return result ? pmsSpu.getId() : 0;
|
||||||
}
|
}
|
||||||
@ -202,12 +195,12 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
|
|||||||
private boolean saveSku(Long goodsId, List<PmsSku> skuList, Map<String, Long> specTempIdIdMap) {
|
private boolean saveSku(Long goodsId, List<PmsSku> skuList, Map<String, Long> specTempIdIdMap) {
|
||||||
|
|
||||||
// 删除SKU
|
// 删除SKU
|
||||||
List<Long> formSkuIds = skuList.stream().map(item -> item.getId()).collect(Collectors.toList());
|
List<Long> formSkuIds = skuList.stream().map(PmsSku::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
List<Long> dbSkuIds = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>()
|
List<Long> dbSkuIds = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>()
|
||||||
.eq(PmsSku::getSpuId, goodsId)
|
.eq(PmsSku::getSpuId, goodsId)
|
||||||
.select(PmsSku::getId))
|
.select(PmsSku::getId))
|
||||||
.stream().map(item -> item.getId())
|
.stream().map(PmsSku::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
List<Long> removeSkuIds = dbSkuIds.stream().filter(dbSkuId -> !formSkuIds.contains(dbSkuId)).collect(Collectors.toList());
|
List<Long> removeSkuIds = dbSkuIds.stream().filter(dbSkuId -> !formSkuIds.contains(dbSkuId)).collect(Collectors.toList());
|
||||||
@ -219,7 +212,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
|
|||||||
// 新增/修改SKU
|
// 新增/修改SKU
|
||||||
List<PmsSku> pmsSkuList = skuList.stream().map(sku -> {
|
List<PmsSku> pmsSkuList = skuList.stream().map(sku -> {
|
||||||
// 临时规格ID转换
|
// 临时规格ID转换
|
||||||
String specIds = Arrays.asList(sku.getSpecIds().split("\\|")).stream()
|
String specIds = Arrays.stream(sku.getSpecIds().split("\\|"))
|
||||||
.map(specId ->
|
.map(specId ->
|
||||||
specId.startsWith(PmsConstants.TEMP_ID_PREFIX) ? specTempIdIdMap.get(specId) + "" : specId
|
specId.startsWith(PmsConstants.TEMP_ID_PREFIX) ? specTempIdIdMap.get(specId) + "" : specId
|
||||||
)
|
)
|
||||||
@ -249,7 +242,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
|
|||||||
.eq(PmsSpuAttributeValue::getSpuId, goodsId)
|
.eq(PmsSpuAttributeValue::getSpuId, goodsId)
|
||||||
.eq(PmsSpuAttributeValue::getType, AttributeTypeEnum.ATTRIBUTE.getValue())
|
.eq(PmsSpuAttributeValue::getType, AttributeTypeEnum.ATTRIBUTE.getValue())
|
||||||
.select(PmsSpuAttributeValue::getId)
|
.select(PmsSpuAttributeValue::getId)
|
||||||
).stream().map(item -> item.getId()).collect(Collectors.toList());
|
).stream().map(PmsSpuAttributeValue::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
List<Long> removeAttrValIds = dbAttrValIds.stream().filter(id -> !formAttrValIds.contains(id)).collect(Collectors.toList());
|
List<Long> removeAttrValIds = dbAttrValIds.stream().filter(id -> !formAttrValIds.contains(id)).collect(Collectors.toList());
|
||||||
if (CollectionUtil.isNotEmpty(removeAttrValIds)) {
|
if (CollectionUtil.isNotEmpty(removeAttrValIds)) {
|
||||||
@ -289,7 +282,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
|
|||||||
.eq(PmsSpuAttributeValue::getSpuId, goodsId)
|
.eq(PmsSpuAttributeValue::getSpuId, goodsId)
|
||||||
.eq(PmsSpuAttributeValue::getType, AttributeTypeEnum.SPECIFICATION.getValue())
|
.eq(PmsSpuAttributeValue::getType, AttributeTypeEnum.SPECIFICATION.getValue())
|
||||||
.select(PmsSpuAttributeValue::getId)
|
.select(PmsSpuAttributeValue::getId)
|
||||||
).stream().map(item -> item.getId()).collect(Collectors.toList());
|
).stream().map(PmsSpuAttributeValue::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
List<Long> removeAttrValIds = dbSpecValIds.stream().filter(id -> !formSpecValIds.contains(id)).collect(Collectors.toList());
|
List<Long> removeAttrValIds = dbSpecValIds.stream().filter(id -> !formSpecValIds.contains(id)).collect(Collectors.toList());
|
||||||
if (CollectionUtil.isNotEmpty(removeAttrValIds)) {
|
if (CollectionUtil.isNotEmpty(removeAttrValIds)) {
|
||||||
|
@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.youlai.mall.pms.common.enums.AttributeTypeEnum;
|
import com.youlai.mall.pms.common.enums.AttributeTypeEnum;
|
||||||
@ -20,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -50,8 +50,8 @@ public class GoodsServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implemen
|
|||||||
if (StrUtil.isNotBlank(pmsSpu.getPicUrl())) {
|
if (StrUtil.isNotBlank(pmsSpu.getPicUrl())) {
|
||||||
album.add(pmsSpu.getPicUrl());
|
album.add(pmsSpu.getPicUrl());
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(pmsSpu.getAlbum())) {
|
if (pmsSpu.getAlbum() != null && pmsSpu.getAlbum().length > 0) {
|
||||||
album.addAll(JSONUtil.parseArray(pmsSpu.getAlbum()).toList(String.class));
|
album.addAll(Arrays.asList(pmsSpu.getAlbum()));
|
||||||
goodsInfo.setAlbum(album);
|
goodsInfo.setAlbum(album);
|
||||||
}
|
}
|
||||||
goodsDetailVO.setGoodsInfo(goodsInfo);
|
goodsDetailVO.setGoodsInfo(goodsInfo);
|
||||||
@ -79,7 +79,7 @@ public class GoodsServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implemen
|
|||||||
List<GoodsDetailVO.Specification> specList = new ArrayList<>();
|
List<GoodsDetailVO.Specification> specList = new ArrayList<>();
|
||||||
// 规格Map [key:"颜色",value:[{id:1,value:"黑"},{id:2,value:"白"}]]
|
// 规格Map [key:"颜色",value:[{id:1,value:"黑"},{id:2,value:"白"}]]
|
||||||
Map<String, List<PmsSpuAttributeValue>> specValueMap = specSourceList.stream()
|
Map<String, List<PmsSpuAttributeValue>> specValueMap = specSourceList.stream()
|
||||||
.collect(Collectors.groupingBy(item -> item.getName()));
|
.collect(Collectors.groupingBy(PmsSpuAttributeValue::getName));
|
||||||
|
|
||||||
for (Map.Entry<String, List<PmsSpuAttributeValue>> entry : specValueMap.entrySet()) {
|
for (Map.Entry<String, List<PmsSpuAttributeValue>> entry : specValueMap.entrySet()) {
|
||||||
String specName = entry.getKey();
|
String specName = entry.getKey();
|
||||||
|
Loading…
Reference in New Issue
Block a user