Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mes
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
ximai
mes
Commits
e191dd30
Commit
e191dd30
authored
Jan 17, 2025
by
温志超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
暂存
parent
39e187b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
262 additions
and
4 deletions
+262
-4
DailyProductionReportController.java
...es/report/controller/DailyProductionReportController.java
+13
-0
DailyProductionReportService.java
...imai/mes/report/service/DailyProductionReportService.java
+3
-0
DailyProductionReportServiceImp.java
.../report/service/impl/DailyProductionReportServiceImp.java
+246
-4
No files found.
mes/src/main/java/com/ximai/mes/report/controller/DailyProductionReportController.java
View file @
e191dd30
...
...
@@ -6,6 +6,7 @@ import com.ximai.common.core.controller.BaseController;
import
com.ximai.common.core.domain.AjaxResult
;
import
com.ximai.common.core.page.TableDataInfo
;
import
com.ximai.common.enums.BusinessType
;
import
com.ximai.common.utils.poi.ExcelUtil
;
import
com.ximai.mes.report.request.DailyProductionReportRequest
;
import
com.ximai.mes.report.request.FeedbackRequest
;
import
com.ximai.mes.report.response.FeedbackResponse
;
...
...
@@ -16,9 +17,11 @@ import io.swagger.annotations.ApiOperation;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.text.DecimalFormat
;
...
...
@@ -52,6 +55,16 @@ public class DailyProductionReportController extends BaseController {
return
AjaxResult
.
success
(
data
);
}
/**
* 明细界面导出
*/
@PreAuthorize
(
"@ss.hasPermi('pro:materialReturn:export')"
)
@Log
(
title
=
"日产能对比统计:统计方式工序导出"
,
businessType
=
BusinessType
.
EXPORT
)
@PostMapping
(
"/getListByProcess/export"
)
public
void
export
(
HttpServletResponse
response
,
DailyProductionReportRequest
dailyProductionReportRequest
)
{
List
data
=
dailyProductionReportService
.
getListByProcess
(
dailyProductionReportRequest
);
dailyProductionReportService
.
export
(
response
,
data
,
"日产能对比统计-统计方式工序导出"
,
"工序名称"
,
"工序编码"
,
"工序"
,
dailyProductionReportRequest
);
}
@ApiOperation
(
"日产能对比统计:统计方式车间"
)
@PreAuthorize
(
"@ss.hasPermi('mes:pro:dailyProductionReport:get')"
)
...
...
mes/src/main/java/com/ximai/mes/report/service/DailyProductionReportService.java
View file @
e191dd30
...
...
@@ -2,6 +2,7 @@ package com.ximai.mes.report.service;
import
com.ximai.mes.report.request.DailyProductionReportRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -17,4 +18,6 @@ public interface DailyProductionReportService {
List
getListByWorkunit
(
DailyProductionReportRequest
dailyProductionReportRequest
);
List
getListByUser
(
DailyProductionReportRequest
dailyProductionReportRequest
);
public
void
export
(
HttpServletResponse
response
,
List
<
Map
>
returnList
,
String
filename
,
String
name
,
String
code
,
String
key
,
DailyProductionReportRequest
dailyProductionReportRequest
);
}
mes/src/main/java/com/ximai/mes/report/service/impl/DailyProductionReportServiceImp.java
View file @
e191dd30
...
...
@@ -5,19 +5,23 @@ import com.ximai.common.utils.data.ExceptionUtil;
import
com.ximai.mes.report.mapper.DailyProductionReportMapper
;
import
com.ximai.mes.report.request.DailyProductionReportRequest
;
import
com.ximai.mes.report.service.DailyProductionReportService
;
import
org.apache.commons.compress.utils.IOUtils
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.usermodel.*
;
import
org.checkerframework.checker.units.qual.A
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.net.URLEncoder
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDate
;
import
java.time.temporal.ChronoUnit
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
...
...
@@ -199,4 +203,242 @@ public class DailyProductionReportServiceImp implements DailyProductionReportSer
return
returnList
;
}
public
void
export
(
HttpServletResponse
response
,
List
<
Map
>
returnList
,
String
filename
,
String
name
,
String
code
,
String
key
,
DailyProductionReportRequest
dailyProductionReportRequest
){
// 第一步,创建一个Workbook,对应一个Excel文件
XSSFWorkbook
wb
=
new
XSSFWorkbook
();
// 第二步,在Workbook中添加一个sheet,对应Excel文件中的sheet
XSSFSheet
sheet
=
wb
.
createSheet
(
"sheet"
);
// 第三步,设置样式以及字体样式
XSSFCellStyle
titleStyle
=
createTitleCellStyle
(
wb
);
XSSFCellStyle
headerStyle
=
createHeadCellStyle
(
wb
);
XSSFCellStyle
contentStyle
=
createContentCellStyle
(
wb
);
if
(
returnList
.
size
()
>
0
){
// 在工作表中合并单元格,合并第一行的前两个单元格
CellRangeAddress
cellRangeAddress
=
new
CellRangeAddress
(
0
,
1
,
0
,
0
);
// 参数依次是:开始行,结束行,开始列,结束列
CellRangeAddress
cellRangeAddressb
=
new
CellRangeAddress
(
0
,
1
,
1
,
1
);
sheet
.
addMergedRegion
(
cellRangeAddress
);
sheet
.
addMergedRegion
(
cellRangeAddressb
);
// 创建第一页的第一行,索引从0开始
XSSFRow
row0
=
sheet
.
createRow
(
0
);
XSSFRow
row1
=
sheet
.
createRow
(
1
);
// 设置列宽
XSSFCell
r0c0
=
row0
.
createCell
(
0
);
r0c0
.
setCellValue
(
code
);
r0c0
.
setCellStyle
(
headerStyle
);
row0
.
setHeight
((
short
)
600
);
XSSFCell
r1c0
=
row1
.
createCell
(
0
);
r1c0
.
setCellStyle
(
headerStyle
);
XSSFCell
r0c1
=
row0
.
createCell
(
1
);
r0c1
.
setCellValue
(
name
);
r0c1
.
setCellStyle
(
headerStyle
);
XSSFCell
r1c1
=
row1
.
createCell
(
1
);
r1c1
.
setCellStyle
(
headerStyle
);
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
startDate
=
simpleDateFormat
.
format
(
dailyProductionReportRequest
.
getStartDate
());
String
endDate
=
simpleDateFormat
.
format
(
dailyProductionReportRequest
.
getEndDate
());
List
<
String
>
dataList
=
getAscDateList
(
startDate
,
endDate
);
for
(
int
size
=
0
;
size
<
dataList
.
size
()
*
4
+
6
;
size
++){
sheet
.
setColumnWidth
(
size
,
3000
);
}
int
i
=
2
;
int
x
=
0
;
for
(
String
date
:
dataList
){
x
++;
//设置日期
CellRangeAddress
cellAddresses
=
new
CellRangeAddress
(
0
,
0
,
i
,
i
+
3
);
sheet
.
addMergedRegion
(
cellAddresses
);
XSSFCell
r0i
=
row0
.
createCell
(
i
);
r0i
.
setCellValue
(
date
);
r0i
.
setCellStyle
(
headerStyle
);
//设置日期下的字段
XSSFCell
r1i
=
row1
.
createCell
(
i
);
r1i
.
setCellValue
(
"报工数量"
);
r1i
.
setCellStyle
(
headerStyle
);
XSSFCell
r1i1
=
row1
.
createCell
(
i
+
1
);
r1i1
.
setCellValue
(
"合格数量"
);
r1i1
.
setCellStyle
(
headerStyle
);
XSSFCell
r1i2
=
row1
.
createCell
(
i
+
2
);
r1i2
.
setCellValue
(
"不合格数量"
);
r1i2
.
setCellStyle
(
headerStyle
);
XSSFCell
r1i3
=
row1
.
createCell
(
i
+
3
);
r1i3
.
setCellValue
(
"合格率"
);
r1i3
.
setCellStyle
(
headerStyle
);
for
(
int
t
=
0
;
t
<
returnList
.
size
()
;
t
++){
Map
rowData
=
returnList
.
get
(
t
);
XSSFRow
rt
=
sheet
.
createRow
(
2
+
t
);
if
(
rowData
!=
null
){
Map
dataMap
=
(
Map
)
rowData
.
get
(
date
);
if
(
dataMap
.
keySet
().
size
()
>
0
){
Double
feedback
=
(
Double
)
dataMap
.
get
(
"报工数量"
);
Double
unqualify
=
(
Double
)
dataMap
.
get
(
"不合格数量"
);
Double
qualify
=
(
Double
)
dataMap
.
get
(
"合格数量"
);
BigDecimal
fee
=
(
BigDecimal
)
dataMap
.
get
(
"合格率"
);
if
(
feedback
==
null
){
feedback
=
(
Double
)
dataMap
.
get
(
"日期统计报工数量"
);
unqualify
=
(
Double
)
dataMap
.
get
(
"日期统计不合格数量"
);
qualify
=
(
Double
)
dataMap
.
get
(
"日期统计合格数量"
);
fee
=
(
BigDecimal
)
dataMap
.
get
(
"日期统计合格率"
);
}
XSSFCell
ri
=
rt
.
createCell
(
i
);
ri
.
setCellValue
(
"a"
);
//ri.setCellStyle(contentStyle);
XSSFCell
ri1
=
rt
.
createCell
(
i
+
1
);
ri1
.
setCellValue
(
qualify
.
doubleValue
());
//ri1.setCellStyle(contentStyle);
XSSFCell
ri2
=
rt
.
createCell
(
i
+
2
);
ri2
.
setCellValue
(
unqualify
.
doubleValue
());
//ri2.setCellStyle(contentStyle);
XSSFCell
ri3
=
rt
.
createCell
(
i
+
3
);
ri3
.
setCellValue
(
fee
.
doubleValue
());
//ri3.setCellStyle(contentStyle);
}
XSSFCell
ri0
=
rt
.
createCell
(
0
);
ri0
.
setCellValue
((
String
)
rowData
.
get
(
code
));
XSSFCell
ri1
=
rt
.
createCell
(
1
);
ri1
.
setCellValue
((
String
)
rowData
.
get
(
name
));
XSSFCell
ri
=
rt
.
createCell
(
i
);
ri
.
setCellValue
(
"a"
);
}
}
i
=
i
+
4
;
//末尾累加统计
if
(
dataList
.
size
()
==
x
){
//设置日期
CellRangeAddress
cellAddressesOver
=
new
CellRangeAddress
(
0
,
0
,
i
,
i
+
3
);
sheet
.
addMergedRegion
(
cellAddressesOver
);
XSSFCell
r0iOver
=
row0
.
createCell
(
i
);
r0iOver
.
setCellValue
(
"合计"
);
r0iOver
.
setCellStyle
(
headerStyle
);
//设置日期下的字段
XSSFCell
r1iOver
=
row1
.
createCell
(
i
);
r1iOver
.
setCellValue
(
"报工数量"
);
r1iOver
.
setCellStyle
(
headerStyle
);
XSSFCell
r1i1Over
=
row1
.
createCell
(
i
+
1
);
r1i1Over
.
setCellValue
(
"合格数量"
);
r1i1Over
.
setCellStyle
(
headerStyle
);
XSSFCell
r1i2Over
=
row1
.
createCell
(
i
+
2
);
r1i2Over
.
setCellValue
(
"不合格数量"
);
r1i2Over
.
setCellStyle
(
headerStyle
);
XSSFCell
r1i3Over
=
row1
.
createCell
(
i
+
3
);
r1i3Over
.
setCellValue
(
"合格率"
);
r1i3Over
.
setCellStyle
(
headerStyle
);
}
}
}
buildExcelDocument
(
filename
+
".xlsx"
,
wb
,
response
);
}
/**
* 创建标题样式
*
* @param wb
* @return
*/
private
static
XSSFCellStyle
createTitleCellStyle
(
XSSFWorkbook
wb
)
{
XSSFCellStyle
cellStyle
=
wb
.
createCellStyle
();
cellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
//水平居中
cellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
//垂直对齐
cellStyle
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
// cellStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());//背景颜色
XSSFFont
headerFont1
=
(
XSSFFont
)
wb
.
createFont
();
// 创建字体样式
headerFont1
.
setBold
(
true
);
//字体加粗
headerFont1
.
setFontName
(
"黑体"
);
// 设置字体类型
headerFont1
.
setFontHeightInPoints
((
short
)
15
);
// 设置字体大小
cellStyle
.
setFont
(
headerFont1
);
// 为标题样式设置字体样式
return
cellStyle
;
}
/**
* 创建表头样式
*
* @param wb
* @return
*/
private
static
XSSFCellStyle
createHeadCellStyle
(
XSSFWorkbook
wb
)
{
XSSFCellStyle
cellStyle
=
wb
.
createCellStyle
();
cellStyle
.
setWrapText
(
true
);
// 设置自动换行
cellStyle
.
setFillForegroundColor
(
IndexedColors
.
GREY_25_PERCENT
.
getIndex
());
//背景颜色
cellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
//水平居中
cellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
//垂直对齐
cellStyle
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
// cellStyle.setBottomBorderColor(IndexedColors.BLACK.index);
cellStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
//下边框
cellStyle
.
setBorderLeft
(
BorderStyle
.
THIN
);
//左边框
cellStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
//右边框
cellStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
//上边框
XSSFFont
headerFont
=
(
XSSFFont
)
wb
.
createFont
();
// 创建字体样式
headerFont
.
setBold
(
true
);
//字体加粗
headerFont
.
setFontName
(
"黑体"
);
// 设置字体类型
headerFont
.
setFontHeightInPoints
((
short
)
12
);
// 设置字体大小
cellStyle
.
setFont
(
headerFont
);
// 为标题样式设置字体样式
return
cellStyle
;
}
/**
* 创建内容样式
*
* @param wb
* @return
*/
private
static
XSSFCellStyle
createContentCellStyle
(
XSSFWorkbook
wb
)
{
XSSFCellStyle
cellStyle
=
wb
.
createCellStyle
();
cellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
// 垂直居中
cellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
// 水平居中
cellStyle
.
setWrapText
(
true
);
// 设置自动换行
cellStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
//下边框
cellStyle
.
setBorderLeft
(
BorderStyle
.
THIN
);
//左边框
cellStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
//右边框
cellStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
//上边框
// 生成12号字体
XSSFFont
font
=
wb
.
createFont
();
font
.
setColor
((
short
)
8
);
font
.
setFontHeightInPoints
((
short
)
12
);
cellStyle
.
setFont
(
font
);
return
cellStyle
;
}
private
static
void
buildExcelDocument
(
String
fileName
,
Workbook
wb
,
HttpServletResponse
response
)
{
try
{
response
.
setContentType
(
"application/octet-stream"
);
// 可自行定义编码格式
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
fileName
,
"utf-8"
));
//清除jsp编译html文件的空白,防止excel出现空行
response
.
flushBuffer
();
//写出
wb
.
write
(
response
.
getOutputStream
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
IOUtils
.
closeQuietly
(
wb
);
}
}
}
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