feat: 标签切回mysql
This commit is contained in:
parent
abdf14cbee
commit
cf79216a6e
7
apps/services/dicom/src/app.constant.ts
Normal file
7
apps/services/dicom/src/app.constant.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* 标签的来源
|
||||
*/
|
||||
export enum LabelSource {
|
||||
SYSTEM = 'SYSTEM',
|
||||
USER = 'USER',
|
||||
}
|
30
apps/services/dicom/src/label/entity/label.entity.ts
Normal file
30
apps/services/dicom/src/label/entity/label.entity.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { LabelSource } from 'src/app.constant';
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
export class Label {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: LabelSource,
|
||||
default: LabelSource.SYSTEM, // 设置一个默认值,如果需要的话
|
||||
})
|
||||
source: LabelSource;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamp' })
|
||||
createAt: Date;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamp' })
|
||||
updateAt: Date;
|
||||
}
|
|
@ -8,6 +8,6 @@ export class LabelController {
|
|||
|
||||
@EventPattern({ cmd: 'dicom.label.create' })
|
||||
async createLabel(payload) {
|
||||
return await this.labelService.createLabel();
|
||||
return await this.labelService.createLabel(payload);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { LabelController } from './label.controller';
|
||||
import { Label, LabelSchema } from './schema/label.schema';
|
||||
import { LabelService } from './label.service';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Label } from './entity/label.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [LabelController],
|
||||
imports: [
|
||||
MongooseModule.forRoot('mongodb://test:test@localhost:27017/tavi'),
|
||||
MongooseModule.forFeature([{ name: Label.name, schema: LabelSchema }]),
|
||||
TypeOrmModule.forRoot({
|
||||
type: 'mysql',
|
||||
host: 'localhost',
|
||||
port: 3306,
|
||||
username: 'root',
|
||||
password: 'root',
|
||||
database: 'dicom',
|
||||
entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
||||
synchronize: true,
|
||||
timezone: 'Asia/Shanghai', // 这里设置了时区
|
||||
}),
|
||||
TypeOrmModule.forFeature([Label]),
|
||||
],
|
||||
providers: [LabelService],
|
||||
})
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { Label, LabelDocument } from './schema/label.schema';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Label } from './entity/label.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class LabelService {
|
||||
constructor(
|
||||
@InjectModel(Label.name)
|
||||
private readonly labelModel: Model<LabelDocument>,
|
||||
@InjectRepository(Label)
|
||||
private readonly labelRepository: Repository<Label>,
|
||||
) {}
|
||||
async createLabel() {
|
||||
// 创建一个新的 Label 实例
|
||||
const newLabel = new this.labelModel({
|
||||
async createLabel(payload) {
|
||||
console.log(payload);
|
||||
return await this.labelRepository.save({
|
||||
name: '钙化',
|
||||
description: '钙化的关键词',
|
||||
});
|
||||
|
||||
// 使用 save 方法保存实例到数据库
|
||||
return await newLabel.save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
import { Schema, Document, model } from 'mongoose';
|
||||
|
||||
export interface LabelDocument extends Document {
|
||||
name: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export const LabelSchema = new Schema({
|
||||
name: { type: String, required: true },
|
||||
description: String,
|
||||
});
|
||||
|
||||
export const Label = model<LabelDocument>('Label', LabelSchema);
|
Loading…
Reference in New Issue
Block a user