develop #18
@@ -24,8 +24,8 @@ public class ListEventHistSurveyMetaDto {
|
|||||||
@Schema(description = "입력 action 코드")
|
@Schema(description = "입력 action 코드")
|
||||||
private ListEventHistorySurveyType action;
|
private ListEventHistorySurveyType action;
|
||||||
|
|
||||||
@Schema(description = "프로젝트 고유번호")
|
@Schema(description = "프로젝트 설문 고유번호")
|
||||||
private String pid;
|
private String psidx;
|
||||||
|
|
||||||
@Schema(description = "리스트 고유번호")
|
@Schema(description = "리스트 고유번호")
|
||||||
private String sid;
|
private String sid;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import com.kri.contact.server.persistence.entity.QTPrjctAssignUserEntity;
|
|||||||
import com.kri.contact.server.persistence.entity.QTUserEntity;
|
import com.kri.contact.server.persistence.entity.QTUserEntity;
|
||||||
import com.querydsl.core.BooleanBuilder;
|
import com.querydsl.core.BooleanBuilder;
|
||||||
import com.querydsl.core.Tuple;
|
import com.querydsl.core.Tuple;
|
||||||
import com.querydsl.core.types.dsl.CaseBuilder;
|
|
||||||
import com.querydsl.core.types.dsl.NumberExpression;
|
import com.querydsl.core.types.dsl.NumberExpression;
|
||||||
import com.querydsl.jpa.impl.JPAQuery;
|
import com.querydsl.jpa.impl.JPAQuery;
|
||||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
@@ -78,66 +77,53 @@ public class AssignSummaryQuerySupport {
|
|||||||
public ScopeCountRow findFieldworkScopeCounts(
|
public ScopeCountRow findFieldworkScopeCounts(
|
||||||
Long prjctIdx,
|
Long prjctIdx,
|
||||||
Short assignType,
|
Short assignType,
|
||||||
Collection<Integer> allowedUserRoles,
|
|
||||||
Collection<String> companyIds,
|
Collection<String> companyIds,
|
||||||
boolean externalUser
|
boolean externalUser
|
||||||
) {
|
) {
|
||||||
QTListEntity list = QTListEntity.tListEntity;
|
QTListEntity list = QTListEntity.tListEntity;
|
||||||
QTListAssignUserEntity listAssign = new QTListAssignUserEntity("summaryScopeUserAssign");
|
QTListAssignUserEntity listAssign = new QTListAssignUserEntity("summaryScopeUserAssign");
|
||||||
QTUserEntity assignedUser = new QTUserEntity("summaryScopeAssignedUser");
|
|
||||||
QTListAssignCmpnEntity companyAssign = new QTListAssignCmpnEntity("summaryScopeCompanyAssign");
|
QTListAssignCmpnEntity companyAssign = new QTListAssignCmpnEntity("summaryScopeCompanyAssign");
|
||||||
boolean companyScoped = companyIds != null && !companyIds.isEmpty();
|
|
||||||
|
|
||||||
NumberExpression<Long> totalCount = list.id.sid.count();
|
var totalQuery = jpaQueryFactory
|
||||||
NumberExpression<Long> unassignedCount = new CaseBuilder()
|
.select(list.id.sid.count())
|
||||||
.when(assignedUser.userId.isNull())
|
|
||||||
.then(1L)
|
|
||||||
.otherwise(0L)
|
|
||||||
.sumLong();
|
|
||||||
|
|
||||||
JPAQuery<Tuple> query = jpaQueryFactory
|
|
||||||
.select(totalCount, unassignedCount)
|
|
||||||
.from(list);
|
.from(list);
|
||||||
|
|
||||||
if (externalUser) {
|
if (externalUser) {
|
||||||
query.join(companyAssign).on(
|
totalQuery.join(companyAssign).on(
|
||||||
companyAssign.prjctIdx.eq(list.id.prjctIdx),
|
companyAssign.prjctIdx.eq(list.id.prjctIdx),
|
||||||
companyAssign.sid.eq(list.id.sid),
|
companyAssign.sid.eq(list.id.sid),
|
||||||
companyAssign.cmpnId.in(companyIds)
|
companyAssign.cmpnId.in(companyIds)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
long totalCount = safeLong(totalQuery
|
||||||
|
.where(list.id.prjctIdx.eq(prjctIdx))
|
||||||
|
.fetchOne());
|
||||||
|
|
||||||
query.leftJoin(listAssign).on(
|
QTListEntity unassignedList = new QTListEntity("summaryUnassignedList");
|
||||||
listAssign.prjctIdx.eq(list.id.prjctIdx),
|
QTListAssignCmpnEntity unassignedCompany =
|
||||||
listAssign.sid.eq(list.id.sid),
|
new QTListAssignCmpnEntity("summaryUnassignedCompany");
|
||||||
|
var unassignedQuery = jpaQueryFactory
|
||||||
|
.select(unassignedList.id.sid.count())
|
||||||
|
.from(unassignedList);
|
||||||
|
if (externalUser) {
|
||||||
|
unassignedQuery.join(unassignedCompany).on(
|
||||||
|
unassignedCompany.prjctIdx.eq(unassignedList.id.prjctIdx),
|
||||||
|
unassignedCompany.sid.eq(unassignedList.id.sid),
|
||||||
|
unassignedCompany.cmpnId.in(companyIds)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
unassignedQuery.leftJoin(listAssign).on(
|
||||||
|
listAssign.prjctIdx.eq(unassignedList.id.prjctIdx),
|
||||||
|
listAssign.sid.eq(unassignedList.id.sid),
|
||||||
listAssign.assignRole.eq(assignType)
|
listAssign.assignRole.eq(assignType)
|
||||||
);
|
);
|
||||||
|
long unassignedCount = safeLong(unassignedQuery
|
||||||
|
.where(
|
||||||
|
unassignedList.id.prjctIdx.eq(prjctIdx),
|
||||||
|
listAssign.listAssignIdx.isNull()
|
||||||
|
)
|
||||||
|
.fetchOne());
|
||||||
|
|
||||||
BooleanBuilder userJoin = new BooleanBuilder()
|
return new ScopeCountRow(totalCount, unassignedCount);
|
||||||
.and(assignedUser.userId.eq(listAssign.userId))
|
|
||||||
.and(assignedUser.del.isFalse())
|
|
||||||
.and(assignedUser.userRole.in(allowedUserRoles));
|
|
||||||
if (externalUser) {
|
|
||||||
userJoin.and(assignedUser.userCmpn.in(companyIds));
|
|
||||||
}
|
|
||||||
query.leftJoin(assignedUser).on(userJoin);
|
|
||||||
|
|
||||||
BooleanBuilder predicate = new BooleanBuilder(list.id.prjctIdx.eq(prjctIdx));
|
|
||||||
if (!externalUser && companyScoped) {
|
|
||||||
predicate.and(
|
|
||||||
assignedUser.userId.isNull()
|
|
||||||
.or(assignedUser.userCmpn.in(companyIds))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Tuple row = query.where(predicate).fetchOne();
|
|
||||||
if (row == null) {
|
|
||||||
return new ScopeCountRow(0L, 0L);
|
|
||||||
}
|
|
||||||
return new ScopeCountRow(
|
|
||||||
safeLong(row.get(totalCount)),
|
|
||||||
safeLong(row.get(unassignedCount))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FieldworkAssignSummaryRow> findFieldworkAssignees(
|
public List<FieldworkAssignSummaryRow> findFieldworkAssignees(
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ public interface ListEventHistRepository extends JpaRepository<TListEventHistEnt
|
|||||||
String sid
|
String sid
|
||||||
);
|
);
|
||||||
|
|
||||||
|
boolean existsByPrjctIdxAndPrjctSurveyIdxAndSidAndEventTyAndResultCdNot(
|
||||||
|
Long prjctIdx,
|
||||||
|
Long prjctSurveyIdx,
|
||||||
|
String sid,
|
||||||
|
Short eventTy,
|
||||||
|
Integer resultCd
|
||||||
|
);
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
select h
|
select h
|
||||||
from TListEventHistEntity h
|
from TListEventHistEntity h
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ public class AssignService {
|
|||||||
ScopeCountRow scopeCounts = assignSummaryQuerySupport.findFieldworkScopeCounts(
|
ScopeCountRow scopeCounts = assignSummaryQuerySupport.findFieldworkScopeCounts(
|
||||||
prjctIdx,
|
prjctIdx,
|
||||||
validatedAssignType,
|
validatedAssignType,
|
||||||
allowedUserRoles,
|
|
||||||
companyIds,
|
companyIds,
|
||||||
externalUser
|
externalUser
|
||||||
);
|
);
|
||||||
@@ -131,10 +130,8 @@ public class AssignService {
|
|||||||
.build())
|
.build())
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
long responseAssignedCount = assignees.stream()
|
if (scopeCounts.unassignedCount() < 0
|
||||||
.mapToLong(FieldworkAssignSummaryItemDto::getAssignedCount)
|
|| scopeCounts.unassignedCount() > scopeCounts.totalCount()) {
|
||||||
.sum();
|
|
||||||
if (scopeCounts.totalCount() != scopeCounts.unassignedCount() + responseAssignedCount) {
|
|
||||||
throw BusinessException.internalError("필드워커 배정 현황을 계산할 수 없습니다.");
|
throw BusinessException.internalError("필드워커 배정 현황을 계산할 수 없습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.kri.common.feature.util.CollectionUtil;
|
import com.kri.common.feature.util.CollectionUtil;
|
||||||
import com.kri.common.feature.web.BusinessException;
|
import com.kri.common.feature.web.BusinessException;
|
||||||
import com.kri.contact.server.common.consts.ContactConstant;
|
import com.kri.contact.server.common.consts.ContactConstant;
|
||||||
|
import com.kri.contact.server.common.enums.ListEventHistorySurveyType;
|
||||||
import com.kri.contact.server.common.enums.ListHeaderGrade;
|
import com.kri.contact.server.common.enums.ListHeaderGrade;
|
||||||
import com.kri.contact.server.common.enums.ListHeaderType;
|
import com.kri.contact.server.common.enums.ListHeaderType;
|
||||||
import com.kri.contact.server.common.enums.ListIsUse;
|
import com.kri.contact.server.common.enums.ListIsUse;
|
||||||
@@ -200,6 +201,17 @@ public class ListUpdateService {
|
|||||||
validateEventHistoryTarget(survey.getPrjctIdx(), request.getSid());
|
validateEventHistoryTarget(survey.getPrjctIdx(), request.getSid());
|
||||||
applySurveySnapshot(request, survey);
|
applySurveySnapshot(request, survey);
|
||||||
|
|
||||||
|
if (request.getAction() == ListEventHistorySurveyType.START
|
||||||
|
&& listEventHistRepository.existsByPrjctIdxAndPrjctSurveyIdxAndSidAndEventTyAndResultCdNot(
|
||||||
|
survey.getPrjctIdx(),
|
||||||
|
request.getPrjctSurveyIdx(),
|
||||||
|
request.getSid(),
|
||||||
|
ResultCodeType.SURVEY.getCode(),
|
||||||
|
ListEventHistorySurveyType.START.getCode().intValue()
|
||||||
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
listEventHistRepository.save(TListEventHistEntity.fromSurveyHistory(
|
listEventHistRepository.save(TListEventHistEntity.fromSurveyHistory(
|
||||||
request,
|
request,
|
||||||
survey.getPrjctIdx(),
|
survey.getPrjctIdx(),
|
||||||
|
|||||||
@@ -69,8 +69,14 @@ public class ReserveService {
|
|||||||
boolean requestPast,
|
boolean requestPast,
|
||||||
LocalDateTime now
|
LocalDateTime now
|
||||||
) {
|
) {
|
||||||
LocalDateTime startDt = requestPast ? now.minusMinutes(NOTIFICATION_RANGE_MINUTES) : now;
|
LocalDateTime currentMinute = now.withSecond(0).withNano(0);
|
||||||
LocalDateTime endDt = now.plusMinutes(NOTIFICATION_RANGE_MINUTES);
|
LocalDateTime startDt = requestPast
|
||||||
|
? currentMinute.minusMinutes(NOTIFICATION_RANGE_MINUTES)
|
||||||
|
: currentMinute;
|
||||||
|
LocalDateTime endDt = currentMinute
|
||||||
|
.plusMinutes(NOTIFICATION_RANGE_MINUTES)
|
||||||
|
.withSecond(59)
|
||||||
|
.withNano(999_999_999);
|
||||||
return toDtosWithProjectNames(
|
return toDtosWithProjectNames(
|
||||||
listReserveRepository.findNotifications(userId, startDt, endDt)
|
listReserveRepository.findNotifications(userId, startDt, endDt)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user