|
@@ -3,7 +3,7 @@ import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
|
import { Repository, Equal } from 'typeorm';
|
|
|
import { Incubator } from '../../entity/users/incubator.entity';
|
|
|
import { BaseServiceV2 } from '../../frame/BaseServiceV2';
|
|
|
-import { get } from 'lodash';
|
|
|
+import { get, uniq } from 'lodash';
|
|
|
import { Cirelation } from '../../entity/users/cirelation.entity';
|
|
|
import { CompanyService } from './company.service';
|
|
|
import { CompanyYear } from '../../entity/users/companyYear.entity';
|
|
@@ -109,29 +109,16 @@ export class IncubatorService extends BaseServiceV2 {
|
|
|
async field(query) {
|
|
|
const { incubator, status } = query;
|
|
|
const builder = await this.cModel.createQueryBuilder('cirelation').select(['cirelation.company']).setFindOptions({ where: { incubator, status } });
|
|
|
- const data = await builder.getMany();
|
|
|
- let list = [];
|
|
|
- const companyList = [];
|
|
|
- const nameList = ['生物医药', '化工新材料', '先进装备制造', '高端服务', '光电子', '电子信息'];
|
|
|
- for (const val of data) {
|
|
|
- const company = await this.companyService.fetch({ id: get(val, 'company') });
|
|
|
- if (get(company, 'industry')) {
|
|
|
- const info = { value: 0, name: get(company, 'industry') };
|
|
|
- for (const tags of nameList) {
|
|
|
- if (get(company, 'industry') === tags) info.value = info.value + 1;
|
|
|
- }
|
|
|
- companyList.push(info);
|
|
|
- }
|
|
|
+ const res = await builder.getMany();
|
|
|
+ const companyids = res.map(i => i.company);
|
|
|
+ const list = [];
|
|
|
+ const { data } = await this.companyService.query({ id: companyids }, {});
|
|
|
+ const nameList = uniq(data.map(i => i.industry));
|
|
|
+ for (const val of nameList) {
|
|
|
+ const { total } = await this.companyService.query({ id: companyids, industry: val }, { skip: 0, limit: 1 });
|
|
|
+ const info = { value: total, name: val };
|
|
|
+ list.push(info);
|
|
|
}
|
|
|
- list = companyList.reduce((accumulator, currentItem) => {
|
|
|
- const existingItem = accumulator.find(item => item.name === currentItem.name);
|
|
|
- if (existingItem) {
|
|
|
- existingItem.value += currentItem.value;
|
|
|
- } else {
|
|
|
- accumulator.push({ ...currentItem });
|
|
|
- }
|
|
|
- return accumulator;
|
|
|
- }, []);
|
|
|
return { nameList, list };
|
|
|
}
|
|
|
|