Jelajahi Sumber

,导入项目库

zs 8 bulan lalu
induk
melakukan
1cbc02247b

+ 1 - 0
src/controller/platform/match.controller.ts

@@ -53,6 +53,7 @@ export class MatchController implements BaseController {
   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);
+    await this.service.updateProject({ id }, data);
     return result;
   }
 

+ 20 - 1
src/service/platform/match.service.ts

@@ -1,16 +1,35 @@
 import { Match } from '../../entity/platform/match.entity';
-import { Provide } from '@midwayjs/core';
+import { Provide, Inject } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
+import { ProjectService } from './project.service';
+import dayjs = require('dayjs');
 @Provide()
 export class MatchService extends BaseServiceV2 {
   @InjectEntityModel(Match)
   model: Repository<Match>;
+
+  @Inject()
+  projectService: ProjectService;
   getQueryColumnsOpera() {
     const obj = {
       tags: this.Opera.Json,
     };
     return obj;
   }
+  // 赛事完成后,导入项目库,贴 赛事 标签,支持筛选
+  async updateProject({ id }, data) {
+    const builder = this.model.createQueryBuilder();
+    this.completeBuilderCondition({ id });
+    const match = await builder.getOne();
+    if (match && match.match_status === '2') {
+      const result = await this.projectService.query({ user: match.user, name: match.name });
+      if (result && result.total > 0) {
+        await this.projectService.update({ id: result.data[0].id }, { user: match.user, name: match.name, industry: match.industry, tags: ['赛事'], time: dayjs().format('YYYY-MM-DD'), source: '赛事', status: '1' });
+      } else {
+        await this.projectService.create({ user: match.user, name: match.name, industry: match.industry, tags: ['赛事'], time: dayjs().format('YYYY-MM-DD'), source: '赛事', status: '1' });
+      }
+    }
+  }
 }