ソースを参照

导入标签机0611导入数据

lrf 9 ヶ月 前
コミット
3c032c9024

BIN
importData/20240611/专家库.xlsx


BIN
importData/20240611/成果库.xlsx


BIN
importData/20240611/需求库.xlsx


+ 3 - 3
src/config/config.self.ts

@@ -1,6 +1,6 @@
 import { MidwayConfig } from '@midwayjs/core';
 /**数据库ip */
-const ip = 'localhost';
+const ip = 'localhost'; //localhost
 /**数据库名 */
 const dbName = 'cxyy';
 /**日志数据库名 */
@@ -52,8 +52,8 @@ export default {
         port: 54321,
         entities: ['./entity'],
         type: 'postgres',
-        synchronize: true, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
-        logging: false,
+        synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
+        logging: true,
       },
       logs: {
         database: logsDB,

+ 7 - 5
src/controller/home.controller.ts

@@ -1,19 +1,21 @@
 import { Controller, Get, Inject } from '@midwayjs/core';
 import { initTwoService } from '../service/initData/initTwo.service';
 import { InitRegionService } from '../service/initData/initRegion.service';
+import { initOneService } from '../service/initData/initOne.service';
 
 @Controller('/')
 export class HomeController {
   @Inject()
-  service: initTwoService;
+  twoService: initTwoService;
+  @Inject()
+  oneService: initOneService;
   @Inject()
   regionService: InitRegionService;
   @Get('/')
   async home(): Promise<any> {
-    // const result: any = await this.adminService.create();
-    const res = await this.service.initData();
-    // const res = await this.regionService.index();
-    return res;
+    await this.oneService.addImportDataTags();
+    await this.twoService.addImportDataTags();
+    return 'ok';
     // return 'starting...';
   }
   // @Get('/:method')

+ 1 - 1
src/entity/users/company.entity.ts

@@ -8,7 +8,7 @@ export class Company extends BaseModel {
   user: number;
   @Column({ type: 'character varying', nullable: true, comment: '所属产业' })
   industry: string;
-  @Column({ type: 'character varying', nullable: true, comment: '标签' })
+  @Column({ type: 'jsonb', nullable: true, comment: '标签' })
   tags: Array<any>;
   @Column({ type: 'character varying', nullable: true, comment: '企业名称' })
   name: string;

+ 1 - 1
src/entity/users/expert.entity.ts

@@ -7,7 +7,7 @@ import dayjs = require('dayjs');
 export class Expert extends BaseModel {
   @Column({ type: 'integer', nullable: true, comment: '平台用户id' })
   user: number;
-  @Column({ type: 'character varying', nullable: true, comment: '标签' })
+  @Column({ type: 'jsonb', nullable: true, comment: '标签' })
   tags: Array<any>;
   @Column({ type: 'character varying', nullable: true, comment: '专家姓名' })
   name: string;

+ 22 - 7
src/service/initData/initOne.service.ts

@@ -6,9 +6,12 @@ import { Achievement } from '../../entity/platform/achievement.entity';
 import { Demand } from '../../entity/platform/demand.entity';
 import { Expert } from '../../entity/users/expert.entity';
 import * as Excel from 'exceljs';
+import * as path from 'path';
 // 2024-06-11 导入
 @Provide()
 export class initOneService {
+  // 本次导入公共标签
+  tags = ['240611'];
   @InjectEntityModel(Demand)
   demandModel: Repository<Demand>;
   @InjectEntityModel(Achievement)
@@ -17,14 +20,26 @@ export class initOneService {
   expertModel: Repository<Expert>;
   async initData() {
     console.log('in initData');
-    await this.importRequirementFromExcel();
+    // await this.importRequirementFromExcel();
     // await this.importAchieveFromExcel();
     // await this.importExpertFromExcel();
   }
+
+  async addImportDataTags() {
+    // 查询achievementModel和expertModel的所有数据,并为其添加标签
+    const achieveTags: any = [...this.tags, '成果'];
+    const expertTags: any = [...this.tags, '专家'];
+    await this.achievementModel.update({}, { tags: achieveTags });
+    await this.expertModel.update({}, { tags: expertTags });
+    // 查询demandModel 2024-06-10 至 2024-06-12 (其实就是2024-06-11)的数据,添加标签,之后24号的数据在initTwo中添加
+    const demandTags: any = [...this.tags, '需求'];
+    const list = await this.demandModel.createQueryBuilder().update().set({ tags: demandTags }).where('created_time BETWEEN :start AND :end', { start: '2024-06-10', end: '2024-06-12' }).execute();
+    console.log(list);
+  }
   async importRequirementFromExcel() {
-    const path = 'C:/document/需求库.xlsx';
+    const p = path.resolve(__dirname, '../../../importData/20240611', '需求库.xlsx');
     const wb = new Excel.Workbook();
-    await wb.xlsx.readFile(path);
+    await wb.xlsx.readFile(p);
     const sheet = wb.getWorksheet(1);
     const meta = this.requirementMeta();
     const allData = [];
@@ -170,9 +185,9 @@ export class initOneService {
   }
 
   async importAchieveFromExcel() {
-    const path = 'C:/document/成果库.xlsx';
+    const p = path.resolve(__dirname, '../../../importData/20240611', '成果库.xlsx');
     const wb = new Excel.Workbook();
-    await wb.xlsx.readFile(path);
+    await wb.xlsx.readFile(p);
     const sheet = wb.getWorksheet(1);
     const meta = this.achieveMeta();
     const allData = [];
@@ -203,9 +218,9 @@ export class initOneService {
   }
 
   async importExpertFromExcel() {
-    const path = 'C:/document/专家库.xlsx';
+    const p = path.resolve(__dirname, '../../../importData/20240611', '专家库.xlsx');
     const wb = new Excel.Workbook();
-    await wb.xlsx.readFile(path);
+    await wb.xlsx.readFile(p);
     const sheet = wb.getWorksheet(1);
     const rows = sheet.getRows(3, 200);
     const meta = this.exportsMeta();

+ 17 - 1
src/service/initData/initTwo.service.ts

@@ -14,6 +14,7 @@ import { Project } from '../../entity/platform/project.entity';
 // 2024-06-24 导入
 @Provide()
 export class initTwoService {
+  tags = ['20240624'];
   @InjectEntityModel(Region)
   regionModel: Repository<Region>;
   @InjectEntityModel(Company)
@@ -31,8 +32,23 @@ export class initTwoService {
     // return await this.importCompany();
     // return await this.importSupply();
     // return await this.importDemand();
-    return await this.importProject();
+    // return await this.importProject();
   }
+
+  async addImportDataTags() {
+    // company,supply,project 直接全表更新tags
+    const ctags: any = [...this.tags, '企业'];
+    await this.companyModel.update({}, { tags: ctags });
+    const stags: any = [...this.tags, '供给'];
+    await this.supplyModel.update({}, { tags: stags });
+    const ptags: any = [...this.tags, '项目'];
+    await this.projectModel.update({}, { tags: ptags });
+    // demand 2024-06-23 至2024-06-25内的所有数据加标签
+    const demandTags: any = [...this.tags, '需求'];
+    const list = await this.demandModel.createQueryBuilder().update().set({ tags: demandTags }).where('created_time BETWEEN :start AND :end', { start: '2024-06-23', end: '2024-06-25' }).execute();
+    console.log(list)
+  }
+
   /**
    * 获取excel表头对应的字段
    * @returns 表格列对应字段对象