Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataDeclaration
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
dataDeclaration
Commits
e4e016f5
提交
e4e016f5
authored
5月 23, 2021
作者:
xc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[excel导入]修改百分比BUG
上级
619afa4e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
44 行增加
和
38 行删除
+44
-38
ExcelController.java
...java/com/tykj/model_layer/controller/ExcelController.java
+3
-1
ExcelVo.java
src/main/java/com/tykj/model_layer/entity/vo/ExcelVo.java
+4
-4
ExcelData.java
src/main/java/com/tykj/model_layer/excel/ExcelData.java
+37
-33
没有找到文件。
src/main/java/com/tykj/model_layer/controller/ExcelController.java
浏览文件 @
e4e016f5
...
...
@@ -13,6 +13,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -55,7 +56,8 @@ public class ExcelController {
@ApiOperation
(
"导入预览"
)
@PostMapping
(
"/rule"
)
public
ResponseEntity
importRule
(){
return
excelData
.
compareRule
();
int
num
=
9
;
return
excelData
.
compareRule
(
num
,
new
ArrayList
<>(),
new
ArrayList
<>());
}
@ApiOperation
(
"新增excel路径"
)
...
...
src/main/java/com/tykj/model_layer/entity/vo/ExcelVo.java
浏览文件 @
e4e016f5
...
...
@@ -10,10 +10,10 @@ import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
public
class
ExcelVo
{
private
Integer
total
;
private
Integer
successNum
;
private
Integer
errorNum
;
private
Integer
importNum
;
private
int
total
;
private
int
successNum
;
private
int
errorNum
;
private
int
importNum
;
private
Date
date
;
private
List
<
ExcelErrorVo
>
list
;
...
...
src/main/java/com/tykj/model_layer/excel/ExcelData.java
浏览文件 @
e4e016f5
...
...
@@ -78,13 +78,15 @@ public class ExcelData {
//{className={propertyName=""}}
Map
<
String
,
Map
<
String
,
Object
>>
dataMap
=
JSON
.
parseObject
(
jsonData
,
new
TypeReference
<
Map
<
String
,
Map
<
String
,
Object
>>>(){});
File
file
=
new
File
(
tmpPath
);
if
(!
file
.
isDirectory
()){
excelLogService
.
save
(
new
ExcelLog
(
"导入失败"
,
"文件路径不是文件夹"
,
tmpPath
));
return
ResultUtil
.
failed
(
"文件路径不是文件夹!"
);
}
File
[]
dataFiles
=
file
.
listFiles
();
if
(
dataFiles
==
null
||
dataFiles
.
length
==
0
){
List
<
File
>
dataFiles
=
new
ArrayList
<>();
List
<
File
>
erroeFiles
=
new
ArrayList
<>();
compareRule
(
1
,
dataFiles
,
erroeFiles
);
System
.
out
.
println
(
path
);
File
[]
successFile
=
new
File
(
path
).
listFiles
();
int
totalNum
=
successFile
==
null
?
0
:
successFile
.
length
;
// File[] dataFiles = file.listFiles();
if
(
dataFiles
==
null
||
dataFiles
.
size
()
==
0
){
excelLogService
.
save
(
new
ExcelLog
(
"导入失败"
,
"文件路径下没有文件"
,
""
));
return
ResultUtil
.
failed
(
"没有待导入文件!"
);
}
...
...
@@ -99,7 +101,9 @@ public class ExcelData {
int
total
=
0
;
//操作完成的总数量
int
successNum
=
0
;
int
errorNum
=
0
;
for
(
File
file1
:
erroeFiles
){
file1
.
renameTo
(
new
File
(
errorPath
+
file1
.
getName
()));
}
for
(
File
dataFile
:
dataFiles
){
//传给保存接口的list
List
<
Map
<
String
,
Object
>>
saveMapList
=
new
ArrayList
<>();
...
...
@@ -202,7 +206,7 @@ public class ExcelData {
errorNum
=
errorNum
+
1
;
}
total
=
total
+
1
;
this
.
percent
=
(
float
)
total
/
dataFiles
.
length
;
this
.
percent
=
(
float
)
total
/
dataFiles
.
size
()
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
errorFileNameList
=
errorFileNameList
+
"["
+
fileName
+
"]"
;
...
...
@@ -211,16 +215,18 @@ public class ExcelData {
}
File
[]
successFile
=
new
File
(
tmpPath
).
listFiles
();
int
importNum
=
successFile
==
null
?
0
:
successFile
.
length
;
ExcelVo
excelVo
=
new
ExcelVo
(
dataFiles
.
length
,
successNum
,
errorNum
,
importNum
,
new
Date
(),
null
);
System
.
out
.
println
(
successPath
);
System
.
out
.
println
(
errorPath
);
errorNum
=
errorNum
+
erroeFiles
.
size
();
ExcelVo
excelVo
=
new
ExcelVo
(
totalNum
,
successNum
,
errorNum
,
0
,
new
Date
(),
null
);
if
(!
""
.
equals
(
errorFileNameList
)){
excelLogService
.
save
(
new
ExcelLog
(
"导入失败"
,
errorReason
,
errorFileNameList
));
String
s
=
"
没有文件
"
;
String
s
=
"
导入失败
"
;
if
(!
""
.
equals
(
successFileNameList
)){
s
=
successFileNameList
;
s
=
"部分文件导入失败,"
+
successFileNameList
+
"导入成功"
;
}
return
ResultUtil
.
failed
(
excelVo
+
"导入失败,"
+
s
+
"导入成功"
);
return
ResultUtil
.
failed
(
s
);
}
else
{
excelLogService
.
save
(
new
ExcelLog
(
"导入成功"
,
""
,
successFileNameList
));
return
ResultUtil
.
success
(
excelVo
,
"导入成功!"
);
...
...
@@ -237,7 +243,7 @@ public class ExcelData {
* 预览
* @return
*/
public
ResponseEntity
compareRule
(){
public
ResponseEntity
compareRule
(
int
num
,
List
<
File
>
resultFiles
,
List
<
File
>
errorFiles
){
this
.
percent
=
0
;
this
.
previewResult
=
null
;
if
(
path
==
null
||
rootPath
==
null
){
...
...
@@ -249,6 +255,8 @@ public class ExcelData {
if
(
rootPath
==
null
){
rootPath
=
System
.
getProperty
(
"user.dir"
)
+
"/"
;
}
File
rootFile
=
new
File
(
rootPath
);
rootFile
.
mkdirs
();
}
tmpPath
=
rootPath
+
"/research/tmp/"
;
File
tmp
=
new
File
(
tmpPath
);
...
...
@@ -258,8 +266,6 @@ public class ExcelData {
List
<
ExcelErrorVo
>
excelVos
=
new
ArrayList
<>();
List
<
Rule
>
rules
=
ruleService
.
findAll
();
int
successNum
=
0
;
//符合规则文件数量
int
errorNum
=
0
;
//不符合规则文件数据
int
total
=
0
;
//总文件数量
boolean
isSuccess
=
true
;
try
{
...
...
@@ -273,7 +279,8 @@ public class ExcelData {
File
file
=
new
File
(
path
);
File
[]
dataFiles
=
file
.
listFiles
();
if
(
dataFiles
==
null
||
dataFiles
.
length
==
0
){
return
ResultUtil
.
failed
(
"文件夹为空,请检查"
+
path
+
"下是否有excel文件!"
);
this
.
percent
=
1
;
return
ResultUtil
.
success
(
new
ExcelVo
(),
"空文件夹"
);
}
total
=
dataFiles
.
length
;
...
...
@@ -308,6 +315,7 @@ public class ExcelData {
Map
<
String
,
String
>
sheetNameAndContent
=
new
HashMap
<>();
Map
<
String
,
String
>
networkNameAndSheetName
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
wb
.
getNumberOfSheets
();
i
++){
Sheet
sheet1
=
wb
.
getSheetAt
(
i
);
if
(
"引用表(请勿改动)"
.
equals
(
sheet1
.
getSheetName
())
||
sheet1
==
null
){
continue
;
...
...
@@ -316,6 +324,9 @@ public class ExcelData {
String
sameNetName
=
""
;
//网络名称别名
Row
row
=
null
;
for
(
String
key
:
indexMap
.
keySet
()){
if
(
result
.
size
()
>
num
){
break
;
}
//key=className.property,从模板文件中取该字段的位置
int
[]
value
=
indexMap
.
get
(
key
);
int
dataRow
=
value
[
0
];
...
...
@@ -428,34 +439,27 @@ public class ExcelData {
}
}
if
(
isSuccess
){
dataFile
.
renameTo
(
new
File
(
tmpPath
+
fileName
));
successNum
=
successNum
+
1
;
resultFiles
.
add
(
dataFile
);
}
else
{
// dataFile.renameTo(new File(errorPath + fileName));
errorNum
=
errorNum
+
1
;
excelVos
.
add
(
new
ExcelErrorVo
(
fileName
,
unitName
,
tel
,
buildTel
,
result
));
errorFiles
.
add
(
dataFile
);
}
System
.
out
.
println
(
"++++++++++++++++="
);
System
.
out
.
println
(
successNum
+
errorNum
);
}
catch
(
Exception
e
){
// e.printStackTrace();
errorNum
=
errorNum
+
1
;
int
k
=
result
.
size
()
+
1
;
result
.
add
(
k
+
"."
+
"不是模板文件或读文件失败"
);
excelVos
.
add
(
new
ExcelErrorVo
(
fileName
,
unitName
,
tel
,
buildTel
,
result
));
errorFiles
.
add
(
dataFile
);
}
if
(
num
!=
1
){
this
.
percent
=
(
float
)
(
resultFiles
.
size
()
+
errorFiles
.
size
())/
dataFiles
.
length
;
}
this
.
percent
=
(
float
)
(
successNum
+
errorNum
)/
dataFiles
.
length
;
System
.
out
.
println
(
percent
+
" lll "
+
dataFiles
.
length
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
ResultUtil
.
failed
(
"预览失败!"
);
}
File
[]
successFile
=
new
File
(
tmpPath
).
listFiles
();
int
importNum
=
successFile
==
null
?
0
:
successFile
.
length
;
ExcelVo
excelVo
=
new
ExcelVo
(
total
,
successNum
,
errorNum
,
importNum
,
new
Date
(),
excelVos
);
ExcelVo
excelVo
=
new
ExcelVo
(
total
,
resultFiles
.
size
(),
errorFiles
.
size
(),
0
,
new
Date
(),
excelVos
);
this
.
previewResult
=
excelVo
;
return
ResultUtil
.
success
(
excelVo
,
"预览成功"
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论