From b425a85dfb20071f7e1d9416cc62714b330b2a81 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Mon, 16 Aug 2021 15:13:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20List=E6=8D=A2String[]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/pms/pojo/dto/admin/GoodsFormDTO.java | 2 +- .../youlai/mall/pms/pojo/entity/PmsSpu.java | 2 +- .../mall/pms/pojo/vo/admin/GoodsDetailVO.java | 2 +- .../pms/service/impl/PmsSkuServiceImpl.java | 1 - .../pms/service/impl/PmsSpuServiceImpl.java | 19 ++++++------------- .../pms/serviceapp/impl/GoodsServiceImpl.java | 8 ++++---- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/admin/GoodsFormDTO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/admin/GoodsFormDTO.java index 527eb5b5d..35c68c4db 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/admin/GoodsFormDTO.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/dto/admin/GoodsFormDTO.java @@ -17,7 +17,7 @@ public class GoodsFormDTO { private Long originPrice; private Long price; private String picUrl; - private List subPicUrls; + private String[] subPicUrls; private String description; private String detail; diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/entity/PmsSpu.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/entity/PmsSpu.java index 38f31735a..13313ca5c 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/entity/PmsSpu.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/entity/PmsSpu.java @@ -24,7 +24,7 @@ public class PmsSpu extends BaseEntity { private Long price; private Integer sales; private String picUrl; - private String album; + private String[] album; private String unit; private String description; private String detail; diff --git a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/vo/admin/GoodsDetailVO.java b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/vo/admin/GoodsDetailVO.java index 2884f89d4..4bcbb7361 100644 --- a/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/vo/admin/GoodsDetailVO.java +++ b/mall-pms/pms-api/src/main/java/com/youlai/mall/pms/pojo/vo/admin/GoodsDetailVO.java @@ -30,7 +30,7 @@ public class GoodsDetailVO { private String picUrl; - private List subPicUrls; + private String[] subPicUrls; private String description; diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java index dc53422e8..a18fbfd78 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSkuServiceImpl.java @@ -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.tcc.service.SeataTccSkuService; import io.seata.spring.annotation.GlobalTransactional; -import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSpuServiceImpl.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSpuServiceImpl.java index 8432bc874..bba33ea3a 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSpuServiceImpl.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/service/impl/PmsSpuServiceImpl.java @@ -122,13 +122,6 @@ public class PmsSpuServiceImpl extends ServiceImpl impleme BeanUtil.copyProperties(spu, goodsDetailVO); - // 商品图册JSON字符串转集合 - String album = spu.getAlbum(); - if (StrUtil.isNotBlank(album)) { - List picUrls = JSONUtil.toList(album, String.class); - goodsDetailVO.setSubPicUrls(picUrls); - } - // 商品属性列表 List attrList = iPmsSpuAttributeValueService.list(new LambdaQueryWrapper() .eq(PmsSpuAttributeValue::getSpuId, id) @@ -185,7 +178,7 @@ public class PmsSpuServiceImpl extends ServiceImpl impleme PmsSpu pmsSpu = new PmsSpu(); BeanUtil.copyProperties(goods, pmsSpu); // 商品图册 - pmsSpu.setAlbum(JSONUtil.toJsonStr(goods.getSubPicUrls())); + pmsSpu.setAlbum(goods.getSubPicUrls()); boolean result = this.saveOrUpdate(pmsSpu); return result ? pmsSpu.getId() : 0; } @@ -202,12 +195,12 @@ public class PmsSpuServiceImpl extends ServiceImpl impleme private boolean saveSku(Long goodsId, List skuList, Map specTempIdIdMap) { // 删除SKU - List formSkuIds = skuList.stream().map(item -> item.getId()).collect(Collectors.toList()); + List formSkuIds = skuList.stream().map(PmsSku::getId).collect(Collectors.toList()); List dbSkuIds = iPmsSkuService.list(new LambdaQueryWrapper() .eq(PmsSku::getSpuId, goodsId) .select(PmsSku::getId)) - .stream().map(item -> item.getId()) + .stream().map(PmsSku::getId) .collect(Collectors.toList()); List removeSkuIds = dbSkuIds.stream().filter(dbSkuId -> !formSkuIds.contains(dbSkuId)).collect(Collectors.toList()); @@ -219,7 +212,7 @@ public class PmsSpuServiceImpl extends ServiceImpl impleme // 新增/修改SKU List pmsSkuList = skuList.stream().map(sku -> { // 临时规格ID转换 - String specIds = Arrays.asList(sku.getSpecIds().split("\\|")).stream() + String specIds = Arrays.stream(sku.getSpecIds().split("\\|")) .map(specId -> specId.startsWith(PmsConstants.TEMP_ID_PREFIX) ? specTempIdIdMap.get(specId) + "" : specId ) @@ -249,7 +242,7 @@ public class PmsSpuServiceImpl extends ServiceImpl impleme .eq(PmsSpuAttributeValue::getSpuId, goodsId) .eq(PmsSpuAttributeValue::getType, AttributeTypeEnum.ATTRIBUTE.getValue()) .select(PmsSpuAttributeValue::getId) - ).stream().map(item -> item.getId()).collect(Collectors.toList()); + ).stream().map(PmsSpuAttributeValue::getId).collect(Collectors.toList()); List removeAttrValIds = dbAttrValIds.stream().filter(id -> !formAttrValIds.contains(id)).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(removeAttrValIds)) { @@ -289,7 +282,7 @@ public class PmsSpuServiceImpl extends ServiceImpl impleme .eq(PmsSpuAttributeValue::getSpuId, goodsId) .eq(PmsSpuAttributeValue::getType, AttributeTypeEnum.SPECIFICATION.getValue()) .select(PmsSpuAttributeValue::getId) - ).stream().map(item -> item.getId()).collect(Collectors.toList()); + ).stream().map(PmsSpuAttributeValue::getId).collect(Collectors.toList()); List removeAttrValIds = dbSpecValIds.stream().filter(id -> !formSpecValIds.contains(id)).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(removeAttrValIds)) { diff --git a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/serviceapp/impl/GoodsServiceImpl.java b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/serviceapp/impl/GoodsServiceImpl.java index b35b1cd77..7e505b04f 100644 --- a/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/serviceapp/impl/GoodsServiceImpl.java +++ b/mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/serviceapp/impl/GoodsServiceImpl.java @@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.youlai.mall.pms.common.enums.AttributeTypeEnum; @@ -20,6 +19,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -50,8 +50,8 @@ public class GoodsServiceImpl extends ServiceImpl implemen if (StrUtil.isNotBlank(pmsSpu.getPicUrl())) { album.add(pmsSpu.getPicUrl()); } - if (StrUtil.isNotBlank(pmsSpu.getAlbum())) { - album.addAll(JSONUtil.parseArray(pmsSpu.getAlbum()).toList(String.class)); + if (pmsSpu.getAlbum() != null && pmsSpu.getAlbum().length > 0) { + album.addAll(Arrays.asList(pmsSpu.getAlbum())); goodsInfo.setAlbum(album); } goodsDetailVO.setGoodsInfo(goodsInfo); @@ -79,7 +79,7 @@ public class GoodsServiceImpl extends ServiceImpl implemen List specList = new ArrayList<>(); // 规格Map [key:"颜色",value:[{id:1,value:"黑"},{id:2,value:"白"}]] Map> specValueMap = specSourceList.stream() - .collect(Collectors.groupingBy(item -> item.getName())); + .collect(Collectors.groupingBy(PmsSpuAttributeValue::getName)); for (Map.Entry> entry : specValueMap.entrySet()) { String specName = entry.getKey();