Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
T
topology
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
姜立玮
topology
Commits
b508e6f2
提交
b508e6f2
authored
12月 11, 2019
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增用户导入
上级
8216d4e8
变更
8
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
220 行增加
和
10 行删除
+220
-10
user.js
ruoyi-ui/src/api/system/user.js
+8
-0
index.vue
ruoyi-ui/src/views/system/user/index.vue
+88
-5
SysUserController.java
...om/ruoyi/project/system/controller/SysUserController.java
+27
-0
SysUser.java
...rc/main/java/com/ruoyi/project/system/domain/SysUser.java
+8
-3
ISysConfigService.java
...a/com/ruoyi/project/system/service/ISysConfigService.java
+1
-1
ISysUserService.java
...ava/com/ruoyi/project/system/service/ISysUserService.java
+10
-0
SysConfigServiceImpl.java
...oyi/project/system/service/impl/SysConfigServiceImpl.java
+1
-1
SysUserServiceImpl.java
...ruoyi/project/system/service/impl/SysUserServiceImpl.java
+77
-0
没有找到文件。
ruoyi-ui/src/api/system/user.js
浏览文件 @
b508e6f2
...
...
@@ -117,3 +117,11 @@ export function uploadAvatar(data) {
data
:
data
})
}
// 下载用户导入模板
export
function
importTemplate
()
{
return
request
({
url
:
'/system/user/importTemplate'
,
method
:
'get'
})
}
ruoyi-ui/src/views/system/user/index.vue
浏览文件 @
b508e6f2
...
...
@@ -112,6 +112,15 @@
v-hasPermi=
"['system:user:remove']"
>
删除
</el-button>
</el-col>
<el-col
:span=
"1.5"
>
<el-button
type=
"info"
icon=
"el-icon-upload2"
size=
"mini"
@
click=
"handleImport"
v-hasPermi=
"['system:user:import']"
>
导入
</el-button>
</el-col>
<el-col
:span=
"1.5"
>
<el-button
type=
"warning"
...
...
@@ -284,11 +293,43 @@
<el-button
@
click=
"cancel"
>
取 消
</el-button>
</div>
</el-dialog>
<!-- 用户导入对话框 -->
<el-dialog
:title=
"upload.title"
:visible
.
sync=
"upload.open"
width=
"400px"
>
<el-upload
ref=
"upload"
:limit=
"1"
accept=
".xlsx, .xls"
:headers=
"upload.headers"
:action=
"upload.url + '?updateSupport=' + upload.updateSupport"
:disabled=
"upload.isUploading"
:on-progress=
"handleFileUploadProgress"
:on-success=
"handleFileSuccess"
:auto-upload=
"false"
drag
>
<i
class=
"el-icon-upload"
></i>
<div
class=
"el-upload__text"
>
将文件拖到此处,或
<em>
点击上传
</em>
</div>
<div
class=
"el-upload__tip"
slot=
"tip"
>
<el-checkbox
v-model=
"upload.updateSupport"
/>
是否更新已经存在的用户数据
<el-link
type=
"info"
style=
"font-size:12px"
@
click=
"importTemplate"
>
下载模板
</el-link>
</div>
<div
class=
"el-upload__tip"
style=
"color:red"
slot=
"tip"
>
提示:仅允许导入“xls”或“xlsx”格式文件!
</div>
</el-upload>
<div
slot=
"footer"
class=
"dialog-footer"
>
<el-button
type=
"primary"
@
click=
"submitFileForm"
>
确 定
</el-button>
<el-button
@
click=
"upload.open = false"
>
取 消
</el-button>
</div>
</el-dialog>
</div>
</template>
<
script
>
import
{
listUser
,
getUser
,
delUser
,
addUser
,
updateUser
,
exportUser
,
resetUserPwd
,
changeUserStatus
}
from
"@/api/system/user"
;
import
{
listUser
,
getUser
,
delUser
,
addUser
,
updateUser
,
exportUser
,
resetUserPwd
,
changeUserStatus
,
importTemplate
}
from
"@/api/system/user"
;
import
{
getToken
}
from
"@/utils/auth"
;
import
{
treeselect
}
from
"@/api/system/dept"
;
import
Treeselect
from
"@riophae/vue-treeselect"
;
import
"@riophae/vue-treeselect/dist/vue-treeselect.css"
;
...
...
@@ -336,6 +377,21 @@ export default {
children
:
"children"
,
label
:
"label"
},
// 用户导入参数
upload
:
{
// 是否显示弹出层(用户导入)
open
:
false
,
// 弹出层标题(用户导入)
title
:
""
,
// 是否禁用上传
isUploading
:
false
,
// 是否更新已经存在的用户数据
updateSupport
:
0
,
// 设置上传的请求头部
headers
:
{
Authorization
:
"Bearer "
+
getToken
()
},
// 上传的地址
url
:
process
.
env
.
VUE_APP_BASE_API
+
"/system/user/importData"
},
// 查询参数
queryParams
:
{
pageNum
:
1
,
...
...
@@ -473,9 +529,9 @@ export default {
},
// 多选框选中数据
handleSelectionChange
(
selection
)
{
this
.
ids
=
selection
.
map
(
item
=>
item
.
userId
)
this
.
single
=
selection
.
length
!=
1
this
.
multiple
=
!
selection
.
length
this
.
ids
=
selection
.
map
(
item
=>
item
.
userId
)
;
this
.
single
=
selection
.
length
!=
1
;
this
.
multiple
=
!
selection
.
length
;
},
/** 新增按钮操作 */
handleAdd
()
{
...
...
@@ -493,7 +549,7 @@ export default {
handleUpdate
(
row
)
{
this
.
reset
();
this
.
getTreeselect
();
const
userId
=
row
.
userId
||
this
.
ids
const
userId
=
row
.
userId
||
this
.
ids
;
getUser
(
userId
).
then
(
response
=>
{
this
.
form
=
response
.
data
;
this
.
postOptions
=
response
.
posts
;
...
...
@@ -574,6 +630,33 @@ export default {
}).
then
(
response
=>
{
this
.
download
(
response
.
msg
);
}).
catch
(
function
()
{});
},
/** 导入按钮操作 */
handleImport
()
{
this
.
upload
.
title
=
"用户导入"
;
this
.
upload
.
open
=
true
;
},
/** 下载模板操作 */
importTemplate
()
{
importTemplate
().
then
(
response
=>
{
this
.
download
(
response
.
msg
);
});
},
// 文件上传中处理
handleFileUploadProgress
(
event
,
file
,
fileList
)
{
this
.
upload
.
isUploading
=
true
;
},
// 文件上传成功处理
handleFileSuccess
(
response
,
file
,
fileList
)
{
this
.
upload
.
open
=
false
;
this
.
upload
.
isUploading
=
false
;
this
.
$refs
.
upload
.
clearFiles
();
this
.
$alert
(
response
.
msg
,
"导入结果"
,
{
dangerouslyUseHTMLString
:
true
});
this
.
getList
();
},
// 提交上传文件
submitFileForm
()
{
this
.
$refs
.
upload
.
submit
();
}
}
};
...
...
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysUserController.java
浏览文件 @
b508e6f2
...
...
@@ -12,12 +12,16 @@ import org.springframework.web.bind.annotation.PutMapping;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.ruoyi.common.constant.UserConstants
;
import
com.ruoyi.common.utils.SecurityUtils
;
import
com.ruoyi.common.utils.ServletUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.poi.ExcelUtil
;
import
com.ruoyi.framework.aspectj.lang.annotation.Log
;
import
com.ruoyi.framework.aspectj.lang.enums.BusinessType
;
import
com.ruoyi.framework.security.LoginUser
;
import
com.ruoyi.framework.security.service.TokenService
;
import
com.ruoyi.framework.web.controller.BaseController
;
import
com.ruoyi.framework.web.domain.AjaxResult
;
import
com.ruoyi.framework.web.page.TableDataInfo
;
...
...
@@ -44,6 +48,9 @@ public class SysUserController extends BaseController
@Autowired
private
ISysPostService
postService
;
@Autowired
private
TokenService
tokenService
;
/**
* 获取用户列表
*/
...
...
@@ -66,6 +73,26 @@ public class SysUserController extends BaseController
return
util
.
exportExcel
(
list
,
"用户数据"
);
}
@Log
(
title
=
"用户管理"
,
businessType
=
BusinessType
.
IMPORT
)
@PreAuthorize
(
"@ss.hasPermi('system:user:import')"
)
@PostMapping
(
"/importData"
)
public
AjaxResult
importData
(
MultipartFile
file
,
boolean
updateSupport
)
throws
Exception
{
ExcelUtil
<
SysUser
>
util
=
new
ExcelUtil
<
SysUser
>(
SysUser
.
class
);
List
<
SysUser
>
userList
=
util
.
importExcel
(
file
.
getInputStream
());
LoginUser
loginUser
=
tokenService
.
getLoginUser
(
ServletUtils
.
getRequest
());
String
operName
=
loginUser
.
getUsername
();
String
message
=
userService
.
importUser
(
userList
,
updateSupport
,
operName
);
return
AjaxResult
.
success
(
message
);
}
@GetMapping
(
"/importTemplate"
)
public
AjaxResult
importTemplate
()
{
ExcelUtil
<
SysUser
>
util
=
new
ExcelUtil
<
SysUser
>(
SysUser
.
class
);
return
util
.
importTemplateExcel
(
"用户数据"
);
}
/**
* 根据用户编号获取详细信息
*/
...
...
ruoyi/src/main/java/com/ruoyi/project/system/domain/SysUser.java
浏览文件 @
b508e6f2
...
...
@@ -9,6 +9,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
com.ruoyi.framework.aspectj.lang.annotation.Excel
;
import
com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType
;
import
com.ruoyi.framework.aspectj.lang.annotation.Excel.Type
;
import
com.ruoyi.framework.aspectj.lang.annotation.Excels
;
import
com.ruoyi.framework.web.domain.BaseEntity
;
...
...
@@ -26,6 +27,7 @@ public class SysUser extends BaseEntity
private
Long
userId
;
/** 部门ID */
@Excel
(
name
=
"部门编号"
,
type
=
Type
.
IMPORT
)
private
Long
deptId
;
/** 用户账号 */
...
...
@@ -65,15 +67,18 @@ public class SysUser extends BaseEntity
private
String
delFlag
;
/** 最后登陆IP */
@Excel
(
name
=
"最后登陆IP"
)
@Excel
(
name
=
"最后登陆IP"
,
type
=
Type
.
EXPORT
)
private
String
loginIp
;
/** 最后登陆时间 */
@Excel
(
name
=
"最后登陆时间"
,
width
=
30
,
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
)
@Excel
(
name
=
"最后登陆时间"
,
width
=
30
,
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
,
type
=
Type
.
EXPORT
)
private
Date
loginDate
;
/** 部门对象 */
@Excels
({
@Excel
(
name
=
"部门名称"
,
targetAttr
=
"deptName"
),
@Excel
(
name
=
"部门负责人"
,
targetAttr
=
"leader"
)
})
@Excels
({
@Excel
(
name
=
"部门名称"
,
targetAttr
=
"deptName"
,
type
=
Type
.
EXPORT
),
@Excel
(
name
=
"部门负责人"
,
targetAttr
=
"leader"
,
type
=
Type
.
EXPORT
)
})
private
SysDept
dept
;
/** 角色对象 */
...
...
ruoyi/src/main/java/com/ruoyi/project/system/service/ISysConfigService.java
浏览文件 @
b508e6f2
...
...
@@ -24,7 +24,7 @@ public interface ISysConfigService
* @param configKey 参数键名
* @return 参数键值
*/
public
Object
selectConfigByKey
(
String
configKey
);
public
String
selectConfigByKey
(
String
configKey
);
/**
* 查询参数配置列表
...
...
ruoyi/src/main/java/com/ruoyi/project/system/service/ISysUserService.java
浏览文件 @
b508e6f2
...
...
@@ -154,4 +154,14 @@ public interface ISysUserService
* @return 结果
*/
public
int
deleteUserByIds
(
Long
[]
userIds
);
/**
* 导入用户数据
*
* @param userList 用户数据列表
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
* @param operName 操作用户
* @return 结果
*/
public
String
importUser
(
List
<
SysUser
>
userList
,
Boolean
isUpdateSupport
,
String
operName
);
}
ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysConfigServiceImpl.java
浏览文件 @
b508e6f2
...
...
@@ -41,7 +41,7 @@ public class SysConfigServiceImpl implements ISysConfigService
* @return 参数键值
*/
@Override
public
Object
selectConfigByKey
(
String
configKey
)
public
String
selectConfigByKey
(
String
configKey
)
{
SysConfig
config
=
new
SysConfig
();
config
.
setConfigKey
(
configKey
);
...
...
ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysUserServiceImpl.java
浏览文件 @
b508e6f2
...
...
@@ -2,11 +2,14 @@ package com.ruoyi.project.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
org.springframework.transaction.annotation.Transactional
;
import
com.ruoyi.common.constant.UserConstants
;
import
com.ruoyi.common.exception.CustomException
;
import
com.ruoyi.common.utils.SecurityUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.framework.aspectj.lang.annotation.DataScope
;
import
com.ruoyi.project.system.domain.SysPost
;
...
...
@@ -19,6 +22,7 @@ import com.ruoyi.project.system.mapper.SysRoleMapper;
import
com.ruoyi.project.system.mapper.SysUserMapper
;
import
com.ruoyi.project.system.mapper.SysUserPostMapper
;
import
com.ruoyi.project.system.mapper.SysUserRoleMapper
;
import
com.ruoyi.project.system.service.ISysConfigService
;
import
com.ruoyi.project.system.service.ISysUserService
;
/**
...
...
@@ -29,6 +33,8 @@ import com.ruoyi.project.system.service.ISysUserService;
@Service
public
class
SysUserServiceImpl
implements
ISysUserService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
SysUserServiceImpl
.
class
);
@Autowired
private
SysUserMapper
userMapper
;
...
...
@@ -44,6 +50,9 @@ public class SysUserServiceImpl implements ISysUserService
@Autowired
private
SysUserPostMapper
userPostMapper
;
@Autowired
private
ISysConfigService
configService
;
/**
* 根据条件分页查询用户列表
*
...
...
@@ -375,4 +384,72 @@ public class SysUserServiceImpl implements ISysUserService
}
return
userMapper
.
deleteUserByIds
(
userIds
);
}
/**
* 导入用户数据
*
* @param userList 用户数据列表
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
* @param operName 操作用户
* @return 结果
*/
@Override
public
String
importUser
(
List
<
SysUser
>
userList
,
Boolean
isUpdateSupport
,
String
operName
)
{
if
(
StringUtils
.
isNull
(
userList
)
||
userList
.
size
()
==
0
)
{
throw
new
CustomException
(
"导入用户数据不能为空!"
);
}
int
successNum
=
0
;
int
failureNum
=
0
;
StringBuilder
successMsg
=
new
StringBuilder
();
StringBuilder
failureMsg
=
new
StringBuilder
();
String
password
=
configService
.
selectConfigByKey
(
"sys.user.initPassword"
);
for
(
SysUser
user
:
userList
)
{
try
{
// 验证是否存在这个用户
SysUser
u
=
userMapper
.
selectUserByUserName
(
user
.
getUserName
());
if
(
StringUtils
.
isNull
(
u
))
{
user
.
setPassword
(
SecurityUtils
.
encryptPassword
(
password
));
user
.
setCreateBy
(
operName
);
this
.
insertUser
(
user
);
successNum
++;
successMsg
.
append
(
"<br/>"
+
successNum
+
"、账号 "
+
user
.
getUserName
()
+
" 导入成功"
);
}
else
if
(
isUpdateSupport
)
{
user
.
setUpdateBy
(
operName
);
this
.
updateUser
(
user
);
successNum
++;
successMsg
.
append
(
"<br/>"
+
successNum
+
"、账号 "
+
user
.
getUserName
()
+
" 更新成功"
);
}
else
{
failureNum
++;
failureMsg
.
append
(
"<br/>"
+
failureNum
+
"、账号 "
+
user
.
getUserName
()
+
" 已存在"
);
}
}
catch
(
Exception
e
)
{
failureNum
++;
String
msg
=
"<br/>"
+
failureNum
+
"、账号 "
+
user
.
getUserName
()
+
" 导入失败:"
;
failureMsg
.
append
(
msg
+
e
.
getMessage
());
log
.
error
(
msg
,
e
);
}
}
if
(
failureNum
>
0
)
{
failureMsg
.
insert
(
0
,
"很抱歉,导入失败!共 "
+
failureNum
+
" 条数据格式不正确,错误如下:"
);
throw
new
CustomException
(
failureMsg
.
toString
());
}
else
{
successMsg
.
insert
(
0
,
"恭喜您,数据已全部导入成功!共 "
+
successNum
+
" 条,数据如下:"
);
}
return
successMsg
.
toString
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论