lrf преди 3 месеца
родител
ревизия
9ebee450c0
променени са 2 файла, в които са добавени 61 реда и са изтрити 2 реда
  1. 48 1
      src/controller/match/matchExt.controller.ts
  2. 13 1
      src/entity/match/matchRegistration.entity.ts

+ 48 - 1
src/controller/match/matchExt.controller.ts

@@ -584,7 +584,54 @@ export class MatchExtController implements BaseController {
     await this.matchRegService.update({ match_id, ext_status: '6', final_confirm: '0' }, { ext_status: '7' });
   }
 
-  // TODO:决赛大屏,评委打分
+  // TODO:决赛大屏
+  /**
+   * 评委打分,前端将评委的数据传来.然后再做总分计算,总分通过平均分方式计算
+   * @param match_id 赛事id
+   * @param data body
+   * @property id 报名数据id
+   * @property {Object} details 决赛总分数详情
+   */
+  @Post('/step7/score/:match_id', { routerName: '决赛阶段-赛事进行' })
+  async step7Score(@Param('match_id') match_id: string, @Body() data: object) {
+    /**
+     * 检查内容:
+     *  赛事拓展表:
+     *    ext.status = "7"
+     * 修改内容:
+     *  赛事报名表:
+     *    reg.ext_status: "7"
+     *    reg.final_confirm: "0"
+     *    reg.id: ${id}
+     *    reg.final_score_details=>  ${details}
+     */
+    await this.service.checkMatchExtStatus(match_id, '7');
+    const id = get(data, 'id')
+    if (!id) {
+      // 抛出异常
+      throw new ServiceError(ErrorCode.MATCH_REG_NOT_FOUND);
+    }
+    const query = { id, match_id, ext_status: '7', final_confirm: '0' };
+    const regData = await this.matchRegService.fetch(query);
+    if (!regData) {
+      throw new ServiceError(ErrorCode.MATCH_REG_NOT_FOUND);
+    }
+    // 合并评审记录
+    const oldDetails: Array<any> = get(regData, 'final_score_details')
+    const final_score_details: object = get(data, 'details')
+    const alreadyGiven = oldDetails.findIndex(f => get(final_score_details, 'name') && f.name === get(final_score_details, 'name'))
+    if (alreadyGiven >= 0) {
+      // 已经给过了,最新的覆盖
+      oldDetails.splice(alreadyGiven, 0, final_score_details)
+    } else {
+      // 没有给,那就直接push
+      oldDetails.push(final_score_details)
+    }
+    // 计算总分
+    const final_score_total = oldDetails.reduce((p, n) => p + get(n, 'score', 0), 0);
+    const final_score = final_score_total / oldDetails.length;
+    await this.matchRegService.update(query, { final_score, final_score_details: oldDetails });
+  }
 
   @Post('/step8', { routerName: '决赛阶段-赛事结束' })
   async step8(@Body() data: object) {

+ 13 - 1
src/entity/match/matchRegistration.entity.ts

@@ -12,6 +12,18 @@ dayjs.tz.setDefault("Asia/Shanghai")
  * 1:已通过: 报名阶段: 报名信息已通过审核; 初审阶段:进入初审,已通过初审(有分,且已被选中参加决赛); 决赛阶段: 进入决赛,已确认且完成决赛(确认参加,有分)
  * 2:已退回: 报名阶段: 报名信息有问题,被主办方退回的状态; 初审阶段:进入初审,但未通过初审(有分,但未被选中参加决赛); 决赛阶段: 进入决赛,但是不参加决赛(不确认)
  */
+/**
+ * final_score_details:[
+ *  {
+ *    name:string,
+ *    score:number,
+ *    details:[{
+ *      title,
+ *      score,
+ *    },...],
+ *  }
+ * ]
+ */
 //赛事
 @Entity('matchRegistration', { comment: '赛事报名' })
 export class MatchRegistration extends BaseModel {
@@ -43,7 +55,7 @@ export class MatchRegistration extends BaseModel {
   @Column({ type: 'integer', nullable: true, comment: '决赛总分数' })
   final_score: number;
   @Column({ type: 'jsonb', nullable: true, comment: '决赛分数详情' })
-  final_score_details: object;
+  final_score_details: Array<any>;
   @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 } })
   final_start_time: Date;