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
fea41b40
"eladmin-common/src/vscode:/vscode.git/clone" did not exist on "7bb4ade348b1fdc96de00ebf4a43b0108b506013"
Commit
fea41b40
authored
Feb 27, 2018
by
李家智
Browse files
export excel by jxsl
parent
7a72fead
Changes
15
Hide whitespace changes
Inline
Side-by-side
admin-console/pom.xml
View file @
fea41b40
...
...
@@ -12,7 +12,16 @@
</parent>
<dependencies>
<dependency>
<groupId>
org.jxls
</groupId>
<artifactId>
jxls
</artifactId>
<version>
2.4.3
</version>
</dependency>
<dependency>
<groupId>
org.jxls
</groupId>
<artifactId>
jxls-poi
</artifactId>
<version>
1.0.14
</version>
</dependency>
<dependency>
<groupId>
com.ibeetl
</groupId>
<artifactId>
admin-core
</artifactId>
...
...
admin-console/src/main/java/com/ibeetl/admin/console/service/UserConsoleService.java
View file @
fea41b40
package
com.ibeetl.admin.console.service
;
import
java.util.ArrayList
;
import
java.util.Date
;
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
;
...
...
@@ -11,11 +13,16 @@ import org.springframework.transaction.annotation.Transactional;
import
com.ibeetl.admin.console.dao.UserConsoleDao
;
import
com.ibeetl.admin.console.exception.DeletedException
;
import
com.ibeetl.admin.console.exception.NoResourceException
;
import
com.ibeetl.admin.console.web.dto.UserExcelData
;
import
com.ibeetl.admin.console.web.query.UserRoleQuery
;
import
com.ibeetl.admin.core.conf.PasswordConfig.PasswordEncryptService
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.entity.CoreUserRole
;
import
com.ibeetl.admin.core.rbac.tree.OrgItem
;
import
com.ibeetl.admin.core.service.BaseService
;
import
com.ibeetl.admin.core.service.CoreDictService
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.util.enums.DelFlagEnum
;
import
com.ibeetl.admin.core.util.enums.GeneralStateEnum
;
...
...
@@ -26,10 +33,15 @@ public class UserConsoleService extends BaseService<CoreUser> {
@Autowired
UserConsoleDao
userDao
;
@Autowired
PasswordEncryptService
passwordEncryptService
;
@Autowired
CoreDictService
dictService
;
@Autowired
CorePlatformService
platformService
;
/**
* 根据条件查询
*
...
...
@@ -53,11 +65,11 @@ public class UserConsoleService extends BaseService<CoreUser> {
throw
new
PlatformException
(
"保存用户信息失败,用户已经存在"
);
}
user
.
setCreateTime
(
new
Date
());
user
.
setState
(
GeneralStateEnum
.
ENABLE
.
getValue
());
user
.
setState
(
GeneralStateEnum
.
ENABLE
.
getValue
());
user
.
setPassword
(
passwordEncryptService
.
password
(
user
.
getPassword
()));
user
.
setDelFlag
(
DelFlagEnum
.
NORMAL
.
getValue
());
userDao
.
insert
(
user
,
true
);
userDao
.
insert
(
user
,
true
);
}
/**
...
...
@@ -90,7 +102,7 @@ public class UserConsoleService extends BaseService<CoreUser> {
if
(
user
==
null
)
{
throw
new
NoResourceException
(
"用户不存在!"
);
}
if
(
user
.
getDelFlag
()==
DelFlagEnum
.
DELETED
.
getValue
())
{
if
(
user
.
getDelFlag
()
==
DelFlagEnum
.
DELETED
.
getValue
())
{
throw
new
DeletedException
(
"用户已被删除!"
);
}
user
=
new
CoreUser
();
...
...
@@ -138,27 +150,54 @@ public class UserConsoleService extends BaseService<CoreUser> {
user
.
setUpdateTime
(
new
Date
());
return
userDao
.
updateTemplateById
(
user
);
}
public
List
<
CoreUserRole
>
getUserRoles
(
UserRoleQuery
roleQuery
)
{
return
userDao
.
queryUserRole
(
roleQuery
.
getUserId
(),
roleQuery
.
getOrgId
(),
roleQuery
.
getRoleId
());
}
public
void
deleteUserRoles
(
List
<
Long
>
ids
)
{
// 考虑到这个操作较少使用,就不做批处理优化了
for
(
Long
id
:
ids
)
{
sqlManager
.
deleteById
(
CoreUserRole
.
class
,
id
);
}
}
public
void
saveUserRole
(
CoreUserRole
userRole
)
{
long
queryCount
=
sqlManager
.
templateCount
(
userRole
);
if
(
queryCount
>
0
)
{
throw
new
PlatformException
(
"已存在用户角色关系"
);
}
sqlManager
.
insert
(
userRole
);
}
public
List
<
CoreUserRole
>
getUserRoles
(
UserRoleQuery
roleQuery
)
{
return
userDao
.
queryUserRole
(
roleQuery
.
getUserId
(),
roleQuery
.
getOrgId
(),
roleQuery
.
getRoleId
());
}
public
void
deleteUserRoles
(
List
<
Long
>
ids
)
{
//考虑到这个操作较少使用,就不做批处理优化了
for
(
Long
id
:
ids
)
{
sqlManager
.
deleteById
(
CoreUserRole
.
class
,
id
);
}
}
public
void
saveUserRole
(
CoreUserRole
userRole
)
{
long
queryCount
=
sqlManager
.
templateCount
(
userRole
);
if
(
queryCount
>
0
)
{
throw
new
PlatformException
(
"已存在用户角色关系"
);
}
sqlManager
.
insert
(
userRole
);
}
public
List
<
UserExcelData
>
queryExcel
(
PageQuery
<
CoreUser
>
query
)
{
PageQuery
<
CoreUser
>
ret
=
userDao
.
queryByCondtion
(
query
);
List
<
CoreUser
>
list
=
ret
.
getList
();
OrgItem
orgRoot
=
platformService
.
buildOrg
();
List
<
UserExcelData
>
items
=
new
ArrayList
<>();
for
(
CoreUser
user:
list
)
{
UserExcelData
userItem
=
new
UserExcelData
();
userItem
.
setCode
(
user
.
getCode
());
userItem
.
setId
(
user
.
getId
());
userItem
.
setName
(
user
.
getName
());
CoreDict
dict
=
dictService
.
findCoreDict
(
user
.
getState
());
userItem
.
setStateText
(
dict
.
getName
());
if
(
StringUtils
.
isNotEmpty
(
user
.
getJobType1
())){
dict
=
dictService
.
findCoreDict
(
user
.
getJobType1
());
userItem
.
setJobType1Text
(
dict
.
getName
());
}
String
orgName
=
orgRoot
.
findChild
(
user
.
getOrgId
()).
getName
();
userItem
.
setOrgText
(
orgName
);
items
.
add
(
userItem
);
}
return
items
;
}
}
admin-console/src/main/java/com/ibeetl/admin/console/web/UserConsoleController.java
View file @
fea41b40
package
com.ibeetl.admin.console.web
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletResponse
;
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
;
...
...
@@ -18,16 +26,19 @@ import org.springframework.web.servlet.ModelAndView;
import
com.ibeetl.admin.console.service.OrgConsoleService
;
import
com.ibeetl.admin.console.service.RoleConsoleService
;
import
com.ibeetl.admin.console.service.UserConsoleService
;
import
com.ibeetl.admin.console.web.dto.UserExcelData
;
import
com.ibeetl.admin.console.web.query.UserQuery
;
import
com.ibeetl.admin.console.web.query.UserRoleQuery
;
import
com.ibeetl.admin.core.annotation.Function
;
import
com.ibeetl.admin.core.annotation.Query
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.entity.CoreUserRole
;
import
com.ibeetl.admin.core.file.FileItem
;
import
com.ibeetl.admin.core.file.FileService
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.util.AnnotationUtil
;
import
com.ibeetl.admin.core.util.ConvertUtil
;
import
com.ibeetl.admin.core.util.
DictUtil
;
import
com.ibeetl.admin.core.util.
PlatformException
;
import
com.ibeetl.admin.core.util.ValidateConfig
;
import
com.ibeetl.admin.core.util.enums.GeneralStateEnum
;
import
com.ibeetl.admin.core.web.JsonResult
;
...
...
@@ -53,7 +64,9 @@ public class UserConsoleController {
@Autowired
OrgConsoleService
orgConsoleService
;
@Autowired
DictUtil
dictUtil
;
FileService
fileService
;
/* 页面 */
...
...
@@ -263,5 +276,35 @@ public class UserConsoleController {
this
.
platformService
.
clearFunctionCache
();
return
JsonResult
.
success
();
}
@GetMapping
(
MODEL
+
"/excel/export.json"
)
@Function
(
"user.export"
)
public
JsonResult
export
(
HttpServletResponse
response
,
UserQuery
condtion
)
{
String
excelTemplate
=
"excelTemplates/admin/user/user_collection_template.xls"
;
PageQuery
<
CoreUser
>
page
=
condtion
.
getPageQuery
();
//取出全部符合条件的
page
.
setPageSize
(
Integer
.
MAX_VALUE
);
page
.
setPageNumber
(
1
);
page
.
setTotalRow
(
Integer
.
MAX_VALUE
);
List
<
UserExcelData
>
users
=
userConsoleService
.
queryExcel
(
page
);
try
(
InputStream
is
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
excelTemplate
))
{
if
(
is
==
null
)
{
throw
new
PlatformException
(
"模板资源不存在:"
+
excelTemplate
);
}
FileItem
item
=
fileService
.
createFileTemp
(
"user_collection.xls"
);
OutputStream
os
=
item
.
openOutpuStream
();
Context
context
=
new
Context
();
context
.
putVar
(
"users"
,
users
);
JxlsHelper
.
getInstance
().
processTemplate
(
is
,
os
,
context
);
return
JsonResult
.
success
(
item
.
getId
());
}
catch
(
IOException
e
)
{
throw
new
PlatformException
(
e
.
getMessage
());
}
}
}
admin-console/src/main/java/com/ibeetl/admin/console/web/dto/UserExcelData.java
0 → 100644
View file @
fea41b40
package
com.ibeetl.admin.console.web.dto
;
import
javax.validation.constraints.NotBlank
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.ibeetl.admin.core.annotation.Dict
;
/**
* excel导出需要的模板数据
* @author Administrator
*
*/
public
class
UserExcelData
{
protected
Long
id
;
private
String
code
;
private
String
name
;
private
String
orgText
;
private
String
password
;
private
String
stateText
;
private
String
jobType1Text
;
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getOrgText
()
{
return
orgText
;
}
public
void
setOrgText
(
String
orgText
)
{
this
.
orgText
=
orgText
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getStateText
()
{
return
stateText
;
}
public
void
setStateText
(
String
stateText
)
{
this
.
stateText
=
stateText
;
}
public
String
getJobType1Text
()
{
return
jobType1Text
;
}
public
void
setJobType1Text
(
String
jobType1Text
)
{
this
.
jobType1Text
=
jobType1Text
;
}
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
}
admin-console/src/main/resources/excelTemplates/admin/user/user_collection_template.xls
0 → 100644
View file @
fea41b40
File added
admin-console/src/main/resources/static/js/admin/user/index.js
View file @
fea41b40
...
...
@@ -123,7 +123,15 @@ layui.define([ 'form', 'laydate', 'table','userApi' ], function(exports) {
var
url
=
"
/admin/user/changePassword.do?id=
"
+
data
.
id
;
Common
.
openDlg
(
url
,
"
用户管理>更改密码
"
);
}
},
exportUsers
:
function
(){
Common
.
openConfirm
(
"
确认要导出这些用户?
"
,
function
(){
userApi
.
exportUsers
(
$
(
"
#searchForm
"
),
function
(){
Common
.
info
(
"
导出成功
"
)
})
})
}
};
$
(
'
.ext-toolbar
'
).
on
(
'
click
'
,
function
()
{
var
type
=
$
(
this
).
data
(
'
type
'
);
...
...
admin-console/src/main/resources/static/js/admin/user/userApi.js
View file @
fea41b40
...
...
@@ -28,6 +28,12 @@ layui.define([], function(exports) {
callback
();
})
},
exportUsers
:
function
(
form
,
callback
){
var
formPara
=
form
.
serializeJson
();
Common
.
post
(
"
/admin/user/excel/export.json
"
,
formPara
,
function
()
{
callback
();
})
}
};
...
...
admin-console/src/main/resources/templates/admin/user/index.html
View file @
fea41b40
...
...
@@ -9,6 +9,8 @@
<layui:accessButton
function=
"user.role"
action=
"userRole"
>
操作角色
</layui:accessButton>
<layui:accessButton
function=
"user.role"
action=
"userRole"
>
流程角色
</layui:accessButton>
<layui:accessButton
function=
"user.password"
action=
"changePassword"
>
修改密码
</layui:accessButton>
<layui:accessButton
function=
"user.export"
action=
"export"
>
导出
</layui:accessButton>
<layui:accessButton
function=
"user.import"
action=
"import"
>
导入
</layui:accessButton>
</div>
<table
id=
"userTable"
lay-filter=
"userTable"
></table>
...
...
admin-core/src/main/java/com/ibeetl/admin/core/conf/FileSystemConfig.java
0 → 100644
View file @
fea41b40
package
com.ibeetl.admin.core.conf
;
import
java.io.File
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.Environment
;
import
com.ibeetl.admin.core.file.FileService
;
import
com.ibeetl.admin.core.file.LocaFileService
;
@Configuration
@ConditionalOnMissingBean
(
FileService
.
class
)
public
class
FileSystemConfig
{
@Autowired
Environment
env
;
@Bean
public
FileService
getFileService
()
{
String
root
=
env
.
getProperty
(
"localFile.root"
);
if
(
StringUtils
.
isEmpty
(
root
))
{
String
userDir
=
System
.
getProperty
(
"user.dir"
);
root
=
userDir
+
File
.
separator
+
"filesystem"
;
}
File
f
=
new
File
(
root
);
if
(!
f
.
exists
())
{
f
.
mkdirs
();
}
return
new
LocaFileService
(
root
);
}
}
admin-core/src/main/java/com/ibeetl/admin/core/file/FileItem.java
0 → 100644
View file @
fea41b40
package
com.ibeetl.admin.core.file
;
import
java.io.OutputStream
;
public
abstract
class
FileItem
{
String
name
;
String
id
;
public
abstract
OutputStream
openOutpuStream
();
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
}
admin-core/src/main/java/com/ibeetl/admin/core/file/FileService.java
0 → 100644
View file @
fea41b40
package
com.ibeetl.admin.core.file
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
/**
* 文件持久化,默认为文件系统,可以扩展到fastfds等
* @author xiandafu
*
*/
public
interface
FileService
{
/**
* 得到一个临时文件操作
* @param name
* @return
*/
public
FileItem
createFileTemp
(
String
name
);
public
FileItem
getFileItem
(
String
id
);
/**
*
* @param url
* @param os
*/
public
void
copyTemp
(
String
url
,
OutputStream
os
);
}
admin-core/src/main/java/com/ibeetl/admin/core/file/LocaFileService.java
0 → 100644
View file @
fea41b40
package
com.ibeetl.admin.core.file
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Random
;
import
com.ibeetl.admin.core.util.PlatformException
;
public
class
LocaFileService
implements
FileService
{
String
root
=
null
;
public
LocaFileService
(
String
root
)
{
this
.
root
=
root
;
}
@Override
public
FileItem
getFileItem
(
String
id
)
{
FileItem
item
=
new
LocalFileItem
();
item
.
setId
(
id
);
item
.
setName
(
parseName
(
id
));
return
item
;
}
@Override
public
FileItem
createFileTemp
(
String
name
)
{
FileItem
item
=
new
LocalFileItem
();
String
fileName
=
name
+
"."
+
this
.
suffixTemp
();
item
.
setId
(
fileName
);
item
.
setName
(
name
);
return
item
;
}
@Override
public
void
copyTemp
(
String
id
,
OutputStream
os
)
{
File
file
=
new
File
(
root
+
File
.
separator
+
id
);
FileInputStream
input
=
null
;
try
{
input
=
new
FileInputStream
(
file
);
byte
[]
buf
=
new
byte
[
1024
];
int
bytesRead
;
while
((
bytesRead
=
input
.
read
(
buf
))
>
0
)
{
os
.
write
(
buf
,
0
,
bytesRead
);
}
file
.
delete
();
}
catch
(
Exception
ex
)
{
throw
new
PlatformException
(
"下载文件失败"
+
ex
);
}
finally
{
try
{
input
.
close
();
os
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
private
String
suffixTemp
()
{
// TODO,改成唯一算法
return
System
.
currentTimeMillis
()
+
""
+
new
Random
().
nextInt
(
10000
)+
".temp"
;
}
private
String
parseName
(
String
id
)
{
String
[]
array
=
id
.
split
(
"\\."
);
return
array
[
0
]+
"."
+
array
[
1
];
}
class
LocalFileItem
extends
FileItem
{
public
OutputStream
openOutpuStream
()
{
File
file
=
new
File
(
root
+
File
.
separator
+
id
);
try
{
file
.
createNewFile
();
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
return
fos
;
}
catch
(
IOException
e
)
{
throw
new
PlatformException
(
"Open stream error "
+
id
);
}
}
}
}
admin-core/src/main/java/com/ibeetl/admin/core/util/FileDownloadUtil.java
0 → 100644
View file @
fea41b40
package
com.ibeetl.admin.core.util
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
javax.servlet.http.HttpServletResponse
;
public
class
FileDownloadUtil
{
public
static
OutputStream
getDownLoad
(
HttpServletResponse
response
,
String
fileName
)
throws
IOException
{
response
.
setContentType
(
"text/html; charset = UTF-8"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
fileName
);
return
response
.
getOutputStream
();
}
}
admin-core/src/main/java/com/ibeetl/admin/core/web/FileSystemContorller.java
0 → 100644
View file @
fea41b40
package
com.ibeetl.admin.core.web
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.servlet.ModelAndView
;
import
com.ibeetl.admin.core.file.FileItem
;
import
com.ibeetl.admin.core.file.FileService
;
@Controller
public
class
FileSystemContorller
{
private
final
Log
log
=
LogFactory
.
getLog
(
this
.
getClass
());
private
static
final
String
MODEL
=
"/core/file"
;
FileService
fileService
;
@GetMapping
(
MODEL
+
"/get.do"
)
public
ModelAndView
index
(
HttpServletResponse
response
,
String
id
)
throws
IOException
{
response
.
setContentType
(
"text/html; charset = UTF-8"
);
FileItem
fileItem
=
fileService
.
getFileItem
(
id
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
fileItem
.
getName
());
fileService
.
copyTemp
(
id
,
response
.
getOutputStream
());
return
null
;
}
}
pom.xml
View file @
fea41b40
...
...
@@ -66,11 +66,7 @@
<version>
2.1.2
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
com.ibeetl
</groupId>
<artifactId>
xlsunit
</artifactId>
<version>
1.0.8
</version>
</dependency>
<dependency>
<groupId>
com.zaxxer
</groupId>
<artifactId>
HikariCP
</artifactId>
...
...
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