Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
open-platform-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8fa33065
authored
Jan 05, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]设备导入
1 parent
62c79624
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
src/main/java/com/glsx/controller/DeviceMgrController.java
src/main/java/com/glsx/controller/DeviceMgrController.java
View file @
8fa3306
package
com
.
glsx
.
controller
;
import
java.io.InputStream
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
cn.com.glsx.openplatform.service.DeviceMgrService
;
import
cn.com.glsx.openplatform.vo.DeviceImportVo
;
import
cn.com.glsx.openplatform.vo.DeviceVo
;
import
cn.com.glsx.openplatform.vo.R
;
import
cn.hutool.db.Page
;
import
com.glsx.poi.util.ExcelUtil
;
import
org.apache.poi.poifs.filesystem.OfficeXmlFileException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -14,6 +20,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
//@Api
@RestController
...
...
@@ -43,4 +53,56 @@ public class DeviceMgrController {
hashMap
.
put
(
"deviceTypeList"
,
deviceTypeList
);
return
R
.
ok
().
data
(
hashMap
);
}
/**
* 导入设备
*
* @param httpRequest
* @return
*/
@RequestMapping
(
value
=
"/importDeviceList"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
R
importDeviceList
(
HttpServletRequest
httpRequest
){
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
try
{
//加载导入的文件
InputStream
input
=
unloadFile
(
httpRequest
,
"file"
);
//加载导入数据
ExcelUtil
<
DeviceImportVo
>
excelUtil
=
new
ExcelUtil
<
DeviceImportVo
>(
DeviceImportVo
.
class
);
Collection
<
DeviceImportVo
>
list
=
excelUtil
.
importExcel
(
input
);
Map
<
String
,
Object
>
desimap
=
deviceMgrService
.
importDevice
(
list
);
int
successCount
=
desimap
.
get
(
"successCount"
)
==
null
?
0
:
Integer
.
parseInt
(
desimap
.
get
(
"successCount"
)
+
""
);
map
.
put
(
"successCount"
,
successCount
);
map
.
put
(
"errorCount"
,
list
.
size
()
-
successCount
);
map
.
put
(
"errorMessage"
,
desimap
.
get
(
"errorMessage"
));
}
catch
(
OfficeXmlFileException
e
)
{
map
.
put
(
"successCount"
,
0
);
map
.
put
(
"errorCount"
,
0
);
map
.
put
(
"errorMessage"
,
"上传文件出错,无法解析参数,请检查文件是否有误"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
map
.
put
(
"successCount"
,
0
);
map
.
put
(
"errorCount"
,
0
);
map
.
put
(
"errorMessage"
,
"系统异常,请联系管理员处理"
);
}
return
R
.
ok
().
data
(
map
);
}
/**
* 导入文件
*
* @param request
* @return
* @throws Exception
*/
public
InputStream
unloadFile
(
HttpServletRequest
request
,
String
fileName
)
throws
Exception
{
//加载导入文件
MultipartHttpServletRequest
mulRequest
=
(
MultipartHttpServletRequest
)
request
;
MultipartFile
file
=
mulRequest
.
getFile
(
fileName
);
String
filename
=
file
.
getOriginalFilename
();
if
(
filename
==
null
||
""
.
equals
(
filename
))
{
return
null
;
}
return
file
.
getInputStream
();
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment