Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
Y
YX_IDENT_beijing_auxiliary_YD
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
zhangyusheng
YX_IDENT_beijing_auxiliary_YD
Commits
f089ede8
Commit
f089ede8
authored
Jan 07, 2021
by
liuxinben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
批量导入取消邮寄的信息
parent
b63037ef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
7 deletions
+143
-7
PersonPostApi.java
src/main/java/com/yxproject/start/api/PersonPostApi.java
+72
-1
ExportExcel.java
src/main/java/com/yxproject/start/utils/ExportExcel.java
+71
-6
No files found.
src/main/java/com/yxproject/start/api/PersonPostApi.java
View file @
f089ede8
...
...
@@ -3,6 +3,7 @@ package com.yxproject.start.api;
import
com.yxproject.start.dto.ReadCardDto
;
import
com.yxproject.start.entity.PersonPostEntity
;
import
com.yxproject.start.service.PersonPostService
;
import
com.yxproject.start.utils.ExportExcel
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.apache.log4j.Logger
;
...
...
@@ -10,15 +11,22 @@ import org.apache.log4j.MDC;
import
org.apache.poi.hssf.usermodel.*
;
import
org.apache.poi.ss.usermodel.CellType
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory
;
import
org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.multipart.commons.CommonsMultipartResolver
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.transaction.Transactional
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
...
...
@@ -90,13 +98,76 @@ public class PersonPostApi {
String
name
=
noteMap
.
get
(
"name"
).
toString
();
personPostService
.
cancelPostByAcceptNo
(
uploadNo
,
note
,
name
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"备注信息:"
+
jsonArray
);
logger
.
error
(
"Exception 更改备注信息异常"
,
e
);
return
false
;
}
return
true
;
}
/**
* 导入证件追踪查询
*
* @return
*/
@RequestMapping
(
"uploadCancelPost"
)
@Transactional
public
boolean
uploadCancelPost
(
HttpServletRequest
requ
)
{
String
remoteAddr
=
requ
.
getRemoteAddr
();
MDC
.
put
(
"ip"
,
remoteAddr
);
String
filename
=
""
;
String
name
=
requ
.
getParameter
(
"name"
);
DiskFileItemFactory
factory
=
new
DiskFileItemFactory
();
// 设置缓冲区的大小为100KB,如果不指定,那么缓冲区的大小默认是10KB
factory
.
setSizeThreshold
(
1024
*
100
);
ServletFileUpload
upload
=
new
ServletFileUpload
(
factory
);
upload
.
setHeaderEncoding
(
"UTF-8"
);
// 设置上传单个文件的大小的最大值,目前是设置为1024*1024*10字节,也就是10MB
upload
.
setFileSizeMax
(
1024
*
1024
*
10
);
// 设置上传文件总量的最大值,最大值=同时上传的多个文件的大小的最大值的和,目前设置为4000MB
upload
.
setSizeMax
(
1024
*
1024
*
4000
);
// 将普通属性存入map中,之后调用
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
//将当前上下文初始化给 CommonsMutipartResolver (多部分解析器)
CommonsMultipartResolver
multipartResolver
=
new
CommonsMultipartResolver
(
requ
.
getServletContext
());
// 判断是否是多数据段提交格式
if
(
multipartResolver
.
isMultipart
(
requ
))
{
MultipartHttpServletRequest
multiRequest
=
(
MultipartHttpServletRequest
)
requ
;
Iterator
<
String
>
iter
=
multiRequest
.
getFileNames
();
while
(
iter
.
hasNext
())
{
List
<
MultipartFile
>
fileRows
=
multiRequest
.
getFiles
(
iter
.
next
().
toString
());
for
(
MultipartFile
item
:
fileRows
)
{
// 如果fileitem中封装的是普通输入项的数据
// 如果fileitem中封装的是上传文件
// 得到上传的文件名称
filename
=
item
.
getOriginalFilename
();
File
file
=
null
;
try
{
file
=
File
.
createTempFile
(
"prefix"
,
"_"
+
item
.
getOriginalFilename
());
item
.
transferTo
(
file
);
list
=
ExportExcel
.
rearXlsAndXlsx
(
file
,
filename
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Map
<
String
,
Object
>
noteMap
=
list
.
get
(
i
);
String
uploadNo
=
noteMap
.
get
(
"身份证受理号"
).
toString
();
String
note
=
noteMap
.
get
(
"审核错误类型"
).
toString
();
personPostService
.
cancelPostByAcceptNo
(
uploadNo
,
note
,
name
);
}
return
true
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
}
}
return
false
;
}
/**
* 按条件查询个人邮寄信息
*
...
...
src/main/java/com/yxproject/start/utils/ExportExcel.java
View file @
f089ede8
package
com
.
yxproject
.
start
.
utils
;
import
org.apache.poi.hssf.usermodel.*
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.springframework.util.ObjectUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.*
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
static
com
.
yxproject
.
start
.
utils
.
YXStringUtils
.
getCurrentDate2String
;
...
...
@@ -379,4 +377,71 @@ public class ExportExcel {
}
/**
* 解析excel
* @param file
* @return
*/
public
static
List
<
Map
<
String
,
Object
>>
rearXlsAndXlsx
(
File
file
,
String
filePath
){
Workbook
wb
=
readExcel
(
file
,
filePath
);
List
<
Map
<
String
,
Object
>>
outerList
=
new
ArrayList
<>();
if
(
wb
!=
null
)
{
int
sheetSize
=
wb
.
getNumberOfSheets
();
for
(
int
index
=
0
;
index
<
sheetSize
;
index
++)
{
// 每个页签创建一个Sheet对象
Sheet
sheet
=
wb
.
getSheetAt
(
index
);
int
rowNum
=
sheet
.
getLastRowNum
();
int
headerNum
=
sheet
.
getRow
(
2
).
getLastCellNum
();
String
[]
s
=
new
String
[
headerNum
];
for
(
int
o
=
0
;
o
<
headerNum
;
o
++){
Cell
headerCell
=
sheet
.
getRow
(
0
).
getCell
(
o
);
headerCell
.
setCellType
(
CellType
.
STRING
);
s
[
o
]
=
headerCell
.
getStringCellValue
();
}
// sheet.getRows()返回该页的总行数
for
(
int
nowRowNum
=
3
;
nowRowNum
<
rowNum
-
2
;
nowRowNum
++)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Row
row
=
sheet
.
getRow
(
nowRowNum
);
// sheet.getColumns()返回该页的总列数
int
columnNum
=
row
.
getLastCellNum
();
for
(
int
nowColumnNum
=
0
;
nowColumnNum
<
columnNum
;
nowColumnNum
++)
{
Cell
columnCell
=
sheet
.
getRow
(
nowRowNum
).
getCell
(
nowColumnNum
);
columnCell
.
setCellType
(
CellType
.
STRING
);
String
cellinfo
=
columnCell
.
getStringCellValue
();
if
(
cellinfo
.
isEmpty
()
||
cellinfo
.
equals
(
""
)){
continue
;
}
else
{
map
.
put
(
s
[
nowColumnNum
],
cellinfo
);
}
}
if
(!
ObjectUtils
.
isEmpty
(
map
)){
outerList
.
add
(
map
);
}
}
}
}
return
outerList
;
}
private
static
Workbook
readExcel
(
File
file
,
String
filePath
){
if
(
filePath
==
null
){
return
null
;
}
String
extString
=
filePath
.
substring
(
filePath
.
lastIndexOf
(
"."
));
try
{
@SuppressWarnings
(
"resource"
)
InputStream
is
=
new
FileInputStream
(
file
);
if
(
".xls"
.
equals
(
extString
)){
return
new
HSSFWorkbook
(
is
);
}
else
if
(
".xlsx"
.
equals
(
extString
)){
throw
new
FileNotFoundException
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
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