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
ab42eb86
Commit
ab42eb86
authored
Feb 28, 2018
by
xiandafu
Browse files
dict excel expor
parent
94110c19
Changes
8
Hide whitespace changes
Inline
Side-by-side
admin-console/src/main/java/com/ibeetl/admin/console/service/DictConsoleService.java
View file @
ab42eb86
package
com.ibeetl.admin.console.service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ibeetl.admin.console.dao.DictConsoleDao
;
import
com.ibeetl.admin.console.web.dto.UserExcelData
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.rbac.tree.OrgItem
;
import
com.ibeetl.admin.core.service.BaseService
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.util.enums.CoreDictType
;
/**
* CoreDict Service
...
...
@@ -36,4 +42,13 @@ public class DictConsoleService extends BaseService<CoreDict>{
throw
new
PlatformException
(
"批量删除CoreDict失败"
,
e
);
}
}
public
List
<
CoreDict
>
queryExcel
(
PageQuery
<
CoreUser
>
query
)
{
//同查询,不需要额外数据
PageQuery
ret
=
dictDao
.
queryByCondition
(
query
);
queryListAfter
(
ret
.
getList
());
return
ret
.
getList
();
}
}
\ No newline at end of file
admin-console/src/main/java/com/ibeetl/admin/console/web/DictConsoleController.java
View file @
ab42eb86
package
com.ibeetl.admin.console.web
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.jxls.common.Context
;
import
org.jxls.util.JxlsHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -17,10 +24,16 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
org.springframework.web.servlet.ModelAndView
;
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.UserQuery
;
import
com.ibeetl.admin.core.annotation.Function
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.file.FileItem
;
import
com.ibeetl.admin.core.file.FileService
;
import
com.ibeetl.admin.core.util.ConvertUtil
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.util.ValidateConfig
;
import
com.ibeetl.admin.core.web.JsonResult
;
...
...
@@ -35,7 +48,8 @@ public class DictConsoleController{
@Autowired
private
DictConsoleService
dictService
;
@Autowired
FileService
fileService
;
/* 页面 */
@GetMapping
(
MODEL
+
"/index.do"
)
...
...
@@ -115,5 +129,33 @@ public class DictConsoleController{
dictService
.
batchDelCoreDict
(
dels
);
return
new
JsonResult
().
success
();
}
@PostMapping
(
MODEL
+
"/excel/export.json"
)
@Function
(
"dict.export"
)
@ResponseBody
public
JsonResult
<
String
>
export
(
HttpServletResponse
response
,
UserQuery
condtion
)
{
String
excelTemplate
=
"excelTemplates/admin/dict/dict_collection_template.xls"
;
PageQuery
<
CoreUser
>
page
=
condtion
.
getPageQuery
();
//取出全部符合条件的
page
.
setPageSize
(
Integer
.
MAX_VALUE
);
page
.
setPageNumber
(
1
);
page
.
setTotalRow
(
Integer
.
MAX_VALUE
);
List
<
CoreDict
>
dicts
=
dictService
.
queryExcel
(
page
);
try
(
InputStream
is
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
excelTemplate
))
{
if
(
is
==
null
)
{
throw
new
PlatformException
(
"模板资源不存在:"
+
excelTemplate
);
}
FileItem
item
=
fileService
.
createFileTemp
(
"dict_collection.xls"
);
OutputStream
os
=
item
.
openOutpuStream
();
Context
context
=
new
Context
();
context
.
putVar
(
"dicts"
,
dicts
);
JxlsHelper
.
getInstance
().
processTemplate
(
is
,
os
,
context
);
//下载参考FileSystemContorller
return
JsonResult
.
success
(
item
.
getId
());
}
catch
(
IOException
e
)
{
throw
new
PlatformException
(
e
.
getMessage
());
}
}
}
admin-console/src/main/resources/excelTemplates/admin/dict/dict_collection_template.xls
0 → 100644
View file @
ab42eb86
File added
admin-console/src/main/resources/static/js/admin/dict/dictApi.js
View file @
ab42eb86
...
...
@@ -11,7 +11,13 @@ layui.define([], function(exports) {
Common
.
post
(
"
/admin/dict/delete.json
"
,{
"
ids
"
:
ids
},
function
(){
callback
();
})
}
},
exportExcel
:
function
(
form
,
callback
){
var
formPara
=
form
.
serializeJson
();
Common
.
post
(
"
/admin/dict/excel/export.json
"
,
formPara
,
function
(
fileId
)
{
callback
(
fileId
);
})
}
};
...
...
admin-console/src/main/resources/static/js/admin/dict/index.js
View file @
ab42eb86
...
...
@@ -3,115 +3,120 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
var
laydate
=
layui
.
laydate
;
var
table
=
layui
.
table
;
var
dictTable
=
null
;
var
view
=
{
init
:
function
(){
var
view
=
{
init
:
function
()
{
this
.
initTable
();
this
.
initSearchForm
();
this
.
initToolBar
();
window
.
dataReload
=
function
(){
Lib
.
doSearchForm
(
$
(
"
#searchForm
"
),
dictTable
)
window
.
dataReload
=
function
()
{
Lib
.
doSearchForm
(
$
(
"
#searchForm
"
),
dictTable
)
}
},
initTable
:
function
(){
initTable
:
function
()
{
dictTable
=
table
.
render
({
elem
:
'
#dictTable
'
,
height
:
Lib
.
getTableHeight
(
1
),
method
:
'
post
'
,
url
:
Common
.
CTX
+
'
/admin/dict/list.json
'
//数据接口
,
page
:
Lib
.
tablePage
//开启分页
,
limit
:
10
,
,
page
:
Lib
.
tablePage
//开启分页
,
limit
:
10
,
cols
:
[
[
//表头
{
type
:
'
checkbox
'
,
fixed
:
'
left
'
,
},
{
field
:
'
id
'
,
title
:
'
id
'
,
width
:
80
,
fixed
:
'
left
'
,
sort
:
true
},
{
type
:
'
checkbox
'
,
fixed
:
'
left
'
,
},
{
field
:
'
id
'
,
title
:
'
id
'
,
width
:
80
,
fixed
:
'
left
'
,
sort
:
true
},
{
field
:
'
value
'
,
title
:
'
字典值1
'
,
fixed
:
'
left
'
,
fixed
:
'
left
'
,
width
:
120
,
},
{
},
{
field
:
'
name
'
,
title
:
'
字典名称
'
,
width
:
180
,
},
{
},
{
field
:
'
type
'
,
title
:
'
字典类型
'
,
width
:
180
,
},
{
},
{
field
:
'
typeName
'
,
title
:
'
字典类型名称
'
,
width
:
180
,
},
{
},
{
field
:
'
sort
'
,
title
:
'
排序
'
,
width
:
60
,
},
{
},
{
field
:
'
parent
'
,
title
:
'
父字典
'
,
width
:
100
,
},
},
{
field
:
'
remark
'
,
title
:
'
备注
'
,
width
:
100
,
},
{
},
{
field
:
'
createTime
'
,
title
:
'
创建时间
'
,
width
:
100
,
}
}
]
]
});
},
initSearchForm
:
function
(){
Lib
.
initSearchForm
(
$
(
"
#searchForm
"
),
dictTable
,
form
);
initSearchForm
:
function
()
{
Lib
.
initSearchForm
(
$
(
"
#searchForm
"
),
dictTable
,
form
);
},
initToolBar
:
function
(){
initToolBar
:
function
()
{
toolbar
=
{
add
:
function
()
{
//获取选中数据
var
url
=
"
/admin/dict/add.do
"
;
Common
.
openDlg
(
url
,
"
字典数据管理>新增
"
);
},
edit
:
function
()
{
//获取选中数目
var
data
=
Common
.
getOneFromTable
(
table
,
"
dictTable
"
);
if
(
data
==
null
){
return
;
}
var
url
=
"
/admin/dict/edit.do?id=
"
+
data
.
id
;
Common
.
openDlg
(
url
,
"
字典数据管理>
"
+
data
.
value
+
"
>编辑
"
);
},
del
:
function
()
{
layui
.
use
([
'
del
'
],
function
(){
var
delView
=
layui
.
del
delView
.
delBatch
();
});
add
:
function
()
{
//获取选中数据
var
url
=
"
/admin/dict/add.do
"
;
Common
.
openDlg
(
url
,
"
字典数据管理>新增
"
);
},
edit
:
function
()
{
//获取选中数目
var
data
=
Common
.
getOneFromTable
(
table
,
"
dictTable
"
);
if
(
data
==
null
)
{
return
;
}
};
var
url
=
"
/admin/dict/edit.do?id=
"
+
data
.
id
;
Common
.
openDlg
(
url
,
"
字典数据管理>
"
+
data
.
value
+
"
>编辑
"
);
},
del
:
function
()
{
layui
.
use
([
'
del
'
],
function
()
{
var
delView
=
layui
.
del
delView
.
delBatch
();
});
},
exportExcel
:
function
()
{
layui
.
use
([
'
dictApi
'
],
function
()
{
var
dictApi
=
layui
.
dictApi
Common
.
openConfirm
(
"
确认要导出这些字典数据?
"
,
function
()
{
dictApi
.
exportExcel
(
$
(
"
#searchForm
"
),
function
(
fileId
)
{
Lib
.
download
(
fileId
);
})
})
});
}
};
$
(
'
.ext-toolbar
'
).
on
(
'
click
'
,
function
()
{
var
type
=
$
(
this
).
data
(
'
type
'
);
toolbar
[
type
]
?
toolbar
[
type
].
call
(
this
)
:
''
;
...
...
@@ -119,6 +124,6 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
}
}
exports
(
'
index
'
,
view
);
exports
(
'
index
'
,
view
);
});
\ No newline at end of file
admin-console/src/main/resources/templates/admin/dict/index.html
View file @
ab42eb86
...
...
@@ -6,6 +6,8 @@
<layui:accessButton
function=
"dict.add"
action=
"add"
>
增加
</layui:accessButton>
<layui:accessButton
function=
"dict.edit"
action=
"edit"
>
编辑
</layui:accessButton>
<layui:accessButton
function=
"dict.del"
action=
"del"
>
删除
</layui:accessButton>
<layui:accessButton
function=
"dict.exportExcel"
action=
"exportExcel"
>
导出
</layui:accessButton>
<layui:accessButton
function=
"dict.importExcel"
action=
"importExcel"
>
导入
</layui:accessButton>
</div>
<table
id=
"dictTable"
lay-filter=
"dictTable"
></table>
...
...
admin-core/src/main/java/com/ibeetl/admin/core/annotation/Function.java
View file @
ab42eb86
...
...
@@ -18,4 +18,5 @@ import java.lang.annotation.RetentionPolicy;
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
Function
{
public
String
value
();
public
String
name
()
default
""
;
}
admin-core/src/main/java/com/ibeetl/admin/core/conf/RbacAnnotationConfig.java
View file @
ab42eb86
...
...
@@ -3,6 +3,7 @@ package com.ibeetl.admin.core.conf;
import
java.lang.reflect.Method
;
import
java.util.Date
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.aspectj.lang.ProceedingJoinPoint
;
...
...
@@ -63,20 +64,20 @@ public class RbacAnnotationConfig {
if
(
function
!=
null
)
{
MethodSignature
ms
=
(
MethodSignature
)
pjp
.
getSignature
();
m
=
ms
.
getMethod
();
createAudit
(
funCode
,
user
,
true
,
""
,
m
);
createAudit
(
funCode
,
function
.
name
(),
user
,
true
,
""
,
m
);
}
return
o
;
}
catch
(
Throwable
e
)
{
if
(
function
!=
null
)
{
createAudit
(
funCode
,
user
,
false
,
e
.
getMessage
(),
m
);
createAudit
(
funCode
,
function
.
name
(),
user
,
false
,
e
.
getMessage
(),
m
);
}
throw
e
;
}
}
private
void
createAudit
(
String
functionCode
,
CoreUser
user
,
boolean
success
,
String
msg
,
Method
m
)
{
private
void
createAudit
(
String
functionCode
,
String
functionName
,
CoreUser
user
,
boolean
success
,
String
msg
,
Method
m
)
{
boolean
enable
=
env
.
getProperty
(
"audit.enable"
,
Boolean
.
class
,
false
);
if
(!
enable
)
{
return
;
...
...
@@ -86,15 +87,16 @@ public class RbacAnnotationConfig {
}
CoreAudit
audit
=
new
CoreAudit
();
String
functionName
=
null
;
CoreFunction
fun
=
this
.
platformService
.
getFunction
(
functionCode
);
if
(
String
Utils
.
isEmpty
(
functionName
))
{
CoreFunction
fun
=
this
.
platformService
.
getFunction
(
functionCode
);
if
(
fun
==
null
)
{
// 没有在数据库定义,但写在代码里了
log
.
warn
(
functionCode
+
" 未在数据库里定义"
);
functionName
=
"未定义"
;
}
else
{
functionName
=
fun
.
getName
();
if
(
fun
==
null
)
{
// 没有在数据库定义,但写在代码里了
log
.
warn
(
functionCode
+
" 未在数据库里定义"
);
functionName
=
"未定义"
;
}
else
{
functionName
=
fun
.
getName
();
}
}
audit
.
setCreateTime
(
new
Date
());
audit
.
setFunctionCode
(
functionCode
);
...
...
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