浏览代码

修改分数跟流程

zs 9 月之前
父节点
当前提交
a0da7ac14c

+ 79 - 0
src/controller/platform/score.controller.ts

@@ -0,0 +1,79 @@
+import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
+import { ScoreService } from '../../service/platform/score.service';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+import { omit, pick } from 'lodash';
+import { ServiceError, ErrorCode } from '../../error/service.error';
+import { BaseController } from '../../frame/BaseController';
+import { QVO_score, FVO_score, CVO_score, UVAO_score } from '../../interface/platform/score.interface';
+import { Context } from '@midwayjs/koa';
+const namePrefix = '分数';
+@ApiTags(['分数'])
+@Controller('/score', { tagName: namePrefix })
+export class ScoreController implements BaseController {
+  @Inject()
+  service: ScoreService;
+  @Inject()
+  ctx: Context;
+
+  @Get('/')
+  @ApiTags('列表查询')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_score })
+  async index(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const result = await this.service.query(qobj, others);
+    return result;
+  }
+
+  @Get('/:id')
+  @ApiTags('单查询')
+  @ApiResponse({ type: FVO_score })
+  async fetch(@Param('id') id: number) {
+    const data = await this.service.fetch({ id });
+    const result = new FVO_score(data);
+    return result;
+  }
+
+  @Post('/', { routerName: `创建${namePrefix}` })
+  @ApiTags('创建数据')
+  @Validate()
+  @ApiResponse({ type: CVO_score })
+  async create(@Body() data: object) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_score(dbData);
+    return result;
+  }
+
+  @Post('/:id', { routerName: `修改${namePrefix}` })
+  @ApiTags('修改数据')
+  @Validate()
+  @ApiResponse({ type: UVAO_score })
+  async update(@Param('id') id: number, @Body() data: object) {
+    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    const result = await this.service.update({ id }, data);
+    return result;
+  }
+
+  @Del('/:id', { routerName: `删除${namePrefix}` })
+  @ApiTags('删除数据')
+  @Validate()
+  async delete(@Param('id') id: number) {
+    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    const result = await this.service.delete({ id });
+    return result;
+  }
+
+  @Get('/list')
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    const list = [];
+    for (const i of data) {
+      list.push(await this.service.fillName(i));
+    }
+    return { data: list, total };
+  }
+}

+ 18 - 0
src/entity/platform/score.entity.ts

@@ -0,0 +1,18 @@
+import { Entity, Column } from 'typeorm';
+import { BaseModel } from '../../frame/BaseModel';
+//项目
+@Entity('score')
+export class Score extends BaseModel {
+  @Column({ type: 'integer', nullable: true, comment: '平台用户id' })
+  user: number;
+  @Column({ type: 'integer', nullable: true, comment: '赛事id' })
+  match: number;
+  @Column({ type: 'integer', nullable: true, comment: '流程id' })
+  matchPath: number;
+  @Column({ type: 'integer', nullable: true, comment: '选手id' })
+  sign: number;
+  @Column({ type: 'integer', nullable: true, comment: '分数' })
+  score: number;
+  @Column({ type: 'character varying', nullable: true, comment: '发布时间' })
+  time: string;
+}

+ 2 - 0
src/entity/users/competition.entity.ts

@@ -11,6 +11,8 @@ export class Competition extends BaseModel {
   person: string;
   @Column({ type: 'character varying', nullable: true, comment: '负责人电话' })
   person_phone: string;
+  @Column({ type: 'character varying', nullable: true, comment: '盈利模式' })
+  mode: string;
   @Column({ type: 'text', nullable: true, comment: '简介' })
   brief: string;
   @Column({ type: 'character varying', nullable: true, comment: '地址' })

+ 86 - 0
src/interface/platform/score.interface.ts

@@ -0,0 +1,86 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from '../../frame/SearchBase';
+import { dealVO } from '../../frame/VOBase';
+export class FVO_score {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  id: number = undefined;
+  @ApiProperty({ description: '平台用户id' })
+  'user': number = undefined;
+  @ApiProperty({ description: '赛事id' })
+  'match': number = undefined;
+  @ApiProperty({ description: '流程id' })
+  'matchPath': number = undefined;
+  @ApiProperty({ description: '选手id' })
+  'sign': number = undefined;
+  @ApiProperty({ description: '分数' })
+  'score': number = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+}
+
+export class QDTO_score extends SearchBase {
+  @ApiProperty({ description: '平台用户id' })
+  'user': number = undefined;
+  @ApiProperty({ description: '赛事id' })
+  'match': number = undefined;
+  @ApiProperty({ description: '流程id' })
+  'matchPath': number = undefined;
+  @ApiProperty({ description: '选手id' })
+  'sign': number = undefined;
+  @ApiProperty({ description: '分数' })
+  'score': number = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+}
+
+export class QVO_score extends FVO_score {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_score {
+  @ApiProperty({ description: '平台用户id' })
+  @Rule(RuleType['number']().empty(''))
+  'user': number = undefined;
+  @ApiProperty({ description: '赛事id' })
+  @Rule(RuleType['number']().empty(''))
+  'match': number = undefined;
+  @ApiProperty({ description: '流程id' })
+  @Rule(RuleType['number']().empty(''))
+  'matchPath': number = undefined;
+  @ApiProperty({ description: '选手id' })
+  @Rule(RuleType['number']().empty(''))
+  'sign': number = undefined;
+  @ApiProperty({ description: '分数' })
+  @Rule(RuleType['number']().empty(''))
+  'score': number = undefined;
+  @ApiProperty({ description: '发布时间' })
+  @Rule(RuleType['string']().empty(''))
+  'time': string = undefined;
+}
+
+export class CVO_score extends FVO_score {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_score extends CDTO_score {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['number']().empty(''))
+  id: number = undefined;
+}
+
+export class UVAO_score extends FVO_score {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 7 - 0
src/interface/users/competition.interface.ts

@@ -15,6 +15,8 @@ export class FVO_competition {
   'person': string = undefined;
   @ApiProperty({ description: '负责人电话' })
   'person_phone': string = undefined;
+  @ApiProperty({ description: '盈利模式' })
+  'mode': string = undefined;
   @ApiProperty({ description: '简介' })
   'brief': string = undefined;
   @ApiProperty({ description: '地址' })
@@ -34,6 +36,8 @@ export class QDTO_competition {
   'person': string = undefined;
   @ApiProperty({ description: '负责人电话' })
   'person_phone': string = undefined;
+  @ApiProperty({ description: '盈利模式' })
+  'mode': string = undefined;
   @ApiProperty({ description: '是否公开' })
   'is_show': string = undefined;
   @ApiProperty({ description: '状态' })
@@ -60,6 +64,9 @@ export class CDTO_competition {
   @ApiProperty({ description: '负责人电话' })
   @Rule(RuleType['string']().empty(''))
   'person_phone': string = undefined;
+  @ApiProperty({ description: '盈利模式' })
+  @Rule(RuleType['string']().empty(''))
+  'mode': string = undefined;
   @ApiProperty({ description: '简介' })
   @Rule(RuleType['string']().empty(''))
   'brief': string = undefined;

+ 35 - 0
src/service/platform/score.service.ts

@@ -0,0 +1,35 @@
+import { Score } from '../../entity/platform/score.entity';
+import { Provide, Inject } from '@midwayjs/core';
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { Repository } from 'typeorm';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
+import { get } from 'lodash';
+import { SignService } from './sign.service';
+import { MatchPathService } from './matchPath.service';
+@Provide()
+export class ScoreService extends BaseServiceV2 {
+  @InjectEntityModel(Score)
+  model: Repository<Score>;
+
+  @Inject()
+  matchPathService: MatchPathService;
+
+  @Inject()
+  signService: SignService;
+
+  /**
+   * 填充赛事信息
+   * @param {object} data 数据
+   */
+  async fillName(data) {
+    const { matchPath, sign } = data;
+    // 流程名称
+    const matchPathInfo = await this.matchPathService.fetch({ id: matchPath });
+    if (matchPathInfo) data = { ...data, matchPath_name: get(matchPathInfo, 'name') };
+    // 选手
+    const signInfo = await this.signService.fetch({ id: sign });
+    if (signInfo) data = { ...data, sign_name: get(signInfo, 'name') };
+
+    return data;
+  }
+}