Commit 897acef5 authored by maggie's avatar maggie

save

parent d4474579
......@@ -340,6 +340,136 @@
]
}
}
},
"custom": {
"test1": {
"addStat": {
"desc": "增加埋点记录",
"decorators": [
{
"type": "common",
"name": "checkParams",
"params": [
"activityId",
"type"
]
}
],
"main": [
{
"type": "common",
"service": "stat",
"function": "addStat",
"params": [
{ "type": "var", "value": "context.data.type" },
{ "type": "var", "value": "userInfo" }
],
"return": true
}
]
},
"getStats": {
"desc": "统计数据",
"decorators": [
{
"type": "common",
"name": "checkParams",
"params": [
"activityId",
"startDay",
"endDay"
]
}
],
"main": [
{
"type": "common",
"service": "stat",
"function": "getStats",
"params": [
{ "type": "var", "value": "context.data.activityId" },
{ "type": "var", "value": "context.data.startDay" },
{ "type": "var", "value": "context.data.endDay" }
]
},
{
"type": "common",
"service": "stat",
"function": "buildExcel",
"params": [
{ "type": "var", "value": "context.data.startDay" },
{ "type": "var", "value": "context.data.endDay" },
{ "type": "var", "value": "commonStatGetstatsResult1" }
],
"return": true
}
]
}
},
"test2": {
"addStat": {
"desc": "增加埋点记录",
"decorators": [
{
"type": "common",
"name": "checkParams",
"params": [
"activityId",
"type"
]
}
],
"main": [
{
"type": "common",
"service": "stat",
"function": "addStat",
"params": [
{ "type": "var", "value": "context.data.type" },
{ "type": "var", "value": "userInfo" }
],
"return": true
}
]
},
"getStats": {
"desc": "统计数据",
"decorators": [
{
"type": "common",
"name": "checkParams",
"params": [
"activityId",
"startDay",
"endDay"
]
}
],
"main": [
{
"type": "common",
"service": "stat",
"function": "getStats",
"params": [
{ "type": "var", "value": "context.data.activityId" },
{ "type": "var", "value": "context.data.startDay" },
{ "type": "var", "value": "context.data.endDay" }
]
},
{
"type": "common",
"service": "stat",
"function": "buildExcel",
"params": [
{ "type": "var", "value": "context.data.startDay" },
{ "type": "var", "value": "context.data.endDay" },
{ "type": "var", "value": "commonStatGetstatsResult1" }
],
"return": true
}
]
}
}
}
}
}
\ No newline at end of file
......@@ -4,40 +4,70 @@ const fs = require('fs-extra')
const config = require('./config.json')
const serverTemplatePath = 'templates'
const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
//生成控制器service
const controllerServices = {
common: {},
custom: {}
}
//通用控制器
for (let commonController in config.controllers.common) {
controllerServices.common[commonController] = {}
for (let fn in config.controllers.common[commonController]) {
for (let main of config.controllers.common[commonController][fn].main) {
if (!controllerServices.common[commonController][main.type]) {
controllerServices.common[commonController][main.type] = {}
}
controllerServices.common[commonController][main.type][main.service] = true
const controllerImport = (controller = {}) => {
const result = {
service: {}
}
for (let fn in controller) {
for (let main of controller[fn].main) {
result.service[main.service] = true
}
}
console.log(result)
return result
}
const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
// //生成控制器service
// const controllerServices = {
// common: {},
// custom: {}
// }
// for (let customController in config.controllers.common) {
// controllerServices.common[commonController] = {}
// for (let fn in config.controllers.common[commonController]) {
// for (let main of config.controllers.common[commonController][fn].main) {
// if (!controllerServices.common[commonController][main.type]) {
// controllerServices.common[commonController][main.type] = {}
// }
// controllerServices.common[commonController][main.type][main.service] = true
// }
// }
// }
//编译controller.common
for (let commonController in config.controllers.common) {
await gulp
.src(`${serverTemplatePath}/controllers/common/${commonController}.controller.njk`)
.src(`${serverTemplatePath}/controller.njk`)
.pipe(
nunjucksRender({
...nunjucksRenderConfig,
data: {
name: commonController,
model: config.controllers.common[commonController],
service: controllerServices.common[commonController]
...controllerImport(config.controllers.common[commonController])
}
})
)
.pipe(rename(`${commonController}.controller.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/controller/common'))
}
//编译controller.custom
for (let customController in config.controllers.custom) {
await gulp
.src(`${serverTemplatePath}/controller.njk`)
.pipe(
nunjucksRender({
...nunjucksRenderConfig,
data: {
name: customController,
model: config.controllers.custom[customController],
...controllerImport(config.controllers.custom[customController])
}
})
)
.pipe(rename(`${customController}.controller.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/controller/custom'))
}
}
module.exports = {
......
......@@ -5,9 +5,9 @@ import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)}}
{{-macro.genControllerService(service)-}}
export default class Stat {
export default class {{name | capitalize}}Controller {
{%- for fn, item in model %}
/**
* {{item.desc}}
......
/** @format */
{% import "macro.njk" as macro -%}
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)}}
export default class Task {
{%- for fn, item in model %}
/**
* {{item.desc}}
*/
{{-macro.genDecorator(model[fn].decorators)}}
@services([{{-macro.genServicesDecorator(model[fn].main)}}])
async {{fn}}(
context: IContext<IParams>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model[fn].decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model[fn].main)}}
) {
{{-macro.genMain(model[fn].main)}}
{{-macro.genReturn(model[fn].main)}}
}
{%- endfor %}
}
/** @format */
{% import "macro.njk" as macro -%}
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)}}
export default class User {
{%- for fn, item in model %}
/**
* {{item.desc}}
*/
{{-macro.genDecorator(model[fn].decorators)}}
@services([{{-macro.genServicesDecorator(model[fn].main)}}])
async {{fn}}(
context: IContext<IParams>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model[fn].decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model[fn].main)}}
) {
{{-macro.genMain(model[fn].main)}}
{{-macro.genReturn(model[fn].main)}}
}
{%- endfor %}
}
/** @format */
{# {% import "macro.njk" as macro -%} #}
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
{# {{-macro.genControllerService(service)}} #}
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>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model.getVipInfo.decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model.getVipInfo.main)}}
): Promise<IResult<IVipInfo>> {
{{-macro.genMain(model.getVipInfo.main)}}
{{-macro.genReturn(model.getVipInfo.main)}}
}
/**
* 获取排行榜
*/
{{-macro.genDecorator(model.getRankList.decorators)}}
@services([{{-macro.genServicesDecorator(model.getRankList.main)}}])
async getRankList(
context: IContext<{
activityId: string
key: string // 排序的key值 如 score
timeKey: string // 排序时间的key值 如:updateScoreTime
limit: number
}>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model.getRankList.decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model.getRankList.main)}}
) {
{{-macro.genMain(model.getRankList.main)}}
{{-macro.genReturn(model.getRankList.main)}}
}
} #}
\ No newline at end of file
{# 生成控制器引用的服务 #}
{% macro genControllerService(service)%}
{%- for type, item1 in service %}
import { {% for s, item2 in item1 %}{{s | capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}{% endfor %} } from '../../service'
{%- endfor -%}
import { {% for key, item in service %}{{key | capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}{%- endfor %} } from '../../service'
{% endmacro %}
{# 生成装饰器 #}
......
......@@ -4,8 +4,7 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
import { StatService } from '../../service'
export default class Stat {
export default class StatController {
/**
* 增加埋点记录
*/
......
......@@ -4,8 +4,7 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
import { TaskService, BaseService } from '../../service'
export default class Task {
export default class TaskController {
/**
* 任务列表
*/
......
......@@ -4,8 +4,7 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
import { UserService } from '../../service'
export default class User {
export default class UserController {
/**
* 获取会员信息
*/
......
/** @format */
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
import { StatService } from '../../service'
export default class Test1Controller {
/**
* 增加埋点记录
*/
@commonDecorator.checkParams(['activityId', 'type'])
@services([StatService])
async addStat(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[statService]: [StatService]
) {
const commonStatAddstatResult1 = await statService.addStat(context.data.type, userInfo)
return resultsModel.success({
...commonStatAddstatResult1
})
}
/**
* 统计数据
*/
@commonDecorator.checkParams(['activityId', 'startDay', 'endDay'])
@services([StatService])
async getStats(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[statService]: [StatService]
) {
const commonStatGetstatsResult1 = await statService.getStats(context.data.activityId, context.data.startDay, context.data.endDay)
const commonStatBuildexcelResult2 = await statService.buildExcel(context.data.startDay, context.data.endDay, commonStatGetstatsResult1)
return resultsModel.success({
...commonStatBuildexcelResult2
})
}
}
/** @format */
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
import { StatService } from '../../service'
export default class Test2Controller {
/**
* 增加埋点记录
*/
@commonDecorator.checkParams(['activityId', 'type'])
@services([StatService])
async addStat(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[statService]: [StatService]
) {
const commonStatAddstatResult1 = await statService.addStat(context.data.type, userInfo)
return resultsModel.success({
...commonStatAddstatResult1
})
}
/**
* 统计数据
*/
@commonDecorator.checkParams(['activityId', 'startDay', 'endDay'])
@services([StatService])
async getStats(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[statService]: [StatService]
) {
const commonStatGetstatsResult1 = await statService.getStats(context.data.activityId, context.data.startDay, context.data.endDay)
const commonStatBuildexcelResult2 = await statService.buildExcel(context.data.startDay, context.data.endDay, commonStatGetstatsResult1)
return resultsModel.success({
...commonStatBuildexcelResult2
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment