Commit b0b39561 authored by maggie's avatar maggie

修改service编译方式

parent 59323d0c
......@@ -268,7 +268,7 @@
"service": "task",
"function": "getItemListWithCollectStatus",
"params": [
{ "type": "var", "value": "commonBaseGetitemlistbyidsResult1" },
{ "type": "var", "value": "commonBaseGetItemListByIdsResult1" },
{ "type": "var", "value": "userInfo" }
],
"return": true
......@@ -333,7 +333,7 @@
"params": [
{ "type": "var", "value": "context.data.startDay" },
{ "type": "var", "value": "context.data.endDay" },
{ "type": "var", "value": "commonStatGetstatsResult1" }
{ "type": "var", "value": "commonStatGetStatsResult1" }
],
"return": true
}
......@@ -415,7 +415,7 @@
"params": [
{ "type": "var", "value": "context.data.startDay" },
{ "type": "var", "value": "context.data.endDay" },
{ "type": "var", "value": "commonStatGetstatsResult1" }
{ "type": "var", "value": "commonStatGetStatsResult1" }
],
"return": true
}
......
......@@ -6,11 +6,14 @@ const serverTemplatePath = 'templates'
const controllerImport = (controller = {}) => {
const result = {
service: {}
services: {}
}
for (let fn in controller) {
for (let main of controller[fn].main) {
result.service[main.service] = true
if (!result.services[main.type]) {
result.services[main.type] = {}
}
result.services[main.type][main.service] = true
}
}
console.log(result)
......
......@@ -12,6 +12,8 @@ export default {
{{type}}{{controller | capitalize}}{{function | capitalize}}: {{type | capitalize}}{{controller | capitalize}}ControllerInstance.{{function}}
{%-if loop.last-%}{%else%},{%-endif-%}
{%- endfor -%}
{%-if loop.last-%}{%else%},{%-endif-%}
{%- endfor -%}
{%-if loop.last-%}{%else%},{%-endif-%}
{%- endfor %}
}
......@@ -6,10 +6,10 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import customUtil from '../../utils/custom'
import commonService from '../../service/common'
import customService from '../../service/custom'
{# import commonService from '../../service/common'
import customService from '../../service/custom' #}
import { resultsModel } from '../../sdk'
{# {{-macro.genControllerService(service)-}} #}
{{-macro.genControllerService(services)-}}
export default class {{name | capitalize}}Controller {
{%- for fn, item in model %}
......
{# 生成控制器引用的服务 #}
{% macro genControllerService(service)%}
import { {% for key, item in service %}{{key | capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}{%- endfor %} } from '../../service'
{% macro genControllerService(services)%}
{% for type, type_item in services %}
import { {%for service, service_item in type_item %}{{type|capitalize}}{{service|capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}{% endfor %} } from '../../service/{{type}}'
{% endfor%}
{% endmacro %}
{# 生成装饰器 #}
......@@ -20,7 +22,7 @@ import { {% for key, item in service %}{{key | capitalize}}Service{%- if loop.la
{% macro genServicesDecorator(mains) %}
{%- for type, type_item in mains | groupByTypeAndService -%}
{%- for service, service_item in type_item -%}
{{type}}Service.{{service|capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}
{{type|capitalize}}{{service|capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
......@@ -38,7 +40,7 @@ import { {% for key, item in service %}{{key | capitalize}}Service{%- if loop.la
]: [
{%- for type, type_item in mains | groupByTypeAndService -%}
{%- for service, service_item in type_item -%}
{{type}}Service.{{service|capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}
{{type|capitalize}}{{service|capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
......
/** @format */
{%- for service, service_item in services %}
import {{ service | capitalize }}Service from './{{ service }}.service'
import Custom{{ service | capitalize }}Service from './{{ service }}.service'
{%- endfor %}
const common = {
const custom = {
{%- for service, service_item in services %}
{{ service | capitalize }}Service{% if loop.last %}{%else%},{% endif %}
Custom{{ service | capitalize }}Service{% if loop.last %}{%else%},{% endif %}
{%- endfor %}
}
export default common
export default custom
export {
{%- for service, service_item in services %}
{{ service | capitalize }}Service{% if loop.last %}{%else%},{% endif %}
Custom{{ service | capitalize }}Service{% if loop.last %}{%else%},{% endif %}
{%- endfor %}
}
......@@ -4,21 +4,21 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import customUtil from '../../utils/custom'
import commonService from '../../service/common'
import customService from '../../service/custom'
import { resultsModel } from '../../sdk'
import { CommonStatService } from '../../service/common'
export default class StatController {
/**
* 增加埋点记录
*/
@commonDecorator.checkParams(['activityId', 'type'])
@services([commonService.StatService])
@services([CommonStatService])
async addStat(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonStatService]: [commonService.StatService]
[commonStatService]: [CommonStatService]
) {
const commonStatAddStatResult1 = await commonStatService.addStat(context.data.type, userInfo)
return resultsModel.success({
......@@ -29,14 +29,14 @@ export default class StatController {
* 统计数据
*/
@commonDecorator.checkParams(['activityId', 'startDay', 'endDay'])
@services([commonService.StatService])
@services([CommonStatService])
async getStats(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonStatService]: [commonService.StatService]
[commonStatService]: [CommonStatService]
) {
const commonStatGetStatsResult1 = await commonStatService.getStats(context.data.activityId, context.data.startDay, context.data.endDay)
const commonStatBuildExcelResult2 = await commonStatService.buildExcel(context.data.startDay, context.data.endDay, commonStatGetstatsResult1)
const commonStatBuildExcelResult2 = await commonStatService.buildExcel(context.data.startDay, context.data.endDay, commonStatGetStatsResult1)
return resultsModel.success({
...commonStatBuildExcelResult2
})
......
......@@ -4,10 +4,10 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import customUtil from '../../utils/custom'
import commonService from '../../service/common'
import customService from '../../service/custom'
import { resultsModel } from '../../sdk'
import { CommonTaskService, CommonBaseService } from '../../service/common'
export default class TaskController {
/**
......@@ -17,11 +17,11 @@ export default class TaskController {
@commonDecorator.registeInfos(['vipInfo'])
@commonDecorator.preCheck([commonUtilCheck.checkActivityTime])
@commonDecorator.preUpdate([commonUtilUpdate.updateVip, commonUtilUpdate.updateSignTask, commonUtilUpdate.updateOrderGoods])
@services([commonService.TaskService])
@services([CommonTaskService])
async getTaskList(
context: IContext<IParams>,
{ activityInfo, userInfo, vipInfo }: IControllerInfos,
[commonTaskService]: [commonService.TaskService]
[commonTaskService]: [CommonTaskService]
) {
const commonTaskInitTaskResult1 = await commonTaskService.initTask(activityInfo, userInfo)
return resultsModel.success({
......@@ -34,11 +34,11 @@ export default class TaskController {
@commonDecorator.checkParams(['activityId', 'taskType'])
@commonDecorator.registeInfos(['session'])
@commonDecorator.preCheck([commonUtilCheck.checkActivityTime, commonUtilCheck.checkTaskLimit, commonUtilCheck.checkExchangeCreditsTask])
@services([commonService.TaskService])
@services([CommonTaskService])
async doCompleteTask(
context: IContext<IParams>,
{ activityInfo, userInfo, session }: IControllerInfos,
[commonTaskService]: [commonService.TaskService]
[commonTaskService]: [CommonTaskService]
) {
const commonTaskCompleteTaskResult1 = await commonTaskService.completeTask(context.data.taskType, activityInfo, userInfo)
return resultsModel.success({
......@@ -50,11 +50,11 @@ export default class TaskController {
*/
@commonDecorator.checkParams(['activityId', 'taskType', 'rewardsKey'])
@commonDecorator.preCheck([commonUtilCheck.checkActivityTime, commonUtilCheck.checkRemainTimes])
@services([commonService.TaskService])
@services([CommonTaskService])
async receiveTaskRewards(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonTaskService]: [commonService.TaskService]
[commonTaskService]: [CommonTaskService]
) {
const commonTaskReceiveTaskRewardsResult1 = await commonTaskService.receiveTaskRewards(context.data.taskType, context.data.rewardsKey, userInfo)
return resultsModel.success({
......@@ -66,14 +66,14 @@ export default class TaskController {
*/
@commonDecorator.checkParams(['activityId', 'itemIds'])
@commonDecorator.registeInfos(['session'])
@services([commonService.BaseService, commonService.TaskService])
@services([CommonBaseService, CommonTaskService])
async getCollectGoodsList(
context: IContext<IParams>,
{ activityInfo, userInfo, session }: IControllerInfos,
[commonBaseService, commonTaskService]: [commonService.BaseService, commonService.TaskService]
[commonBaseService, commonTaskService]: [CommonBaseService, CommonTaskService]
) {
const commonBaseGetItemListByIdsResult1 = await commonBaseService.getItemListByIds(context.data.itemIds, session)
const commonTaskGetItemListWithCollectStatusResult2 = await commonTaskService.getItemListWithCollectStatus(commonBaseGetitemlistbyidsResult1, userInfo)
const commonTaskGetItemListWithCollectStatusResult2 = await commonTaskService.getItemListWithCollectStatus(commonBaseGetItemListByIdsResult1, userInfo)
return resultsModel.success({
...commonTaskGetItemListWithCollectStatusResult2
})
......
......@@ -4,10 +4,10 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import customUtil from '../../utils/custom'
import commonService from '../../service/common'
import customService from '../../service/custom'
import { resultsModel } from '../../sdk'
import { CommonUserService } from '../../service/common'
export default class UserController {
/**
......@@ -15,11 +15,11 @@ export default class UserController {
*/
@commonDecorator.checkParams(['activityId'])
@commonDecorator.registeInfos(['session'])
@services([commonService.UserService])
@services([CommonUserService])
async getVipInfo(
context: IContext<IParams>,
{ activityInfo, userInfo, session }: IControllerInfos,
[commonUserService]: [commonService.UserService]
[commonUserService]: [CommonUserService]
) {
const commonUserGetShopVipResult1 = await commonUserService.getShopVip(context, session)
return resultsModel.success({
......@@ -30,11 +30,11 @@ export default class UserController {
* 获取排行榜
*/
@commonDecorator.checkParams(['activityId', 'key', 'timeKey', 'limit'])
@services([commonService.UserService])
@services([CommonUserService])
async getRankList(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonUserService]: [commonService.UserService]
[commonUserService]: [CommonUserService]
) {
const commonUserGetMyRankInfoResult1 = await commonUserService.getMyRankInfo(context.data.key, context.data.timeKey, userInfo)
const commonUserGetRankResult2 = await commonUserService.getRank(context.data.key, context.data.timeKey, context.data.limit)
......
......@@ -4,10 +4,12 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import customUtil from '../../utils/custom'
import commonService from '../../service/common'
import customService from '../../service/custom'
import { resultsModel } from '../../sdk'
import { CommonStatService } from '../../service/common'
import { CustomTestService } from '../../service/custom'
export default class Test1Controller {
/**
......@@ -15,11 +17,11 @@ export default class Test1Controller {
*/
@commonDecorator.checkParams(['activityId', 'type'])
@customDecorator.test1(['tt'])
@services([commonService.StatService, customService.TestService])
@services([CommonStatService, CustomTestService])
async addStat(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonStatService, customTestService]: [commonService.StatService, customService.TestService]
[commonStatService, customTestService]: [CommonStatService, CustomTestService]
) {
const commonStatAddStatResult1 = await commonStatService.addStat(context.data.type, userInfo)
const customTestTest1Result2 = await customTestService.test1()
......@@ -32,11 +34,11 @@ export default class Test1Controller {
* 统计数据
*/
@commonDecorator.checkParams(['activityId', 'startDay', 'endDay'])
@services([commonService.StatService])
@services([CommonStatService])
async getStats(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonStatService]: [commonService.StatService]
[commonStatService]: [CommonStatService]
) {
const commonStatGetStatsResult1 = await commonStatService.getStats(context.data.activityId, context.data.startDay, context.data.endDay)
const commonStatBuildExcelResult2 = await commonStatService.buildExcel(context.data.startDay, context.data.endDay, commonStatGetStatsResult1)
......
......@@ -4,21 +4,21 @@ import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import customUtil from '../../utils/custom'
import commonService from '../../service/common'
import customService from '../../service/custom'
import { resultsModel } from '../../sdk'
import { CommonStatService } from '../../service/common'
export default class Test2Controller {
/**
* 增加埋点记录
*/
@commonDecorator.checkParams(['activityId', 'type'])
@services([commonService.StatService])
@services([CommonStatService])
async addStat(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonStatService]: [commonService.StatService]
[commonStatService]: [CommonStatService]
) {
const commonStatAddStatResult1 = await commonStatService.addStat(context.data.type, userInfo)
return resultsModel.success({
......@@ -29,11 +29,11 @@ export default class Test2Controller {
* 统计数据
*/
@commonDecorator.checkParams(['activityId', 'startDay', 'endDay'])
@services([commonService.StatService])
@services([CommonStatService])
async getStats(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonStatService]: [commonService.StatService]
[commonStatService]: [CommonStatService]
) {
const commonStatGetStatsResult1 = await commonStatService.getStats(context.data.activityId, context.data.startDay, context.data.endDay)
const commonStatBuildExcelResult2 = await commonStatService.buildExcel(context.data.startDay, context.data.endDay, commonStatGetstatsResult1)
......
/** @format */
import UserController from './controller/user.controller'
import TaskController from './controller/task.controller'
import BaseController from './controller/base.controller'
import AwardsController from './controller/awards.controller'
import ShareController from './controller/share.controller'
import StatController from './controller/stat.controller'
import LoginController from './controller/login.controller'
import GameController from './controller/game.controller'
const { getVipInfo, getRankList } = new UserController()
const { login } = new LoginController()
const { getGameInfo, startGame, submitGame } = new GameController()
const {
getTaskList,
receiveTaskRewards,
doCompleteTask,
getCollectGoodsList // 获取收藏商品列表,包含收藏状态
} = new TaskController()
const { getActivityBaseInfoById, getItemListByItemIds } = new BaseController()
const { getMyPrizeList, receiveObjectPrize, receiveEnamePrize, drawLotteryPrize } = new AwardsController()
const { doHelp } = new ShareController()
const { getStats, addStat } = new StatController()
import CommonUserController from './controller/common/user.controller'
const CommonUserControllerInstance = new CommonUserController()
import CommonTaskController from './controller/common/task.controller'
const CommonTaskControllerInstance = new CommonTaskController()
import CommonStatController from './controller/common/stat.controller'
const CommonStatControllerInstance = new CommonStatController()
import CustomTest1Controller from './controller/custom/test1.controller'
const CustomTest1ControllerInstance = new CustomTest1Controller()
import CustomTest2Controller from './controller/custom/test2.controller'
const CustomTest2ControllerInstance = new CustomTest2Controller()
export default {
login,
getVipInfo,
getTaskList,
doCompleteTask,
receiveTaskRewards,
getActivityBaseInfoById,
getMyPrizeList,
receiveObjectPrize,
receiveEnamePrize,
doHelp,
getStats,
addStat,
getRankList,
// 游戏类
getGameInfo,
startGame,
submitGame
commonUserGetvipinfo: CommonUserControllerInstance.getVipInfo,
commonUserGetranklist: CommonUserControllerInstance.getRankList,
commonTaskGettasklist: CommonTaskControllerInstance.getTaskList,
commonTaskDocompletetask: CommonTaskControllerInstance.doCompleteTask,
commonTaskReceivetaskrewards: CommonTaskControllerInstance.receiveTaskRewards,
commonTaskGetcollectgoodslist: CommonTaskControllerInstance.getCollectGoodsList,
commonStatAddstat: CommonStatControllerInstance.addStat,
commonStatGetstats: CommonStatControllerInstance.getStats,
customTest1Addstat: CustomTest1ControllerInstance.addStat,
customTest1Getstats: CustomTest1ControllerInstance.getStats,
customTest2Addstat: CustomTest2ControllerInstance.addStat,
customTest2Getstats: CustomTest2ControllerInstance.getStats
}
/** @format */
import TestService from './test.service'
import CustomTestService from './test.service'
const common = {
TestService
const custom = {
CustomTestService
}
export default common
export default custom
export {
TestService
CustomTestService
}
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