import { Provide } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/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 = {
      id: this.Opera.In,
      name: this.Opera.Like,
      industry: this.Opera.In,
      pattern: this.Opera.In,
      tags: this.Opera.Json,
      area: this.Opera.Json,
    };
    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;
  }
}
