ソースを参照

解决海博添加商品问题

fubojin 11 時間 前
コミット
9777b9ed81

+ 2 - 2
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/ChannelProdImportVO.java

@@ -18,12 +18,12 @@ import java.math.BigDecimal;
 public class ChannelProdImportVO {
 
 
-    @ExcelProperty(value = "海博商品ID", index = 0)
+    @ExcelProperty(value = {"商品信息*(可二选一)", "海博商品ID"},  index = 0)
     @ColumnWidth(20) // 列宽
     @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER) // 居中对齐
     private String skuId;
 
-    @ExcelProperty(value = "海博商品编码", index = 1)
+    @ExcelProperty(value = {"商品信息*(可二选一)", "海博商品编码"}, index = 1)
     @ColumnWidth(20) // 列宽
     @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER) // 居中对齐
     private String skuCode;

+ 22 - 11
yami-shop-service/src/main/java/com/yami/shop/service/impl/ChannelProdServiceImpl.java

@@ -231,8 +231,8 @@ public class ChannelProdServiceImpl extends ServiceImpl<ChannelProdMapper, Chann
                 if (importVO.getChannelName() == null) {
                     throw new RuntimeException("渠道不能为空");
                 }
-                if (importVO.getSkuId() == null) {
-                    throw new RuntimeException("海博商品ID不能为空");
+                if (importVO.getSkuId() == null && importVO.getSkuCode() == null) {
+                    throw new RuntimeException("失败原因:海博商品ID和商品编码不能同时为空");
                 }
                 if (importVO.getShopName() == null) {
                     throw new RuntimeException("海博门店不能为空");
@@ -246,17 +246,28 @@ public class ChannelProdServiceImpl extends ServiceImpl<ChannelProdMapper, Chann
                 Channel channel = channelMapper.selectByName(importVO.getChannelName());
                 if (ObjectUtil.isEmpty(channel)) {
                     log.error("渠道:{},在系统中不存在", importVO.getChannelName());
-                    throw new GlobalException(String.format("第%d行数据导入失败! 失败原因: 渠道=%s,在系统中不存在", i + 2, importVO.getChannelName()));
+                    throw new GlobalException(String.format("失败原因: 渠道=%s,在系统中不存在", importVO.getChannelName()));
                 }
                 channelProd.setChannelId(channel.getId());
 
-                Sku sku = skuMapper.selectByHbSkuId(importVO.getSkuId());
+                Sku sku = skuMapper.selectOne(new LambdaQueryWrapper<Sku>()
+                        .eq(importVO.getSkuId()!=null,Sku::getHbSkuId, importVO.getSkuId())
+                        .eq(importVO.getSkuCode()!=null,Sku::getSkuCode, importVO.getSkuCode())
+                        .eq(Sku::getIsDelete, 0));
                 if (ObjectUtil.isEmpty(sku)) {
-                    log.error("商品ID:{},在系统中不存在", importVO.getSkuId());
-
-                    throw new GlobalException(String.format("第%d行数据导入失败! 失败原因: 商品ID=%s,在系统中不存在", i + 2, importVO.getSkuId()));
+                    if (importVO.getSkuId() != null && importVO.getSkuCode() != null){
+                        log.error("商品ID:{} 商品编码:{},在系统中不存在", importVO.getSkuId(), importVO.getSkuCode());
+                        throw new GlobalException(String.format("失败原因: 商品ID=%s 商品编码=%s,在系统中不存在", importVO.getSkuId(), importVO.getSkuCode()));
+                    }
+                    if (importVO.getSkuId() != null){
+                        log.error("商品ID:{},在系统中不存在", importVO.getSkuId());
+                        throw new GlobalException(String.format("失败原因: 商品ID=%s,在系统中不存在", importVO.getSkuId()));
+                    }
+                    if (importVO.getSkuCode() != null){
+                        log.error("商品编码:{},在系统中不存在", importVO.getSkuCode());
+                        throw new GlobalException(String.format("失败原因: 商品编码=%s,在系统中不存在", importVO.getSkuCode()));
+                    }
                 }
-
                 channelProd.setSkuId(sku.getSkuId());
                 channelProd.setPurchasePrice(importVO.getPurchasePrice());
                 channelProd.setDeliveryPrice(importVO.getDeliveryPrice());
@@ -268,7 +279,7 @@ public class ChannelProdServiceImpl extends ServiceImpl<ChannelProdMapper, Chann
                 ShopDetail shopDetail = shopDetailMapper.selectOne(new LambdaQueryWrapper<ShopDetail>().eq(ShopDetail::getShopName, importVO.getShopName()));
                 if (ObjectUtil.isEmpty(shopDetail)) {
                     log.error("门店:{},在系统中不存在", importVO.getShopName());
-                    throw new GlobalException(String.format("第%d行数据导入失败! 失败原因: 门店=%s,在系统中不存在", i + 2, importVO.getShopName()));
+                    throw new GlobalException(String.format("失败原因: 门店=%s,在系统中不存在", importVO.getShopName()));
                 }
                 channelProd.setShopId(shopDetail.getShopId());
 
@@ -301,8 +312,8 @@ public class ChannelProdServiceImpl extends ServiceImpl<ChannelProdMapper, Chann
                 }
                 successCount++;
             } catch (Exception e) {
-                log.error("导入数据失败,行号:{},错误:{}", i + 2, e.getMessage());
-                throw new GlobalException(String.format("第%s行数据导入失败:%s", i + 2,e.getMessage()));
+                log.error("导入数据失败,行号:{},错误:{}", i + 3, e.getMessage());
+                throw new GlobalException(String.format("第%s行数据导入失败! %s", i + 3,e.getMessage()));
             }
         }
         return String.format("导入完成,成功:%d条", successCount);