Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
W
work_service
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
licc
work_service
Commits
7b0cd554
Commit
7b0cd554
authored
Mar 13, 2021
by
nie'hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善工时统计
parent
559c5daf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
20 deletions
+65
-20
StatisticsServiceImpl.java
...java/cn/wisenergy/service/impl/StatisticsServiceImpl.java
+26
-8
StatisticsController.java
...energy/web/admin/controller/app/StatisticsController.java
+39
-12
No files found.
wisenergy-service/src/main/java/cn/wisenergy/service/impl/StatisticsServiceImpl.java
View file @
7b0cd554
...
...
@@ -377,6 +377,11 @@ public class StatisticsServiceImpl implements StatisticsService {
public
HSSFWorkbook
exportWorkTimeExcel
(
GetMonthlyCollectParam
param
)
{
log
.
info
(
"StatisticsServiceImpl[]exportWorkTimeExcel[]input.param{}"
+
param
);
PageInfo
dayWorkTimeOfMonth
=
this
.
getDayWorkTimeOfMonth
(
param
);
// 返回一个“暂无数据”的Excel
if
(
CollectionUtil
.
isEmpty
(
dayWorkTimeOfMonth
.
getList
()))
{
HSSFWorkbook
sheets
=
this
.
creatEmptyHSSFWorkbook
();
return
sheets
;
}
Date
date
=
DateUtil
.
convertStrToDate
(
param
.
getYear
()
+
"-"
+
param
.
getMonth
(),
"yyyy-MM"
);
// 传参的时间当月总天数
int
dayCount
=
DateUtil
.
getMonthDaysArray
(
date
).
length
;
...
...
@@ -735,9 +740,7 @@ public class StatisticsServiceImpl implements StatisticsService {
log
.
info
(
"StatisticsServiceImpl[]exportUserStatistics[]param{}"
+
userId
+
deptId
+
startDate
+
endDate
);
List
<
UserWorkTimeStatisticsByProject
>
userWorkTimeStatisticsReport
=
this
.
getUserWorkTimeStatisticsReport
(
userId
,
deptId
,
startDate
,
endDate
);
if
(
CollectionUtil
.
isEmpty
(
userWorkTimeStatisticsReport
))
{
HSSFWorkbook
sheets
=
new
HSSFWorkbook
();
HSSFSheet
sheet
=
sheets
.
createSheet
();
sheet
.
createRow
(
0
).
createCell
(
0
).
setCellValue
(
"暂无数据"
);
HSSFWorkbook
sheets
=
this
.
creatEmptyHSSFWorkbook
();
return
sheets
;
}
// 部门信息
...
...
@@ -924,6 +927,11 @@ public class StatisticsServiceImpl implements StatisticsService {
List
<
ProjectStatisticsByMonth
>
projectStatisticsByMonths1
=
workProjectTimeCostMapper
.
selectListStatistics
(
map
);
map
.
replace
(
"isAll"
,
true
);
List
<
ProjectStatisticsByMonth
>
projectStatisticsByMonths2
=
workProjectTimeCostMapper
.
selectListStatistics
(
map
);
// 如果没有项目统计数据,返回Excel显示暂无数据
if
(
CollectionUtil
.
isEmpty
(
projectStatisticsByMonths
))
{
HSSFWorkbook
sheets
=
creatEmptyHSSFWorkbook
();
return
sheets
;
}
// 计算项目合计
this
.
addProjectStatisticsTotalTime
(
projectStatisticsByMonths
,
"合计"
);
this
.
addProjectStatisticsTotalTime
(
projectStatisticsByMonths1
,
"合计"
);
...
...
@@ -950,7 +958,7 @@ public class StatisticsServiceImpl implements StatisticsService {
HSSFRow
row_0
=
sheet
.
createRow
(
0
);
row_0
.
createCell
(
0
).
setCellValue
(
"部门:"
+
deptName
+
" 项目:"
+
projectName
+
" 时间:"
+
date
);
// 合并第一行的前五个单元格
CellRangeAddress
cellRangeAddress2
=
new
CellRangeAddress
(
0
,
0
,
0
,
4
);
CellRangeAddress
cellRangeAddress2
=
new
CellRangeAddress
(
0
,
0
,
0
,
15
);
sheet
.
addMergedRegion
(
cellRangeAddress2
);
setBorderStyle
(
BorderStyle
.
THIN
,
cellRangeAddress2
,
sheet
);
...
...
@@ -1017,7 +1025,10 @@ public class StatisticsServiceImpl implements StatisticsService {
cell
.
setCellStyle
(
ordinaryCellStyle
);
}
}
// 第一行的样式,水平左对齐
HSSFCellStyle
ordinaryCellStyle1
=
this
.
createOrdinaryCellStyle
(
sheets
);
ordinaryCellStyle1
.
setAlignment
(
HorizontalAlignment
.
LEFT
);
sheet
.
getRow
(
0
).
getCell
(
0
).
setCellStyle
(
ordinaryCellStyle1
);
}
// 释放资源
this
.
closeSheets
(
sheets
);
...
...
@@ -1121,11 +1132,9 @@ public class StatisticsServiceImpl implements StatisticsService {
List
<
ProjectStatisticsByMonth
.
StatisticsDateAndWorkTime
>
statisticsDateAndWorkTimes
=
projectStatisticsByMonth
.
getStatisticsDateAndWorkTimes
();
for
(
int
i
=
0
;
i
<
yearMonthList
.
size
();
i
++)
{
String
s
=
yearMonthList
.
get
(
i
);
String
date
=
new
String
()
;
String
date
=
""
;
if
(
i
<
statisticsDateAndWorkTimes
.
size
())
{
date
=
statisticsDateAndWorkTimes
.
get
(
i
).
getDate
();
}
else
{
break
;
}
// 时间不连续,创建对象
if
(!
s
.
equals
(
date
))
{
...
...
@@ -1265,4 +1274,13 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
// 返回一个空的Excel
public
HSSFWorkbook
creatEmptyHSSFWorkbook
(){
HSSFWorkbook
sheets
=
new
HSSFWorkbook
();
HSSFSheet
sheet
=
sheets
.
createSheet
();
sheet
.
createRow
(
0
).
createCell
(
0
).
setCellValue
(
"暂无数据"
);
return
sheets
;
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/StatisticsController.java
View file @
7b0cd554
...
...
@@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -90,17 +91,27 @@ public class StatisticsController extends BaseController {
@ApiOperation
(
value
=
"导出部门员工一个月每天的工时"
,
notes
=
"导出部门员工一个月每天的工时"
)
@GetMapping
(
"/exportWorkTime"
)
public
void
export
(
GetMonthlyCollectParam
param
,
HttpServletResponse
response
)
{
public
void
export
(
GetMonthlyCollectParam
param
,
HttpServletResponse
response
)
{
log
.
info
(
"StatisticsController[]export[]input.param"
+
param
);
HSSFWorkbook
sheets
=
new
HSSFWorkbook
();
try
{
// 获取excel
HSSFWorkbook
sheets
=
statisticsService
.
exportWorkTimeExcel
(
param
);
sheets
=
statisticsService
.
exportWorkTimeExcel
(
param
);
// 获取excel中的第2行第2列中的部门名称
String
deptName
=
sheets
.
getSheet
(
"Sheet1"
).
getRow
(
1
).
getCell
(
1
).
getStringCellValue
();
// 文件名
String
fileName
=
deptName
+
"-"
+
param
.
getYear
()
+
"年"
+
param
.
getMonth
()
+
"月工时汇总"
;
this
.
downExcel
(
response
,
sheets
,
fileName
);
this
.
downExcel
(
response
,
sheets
,
fileName
);
}
finally
{
try
{
sheets
.
close
();
}
catch
(
IOException
e
)
{
throw
new
BaseCustomException
(
BASE_RESP_CODE_ENUM
.
SERVER_ERROR
);
}
}
}
...
...
@@ -142,11 +153,20 @@ public class StatisticsController extends BaseController {
@GetMapping
(
"/exportUserStatistics"
)
public
void
exportUserStatistics
(
Integer
userId
,
Integer
deptId
,
String
startDate
,
String
endDate
,
HttpServletResponse
response
)
{
log
.
info
(
"StatisticsController[]exportUserStatistics[]input.param"
+
userId
+
deptId
+
startDate
+
endDate
);
// 获取excel
HSSFWorkbook
sheets
=
statisticsService
.
exportUserStatistics
(
userId
,
deptId
,
startDate
,
endDate
);
HSSFWorkbook
sheets
=
new
HSSFWorkbook
();
try
{
// 获取excel
sheets
=
statisticsService
.
exportUserStatistics
(
userId
,
deptId
,
startDate
,
endDate
);
String
fileName
=
"人员工时统计"
;
this
.
downExcel
(
response
,
sheets
,
fileName
);
}
finally
{
try
{
sheets
.
close
();
}
catch
(
IOException
e
)
{
throw
new
BaseCustomException
(
BASE_RESP_CODE_ENUM
.
SERVER_ERROR
);
}
}
String
fileName
=
"人员工时统计"
;
this
.
downExcel
(
response
,
sheets
,
fileName
);
}
...
...
@@ -159,12 +179,19 @@ public class StatisticsController extends BaseController {
@GetMapping
(
"/exportProjectStatistics"
)
public
void
exportProjectStatistics
(
Integer
userId
,
Integer
year
,
String
projectIds
,
HttpServletResponse
response
)
{
log
.
info
(
"StatisticsController[]exportUserStatistics[]input.param"
+
userId
+
year
+
projectIds
);
HSSFWorkbook
sheets
=
new
HSSFWorkbook
();
// 获取excel
HSSFWorkbook
sheets
=
statisticsService
.
exportProjectStatistics
(
userId
,
year
,
projectIds
);
String
fileName
=
"项目工时统计明细"
;
//attachment为以附件方式下载
downExcel
(
response
,
sheets
,
fileName
);
try
{
sheets
=
statisticsService
.
exportProjectStatistics
(
userId
,
year
,
projectIds
);
String
fileName
=
"项目工时统计明细"
;
downExcel
(
response
,
sheets
,
fileName
);
}
finally
{
try
{
sheets
.
close
();
}
catch
(
IOException
e
)
{
throw
new
BaseCustomException
(
BASE_RESP_CODE_ENUM
.
SERVER_ERROR
);
}
}
}
// 导出Excel
...
...
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