Browse Source

图稿库

24282 1 year ago
parent
commit
97e3eee1a8
1 changed files with 76 additions and 5 deletions
  1. 76 5
      sd-starter/src/test/java/B1_SyncSkuTest.java

+ 76 - 5
sd-starter/src/test/java/B1_SyncSkuTest.java

@@ -1,39 +1,104 @@
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.annotation.ExcelProperty;
 import com.alibaba.excel.read.builder.ExcelReaderBuilder;
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.sd.SdApplication;
+import com.sd.business.entity.artwork.po.ArtworkLibrary;
+import com.sd.business.entity.sku.po.SkuSpec;
+import com.sd.business.service.artwork.ArtworkLibraryService;
+import com.sd.business.service.sku.SkuSpecService;
 import com.sd.framework.util.excel.listener.DataListener;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.SneakyThrows;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.io.FileInputStream;
 import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest(classes = SdApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
 public class B1_SyncSkuTest {
 
 
+    @Autowired
+    private SkuSpecService skuSpecService;
+
+    @Autowired
+    private ArtworkLibraryService artworkLibraryService;
+
     @SneakyThrows
-    @Transactional
+    @DSTransactional
     @Test
     public void test() {
 
         DataListener<ExcelData> listener = new DataListener<>();
 
-        FileInputStream fileInputStream = new FileInputStream("E:\\峰燕-胜德体育-品号汇总模板-2 (1).xlsx");
+        FileInputStream fileInputStream = new FileInputStream("E:\\峰燕-胜德体育-品号汇总模板-2.xlsx");
 
         ExcelReaderBuilder read = EasyExcel.read(fileInputStream, ExcelData.class, listener);
         read.sheet(0).doRead();
-        List<ExcelData> dataList = listener.getDataList();
+        List<ExcelData> list = listener.getDataList();
+        Map<String, ExcelData> map = list.stream().collect(Collectors.toMap(ExcelData::getCode, Function.identity()));
+
+        List<SkuSpec> skuSpecList = skuSpecService.list();
+        List<ArtworkLibrary> artworkLibraryList = artworkLibraryService.list();
+        Map<String, ArtworkLibrary> artworkLibraryMap = artworkLibraryList.stream().collect(Collectors.toMap(ArtworkLibrary::getArtworkName, Function.identity()));
+
+        // 机关图案算体位线
+        for (SkuSpec skuSpec : skuSpecList) {
+            ExcelData excelData = map.get(skuSpec.getCode());
+            if (excelData == null) {
+                continue;
+            }
+
+            String machinedPanelStr = excelData.getMachinedPanelStr();
+            if (StrUtil.isNotBlank(machinedPanelStr)) {
+                machinedPanelStr = machinedPanelStr.replace(" ", "");
+                if (machinedPanelStr.startsWith("激光体位线") || machinedPanelStr.startsWith("激光图案")) {
+                    skuSpec.setMachinedPanel("10");
+                } else if (machinedPanelStr.startsWith("激光logo")) {
+                    skuSpec.setMachinedPanel("20");
+                }
+            }
+
+            String machinedPanelFileStr = excelData.getMachinedPanelFileStr();
+            if (StrUtil.isBlank(machinedPanelFileStr)) {
+                if (skuSpec.getCode().startsWith("FY")) {
+                    ArtworkLibrary artworkLibrary = artworkLibraryMap.get("EMPTY");
+                    skuSpec.setDesignImgUrl(artworkLibrary.getImgUrl());
+                    skuSpec.setSharedFolder(artworkLibrary.getFileUrl());
+                }
+                continue;
+            }
+
 
-        System.out.println();
+            String sp = excelData.getSpec().split("\\*")[1].replace("cm", "").replace(" ", "");
+            for (ArtworkLibrary artworkLibrary : artworkLibraryList) {
+                String[] ar = artworkLibrary.getArtworkName().split("_");
+                String ar0 = ar[0];
+                String arl = ar[ar.length - 1];
+
+                if (machinedPanelFileStr.startsWith(ar0) && arl.equals(sp)) {
+                    skuSpec.setDesignImgUrl(artworkLibrary.getImgUrl());
+                    skuSpec.setSharedFolder(artworkLibrary.getFileUrl());
+                    break;
+                }
+
+            }
+
+
+        }
+
+        skuSpecService.updateBatchById(skuSpecList);
 
     }
 
@@ -47,6 +112,12 @@ public class B1_SyncSkuTest {
         @ExcelProperty("图稿类型")
         private String machinedPanelStr;
 
+        @ExcelProperty("图稿文件")
+        private String machinedPanelFileStr;
+
+        @ExcelProperty("规格")
+        private String spec;
+
     }
 
 }