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");