Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vehicle-quality-review
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王飞
vehicle-quality-review
Commits
b47e3b9c
Commit
b47e3b9c
authored
Aug 30, 2024
by
宋源硕
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'songyuanshuo' into 'dev'
开启第三个子任务时需要解析上传文件,新增此接口 See merge request
!432
parents
30f63b88
953157da
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
5 deletions
+64
-5
TaskController.java
...ty-review/src/main/java/com/ruoyi/web/TaskController.java
+64
-5
No files found.
quality-review/src/main/java/com/ruoyi/web/TaskController.java
View file @
b47e3b9c
...
...
@@ -17,18 +17,18 @@ import com.ruoyi.web.request.*;
import
com.ruoyi.web.response.*
;
import
io.swagger.annotations.Api
;
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.Tags
;
import
org.apache.skywalking.apm.toolkit.trace.Trace
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.
List
;
import
java.util.
*
;
@Api
(
tags
=
"总任务"
)
@RestController
...
...
@@ -188,6 +188,65 @@ public class TaskController extends BaseController {
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment