lrf преди 3 месеца
родител
ревизия
7f0e52fb6c
променени са 3 файла, в които са добавени 53 реда и са изтрити 1 реда
  1. 47 1
      src/controller/match/matchRegistration.controller.ts
  2. 4 0
      src/entity/match/matchRegistration.entity.ts
  3. 2 0
      src/error/service.error.ts

+ 47 - 1
src/controller/match/matchRegistration.controller.ts

@@ -1,7 +1,7 @@
 import { CVO_match, FVO_match, QVO_match, UVAO_match } from '../../interface/platform/match.interface';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
-import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
+import { Controller, Inject, Get, Param, Post, Body, Del, Query, Config } from '@midwayjs/core';
 import { get, omit, pick } from 'lodash';
 import { ServiceError, ErrorCode } from '../../error/service.error';
 import { BaseController } from '../../frame/BaseController';
@@ -9,6 +9,7 @@ import { MatchRegistrationService } from '../../service/match/matchRegistration.
 import { UserService } from '../../service/system/user.service';
 import * as bcrypt from 'bcryptjs';
 import dayjs = require('dayjs');
+import { MatchService } from '../../service/platform/match.service';
 const namePrefix = '创新大赛-赛事报名';
 @ApiTags(['创新大赛-赛事报名'])
 @Controller('/matchReg', { tagName: namePrefix })
@@ -17,6 +18,10 @@ export class MatchRegistrationController implements BaseController {
   service: MatchRegistrationService;
   @Inject()
   userService: UserService;
+  @Inject()
+  matchService: MatchService
+  @Config('PathConfig.path')
+  path;
   @Get('/')
   @ApiTags('列表查询')
   @ApiQuery({ name: 'query' })
@@ -101,4 +106,45 @@ export class MatchRegistrationController implements BaseController {
     const data = await this.service.fetch({ id });
     return data;
   }
+
+  @Get('/detail/:match_id')
+  @ApiTags('导出初赛名单')
+  async exportList(@Param('match_id') match_id: string) {
+    // 查询所有未被退回的报名信息
+    const { data } = await this.service.query({ match_id, status: '0' })
+    // TODO:没有人,提示该赛事没有报名人员,无法导出
+    if (data.length <= 0) throw new ServiceError(ErrorCode.MATCH_NO_PERSON_TO_EXPORT)
+    const match = await this.matchService.fetch({ id: match_id })
+    // TODO:没有找到赛事信息
+    if (!match) throw new ServiceError(ErrorCode.MATCH_NOT_FOUND)
+    // 获取赛事名称, 赛事名称放首行
+    const match_name = get(match, 'name')
+    // 第二行是表头: 项目编号,用户名称,报名时间, ...报名信息,分数
+    const header = ['项目编号', '用户名称', '报名时间']
+    // TODO: 将报名信息的问题塞进来
+
+    // 填充分数列
+    header.push('分数')
+    const list = [];
+    // 整理数据
+    for (const i of data) {
+      const item = [];
+      // 项目编号
+      const no = get(i, 'no', "")
+      item.push(no)
+      // 用户信息
+      const user = await this.userService.fetch({ id: get(i, 'user_id') });
+      if (user) item.push(get(user, 'nick_nake'))
+      else item.push("")
+      // 报名时间
+      const time = get(i, 'time', "")
+      item.push(time)
+      // TODO:处理报名信息
+    }
+    const filename = `${match_name}初赛名单.xlsx`
+    const path = this.path;
+    if (!path) {
+      throw new ServiceError('服务端没有设置存储路径');
+    }
+  }
 }

+ 4 - 0
src/entity/match/matchRegistration.entity.ts

@@ -16,4 +16,8 @@ export class MatchRegistration extends BaseModel {
   no: string;
   @Column({ type: 'timestamp without time zone', nullable: true, comment: '时间', transformer: { from: value => (value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : value), to: value => value } })
   time: Date;
+  @Column({ type: 'integer', nullable: true, comment: '顺序' })
+  order_no: number;
+  @Column({ type: 'integer', nullable: true, comment: '分数' })
+  score: number;
 }

+ 2 - 0
src/error/service.error.ts

@@ -57,6 +57,8 @@ export enum ErrorCode {
   //match
   MATCH_NEED_USER_INFO = 'MATCH_NEED_USER_INFO',
   MATCH_USER_HAS_REGISTED = 'MATCH_USER_HAS_REGISTED',
+  MATCH_NO_PERSON_TO_EXPORT = 'MATCH_NO_PERSON_TO_EXPORT',
+  MATCH_NOT_FOUND = 'MATCH_NOT_FOUND',
 
   DATA_NOT_FOUND = 'DATA_NOT_FOUND',