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
ffe036a6
Commit
ffe036a6
authored
Aug 28, 2025
by
zhuxiang
Browse files
Merge remote-tracking branch 'origin/dev' into dev
parents
62df0303
029e3e71
Changes
4
Show whitespace changes
Inline
Side-by-side
src/main/java/com/platform/controller/AnalysisController.java
View file @
ffe036a6
...
@@ -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/model/vo/AnalysisVO.java
View file @
ffe036a6
package
com.platform.model.vo
;
package
com.platform.model.vo
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Builder
;
...
@@ -17,6 +18,7 @@ import java.util.List;
...
@@ -17,6 +18,7 @@ import java.util.List;
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
@Builder
@Builder
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
AnalysisVO
{
public
class
AnalysisVO
{
@ApiModelProperty
(
"文件夹数"
)
@ApiModelProperty
(
"文件夹数"
)
...
...
src/main/java/com/platform/service/AnalysisService.java
View file @
ffe036a6
...
@@ -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 @
ffe036a6
...
@@ -61,7 +61,34 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -61,7 +61,34 @@ 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
{
//检查文件
List
<
AnalysisVO
>
detail
=
Lists
.
newArrayList
();
int
errorCount
=
0
;
int
totalCount
=
0
;
for
(
MultipartFile
file
:
files
)
{
if
(
isExcelFile
(
file
.
getOriginalFilename
()))
{
File
tempFile
=
convertMultipartFileToFile
(
file
);
Workbook
workbook
=
getWorkbook
(
tempFile
);
if
(
ObjectUtils
.
isEmpty
(
workbook
))
{
errorCount
++;
detail
.
add
(
AnalysisVO
.
builder
().
fileName
(
file
.
getOriginalFilename
()).
errorReason
(
"文件格式错误"
).
build
());
}
totalCount
++;
}
else
{
errorCount
++;
totalCount
++;
detail
.
add
(
AnalysisVO
.
builder
().
fileName
(
file
.
getOriginalFilename
()).
errorReason
(
"文件格式错误"
).
build
());
}
}
if
(
errorCount
>
0
)
{
return
Result
.
data
(
400
,
AnalysisVO
.
builder
()
.
detail
(
detail
)
.
totalCount
(
totalCount
)
.
errorCount
(
errorCount
)
.
build
(),
"部分文件格式错误"
);
}
//查询模板
//查询模板
ExcelTemplateEntity
ExcelTemplate
=
excelTemplateService
.
getMaxId
();
ExcelTemplateEntity
ExcelTemplate
=
excelTemplateService
.
getMaxId
();
List
<
TableHeaderVO
>
tableHeaderList
;
List
<
TableHeaderVO
>
tableHeaderList
;
...
@@ -94,10 +121,6 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -94,10 +121,6 @@ public class AnalysisServiceImpl implements AnalysisService {
return
Result
.
fail
(
"上传的文件为空"
);
return
Result
.
fail
(
"上传的文件为空"
);
}
}
List
<
FileUploadVO
>
fileUploadList
=
Lists
.
newArrayList
();
List
<
FileUploadVO
>
fileUploadList
=
Lists
.
newArrayList
();
//错误数量
List
<
AnalysisVO
>
detail
=
Lists
.
newArrayList
();
int
errorCount
=
0
;
int
totalCount
=
0
;
Map
<
String
,
String
>
groupedMap
=
Maps
.
newHashMap
();
Map
<
String
,
String
>
groupedMap
=
Maps
.
newHashMap
();
List
<
UserAccountEntity
>
userAccountList
=
Lists
.
newArrayList
();
List
<
UserAccountEntity
>
userAccountList
=
Lists
.
newArrayList
();
List
<
ExcelDataEntity
>
excelData
=
Lists
.
newArrayList
();
List
<
ExcelDataEntity
>
excelData
=
Lists
.
newArrayList
();
...
@@ -111,18 +134,11 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -111,18 +134,11 @@ 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
);
fileUploadList
.
add
(
fileUploadVO
);
totalCount
++;
}
}
else
{
errorCount
++;
totalCount
++;
detail
.
add
(
AnalysisVO
.
builder
().
folderName
(
folderName
).
fileName
(
file
.
getOriginalFilename
()).
errorReason
(
"文件格式错误"
).
build
());
}
}
}
}
//把tableHeaderList中filter为true索引组成一个数字类型的集合
//把tableHeaderList中filter为true索引组成一个数字类型的集合
...
@@ -229,11 +245,7 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -229,11 +245,7 @@ public class AnalysisServiceImpl implements AnalysisService {
.
caseId
(
caseId
).
build
());
.
caseId
(
caseId
).
build
());
}
}
}
}
if
(
errorCount
==
0
)
{
return
Result
.
data
(
fileUploadList
);
return
Result
.
data
(
fileUploadList
);
}
else
{
return
Result
.
data
(
AnalysisVO
.
builder
().
folderCount
(
1
).
totalCount
(
totalCount
).
errorCount
(
errorCount
).
detail
(
detail
).
build
());
}
}
}
private
void
deduplicationData
(
Map
<
String
,
ExcelDataEntity
>
excelDataMap
,
List
<
ExcelDataEntity
>
excelData
,
List
<
Integer
>
filterIndex
)
{
private
void
deduplicationData
(
Map
<
String
,
ExcelDataEntity
>
excelDataMap
,
List
<
ExcelDataEntity
>
excelData
,
List
<
Integer
>
filterIndex
)
{
...
@@ -401,9 +413,13 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -401,9 +413,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 +440,25 @@ public class AnalysisServiceImpl implements AnalysisService {
...
@@ -424,24 +440,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