Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
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
yaru
fgqyxxlr
Commits
ec8c7f1d
Commit
ec8c7f1d
authored
Jan 10, 2019
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持用户数据导入
parent
619e1d24
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
290 additions
and
45 deletions
+290
-45
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysJobController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysJobLogController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysPostController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
+1
-1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java
+24
-2
ruoyi-admin/src/main/resources/static/ruoyi/css/ry-ui.css
+44
-9
ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js
+63
-1
ruoyi-admin/src/main/resources/templates/system/user/edit.html
+1
-1
ruoyi-admin/src/main/resources/templates/system/user/user.html
+19
-0
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
+23
-1
ruoyi-common/src/main/java/com/ruoyi/common/reflect/ReflectUtils.java
+0
-0
ruoyi-common/src/main/java/com/ruoyi/common/utils/ExcelUtil.java
+0
-0
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java
+5
-0
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
+8
-0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
+94
-22
No files found.
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysJobController.java
View file @
ec8c7f1d
...
...
@@ -59,7 +59,7 @@ public class SysJobController extends BaseController
{
List
<
SysJob
>
list
=
jobService
.
selectJobList
(
job
);
ExcelUtil
<
SysJob
>
util
=
new
ExcelUtil
<
SysJob
>(
SysJob
.
class
);
return
util
.
exportExcel
(
list
,
"
job
"
);
return
util
.
exportExcel
(
list
,
"
定时任务
"
);
}
@Log
(
title
=
"定时任务"
,
businessType
=
BusinessType
.
DELETE
)
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysJobLogController.java
View file @
ec8c7f1d
...
...
@@ -58,7 +58,7 @@ public class SysJobLogController extends BaseController
{
List
<
SysJobLog
>
list
=
jobLogService
.
selectJobLogList
(
jobLog
);
ExcelUtil
<
SysJobLog
>
util
=
new
ExcelUtil
<
SysJobLog
>(
SysJobLog
.
class
);
return
util
.
exportExcel
(
list
,
"
jobLog
"
);
return
util
.
exportExcel
(
list
,
"
调度日志
"
);
}
@Log
(
title
=
"调度日志"
,
businessType
=
BusinessType
.
DELETE
)
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java
View file @
ec8c7f1d
...
...
@@ -56,7 +56,7 @@ public class SysLogininforController extends BaseController
{
List
<
SysLogininfor
>
list
=
logininforService
.
selectLogininforList
(
logininfor
);
ExcelUtil
<
SysLogininfor
>
util
=
new
ExcelUtil
<
SysLogininfor
>(
SysLogininfor
.
class
);
return
util
.
exportExcel
(
list
,
"
logininfor
"
);
return
util
.
exportExcel
(
list
,
"
登陆日志
"
);
}
@RequiresPermissions
(
"monitor:logininfor:remove"
)
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysOperlogController.java
View file @
ec8c7f1d
...
...
@@ -58,7 +58,7 @@ public class SysOperlogController extends BaseController
{
List
<
SysOperLog
>
list
=
operLogService
.
selectOperLogList
(
operLog
);
ExcelUtil
<
SysOperLog
>
util
=
new
ExcelUtil
<
SysOperLog
>(
SysOperLog
.
class
);
return
util
.
exportExcel
(
list
,
"
operLog
"
);
return
util
.
exportExcel
(
list
,
"
操作日志
"
);
}
@RequiresPermissions
(
"monitor:operlog:remove"
)
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
View file @
ec8c7f1d
...
...
@@ -62,7 +62,7 @@ public class SysConfigController extends BaseController
{
List
<
SysConfig
>
list
=
configService
.
selectConfigList
(
config
);
ExcelUtil
<
SysConfig
>
util
=
new
ExcelUtil
<
SysConfig
>(
SysConfig
.
class
);
return
util
.
exportExcel
(
list
,
"
config
"
);
return
util
.
exportExcel
(
list
,
"
参数数据
"
);
}
/**
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java
View file @
ec8c7f1d
...
...
@@ -59,7 +59,7 @@ public class SysDictDataController extends BaseController
{
List
<
SysDictData
>
list
=
dictDataService
.
selectDictDataList
(
dictData
);
ExcelUtil
<
SysDictData
>
util
=
new
ExcelUtil
<
SysDictData
>(
SysDictData
.
class
);
return
util
.
exportExcel
(
list
,
"
dictData
"
);
return
util
.
exportExcel
(
list
,
"
字典数据
"
);
}
/**
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
View file @
ec8c7f1d
...
...
@@ -60,7 +60,7 @@ public class SysDictTypeController extends BaseController
List
<
SysDictType
>
list
=
dictTypeService
.
selectDictTypeList
(
dictType
);
ExcelUtil
<
SysDictType
>
util
=
new
ExcelUtil
<
SysDictType
>(
SysDictType
.
class
);
return
util
.
exportExcel
(
list
,
"
dictType
"
);
return
util
.
exportExcel
(
list
,
"
字典类型
"
);
}
/**
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysPostController.java
View file @
ec8c7f1d
...
...
@@ -59,7 +59,7 @@ public class SysPostController extends BaseController
{
List
<
SysPost
>
list
=
postService
.
selectPostList
(
post
);
ExcelUtil
<
SysPost
>
util
=
new
ExcelUtil
<
SysPost
>(
SysPost
.
class
);
return
util
.
exportExcel
(
list
,
"
post
"
);
return
util
.
exportExcel
(
list
,
"
岗位数据
"
);
}
@RequiresPermissions
(
"system:post:remove"
)
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
View file @
ec8c7f1d
...
...
@@ -60,7 +60,7 @@ public class SysRoleController extends BaseController
{
List
<
SysRole
>
list
=
roleService
.
selectRoleList
(
role
);
ExcelUtil
<
SysRole
>
util
=
new
ExcelUtil
<
SysRole
>(
SysRole
.
class
);
return
util
.
exportExcel
(
list
,
"
role
"
);
return
util
.
exportExcel
(
list
,
"
角色数据
"
);
}
/**
...
...
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java
View file @
ec8c7f1d
...
...
@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.ruoyi.common.annotation.Log
;
import
com.ruoyi.common.base.AjaxResult
;
import
com.ruoyi.common.enums.BusinessType
;
...
...
@@ -19,11 +20,11 @@ import com.ruoyi.common.utils.ExcelUtil;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.framework.shiro.service.SysPasswordService
;
import
com.ruoyi.framework.util.ShiroUtils
;
import
com.ruoyi.framework.web.base.BaseController
;
import
com.ruoyi.system.domain.SysUser
;
import
com.ruoyi.system.service.ISysPostService
;
import
com.ruoyi.system.service.ISysRoleService
;
import
com.ruoyi.system.service.ISysUserService
;
import
com.ruoyi.framework.web.base.BaseController
;
/**
* 用户信息
...
...
@@ -73,7 +74,28 @@ public class SysUserController extends BaseController
{
List
<
SysUser
>
list
=
userService
.
selectUserList
(
user
);
ExcelUtil
<
SysUser
>
util
=
new
ExcelUtil
<
SysUser
>(
SysUser
.
class
);
return
util
.
exportExcel
(
list
,
"user"
);
return
util
.
exportExcel
(
list
,
"用户数据"
);
}
@Log
(
title
=
"用户管理"
,
businessType
=
BusinessType
.
IMPORT
)
@RequiresPermissions
(
"system:user:import"
)
@PostMapping
(
"/importData"
)
@ResponseBody
public
AjaxResult
importData
(
MultipartFile
file
,
boolean
updateSupport
)
throws
Exception
{
ExcelUtil
<
SysUser
>
util
=
new
ExcelUtil
<
SysUser
>(
SysUser
.
class
);
List
<
SysUser
>
userList
=
util
.
importExcel
(
file
.
getInputStream
());
String
message
=
userService
.
importUser
(
userList
,
updateSupport
);
return
AjaxResult
.
success
(
message
);
}
@RequiresPermissions
(
"system:user:view"
)
@GetMapping
(
"/importTemplate"
)
@ResponseBody
public
AjaxResult
importTemplate
()
{
ExcelUtil
<
SysUser
>
util
=
new
ExcelUtil
<
SysUser
>(
SysUser
.
class
);
return
util
.
importTemplateExcel
(
"用户数据"
);
}
/**
...
...
ruoyi-admin/src/main/resources/static/ruoyi/css/ry-ui.css
View file @
ec8c7f1d
...
...
@@ -3,7 +3,42 @@
* Copyright (c) 2018 ruoyi
*/
/** 用户管理 样式布局 */
/** 基础通用 **/
.pt5
{
padding-top
:
5px
;
}
.pr5
{
padding-right
:
5px
;
}
.pb5
{
padding-bottom
:
5px
;
}
.mt10
{
margin-top
:
10px
;
}
.mr10
{
margin-right
:
10px
;
}
.mb10
{
margin-bottom
:
10px
;
}
.ml0
{
margin-left
:
10px
;
}
.mt20
{
margin-top
:
20px
;
}
.mr20
{
margin-right
:
20px
;
}
.mb20
{
margin-bottom
:
20px
;
}
.ml20
{
margin-left
:
20px
;
}
/** 用户管理 样式布局 **/
.box
{
position
:
relative
;
border-radius
:
3px
;
...
...
@@ -91,7 +126,7 @@
margin
:
5px
0
5px
-25px
}
/** select2 样式修改 */
/** select2 样式修改 *
*
/
.select2-container--default
.select2-selection--multiple
.select2-selection__choice
{
background-color
:
#1AB394
;
border-color
:
#1AB394
;
...
...
@@ -112,7 +147,7 @@
padding-right
:
10px
}
/** 表单验证 样式布局 */
/** 表单验证 样式布局 *
*
/
label
.error
{
position
:
absolute
;
right
:
18px
;
...
...
@@ -143,7 +178,7 @@ label.error {
max-width
:
none
;
}
/** 复选框&单选框 */
/** 复选框&单选框 *
*
/
.check-box
,
.radio-box
{
display
:
inline-block
;
box-sizing
:
border-box
;
...
...
@@ -160,7 +195,7 @@ label.error {
left
:
0
}
/*
iCheck
*/
/*
* iCheck *
*/
.icheckbox-blue
,
.iradio-blue
{
display
:
block
;
margin
:
0
;
...
...
@@ -214,7 +249,7 @@ label.error {
background-position
:
-180px
0
}
/** 遮罩层 */
/** 遮罩层 *
*
/
.loaderbox
{
display
:
inline-block
;
min-width
:
125px
;
...
...
@@ -281,7 +316,7 @@ label.error {
}
}
/** 表单查询条件 */
/** 表单查询条件 *
*
/
ul
{
margin
:
0
;
padding
:
0
;
...
...
@@ -409,7 +444,7 @@ label {
cursor
:
pointer
;
}
/** 表格查询数据 */
/** 表格查询数据 *
*
/
.table-striped
{
min-height
:
75%
;
}
...
...
@@ -437,7 +472,7 @@ label {
border
:
1px
solid
#ddd
!important
}
/** 首页样式 */
/** 首页样式 *
*
/
.ax_close_max
{
position
:
fixed
;
top
:
5px
;
...
...
ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js
View file @
ec8c7f1d
...
...
@@ -92,7 +92,7 @@
}
$
(
"#bootstrap-table"
).
bootstrapTable
(
'refresh'
,
params
);
},
//
下载-默认第一个form
//
导出数据
exportExcel
:
function
(
formId
)
{
var
currentId
=
$
.
common
.
isEmpty
(
formId
)
?
$
(
'form'
).
attr
(
'id'
)
:
formId
;
$
.
modal
.
loading
(
"正在导出数据,请稍后..."
);
...
...
@@ -105,6 +105,64 @@
$
.
modal
.
closeLoading
();
});
},
// 下载模板
importTemplate
:
function
()
{
$
.
get
(
$
.
table
.
_option
.
importTemplateUrl
,
function
(
result
)
{
if
(
result
.
code
==
web_status
.
SUCCESS
)
{
window
.
location
.
href
=
ctx
+
"common/download?fileName="
+
result
.
msg
+
"&delete="
+
true
;
}
else
{
$
.
modal
.
alertError
(
result
.
msg
);
}
});
},
// 导入数据
importExcel
:
function
(
formId
)
{
var
currentId
=
$
.
common
.
isEmpty
(
formId
)
?
'importForm'
:
formId
;
$
.
form
.
reset
(
currentId
);
layer
.
open
({
type
:
1
,
area
:
[
'400px'
],
fix
:
false
,
//不固定
maxmin
:
true
,
shade
:
0.3
,
title
:
'导入'
+
$
.
table
.
_option
.
modalName
+
'数据'
,
content
:
$
(
'#'
+
currentId
),
btn
:
[
'<i class="fa fa-check"></i> 导入'
,
'<i class="fa fa-remove"></i> 取消'
],
// 弹层外区域关闭
shadeClose
:
true
,
btn1
:
function
(
index
,
layero
){
var
file
=
layero
.
find
(
'#file'
).
val
();
if
(
file
==
''
||
(
!
$
.
common
.
endWith
(
file
,
'.xls'
)
&&
!
$
.
common
.
endWith
(
file
,
'.xlsx'
))){
$
.
modal
.
msgWarning
(
"请选择后缀为 “xls”或“xlsx”的文件。"
);
return
false
;
}
var
index
=
layer
.
load
(
2
,
{
shade
:
false
});
var
url
=
prefix
+
"/importData"
;
var
formData
=
new
FormData
();
formData
.
append
(
"file"
,
$
(
'#file'
)[
0
].
files
[
0
]);
formData
.
append
(
"updateSupport"
,
$
(
"input[name='updateSupport']"
).
is
(
':checked'
));
$
.
ajax
({
url
:
url
,
data
:
formData
,
cache
:
false
,
contentType
:
false
,
processData
:
false
,
type
:
'POST'
,
success
:
function
(
result
)
{
if
(
result
.
code
==
web_status
.
SUCCESS
)
{
$
.
modal
.
closeAll
();
$
.
modal
.
alertSuccess
(
result
.
msg
);
$
.
table
.
refresh
();
}
else
{
layer
.
close
(
index
);
$
.
modal
.
alertError
(
result
.
msg
);
}
}
});
}
});
},
// 刷新表格
refresh
:
function
()
{
$
(
"#bootstrap-table"
).
bootstrapTable
(
'refresh'
,
{
...
...
@@ -288,6 +346,10 @@
var
index
=
parent
.
layer
.
getFrameIndex
(
window
.
name
);
parent
.
layer
.
close
(
index
);
},
// 关闭全部窗体
closeAll
:
function
()
{
layer
.
closeAll
();
},
// 确认窗体
confirm
:
function
(
content
,
callBack
)
{
layer
.
confirm
(
content
,
{
...
...
ruoyi-admin/src/main/resources/templates/system/user/edit.html
View file @
ec8c7f1d
...
...
@@ -184,7 +184,7 @@
/*用户管理-修改-选择部门树*/
function
selectDeptTree
()
{
var
deptId
=
$
(
"#treeId"
).
val
();
var
deptId
=
$
.
common
.
isEmpty
(
$
(
"#treeId"
).
val
())
?
"100"
:
$
(
"#treeId"
).
val
();
var
url
=
ctx
+
"system/dept/selectDeptTree/"
+
deptId
;
var
options
=
{
title
:
'选择部门'
,
...
...
ruoyi-admin/src/main/resources/templates/system/user/user.html
View file @
ec8c7f1d
...
...
@@ -73,6 +73,9 @@
<a
class=
"btn btn-danger btn-del disabled"
onclick=
"$.operate.removeAll()"
shiro:hasPermission=
"system:user:remove"
>
<i
class=
"fa fa-remove"
></i>
删除
</a>
<a
class=
"btn btn-info"
onclick=
"$.table.importExcel()"
shiro:hasPermission=
"system:user:import"
>
<i
class=
"fa fa-download"
></i>
导入
</a>
<a
class=
"btn btn-warning"
onclick=
"$.table.exportExcel()"
shiro:hasPermission=
"system:user:export"
>
<i
class=
"fa fa-download"
></i>
导出
</a>
...
...
@@ -83,6 +86,7 @@
</div>
</div>
</div>
<div
th:include=
"include :: footer"
></div>
<script
th:src=
"@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"
></script>
<script
th:src=
"@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"
></script>
...
...
@@ -106,6 +110,8 @@
updateUrl
:
prefix
+
"/edit/{id}"
,
removeUrl
:
prefix
+
"/remove"
,
exportUrl
:
prefix
+
"/export"
,
importUrl
:
prefix
+
"/importData"
,
importTemplateUrl
:
prefix
+
"/importTemplate"
,
sortName
:
"createTime"
,
sortOrder
:
"desc"
,
modalName
:
"用户"
,
...
...
@@ -214,4 +220,16 @@
}
</script>
</body>
<form
id=
"importForm"
enctype=
"multipart/form-data"
class=
"mt20 mb10"
style=
"display: none;"
>
<div
class=
"col-xs-offset-1"
>
<input
type=
"file"
id=
"file"
name=
"file"
/>
<div
class=
"mt10 pt5"
>
<input
type=
"checkbox"
id=
"updateSupport"
name=
"updateSupport"
title=
"如果登录账户已经存在,更新这条数据。"
>
是否更新已经存在的用户数据
<a
onclick=
"$.table.importTemplate()"
class=
"btn btn-default btn-xs"
><i
class=
"fa fa-file-excel-o"
></i>
下载模板
</a>
</div>
<font
color=
"red"
class=
"pull-left mt10"
>
提示:仅允许导入“xls”或“xlsx”格式文件!
</font>
</div>
</form>
</html>
\ No newline at end of file
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
View file @
ec8c7f1d
...
...
@@ -37,7 +37,7 @@ public @interface Excel
/**
* 导出时在excel中每个列的宽 单位为字符
*/
public
double
width
()
default
20
;
public
double
width
()
default
16
;
/**
* 文字后缀,如% 90 变成90%
...
...
@@ -68,4 +68,25 @@ public @interface Excel
* 另一个类中的属性名称,支持多级获取,以小数点隔开
*/
public
String
targetAttr
()
default
""
;
/**
* 字段类型( 1:仅导出;2:仅导入)
*/
Type
type
()
default
Type
.
EXPORT
;
public
enum
Type
{
EXPORT
(
1
),
IMPORT
(
2
);
private
final
int
value
;
Type
(
int
value
)
{
this
.
value
=
value
;
}
public
int
value
()
{
return
this
.
value
;
}
}
}
\ No newline at end of file
ruoyi-common/src/main/java/com/ruoyi/common/reflect/ReflectUtils.java
0 → 100644
View file @
ec8c7f1d
This diff is collapsed.
Click to expand it.
ruoyi-common/src/main/java/com/ruoyi/common/utils/ExcelUtil.java
View file @
ec8c7f1d
This diff is collapsed.
Click to expand it.
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java
View file @
ec8c7f1d
...
...
@@ -244,6 +244,10 @@ public class SysUser extends BaseEntity
public
SysDept
getDept
()
{
if
(
dept
==
null
)
{
dept
=
new
SysDept
();
}
return
dept
;
}
...
...
@@ -304,6 +308,7 @@ public class SysUser extends BaseEntity
.
append
(
"updateBy"
,
getUpdateBy
())
.
append
(
"updateTime"
,
getUpdateTime
())
.
append
(
"remark"
,
getRemark
())
.
append
(
"dept"
,
getDept
())
.
toString
();
}
}
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
View file @
ec8c7f1d
...
...
@@ -138,4 +138,12 @@ public interface ISysUserService
* @return 结果
*/
public
String
selectUserPostGroup
(
Long
userId
);
/**
* 导入用户数据
*
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
* @return 结果
*/
public
String
importUser
(
List
<
SysUser
>
userList
,
Boolean
isUpdateSupport
);
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
View file @
ec8c7f1d
...
...
@@ -2,6 +2,8 @@ package com.ruoyi.system.service.impl;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ruoyi.common.annotation.DataScope
;
...
...
@@ -29,6 +31,8 @@ import com.ruoyi.system.service.ISysUserService;
@Service
public
class
SysUserServiceImpl
implements
ISysUserService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
SysUserServiceImpl
.
class
);
@Autowired
private
SysUserMapper
userMapper
;
...
...
@@ -212,18 +216,22 @@ public class SysUserServiceImpl implements ISysUserService
*/
public
void
insertUserRole
(
SysUser
user
)
{
// 新增用户与角色管理
List
<
SysUserRole
>
list
=
new
ArrayList
<
SysUserRole
>();
for
(
Long
roleId
:
user
.
getRoleIds
())
Long
[]
roles
=
user
.
getRoleIds
();
if
(
StringUtils
.
isNotNull
(
roles
))
{
SysUserRole
ur
=
new
SysUserRole
();
ur
.
setUserId
(
user
.
getUserId
());
ur
.
setRoleId
(
roleId
);
list
.
add
(
ur
);
}
if
(
list
.
size
()
>
0
)
{
userRoleMapper
.
batchUserRole
(
list
);
// 新增用户与角色管理
List
<
SysUserRole
>
list
=
new
ArrayList
<
SysUserRole
>();
for
(
Long
roleId
:
roles
)
{
SysUserRole
ur
=
new
SysUserRole
();
ur
.
setUserId
(
user
.
getUserId
());
ur
.
setRoleId
(
roleId
);
list
.
add
(
ur
);
}
if
(
list
.
size
()
>
0
)
{
userRoleMapper
.
batchUserRole
(
list
);
}
}
}
...
...
@@ -234,18 +242,22 @@ public class SysUserServiceImpl implements ISysUserService
*/
public
void
insertUserPost
(
SysUser
user
)
{
// 新增用户与岗位管理
List
<
SysUserPost
>
list
=
new
ArrayList
<
SysUserPost
>();
for
(
Long
postId
:
user
.
getPostIds
())
Long
[]
posts
=
user
.
getPostIds
();
if
(
StringUtils
.
isNotNull
(
posts
))
{
SysUserPost
up
=
new
SysUserPost
();
up
.
setUserId
(
user
.
getUserId
());
up
.
setPostId
(
postId
);
list
.
add
(
up
);
}
if
(
list
.
size
()
>
0
)
{
userPostMapper
.
batchUserPost
(
list
);
// 新增用户与岗位管理
List
<
SysUserPost
>
list
=
new
ArrayList
<
SysUserPost
>();
for
(
Long
postId
:
posts
)
{
SysUserPost
up
=
new
SysUserPost
();
up
.
setUserId
(
user
.
getUserId
());
up
.
setPostId
(
postId
);
list
.
add
(
up
);
}
if
(
list
.
size
()
>
0
)
{
userPostMapper
.
batchUserPost
(
list
);
}
}
}
...
...
@@ -345,4 +357,64 @@ public class SysUserServiceImpl implements ISysUserService
}
return
idsStr
.
toString
();
}
/**
* 导入用户数据
*
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
* @return 结果
*/
public
String
importUser
(
List
<
SysUser
>
userList
,
Boolean
isUpdateSupport
)
{
if
(
StringUtils
.
isNull
(
userList
)
||
userList
.
size
()
==
0
)
{
throw
new
BusinessException
(
"导入用户数据不能为空!"
);
}
int
successNum
=
0
;
int
failureNum
=
0
;
StringBuilder
successMsg
=
new
StringBuilder
();
StringBuilder
failureMsg
=
new
StringBuilder
();
for
(
SysUser
user
:
userList
)
{
try
{
// 验证是否存在这个用户
SysUser
u
=
userMapper
.
selectUserByLoginName
(
user
.
getLoginName
());
if
(
StringUtils
.
isNull
(
u
))
{
this
.
insertUser
(
user
);
successNum
++;
successMsg
.
append
(
"<br/>"
+
successNum
+
"、账号 "
+
user
.
getLoginName
()
+
" 导入成功"
);
}
else
if
(
isUpdateSupport
)
{
this
.
updateUser
(
user
);
successNum
++;
successMsg
.
append
(
"<br/>"
+
successNum
+
"、账号 "
+
user
.
getLoginName
()
+
" 更新成功"
);
}
else
{
failureNum
++;
failureMsg
.
append
(
"<br/>"
+
failureNum
+
"、账号 "
+
user
.
getLoginName
()
+
" 已存在"
);
}
}
catch
(
Exception
e
)
{
failureNum
++;
String
msg
=
"<br/>"
+
failureNum
+
"、账号 "
+
user
.
getLoginName
()
+
" 导入失败:"
;
failureMsg
.
append
(
msg
+
e
.
getMessage
());
log
.
error
(
msg
,
e
);
}
}
if
(
failureNum
>
0
)
{
failureMsg
.
insert
(
0
,
"很抱歉,导入失败!共 "
+
failureNum
+
" 条数据格式不正确,错误如下:"
);
throw
new
BusinessException
(
failureMsg
.
toString
());
}
else
{
successMsg
.
insert
(
0
,
"恭喜您,数据已全部导入成功!共 "
+
successNum
+
" 条,数据如下:"
);
}
return
successMsg
.
toString
();
}
}
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