개선작업

This commit is contained in:
DanielLee
2026-01-02 21:20:46 +09:00
parent 3a458225c9
commit 358d932e96
13 changed files with 95 additions and 146 deletions

View File

@@ -19,12 +19,12 @@ public class LabelAllocateCoreService {
private final LabelAllocateRepository labelAllocateRepository;
public List<Long> fetchNextIds(Long lastId, Long batchSize) {
return labelAllocateRepository.fetchNextIds(lastId, batchSize);
public List<Long> fetchNextIds(Long lastId, Long batchSize, Long analUid) {
return labelAllocateRepository.fetchNextIds(lastId, batchSize, analUid);
}
public void assignOwner(List<Long> ids, String userId) {
labelAllocateRepository.assignOwner(ids, userId);
public void assignOwner(List<Long> ids, String userId, Long analUid) {
labelAllocateRepository.assignOwner(ids, userId, analUid);
}
public List<LabelAllocateDto.Basic> findAssignedLabelerList(Long analUid) {
@@ -33,8 +33,8 @@ public class LabelAllocateCoreService {
.toList();
}
public Long findLabelUnAssignedCnt(Long analUid) {
return labelAllocateRepository.findLabelUnAssignedCnt(analUid);
public Long findLabelUnAssignedCnt(Long analUid, Integer stage) {
return labelAllocateRepository.findLabelUnAssignedCnt(analUid, stage);
}
public void assignInspector(UUID assignmentUid, String inspectorUid) {

View File

@@ -1,17 +1,8 @@
package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto.LabelWorkMng;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.ErrorDataDto;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import com.kamco.cd.kamcoback.postgres.repository.label.LabelAllocateRepository;
import com.kamco.cd.kamcoback.postgres.repository.label.LabelWorkRepository;
import jakarta.validation.Valid;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@@ -22,10 +13,7 @@ public class LabelWorkCoreService {
private final LabelWorkRepository labelWorkRepository;
public Page<LabelWorkMng> labelWorkMngList(LabelWorkDto.LabelWorkMngSearchReq searchReq) {
return labelWorkRepository.labelWorkMngList(searchReq);
}
}

View File

@@ -11,13 +11,13 @@ import java.util.UUID;
public interface LabelAllocateRepositoryCustom {
List<Long> fetchNextIds(Long lastId, Long batchSize);
List<Long> fetchNextIds(Long lastId, Long batchSize, Long analUid);
void assignOwner(List<Long> ids, String userId);
void assignOwner(List<Long> ids, String userId, Long analUid);
List<LabelingAssignmentEntity> findAssignedLabelerList(Long analUid);
Long findLabelUnAssignedCnt(Long analUid);
Long findLabelUnAssignedCnt(Long analUid, Integer stage);
void assignInspector(UUID assignmentUid, String userId);

View File

@@ -44,16 +44,25 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
@PersistenceContext private EntityManager em;
@Override
public List<Long> fetchNextIds(Long lastId, Long batchSize) {
public List<Long> fetchNextIds(Long lastId, Long batchSize, Long analUid) {
// analUid로 분석 정보 조회
MapSheetAnalEntity analEntity =
queryFactory
.selectFrom(mapSheetAnalEntity)
.where(mapSheetAnalEntity.id.eq(analUid))
.fetchOne();
if (Objects.isNull(analEntity)) {
throw new EntityNotFoundException("MapSheetAnalEntity not found for analUid: " + analUid);
}
return queryFactory
.select(mapSheetAnalDataInferenceGeomEntity.geoUid)
.from(mapSheetAnalDataInferenceGeomEntity)
.where(
// mapSheetAnalDataGeomEntity.pnu.isNotNull(), //TODO: Mockup 진행 이후 확인하기
lastId == null ? null : mapSheetAnalDataInferenceGeomEntity.geoUid.gt(lastId),
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(2022),
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(2024),
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(analEntity.getCompareYyyy()),
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(analEntity.getTargetYyyy()),
mapSheetAnalDataInferenceGeomEntity.labelState.isNull())
.orderBy(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.asc())
.limit(batchSize)
@@ -61,7 +70,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
}
@Override
public void assignOwner(List<Long> ids, String userId) {
public void assignOwner(List<Long> ids, String userId, Long analUid) {
// data_geom 테이블에 label state 를 ASSIGNED 로 update
queryFactory
@@ -87,7 +96,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.setParameter(3, userId)
.setParameter(4, LabelState.ASSIGNED.getId())
.setParameter(5, "")
.setParameter(6, 3)
.setParameter(6, analUid)
.executeUpdate();
}
@@ -108,7 +117,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
}
@Override
public Long findLabelUnAssignedCnt(Long analUid) {
public Long findLabelUnAssignedCnt(Long analUid, Integer stage) {
MapSheetAnalEntity entity =
queryFactory
.selectFrom(mapSheetAnalEntity)
@@ -116,7 +125,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.fetchOne();
if (Objects.isNull(entity)) {
throw new EntityNotFoundException();
throw new EntityNotFoundException("MapSheetAnalEntity not found for analUid: " + analUid);
}
return queryFactory
@@ -125,7 +134,7 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
.where(
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(entity.getCompareYyyy()),
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(entity.getTargetYyyy()),
mapSheetAnalDataInferenceGeomEntity.stage.eq(4), // TODO: 회차 컬럼을 가져와야 할 듯?
mapSheetAnalDataInferenceGeomEntity.stage.eq(stage),
mapSheetAnalDataInferenceGeomEntity.labelState.isNull())
.fetchOne();
}
@@ -149,7 +158,9 @@ public class LabelAllocateRepositoryImpl implements LabelAllocateRepositoryCusto
memberEntity.employeeNo,
memberEntity.name))
.from(memberEntity)
.where(memberEntity.userRole.eq(role), memberEntity.status.eq("ACTIVE"))
.where(
memberEntity.userRole.eq(role),
memberEntity.status.eq(com.kamco.cd.kamcoback.common.enums.StatusType.ACTIVE.getId()))
.orderBy(memberEntity.name.asc())
.fetch();
}

View File

@@ -4,5 +4,4 @@ import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataInferenceGeomEntit
import org.springframework.data.jpa.repository.JpaRepository;
public interface LabelWorkRepository
extends JpaRepository<MapSheetAnalDataInferenceGeomEntity, Long>,
LabelWorkRepositoryCustom {}
extends JpaRepository<MapSheetAnalDataInferenceGeomEntity, Long>, LabelWorkRepositoryCustom {}

View File

@@ -1,11 +1,7 @@
package com.kamco.cd.kamcoback.postgres.repository.label;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto.LabelWorkMng;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import java.util.List;
import java.util.UUID;
import org.springframework.data.domain.Page;
public interface LabelWorkRepositoryCustom {

View File

@@ -1,23 +1,11 @@
package com.kamco.cd.kamcoback.postgres.repository.label;
import static com.kamco.cd.kamcoback.postgres.entity.QLabelingAssignmentEntity.labelingAssignmentEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx5kEntity.mapInkx5kEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataInferenceEntity.mapSheetAnalDataInferenceEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataInferenceGeomEntity.mapSheetAnalDataInferenceGeomEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalEntity.mapSheetAnalEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetMngEntity.mapSheetMngEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetMngHstEntity.mapSheetMngHstEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMemberEntity.memberEntity;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.LabelState;
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.UserList;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto;
import com.kamco.cd.kamcoback.label.dto.LabelWorkDto.LabelWorkMng;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.ErrorDataDto;
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataGeomEntity;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalEntity;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.CaseBuilder;
@@ -25,16 +13,9 @@ import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.PersistenceContext;
import jakarta.validation.Valid;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
@@ -58,7 +39,6 @@ public class LabelWorkRepositoryImpl extends QuerydslRepositorySupport
this.queryFactory = queryFactory;
}
@Override
public Page<LabelWorkMng> labelWorkMngList(LabelWorkDto.LabelWorkMngSearchReq searchReq) {
@@ -72,66 +52,62 @@ public class LabelWorkRepositoryImpl extends QuerydslRepositorySupport
whereBuilder.and(mapSheetAnalDataInferenceEntity.targetYyyy.eq(searchReq.getDetectYyyy()));
}
//mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id)
// mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id)
whereSubBuilder.and(mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id));
whereSubBuilder.and(
mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id));
if (searchReq.getStrtDttm() != null && ! searchReq.getStrtDttm().isEmpty()) {
if (searchReq.getStrtDttm() != null && !searchReq.getStrtDttm().isEmpty()) {
whereSubBuilder.and(mapSheetAnalDataInferenceGeomEntity.labelStateDttm.isNotNull());
whereSubBuilder.and(
Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')", mapSheetAnalDataInferenceEntity.labelStateDttm)
.gt("2024-01-01")
);
Expressions.stringTemplate(
"to_char({0}, 'YYYY-MM-DD')", mapSheetAnalDataInferenceEntity.labelStateDttm)
.gt("2024-01-01"));
}
List<LabelWorkMng> foundContent =
queryFactory
.select(
Projections.constructor(
LabelWorkMng.class,
mapSheetAnalDataInferenceEntity.compareYyyy,
mapSheetAnalDataInferenceEntity.targetYyyy,
mapSheetAnalDataInferenceEntity.stage,
mapSheetAnalDataInferenceEntity.createdDttm.min(),
mapSheetAnalDataInferenceEntity.detectingCnt.sum(),
mapSheetAnalDataInferenceGeomEntity.dataUid.count(),
new CaseBuilder()
.when(mapSheetAnalDataInferenceGeomEntity.labelState.eq("STOP"))
.then(1L)
.otherwise(0L)
.sum(),
new CaseBuilder()
.when(mapSheetAnalDataInferenceGeomEntity.labelState.eq("LABEL_ING"))
.then(1L)
.otherwise(0L)
.sum(),
new CaseBuilder()
.when(mapSheetAnalDataInferenceGeomEntity.labelState.eq("LABEL_COMPLETE"))
.then(1L)
.otherwise(0L)
.sum(),
mapSheetAnalDataInferenceGeomEntity.labelStateDttm.min()
))
.from(mapSheetAnalDataInferenceEntity)
.leftJoin(mapSheetAnalDataInferenceGeomEntity)
.on(whereSubBuilder)
.where(whereBuilder)
.groupBy(
mapSheetAnalDataInferenceEntity.compareYyyy,
mapSheetAnalDataInferenceEntity.targetYyyy,
mapSheetAnalDataInferenceEntity.stage
)
.orderBy(mapSheetAnalDataInferenceEntity.targetYyyy.desc()
,mapSheetAnalDataInferenceEntity.stage.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
queryFactory
.select(
Projections.constructor(
LabelWorkMng.class,
mapSheetAnalDataInferenceEntity.compareYyyy,
mapSheetAnalDataInferenceEntity.targetYyyy,
mapSheetAnalDataInferenceEntity.stage,
mapSheetAnalDataInferenceEntity.createdDttm.min(),
mapSheetAnalDataInferenceEntity.detectingCnt.sum(),
mapSheetAnalDataInferenceGeomEntity.dataUid.count(),
new CaseBuilder()
.when(mapSheetAnalDataInferenceGeomEntity.labelState.eq("STOP"))
.then(1L)
.otherwise(0L)
.sum(),
new CaseBuilder()
.when(mapSheetAnalDataInferenceGeomEntity.labelState.eq("LABEL_ING"))
.then(1L)
.otherwise(0L)
.sum(),
new CaseBuilder()
.when(mapSheetAnalDataInferenceGeomEntity.labelState.eq("LABEL_COMPLETE"))
.then(1L)
.otherwise(0L)
.sum(),
mapSheetAnalDataInferenceGeomEntity.labelStateDttm.min()))
.from(mapSheetAnalDataInferenceEntity)
.leftJoin(mapSheetAnalDataInferenceGeomEntity)
.on(whereSubBuilder)
.where(whereBuilder)
.groupBy(
mapSheetAnalDataInferenceEntity.compareYyyy,
mapSheetAnalDataInferenceEntity.targetYyyy,
mapSheetAnalDataInferenceEntity.stage)
.orderBy(
mapSheetAnalDataInferenceEntity.targetYyyy.desc(),
mapSheetAnalDataInferenceEntity.stage.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
/*
Long countQuery =