浏览代码

孵化器企业选择

zs 9 月之前
父节点
当前提交
c9a4ec6871

+ 13 - 1
src/controller/users/cirelation.controller.ts

@@ -28,6 +28,18 @@ export class cirelationController implements BaseController {
     return result;
   }
 
+  @Get('/list')
+  async list(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    const list = [];
+    for (const i of data) {
+      list.push(await this.service.fillName(i));
+    }
+    return { data: list, total };
+  }
+
   @Get('/:id')
   @ApiTags('单查询')
   @ApiResponse({ type: FVO_cirelation })
@@ -42,8 +54,8 @@ export class cirelationController implements BaseController {
   @Validate()
   @ApiResponse({ type: CVO_cirelation })
   async create(@Body() data: object) {
+    await this.service.createExamine(data);
     const dbData = await this.service.create(data);
-    this.serviceUtil.fillIdentity(data, 'cirelation');
     const result = new CVO_cirelation(dbData);
     return result;
   }

+ 12 - 0
src/controller/users/company.controller.ts

@@ -83,6 +83,18 @@ export class CompanyController implements BaseController {
     return { data, total };
   }
 
+  @Get('/contact')
+  @ApiTags('列表查询')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_company })
+  async contact(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const { data, total } = await this.service.query(qobj, others);
+    const list = await this.service.fillMatch(data);
+    return { data: list, total };
+  }
+
   @Get('/detail/:id')
   @ApiResponse({ type: FVO_company })
   async detail(@Param('id') id: string) {

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

@@ -12,6 +12,7 @@ export enum ErrorCode {
   USER_IS_DISABLED = 'USER_IS_DISABLED',
   ROLE_IS_DISABLED = 'ROLE_IS_DISABLED',
   SERVICE_REPEAT = 'SERVICE_REPEAT',
+  SERVICE_COPY = 'SERVICE_COPY',
   SERVICE_END = 'SERVICE_END',
   DUPLICATE_USERS_ACCOUNT = 'DUPLICATE_USERS_ACCOUNT',
   DUPLICATE_USERS_OPENID = 'DUPLICATE_USERS_OPENID',

+ 19 - 23
src/service/elasticsearch/es.service.ts

@@ -1,26 +1,22 @@
-import { Client } from "@elastic/elasticsearch";
-import { Config, Init, Provide } from "@midwayjs/core";
-
-
+// import { Client } from "@elastic/elasticsearch";
+import { Config, Init, Provide } from '@midwayjs/core';
 
 @Provide()
 export class ESService {
-  @Config('elasticsearch')
-  esConfig: object;
-  /**es连接实例 */
-  esClient: Client;
-  @Init()
-  async initClient() {
-    const esClient = new Client(this.esConfig);
-    this.esClient = esClient;
-  }
-  /**
-   * 1.索引(es中的表)建立:根据编写的文件生成
-   * 2.初始化数据,通过接口触发
-   * 3.对指定表进行的数据修改做同步
-   */
-
-  async initIndex() {
-    
-  }
-}
+  // @Config('elasticsearch')
+  // esConfig: object;
+  // /**es连接实例 */
+  // esClient: Client;
+  // @Init()
+  // async initClient() {
+  //   const esClient = new Client(this.esConfig);
+  //   this.esClient = esClient;
+  // }
+  // /**
+  //  * 1.索引(es中的表)建立:根据编写的文件生成
+  //  * 2.初始化数据,通过接口触发
+  //  * 3.对指定表进行的数据修改做同步
+  //  */
+  // async initIndex() {
+  // }
+}

+ 0 - 9
src/service/elasticsearch/indices.js

@@ -1,9 +0,0 @@
-export const indices = {
-  achievement: {},
-  demand: {},
-  footplate: {},
-  match: {},
-  project: {},
-  supply: {},
-  support: {},
-};

+ 35 - 2
src/service/users/cirelation.service.ts

@@ -1,8 +1,12 @@
-import { Provide } from '@midwayjs/core';
+import { Provide, Inject } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Repository } from 'typeorm';
+import { Repository, Equal } from 'typeorm';
 import { Cirelation } from '../../entity/users/cirelation.entity';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
+import { CompanyService } from './company.service';
+import { IncubatorService } from './incubator.service';
+import { ErrorCode, ServiceError } from '../../error/service.error';
+import { get } from 'lodash';
 @Provide()
 export class CirelationService extends BaseServiceV2 {
   getQueryColumnsOpera(): object {
@@ -10,4 +14,33 @@ export class CirelationService extends BaseServiceV2 {
   }
   @InjectEntityModel(Cirelation)
   model: Repository<Cirelation>;
+
+  @Inject()
+  companyService: CompanyService;
+
+  @Inject()
+  incubatorService: IncubatorService;
+
+  // 添加企业检查
+  async createExamine(data) {
+    const { company, incubator } = data;
+    const result = await this.model.findOne({ where: { company: Equal(company), incubator: Equal(incubator) } });
+    if (result) throw new ServiceError(ErrorCode.SERVICE_COPY);
+  }
+
+  /**
+   * 填充赛事信息
+   * @param {object} data 数据
+   */
+  async fillName(data) {
+    const { company, incubator } = data;
+    // 企业名称
+    const companyInfo = await this.companyService.fetch({ id: company });
+    if (companyInfo) data = { ...data, company_name: get(companyInfo, 'name') };
+    // 孵化器名称
+    const incubatorInfo = await this.incubatorService.fetch({ id: incubator });
+    if (incubatorInfo) data = { ...data, incubator_name: get(incubatorInfo, 'name') };
+
+    return data;
+  }
 }

+ 21 - 1
src/service/users/company.service.ts

@@ -1,13 +1,18 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
-import { Repository } from 'typeorm';
+import { Equal, Repository } from 'typeorm';
 import { Company } from '../../entity/users/company.entity';
 import { BaseServiceV2 } from '../../frame/BaseServiceV2';
+import { get } from 'lodash';
+import { MatchPath } from '../../entity/platform/matchPath.entity';
 @Provide()
 export class CompanyService extends BaseServiceV2 {
   @InjectEntityModel(Company)
   model: Repository<Company>;
 
+  @InjectEntityModel(MatchPath)
+  matchModel: Repository<MatchPath>;
+
   getQueryColumnsOpera() {
     const obj = {
       name: this.Opera.Like,
@@ -18,4 +23,19 @@ export class CompanyService extends BaseServiceV2 {
     };
     return obj;
   }
+
+  /**
+   * 查询企业是否已经与孵化器有关连信息
+   * @param {Array} data 数据
+   */
+  async fillMatch(data) {
+    let list;
+    for (const val of data) {
+      const match = get(data, 'id');
+      if (!match) return;
+      const matchInfo = await this.matchModel.findOne({ where: { match: Equal(match) } });
+      if (!matchInfo) list.push(val);
+    }
+    return list;
+  }
 }