Ver código fonte

修改查询

lrf 9 meses atrás
pai
commit
4b9e078293
2 arquivos alterados com 17 adições e 24 exclusões
  1. 10 23
      src/service/users/incubator.service.ts
  2. 7 1
      src/service/util.service.ts

+ 10 - 23
src/service/users/incubator.service.ts

@@ -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 };
   }
 

+ 7 - 1
src/service/util.service.ts

@@ -274,7 +274,13 @@ export class UtilService {
         try {
           i.id = data.id;
           const userInfo = await this.userModel.findOne({ where: { account: Equal(name), nick_name: Equal(name) } });
-          await this.companyModel.update({ id: data.id }, { ...i, user: userInfo.id, status: '1' });
+          if (userInfo && userInfo.id) {
+            await this.companyModel.update({ id: data.id }, { ...i, user: userInfo.id, status: '1' });
+          } else {
+            const userInfo = await this.userModel.insert({ account: name, nick_name: name, password: '123456', industry: [industry], gender: '0', role: ['User', 'Company'], status: '1' });
+            const id = get(userInfo, 'identifiers.0.id');
+            await this.companyModel.update({ id: data.id }, { ...i, user: id, status: '1' });
+          }
         } catch (error) {
           errorList.push(`修改第${index + 1}条${name}出现错误!!!`);
         }