라벨할당 임시 커밋
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.label.LabelAllocateRepository;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -15,7 +18,19 @@ public class LabelAllocateCoreService {
|
||||
return labelAllocateRepository.fetchNextIds(lastId, batchSize);
|
||||
}
|
||||
|
||||
public Long assignOwner(List<Long> ids, Long userId) {
|
||||
return labelAllocateRepository.assignOwner(ids, userId);
|
||||
public void assignOwner(List<Long> ids, String userId) {
|
||||
labelAllocateRepository.assignOwner(ids, userId);
|
||||
}
|
||||
|
||||
public List<LabelAllocateDto.Basic> findAssignedLabelerList(Long analUid) {
|
||||
return labelAllocateRepository.findAssignedLabelerList(analUid).stream().map(LabelingAssignmentEntity::toDto).toList();
|
||||
}
|
||||
|
||||
public Long findLabelUnAssignedCnt(Long analUid) {
|
||||
return labelAllocateRepository.findLabelUnAssignedCnt(analUid);
|
||||
}
|
||||
|
||||
public void assignInspector(UUID assignmentUid, String inspectorUid) {
|
||||
labelAllocateRepository.assignInspector(assignmentUid, inspectorUid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto;
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "tb_labeling_assignment")
|
||||
public class LabelingAssignmentEntity extends CommonDateEntity {
|
||||
|
||||
@Id
|
||||
@Column(name = "assignment_uid")
|
||||
private UUID assignmentUid;
|
||||
|
||||
@Column(name = "inference_geom_uid")
|
||||
private Long inferenceGeomUid;
|
||||
|
||||
@Column(name = "worker_uid")
|
||||
private String workerUid;
|
||||
|
||||
@Column(name = "inspector_uid")
|
||||
private String inspectorUid;
|
||||
|
||||
@Column(name = "work_state")
|
||||
private String workState;
|
||||
|
||||
@Column(name = "stagnation_yn")
|
||||
private Character stagnationYn;
|
||||
|
||||
@Column(name = "assign_group_id")
|
||||
private String assignGroupId;
|
||||
|
||||
@Column(name = "learn_geom_uid")
|
||||
private Long learnGeomUid;
|
||||
|
||||
@Column(name = "anal_uid")
|
||||
private Long analUid;
|
||||
|
||||
public LabelAllocateDto.Basic toDto() {
|
||||
return new LabelAllocateDto.Basic(
|
||||
this.assignmentUid,
|
||||
this.inferenceGeomUid,
|
||||
this.workerUid,
|
||||
this.inspectorUid,
|
||||
this.workState,
|
||||
this.stagnationYn,
|
||||
this.assignGroupId,
|
||||
this.learnGeomUid,
|
||||
this.analUid,
|
||||
super.getCreatedDate(),
|
||||
super.getModifiedDate());
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,18 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.label;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.LabelingAssignmentEntity;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface LabelAllocateRepositoryCustom {
|
||||
|
||||
List<Long> fetchNextIds(Long lastId, int batchSize);
|
||||
|
||||
Long assignOwner(List<Long> ids, Long userId);
|
||||
void assignOwner(List<Long> ids, String userId);
|
||||
|
||||
List<LabelingAssignmentEntity> findAssignedLabelerList(Long analUid);
|
||||
|
||||
Long findLabelUnAssignedCnt(Long analUid);
|
||||
|
||||
void assignInspector(UUID assignmentUid, String userId);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
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.QMapSheetAnalDataInferenceGeomEntity.mapSheetAnalDataInferenceGeomEntity;
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalEntity.mapSheetAnalEntity;
|
||||
|
||||
import com.kamco.cd.kamcoback.label.dto.LabelAllocateDto.LabelState;
|
||||
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.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 java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@@ -14,11 +24,14 @@ import org.springframework.stereotype.Repository;
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class LabelAllocateRepositoryImpl extends QuerydslRepositorySupport
|
||||
implements LabelAllocateRepositoryCustom {
|
||||
implements LabelAllocateRepositoryCustom {
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
public LabelAllocateRepositoryImpl(JPAQueryFactory queryFactory) {
|
||||
super(MapSheetAnalDataGeomEntity.class);
|
||||
this.queryFactory = queryFactory;
|
||||
@@ -26,26 +39,100 @@ public class LabelAllocateRepositoryImpl extends QuerydslRepositorySupport
|
||||
|
||||
@Override
|
||||
public List<Long> fetchNextIds(Long lastId, int batchSize) {
|
||||
|
||||
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.labelerUid.isNull())
|
||||
.orderBy(mapSheetAnalDataInferenceGeomEntity.geoUid.asc())
|
||||
.limit(batchSize)
|
||||
.fetch();
|
||||
.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.labelState.isNull())
|
||||
.orderBy(mapSheetAnalDataInferenceGeomEntity.geoUid.asc())
|
||||
.limit(batchSize)
|
||||
.fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long assignOwner(List<Long> ids, Long userId) {
|
||||
return queryFactory
|
||||
.update(mapSheetAnalDataInferenceGeomEntity)
|
||||
.set(mapSheetAnalDataInferenceGeomEntity.labelerUid, userId)
|
||||
.where(mapSheetAnalDataInferenceGeomEntity.geoUid.in(ids))
|
||||
public void assignOwner(List<Long> ids, String userId) {
|
||||
|
||||
//data_geom 테이블에 label state 를 ASSIGNED 로 update
|
||||
queryFactory
|
||||
.update(mapSheetAnalDataInferenceGeomEntity)
|
||||
.set(mapSheetAnalDataInferenceGeomEntity.labelState, LabelState.ASSIGNED.getId())
|
||||
.where(mapSheetAnalDataInferenceGeomEntity.geoUid.in(ids))
|
||||
.execute();
|
||||
|
||||
//라벨러 할당 테이블에 insert
|
||||
for (Long geoUid : ids) {
|
||||
queryFactory
|
||||
.insert(labelingAssignmentEntity)
|
||||
.columns(
|
||||
labelingAssignmentEntity.assignmentUid,
|
||||
labelingAssignmentEntity.inferenceGeomUid,
|
||||
labelingAssignmentEntity.workerUid,
|
||||
labelingAssignmentEntity.workState,
|
||||
labelingAssignmentEntity.assignGroupId,
|
||||
labelingAssignmentEntity.analUid
|
||||
)
|
||||
.values(
|
||||
UUID.randomUUID(),
|
||||
geoUid,
|
||||
userId,
|
||||
LabelState.ASSIGNED.getId(),
|
||||
"", //TODO: 도엽번호
|
||||
3
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
|
||||
em.flush();
|
||||
em.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LabelingAssignmentEntity> findAssignedLabelerList(Long analUid) {
|
||||
return queryFactory
|
||||
.selectFrom(labelingAssignmentEntity)
|
||||
.where(
|
||||
labelingAssignmentEntity.analUid.eq(analUid),
|
||||
labelingAssignmentEntity.workState.eq(LabelState.ASSIGNED.getId()),
|
||||
labelingAssignmentEntity.inspectorUid.isNull()
|
||||
)
|
||||
.orderBy(labelingAssignmentEntity.workerUid.asc())
|
||||
.fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long findLabelUnAssignedCnt(Long analUid) {
|
||||
MapSheetAnalEntity entity = queryFactory.selectFrom(mapSheetAnalEntity).where(mapSheetAnalEntity.id.eq(analUid)).fetchOne();
|
||||
|
||||
if (Objects.isNull(entity)) {
|
||||
throw new EntityNotFoundException();
|
||||
}
|
||||
|
||||
return queryFactory
|
||||
.select(mapSheetAnalDataInferenceGeomEntity.geoUid.count())
|
||||
.from(mapSheetAnalDataInferenceGeomEntity)
|
||||
.where(
|
||||
mapSheetAnalDataInferenceGeomEntity.compareYyyy.eq(entity.getCompareYyyy()),
|
||||
mapSheetAnalDataInferenceGeomEntity.targetYyyy.eq(entity.getTargetYyyy()),
|
||||
mapSheetAnalDataInferenceGeomEntity.stage.eq(4), //TODO: 회차 컬럼을 가져와야 할 듯?
|
||||
mapSheetAnalDataInferenceGeomEntity.labelState.isNull()
|
||||
)
|
||||
.fetchOne()
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignInspector(UUID assignmentUid, String inspectorUid) {
|
||||
queryFactory
|
||||
.update(labelingAssignmentEntity)
|
||||
.set(labelingAssignmentEntity.inspectorUid, inspectorUid)
|
||||
.where(
|
||||
labelingAssignmentEntity.assignmentUid.eq(assignmentUid)
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user