feat: 根据名称搜索位置接口

This commit is contained in:
Tony 2024-09-24 09:29:07 +08:00
parent dd3423bfd3
commit 4267adf8f5
4 changed files with 56 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import { RolesGuard } from './common/role.guard';
import { UserModule } from './user/user.module'; import { UserModule } from './user/user.module';
import { User } from './user/entities/user.entity'; import { User } from './user/entities/user.entity';
import { TdtmapModule } from './tdtmap/tdtmap.module'; import { TdtmapModule } from './tdtmap/tdtmap.module';
import { TdtLocal } from './tdtmap/entities/tdtmap.entity';
// 使用sqlite和程序内缓存时全部程序不依赖外部组件 // 使用sqlite和程序内缓存时全部程序不依赖外部组件
// 注意Webpack打包不适用Sqlite! // 注意Webpack打包不适用Sqlite!
@ -30,7 +31,7 @@ const enableSqlite:boolean = false
enableSqlite ? TypeOrmModule.forRoot({ enableSqlite ? TypeOrmModule.forRoot({
type: 'better-sqlite3', type: 'better-sqlite3',
database: 'db.sql', database: 'db.sql',
entities: [User], entities: [User, TdtLocal],
synchronize: !IS_PROD synchronize: !IS_PROD
}) : TypeOrmModule.forRoot({ }) : TypeOrmModule.forRoot({
type: 'mysql', type: 'mysql',
@ -39,7 +40,7 @@ const enableSqlite:boolean = false
username: MYSQL_USER, username: MYSQL_USER,
password: MYSQL_PASSWD, password: MYSQL_PASSWD,
database: MYSQL_DATABASE, database: MYSQL_DATABASE,
entities: [User], entities: [User, TdtLocal],
synchronize: !IS_PROD synchronize: !IS_PROD
}), }),
CacheModule.register({ CacheModule.register({

View File

@ -42,6 +42,39 @@ export class TdtmapController {
this.logger.debug(`bloomFilter inited => minio obj num: ${minioObjNamesArr.length}`) 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") @Get("/tile")
async getTile( async getTile(
@Res({ passthrough: true }) response:Response, @Res({ passthrough: true }) response:Response,

View File

@ -1,8 +1,13 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { TdtmapService } from './tdtmap.service'; import { TdtmapService } from './tdtmap.service';
import { TdtmapController } from './tdtmap.controller'; import { TdtmapController } from './tdtmap.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TdtLocal } from './entities/tdtmap.entity';
@Module({ @Module({
imports: [
TypeOrmModule.forFeature([TdtLocal])
],
controllers: [TdtmapController], controllers: [TdtmapController],
providers: [TdtmapService], providers: [TdtmapService],
}) })

View File

@ -1,11 +1,17 @@
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import * as Minio from 'minio'; import * as Minio from 'minio';
import { TdtLocal } from './entities/tdtmap.entity';
import { Repository } from 'typeorm';
@Injectable() @Injectable()
export class TdtmapService { export class TdtmapService {
private readonly minioClient: Minio.Client; private readonly minioClient: Minio.Client;
private readonly logger: Logger = new Logger(TdtmapService.name) private readonly logger: Logger = new Logger(TdtmapService.name)
constructor() { constructor(
@InjectRepository(TdtLocal)
private readonly tdtLocalRepository: Repository<TdtLocal>
) {
this.minioClient = new Minio.Client({ this.minioClient = new Minio.Client({
endPoint: '117.73.12.97', endPoint: '117.73.12.97',
port: 9000, port: 9000,
@ -17,6 +23,14 @@ export class TdtmapService {
setMinioObj() {} setMinioObj() {}
getTdtLocalArr(keyword:string, pageSize:number, pageNum:number) {
// return this.tdtLocalRepository.find()
}
setTdtLocal(tdtLocalEntitys:TdtLocal[]) {
return this.tdtLocalRepository.save(tdtLocalEntitys);
}
async getTilesNameList():Promise<string[]> { async getTilesNameList():Promise<string[]> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const stream = await this.minioClient.listObjectsV2("nestfiles"); const stream = await this.minioClient.listObjectsV2("nestfiles");