Browse Source

处理查询报错

yuanliang 1 year ago
parent
commit
dc4d9afffa

+ 10 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -57,6 +57,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.math.NumberUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.PictureData;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -74,6 +76,7 @@ import java.awt.image.BufferedImage;
 import java.io.*;
 import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -604,8 +607,13 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public String importGoodsV2(MultipartFile file, Integer userId) throws Exception {
+		File excel = createImportGoodsTempFile(UUID.randomUUID().toString().replaceAll("-","") + ".xlsx");
+		Workbook workbook = WorkbookFactory.create(file.getInputStream());
+		workbook.write(Files.newOutputStream(excel.toPath()));
+
 		List<String> errList = new ArrayList<>();
-		Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
+//		Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
+		Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(excel, 2);
 		if (sheetsListMap.values().isEmpty()) {
 			errList.add("excel未解析到数据");
 			return getExportErrLogFile(errList);
@@ -733,7 +741,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 								if (data instanceof PictureData) {
 									value = ((PictureData) data).getData();
 								}
-							} else {
+							} else if (!(value instanceof byte[])) {
 								lineErrList.add("图片格式错误");
 								continue;
 							}