Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Springboot Plus
Commits
cc0c6fb8
Commit
cc0c6fb8
authored
Mar 01, 2018
by
李家智
Browse files
excel import
parent
3cc878b4
Changes
11
Hide whitespace changes
Inline
Side-by-side
admin-console/src/main/java/com/ibeetl/admin/console/web/DictConsoleController.java
View file @
cc0c6fb8
...
@@ -3,28 +3,33 @@ package com.ibeetl.admin.console.web;
...
@@ -3,28 +3,33 @@ package com.ibeetl.admin.console.web;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.util.Array
s
;
import
java.util.Array
List
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.jxls.common.Context
;
import
org.jxls.common.Context
;
import
org.jxls.reader.ReaderBuilder
;
import
org.jxls.reader.XLSReadStatus
;
import
org.jxls.reader.XLSReader
;
import
org.jxls.util.JxlsHelper
;
import
org.jxls.util.JxlsHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.ModelAndView
;
import
com.ibeetl.admin.console.service.DictConsoleService
;
import
com.ibeetl.admin.console.service.DictConsoleService
;
import
com.ibeetl.admin.console.web.dto.UserExcelData
;
import
com.ibeetl.admin.console.web.query.CoreDictQuery
;
import
com.ibeetl.admin.console.web.query.CoreDictQuery
;
import
com.ibeetl.admin.console.web.query.UserQuery
;
import
com.ibeetl.admin.console.web.query.UserQuery
;
import
com.ibeetl.admin.core.annotation.Function
;
import
com.ibeetl.admin.core.annotation.Function
;
...
@@ -157,5 +162,27 @@ public class DictConsoleController{
...
@@ -157,5 +162,27 @@ public class DictConsoleController{
}
}
}
}
@PostMapping
(
MODEL
+
"/excel/import.do"
)
@Function
(
"dict.import"
)
@ResponseBody
public
JsonResult
importExcel
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
Exception
{
if
(
file
.
isEmpty
())
{
return
JsonResult
.
fail
();
}
String
fileName
=
file
.
getOriginalFilename
();
InputStream
ins
=
file
.
getInputStream
();
InputStream
inputXML
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
"excelTemplates/admin/dict/dict_mapping.xml"
);
XLSReader
mainReader
=
ReaderBuilder
.
buildFromXML
(
inputXML
);
InputStream
inputXLS
=
ins
;
List
<
CoreDict
>
dict
=
new
ArrayList
<
CoreDict
>();
Map
beans
=
new
HashMap
();
beans
.
put
(
"list"
,
dict
);
XLSReadStatus
readStatus
=
mainReader
.
read
(
inputXLS
,
beans
);
return
JsonResult
.
success
();
}
}
}
admin-console/src/main/java/com/ibeetl/admin/console/web/UserConsoleController.java
View file @
cc0c6fb8
...
@@ -308,5 +308,7 @@ public class UserConsoleController {
...
@@ -308,5 +308,7 @@ public class UserConsoleController {
}
}
admin-console/src/main/resources/excelTemplates/admin/dict/dict_mapping.xml
0 → 100644
View file @
cc0c6fb8
<?xml version="1.0" encoding="utf-8"?>
<workbook>
<worksheet
name=
"Sheet1"
>
<section
startRow=
"0"
endRow=
"0"
>
</section>
<loop
startRow=
"1"
endRow=
"1"
items=
"list"
var=
"dict"
varType=
"com.ibeetl.admin.entity.CoreDict"
>
<section
startRow=
"3"
endRow=
"3"
>
<mapping
row=
"3"
col=
"0"
></mapping>
<mapping
row=
"1"
col=
"1"
>
dict.name
</mapping>
<mapping
row=
"1"
col=
"2"
>
dict.value
</mapping>
</section>
<loopbreakcondition>
<rowcheck
offset=
"0"
>
<cellcheck
offset=
"0"
></cellcheck>
</rowcheck>
</loopbreakcondition>
</loop>
</worksheet>
</workbook>
\ No newline at end of file
admin-console/src/main/resources/excelTemplates/admin/dict/dict_upload_template.xls
0 → 100644
View file @
cc0c6fb8
File added
admin-console/src/main/resources/static/js/admin/dict/index.js
View file @
cc0c6fb8
...
@@ -114,6 +114,15 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
...
@@ -114,6 +114,15 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
})
})
});
});
},
importExcel
:
function
(){
//上传路径
var
uploadUrl
=
Common
.
ctxPath
+
"
/admin/dict/excel/import.do
"
;
//模板
var
templatePath
=
"
/admin/dict/dict_upload_template.xls
"
;
//公共的简单上传文件处理
var
url
=
"
/core/file/simpleUpload.do?uploadUrl=
"
+
uploadUrl
+
"
&templatePath=
"
+
templatePath
;
Common
.
openDlg
(
url
,
"
字典数据管理>上传
"
);
}
}
};
};
...
...
admin-core/src/main/java/com/ibeetl/admin/core/file/LocaFileService.java
View file @
cc0c6fb8
...
@@ -63,6 +63,8 @@ public class LocaFileService implements FileService {
...
@@ -63,6 +63,8 @@ public class LocaFileService implements FileService {
}
}
}
}
private
String
suffixTemp
()
{
private
String
suffixTemp
()
{
// TODO,改成唯一算法
// TODO,改成唯一算法
...
...
admin-core/src/main/java/com/ibeetl/admin/core/util/FileUtil.java
0 → 100644
View file @
cc0c6fb8
package
com.ibeetl.admin.core.util
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
public
class
FileUtil
{
public
static
void
copy
(
InputStream
input
,
OutputStream
os
)
{
try
{
byte
[]
buf
=
new
byte
[
1024
];
int
bytesRead
;
while
((
bytesRead
=
input
.
read
(
buf
))
>
0
)
{
os
.
write
(
buf
,
0
,
bytesRead
);
}
}
catch
(
Exception
ex
)
{
throw
new
PlatformException
(
"文件复制出错"
+
ex
);
}
finally
{
try
{
input
.
close
();
os
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
}
admin-core/src/main/java/com/ibeetl/admin/core/web/FileSystemContorller.java
View file @
cc0c6fb8
package
com.ibeetl.admin.core.web
;
package
com.ibeetl.admin.core.web
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -8,11 +10,14 @@ import org.apache.commons.logging.Log;
...
@@ -8,11 +10,14 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.ModelAndView
;
import
com.ibeetl.admin.core.file.FileItem
;
import
com.ibeetl.admin.core.file.FileItem
;
import
com.ibeetl.admin.core.file.FileService
;
import
com.ibeetl.admin.core.file.FileService
;
import
com.ibeetl.admin.core.util.FileUtil
;
import
com.ibeetl.admin.core.util.PlatformException
;
@Controller
@Controller
public
class
FileSystemContorller
{
public
class
FileSystemContorller
{
...
@@ -28,4 +33,29 @@ public class FileSystemContorller {
...
@@ -28,4 +33,29 @@ public class FileSystemContorller {
fileService
.
copyTemp
(
id
,
response
.
getOutputStream
());
fileService
.
copyTemp
(
id
,
response
.
getOutputStream
());
return
null
;
return
null
;
}
}
@GetMapping
(
MODEL
+
"/downloadTemplate.do"
)
public
ModelAndView
dowloadTemplate
(
HttpServletResponse
response
,
String
path
)
throws
IOException
{
response
.
setContentType
(
"text/html; charset = UTF-8"
);
int
start1
=
path
.
lastIndexOf
(
"\\"
);
int
start2
=
path
.
lastIndexOf
(
"/"
);
if
(
start2
>
start1
)
{
start1
=
start2
;
}
String
file
=
path
.
substring
(
start1
+
1
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
file
);
InputStream
input
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
"excelTemplates/"
+
path
);
FileUtil
.
copy
(
input
,
response
.
getOutputStream
());
return
null
;
}
@GetMapping
(
MODEL
+
"/simpleUpload.do"
)
public
ModelAndView
simpleUploadPage
(
String
uploadUrl
,
String
templatePath
,
String
fileType
)
throws
IOException
{
ModelAndView
view
=
new
ModelAndView
(
"/common/simpleUpload.html"
);
view
.
addObject
(
"uploadUrl"
,
uploadUrl
);
view
.
addObject
(
"templatePath"
,
templatePath
);
view
.
addObject
(
"fileType"
,
fileType
);
return
view
;
}
}
}
admin-core/src/main/resources/static/js/common.js
View file @
cc0c6fb8
...
@@ -76,13 +76,18 @@ var Common = {
...
@@ -76,13 +76,18 @@ var Common = {
});
});
layer
.
full
(
index
);
layer
.
full
(
index
);
},
},
openConfirm
:
function
(
content
,
callback
){
openConfirm
:
function
(
content
,
callback
,
callBackNo
){
var
index
=
layer
.
confirm
(
content
,
{
var
index
=
layer
.
confirm
(
content
,
{
btn
:
[
'
确认
'
,
'
取消
'
]
//按钮
btn
:
[
'
确认
'
,
'
取消
'
]
//按钮
},
function
(){
},
function
(){
callback
();
if
(
callback
!=
null
){
callback
();
}
layer
.
close
(
index
);
layer
.
close
(
index
);
},
function
(){
},
function
(){
if
(
callBackNo
!=
null
){
callBackNo
()
}
layer
.
close
(
index
);
layer
.
close
(
index
);
});
});
...
...
admin-core/src/main/resources/templates/common/layout.html
View file @
cc0c6fb8
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
function
(
e
)
{
function
(
e
)
{
if
(
e
.
which
===
27
)
{
if
(
e
.
which
===
27
)
{
Common
.
openConfirm
(
"
是否放弃治疗回到主页?
"
,
function
(){
Common
.
openConfirm
(
"
是否放弃治疗回到主页?
"
,
function
(){
layer
.
closeAll
();
layer
.
closeAll
();
})
})
}
}
...
...
admin-core/src/main/resources/templates/common/simpleUpload.html
0 → 100644
View file @
cc0c6fb8
<!--# layout("/common/layout.html",{"jsBase":"/js/"}){ -->
<!--# if(isNotEmpty(templatePath)){ -->
<blockquote
class=
"layui-elem-quote"
>
<u><a
href=
"${ctxPath}/core/file/downloadTemplate.do?path=${templatePath}"
>
点击下载模板
</a></u>
</blockquote>
<!--#} -->
<form
class=
"layui-form layui-form-pane"
id=
"updateForm"
>
<fieldset
class=
"layui-elem-field layui-field-title"
style=
"margin-top: 30px;"
>
<legend>
拖拽上传
</legend>
</fieldset>
<div
class=
"layui-upload-drag"
id=
"test10"
>
<i
class=
"layui-icon"
>
</i>
<p>
点击上传,或将文件拖拽到此处
</p>
</div>
</form>
<!--#} -->
<script>
layui
.
use
(
'
upload
'
,
function
(){
var
upload
=
layui
.
upload
;
upload
.
render
({
elem
:
'
#test10
'
,
accept
:
'
${fileType!"file"}
'
//默认所有文件都允许
,
url
:
'
${uploadUrl}
'
,
done
:
function
(
res
){
if
(
res
.
code
==
0
){
Common
.
openConfirm
(
"
上传成功,是否继续上传?
"
,
null
,
function
(){
var
index
=
parent
.
layer
.
getFrameIndex
(
window
.
name
);
//先得到当前iframe层的索引
parent
.
layer
.
close
(
index
);
//再执行关闭
})
}
}
,
error
:
function
(){
Common
.
error
(
"
系统错误,无法访问服务器
"
)
}
});
});
</script>
Write
Preview
Supports
Markdown
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