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
b91d5a2c
Commit
b91d5a2c
authored
Jul 24, 2020
by
Sxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add opath
parent
c843cbda
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
82 deletions
+106
-82
center-manage/app/base/controller/ctl.base.js
+9
-1
center-manage/app/base/db/impl/auth/userDao.js
+97
-81
No files found.
center-manage/app/base/controller/ctl.base.js
View file @
b91d5a2c
...
...
@@ -58,6 +58,14 @@ class CtlBase {
bizpath
:
req
.
headers
[
"xbizpath"
],
codename
:
req
.
headers
[
"xcodename"
],
codetitle
:
req
.
headers
[
"xcodetitle"
]
?
decodeURI
(
req
.
headers
[
"xcodetitle"
])
:
''
,
opath
:
req
.
headers
[
'xopath'
],
ptags
:
req
.
headers
[
'xptags'
],
}
//添加组织结构路径,如果是上级,取上级
if
(
req
.
xctx
.
ptags
&&
req
.
xctx
.
ptags
!=
""
)
{
pobj
.
opath
=
req
.
xctx
.
ptags
}
else
{
pobj
.
opath
=
req
.
xctx
.
opath
}
if
(
!
req
.
xctx
.
appkey
)
{
return
[
-
200
,
"请求头缺少应用x-app-key"
]
...
...
@@ -99,7 +107,7 @@ class CtlBase {
}
catch
(
e
)
{
this
.
logClient
.
log
(
pobj
,
req
,
null
,
e
.
stack
)
console
.
log
(
e
.
stack
,
"出现异常,请联系管理员......."
);
return
system
.
getResultFail
(
-
200
,
e
.
message
?
e
.
message
:
"出现异常,请联系管理员"
);
return
system
.
getResultFail
(
-
200
,
e
.
message
?
e
.
message
:
"出现异常,请联系管理员"
);
}
}
}
...
...
center-manage/app/base/db/impl/auth/userDao.js
View file @
b91d5a2c
const
system
=
require
(
"../../../system"
);
const
Dao
=
require
(
"../../dao.base"
);
class
UserDao
extends
Dao
{
constructor
(){
const
system
=
require
(
"../../../system"
);
const
Dao
=
require
(
"../../dao.base"
);
class
UserDao
extends
Dao
{
constructor
()
{
super
(
Dao
.
getModelName
(
UserDao
));
}
async
getAuths
(
userid
){
var
self
=
this
;
async
getAuths
(
userid
)
{
var
self
=
this
;
return
this
.
model
.
findOne
({
where
:{
id
:
userid
},
include
:[{
model
:
self
.
db
.
models
.
account
,
attributes
:[
"id"
,
"isSuper"
,
"referrerOnlyCode"
]},
{
model
:
self
.
db
.
models
.
role
,
as
:
"Roles"
,
attributes
:[
"id"
,
"code"
],
include
:[
{
model
:
self
.
db
.
models
.
product
,
as
:
"Products"
,
attributes
:[
"id"
,
"code"
]}
]},
where
:
{
id
:
userid
},
include
:
[{
model
:
self
.
db
.
models
.
account
,
attributes
:
[
"id"
,
"isSuper"
,
"referrerOnlyCode"
]
},
{
model
:
self
.
db
.
models
.
role
,
as
:
"Roles"
,
attributes
:
[
"id"
,
"code"
],
include
:
[
{
model
:
self
.
db
.
models
.
product
,
as
:
"Products"
,
attributes
:
[
"id"
,
"code"
]
}
]
},
],
});
}
async
getUserByUsername
(
username
,
appkey
,
t
)
{
var
app
=
await
this
.
appDao
.
findOne
(
appkey
);
var
tUser
=
await
this
.
model
.
findOne
({
where
:
{
userName
:
username
,
app_id
:
app
.
id
},
include
:
[{
model
:
this
.
db
.
models
.
app
,
raw
:
true
},
async
getUserByUsername
(
username
,
appkey
,
t
)
{
var
app
=
await
this
.
appDao
.
findOne
(
appkey
);
var
tUser
=
await
this
.
model
.
findOne
({
where
:
{
userName
:
username
,
app_id
:
app
.
id
},
include
:
[{
model
:
this
.
db
.
models
.
app
,
raw
:
true
},
// {model:this.db.models.partnerinfo,attributes:["id","user_id","app_id","userName","applyType","applyName","workPic","tagInfo","mobile","tel","applyProvince","applyCity",
// "applyArea","applyAddr","identityCardPic","identityCard","businessLicensePic","businessLicenseNum","entName","cardNo","realName"]},
{
model
:
this
.
db
.
models
.
account
,
attributes
:[
"id"
,
"isSuper"
,
"referrerOnlyCode"
],
raw
:
true
},
{
model
:
this
.
db
.
models
.
role
,
as
:
"Roles"
,
attributes
:[
"id"
,
"code"
],
include
:[
{
model
:
this
.
db
.
models
.
product
,
as
:
"Products"
,
attributes
:[
"id"
,
"code"
],
raw
:
true
}
]},
]},{
transaction
:
t
});
{
model
:
this
.
db
.
models
.
account
,
attributes
:
[
"id"
,
"isSuper"
,
"referrerOnlyCode"
],
raw
:
true
},
{
model
:
this
.
db
.
models
.
role
,
as
:
"Roles"
,
attributes
:
[
"id"
,
"code"
],
include
:
[
{
model
:
this
.
db
.
models
.
product
,
as
:
"Products"
,
attributes
:
[
"id"
,
"code"
],
raw
:
true
}
]
},
]
},
{
transaction
:
t
});
// if(tUser!=null){
// tUser=tUser.get({plain:true});
// tUser.partnerinfo=await this.partnerinfoDao.model.findOne({where:{onlyCode:tUser.onlyCode},raw:true});
// }
return
tUser
;
}
async
getUserByOpenId
(
popenid
,
appkey
,
t
)
{
var
app
=
await
this
.
appDao
.
findOne
(
appkey
);
var
tUser
=
await
this
.
model
.
findOne
({
where
:{
openId
:
popenid
},
include
:[{
model
:
this
.
db
.
models
.
app
,
raw
:
true
},
async
getUserByOpenId
(
popenid
,
appkey
,
t
)
{
var
app
=
await
this
.
appDao
.
findOne
(
appkey
);
var
tUser
=
await
this
.
model
.
findOne
({
where
:
{
openId
:
popenid
},
include
:
[{
model
:
this
.
db
.
models
.
app
,
raw
:
true
},
// {model:this.db.models.partnerinfo,attributes:["id","user_id","app_id","userName","applyType","applyName","workPic","tagInfo","mobile","tel","applyProvince","applyCity",
// "applyArea","applyAddr","identityCardPic","identityCard","businessLicensePic","businessLicenseNum","entName","cardNo","realName"]},
{
model
:
this
.
db
.
models
.
account
,
attributes
:[
"id"
,
"isSuper"
,
"referrerOnlyCode"
],
raw
:
true
},
{
model
:
this
.
db
.
models
.
role
,
as
:
"Roles"
,
attributes
:[
"id"
,
"code"
],
include
:[
{
model
:
this
.
db
.
models
.
product
,
as
:
"Products"
,
attributes
:[
"id"
,
"code"
],
raw
:
true
}
]},
]},{
transaction
:
t
});
if
(
tUser
!=
null
){
tUser
=
tUser
.
get
({
plain
:
true
});
tUser
.
partnerinfo
=
await
this
.
partnerinfoDao
.
model
.
findOne
({
where
:{
onlyCode
:
tUser
.
onlyCode
},
raw
:
true
});
{
model
:
this
.
db
.
models
.
account
,
attributes
:
[
"id"
,
"isSuper"
,
"referrerOnlyCode"
],
raw
:
true
},
{
model
:
this
.
db
.
models
.
role
,
as
:
"Roles"
,
attributes
:
[
"id"
,
"code"
],
include
:
[
{
model
:
this
.
db
.
models
.
product
,
as
:
"Products"
,
attributes
:
[
"id"
,
"code"
],
raw
:
true
}
]
},
]
},
{
transaction
:
t
});
if
(
tUser
!=
null
)
{
tUser
=
tUser
.
get
({
plain
:
true
});
tUser
.
partnerinfo
=
await
this
.
partnerinfoDao
.
model
.
findOne
({
where
:
{
onlyCode
:
tUser
.
onlyCode
},
raw
:
true
});
}
// console.log("tUser.partnerinfo...................................>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>999sy");
// console.log(tUser);
return
tUser
;
}
async
setAccount
(
user
,
account
,
t
)
{
var
user
=
await
user
.
setAccount
(
account
,{
transaction
:
t
});
async
setAccount
(
user
,
account
,
t
)
{
var
user
=
await
user
.
setAccount
(
account
,
{
transaction
:
t
});
return
user
;
}
async
setApp
(
user
,
app
,
t
)
{
async
setApp
(
user
,
app
,
t
)
{
//按照APPId,获取app对象
var
user
=
await
user
.
setApp
(
app
,{
transaction
:
t
});
var
user
=
await
user
.
setApp
(
app
,
{
transaction
:
t
});
return
user
;
}
extraModelFilter
(){
extraModelFilter
()
{
//return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"],joinTableAttributes:['created_at']}]};
return
{
"key"
:
"include"
,
"value"
:[
return
{
"key"
:
"include"
,
"value"
:
[
// {model:this.db.models.app,},
{
model
:
this
.
db
.
models
.
company
,},
{
model
:
this
.
db
.
models
.
role
,
as
:
"Roles"
,
attributes
:[
"id"
,
"name"
]}]};
}
extraWhere
(
obj
,
w
,
qc
,
linkAttrs
){
if
(
obj
.
bizpath
&&
obj
.
bizpath
!=
""
){
if
(
obj
.
bizpath
.
indexOf
(
"tanents_info"
)
>
0
){
//说明是超级管理员的查询
w
[
"isAdmin"
]
=
true
;
}
else
{
w
[
"isAdmin"
]
=
false
;
w
[
"company_id"
]
=
obj
.
company_id
;
}
}
if
(
linkAttrs
.
length
>
0
){
var
search
=
obj
.
search
;
var
lnkKey
=
linkAttrs
[
0
];
var
strq
=
"$"
+
lnkKey
.
replace
(
"~"
,
"."
)
+
"$"
;
w
[
strq
]
=
{[
this
.
db
.
Op
.
like
]:
"%"
+
search
[
lnkKey
]
+
"%"
};
{
model
:
this
.
db
.
models
.
company
,
},
{
model
:
this
.
db
.
models
.
role
,
as
:
"Roles"
,
attributes
:
[
"id"
,
"name"
]
}]
};
}
extraWhere
(
obj
,
w
,
qc
,
linkAttrs
)
{
console
.
log
(
"----========="
)
console
.
log
(
obj
)
if
(
obj
.
bizpath
&&
obj
.
bizpath
!=
""
)
{
if
(
obj
.
bizpath
.
indexOf
(
"tanents_info"
)
>
0
)
{
//说明是超级管理员的查询
w
[
"isAdmin"
]
=
true
;
}
else
{
w
[
"isAdmin"
]
=
false
;
w
[
"company_id"
]
=
obj
.
company_id
;
// 为空说明是管理员,不需设置组织结构过滤
if
(
obj
.
opath
&&
obj
.
opath
!=
""
)
{
w
[
"opath"
]
=
{
[
this
.
db
.
Op
.
like
]:
`%
${
obj
.
opath
}
%`
}
}
}
}
if
(
linkAttrs
.
length
>
0
)
{
var
search
=
obj
.
search
;
var
lnkKey
=
linkAttrs
[
0
];
var
strq
=
"$"
+
lnkKey
.
replace
(
"~"
,
"."
)
+
"$"
;
w
[
strq
]
=
{
[
this
.
db
.
Op
.
like
]:
"%"
+
search
[
lnkKey
]
+
"%"
};
}
return
w
;
}
async
preUpdate
(
u
){
if
(
u
.
roles
&&
u
.
roles
.
length
>=
0
)
{
var
roles
=
await
this
.
db
.
models
.
role
.
findAll
({
where
:{
id
:{[
this
.
db
.
Op
.
in
]:
u
.
roles
}}
});
u
.
roles
=
roles
async
preUpdate
(
u
)
{
if
(
u
.
roles
&&
u
.
roles
.
length
>=
0
)
{
var
roles
=
await
this
.
db
.
models
.
role
.
findAll
({
where
:
{
id
:
{
[
this
.
db
.
Op
.
in
]:
u
.
roles
}
}
});
u
.
roles
=
roles
}
return
u
;
}
async
update
(
obj
){
var
obj2
=
await
this
.
preUpdate
(
obj
);
await
this
.
model
.
update
(
obj2
,
{
where
:{
id
:
obj2
.
id
}
});
var
user
=
await
this
.
model
.
findOne
({
where
:{
id
:
obj2
.
id
}
});
if
(
obj2
.
roles
)
{
async
update
(
obj
)
{
var
obj2
=
await
this
.
preUpdate
(
obj
);
await
this
.
model
.
update
(
obj2
,
{
where
:
{
id
:
obj2
.
id
}
});
var
user
=
await
this
.
model
.
findOne
({
where
:
{
id
:
obj2
.
id
}
});
if
(
obj2
.
roles
)
{
user
.
setRoles
(
obj2
.
roles
);
}
return
user
;
}
async
findAndCountAll
(
qobj
,
t
)
{
var
users
=
await
super
.
findAndCountAll
(
qobj
,
t
);
async
findAndCountAll
(
qobj
,
t
)
{
var
users
=
await
super
.
findAndCountAll
(
qobj
,
t
);
return
users
;
}
async
preCreate
(
u
){
async
preCreate
(
u
)
{
// var roles=await this.db.models.role.findAll({where:{id:{[this.db.Op.like]:u.roles}}});
// console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// console.log(roles);
...
...
@@ -115,32 +131,32 @@ class UserDao extends Dao{
// u.roles=roles
return
u
;
}
async
create
(
u
,
t
)
{
var
self
=
this
;
var
u2
=
await
this
.
preCreate
(
u
);
if
(
t
)
{
async
create
(
u
,
t
)
{
var
self
=
this
;
var
u2
=
await
this
.
preCreate
(
u
);
if
(
t
)
{
console
.
log
(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
);
console
.
log
(
u2
);
return
this
.
model
.
create
(
u2
,{
transaction
:
t
}).
then
(
user
=>
{
return
this
.
model
.
create
(
u2
,
{
transaction
:
t
}).
then
(
user
=>
{
return
user
;
});
}
else
{
return
this
.
model
.
create
(
u2
).
then
(
user
=>
{
}
else
{
return
this
.
model
.
create
(
u2
).
then
(
user
=>
{
return
user
;
});
}
}
//修改用户(user表)公司的唯一码
async
putUserCompanyOnlyCode
(
userId
,
company_only_code
,
result
)
{
var
customerObj
=
{
companyOnlyCode
:
company_only_code
};
var
putSqlWhere
=
{
where
:{
id
:
userId
}
};
this
.
updateByWhere
(
customerObj
,
putSqlWhere
);
async
putUserCompanyOnlyCode
(
userId
,
company_only_code
,
result
)
{
var
customerObj
=
{
companyOnlyCode
:
company_only_code
};
var
putSqlWhere
=
{
where
:
{
id
:
userId
}
};
this
.
updateByWhere
(
customerObj
,
putSqlWhere
);
return
result
;
}
}
module
.
exports
=
UserDao
;
module
.
exports
=
UserDao
;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
...
...
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