zs před 1 rokem
revize
ccee9eca9e
91 změnil soubory, kde provedl 29714 přidání a 0 odebrání
  1. 11 0
      .editorconfig
  2. 11 0
      .eslintrc.json
  3. 13 0
      .gitignore
  4. 4 0
      .prettierrc.js
  5. 15 0
      README.md
  6. 29 0
      README.zh-CN.md
  7. 2 0
      bootstrap.js
  8. 20 0
      ecosystem.config.js
  9. 6 0
      jest.config.js
  10. 18496 0
      package-lock.json
  11. 61 0
      package.json
  12. 7003 0
      pnpm-lock.yaml
  13. 22 0
      src/config/config.default.ts
  14. 63 0
      src/config/config.local.ts
  15. 52 0
      src/config/config.prod.ts
  16. 7 0
      src/config/config.unittest.ts
  17. 50 0
      src/configuration.ts
  18. 42 0
      src/controller/es.controller.ts
  19. 16 0
      src/controller/home.controller.ts
  20. 21 0
      src/controller/init.controller.ts
  21. 88 0
      src/controller/login.controller.ts
  22. 68 0
      src/controller/platform/achievement.controller.ts
  23. 68 0
      src/controller/platform/demand.controller.ts
  24. 68 0
      src/controller/platform/match.controller.ts
  25. 68 0
      src/controller/platform/news.controller.ts
  26. 68 0
      src/controller/record/dataRecord.controller.ts
  27. 68 0
      src/controller/system/admin.controller.ts
  28. 65 0
      src/controller/system/config.controller.ts
  29. 68 0
      src/controller/system/dictData.controller.ts
  30. 68 0
      src/controller/system/dictType.controller.ts
  31. 62 0
      src/controller/system/menus.controller.ts
  32. 84 0
      src/controller/system/role.controller.ts
  33. 68 0
      src/controller/system/user.controller.ts
  34. 44 0
      src/controller/token.controller.ts
  35. 48 0
      src/decorator/checkPermissionCode.ts
  36. 69 0
      src/decorator/dataRecord.ts
  37. 37 0
      src/decorator/verifyToken.decorator.ts
  38. 65 0
      src/entity/basic.entity.ts
  39. 41 0
      src/entity/platform/achievement.entity.ts
  40. 33 0
      src/entity/platform/demand.entity.ts
  41. 29 0
      src/entity/platform/match.entity.ts
  42. 23 0
      src/entity/platform/news.entity.ts
  43. 34 0
      src/entity/system/admin.entity.ts
  44. 15 0
      src/entity/system/config.entity.ts
  45. 17 0
      src/entity/system/dictData.entity.ts
  46. 15 0
      src/entity/system/dictType.entity.ts
  47. 33 0
      src/entity/system/menus.entity.ts
  48. 17 0
      src/entity/system/role.entity.ts
  49. 15 0
      src/entity/system/user.entity.ts
  50. 27 0
      src/entityRecord/dataRecord.entity.ts
  51. 6 0
      src/interface.ts
  52. 41 0
      src/interface/login.interface.ts
  53. 167 0
      src/interface/platform/achievement.interface.ts
  54. 139 0
      src/interface/platform/demand.interface.ts
  55. 123 0
      src/interface/platform/match.interface.ts
  56. 108 0
      src/interface/platform/news.interface.ts
  57. 112 0
      src/interface/record/dataRecord.interface.ts
  58. 93 0
      src/interface/system/admin.interface.ts
  59. 82 0
      src/interface/system/config.interface.ts
  60. 87 0
      src/interface/system/dictData.interface.ts
  61. 82 0
      src/interface/system/dictType.interface.ts
  62. 127 0
      src/interface/system/menus.interface.ts
  63. 85 0
      src/interface/system/role.interface.ts
  64. 76 0
      src/interface/system/user.interface.ts
  65. 3 0
      src/locales/en_us/defaults.ts
  66. 17 0
      src/locales/en_us/errors.ts
  67. 11 0
      src/locales/zh_cn/controller_method.ts
  68. 3 0
      src/locales/zh_cn/defaults.ts
  69. 17 0
      src/locales/zh_cn/errors.ts
  70. 28 0
      src/middleware/checkOnePointLogin.middleware.ts
  71. 33 0
      src/middleware/checkToken.middleware.ts
  72. 24 0
      src/middleware/setLocaleToCtx.middleware.ts
  73. 209 0
      src/service/elasticsearch.ts
  74. 141 0
      src/service/init.service.ts
  75. 124 0
      src/service/login.service.ts
  76. 11 0
      src/service/platform/achievement.service.ts
  77. 11 0
      src/service/platform/demand.service.ts
  78. 11 0
      src/service/platform/match.service.ts
  79. 11 0
      src/service/platform/news.service.ts
  80. 73 0
      src/service/record/dataRecord.service.ts
  81. 11 0
      src/service/system/admin.service.ts
  82. 17 0
      src/service/system/config.service.ts
  83. 11 0
      src/service/system/dictData.service.ts
  84. 11 0
      src/service/system/dictType.service.ts
  85. 38 0
      src/service/system/menus.service.ts
  86. 67 0
      src/service/system/role.service.ts
  87. 11 0
      src/service/system/user.service.ts
  88. 7 0
      src/service/util.service.ts
  89. 20 0
      test/controller/api.test.ts
  90. 21 0
      test/controller/home.test.ts
  91. 28 0
      tsconfig.json

+ 11 - 0
.editorconfig

@@ -0,0 +1,11 @@
+# 🎨 editorconfig.org
+
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+indent_style = space
+indent_size = 2
+trim_trailing_whitespace = true
+insert_final_newline = true

+ 11 - 0
.eslintrc.json

@@ -0,0 +1,11 @@
+{
+  "extends": "./node_modules/mwts/",
+  "ignorePatterns": ["node_modules", "dist", "test", "jest.config.js", "typings"],
+  "env": {
+    "jest": true
+  },
+  "rules": {
+    "prettier/prettier": 0,
+    "max-len": ["warn", { "code": 250 }]
+  }
+}

+ 13 - 0
.gitignore

@@ -0,0 +1,13 @@
+logs/
+npm-debug.log
+yarn-error.log
+node_modules/
+coverage/
+dist/
+.idea/
+run/
+.DS_Store
+*.sw*
+*.un~
+.tsbuildinfo
+.tsbuildinfo.*

+ 4 - 0
.prettierrc.js

@@ -0,0 +1,4 @@
+module.exports = {
+  ...require('mwts/.prettierrc.json'),
+  printWidth: 250,
+}

+ 15 - 0
README.md

@@ -0,0 +1,15 @@
+# vue3js-template-service
+## 1.单点登录
+* 1.不需要登录就可以使用的接口: 请求函数的方法注解参数添加 description: 'ignore'即可
+
+## 2.注解
+* checkPermissionCode
+|注解名|类型|说明|
+|:-:|:-:|:-:|
+|roleCode|string|该接口权限所需标识 ${路由名称}.${功能}|
+
+* dataRecord
+|注解名|类型|说明|
+|:-:|:-:|:-:|
+|before|string|获取原数据的函数名;该service下的函数名,纯自定义|
+|after|string|获取新数据的函数名;该service下的函数名,纯自定义|

+ 29 - 0
README.zh-CN.md

@@ -0,0 +1,29 @@
+# my_midway_project
+
+## 快速入门
+
+<!-- 在此次添加使用文档 -->
+
+如需进一步了解,参见 [midway 文档][midway]。
+
+### 本地开发
+
+```bash
+$ npm i
+$ npm run dev
+$ open http://localhost:7001/
+```
+
+### 部署
+
+```bash
+$ npm start
+```
+
+### 内置指令
+
+- 使用 `npm run lint` 来做代码风格检查。
+- 使用 `npm test` 来执行单元测试。
+
+
+[midway]: https://midwayjs.org

+ 2 - 0
bootstrap.js

@@ -0,0 +1,2 @@
+const { Bootstrap } = require('@midwayjs/bootstrap');
+Bootstrap.run();

+ 20 - 0
ecosystem.config.js

@@ -0,0 +1,20 @@
+'use strict';
+// 开发服务设置
+const app = 'service';
+module.exports = {
+  apps: [
+    {
+      name: app, // 应用名称
+      script: './bootstrap.js', // 实际启动脚本
+      out: `./logs/${app}.log`,
+      error: `./logs/${app}.err`,
+      watch: [
+        // 监控变化的目录,一旦变化,自动重启
+        'dist',
+      ],
+      env: {
+        NODE_ENV: 'production', // 环境参数,当前指定为生产环境
+      },
+    },
+  ],
+};

+ 6 - 0
jest.config.js

@@ -0,0 +1,6 @@
+module.exports = {
+  preset: 'ts-jest',
+  testEnvironment: 'node',
+  testPathIgnorePatterns: ['<rootDir>/test/fixtures'],
+  coveragePathIgnorePatterns: ['<rootDir>/test/'],
+};

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 18496 - 0
package-lock.json


+ 61 - 0
package.json

@@ -0,0 +1,61 @@
+{
+  "name": "vue3js-template-service",
+  "version": "1.0.0",
+  "description": "",
+  "private": true,
+  "dependencies": {
+    "@elastic/elasticsearch": "^8.12.2",
+    "@midwayjs/bootstrap": "^3.12.0",
+    "@midwayjs/core": "^3.12.0",
+    "@midwayjs/decorator": "^3.12.0",
+    "@midwayjs/i18n": "3",
+    "@midwayjs/info": "^3.12.0",
+    "@midwayjs/jwt": "^3.13.7",
+    "@midwayjs/koa": "^3.12.0",
+    "@midwayjs/logger": "^3.1.0",
+    "@midwayjs/redis": "3",
+    "@midwayjs/swagger": "^3.13.7",
+    "@midwayjs/typegoose": "^3.0.0",
+    "@midwayjs/validate": "^3.12.0",
+    "@typegoose/typegoose": "^9.0.0",
+    "crypto-js": "^4.2.0",
+    "dayjs": "^1.11.10",
+    "free-midway-component": "^1.0.53",
+    "lodash": "^4.17.21",
+    "mongoose": "^6.0.7"
+  },
+  "devDependencies": {
+    "@midwayjs/cli": "^2.1.1",
+    "@midwayjs/mock": "^3.12.0",
+    "@types/jest": "^29.2.0",
+    "@types/koa": "^2.13.4",
+    "@types/lodash": "^4.14.202",
+    "@types/node": "14",
+    "cross-env": "^6.0.0",
+    "jest": "^29.2.2",
+    "mwts": "^1.3.0",
+    "mwtsc": "^1.4.0",
+    "swagger-ui-dist": "^5.10.5",
+    "ts-jest": "^29.0.3",
+    "typescript": "~4.8.0"
+  },
+  "engines": {
+    "node": ">=12.0.0"
+  },
+  "scripts": {
+    "start": "NODE_ENV=production node ./bootstrap.js",
+    "dev": "cross-env TS_NODE_TYPE_CHECK=false TS_NODE_TRANSPILE_ONLY=true NODE_ENV=local midway-bin dev --ts",
+    "test": "cross-env NODE_ENV=unittest jest",
+    "cov": "jest --coverage",
+    "lint": "mwts check",
+    "lint:fix": "mwts fix",
+    "ci": "npm run cov",
+    "build": "mwtsc --cleanOutDir"
+  },
+  "repository": {
+    "type": "git",
+    "url": ""
+  },
+  "author": "anonymous",
+  "license": "MIT"
+}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 7003 - 0
pnpm-lock.yaml


+ 22 - 0
src/config/config.default.ts

@@ -0,0 +1,22 @@
+import { MidwayConfig } from '@midwayjs/core';
+
+export default {
+  // use for cookie sign key, should change to your own and keep security
+  keys: '1706233305258_2242',
+  koa: {
+    port: 7001,
+  },
+  i18n: {
+    localeTable: {
+      en_us: {
+        default: require('../locales/en_us/defaults'),
+        error: require('../locales/en_us/errors'),
+      },
+      zh_cn: {
+        default: require('../locales/zh_cn/defaults'),
+        error: require('../locales/zh_cn/errors'),
+        methods: require('../locales/zh_cn/controller_method'),
+      },
+    },
+  },
+} as MidwayConfig;

+ 63 - 0
src/config/config.local.ts

@@ -0,0 +1,63 @@
+import { MidwayConfig } from '@midwayjs/core';
+const ip = '127.0.0.1'; //120.48.146.1
+const redisHost = '127.0.0.1';
+const redisPwd = '123456';
+const redisDB = 6;
+const projectDB = 'vue3js-template-test';
+const recordDB = 'vue3js-template-test-record'
+const loginSign = 'tsFrameDev';
+export default {
+  // use for cookie sign key, should change to your own and keep security
+  keys: '1697684406848_4978',
+  loginSign,
+  koa: {
+    port: 9700,
+    globalPrefix: '/ts/frame/api',
+  },
+  swagger: {
+    swaggerPath: '/doc/api',
+  },
+  jwt: {
+    secret: 'Ziyouyanfa!@#',
+    expiresIn: 3600, // 3600
+  },
+  mongoose: {
+    dataSource: {
+      default: {
+        uri: `mongodb://${ip}:27017/${projectDB}`,
+        options: {
+          user: 'admin',
+          pass: 'admin',
+          authSource: 'admin',
+          useNewUrlParser: true,
+        },
+        entities: ['./entity'],
+      },
+      record:{
+        uri: `mongodb://${ip}:27017/${recordDB}`,
+        options: {
+          user: 'admin',
+          pass: 'admin',
+          authSource: 'admin',
+          useNewUrlParser: true,
+        },
+        entities: ['./entityRecord'],
+      }
+    },
+  },
+  redis: {
+    client: {
+      port: 6379, // Redis port
+      host: redisHost, // Redis host
+      password: redisPwd,
+      db: redisDB,
+    },
+  },
+  upload: {
+    whitelist: null,
+  },
+  weixinConfig: {
+    appid: 'wxe8b4c4d5e87a7d31',
+    secret: '60cffc9d8766e8b169db970d2422a647',
+  },
+} as MidwayConfig;

+ 52 - 0
src/config/config.prod.ts

@@ -0,0 +1,52 @@
+import { MidwayConfig } from '@midwayjs/core';
+const ip = 'host.docker.internal';
+const redisHost = ip;
+const redisPwd = '123456';
+const redisDB = 6;
+const projectDB = 'vue3js-template-test';
+const loginSign = 'tsFrame';
+export default {
+  // use for cookie sign key, should change to your own and keep security
+  keys: '1697684406848_4978',
+  loginSign,
+  koa: {
+    port: 9700,
+    globalPrefix: '/ts/frame/api',
+  },
+  swagger: {
+    swaggerPath: '/doc/api',
+  },
+  jwt: {
+    secret: 'Ziyouyanfa!@#',
+    expiresIn: 3600, // 3600
+  },
+  mongoose: {
+    dataSource: {
+      default: {
+        uri: `mongodb://${ip}:27017/${projectDB}`,
+        options: {
+          user: 'admin',
+          pass: 'admin',
+          authSource: 'admin',
+          useNewUrlParser: true,
+        },
+        entities: ['./entity'],
+      },
+    },
+  },
+  redis: {
+    client: {
+      port: 6379, // Redis port
+      host: redisHost, // Redis host
+      password: redisPwd,
+      db: redisDB,
+    },
+  },
+  upload: {
+    whitelist: null,
+  },
+  weixinConfig: {
+    appid: 'wxe8b4c4d5e87a7d31',
+    secret: '60cffc9d8766e8b169db970d2422a647',
+  },
+} as MidwayConfig;

+ 7 - 0
src/config/config.unittest.ts

@@ -0,0 +1,7 @@
+import { MidwayConfig } from '@midwayjs/core';
+
+export default {
+  koa: {
+    port: null,
+  },
+} as MidwayConfig;

+ 50 - 0
src/configuration.ts

@@ -0,0 +1,50 @@
+import { Configuration, App, Inject, MidwayDecoratorService } from '@midwayjs/core';
+import * as koa from '@midwayjs/koa';
+import * as validate from '@midwayjs/validate';
+import * as info from '@midwayjs/info';
+import { join } from 'path';
+import * as FreeFrame from 'free-midway-component';
+import * as jwt from '@midwayjs/jwt';
+import { VerifyTokenInit } from './decorator/verifyToken.decorator';
+import { CheckPermissionCodeInit } from './decorator/checkPermissionCode';
+// import { CheckTokenMiddleware } from './middleware/checkToken.middleware';
+import * as swagger from '@midwayjs/swagger';
+import * as redis from '@midwayjs/redis';
+import { CheckOnePointLoginMiddleware } from './middleware/checkOnePointLogin.middleware';
+import * as i18n from '@midwayjs/i18n';
+import { SetLocaleToCtxMiddleware } from './middleware/setLocaleToCtx.middleware';
+import { DataRecordInit } from './decorator/dataRecord';
+@Configuration({
+  imports: [
+    koa,
+    validate,
+    FreeFrame,
+    jwt,
+    redis,
+    i18n,
+    {
+      component: info,
+      enabledEnvironment: ['local'],
+    },
+    {
+      component: swagger,
+      enabledEnvironment: ['local'],
+    },
+  ],
+  importConfigs: [join(__dirname, './config')],
+})
+export class MainConfiguration {
+  @App('koa')
+  app: koa.Application;
+  @Inject()
+  decoratorService: MidwayDecoratorService;
+
+  async onReady() {
+    this.app.getMiddleware().insertFirst(SetLocaleToCtxMiddleware)
+    this.app.getMiddleware().insertAfter(CheckOnePointLoginMiddleware, 'checkToken');
+    // 注解
+    VerifyTokenInit(this.decoratorService);
+    CheckPermissionCodeInit(this.decoratorService);
+    DataRecordInit(this.decoratorService)
+  }
+}

+ 42 - 0
src/controller/es.controller.ts

@@ -0,0 +1,42 @@
+import { Body, Controller, Del, Get, Inject, Param, Post,  Query } from '@midwayjs/core';
+import { ElasticsearchService } from '../service/elasticsearch';
+
+@Controller('/es')
+export class ESController {
+  @Inject()
+  esService: ElasticsearchService;
+
+  @Post('/async')
+  async asyncData() {
+    await this.esService.asyncData();
+    return 'ok';
+  }
+
+  @Get('/')
+  async search(@Query() query: any) {
+    query.build_time = ['2023-01-01', '2024-01-01']
+    const result = await this.esService.search(query);
+    return result;
+  }
+
+  @Post('/')
+  async create(@Body() data: any) {
+    const result = await this.esService.create(data);
+    return 'created';
+  }
+
+  @Post('/:id')
+  async update(@Param('id') id: string, @Body() data: any) {
+    const result = await this.esService.update(id, data);
+    console.log(id);
+    console.log(data);
+    return 'update';
+  }
+
+  @Del('/:id')
+  async delete(@Param('id') id: string) {
+    const result = await this.esService.delete(id);
+    console.log(id);
+    return 'delete';
+  }
+}

+ 16 - 0
src/controller/home.controller.ts

@@ -0,0 +1,16 @@
+import { Controller, Get, Inject } from '@midwayjs/core';
+import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+import { Context } from '@midwayjs/koa';
+import { MidwayI18nService } from '@midwayjs/i18n';
+@Controller('/')
+export class HomeController {
+  @Inject()
+  ctx: Context;
+  @Inject()
+  i18n: MidwayI18nService;
+  @Get('/', { description: 'ignore' })
+  async home(): Promise<string> {
+    throw new ServiceError(this.i18n.translate(FrameworkErrorEnum.BAD_ARGS, {  group: 'error' }),FrameworkErrorEnum.BAD_ARGS)
+    // return ;
+  }
+}

+ 21 - 0
src/controller/init.controller.ts

@@ -0,0 +1,21 @@
+import { Controller, Inject, Post } from '@midwayjs/decorator';
+import { Context } from '@midwayjs/koa';
+import { InitService } from '../service/init.service';
+@Controller('/init')
+export class InitController {
+  @Inject()
+  ctx: Context;
+
+  @Inject()
+  service: InitService;
+
+  @Post('/', { description: 'ignore' })
+  async index() {
+    await this.service.adminUser();
+    // 未初始化,则执行初始化程序
+    await this.service.initDict();
+    await this.service.initRole();
+    await this.service.initMenus();
+    return 'ok';
+  }
+}

+ 88 - 0
src/controller/login.controller.ts

@@ -0,0 +1,88 @@
+import { Body, Config, Controller, Inject, Param, Post, Get } from '@midwayjs/core';
+import { ApiTags } from '@midwayjs/swagger';
+import { LoginDTO, LoginType, LoginVO, UPwdDTO } from '../interface/login.interface';
+import { LoginService } from '../service/login.service';
+import { JwtService } from '@midwayjs/jwt';
+import { Context } from '@midwayjs/koa';
+const assert = require('assert');
+import get = require('lodash/get');
+import { UtilService } from '../service/util.service';
+// import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+
+@ApiTags(['登录服务'])
+@Controller('/login')
+export class LoginController {
+  @Inject()
+  loginService: LoginService;
+  @Inject()
+  jwtService: JwtService;
+  @Inject()
+  utilService: UtilService;
+  @Config('jwt.secret')
+  jwtSecret;
+  @Config('jwt.expiresIn')
+  jwtExpiresIn;
+  @Inject()
+  ctx: Context;
+  /**
+   * 账密登录
+   * @param data 用户名和密码
+   * @param type 用户类型
+   */
+  @Post('/:type', { description: 'ignore' })
+  async toLogin(@Body() data: LoginDTO, @Param('type') type: string) {
+    const user = await this.loginService.loginByAccount(data, LoginType[type]);
+    if (user) user.role = type;
+    let vo = new LoginVO(user);
+    vo = JSON.parse(JSON.stringify(vo));
+    vo.login_code = await this.loginService.onePointLogin(vo)
+    const token = await this.jwtService.sign(vo, this.jwtSecret);
+    return token;
+  }
+
+  /**
+   * TODO:微信小程序登录
+   * @param openid 微信小程序openid
+   */
+  // @Post('/wxapp/:openid')
+  // async wxAppLogin(@Param('openid') openid: string) {
+  //   if (!openid) throw new ServiceError('缺少微信凭证!', FrameworkErrorEnum.BAD_PARAMS);
+  //   const user = await this.loginService.wxAppLogin(openid);
+  //   let vo = new LoginVO(user);
+  //   vo = JSON.parse(JSON.stringify(vo));
+  //   const token = await this.jwtService.sign(vo, this.jwtSecret, {
+  //     expiresIn: this.jwtExpiresIn,
+  //   });
+  //   return token;
+  // }
+  /**
+   * 修改密码
+   * @param data 修改密码所需数据
+   * @param type 账户类型
+   */
+  @Post('/updatePwd/:type')
+  async updatePwd(@Body() data: UPwdDTO, @Param('type') type: string) {
+    // 随机密码
+    data.password = this.utilService.randomStr();
+    await this.loginService.updatePwd(data, LoginType[type]);
+    return 'ok';
+  }
+
+  @Post('/resetPwd/:type')
+  async resetPwd(@Body('_id') _id: string, @Param('type') type: string) {
+    // 随机密码
+    const data = new UPwdDTO();
+    data._id = _id;
+    data.password = this.utilService.randomStr();
+    await this.loginService.updatePwd(data, LoginType[type]);
+    return data.password;
+  }
+
+  @Get('/analysis')
+  async analysisToken() {
+    const token = get(this.ctx, 'request.header.token');
+    assert(token, '缺少token信息');
+    const result = await this.jwtService.decodeSync(token);
+    return result;
+  }
+}

+ 68 - 0
src/controller/platform/achievement.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { AchievementService } from '../../service/platform/achievement.service';
+import { CDTO_achievement, CVO_achievement, FVO_achievement, QDTO_achievement, QVO_achievement, UDTO_achievement, UVAO_achievement } from '../../interface/platform/achievement.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['成果'])
+@Controller('/achievement')
+export class AchievementController extends BaseController {
+  @Inject()
+  service: AchievementService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_achievement })
+  async create(@Body() data: CDTO_achievement) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_achievement(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_achievement })
+  async query(@Query() filter: QDTO_achievement, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_achievement(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_achievement })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_achievement(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_achievement })
+  async update(@Param('id') id: string, @Body() body: UDTO_achievement) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 68 - 0
src/controller/platform/demand.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { DemandService } from '../../service/platform/demand.service';
+import { CDTO_demand, CVO_demand, FVO_demand, QDTO_demand, QVO_demand, UDTO_demand, UVAO_demand } from '../../interface/platform/demand.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['需求'])
+@Controller('/demand')
+export class DemandController extends BaseController {
+  @Inject()
+  service: DemandService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_demand })
+  async create(@Body() data: CDTO_demand) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_demand(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_demand })
+  async query(@Query() filter: QDTO_demand, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_demand(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_demand })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_demand(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_demand })
+  async update(@Param('id') id: string, @Body() body: UDTO_demand) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 68 - 0
src/controller/platform/match.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { MatchService } from '../../service/platform/match.service';
+import { CDTO_match, CVO_match, FVO_match, QDTO_match, QVO_match, UDTO_match, UVAO_match } from '../../interface/platform/match.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['创新大赛'])
+@Controller('/match')
+export class MatchController extends BaseController {
+  @Inject()
+  service: MatchService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_match })
+  async create(@Body() data: CDTO_match) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_match(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_match })
+  async query(@Query() filter: QDTO_match, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_match(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_match })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_match(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_match })
+  async update(@Param('id') id: string, @Body() body: UDTO_match) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 68 - 0
src/controller/platform/news.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { NewsService } from '../../service/platform/news.service';
+import { CDTO_news, CVO_news, FVO_news, QDTO_news, QVO_news, UDTO_news, UVAO_news } from '../../interface/platform/news.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['新闻'])
+@Controller('/news')
+export class NewsController extends BaseController {
+  @Inject()
+  service: NewsService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_news })
+  async create(@Body() data: CDTO_news) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_news(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_news })
+  async query(@Query() filter: QDTO_news, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_news(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_news })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_news(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_news })
+  async update(@Param('id') id: string, @Body() body: UDTO_news) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 68 - 0
src/controller/record/dataRecord.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { DataRecordService } from '../../service/record/dataRecord.service';
+import { CDTO_dataRecord, CVO_dataRecord, FVO_dataRecord, QDTO_dataRecord, QVO_dataRecord, UDTO_dataRecord, UVAO_dataRecord } from '../../interface/record/dataRecord.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['数据操作记录'])
+@Controller('/dataRecord')
+export class DataRecordController extends BaseController {
+  @Inject()
+  service: DataRecordService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_dataRecord })
+  async create(@Body() data: CDTO_dataRecord) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_dataRecord(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_dataRecord })
+  async query(@Query() filter: QDTO_dataRecord, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_dataRecord(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_dataRecord })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_dataRecord(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_dataRecord })
+  async update(@Param('id') id: string, @Body() body: UDTO_dataRecord) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 68 - 0
src/controller/system/admin.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { AdminService } from '../../service/system/admin.service';
+import { CDTO_admin, CVO_admin, FVO_admin, QDTO_admin, QVO_admin, UDTO_admin, UVAO_admin } from '../../interface/system/admin.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['管理员表'])
+@Controller('/admin')
+export class AdminController extends BaseController {
+  @Inject()
+  service: AdminService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_admin })
+  async create(@Body() data: CDTO_admin) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_admin(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_admin })
+  async query(@Query() filter: QDTO_admin, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_admin(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_admin })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_admin(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_admin })
+  async update(@Param('id') id: string, @Body() body: UDTO_admin) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 65 - 0
src/controller/system/config.controller.ts

@@ -0,0 +1,65 @@
+import { Body, Controller, Del, Get, Inject, Param, Post } from '@midwayjs/decorator';
+import { BaseController, FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+import { ConfigService } from '../../service/system/config.service';
+import { CDTO_config, CVO_config, FVO_config, UDTO_config, UVAO_config } from '../../interface/system/config.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['设置表'])
+@Controller('/config')
+export class ConfigController extends BaseController {
+  @Inject()
+  service: ConfigService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_config })
+  async create(@Body() data: CDTO_config) {
+    throw new ServiceError('功能暂不开放', FrameworkErrorEnum.SERVICE_FAULT);
+    // const dbData = await this.service.create(data);
+    // const result = new CVO_config(dbData);
+    // return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: FVO_config })
+  async query() {
+    const data = await this.service.getConfig();
+    const result = new FVO_config(data);
+    return result;
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_config })
+  async fetch(@Param('id') id: string) {
+    throw new ServiceError('功能暂不开放', FrameworkErrorEnum.SERVICE_FAULT);
+    // const data = await this.service.fetch(id);
+    // const result = new FVO_config(data);
+    // return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_config })
+  async update(@Param('id') id: string, @Body() body: UDTO_config) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 68 - 0
src/controller/system/dictData.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { DictDataService } from '../../service/system/dictData.service';
+import { CDTO_dictData, CVO_dictData, FVO_dictData, QDTO_dictData, QVO_dictData, UDTO_dictData, UVAO_dictData } from '../../interface/system/dictData.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['字典数据表'])
+@Controller('/dictData')
+export class DictDataController extends BaseController {
+  @Inject()
+  service: DictDataService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_dictData })
+  async create(@Body() data: CDTO_dictData) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_dictData(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_dictData })
+  async query(@Query() filter: QDTO_dictData, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit, sort: { sort: 1 } });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_dictData(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_dictData })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_dictData(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_dictData })
+  async update(@Param('id') id: string, @Body() body: UDTO_dictData) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 68 - 0
src/controller/system/dictType.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { DictTypeService } from '../../service/system/dictType.service';
+import { CDTO_dictType, CVO_dictType, FVO_dictType, QDTO_dictType, QVO_dictType, UDTO_dictType, UVAO_dictType } from '../../interface/system/dictType.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['字典类型表'])
+@Controller('/dictType')
+export class DictTypeController extends BaseController {
+  @Inject()
+  service: DictTypeService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_dictType })
+  async create(@Body() data: CDTO_dictType) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_dictType(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_dictType })
+  async query(@Query() filter: QDTO_dictType, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_dictType(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_dictType })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_dictType(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_dictType })
+  async update(@Param('id') id: string, @Body() body: UDTO_dictType) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 62 - 0
src/controller/system/menus.controller.ts

@@ -0,0 +1,62 @@
+import { Body, Controller, Del, Get, Inject, Param, Post } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { MenusService } from '../../service/system/menus.service';
+import { CDTO_menus, CVO_menus, FVO_menus, QVO_menus, UDTO_menus, UVAO_menus } from '../../interface/system/menus.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['菜单表'])
+@Controller('/menus')
+export class MenusController extends BaseController {
+  @Inject()
+  service: MenusService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_menus })
+  async create(@Body() data: CDTO_menus) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_menus(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_menus })
+  async query() {
+    const list = await this.service.queryMenu();
+    return list;
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_menus })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_menus(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_menus })
+  async update(@Param('id') id: string, @Body() body: UDTO_menus) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 84 - 0
src/controller/system/role.controller.ts

@@ -0,0 +1,84 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { RoleService } from '../../service/system/role.service';
+import { CDTO_role, CVO_role, FVO_role, QDTO_role, QVO_role, UDTO_role, UVAO_role } from '../../interface/system/role.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+import { MenusService } from '../../service/system/menus.service';
+import { verifyToken } from '../../decorator/verifyToken.decorator';
+import { checkPermissionCode } from '../../decorator/checkPermissionCode';
+import { dataRecord } from '../../decorator/dataRecord';
+@ApiTags(['角色表'])
+@Controller('/role')
+export class RoleController extends BaseController {
+  @Inject()
+  service: RoleService;
+  @Inject()
+  menusService: MenusService;
+
+  @Post('/')
+  @verifyToken()
+  @Validate()
+  @ApiResponse({ type: CVO_role })
+  @dataRecord()
+  async create(@Body() data: CDTO_role) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_role(dbData);
+    return result;
+  }
+  @Get('/')
+  @verifyToken()
+  @checkPermissionCode({ roleCode: 'system_role' })
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_role })
+  async query(@Query() filter: QDTO_role, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_role(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @verifyToken()
+  @ApiResponse({ type: FVO_role })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_role(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @verifyToken()
+  @checkPermissionCode({ roleCode: 'system_role.update' })
+  @Validate()
+  @ApiResponse({ type: UVAO_role })
+  @dataRecord()
+  async update(@Param('id') id: string, @Body() body: UDTO_role) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @verifyToken()
+  @Validate()
+  @dataRecord()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 68 - 0
src/controller/system/user.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { UserService } from '../../service/system/user.service';
+import { CDTO_user, CVO_user, FVO_user, QDTO_user, QVO_user, UDTO_user, UVAO_user } from '../../interface/system/user.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['用户表'])
+@Controller('/user')
+export class UserController extends BaseController {
+  @Inject()
+  service: UserService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_user })
+  async create(@Body() data: CDTO_user) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_user(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_user })
+  async query(@Query() filter: QDTO_user, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_user(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_user })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_user(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_user })
+  async update(@Param('id') id: string, @Body() body: UDTO_user) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 44 - 0
src/controller/token.controller.ts

@@ -0,0 +1,44 @@
+import { Controller, Get, Inject } from '@midwayjs/decorator';
+import { Context } from '@midwayjs/koa';
+import { ApiResponse, ApiTags } from '@midwayjs/swagger';
+// import { TokenService } from '../service/token.service';
+const assert = require('assert');
+import { JwtService } from '@midwayjs/jwt';
+import get = require('lodash/get');
+import { RoleService } from '../service/system/role.service';
+@ApiTags(['工具'])
+@Controller('/token')
+export class TokenController {
+  // @Inject()
+  // service: TokenService;
+
+  @Inject()
+  jwtService: JwtService;
+
+  @Inject()
+  roleService: RoleService;
+
+  @Inject()
+  ctx: Context;
+
+  @Get('/tokenView')
+  @ApiResponse({})
+  async tokenView() {
+    const token = get(this.ctx, 'request.header.token');
+    assert(token, '缺少token信息');
+    const result: any = await this.jwtService.decode(token);
+    const userMenusResult = await this.roleService.getUserMenus();
+    const menus = get(userMenusResult,'menus')
+    const role_code = get(userMenusResult, 'role_code');
+    result.menus = menus;
+    result.role_code = role_code;
+    return result;
+  }
+
+  // @Get('/app')
+  // async appLogin(fiiter) {
+  //   const { config, js_code } = fiiter.query;
+  //   const result: any = await this.service.appLogin(config, js_code);
+  //   return result;
+  // }
+}

+ 48 - 0
src/decorator/checkPermissionCode.ts

@@ -0,0 +1,48 @@
+import { JoinPoint, MidwayDecoratorService, REQUEST_OBJ_CTX_KEY, createCustomMethodDecorator } from '@midwayjs/core';
+import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+import { get } from 'lodash';
+import { RoleService } from '../service/system/role.service';
+export const CHECKPERMISSIONCODE_KEY = 'decorator:check_permission_code';
+export const checkPermissionCode = options => {
+  return createCustomMethodDecorator(CHECKPERMISSIONCODE_KEY, options);
+};
+// 第二层及以后的权限,去掉第一层级
+const resetRoleMenus = list => {
+  list = list.map(i => {
+    const arr = i.split('.');
+    if (arr.length <= 1) return i;
+    arr.shift();
+    return arr.join('.');
+  });
+  return list;
+};
+
+export const CheckPermissionCodeInit = (decoratorService: MidwayDecoratorService) => {
+  decoratorService.registerMethodHandler(CHECKPERMISSIONCODE_KEY, options => {
+    return {
+      around: async (joinPoint: JoinPoint) => {
+        const roleCode = get(options, 'metadata.roleCode');
+        if (roleCode) {
+          const instance = joinPoint.target;
+          const ctx = instance[REQUEST_OBJ_CTX_KEY];
+          const roleService = await ctx.requestContext.getAsync(RoleService);
+          const isAdmin = roleService.isSuperAdmin();
+          if (!isAdmin) {
+            let roleMenus = await roleService.getUserMenus(true);
+            roleMenus = resetRoleMenus(roleMenus);
+            if (!roleMenus.includes(roleCode)) {
+              console.log(options);
+              throw new ServiceError('您没有当前功能的权限!', FrameworkErrorEnum.SERVICE_FAULT);
+            }
+            const result = await joinPoint.proceed(...joinPoint.args);
+            return result;
+          }
+          const result = await joinPoint.proceed(...joinPoint.args);
+          return result;
+        }
+        const result = await joinPoint.proceed(...joinPoint.args);
+        return result;
+      },
+    };
+  });
+};

+ 69 - 0
src/decorator/dataRecord.ts

@@ -0,0 +1,69 @@
+import { JoinPoint, MidwayDecoratorService, REQUEST_OBJ_CTX_KEY, createCustomMethodDecorator } from '@midwayjs/core';
+import { MidwayI18nService } from '@midwayjs/i18n';
+import { get } from 'lodash';
+import { DataRecordService } from '../service/record/dataRecord.service';
+export const DATARECORD_KEY = 'decorator:data_record';
+export const dataRecord = (options?: any) => {
+  return createCustomMethodDecorator(DATARECORD_KEY, options);
+};
+
+const getMethodName = (mapping: Map<string, any>, controller: string, path: string) => {
+  const map = mapping.get(controller);
+  if (!map) return;
+  return get(map, path);
+};
+// const i18n = await ctx.requestContext.getAsync(MidwayI18nService);
+// const mapping = i18n.getLocaleMapping(ctx.locale, 'methods');
+// const i18nName = getMethodName(mapping, controllerName, methodName);
+// console.log(i18nName);
+
+const defaultMethods = ['create', 'update', 'delete'];
+export const DataRecordInit = (decoratorService: MidwayDecoratorService) => {
+  decoratorService.registerMethodHandler(DATARECORD_KEY, options => {
+    return {
+      around: async (joinPoint: JoinPoint) => {
+        let recordPreData = null;
+        let recordService = null;
+        try {
+          const instance = joinPoint.target;
+          const controllerName = options.target.name;
+          const methodName = options.propertyName;
+          const metaData = options.metadata;
+          const ctx = instance[REQUEST_OBJ_CTX_KEY];
+          recordService = await ctx.requestContext.getAsync(DataRecordService);
+          // 组织记录数据
+          recordPreData = await recordService.makeLogs(controllerName, methodName);
+          if (get(metaData, 'before')) {
+            recordPreData.origin_data = await instance.service[get(metaData, 'before')]();
+          } else if (defaultMethods.includes(methodName)) {
+            // 如果是create,update,delete 默认方法.那就默认处理.自己写的自己处理
+
+            recordPreData.origin_data = await recordService.getDefaultMethodOriginData(instance.service, methodName);
+          }
+          // 执行原函数
+          const result = await joinPoint.proceed(...joinPoint.args);
+          // 如果是create,update,delete 默认方法.那就默认处理.自己写的自己处理
+          if (get(metaData, 'after')) {
+            recordPreData.new_data = await instance.service[get(metaData, 'after')]();
+          } else if (defaultMethods.includes(methodName)) {
+            let od = null;
+            if (methodName === 'create') od = result;
+            else od = recordPreData.origin_data;
+            recordPreData.new_data = await recordService.getDefaultMethodNewData(instance.service, methodName, od);
+          }
+          recordPreData.status = '0';
+          return result;
+        } catch (error) {
+          if (recordPreData) {
+            // 有数据的情况下存日志有意义,否则就是只有个status没意义
+            recordPreData.status = '1';
+          }
+          throw error;
+        } finally {
+          // save logs
+          if (recordPreData) await recordService.create(recordPreData);
+        }
+      },
+    };
+  });
+};

+ 37 - 0
src/decorator/verifyToken.decorator.ts

@@ -0,0 +1,37 @@
+import {
+  JoinPoint,
+  MidwayDecoratorService,
+  REQUEST_OBJ_CTX_KEY,
+  createCustomMethodDecorator,
+} from '@midwayjs/core';
+import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+export const VERIFYTOKEN_KEY = 'decorator:verify_token';
+/**
+ *
+ * 只检测是否有token,此装饰器不做具体用token处理什么.
+ */
+export function verifyToken() {
+  return createCustomMethodDecorator(VERIFYTOKEN_KEY, {});
+}
+/**
+ * 验证token装饰器实现
+ * @param decoratorService 装饰器服务
+ */
+export function VerifyTokenInit(decoratorService: MidwayDecoratorService) {
+  decoratorService.registerMethodHandler(VERIFYTOKEN_KEY, options => {
+    return {
+      around: async (joinPoint: JoinPoint) => {
+        const instance = joinPoint.target;
+        const ctx = instance[REQUEST_OBJ_CTX_KEY];
+        const user = ctx.user;
+        if (!user)
+          throw new ServiceError(
+            '未检测到登录信息,无法访问接口!',
+            FrameworkErrorEnum.NOT_LOGIN
+          );
+        const result = await joinPoint.proceed(...joinPoint.args);
+        return result;
+      },
+    };
+  });
+}

+ 65 - 0
src/entity/basic.entity.ts

@@ -0,0 +1,65 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'basic' },
+})
+export class Basic extends BaseModel {
+  @prop({ required: false, index: true, zh: '实验室类别', remark: '字典:laboratory_type' })
+  type: string;
+  @prop({ required: false, index: true, zh: '实验室名称' })
+  name: string;
+  @prop({ required: false, index: false, zh: '英文名称' })
+  english_name: string;
+  @prop({ required: false, index: false, zh: '所属学科' })
+  subject: string;
+  @prop({ required: false, index: false, zh: '所属专业' })
+  major: string;
+  @prop({ required: false, index: false, zh: '实验室面积' })
+  lab_acreage: string;
+  @prop({ required: false, index: false, zh: '批建时间' })
+  build_time: string;
+  @prop({ required: false, index: false, zh: '实验室地址' })
+  lab_address: string;
+  @prop({ required: false, index: false, zh: '依托单位id', remark: 'unit_name不需要了,现在所有的实验室都有依托单位' })
+  unit: string;
+  @prop({ required: false, index: false, zh: '实验室定位' })
+  position: string;
+  @prop({ required: false, index: false, zh: '实验室建设方案' })
+  plan: Array<any>;
+  @prop({ required: false, index: false, zh: '实验室主任' })
+  chief_name: string;
+  @prop({ required: false, index: false, zh: '实验室联系人' })
+  lab_person: string;
+  @prop({ required: false, index: false, zh: '实验室联系人电话' })
+  lab_phone: string;
+  @prop({ required: false, index: false, zh: '电子邮箱' })
+  lab_email: string;
+  @prop({ required: false, index: false, zh: '申报单位' })
+  declare_unit: object;
+  @prop({ required: false, index: false, zh: '平台负责人' })
+  leading_cadre: object;
+  @prop({ required: false, index: false, zh: '科研助理' })
+  assistant: object;
+  @prop({ required: false, index: false, zh: '财务助理是否与科研助理同一人' })
+  is_alike: boolean;
+  @prop({ required: false, index: false, zh: '财务助理' })
+  finance: object;
+  @prop({ required: false, index: false, zh: '所属吉林省重点实验室' })
+  ss_laboratory: string;
+  @prop({ required: false, index: false, zh: '整合基础' })
+  zh_basis: string;
+  @prop({ required: false, index: false, zh: '是否公开', remark: '字典:info_show' })
+  is_show: string;
+  @prop({ required: false, index: false, zh: '地区' })
+  region: string;
+  @prop({ required: false, index: true, zh: '状态', default: '2' })
+  status: string;
+  @prop({ required: false, index: false, zh: '主任入驻记录' })
+  chief_logs: Array<any>;
+  @prop({ required: false, index: false, zh: '发展前景' })
+  develop: string;
+  @prop({ required: false, index: false, zh: '运行机制' })
+  mechanism: string;
+  @prop({ required: false, index: false, zh: '运行机制文件' })
+  mechanism_file: Array<any>;
+}

+ 41 - 0
src/entity/platform/achievement.entity.ts

@@ -0,0 +1,41 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'achievement' },
+})
+export class Achievement extends BaseModel {
+  @prop({ required: false, index: true, zh: '用户id' })
+  user: string;
+  @prop({ required: false, index: true, zh: '专利号' })
+  patent: string;
+  @prop({ required: false, index: true, zh: '名称' })
+  name: string;
+  @prop({ required: false, index: true, zh: '类型' })
+  type: string;
+  @prop({ required: false, index: true, zh: '属性' })
+  attribute: string;
+  @prop({ required: false, index: true, zh: '出让方式' })
+  sell: string;
+  @prop({ required: false, index: true, zh: '成熟度' })
+  mature: string;
+  @prop({ required: false, index: true, zh: '行业领域' })
+  field: string;
+  @prop({ required: false, index: true, zh: '技术分类' })
+  technology: string;
+  @prop({ required: false, index: true, zh: '成果地区' })
+  area: Array<any>;
+  @prop({ required: false, index: false, zh: '发布时间' })
+  time: string;
+  @prop({ required: false, index: true, zh: '参考价格' })
+  money: string;
+  @prop({ required: false, index: false, zh: '简介' })
+  brief: string;
+  @prop({ required: false, index: false, zh: '附件' })
+  file: Array<any>;
+  @prop({ required: false, index: true, zh: '成果状态', default: '0' })
+  achievement_status: string;
+  @prop({ required: false, index: true, zh: '是否公开', default: '0' })
+  is_use: string;
+  @prop({ required: false, index: true, zh: '状态' , default: '0'})
+  status: string;
+}

+ 33 - 0
src/entity/platform/demand.entity.ts

@@ -0,0 +1,33 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'demand' },
+})
+export class Demand extends BaseModel {
+  @prop({ required: false, index: true, zh: '用户id' })
+  user: string;
+  @prop({ required: false, index: true, zh: '名称' })
+  name: string;
+  @prop({ required: false, index: true, zh: '类型' })
+  type: string;
+  @prop({ required: false, index: true, zh: '行业领域' })
+  field: string;
+  @prop({ required: false, index: false, zh: '需求紧急度' })
+  urgent: string;
+  @prop({ required: false, index: true, zh: '合作方式' })
+  method: string;
+  @prop({ required: false, index: false, zh: '有效期' })
+  time: Array<any>;
+  @prop({ required: false, index: false, zh: '价格' })
+  money: string;
+  @prop({ required: false, index: true, zh: '需求地区' })
+  area: Array<any>;
+  @prop({ required: false, index: false, zh: '简介' })
+  brief: string;
+  @prop({ required: false, index: true, zh: '需求状态', default: '0' })
+  demand_status: string;
+  @prop({ required: false, index: true, zh: '是否公开', default: '0' })
+  is_use: string;
+  @prop({ required: false, index: true, zh: '状态' })
+  status: string;
+}

+ 29 - 0
src/entity/platform/match.entity.ts

@@ -0,0 +1,29 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'match' },
+})
+export class Match extends BaseModel {
+  @prop({ required: false, index: true, zh: '用户id' })
+  user: string;
+  @prop({ required: false, index: true, zh: '名称' })
+  name: string;
+  @prop({ required: false, index: true, zh: '类型' })
+  type: string;
+  @prop({ required: false, index: false, zh: '有效期' })
+  time: Array<any>;
+  @prop({ required: false, index: false, zh: '奖金' })
+  money: string;
+  @prop({ required: false, index: false, zh: '赛事规则' })
+  rules: object;
+  @prop({ required: false, index: false, zh: '简介' })
+  brief: string;
+  @prop({ required: false, index: false, zh: '封面' })
+  file: Array<any>;
+  @prop({ required: false, index: true, zh: '赛事状态', default: '0' })
+  match_status: string;
+  @prop({ required: false, index: true, zh: '是否公开', default: '0' })
+  is_use: string;
+  @prop({ required: false, index: true, zh: '状态' , default: '0'})
+  status: string;
+}

+ 23 - 0
src/entity/platform/news.entity.ts

@@ -0,0 +1,23 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'news' },
+})
+export class News extends BaseModel {
+  @prop({ required: false, index: true, zh: '标题' })
+  title: string;
+  @prop({ required: false, index: false, zh: '发布人' })
+  person: string;
+  @prop({ required: false, index: false, zh: '发布时间' })
+  time: string;
+  @prop({ required: false, index: false, zh: '内容' })
+  content: string;
+  @prop({ required: false, index: false, zh: '浏览次数', default: 0 })
+  number: number;
+  @prop({ required: false, index: false, zh: '类型', remark: '0:政策新闻,1:新闻资讯', default: '0' })
+  type: string;
+  @prop({ required: false, index: true, zh: '是否使用', default: '0' })
+  is_use: string;
+  @prop({ required: false, index: true, zh: '状态' , default: '0'})
+  status: string;
+}

+ 34 - 0
src/entity/system/admin.entity.ts

@@ -0,0 +1,34 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+import { isString } from 'lodash';
+@modelOptions({
+  schemaOptions: { collection: 'admin' },
+})
+export class Admin extends BaseModel {
+  @prop({ required: true, index: true, zh: '账号' })
+  account: string;
+  @prop({ required: false, index: false, zh: '名称' })
+  nick_name: string;
+  // 手动删除set前的大括号,处理太麻烦了.就手动删除吧
+  @prop({
+    required: false,
+    index: false,
+    zh: '密码',
+    select: false,
+    set: val => {
+      if (isString(val)) {
+        return { secret: val };
+      }
+      return val;
+    },
+  })
+  password: object;
+  @prop({ required: false, index: false, zh: '是否是超级管理员', remark: '0:超级管理员;1普通用户', default: '1' })
+  is_super: string;
+  @prop({ required: false, index: false, zh: '角色' })
+  role: string;
+  @prop({ required: false, index: false, zh: 'openid' })
+  openid: string;
+  @prop({ required: false, index: false, zh: '是否启用', default: '0' })
+  is_use: string;
+}

+ 15 - 0
src/entity/system/config.entity.ts

@@ -0,0 +1,15 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'config' },
+})
+export class Config extends BaseModel {
+  @prop({ required: false, index: false, zh: 'logo' })
+  logo: Array<any>;
+  @prop({ required: false, index: false, zh: '早餐时间', remark: '' })
+  b_time: Array<any>;
+  @prop({ required: false, index: false, zh: '午餐时间' })
+  l_time: Array<any>;
+  @prop({ required: false, index: false, zh: '晚餐时间' })
+  d_time: Array<any>;
+}

+ 17 - 0
src/entity/system/dictData.entity.ts

@@ -0,0 +1,17 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'dictData' },
+})
+export class DictData extends BaseModel {
+  @prop({ required: false, index: true, zh: '字典类型编码' })
+  code: string;
+  @prop({ required: false, index: false, zh: '数据显示值' })
+  label: string;
+  @prop({ required: false, index: false, zh: '数据选择值' })
+  value: string;
+  @prop({ required: false, index: false, zh: '排序' })
+  sort: number;
+  @prop({ required: false, index: true, zh: '是否使用', default: '0' })
+  is_use: string;
+}

+ 15 - 0
src/entity/system/dictType.entity.ts

@@ -0,0 +1,15 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'dictType' },
+})
+export class DictType extends BaseModel {
+  @prop({ required: false, index: false, zh: '字典类型名称' })
+  title: string;
+  @prop({ required: false, index: true, zh: '编码' })
+  code: string;
+  @prop({ required: false, index: false, zh: '备注' })
+  remark: string;
+  @prop({ required: false, index: true, zh: '是否使用' })
+  is_use: string;
+}

+ 33 - 0
src/entity/system/menus.entity.ts

@@ -0,0 +1,33 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'menus' },
+})
+export class Menus extends BaseModel {
+  @prop({ required: false, index: false, zh: '菜单名称' })
+  name: string;
+  @prop({ required: false, index: false, zh: '路由名称', remark: '英文' })
+  route_name: string;
+  @prop({ required: false, index: false, zh: '国际化编码' })
+  i18n_code: string;
+  @prop({ required: false, index: true, zh: '父级菜单' })
+  parent_id: string;
+  @prop({ required: false, index: false, zh: '显示顺序' })
+  order_num: number;
+  @prop({ required: false, index: false, zh: '路由地址' })
+  path: string;
+  @prop({ required: false, index: false, zh: '组件地址' })
+  component: string;
+  @prop({ required: false, index: true, zh: '菜单类型', remark: '0:目录;1:菜单;2:子页面' })
+  type: string;
+  @prop({ required: false, index: false, zh: '图标' })
+  icon: string;
+  @prop({ required: false, index: false, zh: '功能列表', remark: '不在功能列表中的功能不能使用' })
+  config: Array<any>;
+  @prop({ required: false, index: true, zh: '是否为默认菜单', default: '1', remark: '默认:0,非默认:1; 默认不能删除' })
+  is_default: string;
+  @prop({ required: false, index: false, zh: '备注' })
+  remark: string;
+  @prop({ required: false, index: true, zh: '是否启用', default: '0' })
+  is_use: string;
+}

+ 17 - 0
src/entity/system/role.entity.ts

@@ -0,0 +1,17 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'role' },
+})
+export class Role extends BaseModel {
+  @prop({ required: false, index: false, zh: '角色名称' })
+  name: string;
+  @prop({ required: false, index: true, zh: '角色编码' })
+  code: string;
+  @prop({ required: false, index: false, zh: '菜单' })
+  menu: Array<any>;
+  @prop({ required: false, index: false, zh: '简介' })
+  brief: string;
+  @prop({ required: false, index: true, zh: '是否使用', default: '0' })
+  is_use: string;
+}

+ 15 - 0
src/entity/system/user.entity.ts

@@ -0,0 +1,15 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'user' },
+})
+export class User extends BaseModel {
+  @prop({ required: false, index: false, zh: '微信小程序id' })
+  openid: string;
+  @prop({ required: false, index: false, zh: '昵称' })
+  nick_name: string;
+  @prop({ required: false, index: false, zh: '电话' })
+  tel: string;
+  @prop({ required: false, index: false, zh: '部门' })
+  dept: string;
+}

+ 27 - 0
src/entityRecord/dataRecord.entity.ts

@@ -0,0 +1,27 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'dataRecord' },
+})
+export class DataRecord extends BaseModel {
+  @prop({ required: false, index: false, zh: '操作人' })
+  operator: object;
+  @prop({ required: false, index: false, zh: 'ip地址' })
+  ip: string;
+  @prop({ required: false, index: false, zh: '时间' })
+  time: string;
+  @prop({ required: false, index: false, zh: '对象', remark: 'controller' })
+  controller: string;
+  @prop({ required: false, index: false, zh: '函数', remark: '函数名,记录code.i18n兑换用' })
+  method: string;
+  @prop({ required: false, index: false, zh: '原数据', remark: '多个表关联性处理时需要先将修改的数据都查出来,key:表名;value:数组(本表修改的数据都放里面)' })
+  origin_data: object;
+  @prop({ required: false, index: false, zh: '新数据' })
+  new_data: object;
+  @prop({ required: false, index: false, zh: '页面路由' })
+  router: string;
+  @prop({ required: false, index: false, zh: '设备' })
+  device: string;
+  @prop({ required: false, index: false, zh: '状态', remark: '0:成功;-1失败' })
+  status: string;
+}

+ 6 - 0
src/interface.ts

@@ -0,0 +1,6 @@
+/**
+ * @description User-Service parameters
+ */
+export interface IUserOptions {
+  uid: number;
+}

+ 41 - 0
src/interface/login.interface.ts

@@ -0,0 +1,41 @@
+import { ApiProperty } from '@midwayjs/swagger';
+import { Rule, RuleType } from '@midwayjs/validate';
+import { get } from 'lodash';
+export enum LoginType {
+  Admin = 'Admin',
+}
+
+export class LoginDTO {
+  @ApiProperty({ description: '账号' })
+  @Rule(RuleType['string']().required())
+  account: string = undefined;
+  @ApiProperty({ description: '密码' })
+  @Rule(RuleType['string']().required())
+  password: string = undefined;
+}
+
+export class UPwdDTO {
+  @ApiProperty({ description: '用户数据id' })
+  @Rule(RuleType['string']().required())
+  _id: string = undefined;
+  @ApiProperty({ description: '密码' })
+  @Rule(RuleType['string']().required())
+  password: string = undefined;
+}
+
+export class LoginVO {
+  constructor(data: object) {
+    this._id = get(data, '_id');
+    this.nick_name = get(data, 'nick_name');
+    this.openid = get(data, 'openid');
+    this.role = get(data, 'role');
+    this.is_super = get(data, 'is_super');
+  }
+  _id: string;
+  nick_name: string;
+  openid: string;
+  role: string;
+  is_super: number;
+  @ApiProperty({ description: '登录标识' })
+  'login_code': string = undefined;
+}

+ 167 - 0
src/interface/platform/achievement.interface.ts

@@ -0,0 +1,167 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_achievement {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '专利号' })
+  'patent': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '属性' })
+  'attribute': string = undefined;
+  @ApiProperty({ description: '出让方式' })
+  'sell': string = undefined;
+  @ApiProperty({ description: '成熟度' })
+  'mature': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  'field': string = undefined;
+  @ApiProperty({ description: '技术分类' })
+  'technology': string = undefined;
+  @ApiProperty({ description: '成果地区' })
+  'area': Array<any> = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '参考价格' })
+  'money': string = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '附件' })
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '成果状态' })
+  'achievement_status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_achievement extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['user', 'patent', 'name', 'type', 'attribute', 'sell', 'mature', 'field', 'technology', 'money', 'status', 'achievement_status', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '专利号' })
+  'patent': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '属性' })
+  'attribute': string = undefined;
+  @ApiProperty({ description: '出让方式' })
+  'sell': string = undefined;
+  @ApiProperty({ description: '成熟度' })
+  'mature': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  'field': string = undefined;
+  @ApiProperty({ description: '技术分类' })
+  'technology': string = undefined;
+  @ApiProperty({ description: '参考价格' })
+  'money': string = undefined;
+  @ApiProperty({ description: '成果状态' })
+  'achievement_status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QVO_achievement extends FVO_achievement {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_achievement {
+  @ApiProperty({ description: '用户id' })
+  @Rule(RuleType['string']().empty(''))
+  'user': string = undefined;
+  @ApiProperty({ description: '专利号' })
+  @Rule(RuleType['string']().empty(''))
+  'patent': string = undefined;
+  @ApiProperty({ description: '名称' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '属性' })
+  @Rule(RuleType['string']().empty(''))
+  'attribute': string = undefined;
+  @ApiProperty({ description: '出让方式' })
+  @Rule(RuleType['string']().empty(''))
+  'sell': string = undefined;
+  @ApiProperty({ description: '成熟度' })
+  @Rule(RuleType['string']().empty(''))
+  'mature': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  @Rule(RuleType['string']().empty(''))
+  'field': string = undefined;
+  @ApiProperty({ description: '技术分类' })
+  @Rule(RuleType['string']().empty(''))
+  'technology': string = undefined;
+  @ApiProperty({ description: '成果地区' })
+  @Rule(RuleType['array']().empty(''))
+  'area': Array<any> = undefined;
+  @ApiProperty({ description: '发布时间' })
+  @Rule(RuleType['string']().empty(''))
+  'time': string = undefined;
+  @ApiProperty({ description: '参考价格' })
+  @Rule(RuleType['string']().empty(''))
+  'money': string = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '附件' })
+  @Rule(RuleType['array']().empty(''))
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: 'achievement_status' })
+  @Rule(RuleType['string']().empty(''))
+  'achievement_status': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_achievement extends FVO_achievement {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_achievement extends CDTO_achievement {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_achievement extends FVO_achievement {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 139 - 0
src/interface/platform/demand.interface.ts

@@ -0,0 +1,139 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_demand {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  'field': string = undefined;
+  @ApiProperty({ description: '需求紧急度' })
+  'urgent': string = undefined;
+  @ApiProperty({ description: '合作方式' })
+  'method': string = undefined;
+  @ApiProperty({ description: '有效期' })
+  'time': Array<any> = undefined;
+  @ApiProperty({ description: '价格' })
+  'money': string = undefined;
+  @ApiProperty({ description: '需求地区' })
+  'area': Array<any> = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '需求状态' })
+  'demand_status': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_demand extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['user', 'name', 'type', 'field', 'urgent', 'method', 'demand_status', 'status', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  'field': string = undefined;
+  @ApiProperty({ description: '合作方式' })
+  'method': string = undefined;
+  @ApiProperty({ description: '需求紧急度' })
+  'urgent': string = undefined;
+  @ApiProperty({ description: '需求状态' })
+  'demand_status': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+}
+
+export class QVO_demand extends FVO_demand {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_demand {
+  @ApiProperty({ description: '用户id' })
+  @Rule(RuleType['string']().empty(''))
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  @Rule(RuleType['string']().empty(''))
+  'field': string = undefined;
+  @ApiProperty({ description: '需求紧急度' })
+  @Rule(RuleType['string']().empty(''))
+  'urgent': string = undefined;
+  @ApiProperty({ description: '合作方式' })
+  @Rule(RuleType['string']().empty(''))
+  'method': string = undefined;
+  @ApiProperty({ description: '有效期' })
+  @Rule(RuleType['array']().empty(''))
+  'time': Array<any> = undefined;
+  @ApiProperty({ description: '价格' })
+  @Rule(RuleType['string']().empty(''))
+  'money': string = undefined;
+  @ApiProperty({ description: '需求地区' })
+  @Rule(RuleType['array']().empty(''))
+  'area': Array<any> = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '需求状态' })
+  @Rule(RuleType['string']().empty(''))
+  'demand_status': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_demand extends FVO_demand {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_demand extends CDTO_demand {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_demand extends FVO_demand {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 123 - 0
src/interface/platform/match.interface.ts

@@ -0,0 +1,123 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_match {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '有效期' })
+  'time': Array<any> = undefined;
+  @ApiProperty({ description: '奖金' })
+  'money': string = undefined;
+  @ApiProperty({ description: '赛事规则' })
+  'rules': object = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '封面' })
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '赛事状态' })
+  'match_status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_match extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['user', 'name', 'type', 'status', 'match_status', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '赛事状态' })
+  'match_status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QVO_match extends FVO_match {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_match {
+  @ApiProperty({ description: '用户id' })
+  @Rule(RuleType['string']().empty(''))
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '有效期' })
+  @Rule(RuleType['array']().empty(''))
+  'time': Array<any> = undefined;
+  @ApiProperty({ description: '奖金' })
+  @Rule(RuleType['string']().empty(''))
+  'money': string = undefined;
+  @ApiProperty({ description: '赛事规则' })
+  @Rule(RuleType['object']().empty(''))
+  'rules': object = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '封面' })
+  @Rule(RuleType['array']().empty(''))
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '赛事状态' })
+  @Rule(RuleType['string']().empty(''))
+  'match_status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+export class CVO_match extends FVO_match {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_match extends CDTO_match {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_match extends FVO_match {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 108 - 0
src/interface/platform/news.interface.ts

@@ -0,0 +1,108 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_news {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '发布人' })
+  'person': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '内容' })
+  'content': string = undefined;
+  @ApiProperty({ description: '浏览次数' })
+  'number': number = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_news extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['title', 'person', 'time', 'type', 'is_use','status'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '标题' })
+  'title': string = undefined;
+  @ApiProperty({ description: '发布人' })
+  'person': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QVO_news extends FVO_news {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_news {
+  @ApiProperty({ description: '标题' })
+  @Rule(RuleType['string']().empty(''))
+  'title': string = undefined;
+  @ApiProperty({ description: '发布人' })
+  @Rule(RuleType['string']().empty(''))
+  'person': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  @Rule(RuleType['string']().empty(''))
+  'time': string = undefined;
+  @ApiProperty({ description: '内容' })
+  @Rule(RuleType['string']().empty(''))
+  'content': string = undefined;
+  @ApiProperty({ description: '浏览次数' })
+  @Rule(RuleType['number']().empty(''))
+  'number': number = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+export class CVO_news extends FVO_news {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_news extends CDTO_news {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_news extends FVO_news {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 112 - 0
src/interface/record/dataRecord.interface.ts

@@ -0,0 +1,112 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_dataRecord {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '操作人' })
+  'operator': object = undefined;
+  @ApiProperty({ description: 'ip地址' })
+  'ip': string = undefined;
+  @ApiProperty({ description: '时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '对象' })
+  'controller': string = undefined;
+  @ApiProperty({ description: '函数' })
+  'method': string = undefined;
+  @ApiProperty({ description: '原数据' })
+  'origin_data': object = undefined;
+  @ApiProperty({ description: '新数据' })
+  'new_data': object = undefined;
+  @ApiProperty({ description: '页面路由' })
+  'router': string = undefined;
+  @ApiProperty({ description: '设备' })
+  'device': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+
+export class QDTO_dataRecord extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+}
+
+
+export class QVO_dataRecord extends FVO_dataRecord {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class CDTO_dataRecord {
+  @ApiProperty({ description: '操作人' })
+@Rule(RuleType['object']().empty(''))
+  'operator': object = undefined;
+  @ApiProperty({ description: 'ip地址' })
+@Rule(RuleType['string']().empty(''))
+  'ip': string = undefined;
+  @ApiProperty({ description: '时间' })
+@Rule(RuleType['string']().empty(''))
+  'time': string = undefined;
+  @ApiProperty({ description: '对象' })
+@Rule(RuleType['string']().empty(''))
+  'controller': string = undefined;
+  @ApiProperty({ description: '函数' })
+@Rule(RuleType['string']().empty(''))
+  'method': string = undefined;
+  @ApiProperty({ description: '原数据' })
+@Rule(RuleType['object']().empty(''))
+  'origin_data': object = undefined;
+  @ApiProperty({ description: '新数据' })
+@Rule(RuleType['object']().empty(''))
+  'new_data': object = undefined;
+  @ApiProperty({ description: '页面路由' })
+@Rule(RuleType['string']().empty(''))
+  'router': string = undefined;
+  @ApiProperty({ description: '设备' })
+@Rule(RuleType['string']().empty(''))
+  'device': string = undefined;
+  @ApiProperty({ description: '状态' })
+@Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+
+export class CVO_dataRecord extends FVO_dataRecord {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class UDTO_dataRecord extends CDTO_dataRecord {
+    @ApiProperty({ description: '数据id' })
+    @Rule(RuleType['string']().empty(''))
+    _id: string = undefined;
+}
+
+
+export class UVAO_dataRecord extends FVO_dataRecord {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 93 - 0
src/interface/system/admin.interface.ts

@@ -0,0 +1,93 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_admin {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '账号' })
+  'account': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'nick_name': string = undefined;
+  @ApiProperty({ description: '密码' })
+  'password': string = undefined;
+  @ApiProperty({ description: '是否是超级管理员' })
+  'is_super': string = undefined;
+  @ApiProperty({ description: '角色' })
+  'role': string = undefined;
+  @ApiProperty({ description: 'openid' })
+  'openid': string = undefined;
+  @ApiProperty({ description: '是否启用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_admin extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['account'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '账号' })
+  'account': string = undefined;
+}
+
+export class QVO_admin extends FVO_admin {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_admin {
+  @ApiProperty({ description: '账号' })
+  @Rule(RuleType['string']().empty(''))
+  'account': string = undefined;
+  @ApiProperty({ description: '名称' })
+  @Rule(RuleType['string']().empty(''))
+  'nick_name': string = undefined;
+  @ApiProperty({ description: '密码' })
+  @Rule(RuleType['string']().empty(''))
+  'password': string = undefined;
+  @ApiProperty({ description: '是否是超级管理员' })
+  @Rule(RuleType['string']().empty(''))
+  'is_super': string = undefined;
+  @ApiProperty({ description: '角色' })
+  @Rule(RuleType['string']().empty(''))
+  'role': string = undefined;
+  @ApiProperty({ description: 'openid' })
+  @Rule(RuleType['string']().empty(''))
+  'openid': string = undefined;
+  @ApiProperty({ description: '是否启用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_admin extends FVO_admin {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_admin extends CDTO_admin {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_admin extends FVO_admin {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 82 - 0
src/interface/system/config.interface.ts

@@ -0,0 +1,82 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_config {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: 'logo' })
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '早餐时间' })
+  'b_time': Array<any> = undefined;
+  @ApiProperty({ description: '午餐时间' })
+  'l_time': Array<any> = undefined;
+  @ApiProperty({ description: '晚餐时间' })
+  'd_time': Array<any> = undefined;
+}
+
+
+export class QDTO_config extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+}
+
+
+export class QVO_config extends FVO_config {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class CDTO_config {
+  @ApiProperty({ description: 'logo' })
+@Rule(RuleType['array']().empty(''))
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '早餐时间' })
+@Rule(RuleType['array']().empty(''))
+  'b_time': Array<any> = undefined;
+  @ApiProperty({ description: '午餐时间' })
+@Rule(RuleType['array']().empty(''))
+  'l_time': Array<any> = undefined;
+  @ApiProperty({ description: '晚餐时间' })
+@Rule(RuleType['array']().empty(''))
+  'd_time': Array<any> = undefined;
+}
+
+
+export class CVO_config extends FVO_config {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class UDTO_config extends CDTO_config {
+    @ApiProperty({ description: '数据id' })
+    @Rule(RuleType['string']().empty(''))
+    _id: string = undefined;
+}
+
+
+export class UVAO_config extends FVO_config {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 87 - 0
src/interface/system/dictData.interface.ts

@@ -0,0 +1,87 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_dictData {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '字典类型编码' })
+  'code': string = undefined;
+  @ApiProperty({ description: '数据显示值' })
+  'label': string = undefined;
+  @ApiProperty({ description: '数据选择值' })
+  'value': string = undefined;
+  @ApiProperty({ description: '排序' })
+  'sort': number = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_dictData extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['code', 'label', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '字典类型编码' })
+  'code': string = undefined;
+  @ApiProperty({ description: '数据显示值' })
+  'label': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QVO_dictData extends FVO_dictData {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_dictData {
+  @ApiProperty({ description: '字典类型编码' })
+  @Rule(RuleType['string']().empty(''))
+  'code': string = undefined;
+  @ApiProperty({ description: '数据显示值' })
+  @Rule(RuleType['string']().empty(''))
+  'label': string = undefined;
+  @ApiProperty({ description: '数据选择值' })
+  @Rule(RuleType['string']().empty(''))
+  'value': string = undefined;
+  @ApiProperty({ description: '排序' })
+  @Rule(RuleType['number']().empty(''))
+  'sort': number = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_dictData extends FVO_dictData {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_dictData extends CDTO_dictData {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_dictData extends FVO_dictData {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 82 - 0
src/interface/system/dictType.interface.ts

@@ -0,0 +1,82 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_dictType {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '字典类型名称' })
+  'title': string = undefined;
+  @ApiProperty({ description: '编码' })
+  'code': string = undefined;
+  @ApiProperty({ description: '备注' })
+  'remark': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_dictType extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['title', 'code', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '字典类型名称' })
+  'title': string = undefined;
+  @ApiProperty({ description: '编码' })
+  'code': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QVO_dictType extends FVO_dictType {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_dictType {
+  @ApiProperty({ description: '字典类型名称' })
+  @Rule(RuleType['string']().empty(''))
+  'title': string = undefined;
+  @ApiProperty({ description: '编码' })
+  @Rule(RuleType['string']().empty(''))
+  'code': string = undefined;
+  @ApiProperty({ description: '备注' })
+  @Rule(RuleType['string']().empty(''))
+  'remark': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_dictType extends FVO_dictType {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_dictType extends CDTO_dictType {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_dictType extends FVO_dictType {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 127 - 0
src/interface/system/menus.interface.ts

@@ -0,0 +1,127 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_menus {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '菜单名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '路由名称' })
+  'route_name': string = undefined;
+  @ApiProperty({ description: '国际化编码' })
+  'i18n_code': string = undefined;
+  @ApiProperty({ description: '父级菜单' })
+  'parent_id': string = undefined;
+  @ApiProperty({ description: '显示顺序' })
+  'order_num': number = undefined;
+  @ApiProperty({ description: '路由地址' })
+  'path': string = undefined;
+  @ApiProperty({ description: '组件地址' })
+  'component': string = undefined;
+  @ApiProperty({ description: '菜单类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '图标' })
+  'icon': string = undefined;
+  @ApiProperty({ description: '功能列表' })
+  'config': Array<any> = undefined;
+  @ApiProperty({ description: '是否为默认菜单' })
+  'is_default': string = undefined;
+  @ApiProperty({ description: '备注' })
+  'remark': string = undefined;
+  @ApiProperty({ description: '是否启用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_menus extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['parent_id', 'type', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '父级菜单' })
+  'parent_id': string = undefined;
+  @ApiProperty({ description: '菜单类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '是否启用' })
+  'is_use': string = undefined;
+}
+
+export class QVO_menus extends FVO_menus {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_menus {
+  @ApiProperty({ description: '菜单名称' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '路由名称' })
+  @Rule(RuleType['string']().empty(''))
+  'route_name': string = undefined;
+  @ApiProperty({ description: '国际化编码' })
+  @Rule(RuleType['string']().empty(''))
+  'i18n_code': string = undefined;
+  @ApiProperty({ description: '父级菜单' })
+  @Rule(RuleType['string']().empty(''))
+  'parent_id': string = undefined;
+  @ApiProperty({ description: '显示顺序' })
+  @Rule(RuleType['number']().empty(''))
+  'order_num': number = undefined;
+  @ApiProperty({ description: '路由地址' })
+  @Rule(RuleType['string']().empty(''))
+  'path': string = undefined;
+  @ApiProperty({ description: '组件地址' })
+  @Rule(RuleType['string']().empty(''))
+  'component': string = undefined;
+  @ApiProperty({ description: '菜单类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '图标' })
+  @Rule(RuleType['string']().empty(''))
+  'icon': string = undefined;
+  @ApiProperty({ description: '功能列表' })
+  @Rule(RuleType['array']().empty(''))
+  'config': Array<any> = undefined;
+  @ApiProperty({ description: '是否为默认菜单' })
+  @Rule(RuleType['string']().empty(''))
+  'is_default': string = undefined;
+  @ApiProperty({ description: '备注' })
+  @Rule(RuleType['string']().empty(''))
+  'remark': string = undefined;
+  @ApiProperty({ description: '是否启用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_menus extends FVO_menus {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_menus extends CDTO_menus {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_menus extends FVO_menus {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 85 - 0
src/interface/system/role.interface.ts

@@ -0,0 +1,85 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_role {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '角色名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '角色编码' })
+  'code': string = undefined;
+  @ApiProperty({ description: '菜单' })
+  'menu': Array<any> = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_role extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['code', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '角色编码' })
+  'code': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QVO_role extends FVO_role {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_role {
+  @ApiProperty({ description: '角色名称' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '角色编码' })
+  @Rule(RuleType['string']().empty(''))
+  'code': string = undefined;
+  @ApiProperty({ description: '菜单' })
+  @Rule(RuleType['array']().empty(''))
+  'menu': Array<any> = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_role extends FVO_role {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_role extends CDTO_role {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_role extends FVO_role {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 76 - 0
src/interface/system/user.interface.ts

@@ -0,0 +1,76 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_user {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '微信小程序id' })
+  'openid': string = undefined;
+  @ApiProperty({ description: '昵称' })
+  'nick_name': string = undefined;
+  @ApiProperty({ description: '电话' })
+  'tel': string = undefined;
+  @ApiProperty({ description: '部门' })
+  'dept': string = undefined;
+}
+
+export class QDTO_user extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+}
+
+export class QVO_user extends FVO_user {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_user {
+  @ApiProperty({ description: '微信小程序id' })
+  @Rule(RuleType['string']().empty(''))
+  'openid': string = undefined;
+  @ApiProperty({ description: '昵称' })
+  @Rule(RuleType['string']().empty(''))
+  'nick_name': string = undefined;
+  @ApiProperty({ description: '电话' })
+  @Rule(RuleType['string']().empty(''))
+  'tel': string = undefined;
+  @ApiProperty({ description: '部门' })
+  @Rule(RuleType['string']().empty(''))
+  'dept': string = undefined;
+}
+
+export class CVO_user extends FVO_user {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_user extends CDTO_user {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_user extends FVO_user {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 3 - 0
src/locales/en_us/defaults.ts

@@ -0,0 +1,3 @@
+export default {
+  locale: 'language is: {locale}',
+};

+ 17 - 0
src/locales/en_us/errors.ts

@@ -0,0 +1,17 @@
+export default {
+  locale: 'error language is: {locale}',
+  '-1': 'unknown error',
+  '-2': 'need params',
+  '-20': 'params error',
+  '-3': 'need query',
+  '-30': 'query error',
+  '-4': 'need body',
+  '-40': 'body error',
+  '-5': 'need args',
+  '-50': 'bad args',
+  '-10': 'data not found',
+  '-100': 'service fault',
+  '-101': 'not login',
+  '-102': 'bad password',
+  '-500': 'request falut',
+};

+ 11 - 0
src/locales/zh_cn/controller_method.ts

@@ -0,0 +1,11 @@
+export default {
+  RoleController: {
+    create: '角色创建',
+    query: '角色查询',
+    fetch: '角色单数据查询',
+    delete: '角色删除',
+    test: {
+      test: 2,
+    },
+  },
+};

+ 3 - 0
src/locales/zh_cn/defaults.ts

@@ -0,0 +1,3 @@
+export default {
+  locale: '当前语言为: {locale}',
+};

+ 17 - 0
src/locales/zh_cn/errors.ts

@@ -0,0 +1,17 @@
+export default {
+  locale: '错误测试: {locale}',
+  '-1': '未知错误',
+  '-2': '缺少params',
+  '-20': 'params错误',
+  '-3': '缺少query',
+  '-30': '缺少query错误',
+  '-4': '缺少body',
+  '-40': 'body错误',
+  '-5': '需要参数',
+  '-50': '参数错误',
+  '-10': '未找到数据',
+  '-100': '服务发生错误',
+  '-101': '未登录',
+  '-102': '密码错误',
+  '-500': '请求错误',
+};

+ 28 - 0
src/middleware/checkOnePointLogin.middleware.ts

@@ -0,0 +1,28 @@
+import { IMiddleware, Inject, MidwayWebRouterService } from '@midwayjs/core';
+import { Middleware } from '@midwayjs/decorator';
+import { NextFunction, Context } from '@midwayjs/koa';
+import { LoginService } from '../service/login.service';
+
+@Middleware()
+export class CheckOnePointLoginMiddleware implements IMiddleware<Context, NextFunction> {
+  @Inject()
+  webRouterService: MidwayWebRouterService;
+  resolve() {
+    return async (ctx: Context, next: NextFunction) => {
+      const routeInfo = await this.webRouterService.getMatchedRouterInfo(ctx.path, ctx.method);
+      if(!routeInfo) {
+        await next()
+        return
+      }
+      const desc = routeInfo.description;
+      if (desc !== 'ignore') {
+        const loginService = await ctx.requestContext.getAsync(LoginService);
+        await loginService.onePointCheck();
+      }
+      await next();
+    };
+  }
+  static getName(): string {
+    return 'checkOnePonitLogin';
+  }
+}

+ 33 - 0
src/middleware/checkToken.middleware.ts

@@ -0,0 +1,33 @@
+import { IMiddleware } from '@midwayjs/core';
+import { Middleware, Inject } from '@midwayjs/decorator';
+import { NextFunction, Context } from '@midwayjs/koa';
+import get = require('lodash/get');
+import { JwtService } from '@midwayjs/jwt';
+
+@Middleware()
+export class CheckTokenMiddleware
+  implements IMiddleware<Context, NextFunction>
+{
+  @Inject()
+  jwtService: JwtService;
+  resolve() {
+    return async (ctx: Context, next: NextFunction) => {
+      const token: any = get(ctx.request, 'header.token');
+      if (token) {
+        const data = this.jwtService.decodeSync(token);
+        if (data) ctx.user = data;
+      }
+      // 添加管理员身份
+      const adminToken: any = get(ctx.request, 'header.admin-token');
+      if (adminToken) {
+        const data = this.jwtService.decodeSync(adminToken);
+        if (data) ctx.admin = data;
+      }
+      await next();
+    };
+  }
+
+  static getName(): string {
+    return 'checkToken';
+  }
+}

+ 24 - 0
src/middleware/setLocaleToCtx.middleware.ts

@@ -0,0 +1,24 @@
+import { IMiddleware } from '@midwayjs/core';
+import { Middleware } from '@midwayjs/decorator';
+import { NextFunction, Context } from '@midwayjs/koa';
+import { head, last } from 'lodash';
+@Middleware()
+export class SetLocaleToCtxMiddleware implements IMiddleware<Context, NextFunction> {
+  resolve() {
+    return async (ctx: Context, next: NextFunction) => {
+      const cookies = ctx.request.headers.cookie;
+      let arr = cookies.split(';');
+      arr = arr.filter(f => f.includes('locale='));
+      // 没找到locale就默认使用中文
+      if (arr.length <= 0) arr = ['locale=zh-cn'];
+      const a2 = head(arr).split('=');
+      const locale = last(a2);
+      ctx.locale = locale;
+      await next();
+    };
+  }
+
+  static getName(): string {
+    return 'setLocale';
+  }
+}

+ 209 - 0
src/service/elasticsearch.ts

@@ -0,0 +1,209 @@
+import { Provide } from '@midwayjs/core';
+import { Client, estypes } from '@elastic/elasticsearch';
+import { get, isArray, pickBy } from 'lodash';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { Basic } from '../entity/basic.entity';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+import * as dayjs from 'dayjs';
+import { Types } from 'mongoose';
+const ObjectId = Types.ObjectId;
+
+@Provide()
+export class ElasticsearchService {
+  @InjectEntityModel(Basic)
+  basicModel: ReturnModelType<typeof Basic>;
+
+  esClient: Client;
+  /**
+   * 同步数据至es
+   * 同步数据需要过滤,有些数据类型,如果为不存在或者未 '' e.g.: 字符串日期,被识别成日期.那这个字符串就不能为 '',加入索引会报错
+   */
+  async asyncData() {
+    if (!this.esClient) await this.init();
+    const list = await this.basicModel.find({}).lean();
+    let nowData;
+    try {
+      for (const i of list) {
+        const _id = new ObjectId(i._id).toString();
+        const doc = pickBy(i, (val, key) => {
+          if (key === '_id') return false;
+          if (val && val !== '') return true;
+        });
+        const obj = {
+          index: 'basic',
+          id: _id,
+          document: doc,
+        };
+        nowData = obj;
+        await this.esClient.index(obj);
+      }
+    } catch (e) {
+      console.log(e);
+    }
+  }
+
+  /**
+   * 查询es中的数据
+   * @param query 查询条件
+   * @returns
+   */
+  async search({ index, skip, limit, ...query }) {
+    if (!this.esClient) await this.init();
+    const res1 = await this.esClient.indices.exists({ index: 'test1' });
+    const res2 = await this.esClient.indices.exists({ index: 'testtime1' });
+    console.log(res1)
+    console.log(res2)
+    // 需要对查询条件进行处理
+    const matchList = ['name', 'english', 'type', 'subject'];
+    const rangeList = ['lab_acreage'];
+    const timeList = ['build_time'];
+    const obj: any = {};
+    const oq: any = {};
+    for (const key in query) {
+      if (matchList.includes(key)) {
+        if (!oq.match) oq.match = {};
+        oq.match[key] = query[key];
+      } else if (rangeList.includes(key)) {
+        if (!oq.match) oq.range = {};
+        const value = query[key];
+        if (!isArray(value)) {
+          oq.range[key] = { gte: value };
+        } else {
+          oq.range[key] = { gte: value[0], lte: value[1] };
+        }
+      } else if (timeList.includes(key)) {
+        if (!oq.match) oq.range = {};
+        const value = query[key];
+        if (!isArray(value)) {
+          oq.range[`${key}`] = { gte: value };
+        } else {
+          oq.range[`${key}`] = { gte: 'now-1y', lte: 'now' };
+        }
+      }
+    }
+    if (skip || skip === 0 || skip === '0') obj.from = skip;
+    if (limit && limit !== '0') obj.size = limit;
+    if (Object.keys(oq).length > 0) obj.query = oq;
+    const r = await this.esClient.search(obj);
+    const result = this.getSearchResult(r);
+    const total = this.getSearchTotal(r);
+    return { data: result, total };
+  }
+  /**
+   * 创建数据
+   * @param index 索引
+   * @param data 数据
+   */
+  async create({ index, data }) {
+    if (!this.esClient) await this.init();
+    console.log(data);
+    const mapping: Record<estypes.PropertyName, estypes.MappingProperty> = {
+      key: {
+        type: 'text',
+      },
+      keyword: {
+        type: 'keyword',
+      },
+      num: {
+        type: 'float',
+      },
+      time: {
+        type: 'date',
+        format: 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis',
+      },
+      boo: {
+        type: 'boolean',
+      },
+      sort: {
+        type: 'integer',
+      },
+    };
+    for (let k = 1; k <= 3; k++) {
+      await this.esClient.indices.create({
+        index: `test${k}`,
+        mappings: {
+          properties: mapping,
+        },
+      });
+      for (let i = 1; i <= 3; i++) {
+        await this.esClient.index({
+          index: `test${k}`,
+          document: {
+            key: `${k}-菜单${i}`,
+            keyword: `${k}-菜${i}`,
+            time: `2023-06-0${i}`,
+            num: `${i}`,
+            boo: i % 2 === 0,
+            sort: i,
+            mkey: `${k}-单${i}`,
+          },
+        });
+      }
+    }
+
+    // return r;
+  }
+  /**
+   * 更新数据
+   * @param id 数据在es中的id
+   * @param data 新数据
+   */
+  async update(id: string, data: any) {
+    if (!this.esClient) await this.init();
+    const result = await this.esClient.update({
+      index: 'basic',
+      id,
+      doc: {
+        doc: data,
+      },
+    });
+  }
+  /**
+   * 删除数据
+   * @param id 数据在es的1id
+   */
+  async delete(id: string) {
+    if (!this.esClient) await this.init();
+    try {
+      const r = await this.esClient.delete({ index: 'basic', id: null });
+    } catch (e) {
+      const code = e.statusCode;
+      if (code === 404) throw new ServiceError('es未找到数据!', FrameworkErrorEnum.DATA_NOT_FOUND);
+      else if (code === 401) throw new ServiceError('es鉴权发生错误!', FrameworkErrorEnum.DATA_NOT_FOUND);
+    }
+  }
+  /**
+   * 删除索引
+   * @param index 索引
+   */
+  async deleteIndex(index: string) {
+    await this.esClient.indices.delete({ index });
+  }
+  getSearchResult(result) {
+    const res = get(result, 'hits.hits');
+    let rData;
+    if (isArray(res)) {
+      // 整理结果,将_id放到数据中
+      rData = res.map(i => ({ _id: i._id, ...get(i, '_source.doc') }));
+    } else {
+      rData = get(res, '_source');
+    }
+    return rData;
+  }
+  getSearchTotal(result) {
+    const res = get(result, 'hits.total.value', 0);
+    return res;
+  }
+
+  async init() {
+    const esClient = new Client({
+      node: 'http://localhost:9200',
+      auth: {
+        username: 'elastic',
+        password: 'NAjqFz_7tS2DkdpU7p*x',
+      },
+    });
+    this.esClient = esClient;
+  }
+}

+ 141 - 0
src/service/init.service.ts

@@ -0,0 +1,141 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { Admin } from '../entity/system/admin.entity';
+import { Role } from '../entity/system/role.entity';
+import { Menus } from '../entity/system/menus.entity';
+import { DictData } from '../entity/system/dictData.entity';
+import { DictType } from '../entity/system/dictType.entity';
+import { Types } from 'mongoose';
+const ObjectId = Types.ObjectId;
+@Provide()
+export class InitService {
+  @InjectEntityModel(Admin)
+  adminModel: ReturnModelType<typeof Admin>;
+  @InjectEntityModel(Role)
+  roleModel: ReturnModelType<typeof Role>;
+  @InjectEntityModel(Menus)
+  menusModel: ReturnModelType<typeof Menus>;
+  @InjectEntityModel(DictType)
+  dictTypeModel: ReturnModelType<typeof DictType>;
+  @InjectEntityModel(DictData)
+  dictDataModel: ReturnModelType<typeof DictData>;
+
+  async adminUser() {
+    const data = {
+      account: 'admin',
+      password: '1qaz2wsx',
+      nick_name: '系统管理员',
+      is_super: '0',
+    };
+    const is_exist = await this.adminModel.count({ is_super: '0' });
+    if (!is_exist) return await this.adminModel.create(data);
+    return;
+  }
+
+  async initRole() {
+    const num = await this.roleModel.count();
+    if (num > 0) return;
+    const datas = [{ name: '管理员', code: 'admin' }];
+    await this.roleModel.insertMany(datas);
+  }
+  async initMenus() {
+    const num = await this.menusModel.count();
+    if (num > 0) return;
+    const datas: any = [{ name: '首页', order_num: 1, path: '/', component: '/home/index', type: '1', i18n_code: 'menus.home', route_name: 'home' }];
+    // 系统设置
+    const smId = new ObjectId();
+    const systemMenus = [
+      { _id: smId, name: '系统设置', path: '/system', order_num: 2, type: '0', i18n_code: 'menus.system', route_name: 'system', is_default: '0' },
+      {
+        name: '菜单设置',
+        parent_id: smId.toString(),
+        order_num: 1,
+        path: '/system/menus',
+        component: '/system/menus/index',
+        type: '1',
+        route_name: 'system_menus',
+        i18n_code: 'menus.system_menus',
+        config: [
+          {
+            zh: '添加',
+            code: 'add',
+          },
+          {
+            zh: '修改',
+            code: 'update',
+          },
+          {
+            zh: '添加下一级',
+            code: 'addNext',
+          },
+          {
+            zh: '删除',
+            code: 'delete',
+          },
+        ],
+        is_default: '0',
+      },
+      {
+        name: '角色管理',
+        parent_id: smId.toString(),
+        order_num: 2,
+        path: '/system/role',
+        component: '/system/role/index',
+        type: '1',
+        route_name: 'system_role',
+        i18n_code: 'menus.system_role',
+        is_default: '0',
+        config: [
+          {
+            zh: '添加',
+            code: 'add',
+          },
+          {
+            zh: '修改',
+            code: 'update',
+          },
+          {
+            zh: '使用',
+            code: 'toAbled',
+          },
+          {
+            zh: '禁用',
+            code: 'toDisabled',
+          },
+          {
+            zh: '删除',
+            code: 'delete',
+          },
+        ],
+      },
+      { name: '字典管理', parent_id: smId.toString(), order_num: 3, path: '/system/dict', component: '/system/dict/index', type: '1', i18n_code: 'menus.system_dict', route_name: 'system_dict', is_default: '0' },
+      { name: '字典数据', parent_id: smId.toString(), order_num: 4, path: '/system/dictData', component: '/system/dictData/index', type: '2', route_name: 'system_dict_data', i18n_code: 'menus.system_dict_data', is_default: '0' },
+    ];
+    // 用户管理
+    const umId = new ObjectId();
+    const userMenus = [
+      { _id: umId, name: '用户管理', order_num: 3, path: '/user', type: '0', i18n_code: 'menus.user', route_name: 'user', is_default: '1' },
+      { name: '管理员用户', parent_id: umId.toString(), order_num: 1, path: '/user/admin', component: '/user/admin/index', type: '1', i18n_code: 'menus.user_admin', route_name: 'user_admin' },
+      { name: '平台用户', parent_id: umId.toString(), order_num: 2, path: '/user/user', component: '/user/user/index', type: '1', i18n_code: 'menus.user_user', route_name: 'user_user' },
+    ];
+    const password = { name: '修改密码', order_num: 999, path: '/acccount/updatepd', component: '/acccount/updatepd/index', type: '1' , i18n_code: 'menus.password', route_name: 'password'};
+
+    datas.push(...systemMenus, ...userMenus, password);
+    // 项目业务菜单
+    const busMenus = [];
+    datas.push(...busMenus);
+    await this.menusModel.insertMany(datas);
+  }
+  async initRoleMenu(admin: Admin) {}
+
+  async initDict() {
+    const isUseType = [{ title: '是否使用', code: 'isUse', is_use: '0' }];
+    const isUseData = [
+      { code: 'isUse', label: '使用', value: '0', sort: 1, is_use: '0' },
+      { code: 'isUse', label: '禁用', value: '1', sort: 2, is_use: '0' },
+    ];
+    await this.dictTypeModel.insertMany(isUseType);
+    await this.dictDataModel.insertMany(isUseData);
+  }
+}

+ 124 - 0
src/service/login.service.ts

@@ -0,0 +1,124 @@
+import { Config, Inject, Provide } from '@midwayjs/core';
+import { FrameworkErrorEnum, GetModel, ServiceError } from 'free-midway-component';
+import { get, isEqual, upperFirst } from 'lodash';
+import { LoginDTO, LoginType, UPwdDTO } from '../interface/login.interface';
+import { RoleService } from '../service/system/role.service';
+import { RedisService } from '@midwayjs/redis';
+import * as Crypto from 'crypto-js';
+import { Context } from '@midwayjs/koa';
+@Provide()
+export class LoginService {
+  @Inject()
+  roleService: RoleService;
+
+  @Inject()
+  ctx: Context;
+  @Config('loginSign')
+  loginSign;
+  @Config('jwt.secret')
+  jwtSecret;
+  @Config('jwt.expiresIn')
+  jwtExpiresIn;
+  @Inject()
+  redisService: RedisService;
+
+  async onePointLogin(loginVo) {
+    const { _id, role } = loginVo;
+    const rediskey = `${this.loginSign}:${role}:${_id}`;
+    // 随机字符串 验证用户登录用
+    const str = this.randomStr();
+    // 拼接成token内的登录code 加密前数据
+    const val = `${rediskey}:${str}`;
+    // 加密后存入token内
+    const code = Crypto.AES.encrypt(val, this.jwtSecret).toString();
+    // 设置redis登录记录 将 随机字符串存在redis中. 验证时需要将加密的字符串解密,解密后和redis中的对比验证
+    await this.redisService.set(rediskey, str, 'EX', this.jwtExpiresIn);
+    return code;
+  }
+
+  async onePointCheck() {
+    const user = this.ctx.user;
+    if (!user) throw new ServiceError('未检测到登录信息,请重新登录!', FrameworkErrorEnum.NOT_LOGIN);
+    const { _id, role, login_code } = user;
+    if (!login_code) throw new ServiceError('未检测到登录标识,请重新登录!', FrameworkErrorEnum.NOT_LOGIN);
+    // 解密
+    const decodeResult = Crypto.AES.decrypt(login_code, this.jwtSecret);
+    const decode = Crypto.enc.Utf8.stringify(decodeResult).toString();
+    // 取出code
+    const codeArr = decode.split(':');
+    const code = codeArr[codeArr.length - 1];
+    // 拼接redis的key
+    const rediskey = `${this.loginSign}:${role}:${_id}`;
+    // 取出当前记录在案的 code
+    const redisCode = await this.redisService.get(rediskey);
+    if(!redisCode) throw new ServiceError('账号登录已失效,请重新登录!', FrameworkErrorEnum.NOT_LOGIN);
+    // 判断是否一致
+    if (code === redisCode) {
+      // 一致,延时
+      await this.redisService.expire(rediskey, this.jwtExpiresIn);
+    } else {
+      throw new ServiceError('本账号已在其他地方登录,请重新登录!', FrameworkErrorEnum.NOT_LOGIN);
+    }
+  }
+
+  /**
+   * 账密登录
+   * @param data 用户名和密码
+   * @param type 用户类型
+   * @returns 用户信息/空值
+   */
+  async loginByAccount(data: LoginDTO, type: LoginType) {
+    const model = GetModel(upperFirst(type));
+    const user = await model.findOne({ account: data.account }, '+password').lean();
+    if (!user) throw new ServiceError('未找到用户信息', FrameworkErrorEnum.NOT_FOUND_DATA);
+    await this.checkAccountCanLogin(user, type);
+    if (!isEqual(user.password.secret, data.password)) throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
+    return user;
+  }
+  /**
+   * 检查用户是否可以登录(从用户本身和角色检查)
+   * @param user 用户信息
+   * @param type 用户类型
+   */
+  async checkAccountCanLogin(user, type: LoginType) {
+    // 判断是否可以使用:
+    // 管理员: 超级管理员无视,直接往下; 普通管理员需要查看is_use是不是'0'
+    // 其他用户需要看status是不是'1';
+    if (type === 'Admin') {
+      if (get(user, 'is_super') === '1') {
+        if (get(user, 'is_use') === '1') throw new ServiceError('该用户已被禁用', FrameworkErrorEnum.SERVICE_FAULT);
+      }
+    } else {
+      if (get(user, 'status') !== '1') throw new ServiceError('该用户已被禁用', FrameworkErrorEnum.SERVICE_FAULT);
+      const role = await this.roleService.findOne({ code: type, is_use: '0' });
+      if (!role) throw new ServiceError('当前角色下的用户无法使用!', FrameworkErrorEnum.SERVICE_FAULT);
+    }
+  }
+
+  async updatePwd(data: UPwdDTO, type: LoginType) {
+    const model = GetModel(upperFirst(type));
+    const user = await model.findById(data._id);
+    if (!user) new ServiceError('未找到用户信息!', FrameworkErrorEnum.DATA_NOT_FOUND);
+    user.password = data.password;
+    await user.save();
+  }
+  // 需要改的时候再用
+  // async wxAppLogin(openid: string) {
+  //   const tables = ['Doctor', 'Nurse', 'Patient'];
+  //   let user;
+  //   let role;
+  //   for (const table of tables) {
+  //     const model = GetModel(upperFirst(table));
+  //     user = await model.findOne({ openid }).lean();
+  //     if (user) {
+  //       role = table;
+  //       break;
+  //     }
+  //   }
+  //   if (user) return { ...user, role };
+  //   throw new ServiceError('未找到用户信息!', FrameworkErrorEnum.NOT_FOUND_DATA);
+  // }
+  randomStr(len = 32) {
+    return Math.random().toString(36).slice(-len);
+  }
+}

+ 11 - 0
src/service/platform/achievement.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Achievement } from '../../entity/platform/achievement.entity';
+type modelType = ReturnModelType<typeof Achievement>;
+@Provide()
+export class AchievementService extends BaseService<modelType> {
+  @InjectEntityModel(Achievement)
+  model: modelType;
+}

+ 11 - 0
src/service/platform/demand.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Demand } from '../../entity/platform/demand.entity';
+type modelType = ReturnModelType<typeof Demand>;
+@Provide()
+export class DemandService extends BaseService<modelType> {
+  @InjectEntityModel(Demand)
+  model: modelType;
+}

+ 11 - 0
src/service/platform/match.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Match } from '../../entity/platform/match.entity';
+type modelType = ReturnModelType<typeof Match>;
+@Provide()
+export class MatchService extends BaseService<modelType> {
+  @InjectEntityModel(Match)
+  model: modelType;
+}

+ 11 - 0
src/service/platform/news.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { News } from '../../entity/platform/news.entity';
+type modelType = ReturnModelType<typeof News>;
+@Provide()
+export class NewsService extends BaseService<modelType> {
+  @InjectEntityModel(News)
+  model: modelType;
+}

+ 73 - 0
src/service/record/dataRecord.service.ts

@@ -0,0 +1,73 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { DataRecord } from '../../entityRecord/dataRecord.entity';
+import { get } from 'lodash';
+import dayjs = require('dayjs');
+
+type modelType = ReturnModelType<typeof DataRecord>;
+@Provide()
+export class DataRecordService extends BaseService<modelType> {
+  @InjectEntityModel(DataRecord)
+  model: modelType;
+
+  async makeLogs(controllerName: string, methodName: string) {
+    const req = this.ctx.request;
+    const user = this.ctx.user;
+    const data = {
+      operator: user,
+      ip: get(req, 'header.x-forwarded-for', req.ip),
+      device: get(req, 'header.user-agent'),
+      time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
+      controller: controllerName,
+      method: methodName,
+      router: get(req, 'header.referer'),
+    };
+    return data;
+  }
+  /**
+   * 为默认函数提供原数据
+   * defaultMethod: create, update, delete
+   * @param service 中间件提供的controller的默认service
+   * @param method 当前执行函数名
+   * @returns {object} 原数据
+   */
+  async getDefaultMethodOriginData(service: any, method: string) {
+    let data = null;
+    if (method === 'create') return data;
+    const id = get(this.ctx.request, 'params.id');
+    const modelName = get(service, 'model.modelName');
+    data = await service.fetch(id);
+    return { [modelName]: [data] };
+  }
+
+  /**
+   * 为默认函数提供新数据
+   * defaultMethod: create, update, delete
+   * @param service 中间件提供的controller的默认service
+   * @param method 当前执行函数名
+   * @param origin_data 原数据
+   * @returns {object} 新数据
+   */
+  async getDefaultMethodNewData(service: any, method: string, origin_data: object) {
+    let data = null;
+    if (method === 'delete') return data;
+    const modelName = get(service, 'model.modelName');
+    if (method === 'update') {
+      if (origin_data) {
+        const list = get(origin_data, modelName);
+        const arr = [];
+        for (const i of list) {
+          const d = await service.fetch(i._id);
+          arr.push(d);
+        }
+        data = arr;
+      }
+    } else if (method === 'create') {
+      data = [origin_data];
+    }
+
+    return { [modelName]: data };
+  }
+}

+ 11 - 0
src/service/system/admin.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Admin } from '../../entity/system/admin.entity';
+type modelType = ReturnModelType<typeof Admin>;
+@Provide()
+export class AdminService extends BaseService<modelType> {
+  @InjectEntityModel(Admin)
+  model: modelType;
+}

+ 17 - 0
src/service/system/config.service.ts

@@ -0,0 +1,17 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Config } from '../../entity/system/config.entity';
+type modelType = ReturnModelType<typeof Config>;
+@Provide()
+export class ConfigService extends BaseService<modelType> {
+  @InjectEntityModel(Config)
+  model: modelType;
+  // 只允许有一个config
+  async getConfig() {
+    let data = await this.model.findOne({}).lean();
+    if (!data) data = await this.model.create({ b_time: ['06:30', '08:00'], l_time: ['11:30', '13:00'], d_time: ['17:30', '18:30'] });
+    return data;
+  }
+}

+ 11 - 0
src/service/system/dictData.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { DictData } from '../../entity/system/dictData.entity';
+type modelType = ReturnModelType<typeof DictData>;
+@Provide()
+export class DictDataService extends BaseService<modelType> {
+  @InjectEntityModel(DictData)
+  model: modelType;
+}

+ 11 - 0
src/service/system/dictType.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { DictType } from '../../entity/system/dictType.entity';
+type modelType = ReturnModelType<typeof DictType>;
+@Provide()
+export class DictTypeService extends BaseService<modelType> {
+  @InjectEntityModel(DictType)
+  model: modelType;
+}

+ 38 - 0
src/service/system/menus.service.ts

@@ -0,0 +1,38 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Menus } from '../../entity/system/menus.entity';
+import orderBy = require('lodash/orderBy');
+import { Types } from 'mongoose';
+const ObjectId = Types.ObjectId;
+type modelType = ReturnModelType<typeof Menus>;
+@Provide()
+export class MenusService extends BaseService<modelType> {
+  @InjectEntityModel(Menus)
+  model: modelType;
+
+  async queryMenu(query: object = {}): Promise<Array<object>> {
+    const data = await this.model.find(query, { meta: 0, __v: 0 }).sort({ order_num: 1 }).lean();
+    let treeMenu = data.filter(f => !f.parent_id);
+    treeMenu = this.treeMenu(data, treeMenu);
+    return treeMenu;
+  }
+
+  treeMenu(allMenus, nowMenu) {
+    for (const nm of nowMenu) {
+      const { _id, parent_id } = nm;
+      // 查下下级其是否有目录
+      let children = allMenus.filter(f => new ObjectId(f.parent_id).equals(_id));
+      children = this.treeMenu(allMenus, children);
+      if (children.length > 0) nm.children = children;
+      // 换父级组件的名称
+      if (parent_id) {
+        const r = allMenus.find(f => new ObjectId(f._id).equals(parent_id));
+        if (r) nm.parent_name = r.name;
+      }
+    }
+    nowMenu = orderBy(nowMenu, ['order_num'], ['asc']);
+    return nowMenu;
+  }
+}

+ 67 - 0
src/service/system/role.service.ts

@@ -0,0 +1,67 @@
+import { Provide, Inject, Init } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService, ServiceError, FrameworkErrorEnum } from 'free-midway-component';
+import { Role } from '../../entity/system/role.entity';
+import { Menus } from '../../entity/system/menus.entity';
+import { MenusService } from './menus.service';
+import { flattenDeep, uniq, get, lowerFirst, upperFirst, last } from 'lodash';
+import { Context } from '@midwayjs/koa';
+type modelType = ReturnModelType<typeof Role>;
+@Provide()
+export class RoleService extends BaseService<modelType> {
+  @InjectEntityModel(Role)
+  model: modelType;
+  @InjectEntityModel(Menus)
+  menusModel: ReturnModelType<typeof Menus>;
+
+  @Inject()
+  menusService: MenusService;
+  @Inject()
+  ctx: Context;
+
+  //是否是超级管理员
+  isSuperAdmin() {
+    const user = this.ctx.user;
+    if (user.role === 'Admin' && user.is_super === '0') return true;
+  }
+
+  async getUserMenus(needCode = false) {
+    const user = this.ctx.user;
+    // 这里需要改下. 平台的超级管理员有这些权限
+    if (this.isSuperAdmin()) {
+      const menus = await this.menusService.queryMenu({ is_use: '0' });
+      return { menus };
+    }
+    const roleCode = [lowerFirst(user.role), upperFirst(user.role)];
+    const role = await this.model.findOne({ code: roleCode, is_use: '0' }).lean();
+    if (!role) throw new ServiceError('当前角色下的用户无法使用!', FrameworkErrorEnum.SERVICE_FAULT);
+    const roleMenu = get(role, 'menu', []);
+    const menu = roleMenu.map(i => {
+      const arr = i.split('.');
+      return last(arr);
+    });
+    if (needCode) return roleMenu;
+    const menuList = await this.menusModel.find({ route_name: menu }).lean();
+    let treeMenu = menuList.filter(f => !f.parent_id);
+    treeMenu = this.menusService.treeMenu(menuList, treeMenu);
+    return { menus: treeMenu, role_code: roleMenu };
+  }
+
+  /**
+   * 根据角色id数组,整理菜单
+   * @param roleIdList 角色id数组
+   */
+  async getMenuByRoles(roleIdList) {
+    let menus = [];
+    // 第一步,整理所有菜单至一维数组
+    for (const r of roleIdList) {
+      menus.push(...flattenDeep(r));
+    }
+    menus = uniq(menus);
+    const allMenu = await this.menusModel.find({ _id: menus, is_use: '0' }, { meta: 0, __v: 0 }).sort({ order_num: 1 }).lean();
+    let treeMenu = allMenu.filter(f => !f.parent_id);
+    treeMenu = this.menusService.treeMenu(allMenu, treeMenu);
+    return treeMenu;
+  }
+}

+ 11 - 0
src/service/system/user.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { User } from '../../entity/system/user.entity';
+type modelType = ReturnModelType<typeof User>;
+@Provide()
+export class UserService extends BaseService<modelType> {
+  @InjectEntityModel(User)
+  model: modelType;
+}

+ 7 - 0
src/service/util.service.ts

@@ -0,0 +1,7 @@
+import { Provide } from '@midwayjs/decorator';
+@Provide()
+export class UtilService {
+  randomStr(len = 6) {
+    return Math.random().toString(36).slice(-len);
+  }
+}

+ 20 - 0
test/controller/api.test.ts

@@ -0,0 +1,20 @@
+import { createApp, close, createHttpRequest } from '@midwayjs/mock';
+import { Framework } from '@midwayjs/koa';
+
+describe('test/controller/home.test.ts', () => {
+
+  it('should POST /api/get_user', async () => {
+    // create app
+    const app = await createApp<Framework>();
+
+    // make request
+    const result = await createHttpRequest(app).get('/api/get_user').query({ uid: 123 });
+
+    // use expect by jest
+    expect(result.status).toBe(200);
+    expect(result.body.message).toBe('OK');
+
+    // close app
+    await close(app);
+  });
+});

+ 21 - 0
test/controller/home.test.ts

@@ -0,0 +1,21 @@
+import { createApp, close, createHttpRequest } from '@midwayjs/mock';
+import { Framework } from '@midwayjs/koa';
+
+describe('test/controller/home.test.ts', () => {
+
+  it('should GET /', async () => {
+    // create app
+    const app = await createApp<Framework>();
+
+    // make request
+    const result = await createHttpRequest(app).get('/');
+
+    // use expect by jest
+    expect(result.status).toBe(200);
+    expect(result.text).toBe('Hello Midwayjs!');
+
+    // close app
+    await close(app);
+  });
+
+});

+ 28 - 0
tsconfig.json

@@ -0,0 +1,28 @@
+{
+  "compileOnSave": true,
+  "compilerOptions": {
+    "target": "es2018",
+    "module": "commonjs",
+    "moduleResolution": "node",
+    "experimentalDecorators": true,
+    "emitDecoratorMetadata": true,
+    "inlineSourceMap":true,
+    "noImplicitThis": true,
+    "noUnusedLocals": true,
+    "stripInternal": true,
+    "skipLibCheck": true,
+    "pretty": true,
+    "declaration": true,
+    "forceConsistentCasingInFileNames": true,
+    "typeRoots": [ "./typings", "./node_modules/@types"],
+    "outDir": "dist",
+    "rootDir": "src"
+  },
+  "exclude": [
+    "*.js",
+    "*.ts",
+    "dist",
+    "node_modules",
+    "test"
+  ]
+}