feat: mongodb接入

This commit is contained in:
Mozzie 2023-09-08 14:15:06 +08:00
parent 72d3fc8619
commit abdf14cbee
12 changed files with 262 additions and 9 deletions

View File

@ -13,8 +13,6 @@ export type ExpandRouteProps = {
export const RouterElements = () => {
const location = useLocation();
console.log(location.pathname);
/**
* document.title
*/

View File

@ -90,13 +90,15 @@ export const Apis = {
/**
* dicom zip
*
*
*/
downloadDicom: (p: DownloadArchiveDTO) =>
axios
.post(PREFIX + `/dicom/download`, p, { responseType: "blob" })
.post(PREFIX + `/dicom/download`, p, {
responseType: "blob",
})
.then((response) => {
const filename = response.headers["content-name"];
const filename = response.headers["content-name"] as string;
const blob = new Blob([response.data], { type: "application/zip" });
saveAs(blob, filename);
})

View File

@ -18,6 +18,8 @@
"@nestjs/common": "10.1.0",
"@nestjs/core": "10.1.0",
"@nestjs/platform-express": "10.1.0",
"@nestjs/mongoose": "10.0.1",
"mongoose": "7.5.0",
"reflect-metadata": "^0.1.13",
"@nestjs/config": "3.0.0",
"rxjs": "7.8.1",

View File

@ -1,4 +1,4 @@
PORT=31121
PORT=31521
# nacos中注册服务的名称
NACOS_SERVICE_NAME=logger
NACOS_ADDR=127.0.0.1:8848

View File

@ -24,4 +24,9 @@ export class AppController {
console.log({ ...rest, dateTime, browserInfo });
return 1;
}
@EventPattern({ cmd: 'logger.save' })
async saveLogger(payload: UserSignLoggerDto) {
return 'ok';
}
}

View File

@ -4,6 +4,7 @@ import { AppService } from './app.service';
import { NacosModule } from './nacos/nacos.module';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Log } from './entity/logs.entity';
@Module({
imports: [
@ -12,6 +13,18 @@ import { TypeOrmModule } from '@nestjs/typeorm';
envFilePath: `.env.${process.env.NODE_ENV}`,
}),
NacosModule,
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'root',
database: 'logger',
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
timezone: 'Asia/Shanghai', // 这里设置了时区
}),
TypeOrmModule.forFeature([Log]),
],
controllers: [AppController],
providers: [AppService],

View File

@ -0,0 +1,31 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';
@Entity('logs')
export class Log {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'varchar', length: 255 })
level: string; // 日志等级, 如:'info', 'error', 'warn' 等
@Column({ type: 'text' })
message: string; // 日志内容
@Column({ type: 'text', nullable: true })
metadata?: string; // 元数据, 可选,可以存储如错误堆栈等额外信息
@Column({ type: 'varchar', length: 255, nullable: true })
service: string; // 来源服务或应用的名称
@CreateDateColumn({ type: 'timestamp' })
createdAt: Date; // 日志创建时间
@UpdateDateColumn({ type: 'timestamp' })
updatedAt: Date; // 日志更新时间
}

View File

@ -35,6 +35,7 @@ export class NacosService
ip: this.getServerIP(),
port: configService.get('PORT'),
};
this.subscribeConfiguration();
}
/**
@ -86,7 +87,9 @@ export class NacosService
dataId,
group,
},
(content) => console.log('content', content),
(content) => {
console.log('content', content, typeof JSON.parse(content));
},
);
}

View File

@ -10,6 +10,19 @@ services:
- "6222:6222"
- "8222:8222"
mongodb:
image: mongo:5.0
container_name: tavi-mongo
restart: always
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
MONGO_INITDB_DATABASE: tavi
volumes:
- ./init.mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
mysql:
image: mysql:5.7
container_name: tavi-mysql
@ -19,7 +32,7 @@ services:
ports:
- "3306:3306"
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
- ./init.mysql.sql:/docker-entrypoint-initdb.d/init.mysql.sql
nacos:
image: nacos/nacos-server

14
init.mongo.js Normal file
View File

@ -0,0 +1,14 @@
db = db.getSiblingDB('tavi'); // 选择 mydatabase
db.someCollection.insert({ initialized: true }); // 在 mydatabase 中插入一条数据
db.createUser(
{
user: "test",
pwd: "test",
roles: [
{
role: "readWrite",
db: "tavi"
}
]
}
);

View File

@ -864,6 +864,9 @@ importers:
'@nestjs/microservices':
specifier: 10.0.5
version: 10.0.5(@nestjs/common@10.1.0)(@nestjs/core@10.1.0)(ioredis@5.3.2)(nats@2.15.1)(reflect-metadata@0.1.13)(rxjs@7.8.1)
'@nestjs/mongoose':
specifier: 10.0.1
version: 10.0.1(@nestjs/common@10.1.0)(@nestjs/core@10.1.0)(mongoose@7.5.0)(reflect-metadata@0.1.13)(rxjs@7.8.1)
'@nestjs/platform-express':
specifier: 10.1.0
version: 10.1.0(@nestjs/common@10.1.0)(@nestjs/core@10.1.0)
@ -897,6 +900,9 @@ importers:
minimatch:
specifier: 9.0.3
version: 9.0.3
mongoose:
specifier: 7.5.0
version: 7.5.0
nacos:
specifier: 2.5.1
version: 2.5.1
@ -3546,6 +3552,14 @@ packages:
read-yaml-file: 1.1.0
dev: true
/@mongodb-js/saslprep@1.1.0:
resolution: {integrity: sha512-Xfijy7HvfzzqiOAhAepF4SGN5e9leLkMvg/OPOF97XemjfVCYN/oWa75wnkc6mltMSTwY+XlbhWgUOJmkFspSw==}
requiresBuild: true
dependencies:
sparse-bitfield: 3.0.3
dev: false
optional: true
/@nestjs/axios@2.0.0(@nestjs/common@9.0.0)(axios@1.5.0)(reflect-metadata@0.1.13)(rxjs@7.8.1):
resolution: {integrity: sha512-F6oceoQLEn031uun8NiommeMkRIojQqVryxQy/mK7fx0CI0KbgkJL3SloCQcsOD+agoEnqKJKXZpEvL6FNswJg==}
peerDependencies:
@ -3841,6 +3855,22 @@ packages:
rxjs: 7.8.1
tslib: 2.6.0
/@nestjs/mongoose@10.0.1(@nestjs/common@10.1.0)(@nestjs/core@10.1.0)(mongoose@7.5.0)(reflect-metadata@0.1.13)(rxjs@7.8.1):
resolution: {integrity: sha512-woUViG28WKf/kRiv6NFXu4Oc0DvAPeX4+fT4coDVt2OqndnfJZTXwkkys23uVsBpKSIflRyjPvmcVBHQvcunZw==}
peerDependencies:
'@nestjs/common': ^8.0.0 || ^9.0.0 || ^10.0.0
'@nestjs/core': ^8.0.0 || ^9.0.0 || ^10.0.0
mongoose: ^6.0.2 || ^7.0.0
reflect-metadata: ^0.1.12
rxjs: ^7.0.0
dependencies:
'@nestjs/common': 10.1.0(class-transformer@0.5.1)(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1)
'@nestjs/core': 10.1.0(@nestjs/common@10.1.0)(@nestjs/microservices@10.0.5)(@nestjs/platform-express@10.1.0)(reflect-metadata@0.1.13)(rxjs@7.8.1)
mongoose: 7.5.0
reflect-metadata: 0.1.13
rxjs: 7.8.1
dev: false
/@nestjs/passport@10.0.0(@nestjs/common@10.1.0)(passport@0.6.0):
resolution: {integrity: sha512-IlKKc6M7JOe+4dBbW6gZsXBSD05ZYgwfGf3GJhgCmUGYVqffpDdALQSS6JftnExrE+12rACoEmHkzYwKAGVK0Q==}
peerDependencies:
@ -4543,10 +4573,21 @@ packages:
/@types/validator@13.11.1:
resolution: {integrity: sha512-d/MUkJYdOeKycmm75Arql4M5+UuXmf4cHdHKsyw1GcvnNgL6s77UkgSgJ8TE/rI5PYsnwYq5jkcWBLuN/MpQ1A==}
/@types/webidl-conversions@7.0.0:
resolution: {integrity: sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==}
dev: false
/@types/webxr@0.5.4:
resolution: {integrity: sha512-41gfGLTtqXZhcmoDlLDHqMJDuwAMwhHwXf9Q2job3TUBsvkNfPNI/3IWVEtLH4tyY1ElWtfwIaoNeqeEX238/Q==}
dev: true
/@types/whatwg-url@8.2.2:
resolution: {integrity: sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==}
dependencies:
'@types/node': 20.3.3
'@types/webidl-conversions': 7.0.0
dev: false
/@types/ws@8.5.5:
resolution: {integrity: sha512-lwhs8hktwxSjf9UaZ9tG5M03PGogvFaH8gUgLNbN9HKIg0dvv6q+gkSuJ8HN4/VbyxkuLzCjlN7GquQ0gUJfIg==}
dependencies:
@ -5742,6 +5783,11 @@ packages:
update-browserslist-db: 1.0.11(browserslist@4.21.10)
dev: true
/bson@5.4.0:
resolution: {integrity: sha512-WRZ5SQI5GfUuKnPTNmAYPiKIof3ORXAF4IRU5UcgmivNIon01rWQlw5RUH954dpu8yGL8T59YShVddIPaU/gFA==}
engines: {node: '>=14.20.1'}
dev: false
/btoa@1.2.1:
resolution: {integrity: sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==}
engines: {node: '>= 0.4.0'}
@ -8338,6 +8384,10 @@ packages:
resolution: {integrity: sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==}
dev: false
/ip@2.0.0:
resolution: {integrity: sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==}
dev: false
/ipaddr.js@1.9.1:
resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==}
engines: {node: '>= 0.10'}
@ -8817,6 +8867,11 @@ packages:
safe-buffer: 5.2.1
dev: false
/kareem@2.5.1:
resolution: {integrity: sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA==}
engines: {node: '>=12.0.0'}
dev: false
/keyv@4.5.3:
resolution: {integrity: sha512-QCiSav9WaX1PgETJ+SpNnx2PRRapJ/oRSXM4VO5OGYGSjrxbKPVFVhB3l2OCbLCk329N8qyAtsJjSjvVBWzEug==}
dependencies:
@ -9130,6 +9185,11 @@ packages:
fs-monkey: 1.0.4
dev: true
/memory-pager@1.5.0:
resolution: {integrity: sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==}
dev: false
optional: true
/meow@6.1.1:
resolution: {integrity: sha512-3YffViIt2QWgTy6Pale5QpopX/IvU3LPL03jOTqp6pGj3VjesdO/U8CuHMKpnQr4shCNCM5fd5XFFvIIl6JBHg==}
engines: {node: '>=8'}
@ -9341,6 +9401,75 @@ packages:
resolution: {integrity: sha512-HdKewQEREEJgsWnErClfbFoVebze6rGazxFLU/XUyrII8dORfVszN1V0BMRnQSzcgsNNtkX8DHj3nC6cdWE9YQ==}
dev: false
/mongodb-connection-string-url@2.6.0:
resolution: {integrity: sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==}
dependencies:
'@types/whatwg-url': 8.2.2
whatwg-url: 11.0.0
dev: false
/mongodb@5.8.1:
resolution: {integrity: sha512-wKyh4kZvm6NrCPH8AxyzXm3JBoEf4Xulo0aUWh3hCgwgYJxyQ1KLST86ZZaSWdj6/kxYUA3+YZuyADCE61CMSg==}
engines: {node: '>=14.20.1'}
peerDependencies:
'@aws-sdk/credential-providers': ^3.188.0
'@mongodb-js/zstd': ^1.0.0
kerberos: ^1.0.0 || ^2.0.0
mongodb-client-encryption: '>=2.3.0 <3'
snappy: ^7.2.2
peerDependenciesMeta:
'@aws-sdk/credential-providers':
optional: true
'@mongodb-js/zstd':
optional: true
kerberos:
optional: true
mongodb-client-encryption:
optional: true
snappy:
optional: true
dependencies:
bson: 5.4.0
mongodb-connection-string-url: 2.6.0
socks: 2.7.1
optionalDependencies:
'@mongodb-js/saslprep': 1.1.0
dev: false
/mongoose@7.5.0:
resolution: {integrity: sha512-FpOWOb0AJuaVcplmEyIJ2eCbVGe4gOoniPD+pmft5BrGrNrsFcnYXlERdXtBApGHMHPwD7WbxTyhCbUNr72F3Q==}
engines: {node: '>=14.20.1'}
dependencies:
bson: 5.4.0
kareem: 2.5.1
mongodb: 5.8.1
mpath: 0.9.0
mquery: 5.0.0
ms: 2.1.3
sift: 16.0.1
transitivePeerDependencies:
- '@aws-sdk/credential-providers'
- '@mongodb-js/zstd'
- kerberos
- mongodb-client-encryption
- snappy
- supports-color
dev: false
/mpath@0.9.0:
resolution: {integrity: sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==}
engines: {node: '>=4.0.0'}
dev: false
/mquery@5.0.0:
resolution: {integrity: sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==}
engines: {node: '>=14.0.0'}
dependencies:
debug: 4.3.4
transitivePeerDependencies:
- supports-color
dev: false
/mrmime@1.0.1:
resolution: {integrity: sha512-hzzEagAgDyoU1Q6yg5uI+AorQgdvMCur3FcKf7NhMKWsaYg+RnbTyHRa/9IlLF9rf455MOCtcqqrQQ83pPP7Uw==}
engines: {node: '>=10'}
@ -10355,7 +10484,6 @@ packages:
/punycode@2.3.0:
resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==}
engines: {node: '>=6'}
dev: true
/purgecss-webpack-plugin@5.0.0(webpack@5.75.0):
resolution: {integrity: sha512-u8J0SxXdMekVOsbyV6hK1x6LlzJbE/mrC+UbNX0mLz5Jo/Jle8o4S3IFIRCgdzGdxtOBPCKW+UNgaULfKVmx2w==}
@ -11979,6 +12107,10 @@ packages:
get-intrinsic: 1.2.1
object-inspect: 1.12.3
/sift@16.0.1:
resolution: {integrity: sha512-Wv6BjQ5zbhW7VFefWusVP33T/EM0vYikCaQ2qR8yULbsilAT8/wQaXvuQ3ptGLpoKx+lihJE3y2UTgKDyyNHZQ==}
dev: false
/signal-exit@3.0.7:
resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==}
dev: true
@ -12002,6 +12134,11 @@ packages:
engines: {node: '>=12'}
dev: true
/smart-buffer@4.2.0:
resolution: {integrity: sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==}
engines: {node: '>= 6.0.0', npm: '>= 3.0.0'}
dev: false
/smartwrap@2.0.2:
resolution: {integrity: sha512-vCsKNQxb7PnCNd2wY1WClWifAc2lwqsG8OaswpJkVJsvMGcnEntdTCDajZCkk93Ay1U3t/9puJmb525Rg5MZBA==}
engines: {node: '>=6'}
@ -12023,6 +12160,14 @@ packages:
websocket-driver: 0.7.4
dev: true
/socks@2.7.1:
resolution: {integrity: sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==}
engines: {node: '>= 10.13.0', npm: '>= 3.0.0'}
dependencies:
ip: 2.0.0
smart-buffer: 4.2.0
dev: false
/source-map-js@1.0.2:
resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==}
engines: {node: '>=0.10.0'}
@ -12055,6 +12200,13 @@ packages:
deprecated: Please use @jridgewell/sourcemap-codec instead
dev: true
/sparse-bitfield@3.0.3:
resolution: {integrity: sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==}
dependencies:
memory-pager: 1.5.0
dev: false
optional: true
/spawndamnit@2.0.0:
resolution: {integrity: sha512-j4JKEcncSjFlqIwU5L/rp2N5SIPsdxaRsIv678+TZxZ0SRDJTm8JrxJMjE/XuiEZNEir3S8l0Fa3Ke339WI4qA==}
dependencies:
@ -12582,6 +12734,13 @@ packages:
/tr46@0.0.3:
resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==}
/tr46@3.0.0:
resolution: {integrity: sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==}
engines: {node: '>=12'}
dependencies:
punycode: 2.3.0
dev: false
/tree-kill@1.2.2:
resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==}
hasBin: true
@ -13287,6 +13446,11 @@ packages:
/webidl-conversions@3.0.1:
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
/webidl-conversions@7.0.0:
resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==}
engines: {node: '>=12'}
dev: false
/webpack-bundle-analyzer@4.8.0:
resolution: {integrity: sha512-ZzoSBePshOKhr+hd8u6oCkZVwpVaXgpw23ScGLFpR6SjYI7+7iIWYarjN6OEYOfRt8o7ZyZZQk0DuMizJ+LEIg==}
engines: {node: '>= 10.13.0'}
@ -13574,6 +13738,14 @@ packages:
engines: {node: '>=0.8.0'}
dev: true
/whatwg-url@11.0.0:
resolution: {integrity: sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==}
engines: {node: '>=12'}
dependencies:
tr46: 3.0.0
webidl-conversions: 7.0.0
dev: false
/whatwg-url@5.0.0:
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
dependencies: