Commit 953157da authored by yuanshuo's avatar yuanshuo

开启第三个子任务时需要解析上传文件,新增此接口

parent 30f63b88
...@@ -17,18 +17,18 @@ import com.ruoyi.web.request.*; ...@@ -17,18 +17,18 @@ import com.ruoyi.web.request.*;
import com.ruoyi.web.response.*; import com.ruoyi.web.response.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.skywalking.apm.toolkit.trace.Tag; import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags; import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace; import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.*;
@Api(tags = "总任务") @Api(tags = "总任务")
@RestController @RestController
...@@ -188,6 +188,65 @@ public class TaskController extends BaseController { ...@@ -188,6 +188,65 @@ public class TaskController extends BaseController {
return R.ok(response); return R.ok(response);
} }
/*
* 开启车型实验任务时-上传文件
* */
@ApiOperation("开启车型实验任务时-上传文件")
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@PostMapping("/uploadExcel")
public R<Map<String, Object>> uploadExcel(@RequestParam("file") MultipartFile file) throws IOException {
// 确保文件类型是Excel
if (!file.getOriginalFilename().endsWith(".xlsx") && !file.getOriginalFilename().endsWith(".xls")) {
throw new IllegalArgumentException("Please upload an Excel file.");
}
// 解析Excel文件
Workbook workbook = WorkbookFactory.create(file.getInputStream());
Sheet sheet = workbook.getSheetAt(3); // 获取第4个工作表
Map<String, Object> result = new HashMap<>();
List<String> useCaseList = new ArrayList<>();
// 获取第一行并查找“用例编号”所在的列
Row headerRow = sheet.getRow(0);
int targetColumnIndex = -1;
if (headerRow != null) {
for (int i = 0; i < headerRow.getLastCellNum(); i++) {
Cell headerCell = headerRow.getCell(i);
if (headerCell != null && "用例编号".equals(headerCell.toString().trim())) {
targetColumnIndex = i; // 找到“用例编号”所在的列索引
break;
}
}
}
if (targetColumnIndex == -1) {
return R.fail("没找到测试用例列");
}
// 设置 "name" 为 "用例编号"
result.put("name", "用例编号");
// 遍历行,提取“用例编号”列的数据
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
if (row != null) {
Cell cell = row.getCell(targetColumnIndex); // 获取“用例编号”列的单元格
if (cell != null && !cell.toString().trim().isEmpty()) {
useCaseList.add(cell.toString().trim()); // 将非空的单元格数据添加到列表
}
}
}
if (useCaseList.isEmpty()){
return R.fail("测试用例id不能为空");
}
result.put("useCaseList", useCaseList); // 设置 "useCaseList" 为解析的数据列表
workbook.close();
return R.ok(result);
}
/** /**
* 快速创建检测项目 * 快速创建检测项目
* @param request * @param request
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment