From 642a761a7a5f1dc6cd6b3b444760a153baae7569 Mon Sep 17 00:00:00 2001 From: DanielLee <198891672+sanghyeonhd@users.noreply.github.com> Date: Wed, 14 Jan 2026 14:42:44 +0900 Subject: [PATCH] =?UTF-8?q?=EB=9D=BC=EB=B2=A8=EB=A7=81=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=EC=9D=B4=EB=A0=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../label/LabelAllocateRepositoryImpl.java | 185 +++++++++++++----- 1 file changed, 133 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryImpl.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryImpl.java index 7d34b4de..685a8217 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryImpl.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/label/LabelAllocateRepositoryImpl.java @@ -1466,13 +1466,6 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto NumberExpression totalCnt = labelingAssignmentEntity.assignmentUid.count(); - NumberExpression assignedCnt = - new CaseBuilder() - .when(labelingAssignmentEntity.workState.eq(LabelState.ASSIGNED.getId())) - .then(1L) - .otherwise((Long) null) - .count(); - NumberExpression skipCnt = new CaseBuilder() .when(labelingAssignmentEntity.workState.eq(LabelState.SKIP.getId())) @@ -1487,78 +1480,166 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto .otherwise((Long) null) .count(); - NumberExpression percent = - new CaseBuilder() - .when(completeCnt.eq(0L)) - .then(0.0) - .otherwise( - Expressions.numberTemplate( - Double.class, - "round({0} / {1}, 2)", - completeCnt, - labelingAssignmentEntity.count())); - Pageable pageable = searchReq.toPageable(); List list = queryFactory .select( - Projections.constructor( + Projections.bean( WorkHistoryDto.class, - Expressions.numberTemplate( - Integer.class, - "row_number() over(order by {0} desc)", - labelingAssignmentEntity.analUid), Expressions.stringTemplate( - "concat({0}, '-', {1})", - mapSheetAnalInferenceEntity.compareYyyy, - mapSheetAnalInferenceEntity.targetYyyy), - mapSheetAnalInferenceEntity.stage, - mapSheetAnalInferenceEntity.gukyuinApplyDttm, - assignedCnt, - completeCnt, - skipCnt, - skipCnt, - // status, - percent, - mapSheetAnalInferenceEntity.createdDttm, + "concat({0}, '-', {1})", + mapSheetAnalInferenceEntity.compareYyyy, + mapSheetAnalInferenceEntity.targetYyyy) + .as("changeDetectionYear"), + mapSheetAnalInferenceEntity.stage.longValue().as("stage"), + mapSheetAnalInferenceEntity.gukyuinApplyDttm.as("gukyuinApplyDttm"), + totalCnt.as("assignedCnt"), + completeCnt.as("completeCnt"), + skipCnt.as("skipCnt"), + mapSheetAnalInferenceEntity.createdDttm.as("createdDttm"), new CaseBuilder() .when(mapSheetAnalInferenceEntity.inspectionClosedYn.eq("Y")) .then(mapSheetAnalInferenceEntity.updatedDttm) - .otherwise((ZonedDateTime) null))) + .otherwise((ZonedDateTime) null) + .as("projectCloseDttm"))) .from(labelingAssignmentEntity) .innerJoin(mapSheetAnalInferenceEntity) .on(labelingAssignmentEntity.analUid.eq(mapSheetAnalInferenceEntity.id)) - .where( - labelingAssignmentEntity.analUid.in( - JPAExpressions.select(labelingAssignmentEntity.analUid) - .from(labelingAssignmentEntity) - .where(labelingAssignmentEntity.workerUid.eq(userId)) - .groupBy(labelingAssignmentEntity.analUid))) - .orderBy(percent.desc()) + .where(labelingAssignmentEntity.workerUid.eq(userId)) + .groupBy( + mapSheetAnalInferenceEntity.id, + mapSheetAnalInferenceEntity.compareYyyy, + mapSheetAnalInferenceEntity.targetYyyy, + mapSheetAnalInferenceEntity.stage, + mapSheetAnalInferenceEntity.gukyuinApplyDttm, + mapSheetAnalInferenceEntity.createdDttm, + mapSheetAnalInferenceEntity.inspectionClosedYn, + mapSheetAnalInferenceEntity.updatedDttm) + .orderBy(mapSheetAnalInferenceEntity.id.desc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetch(); + // rowNum과 remainCnt, percent를 Java에서 계산 + int startRow = (int) pageable.getOffset() + 1; + for (int i = 0; i < list.size(); i++) { + WorkHistoryDto dto = list.get(i); + dto.setRowNum(startRow + i); + + // remainCnt 계산 + Long assigned = dto.getAssignedCnt() != null ? dto.getAssignedCnt() : 0L; + Long complete = dto.getCompleteCnt() != null ? dto.getCompleteCnt() : 0L; + Long skip = dto.getSkipCnt() != null ? dto.getSkipCnt() : 0L; + dto.setRemainCnt(assigned - complete - skip); + + // percent 계산 + if (assigned > 0) { + dto.setPercent(Math.round((double) complete / assigned * 100.0 * 100.0) / 100.0); + } else { + dto.setPercent(0.0); + } + } + Long countQuery = queryFactory - .select(mapSheetAnalInferenceEntity.id.count()) + .select(mapSheetAnalInferenceEntity.id.countDistinct()) .from(labelingAssignmentEntity) .innerJoin(mapSheetAnalInferenceEntity) .on(labelingAssignmentEntity.analUid.eq(mapSheetAnalInferenceEntity.id)) - .where( - labelingAssignmentEntity.analUid.in( - JPAExpressions.select(labelingAssignmentEntity.analUid) - .from(labelingAssignmentEntity) - .where(labelingAssignmentEntity.workerUid.eq(userId)) - .groupBy(labelingAssignmentEntity.analUid))) + .where(labelingAssignmentEntity.workerUid.eq(userId)) .fetchOne(); - return new PageImpl<>(list, pageable, countQuery); + return new PageImpl<>(list, pageable, countQuery != null ? countQuery : 0L); } @Override public Page workReviewerHistoryList(searchReq searchReq, String userId) { - return null; + NumberExpression totalCnt = labelingAssignmentEntity.assignmentUid.count(); + + NumberExpression skipCnt = + new CaseBuilder() + .when(labelingAssignmentEntity.inspectState.eq(InspectState.EXCEPT.getId())) + .then(1L) + .otherwise((Long) null) + .count(); + + NumberExpression completeCnt = + new CaseBuilder() + .when(labelingAssignmentEntity.inspectState.eq(InspectState.COMPLETE.getId())) + .then(1L) + .otherwise((Long) null) + .count(); + + Pageable pageable = searchReq.toPageable(); + List list = + queryFactory + .select( + Projections.bean( + WorkHistoryDto.class, + Expressions.stringTemplate( + "concat({0}, '-', {1})", + mapSheetAnalInferenceEntity.compareYyyy, + mapSheetAnalInferenceEntity.targetYyyy) + .as("changeDetectionYear"), + mapSheetAnalInferenceEntity.stage.longValue().as("stage"), + mapSheetAnalInferenceEntity.gukyuinApplyDttm.as("gukyuinApplyDttm"), + totalCnt.as("assignedCnt"), + completeCnt.as("completeCnt"), + skipCnt.as("skipCnt"), + mapSheetAnalInferenceEntity.createdDttm.as("createdDttm"), + new CaseBuilder() + .when(mapSheetAnalInferenceEntity.inspectionClosedYn.eq("Y")) + .then(mapSheetAnalInferenceEntity.updatedDttm) + .otherwise((ZonedDateTime) null) + .as("projectCloseDttm"))) + .from(labelingAssignmentEntity) + .innerJoin(mapSheetAnalInferenceEntity) + .on(labelingAssignmentEntity.analUid.eq(mapSheetAnalInferenceEntity.id)) + .where(labelingAssignmentEntity.inspectorUid.eq(userId)) + .groupBy( + mapSheetAnalInferenceEntity.id, + mapSheetAnalInferenceEntity.compareYyyy, + mapSheetAnalInferenceEntity.targetYyyy, + mapSheetAnalInferenceEntity.stage, + mapSheetAnalInferenceEntity.gukyuinApplyDttm, + mapSheetAnalInferenceEntity.createdDttm, + mapSheetAnalInferenceEntity.inspectionClosedYn, + mapSheetAnalInferenceEntity.updatedDttm) + .orderBy(mapSheetAnalInferenceEntity.id.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + // rowNum과 remainCnt, percent를 Java에서 계산 + int startRow = (int) pageable.getOffset() + 1; + for (int i = 0; i < list.size(); i++) { + WorkHistoryDto dto = list.get(i); + dto.setRowNum(startRow + i); + + // remainCnt 계산 + Long assigned = dto.getAssignedCnt() != null ? dto.getAssignedCnt() : 0L; + Long complete = dto.getCompleteCnt() != null ? dto.getCompleteCnt() : 0L; + Long skip = dto.getSkipCnt() != null ? dto.getSkipCnt() : 0L; + dto.setRemainCnt(assigned - complete - skip); + + // percent 계산 + if (assigned > 0) { + dto.setPercent(Math.round((double) complete / assigned * 100.0 * 100.0) / 100.0); + } else { + dto.setPercent(0.0); + } + } + + Long countQuery = + queryFactory + .select(mapSheetAnalInferenceEntity.id.countDistinct()) + .from(labelingAssignmentEntity) + .innerJoin(mapSheetAnalInferenceEntity) + .on(labelingAssignmentEntity.analUid.eq(mapSheetAnalInferenceEntity.id)) + .where(labelingAssignmentEntity.inspectorUid.eq(userId)) + .fetchOne(); + + return new PageImpl<>(list, pageable, countQuery != null ? countQuery : 0L); } }