From c50da0bc321670525c253ad43145ab99ef5b830a Mon Sep 17 00:00:00 2001 From: chu eun ju Date: Fri, 12 Dec 2025 14:04:04 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/auth/auth.service.ts | 21 +++++++++++---------- backend/src/genome/genome.service.ts | 28 ++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/backend/src/auth/auth.service.ts b/backend/src/auth/auth.service.ts index e00e5de..e0224d4 100644 --- a/backend/src/auth/auth.service.ts +++ b/backend/src/auth/auth.service.ts @@ -57,8 +57,9 @@ export class AuthService { if (!user) { throw new UnauthorizedException('아이디 또는 비밀번호가 틀렸습니다'); //HTTP 401 상태 코드 예외 } - // 3. 비밀번호 비교 (bcrypt) - const isPasswordValid = await bcrypt.compare(userPassword, user.userPw); + // 3. 비밀번호 비교 (bcrypt) - TODO: 나중에 해시 적용 + // const isPasswordValid = await bcrypt.compare(userPassword, user.userPw); + const isPasswordValid = userPassword === user.userPw; // 평문 비교 (임시) if (!isPasswordValid) { throw new UnauthorizedException('아이디 또는 비밀번호가 틀렸습니다'); } @@ -137,13 +138,13 @@ export class AuthService { } - // 2. 비밀번호 해싱 (bcrypt) - const saltRounds = parseInt(this.configService.get('BCRYPT_SALT_ROUNDS') || '10', 10); - const hashedPassword = await bcrypt.hash(signupDto.userPassword, saltRounds); + // 2. 비밀번호 해싱 (bcrypt) - TODO: 나중에 해시 적용 + // const saltRounds = parseInt(this.configService.get('BCRYPT_SALT_ROUNDS') || '10', 10); + // const hashedPassword = await bcrypt.hash(signupDto.userPassword, saltRounds); // 3. 사용자 생성 const newUser = this.userRepository.create({ userId: signupDto.userId, - userPw: hashedPassword, + userPw: signupDto.userPassword, // 평문 저장 (임시) userName: signupDto.userName, userPhone: signupDto.userPhone, userEmail: signupDto.userEmail, @@ -478,12 +479,12 @@ export class AuthService { throw new NotFoundException('사용자를 찾을 수 없습니다'); } - // 3. 새 비밀번호 해싱 - const saltRounds = parseInt(this.configService.get('BCRYPT_SALT_ROUNDS') || '10', 10); - const hashedPassword = await bcrypt.hash(newPassword, saltRounds); + // 3. 새 비밀번호 해싱 - TODO: 나중에 해시 적용 + // const saltRounds = parseInt(this.configService.get('BCRYPT_SALT_ROUNDS') || '10', 10); + // const hashedPassword = await bcrypt.hash(newPassword, saltRounds); // 4. 비밀번호 업데이트 - user.userPw = hashedPassword; + user.userPw = newPassword; // 평문 저장 (임시) await this.userRepository.save(user); return { diff --git a/backend/src/genome/genome.service.ts b/backend/src/genome/genome.service.ts index 9459cde..c18b585 100644 --- a/backend/src/genome/genome.service.ts +++ b/backend/src/genome/genome.service.ts @@ -553,13 +553,36 @@ export class GenomeService { farms.sort((a, b) => b.avgEbv - a.avgEbv); } + // 보은군 전체 형질별 평균 EPD 계산 (모든 농가의 모든 개체 데이터 사용) + const regionTraitEpdMap = new Map(); + for (const req of allRegionValidRequests) { + const details = traitDetailsByCowId.get(req.cow?.cowId || '') || []; + for (const detail of details) { + if (detail.traitVal !== null && detail.traitName) { + const traitName = detail.traitName; + if (!regionTraitEpdMap.has(traitName)) { + regionTraitEpdMap.set(traitName, { sum: 0, count: 0 }); + } + const t = regionTraitEpdMap.get(traitName)!; + t.sum += Number(detail.traitVal); + t.count++; + } + } + } + // 형질별 평균 및 순위 계산 (표준 경쟁 순위 방식: 동률 시 같은 순위, 다음 순위 건너뜀) const traitAverages = Array.from(traitDataMap.entries()).map(([traitName, data]) => { const avgEbv = Math.round((data.sum / data.count) * 100) / 100; - const avgEpd = Math.round((data.epdSum / data.count) * 100) / 100; // 육종가(EPD) 평균 + const avgEpd = Math.round((data.epdSum / data.count) * 100) / 100; // 농가 평균 육종가(EPD) const rankings = traitRankingMap.get(traitName) || []; const totalFarms = rankings.length; + // 보은군 평균 EPD 계산 + const regionData = regionTraitEpdMap.get(traitName); + const regionAvgEpd = regionData && regionData.count > 0 + ? Math.round((regionData.sum / regionData.count) * 100) / 100 + : 0; + // 표준 경쟁 순위 계산: 동률 처리 let rank: number | null = null; const farmData = rankings.find(r => r.farmNo === farmNo); @@ -575,7 +598,8 @@ export class GenomeService { traitName, category: data.category, avgEbv, - avgEpd, // 육종가(EPD) 평균 추가 + avgEpd, // 농가 평균 육종가(EPD) + regionAvgEpd, // 보은군 평균 육종가(EPD) 추가 avgPercentile: Math.round((data.percentileSum / data.count) * 100) / 100, count: data.count, rank,