INIT
This commit is contained in:
107
backend/src/mpt/entities/mpt.entity.ts
Normal file
107
backend/src/mpt/entities/mpt.entity.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { BaseModel } from 'src/common/entities/base.entity';
|
||||
import { FarmModel } from 'src/farm/entities/farm.entity';
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
/**
|
||||
* 혈액화학검사 결과 (1개체 N검사)
|
||||
*/
|
||||
@Entity({ name: 'tb_mpt' })
|
||||
export class MptModel extends BaseModel {
|
||||
@PrimaryGeneratedColumn({
|
||||
name: 'pk_mpt_no',
|
||||
type: 'int',
|
||||
comment: 'MPT 번호 (PK)',
|
||||
})
|
||||
pkMptNo: number;
|
||||
|
||||
@Column({
|
||||
name: 'cow_short_no',
|
||||
type: 'varchar',
|
||||
length: 4,
|
||||
nullable: true,
|
||||
comment: '개체 요약번호',
|
||||
})
|
||||
cowShortNo: string;
|
||||
|
||||
@Column({
|
||||
name: 'fk_farm_no',
|
||||
type: 'int',
|
||||
nullable: true,
|
||||
comment: '농장번호 FK',
|
||||
})
|
||||
fkFarmNo: number;
|
||||
|
||||
@Column({ name: 'test_dt', type: 'date', nullable: true, comment: '검사일자' })
|
||||
testDt: Date;
|
||||
|
||||
@Column({ name: 'month_age', type: 'int', nullable: true, comment: '월령' })
|
||||
monthAge: number;
|
||||
|
||||
@Column({ name: 'milk_yield', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '유량' })
|
||||
milkYield: number;
|
||||
|
||||
@Column({ name: 'parity', type: 'int', nullable: true, comment: '산차' })
|
||||
parity: number;
|
||||
|
||||
@Column({ name: 'glucose', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '혈당' })
|
||||
glucose: number;
|
||||
|
||||
@Column({ name: 'cholesterol', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '콜레스테롤' })
|
||||
cholesterol: number;
|
||||
|
||||
@Column({ name: 'nefa', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '유리지방산(NEFA)' })
|
||||
nefa: number;
|
||||
|
||||
@Column({ name: 'bcs', type: 'decimal', precision: 5, scale: 2, nullable: true, comment: 'BCS' })
|
||||
bcs: number;
|
||||
|
||||
@Column({ name: 'total_protein', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '총단백질' })
|
||||
totalProtein: number;
|
||||
|
||||
@Column({ name: 'albumin', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '알부민' })
|
||||
albumin: number;
|
||||
|
||||
@Column({ name: 'globulin', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '총글로불린' })
|
||||
globulin: number;
|
||||
|
||||
@Column({ name: 'ag_ratio', type: 'decimal', precision: 5, scale: 2, nullable: true, comment: 'A/G 비율' })
|
||||
agRatio: number;
|
||||
|
||||
@Column({ name: 'bun', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '요소태질소(BUN)' })
|
||||
bun: number;
|
||||
|
||||
@Column({ name: 'ast', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: 'AST' })
|
||||
ast: number;
|
||||
|
||||
@Column({ name: 'ggt', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: 'GGT' })
|
||||
ggt: number;
|
||||
|
||||
@Column({ name: 'fatty_liver_idx', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '지방간지수' })
|
||||
fattyLiverIdx: number;
|
||||
|
||||
@Column({ name: 'calcium', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '칼슘' })
|
||||
calcium: number;
|
||||
|
||||
@Column({ name: 'phosphorus', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '인' })
|
||||
phosphorus: number;
|
||||
|
||||
@Column({ name: 'ca_p_ratio', type: 'decimal', precision: 5, scale: 2, nullable: true, comment: '칼슘/인 비율' })
|
||||
caPRatio: number;
|
||||
|
||||
@Column({ name: 'magnesium', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '마그네슘' })
|
||||
magnesium: number;
|
||||
|
||||
@Column({ name: 'creatinine', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '크레아틴' })
|
||||
creatinine: number;
|
||||
|
||||
// Relations
|
||||
@ManyToOne(() => FarmModel, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'fk_farm_no' })
|
||||
farm: FarmModel;
|
||||
}
|
||||
47
backend/src/mpt/mpt.controller.ts
Normal file
47
backend/src/mpt/mpt.controller.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Controller, Get, Post, Put, Delete, Body, Param, Query } from '@nestjs/common';
|
||||
import { MptService } from './mpt.service';
|
||||
import { MptModel } from './entities/mpt.entity';
|
||||
|
||||
@Controller('mpt')
|
||||
export class MptController {
|
||||
constructor(private readonly mptService: MptService) {}
|
||||
|
||||
@Get()
|
||||
findAll(
|
||||
@Query('farmId') farmId?: string,
|
||||
@Query('cowShortNo') cowShortNo?: string,
|
||||
) {
|
||||
if (farmId) {
|
||||
return this.mptService.findByFarmId(+farmId);
|
||||
}
|
||||
if (cowShortNo) {
|
||||
return this.mptService.findByCowShortNo(cowShortNo);
|
||||
}
|
||||
return this.mptService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.mptService.findOne(+id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() data: Partial<MptModel>) {
|
||||
return this.mptService.create(data);
|
||||
}
|
||||
|
||||
@Post('bulk')
|
||||
bulkCreate(@Body() data: Partial<MptModel>[]) {
|
||||
return this.mptService.bulkCreate(data);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
update(@Param('id') id: string, @Body() data: Partial<MptModel>) {
|
||||
return this.mptService.update(+id, data);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.mptService.remove(+id);
|
||||
}
|
||||
}
|
||||
13
backend/src/mpt/mpt.module.ts
Normal file
13
backend/src/mpt/mpt.module.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { MptController } from './mpt.controller';
|
||||
import { MptService } from './mpt.service';
|
||||
import { MptModel } from './entities/mpt.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([MptModel])],
|
||||
controllers: [MptController],
|
||||
providers: [MptService],
|
||||
exports: [MptService],
|
||||
})
|
||||
export class MptModule {}
|
||||
68
backend/src/mpt/mpt.service.ts
Normal file
68
backend/src/mpt/mpt.service.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, IsNull } from 'typeorm';
|
||||
import { MptModel } from './entities/mpt.entity';
|
||||
|
||||
@Injectable()
|
||||
export class MptService {
|
||||
constructor(
|
||||
@InjectRepository(MptModel)
|
||||
private readonly mptRepository: Repository<MptModel>,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<MptModel[]> {
|
||||
return this.mptRepository.find({
|
||||
where: { delDt: IsNull() },
|
||||
relations: ['farm'],
|
||||
order: { testDt: 'DESC' },
|
||||
});
|
||||
}
|
||||
|
||||
async findByFarmId(farmNo: number): Promise<MptModel[]> {
|
||||
return this.mptRepository.find({
|
||||
where: { fkFarmNo: farmNo, delDt: IsNull() },
|
||||
relations: ['farm'],
|
||||
order: { testDt: 'DESC' },
|
||||
});
|
||||
}
|
||||
|
||||
async findByCowShortNo(cowShortNo: string): Promise<MptModel[]> {
|
||||
return this.mptRepository.find({
|
||||
where: { cowShortNo: cowShortNo, delDt: IsNull() },
|
||||
relations: ['farm'],
|
||||
order: { testDt: 'DESC' },
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: number): Promise<MptModel> {
|
||||
const mpt = await this.mptRepository.findOne({
|
||||
where: { pkMptNo: id, delDt: IsNull() },
|
||||
relations: ['farm'],
|
||||
});
|
||||
if (!mpt) {
|
||||
throw new NotFoundException(`MPT #${id} not found`);
|
||||
}
|
||||
return mpt;
|
||||
}
|
||||
|
||||
async create(data: Partial<MptModel>): Promise<MptModel> {
|
||||
const mpt = this.mptRepository.create(data);
|
||||
return this.mptRepository.save(mpt);
|
||||
}
|
||||
|
||||
async bulkCreate(data: Partial<MptModel>[]): Promise<MptModel[]> {
|
||||
const mpts = this.mptRepository.create(data);
|
||||
return this.mptRepository.save(mpts);
|
||||
}
|
||||
|
||||
async update(id: number, data: Partial<MptModel>): Promise<MptModel> {
|
||||
await this.findOne(id);
|
||||
await this.mptRepository.update(id, data);
|
||||
return this.findOne(id);
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
const mpt = await this.findOne(id);
|
||||
await this.mptRepository.softRemove(mpt);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user