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