|
@@ -1,6 +1,6 @@
|
|
|
import { Inject, Provide } from '@midwayjs/core';
|
|
|
import * as fs from 'fs';
|
|
|
-import { get, isObject } from 'lodash';
|
|
|
+import { compact, get, isArray, isObject } from 'lodash';
|
|
|
import path = require('path');
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
|
@@ -10,6 +10,8 @@ import { Demand } from '../entity/platform/demand.entity';
|
|
|
import { Expert } from '../entity/users/expert.entity';
|
|
|
import { Company } from '../entity/users/company.entity';
|
|
|
import { Context } from '@midwayjs/koa';
|
|
|
+import * as Excel from 'exceljs';
|
|
|
+import { Achievement } from '../entity/platform/achievement.entity';
|
|
|
|
|
|
|
|
|
|
|
@@ -33,316 +35,226 @@ export class UtilService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @InjectEntityModel(Company)
|
|
|
- model: Repository<Company>;
|
|
|
+ @InjectEntityModel(Demand)
|
|
|
+ model: Repository<Demand>;
|
|
|
async initData() {
|
|
|
-
|
|
|
- const d: any = {
|
|
|
- user: 5,
|
|
|
- name: '长春市福瑞科技有限公司',
|
|
|
- logo: [
|
|
|
- {
|
|
|
- id: 'company',
|
|
|
- name: '2.jpg',
|
|
|
- uri: '/files/web/template/company.jpg',
|
|
|
- url: 'http://192.168.1.197/files/web/template/company.jpg',
|
|
|
- uid: 1712632020400,
|
|
|
- status: 'success',
|
|
|
- },
|
|
|
- ],
|
|
|
- code: '1234567890',
|
|
|
- pattern: '0',
|
|
|
- scale: '0',
|
|
|
- phone: '18843520013',
|
|
|
- type: '3',
|
|
|
- area: ['山西省', '阳泉市'],
|
|
|
- representative: '张三',
|
|
|
- email: 'email1233@.com',
|
|
|
- person: 100,
|
|
|
- register: '100',
|
|
|
- create_time: '2024-04-09',
|
|
|
- address: '吉林省长春市力旺广场',
|
|
|
- brief: '简介',
|
|
|
- is_show: '0',
|
|
|
- companyStatus: '0',
|
|
|
- status: '1',
|
|
|
- };
|
|
|
- await this.model.insert(d);
|
|
|
+ console.log('in initData');
|
|
|
+ return this.importRequirementFromExcel();
|
|
|
+ }
|
|
|
+ async importRequirementFromExcel() {
|
|
|
+ const path = 'E:/workspace/产学研用/项目数据资料/项目数据资料/需求库.xlsx';
|
|
|
+ const wb = new Excel.Workbook();
|
|
|
+ await wb.xlsx.readFile(path);
|
|
|
+ const sheet = wb.getWorksheet(1);
|
|
|
+ const meta = this.requirementMeta();
|
|
|
+ const allData = [];
|
|
|
+ const cityArr = ['长春', '吉林', '通化', '白山', '辽源', '四平', '白城', '松原', '延边州', '延边'];
|
|
|
+ const areaArr = [
|
|
|
+ '五棵树经济开发区',
|
|
|
+ '南关区',
|
|
|
+ '宽城区',
|
|
|
+ '朝阳区',
|
|
|
+ '二道区',
|
|
|
+ '绿园区',
|
|
|
+ '双阳区',
|
|
|
+ '九台区',
|
|
|
+ '公主岭市',
|
|
|
+ '榆树市',
|
|
|
+ '德惠市',
|
|
|
+ '农安县',
|
|
|
+ '昌邑区',
|
|
|
+ '龙潭区',
|
|
|
+ '船营区',
|
|
|
+ '丰满区',
|
|
|
+ '蛟河市',
|
|
|
+ '桦甸市',
|
|
|
+ '舒兰市',
|
|
|
+ '磐石市',
|
|
|
+ '永吉县',
|
|
|
+ '东昌区',
|
|
|
+ '二道江区',
|
|
|
+ '集安市',
|
|
|
+ '梅河口市',
|
|
|
+ '通化县',
|
|
|
+ '辉南县',
|
|
|
+ '柳河县',
|
|
|
+ '浑江区',
|
|
|
+ '江源区',
|
|
|
+ '临江市',
|
|
|
+ '抚松县',
|
|
|
+ '靖宇县',
|
|
|
+ '长白朝鲜族自治县',
|
|
|
+ '龙山区',
|
|
|
+ '西安区',
|
|
|
+ '东丰县',
|
|
|
+ '东辽县',
|
|
|
+ '铁西区',
|
|
|
+ '铁东区',
|
|
|
+ '双辽市',
|
|
|
+ '梨树县',
|
|
|
+ '伊通满族自治县',
|
|
|
+ '洮北区',
|
|
|
+ '洮南市',
|
|
|
+ '大安市',
|
|
|
+ '镇赉县',
|
|
|
+ '通榆县',
|
|
|
+ '宁江区',
|
|
|
+ '扶余市',
|
|
|
+ '长岭县',
|
|
|
+ '乾安县',
|
|
|
+ '前郭尔罗斯蒙古族自治县',
|
|
|
+ '延吉市',
|
|
|
+ '图们市',
|
|
|
+ '敦化市',
|
|
|
+ '珲春市',
|
|
|
+ '龙井市',
|
|
|
+ '和龙市',
|
|
|
+ '汪清县',
|
|
|
+ '安图县',
|
|
|
+ ];
|
|
|
+ const specialList = [
|
|
|
+ { e: '高新区', to: '高新技术产业开发区' },
|
|
|
+ { e: '高新', to: '高新技术产业开发区' },
|
|
|
+ { e: '经开', to: '经济技术开发区' },
|
|
|
+ { e: '五棵树', to: '五棵树经济开发区' },
|
|
|
+ { e: '北湖', to: '北湖科技开发区' },
|
|
|
+ { e: '净月', to: '净月高新技术产业开发区' },
|
|
|
+ { e: '绿园经济', to: '绿园经济开发区' },
|
|
|
+ ];
|
|
|
+ const ignoreArea = ['吉林', '长春', '白城'];
|
|
|
+ const specialAreaList = [
|
|
|
+ { e: '梅河口', to: ['吉林省', '通化市', '梅河口市'] },
|
|
|
+ { e: '德惠', to: ['吉林省', '长春市', '德惠市'] },
|
|
|
+ { e: '敦化', to: ['吉林省', '延边州', '敦化市'] },
|
|
|
+ { e: '延吉', to: ['吉林省', '延边州', '延吉市'] },
|
|
|
+ { e: '柳河', to: ['吉林省', '通化市', '柳河县'] },
|
|
|
+ ];
|
|
|
+ sheet.eachRow((row, ri) => {
|
|
|
+ if (ri === 1 || ri === 2) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ const obj = {};
|
|
|
+ row.eachCell((cell, ci) => {
|
|
|
+ const val = cell.value as string;
|
|
|
+ const key = meta[ci];
|
|
|
+ if (ci === 3) {
|
|
|
+ let area = ['吉林省'];
|
|
|
+
|
|
|
+ const res = cityArr.find(f => val.includes(f));
|
|
|
+ if (res) {
|
|
|
+
|
|
|
+ if (res === '延边') area.push('延边州');
|
|
|
+ else if (res !== '延边州') area.push(`${res}市`);
|
|
|
+ else area.push(res);
|
|
|
+ const elseStr = val.replace(res, '');
|
|
|
+ if (elseStr !== '' && !ignoreArea.includes(elseStr)) {
|
|
|
+ const areaVal = areaArr.find(f => f.includes(elseStr));
|
|
|
+ if (areaVal) area.push(areaVal);
|
|
|
+ else {
|
|
|
+ const rs = specialList.find(f => elseStr.includes(f.e));
|
|
|
+ if (rs) area.push(rs.to);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const res = specialAreaList.find(f => val.includes(f.e));
|
|
|
+ if (res) area = res.to;
|
|
|
+ else obj['no_area'] = true;
|
|
|
+ }
|
|
|
+ obj[key] = area;
|
|
|
+ } else if (ci === 6) {
|
|
|
+
|
|
|
+ const strReg = /([\u4e00-\u9fa5]{3}|[\u4e00-\u9fa5]{2})/g;
|
|
|
+ const strRes = val.match(strReg);
|
|
|
+ const numRes = val.replace(strReg, '').replace('\n', '');
|
|
|
+ if (isArray(strRes)) obj['contacts'] = strRes.join(';');
|
|
|
+ if (isArray(numRes)) obj['tel'] = numRes.join(';');
|
|
|
+ if (numRes) obj['tel'] = numRes;
|
|
|
+ } else if (key) obj[key] = val;
|
|
|
+ });
|
|
|
+ allData.push(obj);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const res = await this.model.insert(allData);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ requirementMeta() {
|
|
|
+ return {
|
|
|
+ 2: 'field',
|
|
|
+ 3: 'area',
|
|
|
+ 4: 'company',
|
|
|
+ 5: 'brief',
|
|
|
+ 6: 'contacts',
|
|
|
+ 7: 'year',
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ async importAchieveFromExcel() {
|
|
|
+ const path = 'E:/workspace/产学研用/项目数据资料/项目数据资料/成果库.xlsx';
|
|
|
+ const wb = new Excel.Workbook();
|
|
|
+ await wb.xlsx.readFile(path);
|
|
|
+ const sheet = wb.getWorksheet(1);
|
|
|
+ const meta = this.achieveMeta();
|
|
|
+ const allData = [];
|
|
|
+ sheet.eachRow((row, ri) => {
|
|
|
+ if (ri === 1 || ri === 2) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ const obj = {};
|
|
|
+ row.eachCell((cell, ci) => {
|
|
|
+ const val = cell.value;
|
|
|
+ const key = meta[ci];
|
|
|
+ if (key) obj[key] = val;
|
|
|
+ });
|
|
|
+ allData.push(obj);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return await this.model.insert(allData);
|
|
|
+ }
|
|
|
+ achieveMeta() {
|
|
|
+ return {
|
|
|
+ 2: 'field',
|
|
|
+ 3: 'name',
|
|
|
+ 4: 'brief',
|
|
|
+ 5: 'source',
|
|
|
+ 6: 'person',
|
|
|
+ 7: 'tel',
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ async importExportFromExcel() {
|
|
|
+ const path = 'E:/workspace/产学研用/项目数据资料/项目数据资料/专家库docx.xlsx';
|
|
|
+ const wb = new Excel.Workbook();
|
|
|
+ await wb.xlsx.readFile(path);
|
|
|
+ const sheet = wb.getWorksheet(1);
|
|
|
+ const rows = sheet.getRows(3, 200);
|
|
|
+ const meta = this.exportsMeta();
|
|
|
+ const allData = [];
|
|
|
+ for (const row of rows) {
|
|
|
+ const obj = {};
|
|
|
+ row.eachCell((cell, index) => {
|
|
|
+ let val = cell.value as string;
|
|
|
+ if (index === 4) {
|
|
|
+ const varr = val.split('').filter(f => f !== ' ');
|
|
|
+ val = varr.join('');
|
|
|
+ }
|
|
|
+ const key = meta[index];
|
|
|
+ obj[key] = val;
|
|
|
+ });
|
|
|
+ allData.push(obj);
|
|
|
+ }
|
|
|
+ const res = await this.model.insert(allData);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
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