Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinhaitao
taobao-mini-template
Commits
baf6d241
Commit
baf6d241
authored
Nov 04, 2020
by
maggie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save
parent
13e4acfb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
149 additions
and
49 deletions
+149
-49
config.json
v2.0/compileServer/config.json
+37
-4
user.controller.njk
...leServer/templates/controllers/common/user.controller.njk
+24
-23
macro.njk
v2.0/compileServer/templates/macro.njk
+50
-1
user.controller.ts
v2.0/src/controller/common/user.controller.ts
+38
-21
No files found.
v2.0/compileServer/config.json
View file @
baf6d241
...
...
@@ -19,8 +19,19 @@
]
}
],
"main"
:
[],
"return"
:
[]
"main"
:
[
{
"type"
:
"common"
,
"service"
:
"user"
,
"function"
:
"getShopVip"
,
"params"
:
[
"context"
,
"session"
,
"activityUserNick"
],
"return"
:
true
}
]
},
"getRankList"
:
{
"decorators"
:
[
...
...
@@ -35,8 +46,30 @@
]
}
],
"main"
:
[],
"return"
:
[]
"main"
:
[
{
"type"
:
"common"
,
"service"
:
"user"
,
"function"
:
"getMyRankInfo"
,
"params"
:
[
"context.data.key"
,
"context.data.timeKey"
,
"userInfo"
],
"return"
:
true
},
{
"type"
:
"common"
,
"service"
:
"user"
,
"function"
:
"getRank"
,
"params"
:
[
"context.data.key"
,
"context.data.timeKey"
,
"context.data.limit"
],
"return"
:
true
}
]
}
},
"task"
:
{
...
...
v2.0/compileServer/templates/controllers/common/user.controller.njk
View file @
baf6d241
...
...
@@ -4,35 +4,48 @@
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
import { UserService } from '../../service'
import { formatVipCbUrl, getShopVip } from '../../utils/common/vip'
export interface IVipParams {
activityId: string
callbackUrl?: string
inviteId?: string // 需要助力回调时请求该接口
}
interface IRankList {
userNick: string
avatar: string
score: any
rank: number
}
export interface IRankResult {
rank: number
userNick: string
avatar: string
score: number
list: IRankList[]
}
export default class User {
/**
* 获取会员信息
*/
{{-macro.genDecorator(model.getVipInfo.decorators)}}
@services([])
{{-macro.genServicesDecorator(model.getVipInfo.main)}}
async getVipInfo(
context: IContext<IVipParams>,
{ session, activityUserNick }: IControllerInfos
{ session, activityUserNick }: IControllerInfos,
{{-macro.genServicesParams(model.getVipInfo.main)}}
): Promise<IResult<IVipInfo>> {
const { callbackUrl } = context.data
// 拼接回调参数
const result = await getShopVip(context, session, callbackUrl || formatVipCbUrl(context), activityUserNick)
{{-macro.genMain(model.getVipInfo.main)}}
return resultsModel.success(result)
{{-macro.genReturn(model.getVipInfo.main)}}
}
/**
* 获取排行榜
*/
{{-macro.genDecorator(model.getRankList.decorators)}}
@services([UserService])
{{-macro.genServicesDecorator(model.getRankList.main)}}
async getRankList(
context: IContext<{
activityId: string
...
...
@@ -41,22 +54,10 @@ export default class User {
limit: number
}>,
{ userInfo }: IControllerInfos,
[userService]: [UserService]
{{-macro.genServicesParams(model.getRankList.main)}}
) {
const { key, timeKey, limit = 200 } = context.data
const { userNick, avatar } = userInfo
const rank = await userService.getMyRank(key, timeKey, userInfo[key])
const list = await userService.getRank(key, timeKey, limit)
{{-macro.genMain(model.getRankList.main)}}
return resultsModel.success({
userNick,
avatar,
rank,
score: userInfo[key],
list
})
{{-macro.genReturn(model.getRankList.main)}}
}
}
v2.0/compileServer/templates/macro.njk
View file @
baf6d241
{# 生成控制器引用的服务 #}
{% macro genControllerService(controller)%}
{% endmacro %}
{# 生成装饰器 #}
{% macro genDecorator(decorators) %}
{%- for decorator in decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([
{%- for param in decorator.params -%}'{{ param }}'{%- if loop.last %}{% else %}, {% endif %}{%- endfor -%}
])
{%- endfor -%}
{% endmacro %}
\ No newline at end of file
{% endmacro %}
{# 生成services装饰器 #}
{% macro genServicesDecorator(mains) %}
@services([
{%- for service, main in mains|groupby("service") -%}
{{ service | capitalize }}Service{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
])
{%- endmacro %}
{# 生成services参数 #}
{% macro genServicesParams(mains) %}
[
{%- for service, main in mains|groupby("service") -%}
{{ service }}Service{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
]: [
{%- for service, main in mains|groupby("service") -%}
{{ service | capitalize }}Service{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
]
{%- endmacro %}
{# 生成函数体 #}
{% macro genMain(mains) %}
{%- for main in mains %}
const {{main.type}}{{main.service|capitalize}}{{main.function|capitalize}}Result = await {{main.service}}Service.{{main.function}}(
{%- for param in main.params %}
{{param}}{% if loop.last %}{% else %},{% endif %}
{%- endfor %}
)
{%- endfor -%}
{%- endmacro %}
{# 生成return结果 #}
{% macro genReturn(mains) %}
return resultsModel.success({
{%- for main in mains -%}
{% if main.return %}
...{{main.type}}{{main.service|capitalize}}{{main.function|capitalize}}Result{% if loop.last %}{% else %},{% endif %}
{%- endif -%}
{%- endfor %}
})
{%- endmacro%}
\ No newline at end of file
v2.0/src/controller/common/user.controller.ts
View file @
baf6d241
...
...
@@ -2,29 +2,47 @@
import
commonDecorator
,
{
services
}
from
'../../decorator/common'
import
{
resultsModel
}
from
'../../sdk'
import
{
UserService
}
from
'../../service'
import
{
formatVipCbUrl
,
getShopVip
}
from
'../../utils/common/vip'
export
interface
IVipParams
{
activityId
:
string
callbackUrl
?:
string
inviteId
?:
string
// 需要助力回调时请求该接口
}
interface
IRankList
{
userNick
:
string
avatar
:
string
score
:
any
rank
:
number
}
export
interface
IRankResult
{
rank
:
number
userNick
:
string
avatar
:
string
score
:
number
list
:
IRankList
[]
}
export
default
class
User
{
/**
* 获取会员信息
*/
@
commonDecorator
.
checkParams
([
'activityId'
])
@
commonDecorator
.
registeInfos
([
'session'
])
@
services
([])
@
services
([
UserService
])
async
getVipInfo
(
context
:
IContext
<
IVipParams
>
,
{
session
,
activityUserNick
}:
IControllerInfos
{
session
,
activityUserNick
}:
IControllerInfos
,
[
userService
]:
[
UserService
]
):
Promise
<
IResult
<
IVipInfo
>>
{
const
{
callbackUrl
}
=
context
.
data
// 拼接回调参数
const
result
=
await
getShopVip
(
context
,
session
,
callbackUrl
||
formatVipCbUrl
(
context
),
activityUserNick
)
return
resultsModel
.
success
(
result
)
const
commonUserGetshopvipResult
=
await
userService
.
getShopVip
(
context
,
session
,
activityUserNick
)
return
resultsModel
.
success
({
...
commonUserGetshopvipResult
})
}
/**
...
...
@@ -42,20 +60,19 @@ export default class User {
{
userInfo
}:
IControllerInfos
,
[
userService
]:
[
UserService
]
)
{
const
{
key
,
timeKey
,
limit
=
200
}
=
context
.
data
const
{
userNick
,
avatar
}
=
userInfo
const
rank
=
await
userService
.
getMyRank
(
key
,
timeKey
,
userInfo
[
key
])
const
list
=
await
userService
.
getRank
(
key
,
timeKey
,
limit
)
const
commonUserGetmyrankinfoResult
=
await
userService
.
getMyRankInfo
(
context
.
data
.
key
,
context
.
data
.
timeKey
,
userInfo
)
const
commonUserGetrankResult
=
await
userService
.
getRank
(
context
.
data
.
key
,
context
.
data
.
timeKey
,
context
.
data
.
limit
)
return
resultsModel
.
success
({
userNick
,
avatar
,
rank
,
score
:
userInfo
[
key
],
list
...
commonUserGetmyrankinfoResult
,
...
commonUserGetrankResult
})
}
}
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