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
215fefeb
Commit
215fefeb
authored
Apr 10, 2020
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
ca96edac
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
275 additions
and
103 deletions
+275
-103
center-manage/app/base/controller/ctl.base.js
+11
-0
center-manage/app/base/db/cache.base.js
+1
-1
center-manage/app/base/db/cache/vcodeCache.js
+1
-1
center-manage/app/base/db/dao.base.js
+2
-0
center-manage/app/base/db/impl/common/connection.js
+13
-2
center-manage/app/base/db/models/common/app.js
+1
-1
center-manage/app/base/db/models/common/company.js
+53
-0
center-manage/app/base/service/impl/auth/userSve.js
+77
-13
center-manage/app/base/service/impl/common/appSve.js
+28
-74
center-manage/app/base/service/sve.base.js
+73
-0
center-manage/app/base/system.js
+14
-10
center-manage/app/config/settings.js
+1
-1
No files found.
center-manage/app/base/controller/ctl.base.js
View file @
215fefeb
...
@@ -17,6 +17,17 @@ class CtlBase {
...
@@ -17,6 +17,17 @@ class CtlBase {
async
doexec
(
methodname
,
pobj
,
query
,
req
)
{
async
doexec
(
methodname
,
pobj
,
query
,
req
)
{
try
{
try
{
await
this
.
setContextParams
(
pobj
,
query
,
req
);
await
this
.
setContextParams
(
pobj
,
query
,
req
);
//从请求头里面取appkey_consumename
// var consumeName=req.headers[""]
// var appkey=
// if( this.session["appkey_consumename"]) {
// }else{
// //从头里取,从redis中取出缓存对象赋值到控制基类的session属性
// //appkey_consumename
// this.session={};
// }
//req.session=redis缓存的上下文对象
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
return
rtn
;
return
rtn
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
center-manage/app/base/db/cache.base.js
View file @
215fefeb
...
@@ -34,7 +34,7 @@ class CacheBase {
...
@@ -34,7 +34,7 @@ class CacheBase {
this
.
redisClient
.
sadd
(
this
.
cacheCacheKeyPrefix
,
[
cachekey
+
"|"
+
this
.
desc
]);
this
.
redisClient
.
sadd
(
this
.
cacheCacheKeyPrefix
,
[
cachekey
+
"|"
+
this
.
desc
]);
return
JSON
.
parse
(
objvalstr
);
return
JSON
.
parse
(
objvalstr
);
}
else
{
}
else
{
this
.
redisClient
.
setWithEx
(
cachekey
,
cacheValue
,
ex
);
//
this.redisClient.setWithEx(cachekey, cacheValue, ex);
return
JSON
.
parse
(
cacheValue
);
return
JSON
.
parse
(
cacheValue
);
}
}
}
}
...
...
center-manage/app/base/db/cache/vcodeCache.js
View file @
215fefeb
...
@@ -18,7 +18,7 @@ class VCodeCache extends CacheBase {
...
@@ -18,7 +18,7 @@ class VCodeCache extends CacheBase {
}
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
//inputkey采用appkey_mobile的形式
//inputkey采用appkey_mobile的形式
var
mobile
=
inputkey
.
split
(
"_"
)[
1
]
;
var
mobile
=
inputkey
;
var
tmplCode
=
val
;
var
tmplCode
=
val
;
var
signName
=
items
?
items
[
0
]
:
""
;
var
signName
=
items
?
items
[
0
]
:
""
;
var
vcode
=
await
this
.
smsUtil
.
getUidStr
(
6
,
10
);
var
vcode
=
await
this
.
smsUtil
.
getUidStr
(
6
,
10
);
...
...
center-manage/app/base/db/dao.base.js
View file @
215fefeb
...
@@ -14,6 +14,8 @@ class Dao {
...
@@ -14,6 +14,8 @@ class Dao {
async
create
(
u
,
t
)
{
async
create
(
u
,
t
)
{
var
u2
=
this
.
preCreate
(
u
);
var
u2
=
this
.
preCreate
(
u
);
if
(
t
)
{
if
(
t
)
{
console
.
log
(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
);
console
.
log
(
this
.
model
);
return
this
.
model
.
create
(
u2
,
{
transaction
:
t
}).
then
(
u
=>
{
return
this
.
model
.
create
(
u2
,
{
transaction
:
t
}).
then
(
u
=>
{
return
u
;
return
u
;
});
});
...
...
center-manage/app/base/db/impl/common/connection.js
View file @
215fefeb
...
@@ -37,11 +37,22 @@ class DbFactory{
...
@@ -37,11 +37,22 @@ class DbFactory{
this
.
db
.
models
.
org
.
hasMany
(
this
.
db
.
models
.
org
,{
constraints
:
false
,});
this
.
db
.
models
.
org
.
hasMany
(
this
.
db
.
models
.
org
,{
constraints
:
false
,});
//组织机构和角色是多对多关系
//组织机构和角色是多对多关系
this
.
db
.
models
.
org
.
belongsTo
Many
(
this
.
db
.
models
.
role
,{
through
:
this
.
db
.
models
.
orgrole
,
constraints
:
false
,});
this
.
db
.
models
.
org
.
belongsTo
(
this
.
db
.
models
.
role
,{
constraints
:
false
,});
this
.
db
.
models
.
role
.
belongsToMany
(
this
.
db
.
models
.
org
,{
through
:
this
.
db
.
models
.
orgrole
,
constraints
:
false
,});
//
this.db.models.role.belongsToMany(this.db.models.org,{through: this.db.models.orgrole,constraints: false,});
//组织机构和用户是多对多关系
//组织机构和用户是多对多关系
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
org
,{
constraints
:
false
,});
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
org
,{
constraints
:
false
,});
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
this
.
db
.
models
.
role
.
belongsTo
(
this
.
db
.
models
.
app
,
{
constraints
:
false
,});
this
.
db
.
models
.
org
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
this
.
db
.
models
.
role
.
belongsTo
(
this
.
db
.
models
.
company
,
{
constraints
:
false
,});
this
.
db
.
models
.
org
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
}
}
//async getCon(){,用于使用替换table模型内字段数据使用
//async getCon(){,用于使用替换table模型内字段数据使用
getCon
(){
getCon
(){
...
...
center-manage/app/base/db/models/common/app.js
View file @
215fefeb
...
@@ -49,7 +49,7 @@ module.exports = (db, DataTypes) => {
...
@@ -49,7 +49,7 @@ module.exports = (db, DataTypes) => {
values
:
Object
.
keys
(
appconfig
.
pdict
.
app_type
),
values
:
Object
.
keys
(
appconfig
.
pdict
.
app_type
),
},
},
},
{
},
{
paranoid
:
tru
e
,
//假的删除
paranoid
:
fals
e
,
//假的删除
underscored
:
true
,
underscored
:
true
,
version
:
true
,
version
:
true
,
freezeTableName
:
true
,
freezeTableName
:
true
,
...
...
center-manage/app/base/db/models/common/company.js
0 → 100644
View file @
215fefeb
const
system
=
require
(
"../../../system"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
appconfig
=
system
.
getSysConfig
();
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"company"
,
{
name
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
},
//和user的from相同,在注册user时,去创建
},
{
paranoid
:
true
,
//假的删除
underscored
:
true
,
version
:
true
,
freezeTableName
:
true
,
//freezeTableName: true,
// define the table's name
tableName
:
'p_company'
,
validate
:
{
},
indexes
:
[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
center-manage/app/base/service/impl/auth/userSve.js
View file @
215fefeb
...
@@ -5,16 +5,25 @@ const jwt = require('jsonwebtoken');
...
@@ -5,16 +5,25 @@ const jwt = require('jsonwebtoken');
class
UserService
extends
ServiceBase
{
class
UserService
extends
ServiceBase
{
constructor
()
{
constructor
()
{
super
(
"auth"
,
ServiceBase
.
getDaoName
(
UserService
));
super
(
"auth"
,
ServiceBase
.
getDaoName
(
UserService
));
this
.
companyDao
=
system
.
getObject
(
"db.common.companyDao"
);
}
}
//注册接口
//注册接口
//封装kongurl
//封装kongurl
async
register
(
p
,
q
){
async
register
(
p
,
q
){
var
self
=
this
;
var
self
=
this
;
p
.
password
=
this
.
getEncryptStr
(
p
.
password
);
let
tmppwd
=
p
.
password
;
if
(
!
tmppwd
){
tmppwd
=
settings
.
defaultpwd
;
}
p
.
password
=
this
.
getEncryptStr
(
tmppwd
);
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
//创建一个默认公司,公司名称xxxx的公司
let
cmp
=
await
self
.
companyDao
.
create
({
name
:
p
.
userName
+
"的公司"
},
t
);
p
.
company_id
=
cmp
.
id
;
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
//创建统一账号
//创建统一账号
let
cred
=
await
self
.
cregister
(
u
.
userName
)
let
cred
=
await
self
.
cregister
(
u
.
userName
,
cmp
.
id
)
console
.
log
(
"......................................"
);
console
.
log
(
"......................................"
);
console
.
log
(
cred
.
consumer
.
id
);
console
.
log
(
cred
.
consumer
.
id
);
if
(
cred
){
if
(
cred
){
...
@@ -36,26 +45,80 @@ class UserService extends ServiceBase {
...
@@ -36,26 +45,80 @@ class UserService extends ServiceBase {
}
}
//登录接口封装kong-url
//登录接口封装kong-url
//登录路由放行
//p里面含有appkey,company_id,userName,password
async
login
(
p
,
q
){
async
login
(
p
,
q
){
var
self
=
this
;
var
rtn
=
{}
return
this
.
db
.
transaction
(
async
function
(
t
)
{
p
.
password
=
this
.
getEncryptStr
(
p
.
password
);
let
userfind
=
await
self
.
dao
.
findOne
(
p
);
if
(
userfind
){
let
token
=
self
.
cmakejwt
(
userfind
.
jwtkey
,
userfind
.
jwtsecret
,
null
);
rtn
.
token
=
token
;
rtn
.
user
=
userfind
;
return
rtn
;
}
else
{
return
null
;
}
})
}
//用户验证码登录
//
async
loginByVCode
(
p
,
q
,
req
){
var
rtn
=
{}
//检查传递过来的手机验证码是否与缓存的一致
let
mobile
=
p
.
mobile
;
let
vcode
=
p
.
vcode
;
let
cachevcode
=
await
this
.
cacheManager
[
"vcodeCache"
].
getCache
(
mobile
,
60000
)
if
(
vcode
!==
cachevcode
){
return
null
;
}
else
{
//检查是否在库里存在
//appkey--company_id---需要控制器基类里设置到p对象里
let
user
=
await
this
.
findOne
({
userName
:
mobile
,
appkey
:
p
.
appkey
,
company_id
:
p
.
company_id
})
if
(
user
){
//生成token
}
else
{
//先按照用户名查续身份信息,获取key,secret,
let
u
=
await
this
.
register
({
userName
:
mobile
,
appkey
:
p
.
appkey
,
company_id
:
p
.
company_id
});
}
}
//不一致那么就
}
//发送手机验证码并缓存
async
sendVCode
(
p
,
q
,
req
){
let
mobile
=
p
.
mobile
;
let
vcodeobj
=
this
.
cacheManager
[
"vcodeCache"
].
cache
(
mobile
,
null
,
60000
);
return
vcodeobj
.
vcode
;
}
}
//创建统一账号
async
reSendVCode
(
p
,
q
,
req
){
async
cregister
(
uname
){
let
mobile
=
p
.
mobile
;
await
this
.
cacheManager
[
"vcodeCache"
].
invalidate
(
mobile
);
let
vcodeobj
=
await
this
.
cacheManager
[
"vcodeCache"
].
cache
(
mobile
,
null
,
60000
);
return
vcodeobj
.
vcode
;
}
//创建统一账号及jwt身份
async
cregister
(
uname
,
cmpid
){
try
{
try
{
var
rtn2
=
null
;
var
rtn2
=
null
;
let
rtn
=
await
system
.
post3wFormTypeReq
(
settings
.
kongurl
+
"consumers"
,{
username
:
uname
})
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
newConsumerUrl
(),{
username
:
uname
,
tags
:[
"cmp_"
+
cmpid
]})
console
.
log
(
rtn
)
if
(
rtn
.
statusCode
==
409
){
if
(
rtn
.
statusCode
==
409
){
//return new Error("已经存在相同的统一账号名称!");
throw
new
Error
(
"已经存在相同的统一账号名称!"
);
return
null
;
}
else
{
}
else
{
//创建身份
//创建身份
rtn2
=
await
system
.
post3wFormTypeReq
(
settings
.
kongurl
+
"consumers/"
+
uname
+
"/jwt"
)
rtn2
=
await
system
.
post3wFormTypeReq
(
UserService
.
newJwtCredUrl
(
uname
)
)
}
}
if
(
rtn
.
statusCode
==
201
&&
rtn2
.
statusCode
==
201
){
if
(
rtn
.
statusCode
==
201
&&
rtn2
.
statusCode
==
201
){
return
rtn2
.
data
;
return
rtn2
.
data
;
}
}
return
null
;
return
null
;
}
catch
(
e
){
}
catch
(
e
){
console
.
log
(
e
);
return
null
;
return
null
;
}
}
}
}
...
@@ -80,7 +143,7 @@ class UserService extends ServiceBase {
...
@@ -80,7 +143,7 @@ class UserService extends ServiceBase {
//删除统一账号
//删除统一账号
async
cunregister
(
uname
){
async
cunregister
(
uname
){
try
{
try
{
let
rtn
=
await
system
.
delReq
(
settings
.
kongurl
+
"consumers/"
+
uname
)
let
rtn
=
await
system
.
delReq
(
UserService
.
consumerUrl
(
uname
)
)
if
(
rtn
.
statusCode
==
204
){
if
(
rtn
.
statusCode
==
204
){
return
{};
return
{};
}
}
...
@@ -103,13 +166,13 @@ class UserService extends ServiceBase {
...
@@ -103,13 +166,13 @@ class UserService extends ServiceBase {
module
.
exports
=
UserService
;
module
.
exports
=
UserService
;
// (async ()=>{
// (async ()=>{
//
let u=new UserService();
let
u
=
new
UserService
();
// // let x=await u.cregister("jiangong")
// // let x=await u.cregister("jiangong")
// // console.log(x)
// // console.log(x)
// // let x=await u.cunregister("jiangong")
// // let x=await u.cunregister("jiangong")
// // console.log(x)
// // console.log(x)
// // let t=await u.cmakejwt()
// // let t=await u.cmakejwt()
// // console.log(t)
// // console.log(t)
// let ux=u.register({userName:"jiangyong2
",password:"123"})
let
ux
=
u
.
register
({
userName
:
"jiangyong3
"
,
password
:
"123"
})
//
console.log(ux);
console
.
log
(
ux
);
// })()
// })()
\ No newline at end of file
center-manage/app/base/service/impl/common/appSve.js
View file @
215fefeb
...
@@ -48,13 +48,16 @@ class AppService extends ServiceBase {
...
@@ -48,13 +48,16 @@ class AppService extends ServiceBase {
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
var
app
=
await
self
.
dao
.
create
(
pobj
,
t
);
var
app
=
await
self
.
dao
.
create
(
pobj
,
t
);
//创建后台应用服务
//创建后台应用服务
let
svobj
=
await
self
.
cregisterservice
({
name
:
app
.
name
,
url
:
"http://"
+
app
.
backend
})
let
svobj
=
await
self
.
cjsonregister
(
AppService
.
newServiceUrl
(),{
name
:
app
.
name
,
url
:
"http://"
+
app
.
backend
})
if
(
svobj
){
//添加路由
let
routeobj
=
await
self
.
cjsonregister
(
AppService
.
newRouteUrl
(
app
.
name
),{
name
:
app
.
name
,
hosts
:[
app
.
domainName
]})
if
(
svobj
&&
routeobj
){
try
{
try
{
app
.
appkey
=
svobj
.
id
;
app
.
appkey
=
svobj
.
id
;
await
app
.
save
({
transaction
:
t
});
await
app
.
save
({
transaction
:
t
});
}
catch
(
e
){
}
catch
(
e
){
await
self
.
cdelservice
(
app
.
name
)
await
self
.
cdel
(
AppService
.
routeUrl
(
app
.
name
))
await
self
.
cdel
(
AppService
.
serviceUrl
(
app
.
name
))
}
}
}
else
{
}
else
{
throw
new
Error
(
"创建应用服务失败"
);
throw
new
Error
(
"创建应用服务失败"
);
...
@@ -62,76 +65,22 @@ class AppService extends ServiceBase {
...
@@ -62,76 +65,22 @@ class AppService extends ServiceBase {
return
app
;
return
app
;
});
});
}
}
//kong创建应用服务
//删除应用
async
cregisterservice
(
opts
){
async
delete
(
pobj
,
qobj
){
try
{
var
self
=
this
;
let
rtn
=
await
system
.
post3wFormTypeReq
(
settings
.
kongurl
+
"services"
,
opts
)
return
this
.
db
.
transaction
(
async
function
(
t
)
{
console
.
log
(
rtn
);
await
self
.
dao
.
delete
(
pobj
,
t
)
if
(
rtn
.
statusCode
==
409
){
//删除路由
//return new Error("已经存在相同的统一账号名称!");
await
self
.
cdel
(
AppService
.
routeUrl
(
pobj
.
name
));
return
null
;
//删除服务
}
await
self
.
cdel
(
AppService
.
serviceUrl
(
pobj
.
name
));
if
(
rtn
.
statusCode
==
201
){
return
{}
return
rtn
.
data
;
})
}
return
null
;
}
catch
(
e
){
console
.
log
(
e
);
return
null
;
}
}
//删除统一服务
async
cdelservice
(
sname
){
try
{
let
rtn
=
await
system
.
delReq
(
settings
.
kongurl
+
"services/"
+
sname
)
if
(
rtn
.
statusCode
==
204
){
return
{};
}
return
null
;
}
catch
(
e
){
return
null
;
}
}
async
cregisterRouter
(
sname
,
opts
){
try
{
let
rtn
=
await
system
.
postJsonTypeReq
(
settings
.
kongurl
+
"services/"
+
sname
+
"/routes"
,
opts
)
if
(
rtn
.
statusCode
==
409
){
//return new Error("已经存在相同的统一账号名称!");
return
null
;
}
if
(
rtn
.
statusCode
==
201
){
return
rtn
.
data
;
}
return
null
;
}
catch
(
e
){
console
.
log
(
e
);
return
null
;
}
}
}
//删除统一路由
async
cdelroute
(
rname
){
try
{
let
rtn
=
await
system
.
delReq
(
settings
.
kongurl
+
"routes/"
+
rname
)
console
.
log
(
rtn
);
if
(
rtn
.
statusCode
==
204
){
return
{};
}
return
null
;
}
catch
(
e
){
return
null
;
}
}
async
findAndCountAll
(
obj
)
{
async
findAndCountAll
(
obj
)
{
var
self
=
this
;
var
self
=
this
;
const
apps
=
await
super
.
findAndCountAll
(
obj
);
const
apps
=
await
super
.
findAndCountAll
(
obj
);
for
(
let
i
=
0
;
i
<
apps
.
results
.
rows
.
length
;
i
++
)
{
var
a
=
apps
.
results
.
rows
[
i
];
var
appkey
=
a
.
appkey
;
var
apicallAccu
=
await
this
.
cacheManager
[
"ApiAccuCache"
].
getApiCallAccu
(
appkey
);
a
.
apiCallCount
=
apicallAccu
.
callcount
;
a
.
amount
=
apicallAccu
.
amount
;
}
return
apps
;
return
apps
;
}
}
}
}
...
@@ -142,10 +91,14 @@ module.exports = AppService;
...
@@ -142,10 +91,14 @@ module.exports = AppService;
// console.log(x)
// console.log(x)
// let x=await u.cunregister("jiangong")
// let x=await u.cunregister("jiangong")
// console.log(x)
// console.log(x)
// let t=await u.cmakejwt()
// let t=await u.cmakejwt()
// console.log(t)
// console.log(t)
//let ux=await u.cjsonregister(AppService.newRouteUrl("test-service2"),{name:"test-service2",hosts:["ttest1.com"]})
// let ux=await u.cregisterRouter("test-service2",{name:"test-service2",hosts:["ttest1.com"]})
//let ux=await u.cjsonregister(AppService.newServiceUrl(),{name:"test-service3",url:"http://zhichan.gongsibao.com"})
// // let ux=await u.cdelroute("test-service2")
//let ux=await u.cdel(AppService.routeUrl("test-service2"))
// console.log(ux);
//let ux=await u.cdel(AppService.serviceUrl("test-service2"))
// let ux=await u.create({name:"test4-service",backend:"zhichan-service",domainName:"domain.com"})
// console.log(ux);
// let delrtn=await u.delete({id:2,name:"test4-service"})
// console.log(delrtn);
})()
})()
\ No newline at end of file
center-manage/app/base/service/sve.base.js
View file @
215fefeb
...
@@ -108,5 +108,78 @@ class ServiceBase {
...
@@ -108,5 +108,78 @@ class ServiceBase {
}
}
return
uuid
.
join
(
''
);
return
uuid
.
join
(
''
);
}
}
//kong统一处理
//统一注册组件
async
cformregister
(
opurl
,
opts
){
try
{
let
rtn
=
await
system
.
post3wFormTypeReq
(
opurl
,
opts
)
console
.
log
(
rtn
);
if
(
rtn
.
statusCode
==
409
){
//return new Error("已经存在相同的统一账号名称!");
return
null
;
}
if
(
rtn
.
statusCode
==
201
){
return
rtn
.
data
;
}
else
{
throw
new
Error
(
rtn
.
data
);
}
}
catch
(
e
){
console
.
log
(
e
);
return
null
;
}
}
async
cjsonregister
(
opurl
,
opts
){
try
{
let
rtn
=
await
system
.
postJsonTypeReq
(
opurl
,
opts
)
console
.
log
(
",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"
,
rtn
);
if
(
rtn
.
statusCode
==
409
){
//return new Error("已经存在相同的统一账号名称!");
return
null
;
}
if
(
rtn
.
statusCode
==
201
){
return
rtn
.
data
;
}
else
{
throw
new
Error
(
rtn
.
data
);
}
return
null
;
}
catch
(
e
){
console
.
log
(
e
);
return
null
;
}
}
async
cdel
(
opurl
){
try
{
let
rtn
=
await
system
.
delReq
(
opurl
)
if
(
rtn
.
statusCode
==
204
){
return
{};
}
else
{
throw
new
Error
(
rtn
.
data
);
}
}
catch
(
e
){
console
.
log
(
e
);
return
null
;
}
}
static
newRouteUrl
(
sname
){
return
settings
.
kongurl
+
"services/"
+
sname
+
"/routes"
;
}
static
newServiceUrl
(){
return
settings
.
kongurl
+
"services"
;
}
static
newConsumerUrl
(){
return
settings
.
kongurl
+
"consumers"
;
}
static
newJwtCredUrl
(
consumername
){
return
settings
.
kongurl
+
"consumers/"
+
consumername
+
"/jwt"
;
}
static
serviceUrl
(
sname
){
return
settings
.
kongurl
+
"services/"
+
sname
;
}
static
routeUrl
(
rname
){
return
settings
.
kongurl
+
"routes/"
+
rname
;
}
static
consumerUrl
(
consumerName
){
return
settings
.
kongurl
+
"consumers/"
+
consumerName
;
}
}
}
module
.
exports
=
ServiceBase
;
module
.
exports
=
ServiceBase
;
center-manage/app/base/system.js
View file @
215fefeb
...
@@ -115,16 +115,7 @@ class System {
...
@@ -115,16 +115,7 @@ class System {
})
})
return
promise
;
return
promise
;
}
}
static
register
(
key
,
ClassObj
,
groupName
,
filename
)
{
if
(
System
.
objTable
[
key
]
!=
null
)
{
throw
new
Error
(
"相同key的对象已经存在"
);
}
else
{
let
obj
=
new
ClassObj
(
groupName
,
filename
);
System
.
objTable
[
key
]
=
obj
;
}
return
System
.
objTable
[
key
];
}
/**
/**
* 请求返回成功
* 请求返回成功
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败
...
@@ -176,6 +167,16 @@ class System {
...
@@ -176,6 +167,16 @@ class System {
data
:
data
,
data
:
data
,
};
};
}
}
static
register
(
key
,
ClassObj
,
groupName
,
filename
)
{
if
(
System
.
objTable
[
key
]
!=
null
)
{
throw
new
Error
(
"相同key的对象已经存在"
);
}
else
{
let
obj
=
new
ClassObj
(
groupName
,
filename
);
System
.
objTable
[
key
]
=
obj
;
}
return
System
.
objTable
[
key
];
}
static
getObject
(
objpath
)
{
static
getObject
(
objpath
)
{
var
pathArray
=
objpath
.
split
(
"."
);
var
pathArray
=
objpath
.
split
(
"."
);
var
packageName
=
pathArray
[
0
];
var
packageName
=
pathArray
[
0
];
...
@@ -204,7 +205,10 @@ class System {
...
@@ -204,7 +205,10 @@ class System {
let
fname
=
objsettings
[
packageName
+
"base"
];
let
fname
=
objsettings
[
packageName
+
"base"
];
ClassObj
=
require
(
fname
);
ClassObj
=
require
(
fname
);
}
}
if
(
ClassObj
.
name
==
"Dao"
){
let
modelname
=
filename
.
substring
(
0
,
filename
.
lastIndexOf
(
"Dao"
))
return
System
.
register
(
objabspath
,
ClassObj
,
modelname
);
}
return
System
.
register
(
objabspath
,
ClassObj
,
groupName
,
filename
);
return
System
.
register
(
objabspath
,
ClassObj
,
groupName
,
filename
);
}
}
}
}
...
...
center-manage/app/config/settings.js
View file @
215fefeb
...
@@ -14,7 +14,7 @@ var ENVINPUT={
...
@@ -14,7 +14,7 @@ var ENVINPUT={
var
settings
=
{
var
settings
=
{
env
:
ENVINPUT
.
APP_ENV
,
env
:
ENVINPUT
.
APP_ENV
,
salt
:
"%iatpD1gcxz7iF#B"
,
salt
:
"%iatpD1gcxz7iF#B"
,
defaultpwd
:
"
987456
"
,
defaultpwd
:
"
gsb2020
"
,
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
port
:
process
.
env
.
NODE_PORT
||
4001
,
port
:
process
.
env
.
NODE_PORT
||
4001
,
kongurl
:
"http://127.0.0.1:8001/"
,
kongurl
:
"http://127.0.0.1:8001/"
,
...
...
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