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
5ced773c
Commit
5ced773c
authored
Apr 14, 2020
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
215fefeb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
485 additions
and
155 deletions
+485
-155
.vscode/launch.json
+2
-1
center-manage/app/base/api/api.base.js
+10
-1
center-manage/app/base/api/impl/auth/accessAuth.js
+16
-0
center-manage/app/base/api/impl/common/apps.js
+43
-0
center-manage/app/base/controller/ctl.base.js
+3
-1
center-manage/app/base/controller/impl/auth/userCtl.js
+0
-0
center-manage/app/base/db/impl/common/connection.js
+2
-0
center-manage/app/base/db/initData.js
+12
-4
center-manage/app/base/db/models/common/plugin.js
+53
-0
center-manage/app/base/db/models/common/route.js
+57
-0
center-manage/app/base/service/impl/auth/userSve.js
+59
-34
center-manage/app/base/service/impl/common/apitradeSve.js
+0
-78
center-manage/app/base/service/impl/common/appSve.js
+34
-19
center-manage/app/base/service/impl/common/pluginSve.js
+113
-0
center-manage/app/base/service/impl/common/routeSve.js
+52
-0
center-manage/app/base/service/sve.base.js
+7
-0
center-manage/app/base/system.js
+16
-6
center-manage/app/config/environment.js
+0
-7
center-manage/app/config/routes/api.js
+3
-2
center-manage/app/config/routes/web.js
+0
-1
center-manage/app/config/settings.js
+3
-1
No files found.
.vscode/launch.json
View file @
5ced773c
...
...
@@ -8,7 +8,7 @@
"type"
:
"node"
,
"request"
:
"launch"
,
"name"
:
"Launch Program"
,
"program"
:
"${workspaceFolder}/
bigdata
/main.js"
"program"
:
"${workspaceFolder}/
center-manage
/main.js"
}
]
}
\ No newline at end of file
center-manage/app/base/api/api.base.js
View file @
5ced773c
...
...
@@ -3,11 +3,20 @@ const uuidv4 = require('uuid/v4');
const
settings
=
require
(
"../../config/settings"
);
class
APIBase
{
constructor
()
{
super
();
this
.
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
}
async
doexec
(
gname
,
methodname
,
pobj
,
query
,
req
)
{
try
{
console
.
log
(
"**********************************************"
)
console
.
log
(
req
.
headers
)
let
custtags
=
req
.
headers
[
"x-consumetag"
].
split
(
"|"
);
req
.
xctx
=
{
appkey
:
req
.
headers
[
"x-appkey"
],
companyid
:
custtags
[
0
].
split
(
"_"
)[
1
],
password
:
custtags
[
1
].
split
(
"_"
)[
1
],
username
:
req
.
headers
[
"x-consumer-username"
],
credid
:
req
.
headers
[
"x-credential-identifier"
]
}
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
return
rtn
;
}
catch
(
e
)
{
...
...
center-manage/app/base/api/impl/auth/accessAuth.js
View file @
5ced773c
...
...
@@ -9,6 +9,22 @@ class AccessAuthAPI extends APIBase {
this
.
authUtils
=
system
.
getObject
(
"util.businessManager.authUtils"
);
this
.
userSve
=
system
.
getObject
(
"service.auth.userSve"
);
}
//不从平台应用列表入口登录时
//先要调用平台登录接口
//返回token,利用这个token再去登录某个具体APP
//会话存储具体APP的用户信息
//每个前端应用打开时,先检查是否存在token
//如果存在,就去访问获取用户信息,---调用本接口--即刻
//进入或登录某个具体应用
//前提是已经具备了统一管理的账号,并且已经在统一管理账号登录,客户端具备了token
//进入某个具体应用时,需要指定 x-appkey请求头
//
async
loginToApp
(
p
,
q
,
req
){
let
appkey
=
req
.
xctx
.
appkey
;
}
classDesc
()
{
return
{
groupName
:
"auth"
,
...
...
center-manage/app/base/api/impl/common/apps.js
0 → 100644
View file @
5ced773c
var
APIBase
=
require
(
"../../api.base"
);
var
system
=
require
(
"../../../system"
);
var
settings
=
require
(
"../../../../config/settings"
);
class
AppAPI
extends
APIBase
{
constructor
()
{
super
();
this
.
appS
=
system
.
getObject
(
"service.common.appSve"
);
}
async
create
(
pobj
,
q
,
req
){
// console.log("oooooooooooooooooooooooooooooooooooooooooooooooo")
// console.log(req.xctx)
let
rtn
=
this
.
appS
.
create
(
pobj
,
q
,
req
);
return
system
.
getResult
(
rtn
);
}
async
del
(
pobj
,
q
,
req
){
let
rtn
=
this
.
appS
.
delete
(
pobj
,
q
,
req
);
return
system
.
getResult
(
rtn
);
}
classDesc
()
{
return
{
groupName
:
"auth"
,
groupDesc
:
"认证相关的包"
,
name
:
"AccessAuthAPI"
,
desc
:
"关于认证的类"
,
exam
:
`
post http://p.apps.com/api/auth/accessAuth/getAccessKey
{
appKey:xxxxx,
secret:yyyyyy
}
`
,
};
}
methodDescs
()
{
return
[
];
}
exam
()
{
return
``
}
}
module
.
exports
=
AppAPI
;
center-manage/app/base/controller/ctl.base.js
View file @
5ced773c
...
...
@@ -12,7 +12,9 @@ class CtlBase {
return
ClassObj
[
"name"
].
substring
(
0
,
ClassObj
[
"name"
].
lastIndexOf
(
"Ctl"
)).
toLowerCase
()
+
"Sve"
;
}
async
setContextParams
(
pobj
,
qobj
,
req
)
{
req
.
xctx
=
{
appkey
:
req
.
headers
[
"x-appkey"
],
}
}
async
doexec
(
methodname
,
pobj
,
query
,
req
)
{
try
{
...
...
center-manage/app/base/controller/impl/auth/userCtl.js
View file @
5ced773c
This diff is collapsed.
Click to expand it.
center-manage/app/base/db/impl/common/connection.js
View file @
5ced773c
...
...
@@ -53,6 +53,8 @@ class DbFactory{
this
.
db
.
models
.
org
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
this
.
db
.
models
.
auth
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
this
.
db
.
models
.
route
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
this
.
db
.
models
.
plugin
.
belongsTo
(
this
.
db
.
models
.
app
,{
constraints
:
false
,});
}
//async getCon(){,用于使用替换table模型内字段数据使用
getCon
(){
...
...
center-manage/app/base/db/initData.js
View file @
5ced773c
...
...
@@ -9,11 +9,19 @@ const md5 = require("MD5");
var
dbf
=
system
.
getObject
(
"db.common.connection"
);
var
db
=
dbf
.
getCon
();
db
.
sync
({
force
:
true
}).
then
(
async
()
=>
{
const
User
=
db
.
models
.
user
;
User
.
create
({
userName
:
"sm"
,
password
:
md5
(
"123"
+
"_"
+
settings
.
salt
),
isSuper
:
true
,
isAdmin
:
true
,
isEnabled
:
true
,
nickName
:
"superman"
}).
then
(
function
(
u
){
console
.
log
(
"sync complete..."
);
const
apps
=
await
system
.
getObject
(
"service.common.appSve"
);
let
appnew
=
await
apps
.
create
(
{
"name"
:
"center-app"
,
"domainName"
:
"t9.com"
,
"backend"
:
"cm.com"
});
let
Role
=
db
.
models
[
"role"
];
await
Role
.
create
({
code
:
"ta"
,
name
:
"租户"
,
app_id
:
appnew
.
id
,
company_id
:
settings
.
pmcompanyid
})
const
us
=
await
system
.
getObject
(
"service.auth.userSve"
);
let
usuper
=
await
us
.
pmregister
({
userName
:
"sm"
,
password
:
"951753"
,
isSuper
:
true
,
isAdmin
:
true
,
isEnabled
:
true
,
nickName
:
"superman"
,
app_id
:
appnew
.
id
,
company_id
:
settings
.
id
})
//创建role
// if(settings.env=="prod"){
...
...
center-manage/app/base/db/models/common/plugin.js
0 → 100644
View file @
5ced773c
const
system
=
require
(
"../../../system"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
appconfig
=
system
.
getSysConfig
();
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"plugin"
,
{
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_plugin'
,
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/db/models/common/route.js
0 → 100644
View file @
5ced773c
const
system
=
require
(
"../../../system"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
appconfig
=
system
.
getSysConfig
();
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"route"
,
{
name
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
},
//和user的from相同,在注册user时,去创建
center_id
:
{
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_route'
,
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 @
5ced773c
...
...
@@ -6,11 +6,13 @@ class UserService extends ServiceBase {
constructor
()
{
super
(
"auth"
,
ServiceBase
.
getDaoName
(
UserService
));
this
.
companyDao
=
system
.
getObject
(
"db.common.companyDao"
);
this
.
roleDao
=
system
.
getObject
(
"db.common.roleDao"
);
}
//平台注册,默认角色,不具备平台级别的管理或运营功能
//注册接口
//封装kongurl
async
register
(
p
,
q
){
async
pm
register
(
p
,
q
){
var
self
=
this
;
let
tmppwd
=
p
.
password
;
if
(
!
tmppwd
){
...
...
@@ -22,8 +24,13 @@ class UserService extends ServiceBase {
let
cmp
=
await
self
.
companyDao
.
create
({
name
:
p
.
userName
+
"的公司"
},
t
);
p
.
company_id
=
cmp
.
id
;
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
//设置默认角色,租户
//设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
var
role
=
await
self
.
roleDao
.
model
.
findOne
({
where
:
{
code
:
"ta"
},
transaction
:
t
});
await
u
.
setRoles
([
role
],
{
transaction
:
t
});
//创建统一账号
let
cred
=
await
self
.
cregister
(
u
.
userName
,
cmp
.
id
)
let
cred
=
await
self
.
cregister
(
u
.
userName
,
cmp
.
id
,
p
.
password
)
console
.
log
(
"......................................"
);
console
.
log
(
cred
.
consumer
.
id
);
if
(
cred
){
...
...
@@ -43,18 +50,29 @@ class UserService extends ServiceBase {
}
});
}
//平台登录
//登录接口封装kong-url
//登录路由放行
//p里面含有appkey,company_id,userName,password
async
login
(
p
,
q
){
async
pmlogin
(
p
,
q
,
re
q
){
var
self
=
this
;
//先要按照用户名,在统一账户中查找存在性
//如果不存在
let
consumer
=
await
this
.
cget
(
UserService
.
consumerUrl
(
p
.
userName
));
if
(
!
consumer
.
data
){
return
null
;
}
else
{
let
password
=
consumer
.
data
.
tags
[
1
].
split
(
"_"
)[
1
];
let
inpassword
=
this
.
getEncryptStr
(
p
.
password
);
if
(
password
!=
inpassword
){
return
null
;
}
}
var
rtn
=
{}
return
this
.
db
.
transaction
(
async
function
(
t
)
{
p
.
password
=
this
.
getEncryptStr
(
p
.
password
);
let
userfind
=
await
self
.
dao
.
findOne
(
p
);
let
userfind
=
await
self
.
dao
.
findOne
({
userName
:
p
.
userName
,
app_id
:
settings
.
pmappid
,
company_id
:
settings
.
pmcompanyid
});
if
(
userfind
){
let
token
=
self
.
cmakejwt
(
userfind
.
jwtkey
,
userfind
.
jwtsecret
,
null
);
let
token
=
await
self
.
cmakejwt
(
userfind
.
jwtkey
,
userfind
.
jwtsecret
,
null
);
rtn
.
token
=
token
;
rtn
.
user
=
userfind
;
return
rtn
;
...
...
@@ -63,49 +81,56 @@ class UserService extends ServiceBase {
}
})
}
//平台注册与登录
//用户验证码登录
//
async
loginByVCode
(
p
,
q
,
req
){
async
pm
loginByVCode
(
p
,
q
,
req
){
var
rtn
=
{}
//检查传递过来的手机验证码是否与缓存的一致
let
mobile
=
p
.
mobile
;
let
vcode
=
p
.
vcode
;
let
cachevcode
=
await
this
.
cacheManager
[
"
vcodeCache"
].
getCache
(
mobile
,
6000
0
)
if
(
vcode
!=
=
cache
vcode
){
let
cachevcode
=
await
this
.
cacheManager
[
"
VCodeCache"
].
getCache
(
mobile
,
6
0
)
if
(
vcode
!=
cachevcode
.
vcode
){
return
null
;
}
else
{
//检查是否在库里存在
//appkey--company_id---需要控制器基类里设置到p对象里
let
user
=
await
this
.
findOne
({
userName
:
mobile
,
app
key
:
p
.
appkey
,
company_id
:
p
.
company_
id
})
let
user
=
await
this
.
findOne
({
userName
:
mobile
,
app
_id
:
settings
.
pmappid
,
company_id
:
settings
.
pmcompany
id
})
if
(
user
){
//生成token
let
token
=
await
this
.
cmakejwt
(
user
.
jwtkey
,
user
.
jwtsecret
,
null
);
rtn
.
token
=
token
;
rtn
.
user
=
user
;
return
rtn
;
}
else
{
//先按照用户名查续身份信息,获取key,secret,
let
u
=
await
this
.
register
({
userName
:
mobile
,
appkey
:
p
.
appkey
,
company_id
:
p
.
company_id
});
let
u
=
await
this
.
pmregister
({
userName
:
mobile
,
nickName
:
mobile
});
let
token
=
await
this
.
cmakejwt
(
u
.
jwtkey
,
u
.
jwtsecret
,
null
);
rtn
.
token
=
token
;
rtn
.
user
=
u
;
return
rtn
;
}
}
//不一致那么就
}
//发送手机验证码并缓存
async
sendVCode
(
p
,
q
,
req
){
let
mobile
=
p
.
mobile
;
let
vcodeobj
=
this
.
cacheManager
[
"vcodeCache"
].
cache
(
mobile
,
null
,
6000
0
);
let
vcodeobj
=
await
this
.
cacheManager
[
"VCodeCache"
].
cache
(
mobile
,
null
,
6
0
);
return
vcodeobj
.
vcode
;
}
async
reSendVCode
(
p
,
q
,
req
){
let
mobile
=
p
.
mobile
;
await
this
.
cacheManager
[
"
vc
odeCache"
].
invalidate
(
mobile
);
let
vcodeobj
=
await
this
.
cacheManager
[
"
vcodeCache"
].
cache
(
mobile
,
null
,
6000
0
);
await
this
.
cacheManager
[
"
VC
odeCache"
].
invalidate
(
mobile
);
let
vcodeobj
=
await
this
.
cacheManager
[
"
VCodeCache"
].
cache
(
mobile
,
null
,
6
0
);
return
vcodeobj
.
vcode
;
}
//创建统一账号及jwt身份
async
cregister
(
uname
,
cmpid
){
async
cregister
(
uname
,
cmpid
,
pass
){
try
{
var
rtn2
=
null
;
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
newConsumerUrl
(),{
username
:
uname
,
tags
:[
"cmp_"
+
cmpid
]})
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
newConsumerUrl
(),{
username
:
uname
,
tags
:[
"cmp_"
+
cmpid
,
"pass_"
+
pass
]})
console
.
log
(
rtn
)
if
(
rtn
.
statusCode
==
409
){
throw
new
Error
(
"已经存在相同的统一账号名称!"
);
...
...
@@ -135,8 +160,8 @@ class UserService extends ServiceBase {
return
promise
;
}
//只要登录 生成新的访问jwttoken
async
cmakejwt
(
uname
,
opts
){
var
token
=
await
this
.
jwtsign
(
'a36c3049b36249a3c9f8891cb127243c'
,
'e71829c351aa4242c2719cbfbe671c09'
,
opts
);
async
cmakejwt
(
key
,
secret
,
opts
){
var
token
=
await
this
.
jwtsign
(
key
,
secret
,
opts
);
return
token
;
}
...
...
@@ -165,14 +190,14 @@ class UserService extends ServiceBase {
}
module
.
exports
=
UserService
;
// (async ()=>{
let
u
=
new
UserService
();
// // let x=await u.cregister("jiangong")
// // console.log(x)
// // let x=await u.cunregister("jiangong")
// // console.log(x)
// // let t=await u.cmakejwt()
// // console.log(t)
let
ux
=
u
.
register
({
userName
:
"jiangyong3"
,
password
:
"123"
})
console
.
log
(
ux
);
// })()
\ No newline at end of file
// // (async ()=>{
// let u=new UserService();
// // // let x=await u.cregister("jiangong")
// // // console.log(x)
// // // let x=await u.cunregister("jiangong")
// // // console.log(x)
// // // let t=await u.cmakejwt()
// // // console.log(t)
// let ux=u.register({userName:"jiangyong3",password:"123"})
// console.log(ux);
// // })()
\ No newline at end of file
center-manage/app/base/service/impl/common/apitradeSve.js
deleted
100644 → 0
View file @
215fefeb
const
system
=
require
(
"../../../system"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
ServiceBase
=
require
(
"../../sve.base"
)
var
WXPay
=
require
(
'wx-pay'
);
const
uuidv4
=
require
(
'uuid/v4'
);
class
ApiTradeService
extends
ServiceBase
{
constructor
(){
super
(
"common"
,
ServiceBase
.
getDaoName
(
ApiTradeService
));
this
.
appS
=
system
.
getObject
(
"service.common.appSve"
);
}
async
create
(
tradeObj
){
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
){
//获取缓存二个值,一个是赠送次数,一个是调用价格,取目标应用的appkey
var
pconfig
=
await
self
.
cacheManager
[
"PConfigCache"
].
cache
(
tradeObj
.
destappkey
,
null
,
null
);
var
apiInitGift
=
pconfig
.
find
(
item
=>
{
return
item
.
configType
===
"apiInitGift"
;
});
var
apiCallPrice
=
pconfig
.
find
(
item
=>
{
return
item
.
configType
===
"apiCallPrice"
;
});
var
callCache
=
await
self
.
cacheManager
[
"ApiCallCountCache"
].
getApiCallCount
(
tradeObj
.
srcappkey
,
tradeObj
.
op
);
var
callAccuCache
=
await
self
.
cacheManager
[
"ApiAccuCache"
].
getApiCallAccu
(
tradeObj
.
srcappkey
+
"_"
+
tradeObj
.
destappkey
);
//需要每次增加计数之前,通知目标app,目前的计数值,由目标APP来决定是否准许访问
var
appdest
=
await
self
.
cacheManager
[
"AppCache"
].
cache
(
tradeObj
.
destappkey
);
if
(
appdest
.
id
!=
settings
.
platformid
){
var
recvCountNotityUrl
=
appdest
.
notifyCacheCountUrl
;
self
.
apiCallWithAk
(
recvCountNotityUrl
,
callAccuCache
);
}
else
{
self
.
appS
.
recvNotificationForCacheCount
(
callAccuCache
);
}
var
calledCount
=
Number
(
callCache
.
callcount
);
var
balance
=
Number
(
callCache
.
amount
);
if
(
calledCount
>
Number
(
apiInitGift
?
apiInitGift
.
configValue
:
0
)){
//调用次数大于免费次数
tradeObj
.
amount
=
Number
(
apiCallPrice
?
apiCallPrice
.
configValue
:
0
);
}
else
{
tradeObj
.
amount
=
0
;
}
//解决日志大于4000写入的问题
if
(
tradeObj
.
params
.
length
>
3980
){
tradeObj
.
params
=
tradeObj
.
params
.
substring
(
0
,
3980
);
}
var
apitrade
=
await
self
.
dao
.
model
.
create
(
tradeObj
,{
transaction
:
t
});
//按照调用方法缓存
await
self
.
cacheManager
[
"ApiCallCountCache"
].
addCallCount
(
tradeObj
.
srcappkey
,
tradeObj
.
op
,
1
);
await
self
.
cacheManager
[
"ApiCallCountCache"
].
addCallBalance
(
tradeObj
.
srcappkey
,
tradeObj
.
op
,
tradeObj
.
amount
);
//累计缓存调用次数和金额
await
self
.
cacheManager
[
"ApiAccuCache"
].
addCallCount
(
tradeObj
.
srcappkey
+
"_"
+
tradeObj
.
destappkey
,
1
);
await
self
.
cacheManager
[
"ApiAccuCache"
].
addCallBalance
(
tradeObj
.
srcappkey
+
"_"
+
tradeObj
.
destappkey
,
tradeObj
.
amount
);
// await self.cacheManager["ApiCircuitBreakers"].addCallCount(-1);
return
apitrade
;
});
}
async
beforesel
(
tradeObj
){
var
self
=
this
;
var
callCaches
=
await
self
.
cacheManager
[
"ApiCircuitBreakers"
].
getApiCall
();
var
calledCounts
=
Number
(
callCaches
.
callcount
);
if
(
calledCounts
>
100
){
// return {status:-1,msg:"服务器繁忙,请稍候再试",data:null};
}
else
{
// await self.cacheManager["ApiCircuitBreakers"].addCallCount(1);
}
var
callCache
=
await
self
.
cacheManager
[
"ApiCircuitBreakerCache"
].
getApiCall
(
tradeObj
.
appkey
);
var
calledCount
=
Number
(
callCache
.
callcount
);
if
(
calledCount
>
1000
){
return
{
status
:
-
1
,
msg
:
"调用次数太多,请稍候再试"
,
data
:
null
};
}
else
{
var
result
=
await
self
.
cacheManager
[
"ApiCircuitBreakerCache"
].
addCallCount
(
tradeObj
.
appkey
,
1
);
}
return
{
status
:
1
,
msg
:
"OK"
};
}
}
module
.
exports
=
ApiTradeService
;
center-manage/app/base/service/impl/common/appSve.js
View file @
5ced773c
...
...
@@ -6,6 +6,7 @@ class AppService extends ServiceBase {
constructor
()
{
super
(
"common"
,
ServiceBase
.
getDaoName
(
AppService
));
this
.
userS
=
system
.
getObject
(
"service.auth.userSve"
);
this
.
routeDao
=
system
.
getObject
(
"db.common.routeDao"
);
}
async
getApp
(
appkey
)
{
return
this
.
cacheManager
[
"AppCache"
].
cache
(
appkey
,
null
);
...
...
@@ -43,20 +44,32 @@ class AppService extends ServiceBase {
return
dicRtn
;
}
//创建应用
//每个应用建立两个路由,一个api路由
//对api路由启用jwt插件
async
create
(
pobj
,
qobj
,
req
)
{
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
console
.
log
(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
)
var
app
=
await
self
.
dao
.
create
(
pobj
,
t
);
//创建后台应用服务
console
.
log
(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
)
let
svobj
=
await
self
.
cjsonregister
(
AppService
.
newServiceUrl
(),{
name
:
app
.
name
,
url
:
"http://"
+
app
.
backend
})
//添加路由
let
routeobj
=
await
self
.
cjsonregister
(
AppService
.
newRouteUrl
(
app
.
name
),{
name
:
app
.
name
,
hosts
:[
app
.
domainName
]})
if
(
svobj
&&
routeobj
){
let
routeapi
=
await
self
.
cjsonregister
(
AppService
.
newRouteUrl
(
app
.
name
),{
name
:
app
.
name
+
"_api"
,
hosts
:[
app
.
domainName
],
paths
:[
"/api"
],
strip_path
:
false
})
let
r1
=
await
self
.
routeDao
.
create
({
name
:
app
.
name
,
center_id
:
routeobj
.
id
},
t
);
let
r2
=
await
self
.
routeDao
.
create
({
name
:
app
.
name
+
"_api"
,
center_id
:
routeapi
.
id
},
t
);
//给api路由启动插件
await
self
.
cjsonregister
(
AppService
.
bindPluginUrl
(
app
.
name
+
"_api"
),{
name
:
"jwt"
})
if
(
svobj
&&
routeobj
&&
r1
&&
r2
){
try
{
app
.
appkey
=
svobj
.
id
;
await
app
.
save
({
transaction
:
t
});
}
catch
(
e
){
await
self
.
cdel
(
AppService
.
routeUrl
(
app
.
name
))
await
self
.
cdel
(
AppService
.
routeUrl
(
app
.
name
+
"_api"
))
await
self
.
cdel
(
AppService
.
serviceUrl
(
app
.
name
))
}
}
else
{
...
...
@@ -72,6 +85,8 @@ class AppService extends ServiceBase {
await
self
.
dao
.
delete
(
pobj
,
t
)
//删除路由
await
self
.
cdel
(
AppService
.
routeUrl
(
pobj
.
name
));
//删除api路由
await
self
.
cdel
(
AppService
.
routeUrl
(
pobj
.
name
+
"_api"
));
//删除服务
await
self
.
cdel
(
AppService
.
serviceUrl
(
pobj
.
name
));
return
{}
...
...
@@ -85,20 +100,20 @@ class AppService extends ServiceBase {
}
}
module
.
exports
=
AppService
;
(
async
()
=>
{
let
u
=
new
AppService
();
// let x=await u.cregister("jiangong")
// console.log(x)
// let x=await u.cunregister("jiangong")
// console.log(x)
// let t=await u.cmakejwt()
// console.log(t)
//let ux=await u.cjsonregister(AppService.newRouteUrl("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.cdel(AppService.routeUrl("test-service2"))
//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
// (async ()=>{
// let u=new AppService();
// // let x=await u.cregister("jiangong")
// // console.log(x)
// // let x=await u.cunregister("jiangong")
// // console.log(x)
// // let t=await u.cmakejwt()
// // console.log(t)
// //let ux=await u.cjsonregister(AppService.newRouteUrl("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.cdel(AppService.routeUrl("test-service2"))
// //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/impl/common/pluginSve.js
0 → 100644
View file @
5ced773c
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
appconfig
=
system
.
getSysConfig
();
class
AppService
extends
ServiceBase
{
constructor
()
{
super
(
"common"
,
ServiceBase
.
getDaoName
(
AppService
));
this
.
userS
=
system
.
getObject
(
"service.auth.userSve"
);
}
async
getApp
(
appkey
)
{
return
this
.
cacheManager
[
"AppCache"
].
cache
(
appkey
,
null
);
}
async
findAllApps
(
uid
)
{
var
apps
=
null
;
var
dicRtn
=
{};
var
wheresql
=
{};
if
(
uid
){
wheresql
[
this
.
db
.
Op
.
and
]
=
{
[
this
.
db
.
Op
.
or
]:
[
{
isPublish
:
false
,
creator_id
:
uid
},
{
isEnabled
:
true
,
isPublish
:
true
}
],
};
apps
=
await
this
.
dao
.
model
.
findAll
({
where
:
wheresql
,
attributes
:
[
'id'
,
'name'
,
'appkey'
,
'showimgUrl'
,
'appType'
,
'docUrl'
,
'homePage'
]
});
}
else
{
wheresql
=
{
isEnabled
:
true
,
isPublish
:
true
};
apps
=
await
this
.
dao
.
model
.
findAll
({
where
:
wheresql
,
attributes
:
[
'id'
,
'name'
,
'appkey'
,
'showimgUrl'
,
'appType'
,
'docUrl'
,
'homePage'
]
});
}
for
(
var
app
of
apps
)
{
var
tmk
=
uiconfig
.
config
.
pdict
.
app_type
[
app
.
appType
];
if
(
!
dicRtn
[
tmk
])
{
dicRtn
[
tmk
]
=
[];
dicRtn
[
tmk
].
push
(
app
);
}
else
{
dicRtn
[
tmk
].
push
(
app
);
}
}
return
dicRtn
;
}
//创建应用
//每个应用建立两个路由,一个api路由
//对api路由启用jwt插件
async
create
(
pobj
,
qobj
,
req
)
{
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
var
app
=
await
self
.
dao
.
create
(
pobj
,
t
);
//创建后台应用服务
let
svobj
=
await
self
.
cjsonregister
(
AppService
.
newServiceUrl
(),{
name
:
app
.
name
,
url
:
"http://"
+
app
.
backend
})
//添加路由
let
routeobj
=
await
self
.
cjsonregister
(
AppService
.
newRouteUrl
(
app
.
name
),{
name
:
app
.
name
,
hosts
:[
app
.
domainName
]})
let
routeapi
=
await
self
.
cjsonregister
(
AppService
.
newRouteUrl
(
app
.
name
),{
name
:
app
.
name
+
"_api"
,
hosts
:[
app
.
domainName
],
paths
:[
"/api"
],
strip_path
:
false
})
//给api路由启动插件
if
(
svobj
&&
routeobj
){
try
{
app
.
appkey
=
svobj
.
id
;
await
app
.
save
({
transaction
:
t
});
}
catch
(
e
){
await
self
.
cdel
(
AppService
.
routeUrl
(
app
.
name
))
await
self
.
cdel
(
AppService
.
routeUrl
(
app
.
name
+
"_api"
))
await
self
.
cdel
(
AppService
.
serviceUrl
(
app
.
name
))
}
}
else
{
throw
new
Error
(
"创建应用服务失败"
);
}
return
app
;
});
}
//删除应用
async
delete
(
pobj
,
qobj
){
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
await
self
.
dao
.
delete
(
pobj
,
t
)
//删除路由
await
self
.
cdel
(
AppService
.
routeUrl
(
pobj
.
name
));
//删除api路由
await
self
.
cdel
(
AppService
.
routeUrl
(
pobj
.
name
+
"_api"
));
//删除服务
await
self
.
cdel
(
AppService
.
serviceUrl
(
pobj
.
name
));
return
{}
})
}
async
findAndCountAll
(
obj
)
{
var
self
=
this
;
const
apps
=
await
super
.
findAndCountAll
(
obj
);
return
apps
;
}
}
module
.
exports
=
AppService
;
// (async ()=>{
// let u=new AppService();
// // let x=await u.cregister("jiangong")
// // console.log(x)
// // let x=await u.cunregister("jiangong")
// // console.log(x)
// // let t=await u.cmakejwt()
// // console.log(t)
// //let ux=await u.cjsonregister(AppService.newRouteUrl("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.cdel(AppService.routeUrl("test-service2"))
// //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/impl/common/routeSve.js
0 → 100644
View file @
5ced773c
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
appconfig
=
system
.
getSysConfig
();
class
RouteService
extends
ServiceBase
{
constructor
()
{
super
(
"common"
,
ServiceBase
.
getDaoName
(
AppService
));
}
//创建应用
//每个应用建立两个路由,一个api路由
//对api路由启用jwt插件
async
create
(
serviceName
,
routedata
,
req
)
{
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
var
rtn
=
null
;
try
{
//添加路由
let
routeobj
=
await
self
.
cjsonregister
(
AppService
.
newRouteUrl
(
serviceName
),
{
name
:
routedata
.
name
,
hosts
:
routedata
.
hosts
,
paths
:
routedata
.
paths
,
strip_path
:
routedata
.
isstrip
})
routedata
.
center_id
=
routeobj
.
id
;
rtn
=
await
self
.
dao
.
create
(
routedata
,
t
);
}
catch
(
e
)
{
await
self
.
cdel
(
AppService
.
routeUrl
(
routedata
.
name
));
}
return
rtn
;
});
}
async
findAndCountAll
(
obj
)
{
var
self
=
this
;
const
apps
=
await
super
.
findAndCountAll
(
obj
);
return
apps
;
}
}
module
.
exports
=
RouteService
;
// (async ()=>{
// let u=new AppService();
// // let x=await u.cregister("jiangong")
// // console.log(x)
// // let x=await u.cunregister("jiangong")
// // console.log(x)
// // let t=await u.cmakejwt()
// // console.log(t)
// //let ux=await u.cjsonregister(AppService.newRouteUrl("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.cdel(AppService.routeUrl("test-service2"))
// //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 @
5ced773c
...
...
@@ -128,6 +128,10 @@ class ServiceBase {
return
null
;
}
}
async
cget
(
opurl
){
let
rtn
=
await
system
.
getReq
(
opurl
)
return
rtn
;
}
async
cjsonregister
(
opurl
,
opts
){
try
{
let
rtn
=
await
system
.
postJsonTypeReq
(
opurl
,
opts
)
...
...
@@ -160,6 +164,9 @@ class ServiceBase {
return
null
;
}
}
static
bindPluginUrl
(
rname
){
return
settings
.
kongurl
+
"routes/"
+
rname
+
"/plugins"
;
}
static
newRouteUrl
(
sname
){
return
settings
.
kongurl
+
"services/"
+
sname
+
"/routes"
;
}
...
...
center-manage/app/base/system.js
View file @
5ced773c
...
...
@@ -40,16 +40,24 @@ class System {
return
promise
;
}
static
async
getReq
(
url
,
qdata
){
let
rtn
=
{}
let
promise
=
new
Promise
(
function
(
resv
,
rej
){
request
.
get
({
url
:
url
,
json
:
true
,
qs
:
qdata
},
function
(
error
,
response
,
body
)
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
resv
(
body
);
}
else
{
rej
(
error
)
}
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
body
){
rtn
.
data
=
body
}
else
{
rtn
.
data
=
null
}
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
})
return
promise
;
...
...
@@ -194,7 +202,6 @@ class System {
//判断文件的存在性
//如果不存在,需要查看packageName
//如果packageName=web.service,dao
//
if
(
System
.
objTable
[
objabspath
]
!=
null
)
{
return
System
.
objTable
[
objabspath
];
}
else
{
...
...
@@ -209,6 +216,9 @@ class System {
let
modelname
=
filename
.
substring
(
0
,
filename
.
lastIndexOf
(
"Dao"
))
return
System
.
register
(
objabspath
,
ClassObj
,
modelname
);
}
if
(
ClassObj
.
name
.
indexOf
(
"Ctl"
)
>=
0
){
console
.
log
(
ClassObj
.
name
);
}
return
System
.
register
(
objabspath
,
ClassObj
,
groupName
,
filename
);
}
}
...
...
center-manage/app/config/environment.js
View file @
5ced773c
...
...
@@ -26,13 +26,6 @@ module.exports = function (app) {
app
.
use
(
function
(
err
,
req
,
res
){
console
.
log
(
"prod error handler................................>>>>>>>>>>>>>>>>>"
);
console
.
log
(
err
);
logCtl
.
error
({
optitle
:
"environment 调用异常error:"
,
op
:
classPath
+
"/"
+
methodName
,
content
:
e
.
toString
(),
clientIp
:
system
.
get_client_ip
(
req
),
agent
:
req
.
headers
[
"user-agent"
],
});
//logerApp.error("prod error handler",err);
res
.
send
(
"link admin"
);
});
...
...
center-manage/app/config/routes/api.js
View file @
5ced773c
...
...
@@ -27,12 +27,13 @@ module.exports = function (app) {
});
});
app
.
post
(
'/api/:gname/:qname/:method'
,
function
(
req
,
res
)
{
//
var classPath = req.params["qname"];
var
classPath
=
req
.
params
[
"qname"
];
var
methodName
=
req
.
params
[
"method"
];
var
gname
=
req
.
params
[
"gname"
];
var
params
=
[];
classPath
=
gname
+
"."
+
classPath
;
console
.
log
(
"===================="
);
console
.
log
(
classPath
);
var
tClientIp
=
System
.
get_client_ip
(
req
);
req
.
clientIp
=
tClientIp
;
req
.
uagent
=
req
.
headers
[
"user-agent"
];
...
...
center-manage/app/config/routes/web.js
View file @
5ced773c
var
url
=
require
(
"url"
);
var
system
=
require
(
"../../base/system"
);
var
metaCtl
=
system
.
getObject
(
"web.common.metaCtl"
);
var
userCtl
=
system
.
getObject
(
"web.auth.userCtl"
);
module
.
exports
=
function
(
app
)
{
app
.
get
(
'/web/:gname/:qname/:method'
,
function
(
req
,
res
)
{
var
classPath
=
req
.
params
[
"qname"
];
...
...
center-manage/app/config/settings.js
View file @
5ced773c
...
...
@@ -16,8 +16,10 @@ var settings = {
salt
:
"%iatpD1gcxz7iF#B"
,
defaultpwd
:
"gsb2020"
,
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
port
:
process
.
env
.
NODE_PORT
||
4001
,
port
:
process
.
env
.
NODE_PORT
||
80
,
kongurl
:
"http://127.0.0.1:8001/"
,
pmappid
:
1
,
pmcompanyid
:
1
,
redis
:
function
(){
if
(
this
.
env
==
"dev"
){
var
localsettings
=
require
(
"./localsettings"
);
...
...
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