Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataDeclaration
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
dataDeclaration
Commits
43a4b9de
提交
43a4b9de
authored
5月 23, 2021
作者:
xc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[excel导入]修改百分比BUG
上级
1be24adf
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
69 行增加
和
26 行删除
+69
-26
ExcelController.java
...java/com/tykj/model_layer/controller/ExcelController.java
+8
-2
ExcelConfig.java
src/main/java/com/tykj/model_layer/entity/ExcelConfig.java
+1
-0
ExcelVo.java
src/main/java/com/tykj/model_layer/entity/vo/ExcelVo.java
+2
-0
ExcelData.java
src/main/java/com/tykj/model_layer/excel/ExcelData.java
+58
-24
没有找到文件。
src/main/java/com/tykj/model_layer/controller/ExcelController.java
浏览文件 @
43a4b9de
...
...
@@ -60,8 +60,8 @@ public class ExcelController {
@ApiOperation
(
"新增excel路径"
)
@PostMapping
(
"/path"
)
public
ResponseEntity
savePath
(
@RequestParam
String
path
){
return
excelData
.
savePath
(
path
);
public
ResponseEntity
savePath
(
@RequestParam
String
path
,
@RequestParam
String
rootPath
){
return
excelData
.
savePath
(
path
,
rootPath
);
}
@ApiOperation
(
"查询路径"
)
...
...
@@ -76,4 +76,10 @@ public class ExcelController {
return
excelData
.
findPrecen
();
}
@ApiOperation
(
"查询预览结果"
)
@PostMapping
(
"/preview"
)
public
ResponseEntity
findPreview
(){
return
excelData
.
findPreview
();
}
}
src/main/java/com/tykj/model_layer/entity/ExcelConfig.java
浏览文件 @
43a4b9de
...
...
@@ -15,4 +15,5 @@ import javax.persistence.Table;
@NoArgsConstructor
public
class
ExcelConfig
extends
BaseEntity
{
private
String
path
;
private
String
rootPath
;
}
src/main/java/com/tykj/model_layer/entity/vo/ExcelVo.java
浏览文件 @
43a4b9de
...
...
@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.Date
;
import
java.util.List
;
@Data
@AllArgsConstructor
...
...
@@ -13,6 +14,7 @@ public class ExcelVo {
private
Integer
successNum
;
private
Integer
errorNum
;
private
Integer
importNum
;
private
Date
date
;
private
List
<
ExcelErrorVo
>
list
;
}
src/main/java/com/tykj/model_layer/excel/ExcelData.java
浏览文件 @
43a4b9de
...
...
@@ -32,6 +32,7 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.text.DecimalFormat
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -50,27 +51,27 @@ public class ExcelData {
@Autowired
private
ExcelConfigDao
excelConfigDao
;
private
String
path
;
private
String
rootPath
;
private
float
percent
;
private
String
successPath
=
System
.
getProperty
(
"user.dir"
)
+
"/successFile/"
;
private
String
errorPath
=
System
.
getProperty
(
"user.dir"
)
+
"/errorFile/"
;
private
String
tmpPath
=
System
.
getProperty
(
"user.dir"
)
+
"/tmp/"
;
private
String
tmpPath
;
private
ExcelVo
previewResult
;
public
ExcelData
(){
}
public
ResponseEntity
getExcelData
(
int
id
){
String
successPath
=
rootPath
+
"/research/successFile/"
;
String
errorPath
=
rootPath
+
"/research/errorFile/"
;
File
success
=
new
File
(
successPath
);
File
error
=
new
File
(
errorPath
);
File
tmp
=
new
File
(
tmpPath
);
if
(!
success
.
exists
()){
success
.
mkdirs
();
}
if
(!
error
.
exists
()){
error
.
mkdirs
();
}
if
(!
tmp
.
exists
()){
tmp
.
mkdirs
();
}
}
public
ResponseEntity
getExcelData
(
int
id
){
this
.
percent
=
0
;
//百分比数字
String
jsonData
=
modelHelper
.
getJsonExpample
(
id
);
try
{
...
...
@@ -79,7 +80,7 @@ public class ExcelData {
new
TypeReference
<
Map
<
String
,
Map
<
String
,
Object
>>>(){});
File
file
=
new
File
(
tmpPath
);
if
(!
file
.
isDirectory
()){
excelLogService
.
save
(
new
ExcelLog
(
"导入失败"
,
"文件路径不是文件夹"
,
file
.
getPath
()
));
excelLogService
.
save
(
new
ExcelLog
(
"导入失败"
,
"文件路径不是文件夹"
,
tmpPath
));
return
ResultUtil
.
failed
(
"文件路径不是文件夹!"
);
}
File
[]
dataFiles
=
file
.
listFiles
();
...
...
@@ -210,7 +211,9 @@ public class ExcelData {
}
ExcelVo
excelVo
=
new
ExcelVo
(
dataFiles
.
length
,
successNum
,
errorNum
,
0
,
null
);
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
);
if
(!
""
.
equals
(
errorFileNameList
)){
excelLogService
.
save
(
new
ExcelLog
(
"导入失败"
,
errorReason
,
errorFileNameList
));
String
s
=
"没有文件"
;
...
...
@@ -235,12 +238,24 @@ public class ExcelData {
* @return
*/
public
ResponseEntity
compareRule
(){
if
(
path
==
null
){
path
=
findPaths
();
if
(
""
.
equals
(
path
)){
this
.
percent
=
0
;
this
.
previewResult
=
null
;
if
(
path
==
null
||
rootPath
==
null
){
path
=
findPaths
().
getPath
();
rootPath
=
findPaths
().
getRootPath
();
if
(
path
==
null
){
return
ResultUtil
.
failed
(
"没有配置导入路径!"
);
}
if
(
rootPath
==
null
){
rootPath
=
System
.
getProperty
(
"user.dir"
)
+
"/"
;
}
}
tmpPath
=
rootPath
+
"/research/tmp/"
;
File
tmp
=
new
File
(
tmpPath
);
if
(!
tmp
.
exists
()){
tmp
.
mkdirs
();
}
List
<
ExcelErrorVo
>
excelVos
=
new
ArrayList
<>();
List
<
Rule
>
rules
=
ruleService
.
findAll
();
int
successNum
=
0
;
//符合规则文件数量
...
...
@@ -252,13 +267,13 @@ public class ExcelData {
String
tem
=
template
.
getTemplate
(
"template.txt"
);
Map
<
String
,
int
[]>
indexMap
=
JSON
.
parseObject
(
tem
,
new
TypeReference
<
Map
<
String
,
int
[]>>(){});
if
(
indexMap
.
isEmpty
()){
return
ResultUtil
.
failed
(
"没有excle模板!"
);
return
ResultUtil
.
failed
(
"没有excle模板
,请导入模板文件
!"
);
}
File
file
=
new
File
(
path
);
File
[]
dataFiles
=
file
.
listFiles
();
if
(
dataFiles
==
null
){
return
ResultUtil
.
failed
(
"文件夹为空!"
);
if
(
dataFiles
==
null
||
dataFiles
.
length
==
0
){
return
ResultUtil
.
failed
(
"文件夹为空
,请检查"
+
path
+
"下是否有excel文件
!"
);
}
total
=
dataFiles
.
length
;
...
...
@@ -421,6 +436,9 @@ public class ExcelData {
errorNum
=
errorNum
+
1
;
excelVos
.
add
(
new
ExcelErrorVo
(
fileName
,
unitName
,
tel
,
buildTel
,
result
));
}
System
.
out
.
println
(
"++++++++++++++++="
);
System
.
out
.
println
(
successNum
+
errorNum
);
}
catch
(
Exception
e
){
// e.printStackTrace();
errorNum
=
errorNum
+
1
;
...
...
@@ -428,7 +446,8 @@ public class ExcelData {
result
.
add
(
k
+
"."
+
"不是模板文件或读文件失败"
);
excelVos
.
add
(
new
ExcelErrorVo
(
fileName
,
unitName
,
tel
,
buildTel
,
result
));
}
this
.
percent
=
(
float
)
(
successNum
+
errorNum
)/
dataFiles
.
length
;
System
.
out
.
println
(
percent
+
" lll "
+
dataFiles
.
length
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -436,7 +455,8 @@ public class ExcelData {
}
File
[]
successFile
=
new
File
(
tmpPath
).
listFiles
();
int
importNum
=
successFile
==
null
?
0
:
successFile
.
length
;
ExcelVo
excelVo
=
new
ExcelVo
(
total
,
successNum
,
errorNum
,
importNum
,
excelVos
);
ExcelVo
excelVo
=
new
ExcelVo
(
total
,
successNum
,
errorNum
,
importNum
,
new
Date
(),
excelVos
);
this
.
previewResult
=
excelVo
;
return
ResultUtil
.
success
(
excelVo
,
"预览成功"
);
}
...
...
@@ -514,15 +534,17 @@ public class ExcelData {
}
return
ResultUtil
.
failed
(
"查询失败"
);
}
public
ResponseEntity
savePath
(
String
path
){
public
ResponseEntity
savePath
(
String
path
,
String
rootPath
){
try
{
this
.
path
=
path
;
this
.
rootPath
=
rootPath
;
List
<
ExcelConfig
>
excelConfigs
=
excelConfigDao
.
findAll
();
ExcelConfig
excelConfig
=
new
ExcelConfig
();
if
(
excelConfigs
!=
null
&&
excelConfigs
.
size
()
>
0
){
excelConfig
=
excelConfigs
.
get
(
0
);
}
excelConfig
.
setPath
(
path
);
excelConfig
.
setRootPath
(
rootPath
);
excelConfigDao
.
saveAndFlush
(
excelConfig
);
return
ResultUtil
.
success
(
""
,
"保存成功"
);
}
catch
(
Exception
e
){
...
...
@@ -530,16 +552,28 @@ public class ExcelData {
}
return
ResultUtil
.
failed
(
"新增失败"
);
}
private
Strin
g
findPaths
(){
private
ExcelConfi
g
findPaths
(){
List
<
ExcelConfig
>
excelConfigs
=
excelConfigDao
.
findAll
();
if
(
excelConfigs
!=
null
&&
excelConfigs
.
size
()
>
0
){
return
excelConfigs
.
get
(
0
)
.
getPath
()
;
return
excelConfigs
.
get
(
0
);
}
return
""
;
return
new
ExcelConfig
()
;
}
public
ResponseEntity
findPrecen
(){
return
ResultUtil
.
success
(
this
.
percent
,
"查询成功"
);
DecimalFormat
df
=
new
DecimalFormat
(
"0"
);
//设置保留位数
String
s
=
df
.
format
(
this
.
percent
*
100
);
System
.
out
.
println
(
"============================================="
);
System
.
out
.
println
(
s
);
if
(
"100"
.
equals
(
s
)){
this
.
percent
=
0
;
}
return
ResultUtil
.
success
(
s
,
"查询成功"
);
}
public
ResponseEntity
findPreview
(){
return
ResultUtil
.
success
(
previewResult
,
"查询成功"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论