明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_backend
Project
Project
Details
Activity
Releases
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
zengfanpei
jt_backend
Commits
50497a8a
Commit
50497a8a
authored
Mar 13, 2026
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
d277e9b0
Pipeline
#108298
passed with stage
in 3 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
57 deletions
+59
-57
userController.js
controller/userController.js
+59
-57
No files found.
controller/userController.js
View file @
50497a8a
...
...
@@ -3,7 +3,7 @@ const _ = require('lodash');
const
CryptoJS
=
require
(
'crypto-js'
);
const
{
Op
}
=
require
(
'sequelize'
);
const
userModule
=
require
(
'../module/userModule'
);
const
errorMessage
=
require
(
'../utils/errorMessage'
);
async
function
regist
(
req
,
res
,
next
)
{
...
...
@@ -45,7 +45,7 @@ async function login(req, res, next) {
// attributes: ['id', 'name', 'parentId'],
through
:
{
attributes
:
[]
},
}]
},
},
{
model
:
DB
.
Depart
,
as
:
'departs'
,
...
...
@@ -85,7 +85,7 @@ async function login(req, res, next) {
delete
element
.
menus
;
newRoles
.
push
(
element
);
}
menus
=
_
.
filter
(
_
.
uniqBy
(
menus
,
'id'
),
(
o
)
=>
{
return
o
.
del
==
0
});
menus
=
_
.
filter
(
_
.
uniqBy
(
menus
,
'id'
),
(
o
)
=>
{
return
o
.
del
==
0
});
user
.
roles
=
newRoles
||
[];
// let allMenus = await DB.Menu.findAll({where: {del: 0}, raw: true});
user
.
menus
=
utils
.
buildTree
(
menus
);
...
...
@@ -112,17 +112,17 @@ async function getUserRoleMenuList(req, res, next) {
// attributes: ['id', 'name', 'parentId'],
through
:
{
attributes
:
[]
},
}]
},
// {
// model: DB.Depart,
// as: 'departs',
// // where: { del: 0 }, 当刚注册的用户 没有分配角色、部门时加上条件会查不到
// attributes: ["id", "name"],
// through: { attributes: [] },
// }
},
// {
// model: DB.Depart,
// as: 'departs',
// // where: { del: 0 }, 当刚注册的用户 没有分配角色、部门时加上条件会查不到
// attributes: ["id", "name"],
// through: { attributes: [] },
// }
]
});
if
(
!
user
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
...
...
@@ -137,7 +137,7 @@ async function getUserRoleMenuList(req, res, next) {
delete
element
.
menus
;
newRoles
.
push
(
element
);
}
let
allMenus
=
await
DB
.
Menu
.
findAll
({
where
:
{
del
:
0
},
raw
:
true
});
let
allMenus
=
await
DB
.
Menu
.
findAll
({
where
:
{
del
:
0
},
raw
:
true
});
let
newMenus
=
utils
.
buildTree
(
allMenus
);
return
res
.
sendData
({
menus
:
newMenus
,
...
...
@@ -160,13 +160,13 @@ async function createUser(req, res, next) {
body
.
salt
=
salt
;
body
.
password
=
passwordHash
;
const
checkMobile
=
await
DB
.
User
.
findOne
({
where
:
{
mobile
:
body
.
mobile
,
del
:
0
}
});
if
(
checkMobile
)
{
return
res
.
sendError
(
errorMessage
.
mobileDuplicate
)
where
:
{
mobile
:
body
.
mobile
,
del
:
0
}
});
if
(
checkMobile
)
{
return
res
.
sendError
(
errorMessage
.
mobileDuplicate
)
}
const
ret
=
await
DB
.
User
.
create
(
body
);
if
(
!
(
ret
&&
ret
.
id
))
{
...
...
@@ -204,22 +204,22 @@ async function getUserInfo(req, res, next) {
// raw: true,
attributes
:
{
exclude
:
[
'password'
,
'salt'
]
},
include
:
[
{
model
:
DB
.
Role
,
as
:
'roles'
,
// where: { del: 0 },
// attributes: ['id']
},
{
{
model
:
DB
.
Role
,
as
:
'roles'
,
// where: { del: 0 },
// attributes: ['id']
},
{
model
:
DB
.
Depart
,
as
:
'departs'
,
// attributes: ["id"],
// through: { attributes: [] },
},
{
model
:
DB
.
Position
,
as
:
'positions'
,
// attributes: ["id"],
// through: { attributes: [] },
}
},
{
model
:
DB
.
Position
,
as
:
'positions'
,
// attributes: ["id"],
// through: { attributes: [] },
}
]
});
return
res
.
sendData
(
ret
);
...
...
@@ -265,7 +265,7 @@ async function updateUser(req, res, next) {
const
departIds
=
body
.
departs
.
map
(
o
=>
{
return
o
&&
o
.
id
||
o
});
console
.
log
(
departIds
,
"=================="
)
await
userModule
.
setUserDepart
(
user
.
id
,
departIds
,
user
.
departs
||
[]);
console
.
log
(
'user.departs'
,
user
.
departs
);
console
.
log
(
'user.departs'
,
user
.
departs
);
delete
body
.
departs
;
}
if
(
body
.
roles
&&
body
.
roles
.
length
)
{
...
...
@@ -277,14 +277,16 @@ async function updateUser(req, res, next) {
if
(
body
.
positions
&&
body
.
positions
.
length
)
{
//跟现有情况对比 确定增删关系
const
positionIds
=
body
.
positions
.
map
(
o
=>
{
return
o
&&
o
.
id
||
o
});
await
userModule
.
setUserPosition
(
user
.
id
,
positionIds
,
user
.
positions
||
[]);
await
userModule
.
setUserPosition
(
user
.
id
,
positionIds
,
user
.
positions
||
[]);
delete
body
.
roles
;
}
//
if
(
user
.
mobile
!=
req
.
body
.
mobile
)
{
let
mt
=
await
DB
.
User
.
findOne
({
where
:
{
mobile
:
req
.
body
.
mobile
,
del
:
0
}});
if
(
mt
)
{
return
res
.
sendError
(
errorMessage
.
mobileDuplicate
)
if
(
req
.
body
.
mobile
)
{
if
(
user
.
mobile
!=
req
.
body
.
mobile
)
{
let
mt
=
await
DB
.
User
.
findOne
({
where
:
{
mobile
:
req
.
body
.
mobile
,
del
:
0
}
});
if
(
mt
)
{
return
res
.
sendError
(
errorMessage
.
mobileDuplicate
)
}
}
}
const
ret
=
await
DB
.
User
.
update
(
body
,
{
where
:
{
id
:
body
.
id
}
});
...
...
@@ -305,8 +307,8 @@ async function listUser(req, res, next) {
if
(
req
.
body
.
name
)
{
search
.
where
=
{
[
Op
.
or
]:
[
{
name
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
name
}
%`
}
},
{
mobile
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
mobile
}
%`
}
}
{
name
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
name
}
%`
}
},
{
mobile
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
mobile
}
%`
}
}
],
del
:
0
}
...
...
@@ -314,22 +316,22 @@ async function listUser(req, res, next) {
search
.
limit
=
limit
;
search
.
offset
=
offset
;
search
.
include
=
[
{
model
:
DB
.
Role
,
as
:
'roles'
,
through
:
{
attributes
:
[]
},
},
{
model
:
DB
.
Depart
,
as
:
'departs'
,
through
:
{
attributes
:
[]
},
},
{
model
:
DB
.
Position
,
as
:
'positions'
,
through
:
{
attributes
:
[]
},
}
{
model
:
DB
.
Role
,
as
:
'roles'
,
through
:
{
attributes
:
[]
},
},
{
model
:
DB
.
Depart
,
as
:
'departs'
,
through
:
{
attributes
:
[]
},
},
{
model
:
DB
.
Position
,
as
:
'positions'
,
through
:
{
attributes
:
[]
},
}
];
search
.
distinct
=
true
,
// ✅ 关键:去重
search
.
col
=
'id'
search
.
col
=
'id'
search
.
attributes
=
req
.
body
.
attributes
||
{
exclude
:
[
'password'
,
'salt'
]
};
let
ret
=
await
DB
.
User
.
findAndCountAll
(
search
);
return
res
.
sendData
(
ret
);
...
...
@@ -352,11 +354,11 @@ async function deleteUser(req, res, next) {
}
const
ret
=
await
DB
.
User
.
update
({
del
:
1
},
{
where
:
search
});
//删除标记
//删除用户与角色绑定
await
DB
.
UserRole
.
destroy
({
where
:
{
userId
:
req
.
body
.
id
}
});
await
DB
.
UserRole
.
destroy
({
where
:
{
userId
:
req
.
body
.
id
}
});
//删除用户与部门绑定
await
DB
.
UserDepart
.
destroy
({
where
:
{
userId
:
req
.
body
.
id
}
});
await
DB
.
UserDepart
.
destroy
({
where
:
{
userId
:
req
.
body
.
id
}
});
//删除用户与岗位绑定
await
DB
.
UserPosition
.
destroy
({
where
:
{
userId
:
req
.
body
.
id
}
});
await
DB
.
UserPosition
.
destroy
({
where
:
{
userId
:
req
.
body
.
id
}
});
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
...
...
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