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
6dd0480e
Commit
6dd0480e
authored
Nov 29, 2019
by
王昆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gsb
parent
78a765c4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
271 additions
and
57 deletions
+271
-57
xggsve-uc/app/base/api/impl/op/action.js
+37
-22
xggsve-uc/app/base/db/dao.base.js
+9
-7
xggsve-uc/app/base/db/impl/user/userDao.js
+76
-8
xggsve-uc/app/base/db/impl/user/userroleDao.js
+15
-0
xggsve-uc/app/base/service/impl/user/userSve.js
+132
-18
xggsve-uc/app/base/service/sve.base.js
+2
-2
No files found.
xggsve-uc/app/base/api/impl/op/action.js
View file @
6dd0480e
...
...
@@ -47,17 +47,17 @@ class ActionAPI extends APIBase {
break
;
case
"delSaas"
:
opResult
=
await
this
.
userSve
.
apiFindUserBySaasId
(
action_body
);
if
(
opResult
.
status
==
0
&&
opResult
.
data
.
length
==
0
)
{
if
(
opResult
.
status
==
0
&&
opResult
.
data
.
length
==
0
)
{
opResult
=
await
this
.
saasSve
.
apiDelSaas
(
action_body
);
}
else
{
opResult
=
system
.
getResult
(
-
1
,
`当前SAAS不能删除`
);
}
else
{
opResult
=
system
.
getResult
(
-
1
,
`当前SAAS不能删除`
);
}
break
;
case
"listSaas"
:
opResult
=
await
this
.
saasSve
.
apiListSaas
(
action_body
);
break
;
// 组织机构
// 组织机构
case
"addOrg"
:
opResult
=
await
this
.
orgSve
.
apiAddOrg
(
action_body
);
break
;
...
...
@@ -65,61 +65,76 @@ class ActionAPI extends APIBase {
opResult
=
await
this
.
orgSve
.
apiUpdOrg
(
action_body
);
break
;
case
"delOrg"
:
opResult
=
await
this
.
orgSve
.
apiDelOrg
(
action_body
);
opResult
=
await
this
.
orgSve
.
apiDelOrg
(
action_body
);
break
;
case
"listOrg"
:
opResult
=
await
this
.
orgSve
.
apiListOrg
(
action_body
);
opResult
=
await
this
.
orgSve
.
apiListOrg
(
action_body
);
break
;
case
"findById"
:
opResult
=
await
this
.
orgSve
.
apiFindById
(
action_body
);
opResult
=
await
this
.
orgSve
.
apiFindById
(
action_body
);
break
;
case
"byPid"
:
opResult
=
await
this
.
orgSve
.
apiByPid
(
action_body
);
opResult
=
await
this
.
orgSve
.
apiByPid
(
action_body
);
break
;
case
"tree"
:
opResult
=
await
this
.
orgSve
.
apiTree
();
opResult
=
await
this
.
orgSve
.
apiTree
();
break
;
// 菜单权限
// 菜单权限
case
"addAuth"
:
return
this
.
authSve
.
add
(
action_body
);
opResult
=
this
.
authSve
.
add
(
action_body
);
break
;
case
"updAuth"
:
return
this
.
authSve
.
upd
(
action_body
);
opResult
=
this
.
authSve
.
upd
(
action_body
);
break
;
case
"tree"
:
return
this
.
authSve
.
tree
(
action_body
);
opResult
=
this
.
authSve
.
tree
(
action_body
);
break
;
case
"byPid"
:
return
this
.
authSve
.
byPid
(
action_body
);
opResult
=
this
.
authSve
.
byPid
(
action_body
);
break
;
case
"delAuth"
:
// TODO 验证是否有角色关联
return
this
.
authSve
.
del
(
action_body
);
opResult
=
this
.
authSve
.
del
(
action_body
);
break
;
// 角色
// 角色
case
"addRole"
:
opResult
=
await
this
.
roleSve
.
apiAddRole
(
action_body
);
opResult
=
await
this
.
roleSve
.
apiAddRole
(
action_body
);
break
;
case
"updRole"
:
opResult
=
await
this
.
roleSve
.
apiUpdRole
(
action_body
);
opResult
=
await
this
.
roleSve
.
apiUpdRole
(
action_body
);
break
;
case
"delRole"
:
opResult
=
await
this
.
roleSve
.
apiDelRole
(
action_body
);
opResult
=
await
this
.
roleSve
.
apiDelRole
(
action_body
);
break
;
case
"listRole"
:
opResult
=
await
this
.
roleSve
.
apiListRole
(
action_body
);
opResult
=
await
this
.
roleSve
.
apiListRole
(
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
);
}
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
);
}
break
;
case
"userInfo"
:
opResult
=
this
.
userSve
.
info
(
action_body
);
break
;
case
"delUser"
:
break
;
case
"listUser"
:
opResult
=
this
.
userSve
.
pageByCondition
(
action_body
);
break
;
}
return
opResult
;
...
...
xggsve-uc/app/base/db/dao.base.js
View file @
6dd0480e
...
...
@@ -32,14 +32,14 @@ class Dao {
}
//批量插入
async
bulkCreate
(
objs
)
{
async
bulkCreate
(
objs
,
t
)
{
if
(
!
objs
||
objs
.
length
==
0
)
{
return
;
}
for
(
var
obj
of
objs
)
{
if
(
!
obj
.
id
)
{
obj
.
id
=
await
this
.
redisClient
.
genrateId
(
this
.
modelName
);
}
if
(
t
)
{
return
await
this
.
model
.
bulkCreate
(
objs
,
{
transaction
:
t
}
);
}
return
await
this
.
model
.
bulkCreate
(
objs
);
}
...
...
@@ -156,8 +156,10 @@ class Dao {
console
.
log
(
qc
);
return
qc
;
}
async
findAll
(
obj
){
return
await
this
.
model
.
findAll
({
where
:
obj
||
{}});
async
findAll
(
obj
)
{
return
await
this
.
model
.
findAll
({
where
:
obj
||
{}
});
}
async
findAndCountAll
(
qobj
,
t
)
{
...
...
xggsve-uc/app/base/db/impl/user/userDao.js
View file @
6dd0480e
...
...
@@ -5,32 +5,99 @@ class UserDao extends Dao {
super
(
Dao
.
getModelName
(
UserDao
));
}
/**
* 条件查询
* @param {} params
*/
async
findUserBySaasId
(
params
){
async
findUserBySaasId
(
params
)
{
let
sql
=
[];
sql
.
push
(
'select ucid,ucname,uctype,saas_id,isEnabled from uc_user where 1 = 1'
);
if
(
params
.
ucid
)
{
if
(
params
.
ucid
)
{
sql
.
push
(
"AND ucid = :ucid"
);
}
if
(
params
.
ucname
)
{
if
(
params
.
ucname
)
{
sql
.
push
(
"AND ucname = :ucname"
);
}
if
(
params
.
uctype
)
{
if
(
params
.
uctype
)
{
sql
.
push
(
"AND uctype = :uctype"
);
}
if
(
params
.
saas_id
)
{
if
(
params
.
saas_id
)
{
sql
.
push
(
"AND saas_id = :saas_id"
);
}
if
(
params
.
isEnabled
)
{
if
(
params
.
isEnabled
)
{
sql
.
push
(
"AND saas_id = :isEnabled"
);
}
sql
.
push
(
`AND (deleted_at > NOW() or deleted_at is null)`
);
return
await
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
}
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"
);
var
list
=
await
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
if
(
!
list
||
list
.
length
==
0
)
{
return
0
;
}
return
list
[
0
].
num
;
}
async
listByCondition
(
params
)
{
params
.
startRow
=
Number
(
params
.
startRow
||
0
);
params
.
pageSize
=
Number
(
params
.
pageSize
||
10
);
var
sql
=
[];
sql
.
push
(
"SELECT"
);
sql
.
push
(
"t1.id, t1.ucid, t1.ucname, t1.uctype, t1.org_id, t1.orgpath,"
);
sql
.
push
(
"t1.isMain, t1.saas_id, t1.isEnabled, t1.created_at,"
);
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"
);
this
.
setCondition
(
sql
,
params
);
sql
.
push
(
"ORDER BY t1.id DESC"
);
sql
.
push
(
"LIMIT :startRow, :pageSize"
);
return
await
this
.
customQuery
(
sql
.
join
(
" "
),
params
);
}
setCondition
(
params
,
sql
)
{
if
(
!
params
||
!
sql
)
{
return
;
}
if
(
params
.
saas_id
)
{
sql
.
push
(
"AND t1.saas_id = :saas_id"
);
}
if
(
params
.
ucnameLike
)
{
sql
.
push
(
"AND t1.ucname LIKE :ucnameLike"
);
}
if
(
params
.
mobileLike
)
{
sql
.
push
(
"AND t2.mobile LIKE :mobileLike"
);
}
if
(
params
.
realNameLike
)
{
sql
.
push
(
"AND t2.realName LIKE :realNameLike"
);
}
if
(
params
.
uctype
)
{
sql
.
push
(
"AND t1.uctype LIKE :uctype"
);
}
if
(
params
.
createBegin
)
{
sql
.
push
(
"AND t1.created_at >= :createBegin"
);
}
if
(
params
.
createEnd
)
{
sql
.
push
(
"AND t1.created_at <= :createEnd"
);
}
}
}
module
.
exports
=
UserDao
;
\ No newline at end of file
xggsve-uc/app/base/db/impl/user/userroleDao.js
View file @
6dd0480e
...
...
@@ -4,5 +4,19 @@ class UserroleDao extends Dao {
constructor
()
{
super
(
Dao
.
getModelName
(
UserroleDao
));
}
async
delByUserId
(
user_id
,
t
)
{
var
sql
=
"DELETE FROM uc_user_role WHERE user_id = :user_id"
;
await
this
.
customUpdate
(
sql
,
{
user_id
:
user_id
},
t
)
||
[];
}
async
listByUserId
(
user_id
,
t
)
{
var
sql
=
"SELECT * FROM uc_user_role WHERE user_id = :user_id"
;
return
await
this
.
customQuery
(
sql
,
{
user_id
:
user_id
},
t
)
||
[];
}
}
module
.
exports
=
UserroleDao
;
\ No newline at end of file
xggsve-uc/app/base/service/impl/user/userSve.js
View file @
6dd0480e
...
...
@@ -4,7 +4,8 @@ const settings = require("../../../../config/settings")
class
UserService
extends
ServiceBase
{
constructor
()
{
super
(
"user"
,
ServiceBase
.
getDaoName
(
UserService
));
this
.
user
this
.
userinfoDao
=
system
.
getObject
(
"db.user.userinfoDao"
);
this
.
userroleDao
=
system
.
getObject
(
"db.user.userroleDao"
);
}
...
...
@@ -12,29 +13,27 @@ class UserService extends ServiceBase {
* 条件查询
* @param {*} params
*/
async
apiFindUserBySaasId
(
params
){
async
apiFindUserBySaasId
(
params
)
{
try
{
return
await
this
.
findUserBySaasId
(
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**************************************************************** */
/**************************************************************** */
/**
* 条件查询
* @param {*} params
*/
async
findUserBySaasId
(
params
){
try
{
async
findUserBySaasId
(
params
)
{
try
{
let
res
=
await
this
.
dao
.
findUserBySaasId
(
params
);
return
system
.
getResult
(
res
);
}
catch
(
error
)
{
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
-
1
,
`系统错误 错误信息
${
error
}
`
);
}
}
...
...
@@ -42,42 +41,156 @@ class UserService extends ServiceBase {
var
roles
=
obj
.
roles
||
[];
var
org
=
obj
.
org
;
var
saas_id
=
Number
(
obj
.
saas_id
||
0
);
var
ucid
=
this
.
trim
(
obj
.
ucid
);
var
ucname
=
this
.
trim
(
obj
.
ucname
);
var
password
=
this
.
trim
(
obj
.
password
);
var
uctype
=
this
.
trim
(
obj
.
uctype
);
var
mobile
=
this
.
trim
(
obj
.
mobile
);
var
realName
=
this
.
trim
(
obj
.
realName
);
var
isMain
=
obj
.
isMain
||
0
;
if
(
!
saas_id
)
{
// TODO 写到这
if
(
!
saas_id
)
{
return
system
.
getResult
(
null
,
"请指定saas_id"
);
}
var
exist
=
await
this
.
findOne
({
ucname
:
ucname
});
if
(
exist
)
{
return
system
.
getResult
(
null
,
`用户名【
${
ucname
}
】已存在`
);
}
var
user
=
{
saas_id
:
saas_id
,
ucid
:
ucid
,
ucname
:
ucname
,
password
:
password
,
password
:
await
this
.
getEncryptStr
(
password
)
,
uctype
:
uctype
,
org_id
:
org
.
id
,
isMain
:
obj
.
isMain
||
0
,
isMain
:
isMain
,
orgpath
:
""
,
password
:
""
,
isEnabled
:
1
,
}
var
orgpath
=
org
.
path
;
var
info
=
{
mobile
:
mobile
,
realName
:
realName
,
}
var
self
=
this
;
await
self
.
db
.
transaction
(
async
function
(
t
)
{
user
=
await
self
.
db
.
transaction
(
async
function
(
t
)
{
// 创建商户
user
=
await
self
.
dao
.
create
(
user
,
t
);
info
.
id
=
user
.
id
;
info
=
await
self
.
userinfoDao
.
create
(
info
,
t
);
if
(
roles
&&
roles
.
length
>
0
)
{
for
(
var
r
of
roles
)
{
r
.
user_id
=
user
.
id
;
}
await
self
.
userroleDao
.
bulkCreate
(
roles
,
t
);
}
if
(
!
isMain
)
{
orgpath
=
orgpath
+
"/"
+
user
.
id
;
}
user
.
orgpath
=
orgpath
;
await
self
.
dao
.
update
({
id
:
user
.
id
,
orgpath
:
orgpath
},
t
);
return
user
;
});
return
system
.
getResultSuccess
(
user
);
}
async
upd
(
obj
)
{
var
id
=
obj
.
id
;
var
roles
=
obj
.
roles
||
[];
var
org
=
obj
.
org
;
var
uctype
=
this
.
trim
(
obj
.
uctype
);
var
mobile
=
this
.
trim
(
obj
.
mobile
);
var
realName
=
this
.
trim
(
obj
.
realName
);
var
isMain
=
obj
.
isMain
||
0
;
var
user
=
{
id
:
id
,
org_id
:
org
.
id
,
orgpath
:
isMain
?
org
.
path
:
org
.
path
+
"/"
+
id
,
isMain
:
obj
.
isMain
||
0
,
}
var
info
=
{
id
:
id
,
mobile
:
mobile
,
realName
:
realName
,
}
var
self
=
this
;
user
=
await
self
.
db
.
transaction
(
async
function
(
t
)
{
// 创建商户
await
self
.
dao
.
update
(
user
,
t
);
await
self
.
userinfoDao
.
update
(
info
,
t
);
await
self
.
userroleDao
.
delByUserId
(
id
,
t
);
if
(
roles
&&
roles
.
length
>
0
)
{
for
(
var
r
of
roles
)
{
r
.
user_id
=
id
;
}
await
self
.
userroleDao
.
bulkCreate
(
roles
,
t
);
}
return
user
;
});
return
system
.
getResultSuccess
(
user
);
}
async
info
(
params
)
{
var
id
=
Number
(
params
.
id
||
0
);
var
user
=
await
this
.
dao
.
getById
(
id
);
if
(
!
user
)
{
return
system
.
getResult
(
null
,
"用户不存在"
);
}
var
info
=
await
this
.
userinfoDao
.
getById
(
id
);
user
.
mobile
=
info
.
mobile
;
user
.
realName
=
info
.
realName
;
user
.
roles
=
await
this
.
userroleDao
.
listByUserId
(
id
);
this
.
handleDate
(
user
,
[
"created_at"
],
null
,
-
8
);
return
system
.
getResultSuccess
(
user
);
}
async
pageByCondition
(
params
)
{
var
result
=
{
count
:
0
,
rows
:
[]
};
var
currentPage
=
Number
(
params
.
currentPage
||
1
);
var
pageSize
=
Number
(
params
.
pageSize
||
10
);
var
total
=
await
this
.
dao
.
countByCondition
(
params
);
if
(
total
==
0
)
{
return
result
;
}
result
.
count
=
total
;
params
.
startRow
=
(
currentPage
-
1
)
*
pageSize
;
result
.
rows
=
await
this
.
dao
.
listByCondition
(
params
)
||
[];
return
system
.
getResultSuccess
(
result
);
}
async
delUser
(
params
)
{
await
this
.
delete
({
id
:
params
.
id
});
return
system
.
getResultSuccess
();
}
}
module
.
exports
=
UserService
;
module
.
exports
=
UserService
;
\ No newline at end of file
xggsve-uc/app/base/service/sve.base.js
View file @
6dd0480e
...
...
@@ -277,8 +277,8 @@ class ServiceBase {
if
(
!
str
)
{
throw
new
Error
(
"字符串不能为空"
);
}
var
md5
=
md5
(
str
+
"_"
+
settings
.
salt
);
return
md5
.
toString
().
toLowerCase
();
var
pwd
=
md5
(
str
+
"_"
+
settings
.
salt
);
return
pwd
.
toString
().
toLowerCase
();
}
}
module
.
exports
=
ServiceBase
;
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