lrf преди 4 месеца
родител
ревизия
58a6cf5159
променени са 3 файла, в които са добавени 95 реда и са изтрити 24 реда
  1. 45 10
      src/controller/match/matchExt.controller.ts
  2. 48 14
      src/controller/match/matchRegistration.controller.ts
  3. 2 0
      src/entity/match/matchRegistration.entity.ts

+ 45 - 10
src/controller/match/matchExt.controller.ts

@@ -1,42 +1,47 @@
-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 { omit, pick } from 'lodash';
+import { get, omit, pick } from 'lodash';
 import { ServiceError, ErrorCode } from '../../error/service.error';
 import { BaseController } from '../../frame/BaseController';
 import { MatchExtService } from '../../service/match/matchExt.service';
+import { MatchRegistrationService } from '../../service/match/matchRegistration.service';
+import { UserService } from '../../service/system/user.service';
+import { AliyunSmsService } from '../../service/thirdParty/aliyunSms.service';
 const namePrefix = '创新大赛拓展';
 @ApiTags(['创新大赛拓展'])
 @Controller('/matchExt', { tagName: namePrefix })
 export class MatchExtController implements BaseController {
   @Inject()
   service: MatchExtService;
+  @Inject()
+  matchRegService: MatchRegistrationService
+  @Inject()
+  userService: UserService
+  @Inject()
+  smsService: AliyunSmsService
+
+
   @Get('/')
   @ApiTags('列表查询')
   @ApiQuery({ name: 'query' })
-  @ApiResponse({ type: QVO_match })
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others: any = pick(query, ['skip', 'limit']);
-    others.order = { order_num: 'ASC' };
     const result = await this.service.query(qobj, others);
     return result;
   }
 
   @Get('/:id')
   @ApiTags('单查询')
-  @ApiResponse({ type: FVO_match })
   async fetch(@Param('id') id: number) {
     const data = await this.service.fetch({ id });
-    const result = new FVO_match(data);
-    return result;
+    return data;
   }
 
   @Post('/', { routerName: `创建${namePrefix}` })
   @ApiTags('创建数据')
   @Validate()
-  @ApiResponse({ type: CVO_match })
   async create(@Body() data: object) {
     return false;
   }
@@ -44,7 +49,6 @@ export class MatchExtController implements BaseController {
   @Post('/:id', { routerName: `修改${namePrefix}` })
   @ApiTags('修改数据')
   @Validate()
-  @ApiResponse({ type: UVAO_match })
   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);
@@ -61,9 +65,40 @@ export class MatchExtController implements BaseController {
   }
 
   @Get('/detail/:id')
-  @ApiResponse({ type: FVO_match })
   async detail(@Param('id') id: string) {
     const data = await this.service.fetch({ id });
     return data;
   }
+
+
+  @Get('/firstStep/:match_id', { routerName: `进入初赛阶段` })
+  async toFirstStep(@Param('match_id') match_id: string, @Body() data: object) {
+    // 进入初赛阶段,查询选手名单(未被退回的),根据选手名单的报名顺序,排列名单,并赋予开始时间
+    /**赛事拓展数据 */
+    const extData = await this.service.fetch({ match_id })
+    if (extData) {
+      // 修改流程进度为下一步----初赛
+      await this.service.update({ match_id }, { status: '1' })
+    }
+    const start_time = get(data, 'start_time')
+    const regQuery = { match_id, status: '0' }
+    await this.matchRegService.update(regQuery, { start_time })
+    /**赛事报名数据 */
+    const { data: list } = await this.matchRegService.query(regQuery)
+    // 发送短信通知
+    const msg = `您参加的赛事: ${get(extData, 'name')} 将于 ${start_time}开始初赛,具体安排请通过网页或小程序查看.请您提前做好准备.`
+    for (const i of list) {
+      const user_id = get(i, 'user_id')
+      if (!user_id) continue
+      const user = await this.userService.fetch({ id: user_id })
+      if (!user) continue;
+      const phone = get(user, 'phone')
+      try {
+        await this.smsService.send(phone, msg)
+      } catch (error) {
+        console.error('matchExt - toFirstStep:发送短信发生错误')
+      }
+    }
+
+  }
 }

+ 48 - 14
src/controller/match/matchRegistration.controller.ts

@@ -1,4 +1,3 @@
-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, Config } from '@midwayjs/core';
@@ -38,7 +37,6 @@ export class MatchRegistrationController implements BaseController {
   @Get('/')
   @ApiTags('列表查询')
   @ApiQuery({ name: 'query' })
-  @ApiResponse({ type: QVO_match })
   async index(@Query() query: object) {
     const qobj = omit(query, ['skip', 'limit']);
     const others: any = pick(query, ['skip', 'limit']);
@@ -60,17 +58,14 @@ export class MatchRegistrationController implements BaseController {
 
   @Get('/:id')
   @ApiTags('单查询')
-  @ApiResponse({ type: FVO_match })
   async fetch(@Param('id') id: number) {
     const data = await this.service.fetch({ id });
-    const result = new FVO_match(data);
-    return result;
+    return data;
   }
 
   @Post('/', { routerName: `创建${namePrefix}` })
   @ApiTags('创建数据')
   @Validate()
-  @ApiResponse({ type: CVO_match })
   async create(@Body() data: object) {
     const userColumns = ['user', 'user_id'];
     let regData = omit(data, userColumns);
@@ -93,9 +88,14 @@ export class MatchRegistrationController implements BaseController {
       }
       returnUser = { password, account: get(user, 'account') }
       // 发送短信
-      const phone = get(user, 'phone')
-      const msg = { "账号": get(user, 'account'), "密码": password }
-      await this.smsService.send(phone, msg)
+      try {
+        const phone = get(user, 'phone')
+        const msg = { "账号": get(user, 'account'), "密码": password }
+        await this.smsService.send(phone, msg)
+      } catch (error) {
+        console.error('matchReg - create:发送短信发生错误')
+      }
+
 
       const dbData = await this.userService.create(user);
       regData = { user_id: dbData.id, ...regData };
@@ -116,10 +116,26 @@ export class MatchRegistrationController implements BaseController {
   @Post('/:id', { routerName: `修改${namePrefix}` })
   @ApiTags('修改数据')
   @Validate()
-  @ApiResponse({ type: UVAO_match })
   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);
+    if (get(result, 'stauts') === '-1') {
+      //被退回,发送短信
+      const user_id = get(result, 'user_id')
+      const user = await this.userService.fetch({ id: user_id })
+      if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND)
+      const match_id = get(result, 'match_id')
+      const match = await this.matchService.fetch({ id: match_id })
+      if (!match) throw new ServiceError(ErrorCode.MATCH_NOT_FOUND)
+      const match_name = get(match, 'match_name')
+      const phone = get(user, 'phone')
+      const msg = `您提交的的 ${match_name} 赛事申请已被退回,请登录平台进行修改后提交`
+      try {
+        await this.smsService.send(phone, msg)
+      } catch (error) {
+        console.error('matchReg - update:发送短信发生错误')
+      }
+    }
     return result;
   }
 
@@ -133,21 +149,39 @@ export class MatchRegistrationController implements BaseController {
   }
 
   @Get('/detail/:id')
-  @ApiResponse({ type: FVO_match })
   async detail(@Param('id') id: string) {
     const data = await this.service.fetch({ id });
     return data;
   }
 
-  @Get('/export/:match_id')
+  @Get('/view/:match_id', { routerName: '查看初赛名单结果' })
+  async viewOrderByScore(@Param('match_id') match_id: string) {
+    const query = { match_id, status: '0' }
+    const others = { order: { score: 'DESC' } }
+    const { data: list } = await this.service.query(query, others)
+    const match = await this.matchService.fetch({ id: match_id })
+    const match_name = get(match, 'name')
+    for (const i of list) {
+      const user_id = get(i, 'user_id')
+      const user = await this.userService.fetch({ id: user_id })
+      if (user) i.user_name = get(user, 'nick_name')
+      if (match_name) i.match_name = match_name
+      delete i.info;
+    }
+    return list
+  }
+
+
+
+  @Get('/export/:match_id', { routerName: `导出初赛名单` })
   @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')

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

@@ -20,4 +20,6 @@ export class MatchRegistration extends BaseModel {
   order_no: number;
   @Column({ type: 'integer', nullable: true, comment: '分数' })
   score: number;
+  @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 } })
+  start_time: Date;
 }