lrf 10 months ago
parent
commit
26b9ae4395

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

@@ -52,7 +52,7 @@ export default {
         port: 54321,
         entities: ['./entity'],
         type: 'postgres',
-        synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
+        synchronize: true, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据
         logging: true,
       },
       logs: {

+ 2 - 0
src/controller/home.controller.ts

@@ -13,7 +13,9 @@ export class HomeController {
   regionService: InitRegionService;
   @Get('/')
   async home(): Promise<any> {
+    await this.oneService.addTags();
     await this.oneService.addImportDataTags();
+    await this.twoService.addTags();
     await this.twoService.addImportDataTags();
     return 'ok';
     // return 'starting...';

+ 2 - 2
src/controller/platform/tags.controller.ts

@@ -1,11 +1,11 @@
 import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayjs/core';
-import { TagsService } from '../../service/platform/tags.service';
+import { TagsService } from '../../service/system/tags.service';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
 import { omit, pick } from 'lodash';
 import { BaseController } from '../../frame/BaseController';
 import { ServiceError, ErrorCode } from '../../error/service.error';
-import { QVO_tags, FVO_tags, CVO_tags, UVAO_tags } from '../../interface/platform/tags.interface';
+import { QVO_tags, FVO_tags, CVO_tags, UVAO_tags } from '../../interface/system/tags.interface';
 const namePrefix = '标签';
 
 @ApiTags(['标签'])

+ 0 - 8
src/entity/platform/tags.entity.ts

@@ -5,14 +5,6 @@ import { BaseModel } from '../../frame/BaseModel';
 export class Tags extends BaseModel {
   @Column({ type: 'character varying', nullable: true, comment: '标题' })
   title: string;
-  @Column({ type: 'character varying', nullable: true, comment: '类型', default: '1' })
-  type: string;
-  @Column({ type: 'character varying', nullable: true, comment: '路由' })
-  href: string;
-  @Column({ type: 'character varying', nullable: true, comment: '英文标题' })
-  English: string;
-  @Column({ type: 'jsonb', nullable: true, comment: '子目录' })
-  children: Array<any>;
   @Column({ type: 'integer', nullable: true, comment: '排序' })
   sort: number;
   @Column({ type: 'character varying', nullable: true, comment: '备注' })

+ 1 - 1
src/frame/BaseService.ts

@@ -6,7 +6,7 @@ import { App, Inject } from '@midwayjs/core';
 import { Opera } from './dbOpera';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { OperaService } from '../service/log/opera.service';
-import { Tags } from '../entity/platform/tags.entity';
+import { Tags } from '../entity/system/tags.entity';
 
 export interface QueryOpera {
   column: string;

+ 0 - 22
src/interface/platform/tags.interface.ts

@@ -10,16 +10,8 @@ export class FVO_tags {
   id: number = undefined;
   @ApiProperty({ description: '标题' })
   'title': string = undefined;
-  @ApiProperty({ description: '类型' })
-  'type': string = undefined;
-  @ApiProperty({ description: '路由' })
-  'href': string = undefined;
   @ApiProperty({ description: '排序' })
   'sort': number = undefined;
-  @ApiProperty({ description: '英文标题' })
-  'English': string = undefined;
-  @ApiProperty({ description: '子目录' })
-  'children': Array<any> = undefined;
   @ApiProperty({ description: '备注' })
   'remark': string = undefined;
   @ApiProperty({ description: '是否使用' })
@@ -29,8 +21,6 @@ export class FVO_tags {
 export class QDTO_tags extends SearchBase {
   @ApiProperty({ description: '标题' })
   'title': string = undefined;
-  @ApiProperty({ description: '类型' })
-  'type': string = undefined;
   @ApiProperty({ description: '是否使用' })
   'is_use': string = undefined;
 }
@@ -46,21 +36,9 @@ export class CDTO_tags {
   @ApiProperty({ description: '标题' })
   @Rule(RuleType['string']().empty(''))
   'title': string = undefined;
-  @ApiProperty({ description: '类型' })
-  @Rule(RuleType['string']().empty(''))
-  'type': string = undefined;
-  @ApiProperty({ description: '路由' })
-  @Rule(RuleType['string']().empty(''))
-  'href': string = undefined;
-  @ApiProperty({ description: '英文标题' })
-  @Rule(RuleType['string']().empty(''))
-  'English': string = undefined;
   @ApiProperty({ description: '排序' })
   @Rule(RuleType['number']().empty(''))
   'sort': number = undefined;
-  @ApiProperty({ description: '子目录' })
-  @Rule(RuleType['array']().empty(''))
-  'children': Array<any> = undefined;
   @ApiProperty({ description: '备注' })
   @Rule(RuleType['string']().empty(''))
   'remark': string = undefined;

+ 14 - 3
src/service/initData/initOne.service.ts

@@ -7,11 +7,14 @@ import { Demand } from '../../entity/platform/demand.entity';
 import { Expert } from '../../entity/users/expert.entity';
 import * as Excel from 'exceljs';
 import * as path from 'path';
+import { Tags } from '../../entity/system/tags.entity';
 // 2024-06-11 导入
 @Provide()
 export class initOneService {
   // 本次导入公共标签
-  tags = ['240611'];
+  tags = ['20240611'];
+  @InjectEntityModel(Tags)
+  tagsModel: Repository<Tags>;
   @InjectEntityModel(Demand)
   demandModel: Repository<Demand>;
   @InjectEntityModel(Achievement)
@@ -24,6 +27,15 @@ export class initOneService {
     // await this.importAchieveFromExcel();
     // await this.importExpertFromExcel();
   }
+  async addTags() {
+    const list = [{ title: '20240611' }, { title: '成果' }, { title: '专家' }, { title: '需求' }];
+    for (const i of list) {
+      const num = await this.tagsModel.createQueryBuilder().where('title = :title', { title: i.title }).getCount();
+      if (num <= 0) {
+        await this.tagsModel.insert(i);
+      }
+    }
+  }
 
   async addImportDataTags() {
     // 查询achievementModel和expertModel的所有数据,并为其添加标签
@@ -33,8 +45,7 @@ export class initOneService {
     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);
+    await this.demandModel.createQueryBuilder().update().set({ tags: demandTags }).where('created_time BETWEEN :start AND :end', { start: '2024-06-10', end: '2024-06-12' }).execute();
   }
   async importRequirementFromExcel() {
     const p = path.resolve(__dirname, '../../../importData/20240611', '需求库.xlsx');

+ 13 - 2
src/service/initData/initTwo.service.ts

@@ -11,10 +11,13 @@ import { differenceWith, get, isEqual, isObject, isString, last, take, trim } fr
 import { Demand } from '../../entity/platform/demand.entity';
 import _ = require('lodash');
 import { Project } from '../../entity/platform/project.entity';
+import { Tags } from '../../entity/system/tags.entity';
 // 2024-06-24 导入
 @Provide()
 export class initTwoService {
   tags = ['20240624'];
+  @InjectEntityModel(Tags)
+  tagsModel: Repository<Tags>;
   @InjectEntityModel(Region)
   regionModel: Repository<Region>;
   @InjectEntityModel(Company)
@@ -34,6 +37,15 @@ export class initTwoService {
     // return await this.importDemand();
     // return await this.importProject();
   }
+  async addTags() {
+    const list = [{ title: '20240624' }, { title: '企业' }, { title: '供给' }, { title: '项目' }, { title: '需求' }];
+    for (const i of list) {
+      const num = await this.tagsModel.createQueryBuilder().where('title = :title', { title: i.title }).getCount();
+      if (num <= 0) {
+        await this.tagsModel.insert(i);
+      }
+    }
+  }
 
   async addImportDataTags() {
     // company,supply,project 直接全表更新tags
@@ -45,8 +57,7 @@ export class initTwoService {
     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)
+    await this.demandModel.createQueryBuilder().update().set({ tags: demandTags }).where('created_time BETWEEN :start AND :end', { start: '2024-06-23', end: '2024-06-25' }).execute();
   }
 
   /**

+ 1 - 1
src/service/platform/tags.service.ts

@@ -1,7 +1,7 @@
 import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Repository } from 'typeorm';
-import { Tags } from '../../entity/platform/tags.entity';
+import { Tags } from '../../entity/system/tags.entity';
 import { BaseService } from '../../frame/BaseService';
 @Provide()
 export class TagsService extends BaseService<Tags> {