From 6cf657960188ba9ba83d7b122cea247fcc032710 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 27 Jul 2022 16:20:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8C=85=E5=90=ABexcel=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E8=AF=B7=E6=B1=82=E6=89=A7=E8=A1=8C=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1015442 --user=赵勇 【接口测试】执行带excel文件的接口会报错 https://www.tapd.cn/55049933/s/1213910 --- backend/pom.xml | 2 +- ...ller.java => ApiJMeterFileController.java} | 6 +-- .../api/dto/definition/parse/ESBParser.java | 43 ++++++++----------- ...Service.java => ApiJMeterFileService.java} | 6 +-- ...troller.java => JMeterFileController.java} | 6 +-- ...ileService.java => JMeterFileService.java} | 4 +- 6 files changed, 30 insertions(+), 37 deletions(-) rename backend/src/main/java/io/metersphere/api/controller/{ApiJmeterFileController.java => ApiJMeterFileController.java} (93%) rename backend/src/main/java/io/metersphere/api/service/{ApiJmeterFileService.java => ApiJMeterFileService.java} (98%) rename backend/src/main/java/io/metersphere/performance/controller/{JmeterFileController.java => JMeterFileController.java} (94%) rename backend/src/main/java/io/metersphere/performance/service/{JmeterFileService.java => JMeterFileService.java} (97%) diff --git a/backend/pom.xml b/backend/pom.xml index a60ddd9a06..47aa754429 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -210,7 +210,7 @@ com.alibaba easyexcel - 2.2.10 + 3.1.1 diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiJmeterFileController.java b/backend/src/main/java/io/metersphere/api/controller/ApiJMeterFileController.java similarity index 93% rename from backend/src/main/java/io/metersphere/api/controller/ApiJmeterFileController.java rename to backend/src/main/java/io/metersphere/api/controller/ApiJMeterFileController.java index 476fe3ea9f..a3822960d2 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiJmeterFileController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiJMeterFileController.java @@ -1,7 +1,7 @@ package io.metersphere.api.controller; import io.metersphere.api.jmeter.JMeterThreadUtils; -import io.metersphere.api.service.ApiJmeterFileService; +import io.metersphere.api.service.ApiJMeterFileService; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -12,10 +12,10 @@ import java.util.UUID; @RestController @RequestMapping("/api/jmeter") -public class ApiJmeterFileController { +public class ApiJMeterFileController { @Resource - private ApiJmeterFileService apiJmeterFileService; + private ApiJMeterFileService apiJmeterFileService; @GetMapping("stop/{name}") public String stop(@PathVariable String name) { diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/ESBParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/ESBParser.java index 3f373a7160..330d4b5dba 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/ESBParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/ESBParser.java @@ -501,34 +501,27 @@ public class ESBParser extends EsbAbstractParser { private String getCellValue(Cell cell) { String returnCellValue = ""; - int cellType = cell.getCellType(); - switch (cellType) { - case Cell.CELL_TYPE_BLANK: - returnCellValue = ""; - break; - case Cell.CELL_TYPE_BOOLEAN: - returnCellValue = String.valueOf(cell.getBooleanCellValue()); - break; - case Cell.CELL_TYPE_ERROR: - returnCellValue = ""; - break; - case Cell.CELL_TYPE_NUMERIC: + if (cell.getCellType() == CellType.BLANK) { + returnCellValue = ""; + } else if (cell.getCellType() == CellType.BOOLEAN) { + returnCellValue = String.valueOf(cell.getBooleanCellValue()); + } else if (cell.getCellType() == CellType.ERROR) { + returnCellValue = ""; + } else if (cell.getCellType() == CellType.NUMERIC) { + returnCellValue = getValueOfNumericCell(cell); + } else if (cell.getCellType() == CellType.FORMULA) { + try { returnCellValue = getValueOfNumericCell(cell); - break; - case Cell.CELL_TYPE_FORMULA: + } catch (IllegalStateException e) { try { - returnCellValue = getValueOfNumericCell(cell); - } catch (IllegalStateException e) { - try { - returnCellValue = cell.getRichStringCellValue().toString(); - } catch (IllegalStateException e2) { - } - } catch (Exception e) { - LogUtil.error(e); + returnCellValue = cell.getRichStringCellValue().toString(); + } catch (IllegalStateException e2) { } - break; - default: - returnCellValue = cell.getRichStringCellValue().getString(); + } catch (Exception e) { + LogUtil.error(e); + } + } else { + returnCellValue = cell.getRichStringCellValue().getString(); } if (returnCellValue == null) { returnCellValue = ""; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java b/backend/src/main/java/io/metersphere/api/service/ApiJMeterFileService.java similarity index 98% rename from backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java rename to backend/src/main/java/io/metersphere/api/service/ApiJMeterFileService.java index 6af23cf409..263ddc7b0f 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiJMeterFileService.java @@ -35,7 +35,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @Service -public class ApiJmeterFileService { +public class ApiJMeterFileService { @Resource private ApiCaseSerialService apiCaseSerialService; @Resource @@ -123,7 +123,7 @@ public class ApiJmeterFileService { Map files = new HashMap<>(); // 获取JAR Map jarFiles = this.getJar(); - if (!com.alibaba.excel.util.CollectionUtils.isEmpty(jarFiles)) { + if (!MapUtils.isEmpty(jarFiles)) { for (String k : jarFiles.keySet()) { byte[] v = jarFiles.get(k); files.put(k, v); @@ -136,7 +136,7 @@ public class ApiJmeterFileService { Map files = new HashMap<>(); // 获取JAR Map jarFiles = this.getPlugJar(); - if (!com.alibaba.excel.util.CollectionUtils.isEmpty(jarFiles)) { + if (!MapUtils.isEmpty(jarFiles)) { for (String k : jarFiles.keySet()) { byte[] v = jarFiles.get(k); files.put(k, v); diff --git a/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java b/backend/src/main/java/io/metersphere/performance/controller/JMeterFileController.java similarity index 94% rename from backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java rename to backend/src/main/java/io/metersphere/performance/controller/JMeterFileController.java index 65c1ac0c03..c2ca7b91a8 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/JMeterFileController.java @@ -4,7 +4,7 @@ package io.metersphere.performance.controller; import io.metersphere.commons.utils.WeakConcurrentHashMap; import io.metersphere.controller.handler.annotation.NoResultHolder; import io.metersphere.performance.dto.ZipDTO; -import io.metersphere.performance.service.JmeterFileService; +import io.metersphere.performance.service.JMeterFileService; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -20,9 +20,9 @@ import java.util.stream.Collectors; @RestController @RequestMapping("jmeter") -public class JmeterFileController { +public class JMeterFileController { @Resource - private JmeterFileService jmeterFileService; + private JMeterFileService jmeterFileService; private final WeakConcurrentHashMap> readyMap = new WeakConcurrentHashMap<>(30 * 60 * 1000);// 默认保留30分钟 @GetMapping("ping") diff --git a/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java b/backend/src/main/java/io/metersphere/performance/service/JMeterFileService.java similarity index 97% rename from backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java rename to backend/src/main/java/io/metersphere/performance/service/JMeterFileService.java index d32adaafb9..6452ca31c9 100644 --- a/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java +++ b/backend/src/main/java/io/metersphere/performance/service/JMeterFileService.java @@ -1,6 +1,5 @@ package io.metersphere.performance.service; -import com.alibaba.excel.util.CollectionUtils; import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; @@ -10,6 +9,7 @@ import io.metersphere.performance.dto.ZipDTO; import io.metersphere.performance.engine.EngineContext; import io.metersphere.performance.engine.EngineFactory; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.io.ByteArrayOutputStream; @@ -23,7 +23,7 @@ import java.util.zip.ZipOutputStream; // 非事务运行 @Service -public class JmeterFileService { +public class JMeterFileService { @Resource private ExtLoadTestReportMapper extLoadTestReportMapper; @Resource