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
Show 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 @@
...
@@ -19,8 +19,19 @@
]
]
}
}
],
],
"main"
:
[],
"main"
:
[
"return"
:
[]
{
"type"
:
"common"
,
"service"
:
"user"
,
"function"
:
"getShopVip"
,
"params"
:
[
"context"
,
"session"
,
"activityUserNick"
],
"return"
:
true
}
]
},
},
"getRankList"
:
{
"getRankList"
:
{
"decorators"
:
[
"decorators"
:
[
...
@@ -35,8 +46,30 @@
...
@@ -35,8 +46,30 @@
]
]
}
}
],
],
"main"
:
[],
"main"
:
[
"return"
:
[]
{
"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"
:
{
"task"
:
{
...
...
v2.0/compileServer/templates/controllers/common/user.controller.njk
View file @
baf6d241
...
@@ -4,35 +4,48 @@
...
@@ -4,35 +4,48 @@
import commonDecorator, { services } from '../../decorator/common'
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
import { resultsModel } from '../../sdk'
import { UserService } from '../../service'
import { UserService } from '../../service'
import { formatVipCbUrl, getShopVip } from '../../utils/common/vip'
export interface IVipParams {
export interface IVipParams {
activityId: string
activityId: string
callbackUrl?: string
callbackUrl?: string
inviteId?: 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 {
export default class User {
/**
/**
* 获取会员信息
* 获取会员信息
*/
*/
{{-macro.genDecorator(model.getVipInfo.decorators)}}
{{-macro.genDecorator(model.getVipInfo.decorators)}}
@services([])
{{-macro.genServicesDecorator(model.getVipInfo.main)}}
async getVipInfo(
async getVipInfo(
context: IContext<IVipParams>,
context: IContext<IVipParams>,
{ session, activityUserNick }: IControllerInfos
{ session, activityUserNick }: IControllerInfos,
{{-macro.genServicesParams(model.getVipInfo.main)}}
): Promise<IResult<IVipInfo>> {
): Promise<IResult<IVipInfo>> {
const { callbackUrl } = context.data
{{-macro.genMain(model.getVipInfo.main)}}
// 拼接回调参数
const result = await getShopVip(context, session, callbackUrl || formatVipCbUrl(context), activityUserNick)
return resultsModel.success(result)
{{-macro.genReturn(model.getVipInfo.main)}}
}
}
/**
/**
* 获取排行榜
* 获取排行榜
*/
*/
{{-macro.genDecorator(model.getRankList.decorators)}}
{{-macro.genDecorator(model.getRankList.decorators)}}
@services([UserService])
{{-macro.genServicesDecorator(model.getRankList.main)}}
async getRankList(
async getRankList(
context: IContext<{
context: IContext<{
activityId: string
activityId: string
...
@@ -41,22 +54,10 @@ export default class User {
...
@@ -41,22 +54,10 @@ export default class User {
limit: number
limit: number
}>,
}>,
{ userInfo }: IControllerInfos,
{ userInfo }: IControllerInfos,
[userService]: [UserService]
{{-macro.genServicesParams(model.getRankList.main)}}
) {
) {
const { key, timeKey, limit = 200 } = context.data
{{-macro.genMain(model.getRankList.main)}}
const { userNick, avatar } = userInfo
const rank = await userService.getMyRank(key, timeKey, userInfo[key])
const list = await userService.getRank(key, timeKey, limit)
return resultsModel.success({
{{-macro.genReturn(model.getRankList.main)}}
userNick,
avatar,
rank,
score: userInfo[key],
list
})
}
}
}
}
v2.0/compileServer/templates/macro.njk
View file @
baf6d241
{# 生成控制器引用的服务 #}
{% macro genControllerService(controller)%}
{% endmacro %}
{# 生成装饰器 #}
{% macro genDecorator(decorators) %}
{% macro genDecorator(decorators) %}
{%- for decorator in decorators %}
{%- for decorator in decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([
@{{ decorator.type }}Decorator.{{ decorator.name }}([
...
@@ -5,3 +10,47 @@
...
@@ -5,3 +10,47 @@
])
])
{%- endfor -%}
{%- endfor -%}
{% endmacro %}
{% 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 @@
...
@@ -2,29 +2,47 @@
import
commonDecorator
,
{
services
}
from
'../../decorator/common'
import
commonDecorator
,
{
services
}
from
'../../decorator/common'
import
{
resultsModel
}
from
'../../sdk'
import
{
resultsModel
}
from
'../../sdk'
import
{
UserService
}
from
'../../service'
import
{
UserService
}
from
'../../service'
import
{
formatVipCbUrl
,
getShopVip
}
from
'../../utils/common/vip'
export
interface
IVipParams
{
export
interface
IVipParams
{
activityId
:
string
activityId
:
string
callbackUrl
?:
string
callbackUrl
?:
string
inviteId
?:
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
{
export
default
class
User
{
/**
/**
* 获取会员信息
* 获取会员信息
*/
*/
@
commonDecorator
.
checkParams
([
'activityId'
])
@
commonDecorator
.
checkParams
([
'activityId'
])
@
commonDecorator
.
registeInfos
([
'session'
])
@
commonDecorator
.
registeInfos
([
'session'
])
@
services
([])
@
services
([
UserService
])
async
getVipInfo
(
async
getVipInfo
(
context
:
IContext
<
IVipParams
>
,
context
:
IContext
<
IVipParams
>
,
{
session
,
activityUserNick
}:
IControllerInfos
{
session
,
activityUserNick
}:
IControllerInfos
,
[
userService
]:
[
UserService
]
):
Promise
<
IResult
<
IVipInfo
>>
{
):
Promise
<
IResult
<
IVipInfo
>>
{
const
{
callbackUrl
}
=
context
.
data
const
commonUserGetshopvipResult
=
await
userService
.
getShopVip
(
// 拼接回调参数
context
,
const
result
=
await
getShopVip
(
context
,
session
,
callbackUrl
||
formatVipCbUrl
(
context
),
activityUserNick
)
session
,
activityUserNick
return
resultsModel
.
success
(
result
)
)
return
resultsModel
.
success
({
...
commonUserGetshopvipResult
})
}
}
/**
/**
...
@@ -42,20 +60,19 @@ export default class User {
...
@@ -42,20 +60,19 @@ export default class User {
{
userInfo
}:
IControllerInfos
,
{
userInfo
}:
IControllerInfos
,
[
userService
]:
[
UserService
]
[
userService
]:
[
UserService
]
)
{
)
{
const
{
key
,
timeKey
,
limit
=
200
}
=
context
.
data
const
commonUserGetmyrankinfoResult
=
await
userService
.
getMyRankInfo
(
context
.
data
.
key
,
const
{
userNick
,
avatar
}
=
userInfo
context
.
data
.
timeKey
,
userInfo
const
rank
=
await
userService
.
getMyRank
(
key
,
timeKey
,
userInfo
[
key
])
)
const
commonUserGetrankResult
=
await
userService
.
getRank
(
const
list
=
await
userService
.
getRank
(
key
,
timeKey
,
limit
)
context
.
data
.
key
,
context
.
data
.
timeKey
,
context
.
data
.
limit
)
return
resultsModel
.
success
({
return
resultsModel
.
success
({
userNick
,
...
commonUserGetmyrankinfoResult
,
avatar
,
...
commonUserGetrankResult
rank
,
score
:
userInfo
[
key
],
list
})
})
}
}
}
}
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