From 4267adf8f5b424360c0fab3c2a400930b5145c73 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 24 Sep 2024 09:29:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=B9=E6=8D=AE=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=BD=8D=E7=BD=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.module.ts | 5 +++-- src/tdtmap/tdtmap.controller.ts | 33 +++++++++++++++++++++++++++++++++ src/tdtmap/tdtmap.module.ts | 5 +++++ src/tdtmap/tdtmap.service.ts | 16 +++++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index b93c708..23ae2e1 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -20,6 +20,7 @@ import { RolesGuard } from './common/role.guard'; import { UserModule } from './user/user.module'; import { User } from './user/entities/user.entity'; import { TdtmapModule } from './tdtmap/tdtmap.module'; +import { TdtLocal } from './tdtmap/entities/tdtmap.entity'; // 使用sqlite和程序内缓存时,全部程序不依赖外部组件 // 注意:Webpack打包不适用Sqlite! @@ -30,7 +31,7 @@ const enableSqlite:boolean = false enableSqlite ? TypeOrmModule.forRoot({ type: 'better-sqlite3', database: 'db.sql', - entities: [User], + entities: [User, TdtLocal], synchronize: !IS_PROD }) : TypeOrmModule.forRoot({ type: 'mysql', @@ -39,7 +40,7 @@ const enableSqlite:boolean = false username: MYSQL_USER, password: MYSQL_PASSWD, database: MYSQL_DATABASE, - entities: [User], + entities: [User, TdtLocal], synchronize: !IS_PROD }), CacheModule.register({ diff --git a/src/tdtmap/tdtmap.controller.ts b/src/tdtmap/tdtmap.controller.ts index 13fb33e..5f8c44f 100644 --- a/src/tdtmap/tdtmap.controller.ts +++ b/src/tdtmap/tdtmap.controller.ts @@ -42,6 +42,39 @@ export class TdtmapController { this.logger.debug(`bloomFilter inited => minio obj num: ${minioObjNamesArr.length}`) } + @Get("/search") + async search( + @Query('keyWord') keyWord:string, + @Query('tk') tk:string = '6988fa4ec7ca5ed400097b9bf9dfc22e' + ) { + const res = await axios({ + url: "https://api.tianditu.gov.cn/v2/search", + params: { + type: 'query', + postStr: JSON.stringify({ + yingjiType: 1, + sourceType: 0, + keyWord, + level: 18, + mapBound: '73.66, 3.86, 135.05, 53.55', + queryType: '4', + start: 0, + count: 10, + queryTerminal: 10000 + }), + tk + }, + method: "GET", + responseType: "arraybuffer" + }).catch((err) => { + this.logger.error(`Tile req Fail => ${err}`) + }) + + if (!res) return; + const { suggests } = JSON.parse(res.data); + return Array.isArray(suggests) ? suggests : []; + } + @Get("/tile") async getTile( @Res({ passthrough: true }) response:Response, diff --git a/src/tdtmap/tdtmap.module.ts b/src/tdtmap/tdtmap.module.ts index 3647d24..1150c2c 100644 --- a/src/tdtmap/tdtmap.module.ts +++ b/src/tdtmap/tdtmap.module.ts @@ -1,8 +1,13 @@ import { Module } from '@nestjs/common'; import { TdtmapService } from './tdtmap.service'; import { TdtmapController } from './tdtmap.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { TdtLocal } from './entities/tdtmap.entity'; @Module({ + imports: [ + TypeOrmModule.forFeature([TdtLocal]) + ], controllers: [TdtmapController], providers: [TdtmapService], }) diff --git a/src/tdtmap/tdtmap.service.ts b/src/tdtmap/tdtmap.service.ts index 19f8166..5fc049a 100644 --- a/src/tdtmap/tdtmap.service.ts +++ b/src/tdtmap/tdtmap.service.ts @@ -1,11 +1,17 @@ import { Injectable, Logger } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; import * as Minio from 'minio'; +import { TdtLocal } from './entities/tdtmap.entity'; +import { Repository } from 'typeorm'; @Injectable() export class TdtmapService { private readonly minioClient: Minio.Client; private readonly logger: Logger = new Logger(TdtmapService.name) - constructor() { + constructor( + @InjectRepository(TdtLocal) + private readonly tdtLocalRepository: Repository + ) { this.minioClient = new Minio.Client({ endPoint: '117.73.12.97', port: 9000, @@ -17,6 +23,14 @@ export class TdtmapService { setMinioObj() {} + getTdtLocalArr(keyword:string, pageSize:number, pageNum:number) { + // return this.tdtLocalRepository.find() + } + + setTdtLocal(tdtLocalEntitys:TdtLocal[]) { + return this.tdtLocalRepository.save(tdtLocalEntitys); + } + async getTilesNameList():Promise { return new Promise(async (resolve, reject) => { const stream = await this.minioClient.listObjectsV2("nestfiles");