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
24e3e9b8
Commit
24e3e9b8
authored
Jul 21, 2020
by
sxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 渠道
parent
497a5fa6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
77 deletions
+112
-77
center-manage/app/base/controller/impl/common/channelCtl.js
+9
-1
center-manage/app/base/db/cache/userCache.js
+15
-1
center-manage/app/base/db/models/common/channel.js
+48
-44
center-manage/app/base/service/impl/common/channelSve.js
+40
-31
No files found.
center-manage/app/base/controller/impl/common/channelCtl.js
View file @
24e3e9b8
...
@@ -8,8 +8,16 @@ class ChannelCtl extends CtlBase {
...
@@ -8,8 +8,16 @@ class ChannelCtl extends CtlBase {
super
(
"common"
,
CtlBase
.
getServiceName
(
ChannelCtl
));
super
(
"common"
,
CtlBase
.
getServiceName
(
ChannelCtl
));
}
}
async
refQuery
(
pobj
,
qobj
,
req
)
{
async
refQuery
(
pobj
,
qobj
,
req
)
{
let
rtn
=
await
this
.
service
.
refQuery
(
pobj
);
let
rtn
=
await
this
.
service
.
refQuery
(
pobj
);
return
rtn
return
rtn
}
}
async
authorizeUser
(
pobj
,
qobj
,
req
)
{
if
(
!
pobj
.
channelId
)
{
return
system
.
getResult
(
null
,
"channelId can not be empty,100290"
);
}
await
this
.
service
.
authorizeUser
(
pobj
);
return
system
.
getResult
(
"SUCCESS"
);
}
}
}
module
.
exports
=
ChannelCtl
;
module
.
exports
=
ChannelCtl
;
center-manage/app/base/db/cache/userCache.js
View file @
24e3e9b8
...
@@ -5,6 +5,7 @@ class UserCache extends CacheBase {
...
@@ -5,6 +5,7 @@ class UserCache extends CacheBase {
constructor
()
{
constructor
()
{
super
();
super
();
this
.
userDao
=
system
.
getObject
(
"db.auth.userDao"
);
this
.
userDao
=
system
.
getObject
(
"db.auth.userDao"
);
this
.
channelDao
=
system
.
getObject
(
"db.common.channelDao"
);
}
}
isdebug
()
{
isdebug
()
{
return
settings
.
env
==
"dev"
;
return
settings
.
env
==
"dev"
;
...
@@ -26,7 +27,20 @@ class UserCache extends CacheBase {
...
@@ -26,7 +27,20 @@ class UserCache extends CacheBase {
});
});
if
(
configValue
&&
configValue
[
0
])
{
if
(
configValue
&&
configValue
[
0
])
{
return
JSON
.
stringify
(
configValue
[
0
]);
let
data
=
JSON
.
parse
(
JSON
.
stringify
(
configValue
[
0
]));
let
channelDatas
=
await
this
.
channelDao
.
findAll
({});
channelDatas
=
JSON
.
parse
(
JSON
.
stringify
(
channelDatas
));
channelDatas
.
forEach
(
item
=>
{
if
(
item
.
userids
&&
item
.
userids
.
split
(
","
).
includes
(
data
.
id
.
toString
()))
{
data
.
channel
=
{
id
:
item
.
id
,
code
:
item
.
code
,
name
:
item
.
name
}
}
});
// 获取渠道信息
return
JSON
.
stringify
(
data
);
}
}
return
null
;
return
null
;
}
}
...
...
center-manage/app/base/db/models/common/channel.js
View file @
24e3e9b8
const
system
=
require
(
"../../../system"
);
const
system
=
require
(
"../../../system"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
appconfig
=
system
.
getSysConfig
();
const
appconfig
=
system
.
getSysConfig
();
module
.
exports
=
(
db
,
DataTypes
)
=>
{
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"channel"
,
{
return
db
.
define
(
"channel"
,
{
code
:{
code
:
{
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
allowNull
:
false
,
},
},
...
@@ -14,48 +14,52 @@ module.exports = (db, DataTypes) => {
...
@@ -14,48 +14,52 @@ module.exports = (db, DataTypes) => {
routehost
:
{
routehost
:
{
type
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
allowNull
:
false
,
}
//和user的from相同,在注册user时,去创建
},
//和user的from相同,在注册user时,去创建
userids
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
true
,
},
},
{
},
{
paranoid
:
true
,
//假的删除
paranoid
:
true
,
//假的删除
underscored
:
true
,
underscored
:
true
,
version
:
true
,
version
:
true
,
freezeTableName
:
true
,
freezeTableName
:
true
,
//freezeTableName: true,
//freezeTableName: true,
// define the table's name
// define the table's name
tableName
:
'p_channel'
,
tableName
:
'p_channel'
,
validate
:
{
validate
:
{
},
},
indexes
:
[
indexes
:
[
// Create a unique index on email
// Create a unique index on email
// {
// {
// unique: true,
// unique: true,
// fields: ['email']
// fields: ['email']
// },
// },
//
//
// // Creates a gin index on data with the jsonb_path_ops operator
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// {
// fields: ['data'],
// fields: ['data'],
// using: 'gin',
// using: 'gin',
// operator: 'jsonb_path_ops'
// operator: 'jsonb_path_ops'
// },
// },
//
//
// // By default index name will be [table]_[fields]
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// // Creates a multi column partial index
// {
// {
// name: 'public_by_author',
// name: 'public_by_author',
// fields: ['author', 'status'],
// fields: ['author', 'status'],
// where: {
// where: {
// status: 'public'
// status: 'public'
// }
// }
// },
// },
//
//
// // A BTREE index with a ordered field
// // A BTREE index with a ordered field
// {
// {
// name: 'title_index',
// name: 'title_index',
// method: 'BTREE',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
// }
]
]
});
});
}
}
center-manage/app/base/service/impl/common/channelSve.js
View file @
24e3e9b8
...
@@ -5,71 +5,79 @@ const appconfig = system.getSysConfig();
...
@@ -5,71 +5,79 @@ const appconfig = system.getSysConfig();
class
ChannelService
extends
ServiceBase
{
class
ChannelService
extends
ServiceBase
{
constructor
()
{
constructor
()
{
super
(
"common"
,
ServiceBase
.
getDaoName
(
ChannelService
));
super
(
"common"
,
ServiceBase
.
getDaoName
(
ChannelService
));
this
.
handlers
=
{}
this
.
handlers
=
{}
}
}
async
channelHandle
(
channelobj
,
path
,
datajson
)
{
async
channelHandle
(
channelobj
,
path
,
datajson
)
{
let
p
=
channelobj
.
pts
.
filter
(
item
=>
{
let
p
=
channelobj
.
pts
.
filter
(
item
=>
{
return
item
.
path
==
path
return
item
.
path
==
path
})
})
if
(
p
.
length
==
0
)
{
if
(
p
.
length
==
0
)
{
throw
Error
(
"请配置渠道流量的路径方法映射"
)
throw
Error
(
"请配置渠道流量的路径方法映射"
)
}
}
let
fileName
=
channelobj
.
code
let
fileName
=
channelobj
.
code
let
method
=
p
[
0
].
method
let
method
=
p
[
0
].
method
if
(
!
this
.
handlers
[
fileName
])
{
if
(
!
this
.
handlers
[
fileName
])
{
this
.
handlers
[
fileName
]
=
require
(
"./channelhandlers/"
+
fileName
+
".js"
)
this
.
handlers
[
fileName
]
=
require
(
"./channelhandlers/"
+
fileName
+
".js"
)
}
}
if
(
!
this
.
handlers
[
fileName
][
method
])
{
if
(
!
this
.
handlers
[
fileName
][
method
])
{
throw
Error
(
`请在
${
fileName
}
文件中定义渠道流量的处理方法
${
method
}
`
)
throw
Error
(
`请在
${
fileName
}
文件中定义渠道流量的处理方法
${
method
}
`
)
}
}
let
rtn
=
await
this
.
handlers
[
fileName
][
method
](
datajson
);
let
rtn
=
await
this
.
handlers
[
fileName
][
method
](
datajson
);
return
rtn
;
return
rtn
;
}
}
async
create
(
p
,
q
,
req
)
{
async
create
(
p
,
q
,
req
)
{
let
self
=
this
let
self
=
this
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
try
{
try
{
let
ps
=
[
"/"
]
let
ps
=
[
"/"
]
let
routeobj
=
await
self
.
cjsonregister
(
ChannelService
.
newRouteUrl
(
settings
.
pmappname
),
let
routeobj
=
await
self
.
cjsonregister
(
ChannelService
.
newRouteUrl
(
settings
.
pmappname
),
{
name
:
p
.
code
,
paths
:
ps
,
hosts
:
[
p
.
routehost
],
strip_path
:
false
})
{
name
:
p
.
code
,
paths
:
ps
,
hosts
:
[
p
.
routehost
],
strip_path
:
false
})
}
catch
(
e
)
{
}
catch
(
e
)
{
await
self
.
cdel
(
ChannelService
.
routeUrl
(
p
.
code
))
await
self
.
cdel
(
ChannelService
.
routeUrl
(
p
.
code
))
throw
new
Error
(
"创建渠道报错"
)
throw
new
Error
(
"创建渠道报错"
)
}
}
return
u
return
u
})
})
}
}
async
update
(
p
,
q
,
req
)
{
async
update
(
p
,
q
,
req
)
{
let
self
=
this
let
self
=
this
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
let
old
=
await
self
.
dao
.
findOne
({
id
:
p
.
id
})
let
old
=
await
self
.
dao
.
findOne
({
id
:
p
.
id
})
let
u
=
await
self
.
dao
.
update
(
p
,
t
)
let
u
=
await
self
.
dao
.
update
(
p
,
t
)
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
try
{
try
{
await
self
.
cdel
(
ChannelService
.
routeUrl
(
old
.
code
))
await
self
.
cdel
(
ChannelService
.
routeUrl
(
old
.
code
))
let
ps
=
[
"/"
]
let
ps
=
[
"/"
]
let
routeobj
=
await
self
.
cjsonregister
(
ChannelService
.
newRouteUrl
(
settings
.
pmappname
),
let
routeobj
=
await
self
.
cjsonregister
(
ChannelService
.
newRouteUrl
(
settings
.
pmappname
),
{
name
:
p
.
code
,
paths
:
ps
,
hosts
:
[
p
.
routehost
],
strip_path
:
false
})
{
name
:
p
.
code
,
paths
:
ps
,
hosts
:
[
p
.
routehost
],
strip_path
:
false
})
}
catch
(
e
)
{
}
catch
(
e
)
{
throw
new
Error
(
"创建渠道报错"
)
throw
new
Error
(
"创建渠道报错"
)
}
}
return
u
return
u
})
})
}
}
async
delete
(
p
,
q
,
req
)
{
async
delete
(
p
,
q
,
req
)
{
let
self
=
this
let
self
=
this
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
let
u
=
await
self
.
dao
.
delete
(
p
,
t
)
let
u
=
await
self
.
dao
.
delete
(
p
,
t
)
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
try
{
try
{
await
self
.
cdel
(
ChannelService
.
routeUrl
(
u
.
code
))
await
self
.
cdel
(
ChannelService
.
routeUrl
(
u
.
code
))
}
catch
(
e
)
{
}
catch
(
e
)
{
throw
new
Error
(
"创建渠道报错"
)
throw
new
Error
(
"创建渠道报错"
)
}
}
return
u
return
u
})
})
}
}
async
authorizeUser
(
p
,
q
,
req
)
{
await
this
.
dao
.
updateByWhere
({
userids
:
p
.
userids
},
{
id
:
p
.
channelId
})
}
}
}
module
.
exports
=
ChannelService
;
module
.
exports
=
ChannelService
;
\ No newline at end of file
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