260722_01_ENH: 버그 수정 및 개선 사항 수정
This commit is contained in:
@@ -13,8 +13,9 @@ import lombok.NoArgsConstructor;
|
||||
public final class ContactConstant {
|
||||
public static final int INSERT_CHUNK_SIZE = 1_000;
|
||||
public static final int LIST_SELECT_CHUNK_SIZE = 1_000;
|
||||
public static final String REQUEST_SERVICE = "kri-contact";
|
||||
public static final String SYSTEM_USER_NAME = "SYSTEM";
|
||||
public static final String DEFAULT_COMPANY_NAME = "KRI";
|
||||
public static final String DEFAULT_COMPANY_NAME = "KRic";
|
||||
public static final String DEFAULT_USER_TEAM = "S101";
|
||||
public static final String DEFAULT_CALLER_TELNUM = "0234155100";
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public enum ResultCodeType implements CodeEnum<Short> {
|
||||
|
||||
CONTACT((short) 21), // 컨택 결과코드
|
||||
INTERVIEW((short) 22), // 면접 결과코드
|
||||
SURVEY((short) 99); // 설문 결과코드
|
||||
SURVEY((short) 91); // 설문 결과코드
|
||||
|
||||
private final Short code;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import lombok.RequiredArgsConstructor;
|
||||
@Schema(description = "설문 타입")
|
||||
public enum SurveyType implements CodeEnum<Short> {
|
||||
|
||||
NONE((short) 0), // 없음
|
||||
KON((short) 1), // KON
|
||||
KIWI((short) 2), // KIWI
|
||||
EXTERNAL((short) 99); // 외부
|
||||
|
||||
35
src/main/java/com/kri/contact/server/common/external/notihub/ChannelType.java
vendored
Normal file
35
src/main/java/com/kri/contact/server/common/external/notihub/ChannelType.java
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.kri.contact.server.common.external.notihub;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter(onMethod_ = @JsonValue)
|
||||
@RequiredArgsConstructor
|
||||
public enum ChannelType implements CodeEnum<Short> {
|
||||
|
||||
EMAIL((short) 1),
|
||||
SMS((short) 2),
|
||||
KKO_AT((short) 3);
|
||||
|
||||
private final Short code;
|
||||
|
||||
ChannelType(CodeEnum<Short> source) {
|
||||
this.code = source.getCode();
|
||||
}
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ChannelType fromCode(Short code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (ChannelType s : values()) {
|
||||
if (s.code == code) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ChannelType code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.kri.common.feature.http.ExternalApiResponse;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -64,6 +65,26 @@ public class NotiHubApiClient {
|
||||
return sendBulk("/send-sms/bulk", request);
|
||||
}
|
||||
|
||||
public List<NotiHubSendResultLastWithSidDto> getLastSendResults(
|
||||
ChannelType channelTy,
|
||||
String reqstSvc,
|
||||
String prjctCd,
|
||||
List<String> sids
|
||||
) {
|
||||
String url = notiHubBaseUrl + "/report/last/send/" + channelTy.getCode() + "/" + reqstSvc + "/" + prjctCd;
|
||||
try {
|
||||
ExternalApiResponse response = post(url, sids);
|
||||
return objectMapper.readValue(
|
||||
response.getBody(),
|
||||
objectMapper.getTypeFactory()
|
||||
.constructCollectionType(List.class, NotiHubSendResultLastWithSidDto.class)
|
||||
);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw BusinessException.badRequest("NOTI_HUB_RESPONSE_PARSE_FAILED", "noti-hub 응답을 해석할 수 없습니다.")
|
||||
.with("url", url);
|
||||
}
|
||||
}
|
||||
|
||||
private void postSingle(String path, NotiHubSendRequestSingleDto request, RequestUserContext ctx) {
|
||||
post(urlWithContext(path, ctx), request);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.kri.contact.server.common.external.notihub;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Schema(description = "NotiHubSendResultLastWithSidDto")
|
||||
public class NotiHubSendResultLastWithSidDto {
|
||||
|
||||
@Schema(description = "sid")
|
||||
private String sid;
|
||||
|
||||
@Schema(description = "lastResultCode")
|
||||
private Integer lastResultCode;
|
||||
|
||||
@Schema(description = "lastResultLabel")
|
||||
private String lastResultLabel;
|
||||
|
||||
@Schema(description = "lastResultViewLabel")
|
||||
private String lastResultViewLabel;
|
||||
|
||||
@Schema(description = "lastSendDt")
|
||||
private LocalDateTime lastSendDt;
|
||||
|
||||
@Schema(description = "totalSendCount")
|
||||
private Integer totalSendCount;
|
||||
}
|
||||
88
src/main/java/com/kri/contact/server/common/external/shorturl/ShortUrlApiClient.java
vendored
Normal file
88
src/main/java/com/kri/contact/server/common/external/shorturl/ShortUrlApiClient.java
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
package com.kri.contact.server.common.external.shorturl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.common.feature.http.ExternalApiClient;
|
||||
import com.kri.common.feature.http.ExternalApiResponse;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ShortUrlApiClient {
|
||||
|
||||
private final ExternalApiClient externalApiClient = new ExternalApiClient();
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Value("${kri.api-url.short-url}")
|
||||
private String shortUrlBaseUrl;
|
||||
|
||||
@Value("${kri.auth.apikey.header-name:X-API-Key}")
|
||||
private String apiKeyHeaderName;
|
||||
|
||||
@Value("${kri.auth.apikey.key}")
|
||||
private String apiKey;
|
||||
|
||||
public Optional<String> createShortUrl(String orgUrl, RequestUserContext ctx) {
|
||||
String url = urlWithContext("/short-url/create", ctx);
|
||||
ShortUrlCreateRequestDto request = new ShortUrlCreateRequestDto(orgUrl, true);
|
||||
try {
|
||||
ExternalApiResponse response = externalApiClient.put(
|
||||
url,
|
||||
headers(),
|
||||
objectMapper.writeValueAsString(request)
|
||||
);
|
||||
String shortUrl = normalizeResponse(response.getBody());
|
||||
if (shortUrl == null || shortUrl.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(shortUrl);
|
||||
} catch (Exception e) {
|
||||
log.warn("Short URL creation failed. url={}, orgUrl={}", url, orgUrl, e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeResponse(String body) throws JsonProcessingException {
|
||||
if (body == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = body.trim();
|
||||
if (trimmed.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (trimmed.startsWith("\"") && trimmed.endsWith("\"")) {
|
||||
return objectMapper.readValue(trimmed, String.class);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
private String urlWithContext(String path, RequestUserContext ctx) {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(shortUrlBaseUrl + path);
|
||||
if (ctx != null) {
|
||||
builder.queryParam("userId", ctx.getUserId());
|
||||
builder.queryParam("userCmpn", ctx.getUserCmpn());
|
||||
builder.queryParam("userTeam", ctx.getUserTeam());
|
||||
builder.queryParam("userName", ctx.getUserName());
|
||||
builder.queryParam("userRole", ctx.getUserRole());
|
||||
builder.queryParam("clientIp", ctx.getClientIp());
|
||||
builder.queryParam("authenticated", ctx.isAuthenticated());
|
||||
}
|
||||
return builder.build().toUriString();
|
||||
}
|
||||
|
||||
private Map<String, String> headers() {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put(apiKeyHeaderName, apiKey);
|
||||
headers.put("Content-Type", "application/json");
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
12
src/main/java/com/kri/contact/server/common/external/shorturl/ShortUrlCreateRequestDto.java
vendored
Normal file
12
src/main/java/com/kri/contact/server/common/external/shorturl/ShortUrlCreateRequestDto.java
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.kri.contact.server.common.external.shorturl;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ShortUrlCreateRequestDto {
|
||||
|
||||
private String orgUrl;
|
||||
private boolean useParam;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -33,6 +34,28 @@ public class ListCallHistController {
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
return listCallHistService.saveCallHistory(prjctIdx, sid, request, ctx.getUserId(), now);
|
||||
return listCallHistService.saveCallHistory(
|
||||
prjctIdx,
|
||||
sid,
|
||||
request,
|
||||
ctx.getUserId(),
|
||||
ctx.getUserCmpn(),
|
||||
ctx.getUserRole(),
|
||||
now
|
||||
);
|
||||
}
|
||||
|
||||
@Operation(summary = "Find list call history by agent session")
|
||||
@GetMapping("/session/{agentSessionId}")
|
||||
public ListCallHistDto findByAgentSessionId(
|
||||
@PathVariable String agentSessionId,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return listCallHistService.findByAgentSessionId(
|
||||
agentSessionId,
|
||||
ctx.getUserId(),
|
||||
ctx.getUserCmpn(),
|
||||
ctx.getUserRole()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +199,18 @@ public class ListController {
|
||||
return buildZipResponse(projectInfoDto.getPrjctName() + " item_files.zip", bytes);
|
||||
}
|
||||
|
||||
@Operation(summary = "리스트 단건 파일 다운로드")
|
||||
@GetMapping("/item-file/download/{prjctIdx}/{sid}/{listHderId}")
|
||||
public ResponseEntity<byte[]> downloadOneItemFile(
|
||||
@PathVariable Long prjctIdx,
|
||||
@PathVariable Integer sid,
|
||||
@PathVariable Integer listHderId
|
||||
) {
|
||||
getProjectOrThrow(prjctIdx);
|
||||
ListUploadFileInfoDto file = listDownloadService.downloadItemFile(prjctIdx, sid, listHderId);
|
||||
return buildFileResponse(file.getFileName(), file.getBytes());
|
||||
}
|
||||
|
||||
@Operation(summary = "리스트 초기화")
|
||||
@DeleteMapping("/{prjctIdx}")
|
||||
public int resetList(
|
||||
@@ -244,4 +256,14 @@ public class ListController {
|
||||
.contentType(MediaType.parseMediaType("application/zip"))
|
||||
.body(bytes);
|
||||
}
|
||||
|
||||
private ResponseEntity<byte[]> buildFileResponse(String fileName, byte[] bytes) {
|
||||
String contentDisposition = "attachment; filename*=UTF-8''" +
|
||||
URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20");
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,8 @@ public class ListHistoryController {
|
||||
request,
|
||||
ctx.getClientIp(),
|
||||
ctx.getUserId(),
|
||||
ctx.getUserCmpn(),
|
||||
ctx.getUserRole(),
|
||||
now
|
||||
);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ProjectController {
|
||||
);
|
||||
req.getProjectInfo().setContactSenario(newHtml);
|
||||
|
||||
projectService.updateProject(prjctIdx, req, ctx.getUserId(), now);
|
||||
projectService.updateProject(prjctIdx, req, ctx.getUserId(), now, ctx);
|
||||
|
||||
systemEventLogService.writeUpdateProject(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx,
|
||||
req);
|
||||
|
||||
@@ -11,23 +11,23 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "설문 결과 입력 Dto")
|
||||
@Schema(description = "설문 결과 입력 DTO")
|
||||
public class ListEventHistFromSurveyDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "입력 action 코드")
|
||||
@Schema(description = "설문 action 코드")
|
||||
private ListEventHistorySurveyType action;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "프로젝트 고유 번호")
|
||||
private Long prjctIdx;
|
||||
@Schema(description = "프로젝트 설문 고유번호")
|
||||
private Long prjctSurveyIdx;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "리스트 고유 번호")
|
||||
@Schema(description = "리스트 고유번호")
|
||||
private Integer sid;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "메타 데이터")
|
||||
@Valid
|
||||
@Schema(description = "메타 데이터")
|
||||
private ListEventHistSurveyMetaDto meta;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.kri.contact.server.common.enums.ListEventHistoryExternalEntryType;
|
||||
import com.kri.contact.server.common.enums.ListEventHistorySurveyType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -13,6 +15,7 @@ import lombok.Setter;
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "ListEventHistSurveyMetaDto")
|
||||
public class ListEventHistSurveyMetaDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "진입 유형")
|
||||
private ListEventHistoryExternalEntryType entryType;
|
||||
@@ -21,10 +24,10 @@ public class ListEventHistSurveyMetaDto {
|
||||
@Schema(description = "입력 action 코드")
|
||||
private ListEventHistorySurveyType action;
|
||||
|
||||
@Schema(description = "프로젝트 고유 번호")
|
||||
@Schema(description = "프로젝트 고유번호")
|
||||
private String pid;
|
||||
|
||||
@Schema(description = "리스트 고유 번호")
|
||||
@Schema(description = "리스트 고유번호")
|
||||
private String sid;
|
||||
|
||||
@Schema(description = "요청 클라이언트 IP 주소")
|
||||
@@ -45,9 +48,24 @@ public class ListEventHistSurveyMetaDto {
|
||||
@Schema(description = "요청 Origin 헤더")
|
||||
private String origin;
|
||||
|
||||
@Schema(description = "프록시 또는 로드밸런서를 통해 전달된 X-Forwarded-For 헤더")
|
||||
@Schema(description = "X-Forwarded-For 헤더")
|
||||
private String xForwardedFor;
|
||||
|
||||
@Schema(description = "프록시 표준 전달 정보인 Forwarded 헤더")
|
||||
@Schema(description = "Forwarded 헤더")
|
||||
private String forwarded;
|
||||
|
||||
@Schema(description = "설문 snapshot")
|
||||
private SurveySnapshot survey;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class SurveySnapshot {
|
||||
private Long prjctSurveyIdx;
|
||||
private String surveyName;
|
||||
private Short surveyTy;
|
||||
private String surveyPrjctCd;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
@@ -18,6 +17,8 @@ public class ListEventHistoryDto {
|
||||
private Short eventTy;
|
||||
@Schema(description = "prjctIdx")
|
||||
private Long prjctIdx;
|
||||
@Schema(description = "prjctSurveyIdx")
|
||||
private Long prjctSurveyIdx;
|
||||
@Schema(description = "sid")
|
||||
private Integer sid;
|
||||
@Schema(description = "resultCd")
|
||||
@@ -38,6 +39,7 @@ public class ListEventHistoryDto {
|
||||
.listEventHistIdx(entity.getListEventHistIdx())
|
||||
.eventTy(entity.getEventTy())
|
||||
.prjctIdx(entity.getPrjctIdx())
|
||||
.prjctSurveyIdx(entity.getPrjctSurveyIdx())
|
||||
.sid(entity.getSid())
|
||||
.resultCd(entity.getResultCd())
|
||||
.metaData(entity.getMetaData())
|
||||
|
||||
@@ -20,7 +20,7 @@ import lombok.Setter;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "리스트 필터 Dto")
|
||||
@Schema(description = "리스트 필터 DTO")
|
||||
public class ListFilterDto {
|
||||
|
||||
@NotNull
|
||||
@@ -47,6 +47,9 @@ public class ListFilterDto {
|
||||
@Schema(description = "List 결과값 필터 key: ResultCodeType code, value: result code list")
|
||||
private Map<ResultCodeType, Set<Integer>> resultCodeMap;
|
||||
|
||||
@Schema(description = "설문별 결과 필터 조건")
|
||||
private List<@Valid ListSurveyResultFilterConditionDto> surveyResultConditions;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "메모 필터 조건")
|
||||
private List<@Valid ListFilterConditionDto> memoConditions;
|
||||
@@ -63,6 +66,7 @@ public class ListFilterDto {
|
||||
.assignUserMap(Map.of())
|
||||
.assignConditions(List.of())
|
||||
.resultCodeMap(Map.of())
|
||||
.surveyResultConditions(List.of())
|
||||
.memoConditions(List.of())
|
||||
.otherItemConditions(List.of())
|
||||
.build();
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.kri.contact.server.common.enums.ListIsUse;
|
||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||
import com.kri.contact.server.service.ListSearchService.AssignValues;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -31,7 +32,7 @@ public class ListSearchWithFullResultDto extends ListSearchWithResultDto {
|
||||
AssignValues assignValues,
|
||||
ListContactResultDto contactResult,
|
||||
ListContactResultDto interviewResult,
|
||||
ListResultBaseDto surveyResult,
|
||||
List<ListSurveyResultDto> surveyResults,
|
||||
ListSendResultDto mailSendResult,
|
||||
ListSendResultDto smsSendResult
|
||||
) {
|
||||
@@ -49,7 +50,7 @@ public class ListSearchWithFullResultDto extends ListSearchWithResultDto {
|
||||
.itemList(itemList)
|
||||
.contactResult(contactResult)
|
||||
.interviewResult(interviewResult)
|
||||
.surveyResult(surveyResult)
|
||||
.surveyResults(surveyResults)
|
||||
.mailSendResult(mailSendResult)
|
||||
.smsSendResult(smsSendResult)
|
||||
.build();
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.kri.contact.server.common.enums.ListIsUse;
|
||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||
import com.kri.contact.server.service.ListSearchService.AssignValues;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -18,14 +19,15 @@ import lombok.experimental.SuperBuilder;
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "리스트 조회 기본 + 결과")
|
||||
public class ListSearchWithResultDto extends ListSearchBaseDto {
|
||||
|
||||
@Schema(description = "컨택 결과")
|
||||
private ListContactResultDto contactResult;
|
||||
|
||||
@Schema(description = "대면 면접 결과")
|
||||
private ListContactResultDto interviewResult;
|
||||
|
||||
@Schema(description = "온라인 설문 결과")
|
||||
private ListResultBaseDto surveyResult;
|
||||
@Schema(description = "설문 결과 목록")
|
||||
private List<ListSurveyResultDto> surveyResults;
|
||||
|
||||
public static ListSearchWithResultDto from(
|
||||
TListEntity entity,
|
||||
@@ -33,7 +35,7 @@ public class ListSearchWithResultDto extends ListSearchBaseDto {
|
||||
AssignValues assignValues,
|
||||
ListContactResultDto contactResult,
|
||||
ListContactResultDto interviewResult,
|
||||
ListResultBaseDto surveyResult
|
||||
List<ListSurveyResultDto> surveyResults
|
||||
) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
@@ -49,7 +51,7 @@ public class ListSearchWithResultDto extends ListSearchBaseDto {
|
||||
.itemList(itemList)
|
||||
.contactResult(contactResult)
|
||||
.interviewResult(interviewResult)
|
||||
.surveyResult(surveyResult)
|
||||
.surveyResults(surveyResults)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubSendResultLastWithSidDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -16,21 +16,23 @@ import lombok.experimental.SuperBuilder;
|
||||
@Schema(description = "발송 결과")
|
||||
public class ListSendResultDto extends ListResultBaseDto {
|
||||
|
||||
@Schema(description = "마지막 컨택/방문면접원")
|
||||
@Schema(description = "마지막 발송 결과 라벨")
|
||||
private String lastResultLabel;
|
||||
|
||||
/* Todo Noti hub로 부터 받아서 생성하는 static 메소드 필요
|
||||
public static ListSendResultDto from(TListEventHistEntity entity, String resultLabel, Integer attemptCount) {
|
||||
if (entity == null) {
|
||||
@Schema(description = "마지막 발송 결과 표시 라벨")
|
||||
private String lastResultViewLabel;
|
||||
|
||||
public static ListSendResultDto from(NotiHubSendResultLastWithSidDto dto) {
|
||||
if (dto == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ListSendResultDto.builder()
|
||||
.lastResultCd(entity.getResultCd() == null ? null : entity.getResultCd().shortValue())
|
||||
.lastResultDt(entity.getRegDt())
|
||||
.attemptCount(attemptCount)
|
||||
.lastResultLabel(resultLabel)
|
||||
.lastResultCd(dto.getLastResultCode() == null ? null : dto.getLastResultCode().shortValue())
|
||||
.lastResultDt(dto.getLastSendDt())
|
||||
.attemptCount(dto.getTotalSendCount())
|
||||
.lastResultLabel(dto.getLastResultLabel())
|
||||
.lastResultViewLabel(dto.getLastResultViewLabel())
|
||||
.build();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.contact.server.common.enums.SurveyType;
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctSurveyEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "설문 결과 정보")
|
||||
public class ListSurveyResultDto extends ListResultBaseDto {
|
||||
|
||||
@Schema(description = "프로젝트 설문 고유번호")
|
||||
private Long prjctSurveyIdx;
|
||||
|
||||
@Schema(description = "설문명")
|
||||
private String surveyName;
|
||||
|
||||
@Schema(description = "설문 타입")
|
||||
private SurveyType surveyTy;
|
||||
|
||||
public static ListSurveyResultDto from(
|
||||
TPrjctSurveyEntity survey,
|
||||
TListEventHistEntity entity,
|
||||
Integer attemptCount
|
||||
) {
|
||||
if (survey == null || entity == null) {
|
||||
return null;
|
||||
}
|
||||
return ListSurveyResultDto.builder()
|
||||
.prjctSurveyIdx(survey.getPrjctSurveyIdx())
|
||||
.surveyName(survey.getSurveyNm())
|
||||
.surveyTy(SurveyType.fromCode(survey.getSurveyTy()))
|
||||
.lastResultCd(entity.getResultCd() == null ? null : entity.getResultCd().shortValue())
|
||||
.lastResultDt(entity.getRegDt())
|
||||
.attemptCount(attemptCount)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "설문별 결과 필터 조건")
|
||||
public class ListSurveyResultFilterConditionDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "프로젝트 설문 고유번호")
|
||||
private Long prjctSurveyIdx;
|
||||
|
||||
@NotEmpty
|
||||
@Schema(description = "설문 결과 코드 목록")
|
||||
private Set<Integer> resultCodes;
|
||||
}
|
||||
@@ -2,13 +2,15 @@ package com.kri.contact.server.dto.project;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.kri.contact.server.common.enums.ProjectStatus;
|
||||
import com.kri.contact.server.common.enums.SurveyType;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
@@ -24,7 +26,7 @@ import lombok.Setter;
|
||||
public class ProjectInfoDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "프로젝트 고유 번호")
|
||||
@Schema(description = "프로젝트 고유번호")
|
||||
private Long prjctIdx;
|
||||
|
||||
@Size(max = 32)
|
||||
@@ -38,7 +40,7 @@ public class ProjectInfoDto {
|
||||
|
||||
@Size(max = 128)
|
||||
@NotBlank
|
||||
@Schema(description = "프로젝트 명")
|
||||
@Schema(description = "프로젝트명")
|
||||
private String prjctName;
|
||||
|
||||
@Size(max = 32)
|
||||
@@ -61,21 +63,10 @@ public class ProjectInfoDto {
|
||||
@Schema(description = "발신번호")
|
||||
private String callerTelNum;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "설문지 타입")
|
||||
private SurveyType surveyTy;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "내부 설문 시스템 프로젝트 코드")
|
||||
private String surveyPrjctCd;
|
||||
|
||||
@Size(max = 128)
|
||||
@Schema(description = "설문 URL")
|
||||
private String surveyUrl;
|
||||
|
||||
@Size(max = 128)
|
||||
@Schema(description = "외부 설문 대시보드 URL. surveyTy가 99(EXTERNAL)일 때만 사용")
|
||||
private String surveyDashboardUrl;
|
||||
@Valid
|
||||
@Builder.Default
|
||||
@Schema(description = "프로젝트 설문 목록")
|
||||
private List<ProjectSurveyDto> surveys = new ArrayList<>();
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "면접원 확인사항 여부")
|
||||
@@ -107,6 +98,9 @@ public class ProjectInfoDto {
|
||||
private LocalDateTime modDt;
|
||||
|
||||
public static ProjectInfoDto from(TPrjctEntity entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
return ProjectInfoDto.builder()
|
||||
.prjctIdx(entity.getPrjctIdx())
|
||||
.prjctCd(entity.getPrjctCd())
|
||||
@@ -116,10 +110,7 @@ public class ProjectInfoDto {
|
||||
.ownerDept(entity.getOwnerDept())
|
||||
.ownerFw(entity.getOwnerFw())
|
||||
.callerTelNum(entity.getCallerTelNum())
|
||||
.surveyTy(SurveyType.fromCode(entity.getSurveyTy()))
|
||||
.surveyPrjctCd(entity.getSurveyPrjctCd())
|
||||
.surveyUrl(entity.getSurveyUrl())
|
||||
.surveyDashboardUrl(entity.getSurveyDashboardUrl())
|
||||
.surveys(new ArrayList<>())
|
||||
.ff(entity.getFf())
|
||||
.useContactSenario(entity.getUseContactSenario())
|
||||
.contactSenario(entity.getContactSenario())
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.kri.contact.server.dto.project;
|
||||
|
||||
import com.kri.contact.server.common.enums.SurveyType;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctSurveyEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "프로젝트 설문 정보")
|
||||
public class ProjectSurveyDto {
|
||||
|
||||
@Schema(description = "프로젝트 설문 고유번호")
|
||||
private Long prjctSurveyIdx;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "프로젝트 내 설문 표시 순서")
|
||||
private Short surveyOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotBlank
|
||||
@Schema(description = "설문명")
|
||||
private String surveyName;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "설문 타입")
|
||||
private SurveyType surveyTy;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "설문 시스템 프로젝트 코드")
|
||||
private String surveyPrjctCd;
|
||||
|
||||
@Size(max = 1024)
|
||||
@Schema(description = "설문 URL")
|
||||
private String surveyUrl;
|
||||
|
||||
@Size(max = 1024)
|
||||
@Schema(description = "설문 Full URL")
|
||||
private String surveyFullUrl;
|
||||
|
||||
@Size(max = 1024)
|
||||
@Schema(description = "설문 Short URL")
|
||||
private String surveyShortUrl;
|
||||
|
||||
@Size(max = 1024)
|
||||
@Schema(description = "외부 설문 대시보드 URL. surveyTy가 99(EXTERNAL)일 때만 사용")
|
||||
private String surveyDashboardUrl;
|
||||
|
||||
public static ProjectSurveyDto from(TPrjctSurveyEntity entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
return ProjectSurveyDto.builder()
|
||||
.prjctSurveyIdx(entity.getPrjctSurveyIdx())
|
||||
.surveyOrder(entity.getSurveyOrder())
|
||||
.surveyName(entity.getSurveyNm())
|
||||
.surveyTy(SurveyType.fromCode(entity.getSurveyTy()))
|
||||
.surveyPrjctCd(entity.getSurveyPrjctCd())
|
||||
.surveyUrl(entity.getSurveyUrl())
|
||||
.surveyFullUrl(entity.getSurveyFullUrl())
|
||||
.surveyShortUrl(entity.getSurveyShortUrl())
|
||||
.surveyDashboardUrl(entity.getSurveyDashboardUrl())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -23,7 +24,10 @@ import org.hibernate.annotations.ColumnDefault;
|
||||
@Entity
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Table(name = "t_list_call_hist")
|
||||
@Table(
|
||||
name = "t_list_call_hist",
|
||||
uniqueConstraints = @UniqueConstraint(name = "t_list_call_hist_uk", columnNames = "agent_session_id")
|
||||
)
|
||||
public class TListCallHistEntity {
|
||||
|
||||
@Id
|
||||
@@ -64,7 +68,7 @@ public class TListCallHistEntity {
|
||||
|
||||
@Size(max = 64)
|
||||
@NotNull
|
||||
@Column(name = "dest_session_id", nullable = false, length = 64, updatable = false)
|
||||
@Column(name = "dest_session_id", nullable = false, length = 64)
|
||||
private String destSessionId;
|
||||
|
||||
@Size(max = 64)
|
||||
@@ -97,7 +101,8 @@ public class TListCallHistEntity {
|
||||
private String mediaServerName;
|
||||
|
||||
@Size(max = 256)
|
||||
@Column(name = "record_file_name", length = 256)
|
||||
@NotNull
|
||||
@Column(name = "record_file_name", nullable = false, length = 256)
|
||||
private String recordFileName;
|
||||
|
||||
@Size(max = 32)
|
||||
@@ -128,24 +133,54 @@ public class TListCallHistEntity {
|
||||
.destSessionId(request.getDestSessionId())
|
||||
.callTy(request.getCallTy())
|
||||
.startDt(request.getStartDt())
|
||||
.endDt(regDt)
|
||||
.endDt(resolveEndDt(request, regDt))
|
||||
.totalTime(request.getTotalTime())
|
||||
.talkTime(request.getTalkTime())
|
||||
.mediaServerId(request.getMediaServerId())
|
||||
.mediaServerName(request.getMediaServerName())
|
||||
.recordFileName(request.getRecordFileName())
|
||||
.recordFileName(defaultString(request.getRecordFileName()))
|
||||
.regUser(regUser)
|
||||
.regDt(regDt)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void updateCallResult(ListCallHistRequestDto request, LocalDateTime endDt) {
|
||||
this.endDt = endDt;
|
||||
this.totalTime = request.getTotalTime();
|
||||
this.talkTime = request.getTalkTime();
|
||||
if (isCompletedRequest(request)) {
|
||||
this.endDt = endDt;
|
||||
}
|
||||
if (isPositive(request.getTotalTime())) {
|
||||
this.totalTime = request.getTotalTime();
|
||||
}
|
||||
if (isPositive(request.getTalkTime())) {
|
||||
this.talkTime = request.getTalkTime();
|
||||
}
|
||||
this.mediaServerId = request.getMediaServerId();
|
||||
this.mediaServerName = request.getMediaServerName();
|
||||
this.recordFileName = request.getRecordFileName();
|
||||
if (hasText(request.getRecordFileName())) {
|
||||
this.recordFileName = request.getRecordFileName();
|
||||
}
|
||||
}
|
||||
|
||||
private static LocalDateTime resolveEndDt(ListCallHistRequestDto request, LocalDateTime now) {
|
||||
return isCompletedRequest(request) ? now : null;
|
||||
}
|
||||
|
||||
private static boolean isCompletedRequest(ListCallHistRequestDto request) {
|
||||
return isPositive(request.getTotalTime())
|
||||
|| isPositive(request.getTalkTime())
|
||||
|| hasText(request.getRecordFileName());
|
||||
}
|
||||
|
||||
private static boolean isPositive(Integer value) {
|
||||
return value != null && value > 0;
|
||||
}
|
||||
|
||||
private static boolean hasText(String value) {
|
||||
return value != null && !value.isBlank();
|
||||
}
|
||||
|
||||
private static String defaultString(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ public class TListEventHistEntity {
|
||||
@Column(name = "prjct_idx", columnDefinition = "int UNSIGNED not null")
|
||||
private Long prjctIdx;
|
||||
|
||||
@Column(name = "prjct_survey_idx", columnDefinition = "int UNSIGNED")
|
||||
private Long prjctSurveyIdx;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "sid", nullable = false)
|
||||
private Integer sid;
|
||||
@@ -74,13 +77,15 @@ public class TListEventHistEntity {
|
||||
|
||||
public static TListEventHistEntity fromSurveyHistory(
|
||||
ListEventHistFromSurveyDto request,
|
||||
Long prjctIdx,
|
||||
String metaData,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
return TListEventHistEntity.builder()
|
||||
.eventTy(ResultCodeType.SURVEY.getCode())
|
||||
.prjctIdx(request.getPrjctIdx())
|
||||
.prjctIdx(prjctIdx)
|
||||
.prjctSurveyIdx(request.getPrjctSurveyIdx())
|
||||
.sid(request.getSid())
|
||||
.resultCd(request.getAction().getCode().intValue())
|
||||
.metaData(metaData)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TListEventLatestEntityId;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
@@ -17,8 +18,28 @@ import lombok.Setter;
|
||||
@Table(name = "t_list_event_latest")
|
||||
public class TListEventLatestEntity {
|
||||
|
||||
@EmbeddedId
|
||||
private TListEventLatestEntityId id;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "list_event_latest_idx", nullable = false)
|
||||
private Long listEventLatestIdx;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "prjct_idx", nullable = false, columnDefinition = "int UNSIGNED not null")
|
||||
private Long prjctIdx;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "sid", nullable = false)
|
||||
private Integer sid;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "event_ty", nullable = false)
|
||||
private Short eventTy;
|
||||
|
||||
@Column(name = "prjct_survey_idx", columnDefinition = "int UNSIGNED")
|
||||
private Long prjctSurveyIdx;
|
||||
|
||||
@Column(name = "latest_scope_key", insertable = false, updatable = false)
|
||||
private Long latestScopeKey;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "list_event_hist_idx", nullable = false)
|
||||
@@ -37,15 +58,4 @@ public class TListEventLatestEntity {
|
||||
@Column(name = "reg_dt", nullable = false)
|
||||
private LocalDateTime regDt;
|
||||
|
||||
public Long getPrjctIdx() {
|
||||
return id.getPrjctIdx();
|
||||
}
|
||||
|
||||
public Integer getSid() {
|
||||
return id.getSid();
|
||||
}
|
||||
|
||||
public Short getEventTy() {
|
||||
return id.getEventTy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import static com.kri.contact.server.common.consts.ContactConstant.DEFAULT_CALLE
|
||||
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.contact.server.common.enums.ProjectStatus;
|
||||
import com.kri.contact.server.common.enums.SurveyType;
|
||||
import com.kri.contact.server.dto.project.ProjectCreateRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||
import jakarta.persistence.Column;
|
||||
@@ -73,23 +72,6 @@ public class TPrjctEntity {
|
||||
@Column(name = "caller_telnum", nullable = false, length = 16)
|
||||
private String callerTelNum;
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "survey_ty", nullable = false)
|
||||
private Short surveyTy;
|
||||
|
||||
@Size(max = 32)
|
||||
@Column(name = "survey_prjct_cd", length = 32)
|
||||
private String surveyPrjctCd;
|
||||
|
||||
@Size(max = 128)
|
||||
@Column(name = "survey_url", length = 128)
|
||||
private String surveyUrl;
|
||||
|
||||
@Size(max = 128)
|
||||
@Column(name = "survey_dashboard_url", length = 128)
|
||||
private String surveyDashboardUrl;
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "is_ff", nullable = false)
|
||||
@@ -142,10 +124,6 @@ public class TPrjctEntity {
|
||||
.ownerDept(dto.getOwnerDept())
|
||||
.ownerFw(dto.getOwnerFw())
|
||||
.callerTelNum(dto.getCallerTelNum())
|
||||
.surveyTy(dto.getSurveyTy().getCode())
|
||||
.surveyPrjctCd(dto.getSurveyPrjctCd())
|
||||
.surveyUrl(dto.getSurveyUrl())
|
||||
.surveyDashboardUrl(resolveSurveyDashboardUrl(dto.getSurveyTy(), dto.getSurveyDashboardUrl()))
|
||||
.ff(dto.getFf())
|
||||
.useContactSenario(dto.getUseContactSenario())
|
||||
.contactSenario(dto.getContactSenario())
|
||||
@@ -164,7 +142,6 @@ public class TPrjctEntity {
|
||||
.ownerDept(req.getOwnerDept())
|
||||
.ownerFw(req.getOwnerFw())
|
||||
.callerTelNum(DEFAULT_CALLER_TELNUM)
|
||||
.surveyTy(SurveyType.NONE.getCode())
|
||||
.ff(false)
|
||||
.useContactSenario(false)
|
||||
.regUser(regUser)
|
||||
@@ -179,10 +156,6 @@ public class TPrjctEntity {
|
||||
this.ownerDept = dto.getOwnerDept();
|
||||
this.ownerFw = dto.getOwnerFw();
|
||||
this.callerTelNum = dto.getCallerTelNum();
|
||||
this.surveyTy = dto.getSurveyTy().getCode();
|
||||
this.surveyPrjctCd = dto.getSurveyPrjctCd();
|
||||
this.surveyUrl = dto.getSurveyUrl();
|
||||
this.surveyDashboardUrl = resolveSurveyDashboardUrl(dto.getSurveyTy(), dto.getSurveyDashboardUrl());
|
||||
this.ff = dto.getFf();
|
||||
this.useContactSenario = dto.getUseContactSenario();
|
||||
this.contactSenario = dto.getContactSenario();
|
||||
@@ -190,8 +163,4 @@ public class TPrjctEntity {
|
||||
this.modUser = modUser;
|
||||
this.modDt = modDt;
|
||||
}
|
||||
|
||||
private static String resolveSurveyDashboardUrl(SurveyType surveyTy, String surveyDashboardUrl) {
|
||||
return surveyTy == SurveyType.EXTERNAL ? surveyDashboardUrl : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.common.enums.SurveyType;
|
||||
import com.kri.contact.server.dto.project.ProjectSurveyDto;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "t_prjct_survey")
|
||||
public class TPrjctSurveyEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "prjct_survey_idx", columnDefinition = "int UNSIGNED not null")
|
||||
private Long prjctSurveyIdx;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "prjct_idx", nullable = false, columnDefinition = "int UNSIGNED not null")
|
||||
private Long prjctIdx;
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("1")
|
||||
@Column(name = "survey_order", nullable = false)
|
||||
private Short surveyOrder;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "survey_nm", nullable = false, length = 128)
|
||||
private String surveyNm;
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "survey_ty", nullable = false)
|
||||
private Short surveyTy;
|
||||
|
||||
@Size(max = 32)
|
||||
@Column(name = "survey_prjct_cd", length = 32)
|
||||
private String surveyPrjctCd;
|
||||
|
||||
@Size(max = 1024)
|
||||
@Column(name = "survey_url", length = 1024)
|
||||
private String surveyUrl;
|
||||
|
||||
@Size(max = 1024)
|
||||
@Column(name = "survey_full_url", length = 1024)
|
||||
private String surveyFullUrl;
|
||||
|
||||
@Size(max = 1024)
|
||||
@Column(name = "survey_short_url", length = 1024)
|
||||
private String surveyShortUrl;
|
||||
|
||||
@Size(max = 1024)
|
||||
@Column(name = "survey_dashboard_url", length = 1024)
|
||||
private String surveyDashboardUrl;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "reg_user", nullable = false, length = 32, updatable = false)
|
||||
private String regUser;
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("CURRENT_TIMESTAMP")
|
||||
@Column(name = "reg_dt", nullable = false, updatable = false)
|
||||
private LocalDateTime regDt;
|
||||
|
||||
@Size(max = 32)
|
||||
@Column(name = "mod_user", length = 32, insertable = false)
|
||||
private String modUser;
|
||||
|
||||
@Column(name = "mod_dt", insertable = false)
|
||||
private LocalDateTime modDt;
|
||||
|
||||
public static TPrjctSurveyEntity create(
|
||||
Long prjctIdx,
|
||||
ProjectSurveyDto dto,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
return TPrjctSurveyEntity.builder()
|
||||
.prjctIdx(prjctIdx)
|
||||
.surveyOrder(dto.getSurveyOrder())
|
||||
.surveyNm(dto.getSurveyName())
|
||||
.surveyTy(dto.getSurveyTy().getCode())
|
||||
.surveyPrjctCd(dto.getSurveyPrjctCd())
|
||||
.surveyUrl(dto.getSurveyUrl())
|
||||
.surveyFullUrl(dto.getSurveyFullUrl())
|
||||
.surveyShortUrl(dto.getSurveyShortUrl())
|
||||
.surveyDashboardUrl(resolveSurveyDashboardUrl(dto.getSurveyTy(), dto.getSurveyDashboardUrl()))
|
||||
.regUser(regUser)
|
||||
.regDt(regDt)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void updateFrom(ProjectSurveyDto dto, String modUser, LocalDateTime modDt) {
|
||||
this.surveyOrder = dto.getSurveyOrder();
|
||||
this.surveyNm = dto.getSurveyName();
|
||||
this.surveyTy = dto.getSurveyTy().getCode();
|
||||
this.surveyPrjctCd = dto.getSurveyPrjctCd();
|
||||
this.surveyUrl = dto.getSurveyUrl();
|
||||
this.surveyFullUrl = dto.getSurveyFullUrl();
|
||||
this.surveyShortUrl = dto.getSurveyShortUrl();
|
||||
this.surveyDashboardUrl = resolveSurveyDashboardUrl(dto.getSurveyTy(), dto.getSurveyDashboardUrl());
|
||||
this.modUser = modUser;
|
||||
this.modDt = modDt;
|
||||
}
|
||||
|
||||
private static String resolveSurveyDashboardUrl(SurveyType surveyTy, String surveyDashboardUrl) {
|
||||
return surveyTy == SurveyType.EXTERNAL ? surveyDashboardUrl : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.kri.contact.server.persistence.jdbc;
|
||||
|
||||
import com.kri.contact.server.dto.list.ListCallHistRequestDto;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class ListCallHistJdbcSupport {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public void upsertCallHistory(
|
||||
Long prjctIdx,
|
||||
Integer sid,
|
||||
ListCallHistRequestDto request,
|
||||
String regUser,
|
||||
LocalDateTime now
|
||||
) {
|
||||
LocalDateTime endDt = isCompletedRequest(request) ? now : null;
|
||||
jdbcTemplate.update("""
|
||||
insert into t_list_call_hist (
|
||||
prjct_idx,
|
||||
sid,
|
||||
list_hder_id,
|
||||
dest_num,
|
||||
agent_num,
|
||||
ani_num,
|
||||
agent_session_id,
|
||||
dest_session_id,
|
||||
call_ty,
|
||||
start_dt,
|
||||
end_dt,
|
||||
total_time,
|
||||
talk_time,
|
||||
media_server_id,
|
||||
media_server_name,
|
||||
record_file_name,
|
||||
reg_user,
|
||||
reg_dt
|
||||
) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
on duplicate key update
|
||||
list_call_hist_idx = last_insert_id(list_call_hist_idx),
|
||||
dest_num = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))), values(dest_num), dest_num),
|
||||
agent_num = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))), values(agent_num), agent_num),
|
||||
ani_num = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))), values(ani_num), ani_num),
|
||||
dest_session_id = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))) and (dest_session_id is null or dest_session_id = ''), values(dest_session_id), dest_session_id),
|
||||
call_ty = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))), values(call_ty), call_ty),
|
||||
start_dt = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))) and values(start_dt) < start_dt, values(start_dt), start_dt),
|
||||
end_dt = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))) and values(end_dt) is not null, values(end_dt), end_dt),
|
||||
total_time = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))) and values(total_time) > 0, values(total_time), total_time),
|
||||
talk_time = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))) and values(talk_time) > 0, values(talk_time), talk_time),
|
||||
media_server_id = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))), values(media_server_id), media_server_id),
|
||||
media_server_name = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))), values(media_server_name), media_server_name),
|
||||
record_file_name = if((prjct_idx <=> values(prjct_idx) and sid <=> values(sid) and list_hder_id <=> values(list_hder_id) and (dest_session_id is null or dest_session_id = '' or dest_session_id = values(dest_session_id))) and values(record_file_name) <> '', values(record_file_name), record_file_name)
|
||||
""",
|
||||
prjctIdx,
|
||||
sid,
|
||||
request.getListHderId(),
|
||||
request.getDestNum(),
|
||||
request.getAgentNum(),
|
||||
request.getAniNum(),
|
||||
request.getAgentSessionId(),
|
||||
request.getDestSessionId(),
|
||||
request.getCallTy(),
|
||||
request.getStartDt(),
|
||||
endDt,
|
||||
request.getTotalTime(),
|
||||
request.getTalkTime(),
|
||||
request.getMediaServerId(),
|
||||
request.getMediaServerName(),
|
||||
defaultString(request.getRecordFileName()),
|
||||
regUser,
|
||||
now
|
||||
);
|
||||
}
|
||||
|
||||
private boolean isCompletedRequest(ListCallHistRequestDto request) {
|
||||
return isPositive(request.getTotalTime())
|
||||
|| isPositive(request.getTalkTime())
|
||||
|| hasText(request.getRecordFileName());
|
||||
}
|
||||
|
||||
private boolean isPositive(Integer value) {
|
||||
return value != null && value > 0;
|
||||
}
|
||||
|
||||
private boolean hasText(String value) {
|
||||
return value != null && !value.isBlank();
|
||||
}
|
||||
|
||||
private String defaultString(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,8 +105,8 @@ public class ProgressQuerySupport {
|
||||
)
|
||||
.from(latest)
|
||||
.where(
|
||||
latest.id.prjctIdx.eq(prjctIdx),
|
||||
latest.id.eventTy.eq(eventTy)
|
||||
latest.prjctIdx.eq(prjctIdx),
|
||||
latest.eventTy.eq(eventTy)
|
||||
)
|
||||
.groupBy(expressions.contactDate(), latest.resultCd)
|
||||
.orderBy(expressions.contactDate().asc(), latest.resultCd.asc())
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.kri.contact.server.persistence.query;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
public class ProjectSorts {
|
||||
|
||||
public static Sort toSort(String sortBy, String sortDir) {
|
||||
String prop = switch (sortBy) {
|
||||
case "prjctIdx" -> "prjctIdx";
|
||||
case "prjctCd" -> "prjctCd";
|
||||
case "prjctName" -> "prjctNm";
|
||||
case "prjctStatus" -> "prjctStatus";
|
||||
case "ownerDept" -> "ownerDept";
|
||||
case "ownerFw" -> "ownerFw";
|
||||
case "regDt" -> "regDt";
|
||||
default -> "prjctCd"; // fallback
|
||||
};
|
||||
|
||||
Sort.Direction dir = "asc".equalsIgnoreCase(sortDir) ? Sort.Direction.ASC : Sort.Direction.DESC;
|
||||
return Sort.by(dir, prop);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ public interface ListAssignCmpnRepository extends JpaRepository<TListAssignCmpnE
|
||||
|
||||
long deleteByCmpnId(String cmpnId);
|
||||
|
||||
boolean existsByPrjctIdxAndSidAndCmpnId(Long prjctIdx, Integer sid, String cmpnId);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListAssignCmpnEntity a
|
||||
|
||||
@@ -11,6 +11,8 @@ public interface ListAssignUserRepository extends JpaRepository<TListAssignUserE
|
||||
|
||||
long deleteByUserId(String userId);
|
||||
|
||||
boolean existsByPrjctIdxAndSidAndUserId(Long prjctIdx, Integer sid, String userId);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListAssignUserEntity a
|
||||
|
||||
@@ -7,4 +7,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
public interface ListCallHistRepository extends JpaRepository<TListCallHistEntity, Long> {
|
||||
|
||||
Optional<TListCallHistEntity> findFirstByAgentSessionId(String agentSessionId);
|
||||
|
||||
Optional<TListCallHistEntity> findByAgentSessionId(String agentSessionId);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ public interface ListEventHistRepository extends JpaRepository<TListEventHistEnt
|
||||
and h.listEventHistIdx in (
|
||||
select l.listEventHistIdx
|
||||
from TListEventLatestEntity l
|
||||
where l.id.prjctIdx = :prjctIdx
|
||||
and l.id.sid in :sids
|
||||
where l.prjctIdx = :prjctIdx
|
||||
and l.sid in :sids
|
||||
)
|
||||
""")
|
||||
List<TListEventHistEntity> findLatestListByEventTyFromLatest(
|
||||
@@ -61,7 +61,7 @@ public interface ListEventHistRepository extends JpaRepository<TListEventHistEnt
|
||||
and h2.eventTy in :eventTypes
|
||||
and (:startDate is null or h2.regDt >= :startDate)
|
||||
and (:endDate is null or h2.regDt <= :endDate)
|
||||
group by h2.sid
|
||||
group by h2.sid, h2.eventTy, h2.prjctSurveyIdx
|
||||
)
|
||||
order by h.sid asc, h.regDt asc, h.listEventHistIdx asc
|
||||
""")
|
||||
@@ -80,17 +80,9 @@ public interface ListEventHistRepository extends JpaRepository<TListEventHistEnt
|
||||
and h.listEventHistIdx in (
|
||||
select l.listEventHistIdx
|
||||
from TListEventLatestEntity l
|
||||
where l.id.prjctIdx = :prjctIdx
|
||||
and l.id.sid in :sids
|
||||
and l.id.eventTy in :eventTypes
|
||||
and not exists (
|
||||
select 1
|
||||
from TListEventLatestEntity l2
|
||||
where l2.id.prjctIdx = l.id.prjctIdx
|
||||
and l2.id.sid = l.id.sid
|
||||
and l2.id.eventTy in :eventTypes
|
||||
and l2.listEventHistIdx > l.listEventHistIdx
|
||||
)
|
||||
where l.prjctIdx = :prjctIdx
|
||||
and l.sid in :sids
|
||||
and l.eventTy in :eventTypes
|
||||
)
|
||||
order by h.sid asc, h.regDt asc, h.listEventHistIdx asc
|
||||
""")
|
||||
@@ -119,12 +111,15 @@ public interface ListEventHistRepository extends JpaRepository<TListEventHistEnt
|
||||
);
|
||||
|
||||
@Query("""
|
||||
select h.sid as sid, h.eventTy as eventTy, count(h) as historyCount
|
||||
select h.sid as sid,
|
||||
h.eventTy as eventTy,
|
||||
h.prjctSurveyIdx as prjctSurveyIdx,
|
||||
count(h) as historyCount
|
||||
from TListEventHistEntity h
|
||||
where h.prjctIdx = :prjctIdx
|
||||
and h.sid in :sids
|
||||
and h.eventTy in :eventTypes
|
||||
group by h.sid, h.eventTy
|
||||
group by h.sid, h.eventTy, h.prjctSurveyIdx
|
||||
""")
|
||||
List<EventTypeHistoryCountProjection> findHistoryCountsByEventType(
|
||||
Long prjctIdx,
|
||||
@@ -140,6 +135,7 @@ public interface ListEventHistRepository extends JpaRepository<TListEventHistEnt
|
||||
interface EventTypeHistoryCountProjection {
|
||||
Integer getSid();
|
||||
Short getEventTy();
|
||||
Long getPrjctSurveyIdx();
|
||||
Long getHistoryCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import static com.kri.common.feature.util.StringUtil.normalizeBlank;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.page.PageRequestDto;
|
||||
import com.kri.contact.server.common.enums.ListHeaderTypeAssign;
|
||||
import com.kri.contact.server.common.enums.ListHeaderType;
|
||||
import com.kri.contact.server.common.enums.ListIsUse;
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.dto.list.ListAssignFilterConditionDto;
|
||||
@@ -13,18 +14,22 @@ import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import com.kri.contact.server.common.enums.ListFilterMatchType;
|
||||
import com.kri.contact.server.common.enums.ListFilterOperator;
|
||||
import com.kri.contact.server.dto.list.ListOtherItemFilterConditionDto;
|
||||
import com.kri.contact.server.dto.list.ListSurveyResultFilterConditionDto;
|
||||
import com.kri.contact.server.persistence.entity.QTCmpnEntity;
|
||||
import com.kri.contact.server.persistence.entity.QTListAssignCmpnEntity;
|
||||
import com.kri.contact.server.persistence.entity.QTListAssignUserEntity;
|
||||
import com.kri.contact.server.persistence.entity.QTListEntity;
|
||||
import com.kri.contact.server.persistence.entity.QTListEventLatestEntity;
|
||||
import com.kri.contact.server.persistence.entity.QTListHeaderEntity;
|
||||
import com.kri.contact.server.persistence.entity.QTListItemEntity;
|
||||
import com.kri.contact.server.persistence.entity.QTUserEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Order;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.dsl.ComparableExpressionBase;
|
||||
import com.querydsl.core.types.dsl.StringPath;
|
||||
import com.querydsl.jpa.impl.JPAQuery;
|
||||
import com.querydsl.jpa.JPAExpressions;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import java.util.ArrayList;
|
||||
@@ -57,9 +62,11 @@ public class ListQueryRepositoryImpl implements ListQueryRepository {
|
||||
int pageIndex = pageRequest == null ? 0 : Math.max(pageRequest.getPageIndex(), 0);
|
||||
int pageSize = pageRequest == null ? 10 : Math.max(pageRequest.getPageSize(), 1);
|
||||
|
||||
return jpaQueryFactory.selectFrom(list)
|
||||
.where(predicate)
|
||||
.orderBy(resolveOrderSpecifier(list, pageRequest))
|
||||
JPAQuery<TListEntity> query = jpaQueryFactory.selectFrom(list)
|
||||
.where(predicate);
|
||||
applySort(query, list, prjctIdx, pageRequest);
|
||||
|
||||
return query
|
||||
.offset((long) pageIndex * pageSize)
|
||||
.limit(pageSize)
|
||||
.fetch();
|
||||
@@ -166,6 +173,7 @@ public class ListQueryRepositoryImpl implements ListQueryRepository {
|
||||
appendAssignPredicates(predicate, prjctIdx, list, listFilter.getAssignUserMap());
|
||||
appendAssignConditionPredicates(predicate, prjctIdx, list, listFilter.getAssignConditions());
|
||||
appendResultCodePredicates(predicate, prjctIdx, list, listFilter.getResultCodeMap());
|
||||
appendSurveyResultPredicates(predicate, prjctIdx, list, listFilter.getSurveyResultConditions());
|
||||
appendOtherItemPredicates(predicate, prjctIdx, exactMatchHeaderIds, list, listFilter.getOtherItemConditions());
|
||||
return predicate;
|
||||
}
|
||||
@@ -525,6 +533,9 @@ public class ListQueryRepositoryImpl implements ListQueryRepository {
|
||||
if (resultCodeType == null || resultCodes == null || resultCodes.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (resultCodeType == ResultCodeType.SURVEY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean includeNoHistory = resultCodes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
@@ -547,9 +558,9 @@ public class ListQueryRepositoryImpl implements ListQueryRepository {
|
||||
eventResultPredicate.or(JPAExpressions.selectOne()
|
||||
.from(latest)
|
||||
.where(
|
||||
latest.id.prjctIdx.eq(prjctIdx),
|
||||
latest.id.sid.eq(list.id.sid),
|
||||
latest.id.eventTy.eq(resultCodeType.getCode()),
|
||||
latest.prjctIdx.eq(prjctIdx),
|
||||
latest.sid.eq(list.id.sid),
|
||||
latest.eventTy.eq(resultCodeType.getCode()),
|
||||
latest.resultCd.in(existingHistoryResultCodes)
|
||||
)
|
||||
.exists());
|
||||
@@ -562,9 +573,9 @@ public class ListQueryRepositoryImpl implements ListQueryRepository {
|
||||
eventResultPredicate.or(JPAExpressions.selectOne()
|
||||
.from(noHistoryLatest)
|
||||
.where(
|
||||
noHistoryLatest.id.prjctIdx.eq(prjctIdx),
|
||||
noHistoryLatest.id.sid.eq(list.id.sid),
|
||||
noHistoryLatest.id.eventTy.eq(resultCodeType.getCode())
|
||||
noHistoryLatest.prjctIdx.eq(prjctIdx),
|
||||
noHistoryLatest.sid.eq(list.id.sid),
|
||||
noHistoryLatest.eventTy.eq(resultCodeType.getCode())
|
||||
)
|
||||
.notExists());
|
||||
}
|
||||
@@ -573,6 +584,73 @@ public class ListQueryRepositoryImpl implements ListQueryRepository {
|
||||
}
|
||||
}
|
||||
|
||||
private void appendSurveyResultPredicates(
|
||||
BooleanBuilder predicate,
|
||||
Long prjctIdx,
|
||||
QTListEntity list,
|
||||
List<ListSurveyResultFilterConditionDto> surveyResultConditions
|
||||
) {
|
||||
if (surveyResultConditions == null || surveyResultConditions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ListSurveyResultFilterConditionDto condition : surveyResultConditions) {
|
||||
if (condition == null
|
||||
|| condition.getPrjctSurveyIdx() == null
|
||||
|| condition.getResultCodes() == null
|
||||
|| condition.getResultCodes().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean includeNoHistory = condition.getResultCodes().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.anyMatch(resultCode -> resultCode == NO_RESULT_HISTORY_CODE);
|
||||
List<Integer> existingHistoryResultCodes = condition.getResultCodes().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(resultCode -> resultCode != NO_RESULT_HISTORY_CODE)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (!includeNoHistory && existingHistoryResultCodes.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BooleanBuilder surveyPredicate = new BooleanBuilder();
|
||||
QTListEventLatestEntity latest = new QTListEventLatestEntity(
|
||||
"latest_survey_result_" + condition.getPrjctSurveyIdx()
|
||||
);
|
||||
|
||||
if (!existingHistoryResultCodes.isEmpty()) {
|
||||
surveyPredicate.or(JPAExpressions.selectOne()
|
||||
.from(latest)
|
||||
.where(
|
||||
latest.prjctIdx.eq(prjctIdx),
|
||||
latest.sid.eq(list.id.sid),
|
||||
latest.eventTy.eq(ResultCodeType.SURVEY.getCode()),
|
||||
latest.prjctSurveyIdx.eq(condition.getPrjctSurveyIdx()),
|
||||
latest.resultCd.in(existingHistoryResultCodes)
|
||||
)
|
||||
.exists());
|
||||
}
|
||||
|
||||
if (includeNoHistory) {
|
||||
QTListEventLatestEntity noHistoryLatest = new QTListEventLatestEntity(
|
||||
"no_history_survey_result_" + condition.getPrjctSurveyIdx()
|
||||
);
|
||||
surveyPredicate.or(JPAExpressions.selectOne()
|
||||
.from(noHistoryLatest)
|
||||
.where(
|
||||
noHistoryLatest.prjctIdx.eq(prjctIdx),
|
||||
noHistoryLatest.sid.eq(list.id.sid),
|
||||
noHistoryLatest.eventTy.eq(ResultCodeType.SURVEY.getCode()),
|
||||
noHistoryLatest.prjctSurveyIdx.eq(condition.getPrjctSurveyIdx())
|
||||
)
|
||||
.notExists());
|
||||
}
|
||||
|
||||
predicate.and(surveyPredicate);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendOtherItemPredicates(
|
||||
BooleanBuilder predicate,
|
||||
Long prjctIdx,
|
||||
@@ -737,19 +815,178 @@ public class ListQueryRepositoryImpl implements ListQueryRepository {
|
||||
return predicate;
|
||||
}
|
||||
|
||||
private OrderSpecifier<?> resolveOrderSpecifier(QTListEntity list, PageRequestDto pageRequest) {
|
||||
private void applySort(
|
||||
JPAQuery<TListEntity> query,
|
||||
QTListEntity list,
|
||||
Long prjctIdx,
|
||||
PageRequestDto pageRequest
|
||||
) {
|
||||
SortTarget sortTarget = resolveSortTarget(pageRequest);
|
||||
if (sortTarget.assignType() != null) {
|
||||
applyAssignSort(query, list, prjctIdx, sortTarget);
|
||||
} else if (sortTarget.listHderId() != null) {
|
||||
applyItemSort(query, list, prjctIdx, sortTarget);
|
||||
} else if (sortTarget.resultType() != null) {
|
||||
applyResultSort(query, list, prjctIdx, sortTarget);
|
||||
} else {
|
||||
query.orderBy(toOrderSpecifier(sortTarget.order(), sortTarget.basePath()));
|
||||
}
|
||||
query.orderBy(list.id.sid.asc());
|
||||
}
|
||||
|
||||
private SortTarget resolveSortTarget(PageRequestDto pageRequest) {
|
||||
String sortBy = pageRequest == null ? null : pageRequest.getSortBy();
|
||||
Order order = pageRequest != null && "desc".equalsIgnoreCase(pageRequest.getSortDir())
|
||||
? Order.DESC
|
||||
: Order.ASC;
|
||||
|
||||
if ("use".equalsIgnoreCase(sortBy) || "is_use".equalsIgnoreCase(sortBy)) {
|
||||
return new OrderSpecifier<>(order, list.use);
|
||||
return SortTarget.base(order, QTListEntity.tListEntity.use);
|
||||
}
|
||||
if ("memo".equalsIgnoreCase(sortBy)) {
|
||||
return new OrderSpecifier<>(order, list.memo);
|
||||
return SortTarget.base(order, QTListEntity.tListEntity.memo);
|
||||
}
|
||||
if (sortBy != null && sortBy.matches("assign-(13|14|15)")) {
|
||||
return SortTarget.assign(order, Short.valueOf(sortBy.substring("assign-".length())));
|
||||
}
|
||||
if ("result-contact".equalsIgnoreCase(sortBy)) {
|
||||
return SortTarget.result(order, ResultCodeType.CONTACT.getCode(), null);
|
||||
}
|
||||
if ("result-interview".equalsIgnoreCase(sortBy)) {
|
||||
return SortTarget.result(order, ResultCodeType.INTERVIEW.getCode(), null);
|
||||
}
|
||||
Long surveyIdx = parseSurveyResultSort(sortBy);
|
||||
if (surveyIdx != null) {
|
||||
return SortTarget.result(order, ResultCodeType.SURVEY.getCode(), surveyIdx);
|
||||
}
|
||||
Integer listHderId = parseListHderIdSort(sortBy);
|
||||
if (listHderId != null) {
|
||||
return SortTarget.item(order, listHderId);
|
||||
}
|
||||
return SortTarget.base(order, QTListEntity.tListEntity.id.sid);
|
||||
}
|
||||
|
||||
private void applyAssignSort(
|
||||
JPAQuery<TListEntity> query,
|
||||
QTListEntity list,
|
||||
Long prjctIdx,
|
||||
SortTarget sortTarget
|
||||
) {
|
||||
if (Objects.equals(sortTarget.assignType(), ListHeaderTypeAssign.OUTSOURCE.getCode())) {
|
||||
QTListAssignCmpnEntity assignCmpn = new QTListAssignCmpnEntity("sort_assign_cmpn");
|
||||
query.leftJoin(assignCmpn)
|
||||
.on(
|
||||
assignCmpn.prjctIdx.eq(prjctIdx),
|
||||
assignCmpn.sid.eq(list.id.sid)
|
||||
)
|
||||
.orderBy(toOrderSpecifier(sortTarget.order(), assignCmpn.cmpnId));
|
||||
return;
|
||||
}
|
||||
|
||||
QTListAssignUserEntity assignUser = new QTListAssignUserEntity("sort_assign_user_" + sortTarget.assignType());
|
||||
query.leftJoin(assignUser)
|
||||
.on(
|
||||
assignUser.prjctIdx.eq(prjctIdx),
|
||||
assignUser.sid.eq(list.id.sid),
|
||||
assignUser.assignRole.eq(sortTarget.assignType())
|
||||
)
|
||||
.orderBy(toOrderSpecifier(sortTarget.order(), assignUser.userId));
|
||||
}
|
||||
|
||||
private void applyItemSort(
|
||||
JPAQuery<TListEntity> query,
|
||||
QTListEntity list,
|
||||
Long prjctIdx,
|
||||
SortTarget sortTarget
|
||||
) {
|
||||
QTListItemEntity item = new QTListItemEntity("sort_item_" + sortTarget.listHderId());
|
||||
QTListHeaderEntity header = new QTListHeaderEntity("sort_header_" + sortTarget.listHderId());
|
||||
query.leftJoin(header)
|
||||
.on(
|
||||
header.id.prjctIdx.eq(prjctIdx),
|
||||
header.id.listHderId.eq(sortTarget.listHderId()),
|
||||
header.listHderTy.ne(ListHeaderType.FILE.getCode())
|
||||
)
|
||||
.leftJoin(item)
|
||||
.on(
|
||||
item.id.prjctIdx.eq(prjctIdx),
|
||||
item.id.sid.eq(list.id.sid),
|
||||
item.id.listHderId.eq(header.id.listHderId)
|
||||
)
|
||||
.orderBy(toOrderSpecifier(sortTarget.order(), item.listItemVal));
|
||||
}
|
||||
|
||||
private void applyResultSort(
|
||||
JPAQuery<TListEntity> query,
|
||||
QTListEntity list,
|
||||
Long prjctIdx,
|
||||
SortTarget sortTarget
|
||||
) {
|
||||
QTListEventLatestEntity latest = new QTListEventLatestEntity("sort_result_" + sortTarget.resultType());
|
||||
BooleanBuilder on = new BooleanBuilder()
|
||||
.and(latest.prjctIdx.eq(prjctIdx))
|
||||
.and(latest.sid.eq(list.id.sid))
|
||||
.and(latest.eventTy.eq(sortTarget.resultType()));
|
||||
if (sortTarget.prjctSurveyIdx() == null) {
|
||||
on.and(latest.prjctSurveyIdx.isNull());
|
||||
} else {
|
||||
on.and(latest.prjctSurveyIdx.eq(sortTarget.prjctSurveyIdx()));
|
||||
}
|
||||
query.leftJoin(latest)
|
||||
.on(on)
|
||||
.orderBy(toOrderSpecifier(sortTarget.order(), latest.resultCd));
|
||||
}
|
||||
|
||||
private OrderSpecifier<?> toOrderSpecifier(Order order, ComparableExpressionBase<?> expression) {
|
||||
return new OrderSpecifier<>(order, expression);
|
||||
}
|
||||
|
||||
private Integer parseListHderIdSort(String sortBy) {
|
||||
if (sortBy == null || !sortBy.matches("\\d+")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.valueOf(sortBy);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Long parseSurveyResultSort(String sortBy) {
|
||||
String prefix = "result-survey-";
|
||||
if (sortBy == null || !sortBy.toLowerCase().startsWith(prefix)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Long.valueOf(sortBy.substring(prefix.length()));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private record SortTarget(
|
||||
Order order,
|
||||
ComparableExpressionBase<?> basePath,
|
||||
Short assignType,
|
||||
Integer listHderId,
|
||||
Short resultType,
|
||||
Long prjctSurveyIdx
|
||||
) {
|
||||
private static SortTarget base(Order order, ComparableExpressionBase<?> path) {
|
||||
return new SortTarget(order, path, null, null, null, null);
|
||||
}
|
||||
|
||||
private static SortTarget assign(Order order, Short assignType) {
|
||||
return new SortTarget(order, null, assignType, null, null, null);
|
||||
}
|
||||
|
||||
private static SortTarget item(Order order, Integer listHderId) {
|
||||
return new SortTarget(order, null, null, listHderId, null, null);
|
||||
}
|
||||
|
||||
private static SortTarget result(Order order, Short resultType, Long prjctSurveyIdx) {
|
||||
return new SortTarget(order, null, null, null, resultType, prjctSurveyIdx);
|
||||
}
|
||||
return new OrderSpecifier<>(order, list.id.sid);
|
||||
}
|
||||
|
||||
private Set<Short> toUseCodes(Set<ListIsUse> listUseSet) {
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.springframework.data.jpa.repository.Query;
|
||||
public interface ProjectAssignCmpnRepository
|
||||
extends JpaRepository<TPrjctAssignCmpnEntity, TPrjctAssignCmpnEntityId> {
|
||||
|
||||
boolean existsByIdPrjctIdxAndIdCmpnId(Long prjctIdx, String cmpnId);
|
||||
|
||||
@Query("""
|
||||
select a.id.cmpnId
|
||||
from TPrjctAssignCmpnEntity a
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.springframework.data.jpa.repository.Query;
|
||||
public interface ProjectAssignUserRepository
|
||||
extends JpaRepository<TPrjctAssignUserEntity, TPrjctAssignUserEntityId> {
|
||||
|
||||
boolean existsByIdPrjctIdxAndIdUserId(Long prjctIdx, String userId);
|
||||
|
||||
@Query("""
|
||||
select a.id.userId
|
||||
from TPrjctAssignUserEntity a
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TPrjctSurveyEntity;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ProjectSurveyRepository extends JpaRepository<TPrjctSurveyEntity, Long> {
|
||||
|
||||
List<TPrjctSurveyEntity> findByPrjctIdxOrderBySurveyOrderAscPrjctSurveyIdxAsc(Long prjctIdx);
|
||||
|
||||
List<TPrjctSurveyEntity> findByPrjctIdxInOrderByPrjctIdxAscSurveyOrderAscPrjctSurveyIdxAsc(
|
||||
Collection<Long> prjctIdxs
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import static com.kri.contact.server.common.consts.ContactConstant.DEFAULT_COMPANY_NAME;
|
||||
|
||||
import com.kri.common.feature.auth.dto.JwtUserClaimsDto;
|
||||
import com.kri.common.feature.auth.jwt.JwtService;
|
||||
import com.kri.contact.server.common.external.intranet.IntranetExtensionApiClient;
|
||||
@@ -27,7 +29,7 @@ public class AuthService {
|
||||
if (loginInfoResponse != null) {
|
||||
claims = JwtUserClaimsDto.builder()
|
||||
.userId(loginInfoResponse.getUserId())
|
||||
.userCmpn(loginInfoResponse.getUserCmpn())
|
||||
.userCmpn(DEFAULT_COMPANY_NAME)
|
||||
.userName(loginInfoResponse.getUserNm())
|
||||
.userTeam(loginInfoResponse.getUserTeam())
|
||||
.userRole(loginInfoResponse.getUserRole())
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.dto.list.ListCallHistDto;
|
||||
import com.kri.contact.server.dto.list.ListCallHistRequestDto;
|
||||
import com.kri.contact.server.persistence.entity.TListCallHistEntity;
|
||||
import com.kri.contact.server.persistence.jdbc.ListCallHistJdbcSupport;
|
||||
import com.kri.contact.server.persistence.repository.ListAssignCmpnRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListAssignUserRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListCallHistRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListHeaderRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectAssignCmpnRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectAssignUserRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -19,6 +26,11 @@ public class ListCallHistService {
|
||||
private final ListRepository listRepository;
|
||||
private final ListHeaderRepository listHeaderRepository;
|
||||
private final ListCallHistRepository listCallHistRepository;
|
||||
private final ListCallHistJdbcSupport listCallHistJdbcSupport;
|
||||
private final ProjectAssignUserRepository projectAssignUserRepository;
|
||||
private final ProjectAssignCmpnRepository projectAssignCmpnRepository;
|
||||
private final ListAssignUserRepository listAssignUserRepository;
|
||||
private final ListAssignCmpnRepository listAssignCmpnRepository;
|
||||
|
||||
@Transactional
|
||||
public ListCallHistDto saveCallHistory(
|
||||
@@ -26,8 +38,11 @@ public class ListCallHistService {
|
||||
Integer sid,
|
||||
ListCallHistRequestDto request,
|
||||
String regUser,
|
||||
String userCmpn,
|
||||
Integer userRole,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
validateAgentSessionId(request.getAgentSessionId());
|
||||
if (!listRepository.existsByIdPrjctIdxAndIdSid(prjctIdx, sid)) {
|
||||
throw BusinessException.notFound("LIST_NOT_FOUND", "통화 이력 대상 리스트를 찾을 수 없습니다.")
|
||||
.with("prjctIdx", prjctIdx)
|
||||
@@ -39,13 +54,173 @@ public class ListCallHistService {
|
||||
.with("listHderId", request.getListHderId());
|
||||
}
|
||||
|
||||
TListCallHistEntity entity = listCallHistRepository.findFirstByAgentSessionId(request.getAgentSessionId())
|
||||
.map(existing -> {
|
||||
existing.updateCallResult(request, regDt);
|
||||
return existing;
|
||||
})
|
||||
.orElseGet(() -> TListCallHistEntity.from(prjctIdx, sid, request, regUser, regDt));
|
||||
listCallHistRepository.findByAgentSessionId(request.getAgentSessionId())
|
||||
.ifPresent(existing -> {
|
||||
validateCallIdentity(existing, prjctIdx, sid, request);
|
||||
validateUsableCallHistory(existing, regUser, userCmpn, userRole, "CALL_HISTORY_NOT_FOUND");
|
||||
});
|
||||
|
||||
return ListCallHistDto.from(listCallHistRepository.save(entity));
|
||||
listCallHistJdbcSupport.upsertCallHistory(prjctIdx, sid, request, regUser, regDt);
|
||||
|
||||
TListCallHistEntity entity = listCallHistRepository.findByAgentSessionId(request.getAgentSessionId())
|
||||
.orElseThrow(() -> BusinessException.notFound(
|
||||
"CALL_HISTORY_NOT_FOUND",
|
||||
"통화 이력을 찾을 수 없습니다."
|
||||
).with("agentSessionId", request.getAgentSessionId()));
|
||||
|
||||
validateCallIdentity(entity, prjctIdx, sid, request);
|
||||
validateUsableCallHistory(entity, regUser, userCmpn, userRole, "CALL_HISTORY_NOT_FOUND");
|
||||
|
||||
return ListCallHistDto.from(entity);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public ListCallHistDto findByAgentSessionId(
|
||||
String agentSessionId,
|
||||
String userId,
|
||||
String userCmpn,
|
||||
Integer userRole
|
||||
) {
|
||||
validateAgentSessionId(agentSessionId);
|
||||
TListCallHistEntity entity = listCallHistRepository.findByAgentSessionId(agentSessionId)
|
||||
.orElseThrow(() -> BusinessException.notFound(
|
||||
"CALL_HISTORY_NOT_FOUND",
|
||||
"통화 이력을 찾을 수 없습니다."
|
||||
).with("agentSessionId", agentSessionId));
|
||||
|
||||
validateUsableCallHistory(entity, userId, userCmpn, userRole, "CALL_HISTORY_NOT_FOUND");
|
||||
return ListCallHistDto.from(entity);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public void validateListCallHistoryForEvent(
|
||||
Long listCallHistIdx,
|
||||
Long prjctIdx,
|
||||
Integer sid,
|
||||
String userId,
|
||||
String userCmpn,
|
||||
Integer userRole
|
||||
) {
|
||||
if (listCallHistIdx == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TListCallHistEntity entity = listCallHistRepository.findById(listCallHistIdx)
|
||||
.orElseThrow(() -> BusinessException.notFound(
|
||||
"CALL_HISTORY_NOT_FOUND",
|
||||
"통화 이력을 찾을 수 없습니다."
|
||||
).with("listCallHistIdx", listCallHistIdx));
|
||||
|
||||
if (!Objects.equals(entity.getPrjctIdx(), prjctIdx) || !Objects.equals(entity.getSid(), sid)) {
|
||||
throw BusinessException.conflict(
|
||||
"CALL_HISTORY_TARGET_CONFLICT",
|
||||
"통화 이력의 프로젝트 또는 SID가 요청과 일치하지 않습니다."
|
||||
)
|
||||
.with("listCallHistIdx", listCallHistIdx)
|
||||
.with("callPrjctIdx", entity.getPrjctIdx())
|
||||
.with("callSid", entity.getSid())
|
||||
.with("requestPrjctIdx", prjctIdx)
|
||||
.with("requestSid", sid);
|
||||
}
|
||||
validateUsableCallHistory(entity, userId, userCmpn, userRole, "CALL_HISTORY_FORBIDDEN");
|
||||
}
|
||||
|
||||
private void validateAgentSessionId(String agentSessionId) {
|
||||
if (!hasText(agentSessionId) || agentSessionId.length() > 64) {
|
||||
throw BusinessException.badRequest(
|
||||
"INVALID_AGENT_SESSION_ID",
|
||||
"agentSessionId가 올바르지 않습니다."
|
||||
)
|
||||
.with("agentSessionId", agentSessionId);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateCallIdentity(
|
||||
TListCallHistEntity existing,
|
||||
Long prjctIdx,
|
||||
Integer sid,
|
||||
ListCallHistRequestDto request
|
||||
) {
|
||||
rejectDifferent("prjctIdx", existing.getPrjctIdx(), prjctIdx);
|
||||
rejectDifferent("sid", existing.getSid(), sid);
|
||||
rejectDifferent("listHderId", existing.getListHderId(), request.getListHderId());
|
||||
rejectDifferentText("destSessionId", existing.getDestSessionId(), request.getDestSessionId());
|
||||
}
|
||||
|
||||
private void validateUsableCallHistory(
|
||||
TListCallHistEntity entity,
|
||||
String userId,
|
||||
String userCmpn,
|
||||
Integer userRole,
|
||||
String errorCode
|
||||
) {
|
||||
if (canUseCallHistory(entity, userId, userCmpn, userRole)) {
|
||||
return;
|
||||
}
|
||||
if ("CALL_HISTORY_NOT_FOUND".equals(errorCode)) {
|
||||
throw BusinessException.notFound(errorCode, "통화 이력을 찾을 수 없습니다.");
|
||||
}
|
||||
throw BusinessException.conflict(
|
||||
errorCode,
|
||||
"현재 사용자가 해당 통화 이력을 사용할 권한이 없습니다."
|
||||
)
|
||||
.with("listCallHistIdx", entity.getId())
|
||||
.with("prjctIdx", entity.getPrjctIdx())
|
||||
.with("sid", entity.getSid());
|
||||
}
|
||||
|
||||
private boolean canUseCallHistory(
|
||||
TListCallHistEntity entity,
|
||||
String userId,
|
||||
String userCmpn,
|
||||
Integer userRole
|
||||
) {
|
||||
if (userRole == null) {
|
||||
return hasText(userId) && Objects.equals(entity.getRegUser(), userId);
|
||||
}
|
||||
if (userRole < ContactConstant.OUTSOURCE_USER_ROLE) {
|
||||
return true;
|
||||
}
|
||||
if (hasText(userId) && Objects.equals(entity.getRegUser(), userId)) {
|
||||
return true;
|
||||
}
|
||||
Long prjctIdx = entity.getPrjctIdx();
|
||||
Integer sid = entity.getSid();
|
||||
if (userRole >= ContactConstant.FIELDWORK_USER_ROLE) {
|
||||
return hasText(userId)
|
||||
&& (projectAssignUserRepository.existsByIdPrjctIdxAndIdUserId(prjctIdx, userId)
|
||||
|| listAssignUserRepository.existsByPrjctIdxAndSidAndUserId(prjctIdx, sid, userId));
|
||||
}
|
||||
return hasText(userCmpn)
|
||||
&& (projectAssignCmpnRepository.existsByIdPrjctIdxAndIdCmpnId(prjctIdx, userCmpn)
|
||||
|| listAssignCmpnRepository.existsByPrjctIdxAndSidAndCmpnId(prjctIdx, sid, userCmpn));
|
||||
}
|
||||
|
||||
private void rejectDifferent(String field, Object existing, Object requested) {
|
||||
if (existing == null || requested == null || Objects.equals(existing, requested)) {
|
||||
return;
|
||||
}
|
||||
throw conflict(field, existing, requested);
|
||||
}
|
||||
|
||||
private void rejectDifferentText(String field, String existing, String requested) {
|
||||
if (!hasText(existing) || !hasText(requested) || Objects.equals(existing, requested)) {
|
||||
return;
|
||||
}
|
||||
throw conflict(field, existing, requested);
|
||||
}
|
||||
|
||||
private BusinessException conflict(String field, Object existing, Object requested) {
|
||||
return BusinessException.conflict(
|
||||
"CALL_HISTORY_IDENTITY_CONFLICT",
|
||||
"동일 agentSessionId의 기존 통화 이력과 요청 값이 일치하지 않습니다."
|
||||
)
|
||||
.with("field", field)
|
||||
.with("existing", existing)
|
||||
.with("requested", requested);
|
||||
}
|
||||
|
||||
private boolean hasText(String value) {
|
||||
return value != null && !value.isBlank();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.excel.ExcelMapper;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
@@ -10,9 +12,13 @@ import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.dto.common.DateRangeDto;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import com.kri.contact.server.dto.list.ListUploadFileInfoDto;
|
||||
import com.kri.contact.server.persistence.entity.TListItemFileEntity;
|
||||
import com.kri.contact.server.persistence.entity.id.TListItemFileEntityId;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctSurveyEntity;
|
||||
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
|
||||
import com.kri.contact.server.persistence.repository.ListItemFileRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectSurveyRepository;
|
||||
import com.kri.contact.server.persistence.repository.ResultCodeRepository;
|
||||
import com.kri.contact.server.service.file.ListItemFileService;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -36,6 +42,7 @@ import org.springframework.stereotype.Service;
|
||||
public class ListDownloadService {
|
||||
|
||||
private static final String HEADER_TYPE = "구분";
|
||||
private static final String HEADER_SURVEY = "설문명";
|
||||
private static final String HEADER_DATE = "일시";
|
||||
private static final String HEADER_USER = "사용자";
|
||||
private static final String HEADER_RESULT = "결과";
|
||||
@@ -46,6 +53,7 @@ public class ListDownloadService {
|
||||
|
||||
private static final List<String> EVENT_HISTORY_HEADERS = List.of(
|
||||
HEADER_TYPE,
|
||||
HEADER_SURVEY,
|
||||
HEADER_DATE,
|
||||
HEADER_USER,
|
||||
HEADER_RESULT,
|
||||
@@ -63,6 +71,8 @@ public class ListDownloadService {
|
||||
private final ListItemFileRepository listItemFileRepository;
|
||||
private final ListItemFileService listItemFileService;
|
||||
private final ResultCodeRepository resultCodeRepository;
|
||||
private final ProjectSurveyRepository projectSurveyRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public byte[] downloadList(Long prjctIdx, ListFilterDto listFilter) {
|
||||
List<ListHeaderDto> headers = getSortedHeaders(prjctIdx);
|
||||
@@ -107,6 +117,7 @@ public class ListDownloadService {
|
||||
validateDateRange(dateRange);
|
||||
List<ListHeaderDto> headers = getSortedHeaders(prjctIdx);
|
||||
Map<EventResultKey, String> resultLabelMap = createResultLabelMap(prjctIdx);
|
||||
Map<Long, String> surveyNameMap = createSurveyNameMap(prjctIdx);
|
||||
int maxHistoryCount = findMaxEventHistoryCount(prjctIdx, listFilter, resultCodeTypes, searchBase, dateRange);
|
||||
List<String> excelHeaders = new ArrayList<>(toBaseHeaderNames(headers));
|
||||
appendRepeatedHeaders(excelHeaders, EVENT_HISTORY_HEADERS, maxHistoryCount);
|
||||
@@ -137,6 +148,7 @@ public class ListDownloadService {
|
||||
row,
|
||||
historyMap.getOrDefault(row.sid(), List.of()),
|
||||
resultLabelMap,
|
||||
surveyNameMap,
|
||||
maxHistoryCount
|
||||
));
|
||||
lastSid = row.sid();
|
||||
@@ -255,6 +267,27 @@ public class ListDownloadService {
|
||||
}
|
||||
}
|
||||
|
||||
public ListUploadFileInfoDto downloadItemFile(Long prjctIdx, Integer sid, Integer listHderId) {
|
||||
TListItemFileEntity fileEntity = listItemFileRepository
|
||||
.findById(TListItemFileEntityId.create(prjctIdx, sid, listHderId))
|
||||
.orElseThrow(() -> BusinessException.notFound(
|
||||
"LIST_ITEM_FILE_NOT_FOUND",
|
||||
"리스트 파일을 찾을 수 없습니다."
|
||||
).with("prjctIdx", prjctIdx).with("sid", sid).with("listHderId", listHderId));
|
||||
|
||||
if (fileEntity.getFileNm() == null || fileEntity.getFileNm().isBlank()) {
|
||||
throw BusinessException.notFound(
|
||||
"LIST_ITEM_FILE_NOT_FOUND",
|
||||
"리스트 파일을 찾을 수 없습니다."
|
||||
).with("prjctIdx", prjctIdx).with("sid", sid).with("listHderId", listHderId);
|
||||
}
|
||||
|
||||
return ListUploadFileInfoDto.builder()
|
||||
.fileName(fileEntity.getFileNm())
|
||||
.bytes(listItemFileService.readItemFile(fileEntity.getFilePath(), fileEntity.getFileNm()))
|
||||
.build();
|
||||
}
|
||||
|
||||
private int findMaxEventHistoryCount(
|
||||
Long prjctIdx,
|
||||
ListFilterDto listFilter,
|
||||
@@ -270,14 +303,30 @@ public class ListDownloadService {
|
||||
return maxCount;
|
||||
}
|
||||
|
||||
Map<Integer, Integer> countMap = listSearchService.findEventHistoryCountsForDownload(
|
||||
prjctIdx,
|
||||
sids,
|
||||
resultCodeTypes,
|
||||
dateRange
|
||||
);
|
||||
Map<Integer, Integer> countMap = searchBase == ListEventHistoryBase.LATEST
|
||||
? listSearchService.findEventHistoriesForDownload(
|
||||
prjctIdx,
|
||||
sids,
|
||||
resultCodeTypes,
|
||||
searchBase,
|
||||
dateRange
|
||||
)
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
entry -> entry.getValue().size(),
|
||||
(left, right) -> right,
|
||||
LinkedHashMap::new
|
||||
))
|
||||
: listSearchService.findEventHistoryCountsForDownload(
|
||||
prjctIdx,
|
||||
sids,
|
||||
resultCodeTypes,
|
||||
dateRange
|
||||
);
|
||||
for (Integer count : countMap.values()) {
|
||||
maxCount = Math.max(maxCount, searchBase == ListEventHistoryBase.LATEST ? 1 : count);
|
||||
maxCount = Math.max(maxCount, count);
|
||||
}
|
||||
lastSid = sids.get(sids.size() - 1);
|
||||
}
|
||||
@@ -330,12 +379,14 @@ public class ListDownloadService {
|
||||
ListSearchService.DownloadListRow row,
|
||||
List<ListSearchService.EventHistoryRow> histories,
|
||||
Map<EventResultKey, String> resultLabelMap,
|
||||
Map<Long, String> surveyNameMap,
|
||||
int maxHistoryCount
|
||||
) {
|
||||
Map<String, Object> excelRow = createBaseRow(headers, row);
|
||||
for (int index = 0; index < maxHistoryCount; index++) {
|
||||
ListSearchService.EventHistoryRow history = index < histories.size() ? histories.get(index) : null;
|
||||
excelRow.put(createRepeatedHeaderName(HEADER_TYPE, index), history == null ? "" : resolveEventTypeLabel(history.eventTy()));
|
||||
excelRow.put(createRepeatedHeaderName(HEADER_SURVEY, index), history == null ? "" : resolveSurveyName(history, surveyNameMap));
|
||||
excelRow.put(createRepeatedHeaderName(HEADER_DATE, index), history == null ? "" : formatDateTime(history.regDt()));
|
||||
excelRow.put(createRepeatedHeaderName(HEADER_USER, index), history == null ? "" : defaultString(history.regUser()));
|
||||
excelRow.put(createRepeatedHeaderName(HEADER_RESULT, index), history == null ? "" : resolveResultLabel(history, resultLabelMap));
|
||||
@@ -436,6 +487,17 @@ public class ListDownloadService {
|
||||
));
|
||||
}
|
||||
|
||||
private Map<Long, String> createSurveyNameMap(Long prjctIdx) {
|
||||
return projectSurveyRepository.findByPrjctIdxOrderBySurveyOrderAscPrjctSurveyIdxAsc(prjctIdx)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
TPrjctSurveyEntity::getPrjctSurveyIdx,
|
||||
TPrjctSurveyEntity::getSurveyNm,
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
}
|
||||
|
||||
private String resolveEventTypeLabel(Short eventTy) {
|
||||
if (Objects.equals(eventTy, ResultCodeType.CONTACT.getCode())) {
|
||||
return "컨택";
|
||||
@@ -457,6 +519,34 @@ public class ListDownloadService {
|
||||
return label == null ? defaultString(history.resultCd()) : label;
|
||||
}
|
||||
|
||||
private String resolveSurveyName(
|
||||
ListSearchService.EventHistoryRow history,
|
||||
Map<Long, String> surveyNameMap
|
||||
) {
|
||||
if (!Objects.equals(history.eventTy(), ResultCodeType.SURVEY.getCode())) {
|
||||
return "";
|
||||
}
|
||||
String surveyName = surveyNameMap.get(history.prjctSurveyIdx());
|
||||
if (surveyName != null) {
|
||||
return surveyName;
|
||||
}
|
||||
return resolveSurveyNameFromMetaData(history.metaData());
|
||||
}
|
||||
|
||||
private String resolveSurveyNameFromMetaData(String metaData) {
|
||||
if (metaData == null || metaData.isBlank()) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
JsonNode surveyNameNode = objectMapper.readTree(metaData)
|
||||
.path("survey")
|
||||
.path("surveyName");
|
||||
return surveyNameNode.isMissingNode() || surveyNameNode.isNull() ? "" : surveyNameNode.asText("");
|
||||
} catch (Exception ignored) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private String defaultString(Object value) {
|
||||
return value == null ? "" : String.valueOf(value);
|
||||
}
|
||||
@@ -470,3 +560,4 @@ public class ListDownloadService {
|
||||
Integer resultCd
|
||||
) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ import com.kri.contact.server.common.enums.ListHeaderTypeAssign;
|
||||
import com.kri.contact.server.common.enums.ListIsUse;
|
||||
import com.kri.contact.server.common.enums.ListSearchResponseType;
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.common.external.notihub.ChannelType;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubApiClient;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubSendResultLastWithSidDto;
|
||||
import com.kri.contact.server.dto.common.DateRangeDto;
|
||||
import com.kri.contact.server.dto.list.ListContactResultDto;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
@@ -20,14 +23,19 @@ import com.kri.contact.server.dto.list.ListSearchRequestDto;
|
||||
import com.kri.contact.server.dto.list.ListSearchWithFullResultDto;
|
||||
import com.kri.contact.server.dto.list.ListSearchWithResultDto;
|
||||
import com.kri.contact.server.dto.list.ListSendResultDto;
|
||||
import com.kri.contact.server.dto.list.ListSurveyResultDto;
|
||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListItemEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctSurveyEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListUpdateHistEntity;
|
||||
import com.kri.contact.server.persistence.repository.ListEventHistRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListItemRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListUpdateHistRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectSurveyRepository;
|
||||
import com.kri.contact.server.service.AssignService.ListAssignCmpn;
|
||||
import com.kri.contact.server.service.AssignService.ListAssignUserRole;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -52,12 +60,15 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RequiredArgsConstructor
|
||||
public class ListSearchService {
|
||||
|
||||
private final ListHeaderService listHeaderService;
|
||||
private final AssignService assignService;
|
||||
private final MessageResultService messageResultService;
|
||||
private final ListEventHistRepository listEventHistRepository;
|
||||
private final ListItemRepository listItemRepository;
|
||||
private final ListRepository listRepository;
|
||||
private final ListUpdateHistRepository listUpdateHistRepository;
|
||||
private final ListHeaderService listHeaderService;
|
||||
private final ProjectRepository projectRepository;
|
||||
private final ProjectSurveyRepository projectSurveyRepository;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public ListSearchWithFullResultDto searchListWithSid(Long prjctIdx, Integer sid) {
|
||||
@@ -216,9 +227,11 @@ public class ListSearchService {
|
||||
Collectors.mapping(
|
||||
entity -> new EventHistoryRow(
|
||||
entity.getEventTy(),
|
||||
entity.getPrjctSurveyIdx(),
|
||||
entity.getRegDt(),
|
||||
entity.getRegUser(),
|
||||
entity.getResultCd(),
|
||||
entity.getMetaData(),
|
||||
entity.getMemo()
|
||||
),
|
||||
Collectors.toList()
|
||||
@@ -379,15 +392,9 @@ public class ListSearchService {
|
||||
.map(row -> row.listEntity().getSid())
|
||||
.toList();
|
||||
|
||||
Map<ListResultKey, TListEventHistEntity> resultMap = listEventHistRepository
|
||||
.findLatestListByEventTyFromLatest(prjctIdx, sids)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
entity -> new ListResultKey(entity.getSid(), entity.getEventTy()),
|
||||
entity -> entity,
|
||||
(left, right) -> left
|
||||
));
|
||||
Map<ListResultKey, TListEventHistEntity> resultMap = createLatestResultMap(prjctIdx, sids);
|
||||
Map<ListResultKey, Integer> attemptCountMap = findAttemptCountMap(prjctIdx, sids);
|
||||
Map<Long, TPrjctSurveyEntity> surveyMap = findProjectSurveyMap(prjctIdx);
|
||||
|
||||
return rows.stream()
|
||||
.map(row -> {
|
||||
@@ -397,17 +404,14 @@ public class ListSearchService {
|
||||
row.itemList(),
|
||||
row.assignValues(),
|
||||
ListContactResultDto.from(
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode())),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode()))
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode(), null)),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode(), null))
|
||||
),
|
||||
ListContactResultDto.from(
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode())),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode()))
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode(), null)),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode(), null))
|
||||
),
|
||||
ListResultBaseDto.from(
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.SURVEY.getCode())),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.SURVEY.getCode()))
|
||||
)
|
||||
createSurveyResults(sid, resultMap, attemptCountMap, surveyMap)
|
||||
);
|
||||
})
|
||||
.toList();
|
||||
@@ -423,38 +427,45 @@ public class ListSearchService {
|
||||
.map(row -> row.listEntity().getSid())
|
||||
.toList();
|
||||
|
||||
Map<ListResultKey, TListEventHistEntity> resultMap = listEventHistRepository
|
||||
.findLatestListByEventTyFromLatest(prjctIdx, sids)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
entity -> new ListResultKey(entity.getSid(), entity.getEventTy()),
|
||||
entity -> entity,
|
||||
(left, right) -> left
|
||||
));
|
||||
Map<ListResultKey, TListEventHistEntity> resultMap = createLatestResultMap(prjctIdx, sids);
|
||||
Map<ListResultKey, Integer> attemptCountMap = findAttemptCountMap(prjctIdx, sids);
|
||||
Map<Long, TPrjctSurveyEntity> surveyMap = findProjectSurveyMap(prjctIdx);
|
||||
|
||||
ListSendResultDto mailSendResult = null;
|
||||
ListSendResultDto smsSendResult = null;
|
||||
TPrjctEntity project = projectRepository.findByPrjctIdxAndDelFalse(prjctIdx);
|
||||
if (project == null) {
|
||||
throw BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
|
||||
.with("prjctIdx", prjctIdx);
|
||||
}
|
||||
|
||||
Map<Integer, ListSendResultDto> mailSendResultMap = messageResultService.findSendResultMap(
|
||||
ChannelType.EMAIL,
|
||||
project.getPrjctCd(),
|
||||
sids
|
||||
);
|
||||
Map<Integer, ListSendResultDto> smsSendResultMap = messageResultService.findSendResultMap(
|
||||
ChannelType.SMS,
|
||||
project.getPrjctCd(),
|
||||
sids
|
||||
);
|
||||
|
||||
return rows.stream()
|
||||
.map(row -> {
|
||||
Integer sid = row.listEntity().getSid();
|
||||
ListSendResultDto mailSendResult = mailSendResultMap.get(sid);
|
||||
ListSendResultDto smsSendResult = smsSendResultMap.get(sid);
|
||||
return ListSearchWithFullResultDto.from(
|
||||
row.listEntity(),
|
||||
row.itemList(),
|
||||
row.assignValues(),
|
||||
ListContactResultDto.from(
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode())),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode()))
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode(), null)),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode(), null))
|
||||
),
|
||||
ListContactResultDto.from(
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode())),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode()))
|
||||
),
|
||||
ListResultBaseDto.from(
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.SURVEY.getCode())),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.SURVEY.getCode()))
|
||||
resultMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode(), null)),
|
||||
attemptCountMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode(), null))
|
||||
),
|
||||
createSurveyResults(sid, resultMap, attemptCountMap, surveyMap),
|
||||
mailSendResult,
|
||||
smsSendResult
|
||||
);
|
||||
@@ -462,6 +473,51 @@ public class ListSearchService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Map<ListResultKey, TListEventHistEntity> createLatestResultMap(Long prjctIdx, List<Integer> sids) {
|
||||
return listEventHistRepository
|
||||
.findLatestListByEventTyFromLatest(prjctIdx, sids)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
entity -> new ListResultKey(entity.getSid(), entity.getEventTy(), entity.getPrjctSurveyIdx()),
|
||||
entity -> entity,
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
}
|
||||
|
||||
private List<ListSurveyResultDto> createSurveyResults(
|
||||
Integer sid,
|
||||
Map<ListResultKey, TListEventHistEntity> resultMap,
|
||||
Map<ListResultKey, Integer> attemptCountMap,
|
||||
Map<Long, TPrjctSurveyEntity> surveyMap
|
||||
) {
|
||||
return resultMap.entrySet().stream()
|
||||
.filter(entry -> Objects.equals(entry.getKey().sid(), sid))
|
||||
.filter(entry -> Objects.equals(entry.getKey().eventTy(), ResultCodeType.SURVEY.getCode()))
|
||||
.filter(entry -> entry.getKey().prjctSurveyIdx() != null)
|
||||
.sorted(Comparator.comparing(entry -> {
|
||||
TPrjctSurveyEntity survey = surveyMap.get(entry.getKey().prjctSurveyIdx());
|
||||
return survey == null ? Short.MAX_VALUE : survey.getSurveyOrder();
|
||||
}))
|
||||
.map(entry -> ListSurveyResultDto.from(
|
||||
surveyMap.get(entry.getKey().prjctSurveyIdx()),
|
||||
entry.getValue(),
|
||||
attemptCountMap.get(entry.getKey())
|
||||
))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Map<Long, TPrjctSurveyEntity> findProjectSurveyMap(Long prjctIdx) {
|
||||
return projectSurveyRepository.findByPrjctIdxOrderBySurveyOrderAscPrjctSurveyIdxAsc(prjctIdx)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
TPrjctSurveyEntity::getPrjctSurveyIdx,
|
||||
survey -> survey,
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
}
|
||||
private Map<ListResultKey, Integer> findAttemptCountMap(Long prjctIdx, Collection<Integer> sids) {
|
||||
if (sids == null || sids.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
@@ -475,7 +531,11 @@ public class ListSearchService {
|
||||
return listEventHistRepository.findHistoryCountsByEventType(prjctIdx, sids, eventTypes)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
projection -> new ListResultKey(projection.getSid(), projection.getEventTy()),
|
||||
projection -> new ListResultKey(
|
||||
projection.getSid(),
|
||||
projection.getEventTy(),
|
||||
projection.getPrjctSurveyIdx()
|
||||
),
|
||||
projection -> projection.getHistoryCount().intValue(),
|
||||
(left, right) -> right,
|
||||
LinkedHashMap::new
|
||||
@@ -489,7 +549,7 @@ public class ListSearchService {
|
||||
ListSearchResponseType responseType
|
||||
) {
|
||||
if (responseType == null) {
|
||||
throw BusinessException.badRequest("INVALID_RESPONSE_TYPE", "리스트 반환 타입은 필수입니다.");
|
||||
throw BusinessException.badRequest("INVALID_RESPONSE_TYPE", "리스트 조회 응답 타입이 올바르지 않습니다.");
|
||||
}
|
||||
|
||||
return switch (responseType) {
|
||||
@@ -556,7 +616,7 @@ public class ListSearchService {
|
||||
for (ListAssignUserRole assignRow : assignRows) {
|
||||
Short role = assignRow.assignRole();
|
||||
AssignValues assignValues = result.computeIfAbsent(assignRow.sid(), ignored -> AssignValues.empty());
|
||||
// TODO: 현재 고정된 역할 매핑을 추후 테이블 기반 배정 정책 조회로 교체해야 한다.
|
||||
// TODO: 배정 역할 표시 로직을 헤더 타입과 일치하도록 정리 필요.
|
||||
if (Objects.equals(role, ListHeaderTypeAssign.CONTACT_INTERVIEWER.getCode())) {
|
||||
assignValues.contactInterviewerIds().add(assignRow.userId());
|
||||
} else if (Objects.equals(role, ListHeaderTypeAssign.FIELD_INTERVIEWER.getCode())) {
|
||||
@@ -568,7 +628,7 @@ public class ListSearchService {
|
||||
|
||||
private List<Short> toEventTypeCodes(Collection<ResultCodeType> resultCodeTypes) {
|
||||
if (resultCodeTypes == null || resultCodeTypes.isEmpty()) {
|
||||
throw BusinessException.badRequest("INVALID_RESULT_CODE_TYPE", "조회할 결과 구분은 1개 이상이어야 합니다.");
|
||||
throw BusinessException.badRequest("INVALID_RESULT_CODE_TYPE", "결과 코드 타입은 1개 이상 전달해야 합니다.");
|
||||
}
|
||||
|
||||
return resultCodeTypes.stream()
|
||||
@@ -624,7 +684,8 @@ public class ListSearchService {
|
||||
|
||||
private record ListResultKey(
|
||||
Integer sid,
|
||||
Short eventTy
|
||||
Short eventTy,
|
||||
Long prjctSurveyIdx
|
||||
) {}
|
||||
|
||||
private record UpdateHistoryGroupKey(
|
||||
@@ -653,9 +714,11 @@ public class ListSearchService {
|
||||
|
||||
public record EventHistoryRow(
|
||||
Short eventTy,
|
||||
Long prjctSurveyIdx,
|
||||
LocalDateTime regDt,
|
||||
String regUser,
|
||||
Integer resultCd,
|
||||
String metaData,
|
||||
String memo
|
||||
) {}
|
||||
|
||||
@@ -673,3 +736,4 @@ public class ListSearchService {
|
||||
Map<Integer, String> itemMap
|
||||
) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,15 @@ import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.dto.list.ListEventHistFromSurveyDto;
|
||||
import com.kri.contact.server.dto.list.ListEventHistInternalMetaDto;
|
||||
import com.kri.contact.server.dto.list.ListEventHistInsertRequestDto;
|
||||
import com.kri.contact.server.dto.list.ListEventHistSurveyMetaDto;
|
||||
import com.kri.contact.server.dto.list.ListEventHistSurveyMetaDto.SurveySnapshot;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import com.kri.contact.server.dto.list.ListUpdateRequestDto;
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListHeaderEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListItemFileEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctSurveyEntity;
|
||||
import com.kri.contact.server.persistence.jdbc.ListUpdateJdbcSupport;
|
||||
import com.kri.contact.server.persistence.jdbc.ListUpdateJdbcSupport.ListItemDeleteRow;
|
||||
import com.kri.contact.server.persistence.jdbc.ListUpdateJdbcSupport.ListItemInsertRow;
|
||||
@@ -30,6 +33,7 @@ import com.kri.contact.server.persistence.repository.ListEventHistRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListHeaderRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListItemFileRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectSurveyRepository;
|
||||
import com.kri.contact.server.service.file.ListItemFileService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -58,8 +62,10 @@ public class ListUpdateService {
|
||||
private final ListRepository listRepository;
|
||||
private final ListEventHistRepository listEventHistRepository;
|
||||
private final ListItemFileRepository listItemFileRepository;
|
||||
private final ProjectSurveyRepository projectSurveyRepository;
|
||||
private final ListItemFileService listItemFileService;
|
||||
private final ResultCodeService resultCodeService;
|
||||
private final ListCallHistService listCallHistService;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final EntityManager entityManager;
|
||||
|
||||
@@ -135,10 +141,13 @@ public class ListUpdateService {
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
validateEventHistoryTarget(request.getPrjctIdx(), request.getSid());
|
||||
TPrjctSurveyEntity survey = validateProjectSurvey(request);
|
||||
validateEventHistoryTarget(survey.getPrjctIdx(), request.getSid());
|
||||
applySurveySnapshot(request, survey);
|
||||
|
||||
listEventHistRepository.save(TListEventHistEntity.fromSurveyHistory(
|
||||
request,
|
||||
survey.getPrjctIdx(),
|
||||
writeMetaData(request),
|
||||
regUser,
|
||||
regDt
|
||||
@@ -194,15 +203,47 @@ public class ListUpdateService {
|
||||
}
|
||||
}
|
||||
|
||||
private TPrjctSurveyEntity validateProjectSurvey(ListEventHistFromSurveyDto request) {
|
||||
TPrjctSurveyEntity survey = projectSurveyRepository.findById(request.getPrjctSurveyIdx())
|
||||
.orElseThrow(() -> BusinessException.badRequest(
|
||||
"PROJECT_SURVEY_NOT_FOUND",
|
||||
"프로젝트 설문을 찾을 수 없습니다."
|
||||
).with("prjctSurveyIdx", request.getPrjctSurveyIdx()));
|
||||
return survey;
|
||||
}
|
||||
|
||||
private void applySurveySnapshot(ListEventHistFromSurveyDto request, TPrjctSurveyEntity survey) {
|
||||
ListEventHistSurveyMetaDto meta = request.getMeta();
|
||||
if (meta.getAction() != null && !Objects.equals(meta.getAction(), request.getAction())) {
|
||||
throw BusinessException.badRequest("INVALID_SURVEY_ACTION", "설문 action이 일치하지 않습니다.");
|
||||
}
|
||||
meta.setAction(request.getAction());
|
||||
meta.setSurvey(SurveySnapshot.builder()
|
||||
.prjctSurveyIdx(survey.getPrjctSurveyIdx())
|
||||
.surveyName(survey.getSurveyNm())
|
||||
.surveyTy(survey.getSurveyTy())
|
||||
.surveyPrjctCd(survey.getSurveyPrjctCd())
|
||||
.build());
|
||||
}
|
||||
@Transactional
|
||||
public void putInternalEventHistory(
|
||||
ListEventHistInsertRequestDto request,
|
||||
String remoteAddr,
|
||||
String regUser,
|
||||
String userCmpn,
|
||||
Integer userRole,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
validateEventHistoryTarget(request.getPrjctIdx(), request.getSid());
|
||||
validateResultCode(request);
|
||||
listCallHistService.validateListCallHistoryForEvent(
|
||||
request.getListCallHistIdx(),
|
||||
request.getPrjctIdx(),
|
||||
request.getSid(),
|
||||
regUser,
|
||||
userCmpn,
|
||||
userRole
|
||||
);
|
||||
ListEventHistInternalMetaDto meta = ListEventHistInternalMetaDto.withRemoteAddr(
|
||||
request.getMeta(),
|
||||
remoteAddr
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import static com.kri.contact.server.common.consts.ContactConstant.REQUEST_SERVICE;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.common.enums.ListHeaderType;
|
||||
import com.kri.contact.server.common.enums.ListIsUse;
|
||||
import com.kri.contact.server.common.external.notihub.ChannelType;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubApiClient;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubBulkSendCreateRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubBulkSendResponseDto;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubDestInfoDto;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubSendRequestBulkDto;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubSendRequestSingleDto;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubTemplateDto;
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import com.kri.contact.server.dto.list.ListSendResultDto;
|
||||
import com.kri.contact.server.dto.message.MessageBulkSendResponseDto;
|
||||
import com.kri.contact.server.dto.message.MessageFailedChunkDto;
|
||||
import com.kri.contact.server.dto.message.MessageSendBulkRequestDto;
|
||||
import com.kri.contact.server.dto.message.MessageSendSingleRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MessageResultService {
|
||||
|
||||
private final NotiHubApiClient notiHubApiClient;
|
||||
public Map<Integer, ListSendResultDto> findSendResultMap(
|
||||
ChannelType channelTy,
|
||||
String prjctCd,
|
||||
List<Integer> sids
|
||||
) {
|
||||
if (sids == null || sids.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
List<String> sidValues = sids.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::valueOf)
|
||||
.toList();
|
||||
if (sidValues.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
return notiHubApiClient.getLastSendResults(channelTy, REQUEST_SERVICE, prjctCd, sidValues)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
dto -> parseSid(dto.getSid()),
|
||||
ListSendResultDto::from,
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
}
|
||||
private Integer parseSid(String sid) {
|
||||
if (sid == null || sid.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.valueOf(sid);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import static com.kri.contact.server.common.consts.ContactConstant.REQUEST_SERVICE;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.common.enums.ChannelType;
|
||||
import com.kri.contact.server.common.enums.ListHeaderType;
|
||||
import com.kri.contact.server.common.enums.ListIsUse;
|
||||
@@ -14,6 +15,7 @@ import com.kri.contact.server.common.external.notihub.NotiHubSendRequestBulkDto;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubSendRequestSingleDto;
|
||||
import com.kri.contact.server.common.external.notihub.NotiHubTemplateDto;
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import com.kri.contact.server.dto.list.ListSendResultDto;
|
||||
import com.kri.contact.server.dto.message.MessageBulkSendResponseDto;
|
||||
import com.kri.contact.server.dto.message.MessageFailedChunkDto;
|
||||
import com.kri.contact.server.dto.message.MessageSendBulkRequestDto;
|
||||
@@ -21,6 +23,7 @@ import com.kri.contact.server.dto.message.MessageSendSingleRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -39,8 +42,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MessageService {
|
||||
|
||||
private static final String REQUEST_SERVICE = "kri-contact";
|
||||
private static final int BULK_SEND_CHUNK_SIZE = 1_000;
|
||||
private static final Pattern TEMPLATE_PARAM_PATTERN = Pattern.compile("(?:\\[\\$|#\\{)([^\\]}]+)(?:]|})");
|
||||
|
||||
|
||||
@@ -1,24 +1,36 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.common.feature.web.page.PageRequestDto;
|
||||
import com.kri.common.feature.web.page.PageResponseDto;
|
||||
import com.kri.common.feature.web.page.Pageables;
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.common.external.shorturl.ShortUrlApiClient;
|
||||
import com.kri.contact.server.dto.project.ProjectCreateRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||
import com.kri.contact.server.dto.project.ProjectMainTemplateUpdateRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectOwnerResponseDto;
|
||||
import com.kri.contact.server.dto.project.ProjectSearchRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectSurveyDto;
|
||||
import com.kri.contact.server.dto.project.ProjectUpdateRequestDto;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctMainTmplatEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctSurveyEntity;
|
||||
import com.kri.contact.server.persistence.query.ProjectSpecs;
|
||||
import com.kri.contact.server.persistence.repository.ProjectMainTemplateRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectSurveyRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -29,19 +41,25 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProjectService {
|
||||
|
||||
private static final List<Short> STATUS_0_1 = List.of((short) 0, (short) 1);
|
||||
private static final List<Short> STATUS_1 = List.of((short) 1);
|
||||
private static final String PRJCT_SURVEY_IDX_TOKEN = "[$prjctSurveyIdx]";
|
||||
private static final String KON_URL_TOKEN = "[$KON-URL]";
|
||||
private static final String KIWI_URL_TOKEN = "[$KIWI-URL]";
|
||||
private static final String KON_SURVEY_BASE_URL = "https://kon.kric.com/project/";
|
||||
private static final String KIWI_SURVEY_BASE_URL = "https://kon.kiwisurvey.kr/project/";
|
||||
|
||||
private final AssignService assignService;
|
||||
private final ResultCodeService resultCodeService;
|
||||
private final ListHeaderService listHeaderService;
|
||||
private final ProjectRepository projectRepository;
|
||||
private final ProjectMainTemplateRepository projectMainTemplateRepository;
|
||||
private final ProjectSurveyRepository projectSurveyRepository;
|
||||
private final ShortUrlApiClient shortUrlApiClient;
|
||||
|
||||
@Transactional
|
||||
public ProjectInfoDto createProject(
|
||||
@@ -55,9 +73,8 @@ public class ProjectService {
|
||||
String prjctCd = this.makePrjctCd(itrnt);
|
||||
TPrjctEntity entity = TPrjctEntity.create(req, prjctCd, regUser, regDt);
|
||||
|
||||
ProjectInfoDto savedProject = ProjectInfoDto.from(projectRepository.save(entity));
|
||||
ProjectInfoDto savedProject = withSurveys(projectRepository.save(entity), List.of());
|
||||
resultCodeService.copyResultCodeFromDefault(savedProject.getPrjctIdx(), regUser, regDt);
|
||||
|
||||
listHeaderService.copyDefaultHeader(savedProject.getPrjctIdx(), regUser, regDt);
|
||||
|
||||
return savedProject;
|
||||
@@ -69,15 +86,21 @@ public class ProjectService {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public ProjectInfoDto getProject(Long prjctIdx) {
|
||||
return ProjectInfoDto.from(projectRepository.findByPrjctIdxAndDelFalse(prjctIdx));
|
||||
return withSurveys(projectRepository.findByPrjctIdxAndDelFalse(prjctIdx));
|
||||
}
|
||||
|
||||
public List<ProjectInfoDto> getTopProject(int topCount, String keyword, String userId,
|
||||
String userCmpn, Integer userRole) {
|
||||
Specification<TPrjctEntity> spec =
|
||||
ProjectSpecs.keywordLike(keyword)
|
||||
.and(ProjectSpecs.isDelFalse());
|
||||
@Transactional(readOnly = true)
|
||||
public List<ProjectInfoDto> getTopProject(
|
||||
int topCount,
|
||||
String keyword,
|
||||
String userId,
|
||||
String userCmpn,
|
||||
Integer userRole
|
||||
) {
|
||||
Specification<TPrjctEntity> spec = ProjectSpecs.keywordLike(keyword)
|
||||
.and(ProjectSpecs.isDelFalse());
|
||||
|
||||
if (userRole >= ContactConstant.OUTSOURCE_USER_ROLE) {
|
||||
if (userRole >= ContactConstant.FIELDWORK_USER_ROLE) {
|
||||
@@ -91,22 +114,21 @@ public class ProjectService {
|
||||
}
|
||||
|
||||
Pageable pageable = PageRequest.of(0, topCount, Sort.by(Sort.Direction.DESC, "regDt"));
|
||||
|
||||
return projectRepository.findAll(spec, pageable)
|
||||
.getContent()
|
||||
.stream()
|
||||
.map(ProjectInfoDto::from) // <-- 너네 매핑 방식에 맞게 수정
|
||||
.toList();
|
||||
return withSurveys(projectRepository.findAll(spec, pageable).getContent());
|
||||
}
|
||||
|
||||
public PageResponseDto<ProjectInfoDto> searchProject(ProjectSearchRequestDto req, String userId,
|
||||
String userCmpn, Integer userRole) {
|
||||
Specification<TPrjctEntity> spec =
|
||||
ProjectSpecs.keywordLike(req.getPrjctText())
|
||||
.and(ProjectSpecs.isDelFalse())
|
||||
.and(ProjectSpecs.statusIn(req.getPrjctStatusList()))
|
||||
.and(ProjectSpecs.ownerDeptIn(req.getOwnerDeptList()))
|
||||
.and(ProjectSpecs.ownerFwIn(req.getOwnerFwList()));
|
||||
@Transactional(readOnly = true)
|
||||
public PageResponseDto<ProjectInfoDto> searchProject(
|
||||
ProjectSearchRequestDto req,
|
||||
String userId,
|
||||
String userCmpn,
|
||||
Integer userRole
|
||||
) {
|
||||
Specification<TPrjctEntity> spec = ProjectSpecs.keywordLike(req.getPrjctText())
|
||||
.and(ProjectSpecs.isDelFalse())
|
||||
.and(ProjectSpecs.statusIn(req.getPrjctStatusList()))
|
||||
.and(ProjectSpecs.ownerDeptIn(req.getOwnerDeptList()))
|
||||
.and(ProjectSpecs.ownerFwIn(req.getOwnerFwList()));
|
||||
|
||||
if (userRole >= ContactConstant.OUTSOURCE_USER_ROLE) {
|
||||
if (userRole >= ContactConstant.FIELDWORK_USER_ROLE) {
|
||||
@@ -120,38 +142,39 @@ public class ProjectService {
|
||||
}
|
||||
|
||||
PageRequestDto pageReq = req.getPageRequest();
|
||||
Pageable pageable = Pageables.of(pageReq, TPrjctEntity.class);
|
||||
Pageable pageable = Pageables.of(pageReq, TPrjctEntity.class, Map.of(
|
||||
"prjctName", "prjctNm"
|
||||
));
|
||||
|
||||
Page<ProjectInfoDto> page = projectRepository.findAll(spec, pageable)
|
||||
.map(ProjectInfoDto::from);
|
||||
Page<TPrjctEntity> page = projectRepository.findAll(spec, pageable);
|
||||
Map<Long, List<ProjectSurveyDto>> surveyMap = findSurveyMap(
|
||||
page.getContent().stream()
|
||||
.map(TPrjctEntity::getPrjctIdx)
|
||||
.toList()
|
||||
);
|
||||
|
||||
return PageResponseDto.from(page);
|
||||
return PageResponseDto.from(page.map(entity -> withSurveys(
|
||||
entity,
|
||||
surveyMap.getOrDefault(entity.getPrjctIdx(), List.of())
|
||||
)));
|
||||
}
|
||||
|
||||
public ProjectOwnerResponseDto getOwnerList(Integer userRole) {
|
||||
ProjectOwnerResponseDto responseDto = new ProjectOwnerResponseDto();
|
||||
|
||||
responseDto.setOwnerDeptList(this.getOwnerDeptList(userRole));
|
||||
responseDto.setOwnerFwList(this.getOwnerFwList(userRole));
|
||||
|
||||
return responseDto;
|
||||
}
|
||||
|
||||
public List<String> getOwnerDeptList(Integer userRole) {
|
||||
final List<Short> statusList =
|
||||
(userRole < ContactConstant.OUTSOURCE_USER_ROLE) ? null :
|
||||
(userRole < ContactConstant.FIELDWORK_USER_ROLE) ? STATUS_0_1 :
|
||||
STATUS_1;
|
||||
|
||||
final List<Short> statusList = userRole < ContactConstant.OUTSOURCE_USER_ROLE ? null
|
||||
: userRole < ContactConstant.FIELDWORK_USER_ROLE ? STATUS_0_1 : STATUS_1;
|
||||
return projectRepository.findDistinctOwnerDept(statusList);
|
||||
}
|
||||
|
||||
public List<String> getOwnerFwList(Integer userRole) {
|
||||
final List<Short> statusList =
|
||||
(userRole < ContactConstant.OUTSOURCE_USER_ROLE) ? null :
|
||||
(userRole < ContactConstant.FIELDWORK_USER_ROLE) ? STATUS_0_1 :
|
||||
STATUS_1;
|
||||
|
||||
final List<Short> statusList = userRole < ContactConstant.OUTSOURCE_USER_ROLE ? null
|
||||
: userRole < ContactConstant.FIELDWORK_USER_ROLE ? STATUS_0_1 : STATUS_1;
|
||||
return projectRepository.findDistinctOwnerFw(statusList);
|
||||
}
|
||||
|
||||
@@ -162,16 +185,19 @@ public class ProjectService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProject(long prjctIdx, ProjectUpdateRequestDto req, String modUser,
|
||||
LocalDateTime modDt) {
|
||||
// dirty checking 업데이트
|
||||
public void updateProject(
|
||||
long prjctIdx,
|
||||
ProjectUpdateRequestDto req,
|
||||
String modUser,
|
||||
LocalDateTime modDt,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
TPrjctEntity entity = projectRepository.findById(prjctIdx)
|
||||
.orElseThrow(() ->
|
||||
BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
|
||||
.with("prjctIdx", prjctIdx)
|
||||
);
|
||||
.orElseThrow(() -> BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
|
||||
.with("prjctIdx", prjctIdx));
|
||||
|
||||
entity.updateFrom(req.getProjectInfo(), modUser, modDt);
|
||||
updateProjectSurveys(prjctIdx, req.getProjectInfo().getSurveys(), modUser, modDt, ctx);
|
||||
|
||||
assignService.upsertPrjctCmpnAssign(prjctIdx, req.getAssignCmpnIdList(), modUser, modDt);
|
||||
resultCodeService.updateResultCode(prjctIdx, req.getResultCodeList(), modUser, modDt);
|
||||
@@ -201,7 +227,184 @@ public class ProjectService {
|
||||
}
|
||||
}
|
||||
|
||||
/***************************private************************************/
|
||||
private ProjectInfoDto withSurveys(TPrjctEntity entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
List<ProjectSurveyDto> surveys = projectSurveyRepository
|
||||
.findByPrjctIdxOrderBySurveyOrderAscPrjctSurveyIdxAsc(entity.getPrjctIdx())
|
||||
.stream()
|
||||
.map(ProjectSurveyDto::from)
|
||||
.toList();
|
||||
return withSurveys(entity, surveys);
|
||||
}
|
||||
|
||||
private ProjectInfoDto withSurveys(TPrjctEntity entity, List<ProjectSurveyDto> surveys) {
|
||||
ProjectInfoDto dto = ProjectInfoDto.from(entity);
|
||||
if (dto != null) {
|
||||
dto.setSurveys(surveys == null ? new ArrayList<>() : surveys);
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
private List<ProjectInfoDto> withSurveys(List<TPrjctEntity> entities) {
|
||||
Map<Long, List<ProjectSurveyDto>> surveyMap = findSurveyMap(
|
||||
entities.stream()
|
||||
.map(TPrjctEntity::getPrjctIdx)
|
||||
.toList()
|
||||
);
|
||||
return entities.stream()
|
||||
.map(entity -> withSurveys(entity, surveyMap.getOrDefault(entity.getPrjctIdx(), List.of())))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Map<Long, List<ProjectSurveyDto>> findSurveyMap(Collection<Long> prjctIdxs) {
|
||||
if (prjctIdxs == null || prjctIdxs.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return projectSurveyRepository
|
||||
.findByPrjctIdxInOrderByPrjctIdxAscSurveyOrderAscPrjctSurveyIdxAsc(prjctIdxs)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
TPrjctSurveyEntity::getPrjctIdx,
|
||||
LinkedHashMap::new,
|
||||
Collectors.mapping(ProjectSurveyDto::from, Collectors.toList())
|
||||
));
|
||||
}
|
||||
|
||||
private void updateProjectSurveys(
|
||||
Long prjctIdx,
|
||||
List<ProjectSurveyDto> surveys,
|
||||
String modUser,
|
||||
LocalDateTime modDt,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
List<ProjectSurveyDto> requestSurveys = surveys == null ? List.of() : surveys;
|
||||
Map<Long, TPrjctSurveyEntity> existingMap = projectSurveyRepository
|
||||
.findByPrjctIdxOrderBySurveyOrderAscPrjctSurveyIdxAsc(prjctIdx)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
TPrjctSurveyEntity::getPrjctSurveyIdx,
|
||||
Function.identity(),
|
||||
(left, right) -> left,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
|
||||
Set<Long> requestedIds = requestSurveys.stream()
|
||||
.map(ProjectSurveyDto::getPrjctSurveyIdx)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<TPrjctSurveyEntity> deleteTargets = existingMap.values().stream()
|
||||
.filter(entity -> !requestedIds.contains(entity.getPrjctSurveyIdx()))
|
||||
.toList();
|
||||
if (!deleteTargets.isEmpty()) {
|
||||
projectSurveyRepository.deleteAllInBatch(deleteTargets);
|
||||
}
|
||||
|
||||
List<TPrjctSurveyEntity> saveTargets = new ArrayList<>();
|
||||
for (ProjectSurveyDto survey : requestSurveys) {
|
||||
if (survey.getPrjctSurveyIdx() == null) {
|
||||
saveTargets.add(TPrjctSurveyEntity.create(prjctIdx, survey, modUser, modDt));
|
||||
continue;
|
||||
}
|
||||
|
||||
TPrjctSurveyEntity entity = existingMap.get(survey.getPrjctSurveyIdx());
|
||||
if (entity == null || !Objects.equals(entity.getPrjctIdx(), prjctIdx)) {
|
||||
throw BusinessException.badRequest("PROJECT_SURVEY_NOT_FOUND", "프로젝트 설문을 찾을 수 없습니다.")
|
||||
.with("prjctSurveyIdx", survey.getPrjctSurveyIdx());
|
||||
}
|
||||
entity.updateFrom(survey, modUser, modDt);
|
||||
saveTargets.add(entity);
|
||||
}
|
||||
if (!saveTargets.isEmpty()) {
|
||||
List<TPrjctSurveyEntity> savedTargets = projectSurveyRepository.saveAllAndFlush(saveTargets);
|
||||
replacePrjctSurveyIdxToken(savedTargets);
|
||||
resolveSurveyUrls(savedTargets, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private void replacePrjctSurveyIdxToken(List<TPrjctSurveyEntity> surveys) {
|
||||
for (TPrjctSurveyEntity survey : surveys) {
|
||||
String surveyUrl = survey.getSurveyUrl();
|
||||
Long prjctSurveyIdx = survey.getPrjctSurveyIdx();
|
||||
if (surveyUrl == null || prjctSurveyIdx == null || !surveyUrl.contains(PRJCT_SURVEY_IDX_TOKEN)) {
|
||||
continue;
|
||||
}
|
||||
survey.setSurveyUrl(surveyUrl.replace(PRJCT_SURVEY_IDX_TOKEN, prjctSurveyIdx.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveSurveyUrls(List<TPrjctSurveyEntity> surveys, RequestUserContext ctx) {
|
||||
for (TPrjctSurveyEntity survey : surveys) {
|
||||
ResolvedSurveyUrl resolved = resolveSurveyUrl(survey, ctx);
|
||||
if (resolved == null) {
|
||||
continue;
|
||||
}
|
||||
survey.setSurveyUrl(resolved.finalUrl());
|
||||
survey.setSurveyFullUrl(resolved.fullUrl());
|
||||
survey.setSurveyShortUrl(resolved.shortUrl());
|
||||
}
|
||||
}
|
||||
|
||||
private ResolvedSurveyUrl resolveSurveyUrl(TPrjctSurveyEntity survey, RequestUserContext ctx) {
|
||||
String requestedUrl = survey.getSurveyUrl();
|
||||
if (requestedUrl == null || requestedUrl.isBlank()) {
|
||||
survey.setSurveyFullUrl(null);
|
||||
survey.setSurveyShortUrl(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
String baseUrl = resolveSurveyBaseUrl(survey);
|
||||
if (baseUrl == null) {
|
||||
survey.setSurveyFullUrl(null);
|
||||
survey.setSurveyShortUrl(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
String queryString = extractQueryString(requestedUrl);
|
||||
String fullUrl = appendQueryString(baseUrl, queryString);
|
||||
String shortUrl = shortUrlApiClient.createShortUrl(baseUrl, ctx)
|
||||
.map(url -> appendQueryString(url, queryString))
|
||||
.orElse(null);
|
||||
|
||||
return new ResolvedSurveyUrl(shortUrl == null ? fullUrl : shortUrl, fullUrl, shortUrl);
|
||||
}
|
||||
|
||||
private String resolveSurveyBaseUrl(TPrjctSurveyEntity survey) {
|
||||
String surveyUrl = survey.getSurveyUrl();
|
||||
String surveyPrjctCd = survey.getSurveyPrjctCd();
|
||||
Long prjctSurveyIdx = survey.getPrjctSurveyIdx();
|
||||
if (surveyUrl == null || surveyPrjctCd == null || surveyPrjctCd.isBlank() || prjctSurveyIdx == null) {
|
||||
return null;
|
||||
}
|
||||
if (surveyUrl.contains(KON_URL_TOKEN)) {
|
||||
return KON_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp?psidx=" + prjctSurveyIdx;
|
||||
}
|
||||
if (surveyUrl.contains(KIWI_URL_TOKEN)) {
|
||||
return KIWI_SURVEY_BASE_URL + surveyPrjctCd + "/INDEX.asp?psidx=" + prjctSurveyIdx;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String extractQueryString(String url) {
|
||||
int queryIndex = url.indexOf('?');
|
||||
if (queryIndex < 0 || queryIndex + 1 >= url.length()) {
|
||||
return "";
|
||||
}
|
||||
return url.substring(queryIndex + 1);
|
||||
}
|
||||
|
||||
private String appendQueryString(String baseUrl, String queryString) {
|
||||
if (queryString == null || queryString.isBlank()) {
|
||||
return baseUrl;
|
||||
}
|
||||
return baseUrl + (baseUrl.contains("?") ? "&" : "?") + queryString;
|
||||
}
|
||||
|
||||
private record ResolvedSurveyUrl(String finalUrl, String fullUrl, String shortUrl) {
|
||||
}
|
||||
|
||||
private String makePrjctCd(String itrntPrjctCd) {
|
||||
String prefix = itrntPrjctCd + "_";
|
||||
|
||||
@@ -216,6 +419,6 @@ public class ProjectService {
|
||||
.max()
|
||||
.orElse(0);
|
||||
|
||||
return prefix + String.format("%03d", (maxSubCode + 1));
|
||||
return prefix + String.format("%03d", maxSubCode + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user