Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
qianhe-ydsj
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangyun
qianhe-ydsj
Commits
5da44a9a
Commit
5da44a9a
authored
Sep 22, 2025
by
wangjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2025-09-22 wj 整体修改3
parent
b418d657
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
0 deletions
+148
-0
qianhe-ydsj/src/main/java/com/qianhe/controller/SjFybpController.java
+148
-0
qianhe-ydsj/src/main/resources/static/txgt_fy_zsdwfytj.xlsx
+0
-0
No files found.
qianhe-ydsj/src/main/java/com/qianhe/controller/SjFybpController.java
View file @
5da44a9a
package
com
.
qianhe
.
controller
;
package
com
.
qianhe
.
controller
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
com.qianhe.common.core.domain.BaseEntity
;
import
com.qianhe.common.core.domain.BaseEntity
;
import
com.qianhe.common.exception.BusinessException
;
import
com.qianhe.common.utils.bean.BeanUtils
;
import
com.qianhe.common.utils.bean.BeanUtils
;
import
com.qianhe.domain.SjGfjsYdjcjl
;
import
com.qianhe.domain.SjGfjsZsdwwtcj
;
import
com.qianhe.domain.Vo.SjfybpVo
;
import
com.qianhe.domain.Vo.SjfybpVo
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
@@ -231,4 +243,140 @@ public class SjFybpController extends BaseController
...
@@ -231,4 +243,140 @@ public class SjFybpController extends BaseController
List
<
SjfybpVo
>
list
=
sjFybpService
.
zsdwNdfytj
(
sjFybp
);
List
<
SjfybpVo
>
list
=
sjFybpService
.
zsdwNdfytj
(
sjFybp
);
return
list
;
return
list
;
}
}
//导出 直属单位三基建设费用统计表
@Log
(
title
=
"导出 直属单位三基建设费用统计表"
,
businessType
=
BusinessType
.
EXPORT
)
@PostMapping
(
"/exportZsdwNdfytj"
)
public
void
exportZsdwNdfytj
(
HttpServletResponse
response
,
SjFybp
sjFybp
)
{
List
<
SjfybpVo
>
list
=
sjFybpService
.
zsdwNdfytj
(
sjFybp
);
Workbook
exl
=
null
;
OutputStream
out
=
null
;
InputStream
in
=
null
;
try
{
in
=
this
.
getClass
().
getResourceAsStream
(
"/static/txgt_fy_zsdwfytj.xlsx"
);
exl
=
WorkbookFactory
.
create
(
in
);
out
=
response
.
getOutputStream
();
response
.
reset
();
String
filename
=
URLEncoder
.
encode
(
sjFybp
.
getFyrq
()
+
"年 直属单位三基建设费用统计表.xlsx"
,
"UTF-8"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
filename
);
response
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
);
dcExcelCb
(
exl
,
list
);
exl
.
write
(
out
);
exl
.
close
();
}
catch
(
Exception
e
){
e
.
getMessage
();
throw
new
BusinessException
(
"导出Excel失败,请联系网站管理员!"
);
}
finally
{
if
(
exl
!=
null
)
{
try
{
exl
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
if
(
out
!=
null
)
{
try
{
out
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
}
}
//导出excel 动态设置从表数据
private
void
dcExcelCb
(
Workbook
exl
,
List
<
SjfybpVo
>
cbList
){
Sheet
sheet
=
exl
.
getSheet
(
"三基建设费用统计表"
);
// sheet.getRow(0).getCell(0).setCellValue(sjZdbfZsdwkhpj.getNd()+"年"+sjZdbfZsdwkhpj.getZqfw()+sjZdbfZsdwkhpj.getDeptName());
CellStyle
cellStyle
=
exl
.
createCellStyle
();
cellStyle
.
setWrapText
(
true
);
cellStyle
.
setAlignment
(
HorizontalAlignment
.
LEFT
);
cellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
cellStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
cellStyle
.
setBottomBorderColor
(
IndexedColors
.
BLACK
.
getIndex
());
cellStyle
.
setBorderLeft
(
BorderStyle
.
THIN
);
cellStyle
.
setLeftBorderColor
(
IndexedColors
.
BLACK
.
getIndex
());
cellStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
cellStyle
.
setRightBorderColor
(
IndexedColors
.
BLACK
.
getIndex
());
cellStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
cellStyle
.
setTopBorderColor
(
IndexedColors
.
BLACK
.
getIndex
());
int
lastRow
=
sheet
.
getLastRowNum
()+
1
;
for
(
SjfybpVo
tmp:
cbList
){
Row
row
=
sheet
.
createRow
(
lastRow
);
row
.
setHeightInPoints
(
18
);
int
m
=
0
;
int
xh
=
1
;
//第一列的序号
Cell
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
xh
);
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getDeptName
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getAbztqzded
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getYsyje
().
toString
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getJd
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzc1
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzcmx1
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzc2
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzcmx2
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzc3
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzcmx3
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzc4
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzcmx4
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzc5
());
cell
=
row
.
createCell
(
m
++);
cell
.
setCellStyle
(
cellStyle
);
cell
.
setCellValue
(
tmp
.
getXmzcmx5
());
lastRow
++;
xh
++;
}
//合并行
mergeCellsByColumn
(
sheet
,
0
);
mergeCellsByColumn
(
sheet
,
1
);
mergeCellsByColumn
(
sheet
,
2
);
mergeCellsByColumn
(
sheet
,
3
);
if
(
cbList
.
size
()>
0
){
sheet
.
getRow
(
1
).
getCell
(
2
).
setCellValue
(
cbList
.
get
(
0
).
getFyrq
()
+
"年"
);
}
}
// 根据某一列的值是否相同,对其他列的单元格进行合并
private
static
void
mergeCellsByColumn
(
Sheet
sheet
,
int
columnIndex
)
{
Map
<
String
,
Integer
>
groups
=
new
HashMap
<>();
// 遍历该列,记录相同值的行索引
int
start
=
1
;
int
end
=
1
;
String
old
=
""
;
for
(
int
i
=
1
;
i
<=
sheet
.
getLastRowNum
();
i
++)
{
Row
row
=
sheet
.
getRow
(
i
);
Cell
cell
=
row
.
getCell
(
columnIndex
);
String
cellValue
=
cell
.
getStringCellValue
();
if
(!
groups
.
containsKey
(
cellValue
))
{
if
(
groups
.
get
(
old
)!=
null
){
start
=
groups
.
get
(
old
);
}
old
=
cellValue
;
groups
.
put
(
cellValue
,
i
);
//合并行
mergeCellsInRange
(
sheet
,
columnIndex
,
start
,
end
);
start
=
i
;
end
=
i
;
}
else
{
end
++;
if
(
i
==
sheet
.
getLastRowNum
()){
mergeCellsInRange
(
sheet
,
columnIndex
,
start
,
end
);
}
}
}
}
// 合并指定范围内的单元格
private
static
void
mergeCellsInRange
(
Sheet
sheet
,
int
columnIndex
,
int
startIndex
,
int
endIndex
)
{
if
(
startIndex
!=
endIndex
){
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
startIndex
,
endIndex
,
columnIndex
,
columnIndex
));
}
}
}
}
qianhe-ydsj/src/main/resources/static/txgt_fy_zsdwfytj.xlsx
0 → 100644
View file @
5da44a9a
File added
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