Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
ea8dfdd3
Commit
ea8dfdd3
authored
Dec 02, 2019
by
孙亚楠
Browse files
Options
Browse Files
Download
Plain Diff
修改user查询接口
parents
2514986a
784c8438
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
408 additions
and
108 deletions
+408
-108
xggsve-uc/app/base/api/impl/op/action.js
+36
-18
xggsve-uc/app/base/db/impl/auth/authDao.js
+33
-2
xggsve-uc/app/base/db/impl/org/orgDao.js
+13
-4
xggsve-uc/app/base/db/impl/role/roleauthDao.js
+8
-0
xggsve-uc/app/base/db/impl/user/userDao.js
+47
-14
xggsve-uc/app/base/db/impl/user/userinfoDao.js
+3
-0
xggsve-uc/app/base/db/impl/user/userroleDao.js
+16
-2
xggsve-uc/app/base/db/models/role/roleauth.js
+1
-1
xggsve-uc/app/base/db/models/user/userrole.js
+1
-1
xggsve-uc/app/base/service/impl/auth/authSve.js
+33
-6
xggsve-uc/app/base/service/impl/org/orgSve.js
+68
-43
xggsve-uc/app/base/service/impl/role/roleSve.js
+28
-1
xggsve-uc/app/base/service/impl/user/userSve.js
+120
-16
xggsve-uc/app/base/service/sve.base.js
+1
-0
No files found.
xggsve-uc/app/base/api/impl/op/action.js
View file @
ea8dfdd3
...
...
@@ -9,7 +9,6 @@ class ActionAPI extends APIBase {
this
.
userSve
=
system
.
getObject
(
"service.user.userSve"
);
this
.
roleSve
=
system
.
getObject
(
"service.role.roleSve"
);
this
.
authSve
=
system
.
getObject
(
"service.auth.authSve"
);
}
/**
...
...
@@ -76,14 +75,14 @@ class ActionAPI extends APIBase {
case
"findById"
:
opResult
=
await
this
.
orgSve
.
apiFindById
(
action_body
);
break
;
case
"
b
yPid"
:
case
"
orgB
yPid"
:
opResult
=
await
this
.
orgSve
.
apiByPid
(
action_body
);
break
;
case
"orgTree"
:
opResult
=
await
this
.
orgSve
.
apiTree
();
opResult
=
await
this
.
orgSve
.
apiTree
(
action_body
);
break
;
// 菜单权限
// 菜单权限
case
"addAuth"
:
opResult
=
this
.
authSve
.
add
(
action_body
);
break
;
...
...
@@ -96,7 +95,7 @@ class ActionAPI extends APIBase {
case
"authInfo"
:
opResult
=
this
.
authSve
.
info
(
action_body
);
break
;
case
"
b
yPid"
:
case
"
authB
yPid"
:
opResult
=
this
.
authSve
.
byPid
(
action_body
);
break
;
case
"delAuth"
:
...
...
@@ -118,33 +117,52 @@ class ActionAPI extends APIBase {
opResult
=
await
this
.
roleSve
.
apiListRole
(
action_body
);
break
;
case
"roleQueryById"
:
opResult
=
await
this
.
roleSve
.
apiQueryById
(
action_body
);
opResult
=
await
this
.
roleSve
.
apiQueryById
(
action_body
);
break
;
case
"setAuth"
:
opResult
=
await
this
.
roleSve
.
setAuth
(
action_body
);
break
;
// 用户
// 用户
case
"addUser"
:
action_body
.
org
=
await
this
.
orgSve
.
findById
(
Number
(
action_body
.
org_id
));
if
(
!
action_body
.
org
)
{
opResult
=
system
.
getResult
(
null
,
`组织机构不存在`
);
}
else
{
opResult
=
this
.
userSve
.
add
(
action_body
);
if
(
action_body
.
uctype
===
1
)
{
action_body
.
org
=
await
this
.
orgSve
.
findById
(
Number
(
action_body
.
org_id
));
if
(
!
action_body
.
org
)
{
return
system
.
getResult
(
null
,
`组织机构不存在`
);
}
}
opResult
=
this
.
userSve
.
add
(
action_body
);
break
;
case
"updUser"
:
action_body
.
org
=
await
this
.
orgSve
.
findById
(
Number
(
action_body
.
org_id
));
if
(
!
action_body
.
org
)
{
opResult
=
system
.
getResult
(
null
,
`当前SAAS不能删除`
);
}
else
{
opResult
=
this
.
userSve
.
upd
(
action_body
);
if
(
action_body
.
uctype
===
1
)
{
action_body
.
org
=
await
this
.
orgSve
.
findById
(
Number
(
action_body
.
org_id
));
if
(
!
action_body
.
org
)
{
return
system
.
getResult
(
null
,
`组织机构不存在`
);
}
}
opResult
=
this
.
userSve
.
upd
(
action_body
);
break
;
case
"userInfo"
:
opResult
=
this
.
userSve
.
info
(
action_body
);
break
;
case
"enabled"
:
opResult
=
this
.
userSve
.
enabled
(
action_body
);
break
;
case
"delUser"
:
opResult
=
this
.
userSve
.
delUser
(
action_body
);
break
;
case
"
listUser
"
:
case
"
userPage
"
:
opResult
=
this
.
userSve
.
pageByCondition
(
action_body
);
break
;
case
"updPassword"
:
opResult
=
this
.
userSve
.
updPassword
(
action_body
);
break
;
case
"login"
:
opResult
=
this
.
userSve
.
login
(
action_body
);
break
;
case
"loginByUcid"
:
opResult
=
this
.
userSve
.
loginByUcid
(
action_body
);
break
;
}
return
opResult
;
}
...
...
xggsve-uc/app/base/db/impl/auth/authDao.js
View file @
ea8dfdd3
...
...
@@ -5,8 +5,38 @@ class AuthDao extends Dao {
super
(
Dao
.
getModelName
(
AuthDao
));
}
async
all
()
{
return
this
.
customQuery
(
"SELECT * FROM uc_auth WHERE deleted_at IS NULL"
);
async
all
(
saas_id
,
attrs
)
{
attrs
=
attrs
||
"*"
;
var
sql
=
[];
sql
.
push
(
"SELECT"
);
sql
.
push
(
attrs
);
sql
.
push
(
"FROM uc_auth"
);
sql
.
push
(
"WHERE deleted_at IS NULL"
);
var
params
=
{};
if
(
saas_id
)
{
sql
.
push
(
"AND saas_id = :saas_id"
);
params
.
saas_id
=
saas_id
;
}
return
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
}
async
byRoleIds
(
params
)
{
if
(
!
params
.
roleIds
||
params
.
roleIds
.
length
==
0
)
{
return
[];
}
var
sql
=
[];
sql
.
push
(
"SELECT"
);
sql
.
push
(
"t1.id, t1.`pid`, t1.`name`, t1.`icon`, t1.`path`"
);
sql
.
push
(
"FROM uc_auth t1"
);
sql
.
push
(
"INNER JOIN `uc_role_auth` t2 ON t1.`id` = t2.`auth_id`"
);
sql
.
push
(
"WHERE t2.`role_id` IN (:roleIds)"
);
if
(
params
.
menuType
)
{
sql
.
push
(
"AND t1.menuType = :menuType"
);
}
if
(
params
.
saas_id
)
{
sql
.
push
(
"AND t1.saas_id = :saas_id"
);
}
return
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
}
}
module
.
exports
=
AuthDao
;
\ No newline at end of file
xggsve-uc/app/base/db/impl/org/orgDao.js
View file @
ea8dfdd3
...
...
@@ -20,10 +20,20 @@ class OrgDao extends Dao {
return
await
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
}
async
all
()
{
return
this
.
customQuery
(
"SELECT * FROM uc_org WHERE deleted_at IS NULL"
);
async
all
(
saas_id
,
attrs
)
{
attrs
=
attrs
||
"*"
;
var
sql
=
[];
sql
.
push
(
"SELECT"
);
sql
.
push
(
attrs
);
sql
.
push
(
"FROM uc_org"
);
sql
.
push
(
"WHERE deleted_at IS NULL"
);
var
params
=
{};
if
(
saas_id
)
{
sql
.
push
(
"AND saas_id = :saas_id"
);
params
.
saas_id
=
saas_id
;
}
return
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
}
}
module
.
exports
=
OrgDao
;
\ No newline at end of file
xggsve-uc/app/base/db/impl/role/roleauthDao.js
View file @
ea8dfdd3
...
...
@@ -4,5 +4,12 @@ class RoleauthDao extends Dao {
constructor
()
{
super
(
Dao
.
getModelName
(
RoleauthDao
));
}
async
delByRoleId
(
role_id
,
t
)
{
var
sql
=
"DELETE FROM uc_role_auth WHERE role_id = :role_id"
;
await
this
.
customUpdate
(
sql
,
{
role_id
:
role_id
},
t
)
||
[];
}
}
module
.
exports
=
RoleauthDao
;
\ No newline at end of file
xggsve-uc/app/base/db/impl/user/userDao.js
View file @
ea8dfdd3
...
...
@@ -32,13 +32,37 @@ class UserDao extends Dao {
return
await
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
}
async
getByUcname
(
ucname
)
{
var
sql
=
"SELECT * FROM uc_user WHERE ucname = :ucname AND deleted_at IS NULL"
;
var
list
=
await
this
.
customQuery
(
sql
,
{
ucname
:
ucname
,
});
if
(
!
list
||
list
.
length
==
0
)
{
return
null
;
}
return
list
[
0
];
}
async
getByUcid
(
ucid
)
{
var
sql
=
"SELECT * FROM uc_user WHERE ucid = :ucid AND deleted_at IS NULL"
;
var
list
=
await
this
.
customQuery
(
sql
,
{
ucid
:
ucid
});
if
(
!
list
||
list
.
length
==
0
)
{
return
null
;
}
return
list
[
0
];
}
async
countByCondition
(
params
)
{
var
sql
=
[];
sql
.
push
(
"SELECT"
);
sql
.
push
(
"count(1) as num"
);
sql
.
push
(
"FROM uc_user t1"
);
sql
.
push
(
"INNER JOIN uc_user_info t2 ON t1.id = t2.id"
);
sql
.
push
(
"WHERE 1 = 1"
);
sql
.
push
(
"WHERE t1.deleted_at IS NULL"
);
this
.
setCondition
(
sql
,
params
);
var
list
=
await
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
if
(
!
list
||
list
.
length
==
0
)
{
...
...
@@ -58,7 +82,7 @@ class UserDao extends Dao {
sql
.
push
(
"t2.mobile, t2.realName"
);
sql
.
push
(
"FROM uc_user t1"
);
sql
.
push
(
"INNER JOIN uc_user_info t2 ON t1.id = t2.id"
);
sql
.
push
(
"WHERE
1 = 1
"
);
sql
.
push
(
"WHERE
t1.deleted_at IS NULL
"
);
this
.
setCondition
(
sql
,
params
);
...
...
@@ -67,37 +91,45 @@ class UserDao extends Dao {
return
await
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
}
setCondition
(
params
,
sql
)
{
setCondition
(
sql
,
params
)
{
if
(
!
params
||
!
sql
)
{
return
;
}
if
(
params
.
saas_id
)
{
if
(
params
.
saas_id
)
{
sql
.
push
(
"AND t1.saas_id = :saas_id"
);
}
if
(
params
.
ucnameLik
e
)
{
sql
.
push
(
"AND t1.ucname LIKE :ucname
Like
"
);
if
(
params
.
ucnam
e
)
{
sql
.
push
(
"AND t1.ucname LIKE :ucname"
);
}
if
(
params
.
mobileLik
e
)
{
sql
.
push
(
"AND t2.mobile LIKE :mobile
Like
"
);
if
(
params
.
mobil
e
)
{
sql
.
push
(
"AND t2.mobile LIKE :mobile"
);
}
if
(
params
.
realNameLik
e
)
{
sql
.
push
(
"AND t2.realName LIKE :realName
Like
"
);
if
(
params
.
realNam
e
)
{
sql
.
push
(
"AND t2.realName LIKE :realName"
);
}
if
(
params
.
uctype
)
{
if
(
params
.
uctype
)
{
sql
.
push
(
"AND t1.uctype LIKE :uctype"
);
}
if
(
params
.
createBegin
)
{
if
(
params
.
createBegin
)
{
sql
.
push
(
"AND t1.created_at >= :createBegin"
);
}
if
(
params
.
createEnd
)
{
if
(
params
.
createEnd
)
{
sql
.
push
(
"AND t1.created_at <= :createEnd"
);
}
if
(
params
.
isEnabled
===
0
||
params
.
isEnabled
===
1
)
{
sql
.
push
(
"AND t1.isEnabled = :isEnabled"
);
}
if
(
params
.
orgpath
)
{
sql
.
push
(
"AND t1.orgpath LIKE :orgpath"
);
}
}
}
module
.
exports
=
UserDao
;
\ No newline at end of file
xggsve-uc/app/base/db/impl/user/userinfoDao.js
View file @
ea8dfdd3
...
...
@@ -4,5 +4,7 @@ class UserinfoDao extends Dao {
constructor
()
{
super
(
Dao
.
getModelName
(
UserinfoDao
));
}
}
module
.
exports
=
UserinfoDao
;
\ No newline at end of file
xggsve-uc/app/base/db/impl/user/userroleDao.js
View file @
ea8dfdd3
...
...
@@ -12,11 +12,24 @@ class UserroleDao extends Dao {
},
t
)
||
[];
}
async
listByUserId
(
user_id
,
t
)
{
var
sql
=
"SELECT * FROM uc_user_role WHERE user_id = :user_id"
;
async
listByUserId
(
user_id
,
attrs
,
t
)
{
attrs
=
attrs
||
"*"
;
var
sql
=
"SELECT "
+
attrs
+
" FROM uc_user_role WHERE user_id = :user_id"
;
return
await
this
.
customQuery
(
sql
,
{
user_id
:
user_id
},
t
)
||
[];
}
async
findUserRoles
(
user_id
)
{
var
sql
=
[];
sql
.
push
(
"SELECT"
);
sql
.
push
(
"t2.`id`, t2.`code`, t2.`name`"
);
sql
.
push
(
"FROM uc_user_role t1"
)
sql
.
push
(
"INNER JOIN uc_role t2 ON t1.`role_id` = t2.`id`"
);
sql
.
push
(
"WHERE t1.`user_id` = :user_id"
);
return
await
this
.
customQuery
(
sql
.
join
(
" "
),
{
user_id
:
user_id
})
||
[];
}
}
module
.
exports
=
UserroleDao
;
\ No newline at end of file
xggsve-uc/app/base/db/models/role/roleauth.js
View file @
ea8dfdd3
...
...
@@ -3,7 +3,7 @@ const settings = require("../../../../config/settings");
const
uiconfig
=
system
.
getUiConfig2
(
settings
.
appKey
);
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"roleauth"
,
{
user
_id
:
DataTypes
.
INTEGER
,
role
_id
:
DataTypes
.
INTEGER
,
auth_id
:
DataTypes
.
INTEGER
,
},
{
paranoid
:
true
,
//假的删除
...
...
xggsve-uc/app/base/db/models/user/userrole.js
View file @
ea8dfdd3
...
...
@@ -4,7 +4,7 @@ const uiconfig = system.getUiConfig2(settings.appKey);
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"userrole"
,
{
user_id
:
DataTypes
.
INTEGER
,
org
_id
:
DataTypes
.
INTEGER
,
role
_id
:
DataTypes
.
INTEGER
,
},
{
paranoid
:
true
,
//假的删除
underscored
:
true
,
...
...
xggsve-uc/app/base/service/impl/auth/authSve.js
View file @
ea8dfdd3
...
...
@@ -12,7 +12,7 @@ class AuthService extends ServiceBase {
var
pid
=
Number
(
obj
.
pid
||
0
);
if
(
!
saas_id
)
{
return
system
.
getResult
(
null
,
"
请指定saas_id
"
);
return
system
.
getResult
(
null
,
"
saas_id不存在
"
);
}
if
(
pid
===
0
)
{
...
...
@@ -47,7 +47,7 @@ class AuthService extends ServiceBase {
}
var
auth
=
await
this
.
findById
(
id
);
if
(
!
saas_id
)
{
return
system
.
getResult
(
null
,
"
请指定saas_id
"
);
return
system
.
getResult
(
null
,
"
saas_id不存在
"
);
}
if
(
saas_id
!=
auth
.
saas_id
)
{
...
...
@@ -68,11 +68,11 @@ class AuthService extends ServiceBase {
var
list
=
await
this
.
dao
.
findAll
({
pid
:
obj
.
pid
||
0
,
});
return
list
;
return
system
.
getResultSuccess
(
list
)
;
}
async
tree
()
{
var
all
=
await
this
.
dao
.
all
();
async
tree
(
params
)
{
var
all
=
await
this
.
dao
.
all
(
params
.
saas_id
,
"id, orgname, path, pid"
);
var
pmap
=
{};
for
(
var
item
of
all
)
{
...
...
@@ -88,8 +88,35 @@ class AuthService extends ServiceBase {
for
(
var
item
of
all
)
{
item
.
children
=
pmap
[
item
.
id
]
||
[];
}
return
system
.
getResultSuccess
(
pmap
[
0
][
0
]);
}
async
byRoleIds
(
params
)
{
return
await
this
.
dao
.
byRoleIds
(
params
);
}
async
menuByRoleIds
(
params
)
{
params
.
menuType
=
1
;
var
all
=
await
this
.
byRoleIds
(
params
);
var
pmap
=
{};
for
(
var
item
of
all
)
{
var
list
=
pmap
[
item
.
pid
];
if
(
!
list
)
{
list
=
[];
}
list
.
push
(
item
);
pmap
[
item
.
pid
]
=
list
;
}
for
(
var
item
of
all
)
{
item
.
childs
=
pmap
[
item
.
id
]
||
[];
}
return
system
.
getResultSuccess
(
pmap
[
0
][
0
]);
}
return
system
.
getResultSuccess
(
pmap
[
0
]);
async
authByRoleIds
(
params
)
{
params
.
menuType
=
2
;
return
await
this
.
byRoleIds
(
params
);
}
async
info
(
obj
)
{
...
...
xggsve-uc/app/base/service/impl/org/orgSve.js
View file @
ea8dfdd3
...
...
@@ -55,7 +55,7 @@ class OrgService extends ServiceBase {
/**
* 根据ID查询该组织机构下的所有用户
*/
async
apiFindUserByOrgId
(
params
){
async
apiFindUserByOrgId
(
params
)
{
try
{
return
this
.
findUserByOrgId
(
params
.
id
);
}
catch
(
error
)
{
...
...
@@ -67,11 +67,11 @@ class OrgService extends ServiceBase {
* 根据ID查明细
* @param {*} params
*/
async
apiQueryById
(
params
){
async
apiQueryById
(
params
)
{
try
{
return
await
this
.
queryById
(
params
)
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
...
...
@@ -79,11 +79,11 @@ class OrgService extends ServiceBase {
* 根据Ip查明细
* @param {*} params
*/
async
apiByPid
(
params
){
async
apiByPid
(
params
)
{
try
{
return
await
this
.
byPid
(
params
)
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
...
...
@@ -91,11 +91,11 @@ class OrgService extends ServiceBase {
* 根据ID查明细
* @param {*} params
*/
async
apiTree
(
params
){
async
apiTree
(
params
)
{
try
{
return
await
this
.
tree
(
params
)
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
...
...
@@ -110,26 +110,50 @@ class OrgService extends ServiceBase {
try
{
var
pid
=
Number
(
params
.
pid
||
0
);
params
.
orgname
=
this
.
trim
(
params
.
orgname
);
if
(
!
params
.
orgname
){
return
system
.
getResult
(
-
1
,
`参数错误 组织名称不能为空`
)}
let
_orgByName
=
await
this
.
findOne
({
orgname
:
params
.
orgname
});
if
(
_orgByName
){
return
system
.
getResult
(
-
1
,
`参数错误 组织名称已经存在`
);
params
.
saas_id
=
Number
(
params
.
saas_id
||
0
);
if
(
!
params
.
saas_id
)
{
return
system
.
getResult
(
-
1
,
`saas_id不存在`
)
}
if
(
!
params
.
orgname
)
{
return
system
.
getResult
(
-
1
,
`参数错误 组织名称不能为空`
)
}
let
_orgByName
=
await
this
.
findOne
({
orgname
:
params
.
orgname
,
saas_id
:
params
.
saas_id
});
if
(
_orgByName
)
{
return
system
.
getResult
(
-
1
,
`参数错误 组织名称已经存在`
);
}
let
path
=
""
;
if
(
pid
===
0
){
if
(
pid
===
0
)
{
// 验证是否存在其他权限
var
exist
=
await
this
.
findCount
({
where
:
{
saas_id
:
saas_id
}
});
if
(
exist
)
{
return
system
.
getResult
(
null
,
"菜单根目录已经存在"
);
}
path
=
`/
${
params
.
orgname
}
`
;
}
else
{
let
_org
=
await
this
.
findOne
({
id
:
pid
});
if
(
!
_org
){
return
system
.
getResult
(
-
1
,
`参数错误 父节点不存在`
);
}
else
{
let
_org
=
await
this
.
findOne
({
id
:
pid
});
if
(
!
_org
)
{
return
system
.
getResult
(
-
1
,
`参数错误 父节点不存在`
);
}
path
=
`
${
_org
.
path
}
/
${
params
.
orgname
}
`
;
path
=
`
${
_org
.
path
}
/
${
params
.
orgname
}
`
;
}
params
.
path
=
path
;
params
.
path
=
path
;
let
res
=
await
this
.
dao
.
create
(
params
);
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
...
...
@@ -167,20 +191,20 @@ class OrgService extends ServiceBase {
}
//检查组织机构下是否有用户
let
_usersRes
=
await
this
.
findUserByOrgId
(
params
.
id
);
if
(
_usersRes
.
status
===-
1
)
{
if
(
_usersRes
.
status
===
-
1
)
{
return
_usersRes
;
}
if
(
_usersRes
.
data
.
length
!=
0
)
{
return
system
.
getResult
(
-
1
,
`该组织机构不能删除`
);
}
if
(
_usersRes
.
data
.
length
!=
0
)
{
return
system
.
getResult
(
-
1
,
`该组织机构不能删除`
);
}
//检查父节点 下是否有子节点
let
_orgChildren
=
await
this
.
dao
.
model
.
findAll
({
where
:{
pid
:
this
.
trim
(
params
.
id
)
where
:
{
pid
:
this
.
trim
(
params
.
id
)
}
});
if
(
_orgChildren
.
length
!=
0
)
{
return
system
.
getResult
(
-
1
,
`该组织机构不能删除`
);
if
(
_orgChildren
.
length
!=
0
)
{
return
system
.
getResult
(
-
1
,
`该组织机构不能删除`
);
}
//删除
let
res
=
await
_org
.
destroy
();
...
...
@@ -225,8 +249,8 @@ class OrgService extends ServiceBase {
}
}
async
queryById
(
params
){
if
(
!
params
.
id
)
{
async
queryById
(
params
)
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
-
1
,
`参数错误 ID不能为空`
);
}
try
{
...
...
@@ -235,42 +259,42 @@ class OrgService extends ServiceBase {
this
.
handleDate
(
_org
,[
'updated_at'
],
null
,
-
8
);
return
system
.
getResult
(
_org
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 根据ID查询该组织机构下的所有用户
*/
async
findUserByOrgId
(
id
){
if
(
!
Number
(
id
))
{
return
system
.
getResult
(
-
1
,
`参数错误 组织机构不能为空`
);
async
findUserByOrgId
(
id
)
{
if
(
!
Number
(
id
))
{
return
system
.
getResult
(
-
1
,
`参数错误 组织机构不能为空`
);
}
try
{
let
res
=
await
this
.
dao
.
findUserByOrgId
(
id
);
let
res
=
await
this
.
dao
.
findUserByOrgId
(
id
);
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
async
byPid
(
obj
)
{
try
{
var
list
=
await
this
.
dao
.
findAll
({
pid
:
obj
.
pid
||
0
,
});
return
system
.
getResult
(
list
);
return
system
.
getResult
(
list
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* 结构树
*/
async
tree
()
{
async
tree
(
params
)
{
try
{
var
all
=
await
this
.
dao
.
all
();
var
all
=
await
this
.
dao
.
all
(
params
.
saas_id
);
var
pmap
=
{};
for
(
var
item
of
all
)
{
item
.
label
=
item
.
orgname
;
...
...
@@ -286,9 +310,9 @@ class OrgService extends ServiceBase {
}
return
system
.
getResult
(
pmap
[
0
]);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
module
.
exports
=
OrgService
;
\ No newline at end of file
xggsve-uc/app/base/service/impl/role/roleSve.js
View file @
ea8dfdd3
...
...
@@ -3,6 +3,8 @@ const ServiceBase = require("../../sve.base")
class
RoleService
extends
ServiceBase
{
constructor
()
{
super
(
"role"
,
ServiceBase
.
getDaoName
(
RoleService
));
this
.
roleauthDao
=
system
.
getObject
(
"db.role.roleauthDao"
);
}
/**
...
...
@@ -49,7 +51,6 @@ class RoleService extends ServiceBase {
}
}
/**
* role 查询列表
* @param {*} params
...
...
@@ -62,6 +63,32 @@ class RoleService extends ServiceBase {
}
}
async
setAuth
(
params
)
{
var
saas_id
=
Number
(
params
.
saas_id
||
0
);
var
role
=
await
this
.
findById
(
params
.
id
);
var
authIds
=
params
.
authIds
;
if
(
!
role
)
{
return
system
.
getResult
(
null
,
"角色不存在"
);
}
if
(
role
.
saas_id
!==
saas_id
)
{
return
system
.
getResult
(
null
,
"权限不足"
);
}
var
self
=
this
;
// 先删
await
this
.
roleauthDao
.
delByRoleId
(
role
.
id
);
var
list
=
[];
for
(
var
auth_id
of
authIds
)
{
list
.
push
({
auth_id
:
auth_id
,
role_id
:
role
.
id
});
}
// 后存
if
(
list
.
length
>
0
)
{
await
this
.
roleauthDao
.
bulkCreate
(
list
)
}
return
system
.
getResultSuccess
();
}
...
...
xggsve-uc/app/base/service/impl/user/userSve.js
View file @
ea8dfdd3
...
...
@@ -6,6 +6,9 @@ class UserService extends ServiceBase {
super
(
"user"
,
ServiceBase
.
getDaoName
(
UserService
));
this
.
userinfoDao
=
system
.
getObject
(
"db.user.userinfoDao"
);
this
.
userroleDao
=
system
.
getObject
(
"db.user.userroleDao"
);
this
.
authSve
=
system
.
getObject
(
"service.auth.authSve"
);
}
...
...
@@ -21,6 +24,18 @@ class UserService extends ServiceBase {
}
}
/**
* 根据path查询所有的用户
* @param {*} params
*/
async
apiQueryUserByPath
(
params
){
try
{
return
await
this
.
queryUserByPath
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**************************************************************** */
...
...
@@ -37,9 +52,62 @@ class UserService extends ServiceBase {
}
}
async
login
(
obj
)
{
var
user
=
await
this
.
dao
.
getByUcname
(
obj
.
ucname
);
// 验证登录合法
if
(
!
user
)
{
return
system
.
getResult
(
null
,
"用户名或密码错误"
);
}
if
(
!
user
.
isEnabled
)
{
return
system
.
getResult
(
null
,
"用户已禁用"
);
}
var
loginPwd
=
await
this
.
getEncryptStr
(
obj
.
password
);
if
(
loginPwd
!=
user
.
password
)
{
return
system
.
getResult
(
null
,
"用户名或密码错误"
);
}
await
this
.
setLoginUser
(
user
);
return
system
.
getResultSuccess
(
user
);
}
async
loginByUcid
(
obj
)
{
var
user
=
await
this
.
dao
.
getByUcid
(
obj
.
ucid
);
// 验证登录合法
if
(
!
user
)
{
return
system
.
getResult
(
null
,
"用户名或密码错误"
);
}
await
this
.
setLoginUser
(
user
);
return
system
.
getResultSuccess
(
user
);
}
async
setLoginUser
(
user
)
{
// 登录成功,补充登录所需内容
// 详情
user
.
info
=
await
this
.
userinfoDao
.
findById
(
user
.
id
);
// 角色
user
.
roles
=
await
this
.
userroleDao
.
findUserRoles
(
user
.
id
);
// 构建请求权限接口参数
var
roleIds
=
[];
for
(
var
role
of
user
.
roles
)
{
roleIds
.
push
(
role
.
id
);
}
var
authParams
=
{
roleIds
:
roleIds
,
saas_id
:
user
.
saas_id
,
}
// 菜单权限
user
.
menus
=
await
this
.
authSve
.
menuByRoleIds
(
authParams
);
// 接口权限
user
.
auths
=
await
this
.
authSve
.
authByRoleIds
(
authParams
);
}
async
add
(
obj
)
{
var
roles
=
obj
.
roles
||
[];
var
org
=
obj
.
org
;
var
org
=
obj
.
org
||
{}
;
var
saas_id
=
Number
(
obj
.
saas_id
||
0
);
var
ucid
=
this
.
trim
(
obj
.
ucid
);
var
ucname
=
this
.
trim
(
obj
.
ucname
);
...
...
@@ -50,7 +118,7 @@ class UserService extends ServiceBase {
var
isMain
=
obj
.
isMain
||
0
;
if
(
!
saas_id
)
{
return
system
.
getResult
(
null
,
"
请指定saas_id
"
);
return
system
.
getResult
(
null
,
"
saas_id不存在
"
);
}
var
exist
=
await
this
.
findOne
({
...
...
@@ -66,13 +134,13 @@ class UserService extends ServiceBase {
ucname
:
ucname
,
password
:
await
this
.
getEncryptStr
(
password
),
uctype
:
uctype
,
org_id
:
org
.
id
,
org_id
:
org
.
id
||
0
,
isMain
:
isMain
,
orgpath
:
""
,
isEnabled
:
1
,
}
var
orgpath
=
org
.
path
;
var
orgpath
=
org
.
path
||
""
;
var
info
=
{
mobile
:
mobile
,
...
...
@@ -94,14 +162,14 @@ class UserService extends ServiceBase {
await
self
.
userroleDao
.
bulkCreate
(
roles
,
t
);
}
if
(
!
isMain
)
{
orgpath
=
orgpath
+
"/"
+
user
.
id
;
if
(
user
.
uctype
===
1
)
{
orgpath
=
isMain
?
orgpath
:
orgpath
+
"/"
+
user
.
id
;
await
self
.
dao
.
update
({
id
:
user
.
id
,
orgpath
:
orgpath
},
t
);
}
user
.
orgpath
=
orgpath
;
await
self
.
dao
.
update
({
id
:
user
.
id
,
orgpath
:
orgpath
},
t
);
return
user
;
});
...
...
@@ -111,7 +179,7 @@ class UserService extends ServiceBase {
async
upd
(
obj
)
{
var
id
=
obj
.
id
;
var
roles
=
obj
.
roles
||
[];
var
org
=
obj
.
org
;
var
org
=
obj
.
org
||
{}
;
var
uctype
=
this
.
trim
(
obj
.
uctype
);
var
mobile
=
this
.
trim
(
obj
.
mobile
);
var
realName
=
this
.
trim
(
obj
.
realName
);
...
...
@@ -119,11 +187,13 @@ class UserService extends ServiceBase {
var
user
=
{
id
:
id
,
org_id
:
org
.
id
,
orgpath
:
isMain
?
org
.
path
:
org
.
path
+
"/"
+
id
,
org_id
:
org
.
id
||
""
,
orgpath
:
""
,
isMain
:
obj
.
isMain
||
0
,
}
if
(
user
.
uctype
===
1
)
{
user
.
orgpath
=
isMain
?
org
.
path
:
org
.
path
+
"/"
+
id
;
}
var
info
=
{
id
:
id
,
mobile
:
mobile
,
...
...
@@ -159,11 +229,21 @@ class UserService extends ServiceBase {
user
.
mobile
=
info
.
mobile
;
user
.
realName
=
info
.
realName
;
user
.
roles
=
await
this
.
userroleDao
.
listByUserId
(
id
);
user
.
roles
=
await
this
.
userroleDao
.
listByUserId
(
id
,
"user_id, role_id"
);
this
.
handleDate
(
user
,
[
"created_at"
],
null
,
-
8
);
return
system
.
getResultSuccess
(
user
);
}
async
enabled
(
params
)
{
var
user
=
await
this
.
dao
.
findById
(
params
.
id
);
if
(
!
user
)
{
return
system
.
getResult
(
null
,
"用户不存在"
);
}
user
.
isEnabled
=
Number
(
params
.
enabled
||
0
)
==
0
?
false
:
true
;
await
user
.
save
();
return
system
.
getResultSuccess
();
}
async
pageByCondition
(
params
)
{
var
result
=
{
count
:
0
,
...
...
@@ -171,6 +251,9 @@ class UserService extends ServiceBase {
};
var
currentPage
=
Number
(
params
.
currentPage
||
1
);
var
pageSize
=
Number
(
params
.
pageSize
||
10
);
if
(
params
.
orgpath
)
{
params
.
orgpath
=
params
.
orgpath
+
"%"
;
}
var
total
=
await
this
.
dao
.
countByCondition
(
params
);
if
(
total
==
0
)
{
...
...
@@ -180,17 +263,37 @@ class UserService extends ServiceBase {
result
.
count
=
total
;
params
.
startRow
=
(
currentPage
-
1
)
*
pageSize
;
result
.
rows
=
await
this
.
dao
.
listByCondition
(
params
)
||
[];
if
(
result
.
rows
)
{
for
(
var
item
of
result
.
rows
)
{
this
.
handleDate
(
item
,
[
"created_at"
],
null
,
-
8
);
}
}
return
system
.
getResultSuccess
(
result
);
}
async
delUser
(
params
)
{
var
user
=
await
this
.
findById
(
params
.
id
);
if
(
!
user
)
{
return
system
.
getResultSuccess
();
}
if
(
user
.
saas_id
!=
params
.
saas_id
)
{
return
system
.
getResult
(
null
,
"权限不足"
);
}
await
this
.
delete
({
id
:
params
.
id
});
return
system
.
getResultSuccess
();
}
async
updPassword
(
params
)
{
var
user
=
await
this
.
findById
(
params
.
id
);
if
(
!
user
)
{
return
system
.
getResult
(
null
,
"用户不存在"
);
}
user
.
password
=
await
this
.
getEncryptStr
(
params
.
password
);
await
user
.
save
();
return
system
.
getResultSuccess
();
}
}
module
.
exports
=
UserService
;
\ No newline at end of file
xggsve-uc/app/base/service/sve.base.js
View file @
ea8dfdd3
...
...
@@ -274,6 +274,7 @@ class ServiceBase {
}
async
getEncryptStr
(
str
)
{
str
=
this
.
trim
(
str
);
if
(
!
str
)
{
throw
new
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