Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
relation
Commits
92e7440e
Commit
92e7440e
authored
Aug 26, 2025
by
wujipeng
Browse files
优化
parent
7d929c28
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/platform/controller/AnalysisController.java
View file @
92e7440e
...
@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -29,7 +30,7 @@ public class AnalysisController {
...
@@ -29,7 +30,7 @@ public class AnalysisController {
@PostMapping
(
"/canvas"
)
@PostMapping
(
"/canvas"
)
public
Result
<?>
canvas
(
@RequestParam
(
value
=
"files"
)
List
<
MultipartFile
>
files
,
public
Result
<?>
canvas
(
@RequestParam
(
value
=
"files"
)
List
<
MultipartFile
>
files
,
@RequestParam
(
value
=
"caseId"
)
int
caseId
,
@RequestParam
(
value
=
"caseId"
)
int
caseId
,
@RequestParam
(
value
=
"folderName"
,
required
=
false
)
String
folderName
)
{
@RequestParam
(
value
=
"folderName"
,
required
=
false
)
String
folderName
)
throws
IOException
{
return
analysisService
.
canvas
(
files
,
caseId
,
folderName
);
return
analysisService
.
canvas
(
files
,
caseId
,
folderName
);
}
}
...
...
src/main/java/com/platform/service/AnalysisService.java
View file @
92e7440e
...
@@ -4,6 +4,7 @@ import com.platform.model.resp.Result;
...
@@ -4,6 +4,7 @@ import com.platform.model.resp.Result;
import
com.platform.model.vo.TableHeaderVO
;
import
com.platform.model.vo.TableHeaderVO
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -19,7 +20,7 @@ public interface AnalysisService {
...
@@ -19,7 +20,7 @@ public interface AnalysisService {
* @param files
* @param files
* @return
* @return
*/
*/
Result
<?>
canvas
(
List
<
MultipartFile
>
files
,
int
caseId
,
String
folderName
);
Result
<?>
canvas
(
List
<
MultipartFile
>
files
,
int
caseId
,
String
folderName
)
throws
IOException
;
/**
/**
* 读取模板文件
* 读取模板文件
...
...
src/main/java/com/platform/service/impl/AnalysisServiceImpl.java
View file @
92e7440e
...
@@ -61,7 +61,7 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -61,7 +61,7 @@ public class AnalysisServiceImpl implements AnalysisService {
@Override
@Override
@Transactional
@Transactional
public
Result
<?>
canvas
(
List
<
MultipartFile
>
files
,
int
caseId
,
String
folderName
)
{
public
Result
<?>
canvas
(
List
<
MultipartFile
>
files
,
int
caseId
,
String
folderName
)
throws
IOException
{
//查询模板
//查询模板
ExcelTemplateEntity
ExcelTemplate
=
excelTemplateService
.
getMaxId
();
ExcelTemplateEntity
ExcelTemplate
=
excelTemplateService
.
getMaxId
();
List
<
TableHeaderVO
>
tableHeaderList
;
List
<
TableHeaderVO
>
tableHeaderList
;
...
@@ -111,14 +111,16 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -111,14 +111,16 @@ public class AnalysisServiceImpl implements AnalysisService {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
BusinessException
(
"文件转换错误"
);
throw
new
BusinessException
(
"文件转换错误"
);
}
}
try
{
boolean
b
=
processSingleExcelFile
(
tempFile
,
tableHeaderList
,
folderName
,
fileUploadVO
.
getId
(),
caseId
,
groupedMap
,
excelData
);
processSingleExcelFile
(
tempFile
,
tableHeaderList
,
folderName
,
fileUploadVO
.
getId
(),
caseId
,
groupedMap
,
excelData
);
if
(
b
)
{
}
catch
(
IOException
e
)
{
//文件上传
throw
new
BusinessException
(
"文件解析错误"
);
fileUploadList
.
add
(
fileUploadVO
);
totalCount
++;
}
else
{
errorCount
++;
totalCount
++;
detail
.
add
(
AnalysisVO
.
builder
().
folderName
(
folderName
).
fileName
(
file
.
getOriginalFilename
()).
errorReason
(
"文件格式错误"
).
build
());
}
}
//文件上传
fileUploadList
.
add
(
fileUploadVO
);
totalCount
++;
}
else
{
}
else
{
errorCount
++;
errorCount
++;
totalCount
++;
totalCount
++;
...
@@ -401,9 +403,13 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -401,9 +403,13 @@ public class AnalysisServiceImpl implements AnalysisService {
return
false
;
return
false
;
}
}
private
void
processSingleExcelFile
(
File
excelFile
,
List
<
TableHeaderVO
>
tableHeaderList
,
String
folderName
,
String
fileId
,
int
caseId
,
Map
<
String
,
String
>
groupedMap
,
List
<
ExcelDataEntity
>
excelData
)
throws
IOException
{
private
boolean
processSingleExcelFile
(
File
excelFile
,
List
<
TableHeaderVO
>
tableHeaderList
,
String
folderName
,
String
fileId
,
int
caseId
,
Map
<
String
,
String
>
groupedMap
,
List
<
ExcelDataEntity
>
excelData
)
throws
IOException
{
Workbook
workbook
=
getWorkbook
(
excelFile
);
if
(
ObjectUtils
.
isEmpty
(
workbook
))
{
return
false
;
}
//读取第一个sheet
//读取第一个sheet
Sheet
sheet
=
getW
orkbook
(
excelFile
)
.
getSheetAt
(
0
);
Sheet
sheet
=
w
orkbook
.
getSheetAt
(
0
);
//获取sheet长度
//获取sheet长度
int
sheetLength
=
sheet
.
getLastRowNum
();
int
sheetLength
=
sheet
.
getLastRowNum
();
for
(
int
i
=
1
;
i
<
sheetLength
;
i
++)
{
for
(
int
i
=
1
;
i
<
sheetLength
;
i
++)
{
...
@@ -424,24 +430,25 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -424,24 +430,25 @@ public class AnalysisServiceImpl implements AnalysisService {
}
}
}
}
}
}
return
true
;
}
}
// 根据文件类型创建Workbook
// 根据文件类型创建Workbook
private
Workbook
getWorkbook
(
File
excelFile
)
throws
IOException
{
private
Workbook
getWorkbook
(
File
excelFile
)
{
String
fileName
=
excelFile
.
getName
().
toLowerCase
();
String
fileName
=
excelFile
.
getName
().
toLowerCase
();
if
(
fileName
.
endsWith
(
".xlsx"
))
{
if
(
fileName
.
endsWith
(
".xlsx"
))
{
try
{
try
{
return
new
XSSFWorkbook
(
new
FileInputStream
(
excelFile
));
return
new
XSSFWorkbook
(
new
FileInputStream
(
excelFile
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
n
ew
HSSFWorkbook
(
new
FileInputStream
(
excelFile
))
;
return
n
ull
;
}
}
}
else
if
(
fileName
.
endsWith
(
".xls"
))
{
}
else
if
(
fileName
.
endsWith
(
".xls"
))
{
try
{
try
{
return
new
HSSFWorkbook
(
new
FileInputStream
(
excelFile
));
return
new
HSSFWorkbook
(
new
FileInputStream
(
excelFile
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
n
ew
XSSFWorkbook
(
new
FileInputStream
(
excelFile
))
;
return
n
ull
;
}
}
}
else
{
}
else
{
throw
new
IllegalArgumentException
(
"不支持的Excel文件格式"
);
throw
new
IllegalArgumentException
(
"不支持的Excel文件格式"
);
...
...
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