Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dcs-plan
Project
Project
Details
Activity
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
INET-TWO
server
dcs-plan
Commits
84248c81
Commit
84248c81
authored
Aug 30, 2024
by
wangqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加:使用EasyExcel插件实现采购计划导入数据功能
parent
b4158d7d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
477 additions
and
0 deletions
+477
-0
pom.xml
dcs-plan-common/pom.xml
+5
-0
PurchasePlanExcelListenner.java
.../dcs/plan/common/listener/PurchasePlanExcelListenner.java
+62
-0
EasyExcelUtils.java
.../java/com/yonde/dcs/plan/common/utils/EasyExcelUtils.java
+299
-0
ExtPuchasePlanExcelVO.java
...a/com/yonde/dcs/plan/common/vo/ExtPuchasePlanExcelVO.java
+111
-0
No files found.
dcs-plan-common/pom.xml
View file @
84248c81
...
...
@@ -86,6 +86,11 @@
<version>
2.17.1
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
easyexcel
</artifactId>
<version>
3.0.4
</version>
</dependency>
</dependencies>
...
...
dcs-plan-common/src/main/java/com/yonde/dcs/plan/common/listener/PurchasePlanExcelListenner.java
0 → 100644
View file @
84248c81
package
com
.
yonde
.
dcs
.
plan
.
common
.
listener
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.util.ListUtils
;
import
com.yonde.dcs.plan.common.vo.ExtPuchasePlanExcelVO
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.List
;
@Slf4j
public
class
PurchasePlanExcelListenner
extends
AnalysisEventListener
<
ExtPuchasePlanExcelVO
>
{
/**
* 每隔100条处理下,然后清理list ,方便内存回收
*/
private
static
final
int
BATCH_COUNT
=
100
;
/**
* 缓存的数据
*/
private
List
<
ExtPuchasePlanExcelVO
>
cachedDataList
=
ListUtils
.
newArrayListWithExpectedSize
(
BATCH_COUNT
);
@Override
public
void
invoke
(
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
,
AnalysisContext
analysisContext
)
{
log
.
info
(
"解析到一条数据:{}"
,
extPuchasePlanExcelVO
);
cachedDataList
.
add
(
extPuchasePlanExcelVO
);
if
(
cachedDataList
.
size
()
>=
BATCH_COUNT
)
{
// 处理缓存的数据,比如说入库。。。
// 然后清空
//todo 需要处理采购计划数据到数据库
cachedDataList
.
clear
();
}
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
analysisContext
)
{
// 收尾工作,处理剩下的缓存数据。。。
log
.
info
(
"sheet={} 所有数据解析完成!"
,
analysisContext
.
readSheetHolder
().
getSheetName
());
}
/**
*
* @param exception
* @param context
* @throws Exception
*/
@Override
public
void
onException
(
Exception
exception
,
AnalysisContext
context
)
throws
Exception
{
log
.
error
(
"======>>>解析异常:"
,
exception
);
throw
exception
;
}
//todo wq测试代码
// public static void main(String[] args) {
// String fileName = "F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板.xlsx";
// EasyExcel.read(fileName, ExtPuchasePlanExcelVO.class, new PurchasePlanExcelListenner()).sheet().doRead();
// }
}
dcs-plan-common/src/main/java/com/yonde/dcs/plan/common/utils/EasyExcelUtils.java
0 → 100644
View file @
84248c81
This diff is collapsed.
Click to expand it.
dcs-plan-common/src/main/java/com/yonde/dcs/plan/common/vo/ExtPuchasePlanExcelVO.java
0 → 100644
View file @
84248c81
package
com
.
yonde
.
dcs
.
plan
.
common
.
vo
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.alibaba.excel.annotation.write.style.ColumnWidth
;
import
com.alibaba.excel.annotation.write.style.ContentRowHeight
;
import
com.alibaba.excel.annotation.write.style.HeadRowHeight
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.NoArgsConstructor
;
import
org.apache.poi.ss.usermodel.CellType
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
@EqualsAndHashCode
(
callSuper
=
false
)
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
ExtPuchasePlanExcelVO
{
@ExcelProperty
(
value
=
{
"采购计划"
,
"操作*"
},
index
=
0
)
@ColumnWidth
(
20
)
private
String
operation
;
/**
* 外协项目名称
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"外协(外购)项目名称*"
},
index
=
1
)
@ColumnWidth
(
20
)
private
String
outsourceProjectName
;
/**
* 采购技术文件实际提交时间
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"采购技术文件提交时间*"
},
index
=
2
)
@ColumnWidth
(
20
)
private
LocalDateTime
purDesignFileSubmitTime
;
/**
* 合同签订时间*
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"合同签订时间*"
},
index
=
3
)
@ColumnWidth
(
20
)
private
LocalDateTime
contractActualSigningTime
;
/**
* 合同交付时间*
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"合同交付时间*"
},
index
=
4
)
@ColumnWidth
(
20
)
private
String
contractActualDeliveryTime
;
/**
* 采购技术文件负责人
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"采购技术文件负责人*"
},
index
=
5
)
@ColumnWidth
(
20
)
private
String
purDesignFileManager
;
/**
* 采购预算
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"预算(万元)*"
},
index
=
6
)
@ColumnWidth
(
20
)
private
String
purchaseBudget
;
/**
* 项目代号
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"项目代号*"
},
index
=
7
)
@ColumnWidth
(
20
)
private
String
projectCode
;
/**
* 密级
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"密级*"
},
index
=
8
)
@ColumnWidth
(
20
)
private
String
secretCode
;
/**
* 备注
*/
@ExcelProperty
(
value
=
{
"采购计划"
,
"备注*"
},
index
=
9
)
@ColumnWidth
(
20
)
private
String
note
;
public
static
void
main
(
String
[]
args
)
{
List
<
ExtPuchasePlanExcelVO
>
list
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
1
;
i
++){
ExtPuchasePlanExcelVO
extPuchasePlanExcelVO
=
new
ExtPuchasePlanExcelVO
();
extPuchasePlanExcelVO
.
setNote
(
"测试"
+
i
);
list
.
add
(
extPuchasePlanExcelVO
);
}
EasyExcel
.
write
(
"F:\\yangyi\\项目\\清华核研院\\核研院设计文档及原型\\采购计划导入模板.xlsx"
,
ExtPuchasePlanExcelVO
.
class
)
.
sheet
(
"采购计划"
).
doWrite
(
list
);
}
}
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