zs 3 mesi fa
parent
commit
39f9093815
1 ha cambiato i file con 84 aggiunte e 90 eliminazioni
  1. 84 90
      src/controller/match/matchRegistration.controller.ts

+ 84 - 90
src/controller/match/matchRegistration.controller.ts

@@ -7,7 +7,7 @@ import { BaseController } from '../../frame/BaseController';
 import { MatchRegistrationService } from '../../service/match/matchRegistration.service';
 import { UserService } from '../../service/system/user.service';
 import * as bcrypt from 'bcryptjs';
-import * as Path from 'path'
+import * as Path from 'path';
 import dayjs = require('dayjs');
 import { MatchService } from '../../service/platform/match.service';
 import { ServiceUtilService } from '../../service/serviceUtil.service';
@@ -23,14 +23,13 @@ export class MatchRegistrationController implements BaseController {
   @Inject()
   userService: UserService;
   @Inject()
-  matchService: MatchService
+  matchService: MatchService;
   @Inject()
-  serviceUtil: ServiceUtilService
+  serviceUtil: ServiceUtilService;
   @Inject()
   utilService: UtilService;
   @Inject()
-  smsService: AliyunSmsService
-
+  smsService: AliyunSmsService;
 
   @Config('PathConfig.path')
   path;
@@ -42,16 +41,16 @@ export class MatchRegistrationController implements BaseController {
     const others: any = pick(query, ['skip', 'limit']);
     others.order = { time: 'ASC' };
     const { data, total } = await this.service.query(qobj, others);
-    const fillList = []
+    const fillList = [];
     for (const i of data) {
-      let newItem = cloneDeep(i)
-      const user_id = get(i, 'user_id')
-      const user = await this.userService.fetch({ id: user_id })
-      if (user) newItem.user_name = get(user, 'nick_name')
-      const match_id = get(i, 'match_id')
-      const match = await this.matchService.fetch({ id: match_id })
-      if (match) newItem.match_name = get(match, 'name')
-      fillList.push(newItem)
+      const newItem = cloneDeep(i);
+      const user_id = get(i, 'user_id');
+      const user = await this.userService.fetch({ id: user_id });
+      if (user) newItem.user_name = get(user, 'nick_name');
+      const match_id = get(i, 'match_id');
+      const match = await this.matchService.fetch({ id: match_id });
+      if (match) newItem.match_name = get(match, 'name');
+      fillList.push(newItem);
     }
     return { data: fillList, total };
   }
@@ -86,17 +85,16 @@ export class MatchRegistrationController implements BaseController {
         const hash = bcrypt.hashSync(password, salt);
         Object.assign(user, { password: hash });
       }
-      returnUser = { password, account: get(user, 'account') }
+      returnUser = { password, account: get(user, 'account') };
       // 发送短信
       try {
-        const phone = get(user, 'phone')
-        const msg = { "账号": get(user, 'account'), "密码": password }
-        await this.smsService.send(phone, msg)
+        const phone = get(user, 'phone');
+        const msg = { 账号: get(user, 'account'), 密码: password };
+        await this.smsService.send(phone, msg);
       } catch (error) {
-        console.error('matchReg - create:发送短信发生错误')
+        console.error('matchReg - create:发送短信发生错误');
       }
 
-
       const dbData = await this.userService.create(user);
       regData = { user_id: dbData.id, ...regData };
     }
@@ -109,7 +107,7 @@ export class MatchRegistrationController implements BaseController {
     const no = `${get(data, 'match_id')}-${get(regData, 'user_id')}-${matchRegTotal + 1}`;
     regData = { ...regData, no, time: dayjs().format('YYYY-MM-DD HH:mm:ss') };
     const result = await this.service.create(regData);
-    if (Object.keys(returnUser).length > 0) return returnUser
+    if (Object.keys(returnUser).length > 0) return returnUser;
     else return result;
   }
 
@@ -121,19 +119,19 @@ export class MatchRegistrationController implements BaseController {
     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} 赛事申请已被退回,请登录平台进行修改后提交`
+      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)
+        await this.smsService.send(phone, msg);
       } catch (error) {
-        console.error('matchReg - update:发送短信发生错误')
+        console.error('matchReg - update:发送短信发生错误');
       }
     }
     return result;
@@ -156,95 +154,93 @@ export class MatchRegistrationController implements BaseController {
 
   @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')
+    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
+      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
+    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' })
+    const { data } = await this.service.query({ match_id, status: '0' });
     // 没有人,提示该赛事没有报名人员,无法导出
-    if (data.length <= 0) throw new ServiceError(ErrorCode.MATCH_NO_PERSON_TO_EXPORT)
-    const match = await this.matchService.fetch({ id: match_id })
+    if (data.length <= 0) throw new ServiceError(ErrorCode.MATCH_NO_PERSON_TO_EXPORT);
+    const match = await this.matchService.fetch({ id: match_id });
     // 没有找到赛事信息
-    if (!match) throw new ServiceError(ErrorCode.MATCH_NOT_FOUND)
+    if (!match) throw new ServiceError(ErrorCode.MATCH_NOT_FOUND);
     // 获取赛事名称, 赛事名称放首行
-    const match_name = get(match, 'name')
-    const fir = ['赛事名称', match_name]
+    const match_name = get(match, 'name');
+    const fir = ['赛事名称', match_name];
     // 第二行是表头: 项目编号,用户名称,报名时间, ...报名信息,分数
-    const sec = ['项目编号', '用户名称', '报名时间']
+    const sec = ['项目编号', '用户名称', '报名时间'];
     // 将报名信息的问题塞进来, 并整理出文件列,计算出文件列的字母
     const firstData = head(data);
-    const info = get(firstData, 'info', [])
-    const fileColumns = []
+    const info = get(firstData, 'info', []);
+    const fileColumns = [];
     for (const i of info) {
-      const problem = get(i, 'problem')
-      sec.push(problem)
-      const type = get(i, 'type')
+      const problem = get(i, 'problem');
+      sec.push(problem);
+      const type = get(i, 'type');
       if (type === '5' || type === '7') {
-        const length = sec.length
-        const col = this.utilService.ToExcelColumn(length - 1)
-        const sid = get(i, 'sid')
-        fileColumns.push({ sid, col })
+        const length = sec.length;
+        const col = this.utilService.ToExcelColumn(length - 1);
+        const sid = get(i, 'sid');
+        fileColumns.push({ sid, col });
       }
     }
     // 填充分数列
-    sec.push('分数')
+    sec.push('分数');
     const workbook = new Excel.Workbook();
     const sheet = workbook.addWorksheet('sheet1');
-    sheet.addRow(fir)
+    sheet.addRow(fir);
     sheet.addRow(sec);
     // 整理数据
     for (let index = 0; index < data.length; index++) {
       const i = data[index];
       const item = [];
       // 项目编号
-      const no = get(i, 'no', "")
-      item.push(no)
+      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_name'))
-      else item.push("")
+      if (user) item.push(get(user, 'nick_name'));
+      else item.push('');
       // 报名时间
-      const time = get(i, 'time', "")
-      item.push(time)
+      const time = get(i, 'time', '');
+      item.push(time);
       // 处理报名信息
-      const info = get(i, 'info', [])
+      const info = get(i, 'info', []);
       for (const is of info) {
-        const type = get(is, 'type')
-        const val = get(is, 'reply', '')
+        const type = get(is, 'type');
+        const val = get(is, 'reply', '');
         // 0:单选;2:下拉;3:单行文本;4:多行文本
         if (type === '0' || type === '2' || type === '3' || type === '4') {
-          item.push(val)
+          item.push(val);
         } else if (type === '1') {
           // 1:多选
-          item.push(val.join(';'))
+          item.push(val.join(';'));
         } else if (type === '5' || type === '7') {
           // 5:图片/文件;7:附件模板
           // 1.需要确定单元格位置,生成超链接格式,1个单元格只能有一个超链接
-          const sid = get(is, 'sid')
-          const headFile = head(val)
+          const sid = get(is, 'sid');
+          const headFile = head(val);
           const link = {
             text: get(headFile, 'name'),
             hyperlink: get(headFile, 'uri'),
             toolTip: get(headFile, 'uri'),
-          }
-          const posObj = fileColumns.find(f => f.sid === sid)
+          };
+          const posObj = fileColumns.find(f => f.sid === sid);
           if (!posObj) continue;
           posObj.value = link;
           posObj.line = index + 1 + 2; // +1 是索引加1为行数; +2 是表格从第三行开始的
@@ -258,35 +254,33 @@ export class MatchRegistrationController implements BaseController {
           //     tooltip: uri
           //   }
           // }
-
-
         } else if (type === '6') {
           // 6:数组,将sid外的 key,value拼成字符串作为内容
           if (!isArray(val)) continue;
-          const midArr = []
+          const midArr = [];
           for (const valI of val) {
-            const obj = omit(valI, ['sid'])
+            const obj = omit(valI, ['sid']);
             for (const key in obj) {
-              midArr.push(`${key}: ${obj[key]}`)
+              midArr.push(`${key}: ${obj[key]}`);
             }
           }
           // 将键值对拼成字符串
-          item.push(midArr.join(';'))
+          item.push(midArr.join(';'));
         }
       }
-      sheet.addRow(item)
+      sheet.addRow(item);
     }
     // 处理超链接
     for (const i of fileColumns) {
-      const col = get(i, 'col')
-      const line = get(i, 'line')
-      const pos = `${col}${line}`
-      const value = get(i, 'value')
+      const col = get(i, 'col');
+      const line = get(i, 'line');
+      const pos = `${col}${line}`;
+      const value = get(i, 'value');
       if (!value) continue;
-      sheet.getCell(pos).value = value
+      sheet.getCell(pos).value = value;
     }
     const nowDate = new Date().getTime();
-    const filename = `${match_name}初赛名单-${nowDate}.xlsx`
+    const filename = `${match_name}初赛名单-${nowDate}.xlsx`;
     const path = this.path;
     if (!path) {
       throw new ServiceError('服务端没有设置存储路径');