Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-zx-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
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
Jobs
Commits
Open sidebar
项目统一框架
一体化_户用光伏项目代码
amos-boot-zx-biz
Commits
4bbf8e5d
Commit
4bbf8e5d
authored
Oct 10, 2024
by
chenzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
资料下载
parent
4ca91033
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
2 deletions
+67
-2
CommonServiceImpl.java
.../boot/module/hygf/biz/service/impl/CommonServiceImpl.java
+67
-2
No files found.
amos-boot-system-jxiop/amos-boot-module-hygf-biz/src/main/java/com/yeejoin/amos/boot/module/hygf/biz/service/impl/CommonServiceImpl.java
View file @
4bbf8e5d
...
...
@@ -11,6 +11,7 @@ import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import
com.yeejoin.amos.boot.biz.common.utils.RedisUtils
;
import
com.yeejoin.amos.boot.module.hygf.api.Enum.BusinessTypeEnum
;
import
com.yeejoin.amos.boot.module.hygf.api.Enum.FlowStatusEnum
;
import
com.yeejoin.amos.boot.module.hygf.api.dto.SurveyInfoAllDto
;
import
com.yeejoin.amos.boot.module.hygf.api.dto.TaskModelDto
;
import
com.yeejoin.amos.boot.module.hygf.api.util.JsonUtils
;
import
com.yeejoin.amos.boot.module.hygf.biz.feign.TaskV2FeignService
;
...
...
@@ -32,7 +33,12 @@ import java.lang.reflect.Modifier;
import
java.net.URLEncoder
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
/**
* 公共服务实现类
*
...
...
@@ -48,7 +54,8 @@ public class CommonServiceImpl {
private
RedisUtils
redisUtils
;
@Value
(
"classpath:/json/urlInfo.json"
)
private
Resource
urlInfo
;
@Autowired
SurveyInformationServiceImpl
surveyInformationServiceImpl
;
private
static
final
String
regionRedis
=
"app_region_redis"
;
@Autowired
RedisUtils
redisUtil
;
...
...
@@ -403,4 +410,61 @@ public class CommonServiceImpl {
}
return
jsonArray
;
}
public
void
downZiliao
(
String
surveyInformationId
,
String
peasantHouseholdId
,
String
processInstanceId
)
{
SurveyInfoAllDto
returnDto
=
surveyInformationServiceImpl
.
querySurveyInfo
(
surveyInformationId
,
peasantHouseholdId
,
processInstanceId
,
null
);
// 读取Excel模板
String
templatePath
=
"path/to/informationTemp.xlsx"
;
String
outputPath
=
"path/to/filled_informationTemp.xlsx"
;
Workbook
workbook
=
null
;
try
(
FileInputStream
fis
=
new
FileInputStream
(
templatePath
))
{
workbook
=
new
XSSFWorkbook
(
fis
);
// 处理第一个工作表
Sheet
firstSheet
=
workbook
.
getSheetAt
(
0
);
fillSheet
(
firstSheet
,
returnDto
.
getSurveyInformation
());
// 处理第二个工作表
Sheet
secondSheet
=
workbook
.
getSheetAt
(
1
);
fillSheet
(
secondSheet
,
returnDto
.
getSurveyDetails
());
// 写入到新的Excel文件中
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
outputPath
))
{
workbook
.
write
(
fos
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
/**
* 辅助方法用来填充工作表。
*
* @param sheet 要填充的工作表
* @param data 数据源
*/
private
void
fillSheet
(
Sheet
sheet
,
Object
data
)
{
// 遍历每一行
for
(
Row
row
:
sheet
)
{
// 遍历每一个单元格
for
(
Cell
cell
:
row
)
{
if
(
cell
.
getCellType
()
==
CellType
.
STRING
)
{
String
cellValue
=
cell
.
getStringCellValue
();
try
{
// 尝试获取字段值
Field
field
=
data
.
getClass
().
getDeclaredField
(
cellValue
);
field
.
setAccessible
(
true
);
// 设置为可访问私有字段
Object
value
=
field
.
get
(
data
);
if
(
value
!=
null
)
{
cell
.
setCellValue
(
value
.
toString
());
}
}
catch
(
NoSuchFieldException
|
IllegalAccessException
e
)
{
// 忽略不存在的字段
}
}
}
}
}
}
\ No newline at end of file
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