미사용 파일정리

This commit is contained in:
2025-12-24 08:25:44 +09:00
parent 1644fcf241
commit 05d89fdfcd
120 changed files with 817 additions and 85913 deletions

View File

@@ -1,61 +1,37 @@
import { Controller, Get, Post, Put, Delete, Body, Param, Query } from '@nestjs/common';
import { Controller, Get, 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) {}
/**
* MPT 참조값 조회
*/
@Get('reference')
getReferenceValues() {
return this.mptService.getReferenceValues();
}
@Get()
findAll(
@Query('farmId') farmId?: string,
@Query('cowShortNo') cowShortNo?: string,
@Query('cowId') cowId?: string,
) {
if (farmId) {
return this.mptService.findByFarmId(+farmId);
}
if (cowId) {
return this.mptService.findByCowId(cowId);
}
if (cowShortNo) {
return this.mptService.findByCowShortNo(cowShortNo);
}
return this.mptService.findAll();
return [];
}
/**
* 농장별 MPT 통계 조회
* - 카테고리별 정상/주의/위험 개체 수
* - 위험 개체 목록
*/
@Get('statistics/:farmNo')
getMptStatistics(@Param('farmNo') farmNo: string) {
return this.mptService.getMptStatistics(+farmNo);
}
@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);
}
}

View File

@@ -1,29 +1,13 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, IsNull } from 'typeorm';
import { MptModel } from './entities/mpt.entity';
/**
* MPT 참조값 범위 (정상/주의/위험 판단 기준)
*/
const MPT_REFERENCE_RANGES: Record<string, { upper: number; lower: number; category: string }> = {
glucose: { lower: 40, upper: 84, category: 'energy' },
cholesterol: { lower: 74, upper: 252, category: 'energy' },
nefa: { lower: 115, upper: 660, category: 'energy' },
bcs: { lower: 2.5, upper: 3.5, category: 'energy' },
totalProtein: { lower: 6.2, upper: 7.7, category: 'protein' },
albumin: { lower: 3.3, upper: 4.3, category: 'protein' },
globulin: { lower: 9.1, upper: 36.1, category: 'protein' },
agRatio: { lower: 0.1, upper: 0.4, category: 'protein' },
bun: { lower: 11.7, upper: 18.9, category: 'protein' },
ast: { lower: 47, upper: 92, category: 'liver' },
ggt: { lower: 11, upper: 32, category: 'liver' },
fattyLiverIdx: { lower: -1.2, upper: 9.9, category: 'liver' },
calcium: { lower: 8.1, upper: 10.6, category: 'mineral' },
phosphorus: { lower: 6.2, upper: 8.9, category: 'mineral' },
caPRatio: { lower: 1.2, upper: 1.3, category: 'mineral' },
magnesium: { lower: 1.6, upper: 3.3, category: 'mineral' },
};
import {
MPT_REFERENCE_RANGES,
MPT_CATEGORIES,
MptReferenceRange,
MptCategory,
} from '../common/const/MptReference';
/**
* MPT 통계 응답 DTO
@@ -53,22 +37,6 @@ export class MptService {
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() },
@@ -85,38 +53,6 @@ export class MptService {
});
}
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);
}
/**
* 농장별 MPT 통계 조회
* - 개체별 최신 검사 결과 기준
@@ -187,7 +123,7 @@ export class MptService {
const category = ref.category as keyof typeof categoryStatus;
// 범위 밖이면 주의
if (value > ref.upper || value < ref.lower) {
if (value > ref.upperLimit || value < ref.lowerLimit) {
categoryStatus[category] = 'caution';
// 주의 개체 목록에 추가
@@ -196,7 +132,7 @@ export class MptService {
category,
itemName: itemKey,
value,
status: value > ref.upper ? 'high' : 'low',
status: value > ref.upperLimit ? 'high' : 'low',
});
}
};
@@ -239,11 +175,11 @@ export class MptService {
const refA = MPT_REFERENCE_RANGES[a.itemName];
const refB = MPT_REFERENCE_RANGES[b.itemName];
const deviationA = a.status === 'high'
? (a.value - refA.upper) / (refA.upper - refA.lower)
: (refA.lower - a.value) / (refA.upper - refA.lower);
? (a.value - refA.upperLimit) / (refA.upperLimit - refA.lowerLimit)
: (refA.lowerLimit - a.value) / (refA.upperLimit - refA.lowerLimit);
const deviationB = b.status === 'high'
? (b.value - refB.upper) / (refB.upper - refB.lower)
: (refB.lower - b.value) / (refB.upper - refB.lower);
? (b.value - refB.upperLimit) / (refB.upperLimit - refB.lowerLimit)
: (refB.lowerLimit - b.value) / (refB.upperLimit - refB.lowerLimit);
return deviationB - deviationA;
})
.slice(0, 5);
@@ -255,4 +191,14 @@ export class MptService {
riskyCows: sortedRiskyCows,
};
}
/**
* MPT 참조값 조회
*/
getReferenceValues(): { references: Record<string, MptReferenceRange>; categories: MptCategory[] } {
return {
references: MPT_REFERENCE_RANGES,
categories: MPT_CATEGORIES,
};
}
}