lrf 1 year ago
commit
4080fc8031
76 changed files with 3340 additions and 0 deletions
  1. 11 0
      .editorconfig
  2. 11 0
      .eslintrc.json
  3. 16 0
      .gitignore
  4. 4 0
      .prettierrc.js
  5. 29 0
      README.md
  6. 29 0
      README.zh-CN.md
  7. 2 0
      bootstrap.js
  8. 6 0
      jest.config.js
  9. 59 0
      package.json
  10. 9 0
      src/config/config.default.ts
  11. 7 0
      src/config/config.unittest.ts
  12. 39 0
      src/configuration.ts
  13. 68 0
      src/controller/car.controller.ts
  14. 68 0
      src/controller/config.controller.ts
  15. 67 0
      src/controller/estimate.controller.ts
  16. 9 0
      src/controller/home.controller.ts
  17. 68 0
      src/controller/shop.controller.ts
  18. 68 0
      src/controller/system/brand.controller.ts
  19. 68 0
      src/controller/system/dictData.controller.ts
  20. 68 0
      src/controller/system/dictType.controller.ts
  21. 20 0
      src/controller/system/init.controller.ts
  22. 62 0
      src/controller/system/menus.controller.ts
  23. 77 0
      src/controller/system/role.controller.ts
  24. 82 0
      src/controller/user/admin.controller.ts
  25. 68 0
      src/controller/user/follow.controller.ts
  26. 89 0
      src/controller/user/login.controller.ts
  27. 41 0
      src/controller/user/token.controller.ts
  28. 69 0
      src/controller/user/user.controller.ts
  29. 37 0
      src/decorator/verifyToken.decorator.ts
  30. 73 0
      src/entity/car.entity.ts
  31. 17 0
      src/entity/config.entity.ts
  32. 23 0
      src/entity/estimate.entity.ts
  33. 19 0
      src/entity/shop.entity.ts
  34. 15 0
      src/entity/system/brand.entity.ts
  35. 17 0
      src/entity/system/dictData.entity.ts
  36. 15 0
      src/entity/system/dictType.entity.ts
  37. 27 0
      src/entity/system/menus.entity.ts
  38. 19 0
      src/entity/system/role.entity.ts
  39. 34 0
      src/entity/user/admin.entity.ts
  40. 11 0
      src/entity/user/follow.entity.ts
  41. 13 0
      src/entity/user/user.entity.ts
  42. 13 0
      src/filter/default.filter.ts
  43. 10 0
      src/filter/notfound.filter.ts
  44. 6 0
      src/interface.ts
  45. 221 0
      src/interface/car.interface.ts
  46. 87 0
      src/interface/config.interface.ts
  47. 102 0
      src/interface/estimate.interface.ts
  48. 86 0
      src/interface/shop.interface.ts
  49. 76 0
      src/interface/system/brand.interface.ts
  50. 91 0
      src/interface/system/dictData.interface.ts
  51. 86 0
      src/interface/system/dictType.interface.ts
  52. 118 0
      src/interface/system/menus.interface.ts
  53. 96 0
      src/interface/system/role.interface.ts
  54. 101 0
      src/interface/user/admin.interface.ts
  55. 72 0
      src/interface/user/follow.interface.ts
  56. 39 0
      src/interface/user/login.interface.ts
  57. 77 0
      src/interface/user/user.interface.ts
  58. 33 0
      src/middleware/checkToken.middleware.ts
  59. 11 0
      src/service/car.service.ts
  60. 11 0
      src/service/config.service.ts
  61. 11 0
      src/service/estimate.service.ts
  62. 11 0
      src/service/shop.service.ts
  63. 11 0
      src/service/system/brand.service.ts
  64. 11 0
      src/service/system/dictData.service.ts
  65. 11 0
      src/service/system/dictType.service.ts
  66. 73 0
      src/service/system/init.service.ts
  67. 43 0
      src/service/system/menus.service.ts
  68. 87 0
      src/service/system/role.service.ts
  69. 36 0
      src/service/user/admin.service.ts
  70. 11 0
      src/service/user/follow.service.ts
  71. 69 0
      src/service/user/login.service.ts
  72. 23 0
      src/service/user/user.service.ts
  73. 7 0
      src/service/util.service.ts
  74. 20 0
      test/controller/api.test.ts
  75. 21 0
      test/controller/home.test.ts
  76. 25 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 }]
+  }
+}

+ 16 - 0
.gitignore

@@ -0,0 +1,16 @@
+logs/
+npm-debug.log
+yarn-error.log
+node_modules/
+package-lock.json
+yarn.lock
+coverage/
+dist/
+.idea/
+run/
+.DS_Store
+*.sw*
+*.un~
+.tsbuildinfo
+.tsbuildinfo.*
+src/config/config.local.ts

+ 4 - 0
.prettierrc.js

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

+ 29 - 0
README.md

@@ -0,0 +1,29 @@
+# my_midway_project
+
+## QuickStart
+
+<!-- add docs here for user -->
+
+see [midway docs][midway] for more detail.
+
+### Development
+
+```bash
+$ npm i
+$ npm run dev
+$ open http://localhost:7001/
+```
+
+### Deploy
+
+```bash
+$ npm start
+```
+
+### npm scripts
+
+- Use `npm run lint` to check code style.
+- Use `npm test` to run unit test.
+
+
+[midway]: https://midwayjs.org

+ 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();

+ 6 - 0
jest.config.js

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

+ 59 - 0
package.json

@@ -0,0 +1,59 @@
+{
+  "name": "my-midway-project",
+  "version": "1.0.0",
+  "description": "",
+  "private": true,
+  "dependencies": {
+    "@midwayjs/bootstrap": "^3.12.0",
+    "@midwayjs/core": "^3.12.0",
+    "@midwayjs/decorator": "^3.12.0",
+    "@midwayjs/info": "^3.12.0",
+    "@midwayjs/koa": "^3.12.0",
+    "@midwayjs/logger": "^3.1.0",
+    "@midwayjs/validate": "^3.12.0",
+    "@midwayjs/jwt": "^3.13.7",
+    "@midwayjs/swagger": "^3.13.7",
+    "@midwayjs/typegoose": "^3.0.0",
+    "@typegoose/typegoose": "^9.0.0",
+    "free-midway-component": "^1.0.50",
+    "lodash": "^4.17.21",
+    "mongoose": "^6.0.7"
+  },
+  "devDependencies": {
+    "@midwayjs/cli": "^2.0.0",
+    "@midwayjs/mock": "^3.12.0",
+    "@types/jest": "^29.2.0",
+    "@types/koa": "^2.13.4",
+    "@types/node": "14",
+    "cross-env": "^6.0.0",
+    "jest": "^29.2.2",
+    "mwts": "^1.3.0",
+    "ts-jest": "^29.0.3",
+    "typescript": "~4.8.0",
+    "@types/lodash": "^4.14.202",
+    "swagger-ui-dist": "^5.10.5"
+  },
+  "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": "midway-bin test --ts",
+    "cov": "midway-bin cov --ts",
+    "lint": "mwts check",
+    "lint:fix": "mwts fix",
+    "ci": "npm run cov",
+    "build": "midway-bin build -c"
+  },
+  "midway-bin-clean": [
+    ".vscode/.tsbuildinfo",
+    "dist"
+  ],
+  "repository": {
+    "type": "git",
+    "url": ""
+  },
+  "author": "anonymous",
+  "license": "MIT"
+}

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

@@ -0,0 +1,9 @@
+import { MidwayConfig } from '@midwayjs/core';
+
+export default {
+  // use for cookie sign key, should change to your own and keep security
+  keys: '1704699858754_8427',
+  koa: {
+    port: 7001,
+  },
+} 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;

+ 39 - 0
src/configuration.ts

@@ -0,0 +1,39 @@
+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 { CheckTokenMiddleware } from './middleware/checkToken.middleware';
+import * as swagger from '@midwayjs/swagger';
+@Configuration({
+  imports: [
+    koa,
+    validate,
+    FreeFrame,
+    jwt,
+    {
+      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(CheckTokenMiddleware);
+    // 注解
+    VerifyTokenInit(this.decoratorService);
+  }
+}

+ 68 - 0
src/controller/car.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 { CarService } from '../service/car.service';
+import { CDTO_car, CVO_car, FVO_car, QDTO_car, QVO_car, UDTO_car, UVAO_car } from '../interface/car.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['车源'])
+@Controller('/car')
+export class CarController extends BaseController {
+  @Inject()
+  service: CarService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_car })
+  async create(@Body() data: CDTO_car) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_car(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_car })
+  async query(@Query() filter: QDTO_car, @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_car(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_car })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_car(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_car })
+  async update(@Param('id') id: string, @Body() body: UDTO_car) {
+    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/config.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 { ConfigService } from '../service/config.service';
+import { CDTO_config, CVO_config, FVO_config, QDTO_config, QVO_config, UDTO_config, UVAO_config } from '../interface/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) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_config(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_config })
+  async query(@Query() filter: QDTO_config, @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_config(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_config })
+  async fetch(@Param('id') id: string) {
+    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.');
+  }
+}

+ 67 - 0
src/controller/estimate.controller.ts

@@ -0,0 +1,67 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { EstimateService } from '../service/estimate.service';
+import { CDTO_estimate, CVO_estimate, FVO_estimate,QDTO_estimate, QVO_estimate, UDTO_estimate, UVAO_estimate } from '../interface/estimate.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['车辆估价'])
+@Controller('/estimate')
+export class EstimateController extends BaseController {
+  @Inject()
+  service: EstimateService;
+
+
+@Post('/') @Validate() @ApiResponse({ type: CVO_estimate })
+  async create(@Body() data: CDTO_estimate) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_estimate(dbData);
+    return result;
+  }
+@Get('/')@ApiQuery({name:'query'})@ApiResponse({ type: QVO_estimate })
+  async query(@Query() filter:QDTO_estimate, @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_estimate(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+
+@Get('/:id')@ApiResponse({ type: FVO_estimate })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_estimate(data);
+    return result;
+  }
+
+
+@Post('/:id')@Validate()@ApiResponse({ type: UVAO_estimate })
+  async update(@Param('id') id: string, @Body() body: UDTO_estimate) {
+    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.');
+  }
+}
+

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

@@ -0,0 +1,9 @@
+import { Controller, Get } from '@midwayjs/core';
+
+@Controller('/')
+export class HomeController {
+  @Get('/')
+  async home(): Promise<string> {
+    return 'Hello Midwayjs!';
+  }
+}

+ 68 - 0
src/controller/shop.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 { ShopService } from '../service/shop.service';
+import { CDTO_shop, CVO_shop, FVO_shop, QDTO_shop, QVO_shop, UDTO_shop, UVAO_shop } from '../interface/shop.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['店铺'])
+@Controller('/shop')
+export class ShopController extends BaseController {
+  @Inject()
+  service: ShopService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_shop })
+  async create(@Body() data: CDTO_shop) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_shop(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_shop })
+  async query(@Query() filter: QDTO_shop, @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_shop(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_shop })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_shop(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_shop })
+  async update(@Param('id') id: string, @Body() body: UDTO_shop) {
+    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/brand.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 { BrandService } from '../../service/system/brand.service';
+import { CDTO_brand, CVO_brand, FVO_brand, QDTO_brand, QVO_brand, UDTO_brand, UVAO_brand } from '../../interface/system/brand.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['品牌'])
+@Controller('/brand')
+export class BrandController extends BaseController {
+  @Inject()
+  service: BrandService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_brand })
+  async create(@Body() data: CDTO_brand) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_brand(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_brand })
+  async query(@Query() filter: QDTO_brand, @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_brand(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_brand })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_brand(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_brand })
+  async update(@Param('id') id: string, @Body() body: UDTO_brand) {
+    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 });
+    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.');
+  }
+}

+ 20 - 0
src/controller/system/init.controller.ts

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

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

@@ -0,0 +1,62 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { MenusService } from '../../service/system/menus.service';
+import { CDTO_menus, CVO_menus, FVO_menus, QDTO_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.');
+  }
+}

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

@@ -0,0 +1,77 @@
+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';
+@ApiTags(['角色表'])
+@Controller('/role')
+export class RoleController extends BaseController {
+  @Inject()
+  service: RoleService;
+  @Inject()
+  menusService: MenusService;
+
+  @Post('/')
+  @verifyToken()
+  @Validate()
+  @ApiResponse({ type: CVO_role })
+  async create(@Body() data: CDTO_role) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_role(dbData);
+    return result;
+  }
+  @Get('/')
+  @verifyToken()
+  @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()
+  @Validate()
+  @ApiResponse({ type: UVAO_role })
+  async update(@Param('id') id: string, @Body() body: UDTO_role) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @verifyToken()
+  @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.');
+  }
+}

+ 82 - 0
src/controller/user/admin.controller.ts

@@ -0,0 +1,82 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController, FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+import { AdminService } from '../../service/user/admin.service';
+import { CDTO_admin, CVO_admin, FVO_admin, QDTO_admin, QVO_admin, UDTO_admin, UVAO_admin } from '../../interface/user/admin.interface';
+import { ApiResponse, ApiTags, ApiQuery, ApiOperation } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+import { Context } from '@midwayjs/koa';
+import get = require('lodash/get');
+@ApiTags(['管理员表'])
+@Controller('/admin')
+export class AdminController extends BaseController {
+  @Inject()
+  service: AdminService;
+  @Inject()
+  ctx: Context;
+  @Post('/initSuper')
+  @ApiOperation({ summary: '初始化超级管理员' })
+  async initSuper() {
+    const dbCode = get(this.ctx, 'request.headers.dbcode');
+    if (!dbCode) throw new ServiceError(FrameworkErrorEnum.BAD_PARAMS, '缺少参数,无法使用初始化管理员');
+    if (dbCode !== 'usedCar') throw new ServiceError(FrameworkErrorEnum.BAD_PARAMS, '缺少标识,无法使用初始化管理员');
+    await this.service.initSuper();
+    return 'ok';
+  }
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_admin })
+  async create(@Body() data: CDTO_admin) {
+    await this.service.checkIsExist(data);
+    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.');
+  }
+}

+ 68 - 0
src/controller/user/follow.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 { FollowService } from '../../service/user/follow.service';
+import { CDTO_follow, CVO_follow, FVO_follow, QDTO_follow, QVO_follow, UDTO_follow, UVAO_follow } from '../../interface/user/follow.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['关注'])
+@Controller('/follow')
+export class FollowController extends BaseController {
+  @Inject()
+  service: FollowService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_follow })
+  async create(@Body() data: CDTO_follow) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_follow(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_follow })
+  async query(@Query() filter: QDTO_follow, @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_follow(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_follow })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_follow(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_follow })
+  async update(@Param('id') id: string, @Body() body: UDTO_follow) {
+    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.');
+  }
+}

+ 89 - 0
src/controller/user/login.controller.ts

@@ -0,0 +1,89 @@
+import { Body, Config, Controller, Inject, Param, Post, Get } from '@midwayjs/core';
+import { ApiTags } from '@midwayjs/swagger';
+import { LoginDTO, LoginType, LoginVO, UPwdDTO } from '../../interface/user/login.interface';
+import { LoginService } from '../../service/user/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')
+  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));
+    const token = await this.jwtService.sign(vo, this.jwtSecret, {
+      expiresIn: this.jwtExpiresIn,
+    });
+    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;
+  }
+}

+ 41 - 0
src/controller/user/token.controller.ts

@@ -0,0 +1,41 @@
+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 menus = await this.roleService.getUserMenus();
+    result.menus = menus;
+    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;
+  // }
+}

+ 69 - 0
src/controller/user/user.controller.ts

@@ -0,0 +1,69 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { UserService } from '../../service/user/user.service';
+import { CDTO_user, CVO_user, FVO_user, QDTO_user, QVO_user, UDTO_user, UVAO_user } from '../../interface/user/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) {
+    await this.service.checkIsExist(data);
+    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.');
+  }
+}

+ 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;
+      },
+    };
+  });
+}

+ 73 - 0
src/entity/car.entity.ts

@@ -0,0 +1,73 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'car' },
+})
+export class Car extends BaseModel {
+  @prop({ required: false, index: false })
+  shop: string;
+  @prop({ required: false, index: false, zh: '车辆识别VIN' })
+  vin: string;
+  @prop({ required: false, index: false, zh: '首次上牌时间' })
+  f_time: string;
+  @prop({ required: false, index: false, zh: '车源地', remark: '字典.行政区划' })
+  place: string;
+  @prop({ required: false, index: false, zh: '车牌地', remark: '字典.行政区划' })
+  license: string;
+  @prop({ required: false, index: false, zh: '外观颜色' })
+  out_color: string;
+  @prop({ required: false, index: false, zh: '内饰颜色' })
+  in_color: string;
+  @prop({ required: false, index: false, zh: '车辆使用性质', remark: '字典:车辆使用性质' })
+  use_type: string;
+  @prop({ required: false, index: false, zh: '价格', remark: '万元' })
+  price: number;
+  @prop({ required: false, index: false, zh: '车龄' })
+  age: number;
+  @prop({ required: false, index: false, zh: '里程', remark: '万公里' })
+  mileage: number;
+  @prop({ required: false, index: false, zh: '变速箱', remark: '字典:变速箱类型' })
+  type: string;
+  @prop({ required: false, index: false, zh: '车身结构', remark: '字典:车身结构' })
+  structure: string;
+  @prop({ required: false, index: false, zh: '排放标准', remark: '字典:排放标准' })
+  emission: string;
+  @prop({ required: false, index: false, zh: '能源类型', remark: '字典:能源类型' })
+  energy: string;
+  @prop({ required: false, index: false, zh: '排量', remark: '字典:排量' })
+  displacement: string;
+  @prop({ required: false, index: false, zh: '座椅', remark: '字典:座椅' })
+  set: string;
+  @prop({ required: false, index: false, zh: '车辆级别', remark: '字典:车辆级别' })
+  level: string;
+  @prop({ required: false, index: false, zh: '驱动方式', remark: '字典:驱动方式' })
+  drive: string;
+  @prop({ required: false, index: false, zh: '油耗', remark: '用车成本:单位:L' })
+  oil: string;
+  @prop({ required: false, index: false, zh: '年均保险费', remark: '用车成本:单位:元' })
+  premium: string;
+  @prop({ required: false, index: false, zh: '年均保养费', remark: '用车成本:' })
+  maintenance: string;
+  @prop({ required: false, index: false, zh: '百公里加速', remark: '单位:s' })
+  hundred_time: string;
+  @prop({ required: false, index: false, zh: '轴距', remark: '单位:mm' })
+  wheelbase: string;
+  @prop({ required: false, index: false, zh: '总价' })
+  total_money: string;
+  @prop({ required: false, index: false, zh: '付款方式', remark: '字典:付款方式' })
+  pay_type: string;
+  @prop({ required: false, index: false, zh: '首付' })
+  first_pay: string;
+  @prop({ required: false, index: false, zh: '实付价格' })
+  real_pay: string;
+  @prop({ required: false, index: false, zh: '状态', remark: '字典:车源状态', default: '0' })
+  status: string;
+  @prop({ required: false, index: false, zh: '品牌', remark: '合成标题用:1' })
+  brand: string;
+  @prop({ required: false, index: false, zh: '车型', remark: '合成标题用:2' })
+  series: string;
+  @prop({ required: false, index: false, zh: '年份', remark: '合成标题用:3' })
+  year: string;
+  @prop({ required: false, index: false, zh: '车款', remark: '合成标题用:4' })
+  style: string;
+}

+ 17 - 0
src/entity/config.entity.ts

@@ -0,0 +1,17 @@
+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: '销售模式', remark: '0:平台销售;1:多店铺销售' })
+  mode: string;
+  @prop({ required: false, index: false, zh: '平台名称' })
+  name: string;
+  @prop({ required: false, index: false, zh: 'logo' })
+  logo: Array<any>;
+  @prop({ required: false, index: false, zh: '联系人' })
+  contacts: string;
+  @prop({ required: false, index: false, zh: '联系电话' })
+  tel: string;
+}

+ 23 - 0
src/entity/estimate.entity.ts

@@ -0,0 +1,23 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'estimate' },
+})
+export class Estimate extends BaseModel {
+  @prop({"required":false,"index":false,"zh":"微信用户"})
+  openid: string
+  @prop({"required":false,"index":false,"zh":"品牌","remark":""})
+  brand: string
+  @prop({"required":false,"index":false,"zh":"上牌日期"})
+  start: string
+  @prop({"required":false,"index":false,"zh":"所在地区"})
+  place: string
+  @prop({"required":false,"index":false,"zh":"联系人"})
+  contacts: string
+  @prop({"required":false,"index":false,"zh":"联系电话"})
+  tel: string
+  @prop({"required":false,"index":false,"zh":"预估金额","remark":"单位:万元"})
+  estimate: string
+  @prop({"required":false,"index":false,"zh":"状态"})
+  status: string
+}

+ 19 - 0
src/entity/shop.entity.ts

@@ -0,0 +1,19 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'shop' },
+})
+export class Shop extends BaseModel {
+  @prop({ required: false, index: false, zh: '店铺名称' })
+  name: string;
+  @prop({ required: false, index: false, zh: 'logo' })
+  logo: Array<any>;
+  @prop({ required: false, index: false, zh: '店铺地址' })
+  address: string;
+  @prop({ required: false, index: false, zh: '联系电话' })
+  tel: string;
+  @prop({ required: false, index: false, zh: '联系人' })
+  contacts: string;
+  @prop({ required: false, index: false, zh: '是否使用', remark: '0:使用;1:禁用', default: '0' })
+  is_use: string;
+}

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

@@ -0,0 +1,15 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'brand' },
+})
+export class Brand extends BaseModel {
+  @prop({ required: false, index: false, zh: '品牌名' })
+  name: string;
+  @prop({ required: false, index: false, zh: 'logo' })
+  logo: Array<any>;
+  @prop({ required: false, index: false, zh: '首字母' })
+  letter: string;
+  @prop({ required: false, index: false, zh: '是否使用', remark: '0:使用;1禁用', default: '0' })
+  is_use: string;
+}

+ 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
+}

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

@@ -0,0 +1,27 @@
+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: 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: '菜单类型' })
+  type: string;
+  @prop({ required: false, index: false, zh: '图标' })
+  icon: string;
+  @prop({ required: false, index: false, zh: '备注' })
+  remark: string;
+  @prop({ required: false, index: true, zh: '是否启用', default: '0' })
+  is_use: string;
+  @prop({ required: false, index: false, zh: '只为平台提供', remark: '0:只为平台提供;1为所有用户提供', default: '0' })
+  for_platform: string;
+}

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

@@ -0,0 +1,19 @@
+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;
+  @prop({ required: false, index: false, zh: '店铺id', remark: '如果有店铺id字段,则只提供给店铺自己用' })
+  shop: string;
+}

+ 34 - 0
src/entity/user/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: '是否是平台管理员', remark: '0:平台管理员;1:非平台管理员', default: '1' })
+  is_platform: string;
+  @prop({ required: false, index: true, zh: '店铺' })
+  shop: string;
+  @prop({ required: false, index: false, zh: '是否启用', default: '0' })
+  is_use: string;
+}

+ 11 - 0
src/entity/user/follow.entity.ts

@@ -0,0 +1,11 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'follow' },
+})
+export class Follow extends BaseModel {
+  @prop({"required":false,"index":false,"zh":"用户id"})
+  user: string
+  @prop({"required":false,"index":false,"zh":"车源数据"})
+  car: string
+}

+ 13 - 0
src/entity/user/user.entity.ts

@@ -0,0 +1,13 @@
+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: '所属店铺', remark: '多店铺模式需要shop' })
+  shop: string;
+}

+ 13 - 0
src/filter/default.filter.ts

@@ -0,0 +1,13 @@
+import { Catch } from '@midwayjs/core';
+import { Context } from '@midwayjs/koa';
+
+@Catch()
+export class DefaultErrorFilter {
+  async catch(err: Error, ctx: Context) {
+    // 所有的未分类错误会到这里
+    return {
+      success: false,
+      message: err.message,
+    };
+  }
+}

+ 10 - 0
src/filter/notfound.filter.ts

@@ -0,0 +1,10 @@
+import { Catch, httpError, MidwayHttpError } from '@midwayjs/core';
+import { Context } from '@midwayjs/koa';
+
+@Catch(httpError.NotFoundError)
+export class NotFoundFilter {
+  async catch(err: MidwayHttpError, ctx: Context) {
+    // 404 错误会到这里
+    ctx.redirect('/404.html');
+  }
+}

+ 6 - 0
src/interface.ts

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

+ 221 - 0
src/interface/car.interface.ts

@@ -0,0 +1,221 @@
+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_car {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '店铺' })
+  'shop': string = undefined;
+  @ApiProperty({ description: '车辆识别VIN' })
+  'vin': string = undefined;
+  @ApiProperty({ description: '首次上牌时间' })
+  'f_time': string = undefined;
+  @ApiProperty({ description: '车源地' })
+  'place': string = undefined;
+  @ApiProperty({ description: '车牌地' })
+  'license': string = undefined;
+  @ApiProperty({ description: '外观颜色' })
+  'out_color': string = undefined;
+  @ApiProperty({ description: '内饰颜色' })
+  'in_color': string = undefined;
+  @ApiProperty({ description: '车辆使用性质' })
+  'use_type': string = undefined;
+  @ApiProperty({ description: '价格' })
+  'price': number = undefined;
+  @ApiProperty({ description: '车龄' })
+  'age': number = undefined;
+  @ApiProperty({ description: '里程' })
+  'mileage': number = undefined;
+  @ApiProperty({ description: '变速箱' })
+  'type': string = undefined;
+  @ApiProperty({ description: '车身结构' })
+  'structure': string = undefined;
+  @ApiProperty({ description: '排放标准' })
+  'emission': string = undefined;
+  @ApiProperty({ description: '能源类型' })
+  'energy': string = undefined;
+  @ApiProperty({ description: '排量' })
+  'displacement': string = undefined;
+  @ApiProperty({ description: '座椅' })
+  'set': string = undefined;
+  @ApiProperty({ description: '车辆级别' })
+  'level': string = undefined;
+  @ApiProperty({ description: '驱动方式' })
+  'drive': string = undefined;
+  @ApiProperty({ description: '油耗' })
+  'oil': string = undefined;
+  @ApiProperty({ description: '年均保险费' })
+  'premium': string = undefined;
+  @ApiProperty({ description: '年均保养费' })
+  'maintenance': string = undefined;
+  @ApiProperty({ description: '百公里加速' })
+  'hundred_time': string = undefined;
+  @ApiProperty({ description: '轴距' })
+  'wheelbase': string = undefined;
+  @ApiProperty({ description: '总价' })
+  'total_money': string = undefined;
+  @ApiProperty({ description: '付款方式' })
+  'pay_type': string = undefined;
+  @ApiProperty({ description: '首付' })
+  'first_pay': string = undefined;
+  @ApiProperty({ description: '实付价格' })
+  'real_pay': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '品牌' })
+  'brand': string = undefined;
+  @ApiProperty({ description: '车型' })
+  'series': string = undefined;
+  @ApiProperty({ description: '年份' })
+  'year': string = undefined;
+  @ApiProperty({ description: '车款' })
+  'style': string = undefined;
+}
+
+export class QDTO_car extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+}
+
+export class QVO_car extends FVO_car {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_car {
+  @ApiProperty({ description: '店铺' })
+  @Rule(RuleType['string']().empty(''))
+  'shop': string = undefined;
+  @ApiProperty({ description: '车辆识别VIN' })
+  @Rule(RuleType['string']().empty(''))
+  'vin': string = undefined;
+  @ApiProperty({ description: '首次上牌时间' })
+  @Rule(RuleType['string']().empty(''))
+  'f_time': string = undefined;
+  @ApiProperty({ description: '车源地' })
+  @Rule(RuleType['string']().empty(''))
+  'place': string = undefined;
+  @ApiProperty({ description: '车牌地' })
+  @Rule(RuleType['string']().empty(''))
+  'license': string = undefined;
+  @ApiProperty({ description: '外观颜色' })
+  @Rule(RuleType['string']().empty(''))
+  'out_color': string = undefined;
+  @ApiProperty({ description: '内饰颜色' })
+  @Rule(RuleType['string']().empty(''))
+  'in_color': string = undefined;
+  @ApiProperty({ description: '车辆使用性质' })
+  @Rule(RuleType['string']().empty(''))
+  'use_type': string = undefined;
+  @ApiProperty({ description: '价格' })
+  @Rule(RuleType['number']().empty(''))
+  'price': number = undefined;
+  @ApiProperty({ description: '车龄' })
+  @Rule(RuleType['number']().empty(''))
+  'age': number = undefined;
+  @ApiProperty({ description: '里程' })
+  @Rule(RuleType['number']().empty(''))
+  'mileage': number = undefined;
+  @ApiProperty({ description: '变速箱' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '车身结构' })
+  @Rule(RuleType['string']().empty(''))
+  'structure': string = undefined;
+  @ApiProperty({ description: '排放标准' })
+  @Rule(RuleType['string']().empty(''))
+  'emission': string = undefined;
+  @ApiProperty({ description: '能源类型' })
+  @Rule(RuleType['string']().empty(''))
+  'energy': string = undefined;
+  @ApiProperty({ description: '排量' })
+  @Rule(RuleType['string']().empty(''))
+  'displacement': string = undefined;
+  @ApiProperty({ description: '座椅' })
+  @Rule(RuleType['string']().empty(''))
+  'set': string = undefined;
+  @ApiProperty({ description: '车辆级别' })
+  @Rule(RuleType['string']().empty(''))
+  'level': string = undefined;
+  @ApiProperty({ description: '驱动方式' })
+  @Rule(RuleType['string']().empty(''))
+  'drive': string = undefined;
+  @ApiProperty({ description: '油耗' })
+  @Rule(RuleType['string']().empty(''))
+  'oil': string = undefined;
+  @ApiProperty({ description: '年均保险费' })
+  @Rule(RuleType['string']().empty(''))
+  'premium': string = undefined;
+  @ApiProperty({ description: '年均保养费' })
+  @Rule(RuleType['string']().empty(''))
+  'maintenance': string = undefined;
+  @ApiProperty({ description: '百公里加速' })
+  @Rule(RuleType['string']().empty(''))
+  'hundred_time': string = undefined;
+  @ApiProperty({ description: '轴距' })
+  @Rule(RuleType['string']().empty(''))
+  'wheelbase': string = undefined;
+  @ApiProperty({ description: '总价' })
+  @Rule(RuleType['string']().empty(''))
+  'total_money': string = undefined;
+  @ApiProperty({ description: '付款方式' })
+  @Rule(RuleType['string']().empty(''))
+  'pay_type': string = undefined;
+  @ApiProperty({ description: '首付' })
+  @Rule(RuleType['string']().empty(''))
+  'first_pay': string = undefined;
+  @ApiProperty({ description: '实付价格' })
+  @Rule(RuleType['string']().empty(''))
+  'real_pay': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+  @ApiProperty({ description: '品牌' })
+  @Rule(RuleType['string']().empty(''))
+  'brand': string = undefined;
+  @ApiProperty({ description: '车型' })
+  @Rule(RuleType['string']().empty(''))
+  'series': string = undefined;
+  @ApiProperty({ description: '年份' })
+  @Rule(RuleType['string']().empty(''))
+  'year': string = undefined;
+  @ApiProperty({ description: '车款' })
+  @Rule(RuleType['string']().empty(''))
+  'style': string = undefined;
+}
+
+export class CVO_car extends FVO_car {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_car extends CDTO_car {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_car extends FVO_car {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 87 - 0
src/interface/config.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_config {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '销售模式' })
+  'mode': string = undefined;
+  @ApiProperty({ description: '平台名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: 'logo' })
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '联系人' })
+  'contacts': string = undefined;
+  @ApiProperty({ description: '联系电话' })
+  'tel': string = 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: '销售模式' })
+@Rule(RuleType['string']().empty(''))
+  'mode': string = undefined;
+  @ApiProperty({ description: '平台名称' })
+@Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: 'logo' })
+@Rule(RuleType['array']().empty(''))
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '联系人' })
+@Rule(RuleType['string']().empty(''))
+  'contacts': string = undefined;
+  @ApiProperty({ description: '联系电话' })
+@Rule(RuleType['string']().empty(''))
+  'tel': string = 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);
+  }
+}

+ 102 - 0
src/interface/estimate.interface.ts

@@ -0,0 +1,102 @@
+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_estimate {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '微信用户' })
+  'openid': string = undefined;
+  @ApiProperty({ description: '品牌' })
+  'brand': string = undefined;
+  @ApiProperty({ description: '上牌日期' })
+  'start': string = undefined;
+  @ApiProperty({ description: '所在地区' })
+  'place': string = undefined;
+  @ApiProperty({ description: '联系人' })
+  'contacts': string = undefined;
+  @ApiProperty({ description: '联系电话' })
+  'tel': string = undefined;
+  @ApiProperty({ description: '预估金额' })
+  'estimate': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+
+export class QDTO_estimate extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+}
+
+
+export class QVO_estimate extends FVO_estimate {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class CDTO_estimate {
+  @ApiProperty({ description: '微信用户' })
+@Rule(RuleType['string']().empty(''))
+  'openid': string = undefined;
+  @ApiProperty({ description: '品牌' })
+@Rule(RuleType['string']().empty(''))
+  'brand': string = undefined;
+  @ApiProperty({ description: '上牌日期' })
+@Rule(RuleType['string']().empty(''))
+  'start': string = undefined;
+  @ApiProperty({ description: '所在地区' })
+@Rule(RuleType['string']().empty(''))
+  'place': string = undefined;
+  @ApiProperty({ description: '联系人' })
+@Rule(RuleType['string']().empty(''))
+  'contacts': string = undefined;
+  @ApiProperty({ description: '联系电话' })
+@Rule(RuleType['string']().empty(''))
+  'tel': string = undefined;
+  @ApiProperty({ description: '预估金额' })
+@Rule(RuleType['string']().empty(''))
+  'estimate': string = undefined;
+  @ApiProperty({ description: '状态' })
+@Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+
+export class CVO_estimate extends FVO_estimate {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class UDTO_estimate extends CDTO_estimate {
+    @ApiProperty({ description: '数据id' })
+    @Rule(RuleType['string']().empty(''))
+    _id: string = undefined;
+}
+
+
+export class UVAO_estimate extends FVO_estimate {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 86 - 0
src/interface/shop.interface.ts

@@ -0,0 +1,86 @@
+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_shop {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '店铺名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: 'logo' })
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '店铺地址' })
+  'address': string = undefined;
+  @ApiProperty({ description: '联系电话' })
+  'tel': string = undefined;
+  @ApiProperty({ description: '联系人' })
+  'contacts': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_shop extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+}
+
+export class QVO_shop extends FVO_shop {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_shop {
+  @ApiProperty({ description: '店铺名称' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: 'logo' })
+  @Rule(RuleType['array']().empty(''))
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '店铺地址' })
+  @Rule(RuleType['string']().empty(''))
+  'address': string = undefined;
+  @ApiProperty({ description: '联系电话' })
+  @Rule(RuleType['string']().empty(''))
+  'tel': string = undefined;
+  @ApiProperty({ description: '联系人' })
+  @Rule(RuleType['string']().empty(''))
+  'contacts': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_shop extends FVO_shop {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_shop extends CDTO_shop {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_shop extends FVO_shop {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 76 - 0
src/interface/system/brand.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_brand {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '品牌名' })
+  'name': string = undefined;
+  @ApiProperty({ description: 'logo' })
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '首字母' })
+  'letter': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_brand extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+}
+
+export class QVO_brand extends FVO_brand {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_brand {
+  @ApiProperty({ description: '品牌名' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: 'logo' })
+  @Rule(RuleType['array']().empty(''))
+  'logo': Array<any> = undefined;
+  @ApiProperty({ description: '首字母' })
+  @Rule(RuleType['string']().empty(''))
+  'letter': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_brand extends FVO_brand {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_brand extends CDTO_brand {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_brand extends FVO_brand {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

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

@@ -0,0 +1,91 @@
+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', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '字典类型编码' })
+  'code': 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);
+  }
+}

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

@@ -0,0 +1,86 @@
+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 = ['code', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @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);
+  }
+}

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

@@ -0,0 +1,118 @@
+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: '父级菜单' })
+  '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: '备注' })
+  'remark': string = undefined;
+  @ApiProperty({ description: '是否启用' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '只为平台提供' })
+  'for_platform': 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(''))
+  '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['string']().empty(''))
+  'remark': string = undefined;
+  @ApiProperty({ description: '是否启用' })
+@Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+  @ApiProperty({ description: '只为平台提供' })
+@Rule(RuleType['string']().empty(''))
+  'for_platform': 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);
+  }
+}

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

@@ -0,0 +1,96 @@
+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;
+  @ApiProperty({ description: '店铺id' })
+  'shop': 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;
+  @ApiProperty({ description: '店铺id' })
+@Rule(RuleType['string']().empty(''))
+  'shop': 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);
+  }
+}

+ 101 - 0
src/interface/user/admin.interface.ts

@@ -0,0 +1,101 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { FrameworkErrorEnum, SearchBase, ServiceError } 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: '是否是平台管理员' })
+  'is_platform': string = undefined;
+  @ApiProperty({ description: '店铺' })
+  'shop': string = undefined;
+  @ApiProperty({ description: '是否启用' })
+  'is_use': string = undefined;
+}
+
+
+export class QDTO_admin extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['account', 'shop'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '账号' })
+  'account': string = undefined;
+  @ApiProperty({ description: '店铺' })
+  'shop': 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']().required().error(new ServiceError('缺少账号',FrameworkErrorEnum.NEED_BODY)))
+  '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(''))
+  'is_platform': string = undefined;
+  @ApiProperty({ description: '店铺' })
+@Rule(RuleType['string']().empty(''))
+  'shop': 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);
+  }
+}

+ 72 - 0
src/interface/user/follow.interface.ts

@@ -0,0 +1,72 @@
+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_follow {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '车源数据' })
+  'car': string = undefined;
+}
+
+
+export class QDTO_follow extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = [];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+}
+
+
+export class QVO_follow extends FVO_follow {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class CDTO_follow {
+  @ApiProperty({ description: '用户id' })
+@Rule(RuleType['string']().empty(''))
+  'user': string = undefined;
+  @ApiProperty({ description: '车源数据' })
+@Rule(RuleType['string']().empty(''))
+  'car': string = undefined;
+}
+
+
+export class CVO_follow extends FVO_follow {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+
+export class UDTO_follow extends CDTO_follow {
+    @ApiProperty({ description: '数据id' })
+    @Rule(RuleType['string']().empty(''))
+    _id: string = undefined;
+}
+
+
+export class UVAO_follow extends FVO_follow {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 39 - 0
src/interface/user/login.interface.ts

@@ -0,0 +1,39 @@
+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;
+}

+ 77 - 0
src/interface/user/user.interface.ts

@@ -0,0 +1,77 @@
+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: '所属店铺' })
+  'shop': 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(''))
+  'shop': 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);
+  }
+}

+ 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';
+  }
+}

+ 11 - 0
src/service/car.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 { Car } from '../entity/car.entity';
+type modelType = ReturnModelType<typeof Car>;
+@Provide()
+export class CarService extends BaseService<modelType> {
+  @InjectEntityModel(Car)
+  model: modelType;
+}

+ 11 - 0
src/service/config.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 { Config } from '../entity/config.entity';
+type modelType = ReturnModelType<typeof Config>;
+@Provide()
+export class ConfigService extends BaseService<modelType> {
+  @InjectEntityModel(Config)
+  model: modelType;
+}

+ 11 - 0
src/service/estimate.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 { Estimate } from '../entity/estimate.entity';
+type modelType = ReturnModelType<typeof Estimate>;
+@Provide()
+export class EstimateService extends BaseService<modelType> {
+  @InjectEntityModel(Estimate)
+  model: modelType;
+}

+ 11 - 0
src/service/shop.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 { Shop } from '../entity/shop.entity';
+type modelType = ReturnModelType<typeof Shop>;
+@Provide()
+export class ShopService extends BaseService<modelType> {
+  @InjectEntityModel(Shop)
+  model: modelType;
+}

+ 11 - 0
src/service/system/brand.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 { Brand } from '../../entity/system/brand.entity';
+type modelType = ReturnModelType<typeof Brand>;
+@Provide()
+export class BrandService extends BaseService<modelType> {
+  @InjectEntityModel(Brand)
+  model: modelType;
+}

+ 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;
+}

+ 73 - 0
src/service/system/init.service.ts

@@ -0,0 +1,73 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { Admin } from '../../entity/user/admin.entity';
+import { Role } from '../../entity/system/role.entity';
+import { Menus } from '../../entity/system/menus.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>;
+
+  async adminUser() {
+    const data = {
+      account: 'admin',
+      password: '1qaz2wsx',
+      nick_name: '系统管理员',
+      is_super: '0',
+      is_platform: '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: '/homeIndex', component: '/home/index', type: '1' }];
+    // 系统设置
+    const smId = new ObjectId();
+    const systemMenus = [
+      { _id: smId, name: '系统设置', order_num: 2, type: '0' },
+      { name: '菜单设置', parent_id: smId.toString(), order_num: 1, path: '/system/menus', component: '/system/menus/index', type: '1' },
+      { name: '角色管理', parent_id: smId.toString(), order_num: 2, path: '/system/role', component: '/system/role/index', type: '1' },
+      { name: '字典管理', parent_id: smId.toString(), order_num: 3, path: '/system/dict', component: '/system/dict/index', type: '1' },
+      { name: '字典数据', parent_id: smId.toString(), order_num: 4, path: '/system/dictData', component: '/system/dictData/index', type: '2' },
+    ];
+    // 用户管理
+    const umId = new ObjectId();
+    const userMenus = [
+      { _id: umId, name: '用户管理', order_num: 3, type: '0' },
+      { name: '管理员用户', parent_id: umId.toString(), order_num: 1, path: '/user/admin', component: '/user/admin/index', type: '1' },
+      { name: '平台用户', parent_id: umId.toString(), order_num: 2, path: '/user/user', component: '/user/user/index', type: '1' },
+    ];
+    const password = { name: '修改密码', order_num: 999, path: '/acccount/updatepd', component: '/acccount/updatepd/index', type: '1' };
+
+    datas.push(...systemMenus, ...userMenus, password);
+    // 项目业务菜单
+    const busMenus = [
+      { name: '品牌管理', parent_id: smId.toString(), order_num: 5, path: '/system/brand', component: '/system/brand/index', type: '1' },
+      { name: '店铺管理', order_num: 4, path: '/shop', component: '/shop/index', type: '1' },
+      { name: '车源管理', order_num: 5, path: '/car', component: '/car/index', type: '1' },
+      { name: '车源估价', order_num: 6, path: '/estimate', component: '/estimate/index', type: '1' },
+    ];
+    datas.push(...busMenus);
+    await this.menusModel.insertMany(datas);
+  }
+  async initRoleMenu(admin: Admin) {}
+
+  async initDict() {}
+}

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

@@ -0,0 +1,43 @@
+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(): Promise<Array<object>> {
+    const data = await this.model
+      .find({}, { 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;
+  }
+}

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

@@ -0,0 +1,87 @@
+import { Provide, Inject } 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 = require('lodash/flattenDeep');
+import uniq = require('lodash/uniq');
+import get = require('lodash/get');
+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;
+
+  async getUserMenus() {
+    const user = this.ctx.user;
+    // TODO:这里需要改下. 平台的超级管理员有这些权限
+    if (user.role === 'Admin' && user.is_super === '0')
+      return await this.menusService.queryMenu();
+    const role = await this.model
+      .findOne({ code: user.role, is_use: '0' })
+      .lean();
+    if (!role)
+      throw new ServiceError(
+        '当前角色下的用户无法使用!',
+        FrameworkErrorEnum.SERVICE_FAULT
+      );
+    const menu = get(role, 'menu', {});
+    const mode = get(menu, 'mode');
+    if (mode !== 'select') return await this.menusService.queryMenu();
+    let routerPaths = Object.keys(menu);
+    routerPaths = routerPaths.filter(f => f !== 'mode');
+    const pageMenus = await this.menusModel
+      .find(
+        { path: routerPaths, is_use: '0' },
+        { _id: 1, parent_id: 1 },
+        { sort: { order_num: 1 } }
+      )
+      .lean();
+    const menuIds = pageMenus.map(i => i._id);
+    let parentIds = pageMenus.filter(i => i.parent_id);
+    while (parentIds.length > 0) {
+      const mid = await this.menusModel
+        .find({ _id: parentIds, is_use: '0' }, { _id: 1, parent_id: 1 })
+        .lean();
+      if (mid.length <= 0) break;
+      menuIds.push(mid.map(i => i._id));
+      parentIds = mid.filter(i => i.parent_id);
+    }
+    const rmenus = await this.menusModel
+      .find({ _id: menuIds, is_use: '0' }, {}, { sort: { order_num: 1 } })
+      .lean();
+    let treeMenu = rmenus.filter(f => !f.parent_id);
+    treeMenu = this.menusService.treeMenu(rmenus, treeMenu);
+    return treeMenu;
+  }
+
+  /**
+   * 根据角色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;
+  }
+}

+ 36 - 0
src/service/user/admin.service.ts

@@ -0,0 +1,36 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService, FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+import { Admin } from '../../entity/user/admin.entity';
+type modelType = ReturnModelType<typeof Admin>;
+import { Types } from 'mongoose';
+const ObjectId = Types.ObjectId;
+import get = require('lodash/get');
+@Provide()
+export class AdminService extends BaseService<modelType> {
+  @InjectEntityModel(Admin)
+  model: modelType;
+
+  async initSuper() {
+    const data = {
+      account: 'admin',
+      password: '1qaz2wsx',
+      nick_name: '系统管理员',
+      is_super: '0',
+      is_platform: '0',
+    };
+    const is_exist = await this.model.count({ is_super: '0' });
+    if (!is_exist) await this.model.create(data);
+    return;
+  }
+
+  async checkIsExist(data) {
+    if (!get(data, 'account')) return true;
+    const checkData: any = { account: get(data, 'account'), shop: get(data, 'account') };
+    if (get(data, '_id')) checkData._id = { $ne: new ObjectId(get(data, '_id')) };
+    const num = await this.model.count(checkData);
+    if (num > 0) throw new ServiceError('账户已存在!', FrameworkErrorEnum.SERVICE_FAULT);
+    return true;
+  }
+}

+ 11 - 0
src/service/user/follow.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 { Follow } from '../../entity/user/follow.entity';
+type modelType = ReturnModelType<typeof Follow>;
+@Provide()
+export class FollowService extends BaseService<modelType> {
+  @InjectEntityModel(Follow)
+  model: modelType;
+}

+ 69 - 0
src/service/user/login.service.ts

@@ -0,0 +1,69 @@
+import { 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/user/login.interface';
+import { RoleService } from '../system/role.service';
+
+@Provide()
+export class LoginService {
+  @Inject()
+  roleService: RoleService;
+
+  /**
+   * 账密登录
+   * @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);
+  // }
+}

+ 23 - 0
src/service/user/user.service.ts

@@ -0,0 +1,23 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService, FrameworkErrorEnum, ServiceError } from 'free-midway-component';
+import { User } from '../../entity/user/user.entity';
+type modelType = ReturnModelType<typeof User>;
+import get = require('lodash/get');
+import { Types } from 'mongoose';
+const ObjectId = Types.ObjectId;
+@Provide()
+export class UserService extends BaseService<modelType> {
+  @InjectEntityModel(User)
+  model: modelType;
+
+  async checkIsExist(data) {
+    if (!get(data, 'openid')) return true;
+    const checkData: any = { openid: get(data, 'openid'), shop: get(data, 'shop') };
+    if (get(data, '_id')) checkData._id = { $ne: new ObjectId(get(data, '_id')) };
+    const num = await this.model.count(checkData);
+    if (num > 0) throw new ServiceError('账户已存在!', FrameworkErrorEnum.SERVICE_FAULT);
+    return true;
+  }
+}

+ 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);
+  });
+
+});

+ 25 - 0
tsconfig.json

@@ -0,0 +1,25 @@
+{
+  "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"
+  },
+  "exclude": [
+    "dist",
+    "node_modules",
+    "test"
+  ]
+}