|
@@ -2,7 +2,7 @@ import { Provide } from '@midwayjs/core';
|
|
|
import { InjectDataSource, InjectEntityModel } from '@midwayjs/typeorm';
|
|
|
import { DataSource, In, Repository } from 'typeorm';
|
|
|
import { Menus } from '../../entity/system/menus.entity';
|
|
|
-import { get, isNull, isUndefined, omit } from 'lodash';
|
|
|
+import { cloneDeep, get, isNull, isNumber, isObject, isUndefined, omit } from 'lodash';
|
|
|
import { User } from '../../entity/system/user.entity';
|
|
|
import { Admin } from '../../entity/system/admin.entity';
|
|
|
import { Achievement } from '../../entity/platform/achievement.entity';
|
|
@@ -19,6 +19,8 @@ import { Supply } from '../../entity/platform/supply.entity';
|
|
|
import { Support } from '../../entity/platform/support.entity';
|
|
|
import { UserMenus } from '../../entity/system/userMenus.entity';
|
|
|
import { Role } from '../../entity/system/role.entity';
|
|
|
+import { Expert } from '../../entity/users/expert.entity';
|
|
|
+import { Company } from '../../entity/users/company.entity';
|
|
|
|
|
|
@Provide()
|
|
|
export class DataDealService {
|
|
@@ -55,12 +57,70 @@ export class DataDealService {
|
|
|
|
|
|
@InjectEntityModel(UserMenus)
|
|
|
UserMenus: Repository<UserMenus>;
|
|
|
-
|
|
|
+ @InjectEntityModel(Expert)
|
|
|
+ Expert: Repository<Expert>;
|
|
|
+ @InjectEntityModel(Company)
|
|
|
+ Company: Repository<Company>;
|
|
|
@InjectEntityModel(Role)
|
|
|
Role: Repository<Role>;
|
|
|
|
|
|
@InjectDataSource('default')
|
|
|
defaultDataSource: DataSource;
|
|
|
+
|
|
|
+ async correctImportData() {
|
|
|
+ const config = [
|
|
|
+ { model: this.Demand, entity: Demand, fields: ['field', 'company', 'brief', 'contacts', 'year', 'industry', 'company', 'tec_name', 'company_brief', 'question', 'month', 'tel'] },
|
|
|
+ { model: this.Achievement, entity: Achievement, fields: ['field', 'name', 'brief', 'source', 'person', 'tel'] },
|
|
|
+ { model: this.Expert, entity: Expert, fields: ['industry_type', 'industry', 'work_type', 'name', 'work', 'title'] },
|
|
|
+ { model: this.Company, entity: Company, fields: ['name', 'products', 'type', 'person'] },
|
|
|
+ { model: this.Supply, entity: Supply, fields: ['industry', 'field', 'name', 'brief', 'source'] },
|
|
|
+ { model: this.Project, entity: Project, fields: ['name', 'brief', 'main', 'progress', 'track_unit', 'source'] },
|
|
|
+ { model: this.Match, entity: Match, fields: ['name', 'address'] },
|
|
|
+ ];
|
|
|
+ const limit = 50;
|
|
|
+ for (const c of config) {
|
|
|
+ const { model, fields, entity } = c;
|
|
|
+ let skip = 0;
|
|
|
+ let isEmpty = false;
|
|
|
+ while (!isEmpty) {
|
|
|
+ const list = await model.find({ skip, take: limit });
|
|
|
+ if (list.length <= 0) {
|
|
|
+ isEmpty = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ for (const i of list) {
|
|
|
+ let needUpdate = false;
|
|
|
+ const updateObj = {};
|
|
|
+ for (const f of fields) {
|
|
|
+ const fd = get(i, f);
|
|
|
+ if (!fd) continue;
|
|
|
+ try {
|
|
|
+ if (isNumber(fd)) {
|
|
|
+ continue;
|
|
|
+ } else if (fd.includes('richText')) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ const obj = JSON.parse(fd);
|
|
|
+ const str = obj.richText.reduce((p, n) => `${p}${n.text}`, '');
|
|
|
+ updateObj[f] = str;
|
|
|
+ needUpdate = true;
|
|
|
+ } catch (error) {
|
|
|
+ console.log('update field check', model.metadata.name, `id:${i.id}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (needUpdate) {
|
|
|
+ await model.createQueryBuilder().update(entity).set(updateObj).where('id =:id', { id: i.id }).execute();
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log('field data check', model.metadata.name, `id:${i.id}`, f);
|
|
|
+ console.log(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ skip = skip + limit;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
async initUserMenus() {
|