Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
caosy
/
fun-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d723a921
authored
Jan 25, 2019
by
chongli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
赛事导出分组excel功能开发
parent
9d4b25d6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
184 additions
and
0 deletions
src/main/java/com/ctrip/fun/admin/controller/golf/EventCustomerInfoConttroller.java
src/main/java/com/ctrip/fun/admin/service/basic/InvoiceRequestExcelImportService.java
src/main/webapp/WEB-INF/templates/golf/findOrderPlayers.ftl
src/main/java/com/ctrip/fun/admin/controller/golf/EventCustomerInfoConttroller.java
View file @
d723a921
...
...
@@ -2,6 +2,7 @@ package com.ctrip.fun.admin.controller.golf;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
...
...
@@ -249,6 +250,173 @@ public class EventCustomerInfoConttroller {
}
return
workBook
;
}
private
XSSFWorkbook
buildExcelForCourses
(
Map
<
String
,
List
<
OrderPlayerBean
>>
beansMap
)
{
XSSFWorkbook
workBook
=
new
XSSFWorkbook
();
XSSFSheet
sheet
=
workBook
.
createSheet
(
"playerGroup"
);
int
[]
sheetWitdh
=
{
16
*
256
,
16
*
256
,
16
*
256
,
16
*
256
,
16
*
256
};
int
sheetRowNum
=
0
;
XSSFCellStyle
headStyle
=
workBook
.
createCellStyle
();
headStyle
.
setAlignment
(
XSSFCellStyle
.
ALIGN_CENTER
);
headStyle
.
setVerticalAlignment
(
XSSFCellStyle
.
VERTICAL_CENTER
);
headStyle
.
setBorderLeft
(
XSSFCellStyle
.
BORDER_THIN
);
headStyle
.
setBorderBottom
(
XSSFCellStyle
.
BORDER_THIN
);
headStyle
.
setBorderRight
(
XSSFCellStyle
.
BORDER_THIN
);
headStyle
.
setBorderTop
(
XSSFCellStyle
.
BORDER_THIN
);
XSSFCellStyle
cellStyle_body
=
workBook
.
createCellStyle
();
cellStyle_body
.
setAlignment
(
XSSFCellStyle
.
ALIGN_CENTER
);
cellStyle_body
.
setVerticalAlignment
(
XSSFCellStyle
.
VERTICAL_CENTER
);
cellStyle_body
.
setBorderLeft
(
XSSFCellStyle
.
BORDER_THIN
);
cellStyle_body
.
setBorderBottom
(
XSSFCellStyle
.
BORDER_THIN
);
cellStyle_body
.
setBorderRight
(
XSSFCellStyle
.
BORDER_THIN
);
cellStyle_body
.
setBorderTop
(
XSSFCellStyle
.
BORDER_THIN
);
Date
playDate
=
null
;
//打球日期
String
productName
=
null
;
//产品名称
Iterator
<
Entry
<
String
,
List
<
OrderPlayerBean
>>>
iters
=
beansMap
.
entrySet
().
iterator
();
while
(
iters
.
hasNext
())
{
Entry
<
String
,
List
<
OrderPlayerBean
>>
next
=
iters
.
next
();
List
<
OrderPlayerBean
>
orderPlayerBeans
=
next
.
getValue
();
for
(
int
i
=
0
;
i
<
orderPlayerBeans
.
size
();
i
++)
{
playDate
=
orderPlayerBeans
.
get
(
0
).
getPlayDate
();
productName
=
orderPlayerBeans
.
get
(
0
).
getProductName
();
}
}
//创建活动最大的标题:日期:产品名称
XSSFRow
bigTitleRow
=
sheet
.
createRow
(
sheetRowNum
++);
bigTitleRow
.
setHeight
((
short
)
(
2
*
256
));
XSSFCell
bigTitleRow_Cell
=
bigTitleRow
.
createCell
(
0
);
bigTitleRow_Cell
.
setCellStyle
(
cellStyle_body
);
bigTitleRow_Cell
.
setCellValue
(
DateUtil
.
getDateStrC
(
playDate
)+
":"
+
productName
);
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
0
,
0
,
0
,
4
));
for
(
int
i
=
0
;
i
<
4
;
i
++){
XSSFCell
createCell
=
bigTitleRow
.
createCell
(
1
+
i
);
createCell
.
setCellStyle
(
cellStyle_body
);
createCell
.
setCellValue
(
""
);
}
XSSFRow
row
=
sheet
.
createRow
(
sheetRowNum
++);
row
.
setHeight
((
short
)
(
2
*
256
));
// 创建表格头信息
XSSFCell
createCell_1
=
row
.
createCell
(
0
);
createCell_1
.
setCellStyle
(
headStyle
);
createCell_1
.
setCellValue
(
"开球时间"
);
XSSFCell
createCell_2
=
row
.
createCell
(
1
);
createCell_2
.
setCellStyle
(
headStyle
);
createCell_2
.
setCellValue
(
"姓名"
);
for
(
int
i
=
0
;
i
<
3
;
i
++){
XSSFCell
createCell
=
row
.
createCell
(
2
+
i
);
createCell
.
setCellStyle
(
headStyle
);
createCell
.
setCellValue
(
""
);
}
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
1
,
1
,
1
,
4
));
Iterator
<
Entry
<
String
,
List
<
OrderPlayerBean
>>>
iter
=
beansMap
.
entrySet
().
iterator
();
while
(
iter
.
hasNext
())
{
Entry
<
String
,
List
<
OrderPlayerBean
>>
next
=
iter
.
next
();
List
<
OrderPlayerBean
>
orderPlayerBeans
=
next
.
getValue
();
int
size
=
orderPlayerBeans
.
size
();
XSSFRow
dataRow
=
null
;
for
(
int
i
=
0
;
i
<
orderPlayerBeans
.
size
();
i
++)
{
if
(
i
%
4
==
0
){
dataRow
=
sheet
.
createRow
(
sheetRowNum
++);
dataRow
.
setHeight
((
short
)
(
2
*
256
));
}
OrderPlayerBean
bean
=
orderPlayerBeans
.
get
(
i
);
XSSFCell
dataCell_1
=
dataRow
.
createCell
(
i
%
4
+
1
);
dataCell_1
.
setCellValue
(
bean
.
getPlayerName
());
dataCell_1
.
setCellStyle
(
cellStyle_body
);
if
(
i
==
0
)
{
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
sheetRowNum
-
1
,(
sheetRowNum
-
1
)
+
((
size
-
1
)/
4
),
0
,
0
));
XSSFCell
dataCell_2
=
dataRow
.
createCell
(
0
);
dataCell_2
.
setCellValue
(
bean
.
getTeeTime
());
dataCell_2
.
setCellStyle
(
cellStyle_body
);
}
if
(
i
==(
size
-
1
)){
int
haveCell
=
(
i
+
1
)%
4
;
int
needCellCount
=
4
-(
i
+
1
)%
4
;
if
(
size
%
4
!=
0
&&
needCellCount
>
0
){
for
(
int
j
=
0
;
j
<
needCellCount
;
j
++){
XSSFCell
needCell
=
dataRow
.
createCell
(
1
+
haveCell
+
j
);
needCell
.
setCellValue
(
""
);
needCell
.
setCellStyle
(
cellStyle_body
);
}
}
}
}
}
for
(
int
i
=
0
;
i
<
sheetWitdh
.
length
;
i
++)
{
sheet
.
setColumnWidth
(
i
,
sheetWitdh
[
i
]);
}
return
workBook
;
}
/**
* 导出给球场的分组表
* @return
*/
@RequestMapping
(
value
=
"exportPlayersForCourses"
,
method
=
RequestMethod
.
GET
)
public
void
exportPlayersForCourses
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@ModelAttribute
(
"dto"
)
OrderPlayerQuery
form
,
ModelMap
model
)
{
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setContentType
(
"multipart/form-data"
);
List
<
OrderPlayerBean
>
beans
=
eventCustomerInfoService
.
findOrderPlayers
(
form
);
Map
<
String
,
List
<
OrderPlayerBean
>>
beansMap
=
new
LinkedHashMap
<
String
,
List
<
OrderPlayerBean
>>();
Date
playDate
=
null
;
//打球日期
String
productName
=
null
;
//产品名称
for
(
OrderPlayerBean
bean
:
beans
)
{
if
(
playDate
==
null
){
playDate
=
bean
.
getPlayDate
();
productName
=
bean
.
getProductName
();
}
String
dateStr
=
DateUtil
.
getDateStr
(
bean
.
getPlayDate
());
String
key
=
bean
.
getProductId
()
+
"-"
+
bean
.
getResourceId
()
+
"-"
+
bean
.
getGroupNum
()
+
"-"
+
dateStr
;
if
(
StringUtils
.
equals
(
"实时"
,
bean
.
getType
()))
{
key
=
bean
.
getProductId
()
+
"-"
+
bean
.
getResourceId
();
}
List
<
OrderPlayerBean
>
array
=
beansMap
.
get
(
key
);
if
(
array
==
null
)
{
array
=
new
ArrayList
<
OrderPlayerBean
>();
}
array
.
add
(
bean
);
beansMap
.
put
(
key
,
array
);
}
try
{
response
.
setHeader
(
"Content-Disposition"
,
"attachment;fileName="
+
java
.
net
.
URLEncoder
.
encode
(
DateUtil
.
getDateStrC
(
playDate
)+
productName
+
".xlsx"
,
"UTF-8"
));
buildExcelForCourses
(
beansMap
).
write
(
response
.
getOutputStream
());
}
catch
(
IOException
e
)
{
}
}
/**
* 获取表头的单元格样式
...
...
src/main/java/com/ctrip/fun/admin/service/basic/InvoiceRequestExcelImportService.java
View file @
d723a921
...
...
@@ -40,6 +40,9 @@ public class InvoiceRequestExcelImportService {
for
(
int
i
=
1
;
i
<
count
;
i
++){
rowIndex
=
i
;
Row
row
=
sheet
.
getRow
(
i
);
if
(
row
==
null
){
break
;
}
InvoiceRequestBean
bean
=
new
InvoiceRequestBean
();
bean
.
setId
(
Integer
.
valueOf
(
getCellValue
(
row
.
getCell
(
0
))));
...
...
@@ -54,6 +57,7 @@ public class InvoiceRequestExcelImportService {
}
return
beans
;
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
message
=
"Import failed, please check the data in "
+
rowIndex
+
" rows "
;
return
null
;
}
finally
{
...
...
src/main/webapp/WEB-INF/templates/golf/findOrderPlayers.ftl
View file @
d723a921
...
...
@@ -13,6 +13,17 @@ $(function(){
//导出之后修改回来
form.action = '/eventCustomerInfo/findOrderPlayers';
})
var $J_exportForCourse = $("#J_exportForCourse");
$J_exportForCourse.click(function(){
var form = $('.search-box')[0];
form.action = '/eventCustomerInfo/exportPlayersForCourses';
form.submit();
//导出之后修改回来
form.action = '/eventCustomerInfo/findOrderPlayers';
})
$("#J_reset").click(function(){
location.href='/eventCustomerInfo/findOrderPlayers';
})
...
...
@@ -36,6 +47,7 @@ $(function(){
<@com.textInput "dto.mobilePhone" "style=\"margin-left: 5px;\"" "手机号"/>
<@com.textInput "dto.playDate" "style=\"margin-left: 5px;\"" "打球日期"/>
<button id="J_submit" class="btn btn-primary">查询</button>
<input type="button" id="J_exportForCourse" class="btn btn-warning" value="球场分组导出">
<input type="button" id="J_export" class="btn btn-warning" value="导出">
<input type="button" id="J_reset" class="btn btn-danger" value="重置">
<br>
...
...
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