260408_01_ENH: 리스트 업로드, 조회, 삭제 1차 구현 완료
This commit is contained in:
@@ -38,7 +38,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "com.kri.common:starter:beta.1.0.66"
|
||||
implementation "com.kri.common:starter:beta.1.1.15"
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
@@ -56,7 +56,7 @@ dependencies {
|
||||
//MySQL
|
||||
runtimeOnly "com.mysql:mysql-connector-j"
|
||||
// QueryDSL JPA
|
||||
implementation "com.querydsl:querydsl-jpa:5.0.0:jakarta"
|
||||
implementation "io.github.openfeign.querydsl:querydsl-jpa:7.1"
|
||||
|
||||
// QClass 생성용 annotationProcessor
|
||||
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
|
||||
@@ -66,7 +66,7 @@ dependencies {
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
|
||||
implementation 'org.apache.poi:poi-ooxml:5.2.5'
|
||||
implementation 'org.apache.poi:poi-ooxml:5.5.1'
|
||||
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package com.kri.contact.server.common.consts;
|
||||
|
||||
import com.kri.contact.server.common.enums.ListHeaderType;
|
||||
import com.kri.contact.server.common.enums.ListHeaderTypeDefault;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class ContactConstant {
|
||||
public static final int INSERT_CHUNK_SIZE = 1_000;
|
||||
public static final String DEFAULT_COMPANY_NAME = "KRI";
|
||||
@@ -7,6 +13,23 @@ public final class ContactConstant {
|
||||
|
||||
public static final int OUTSOURCE_USER_ROLE = 4000;
|
||||
public static final int FIELDWORK_USER_ROLE = 9000;
|
||||
|
||||
public static final String LIST_TEXT_REGEX = "^[가-힣a-zA-Z0-9()_\\-\\[\\] ]+$";
|
||||
|
||||
public static final List<ListHeaderType> DEFAULT_AND_FILE_TYPE = Stream.concat(
|
||||
Arrays.stream(ListHeaderTypeDefault.values())
|
||||
.map(defaultType -> ListHeaderType.fromCode(defaultType.getCode())),
|
||||
Stream.of(ListHeaderType.FILE)
|
||||
).toList();
|
||||
public static final List<ListHeaderType> ASSIGN_TYPE = List.of(
|
||||
ListHeaderType.OUTSOURCE,
|
||||
ListHeaderType.FIELDWORK
|
||||
);
|
||||
public static final List<ListHeaderType> EMAIL_TELNUM_TYPE = List.of(
|
||||
ListHeaderType.EMAIL,
|
||||
ListHeaderType.TEL_NUM
|
||||
);
|
||||
|
||||
private ContactConstant() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,19 @@ package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter(onMethod_ = @JsonValue)
|
||||
@RequiredArgsConstructor
|
||||
@Schema(description = "발송 채널")
|
||||
public enum ChannelType implements CodeEnum<Short> {
|
||||
|
||||
@Schema(description = "이메일")
|
||||
EMAIL((short) 1),
|
||||
@Schema(description = "문자")
|
||||
SMS((short) 2);
|
||||
|
||||
private final Short code;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -10,16 +10,20 @@ import lombok.RequiredArgsConstructor;
|
||||
@RequiredArgsConstructor
|
||||
public enum ListHeaderType implements CodeEnum<Short> {
|
||||
|
||||
SID((short) 11), //11 : SID
|
||||
IS_USE((short) 12), //12 : 사용여부
|
||||
MEMO((short) 19), //19 : 메모
|
||||
TEL_NUM((short) 21), //21 : 전화번호
|
||||
EMAIL((short) 31), //31 : 이메일
|
||||
FILE((short) 81), //81 : 파일업로드
|
||||
SID(ListHeaderTypeDefault.SID), //11 : SID
|
||||
IS_USE(ListHeaderTypeDefault.IS_USE), //12 : 사용여부
|
||||
OUTSOURCE(ListHeaderTypeDefault.OUTSOURCE), //13 : 외주사
|
||||
FIELDWORK(ListHeaderTypeDefault.FIELDWORK), //14 : 컨택원/면접원
|
||||
MEMO(ListHeaderTypeDefault.MEMO), //19 : 메모
|
||||
TEL_NUM(ListHeaderTypeSpecific.TEL_NUM), //21 : 전화번호
|
||||
EMAIL(ListHeaderTypeSpecific.EMAIL), //31 : 이메일
|
||||
FILE(ListHeaderTypeSpecific.FILE), //81 : 파일업로드
|
||||
TEXT((short) 91); //91 : 텍스트
|
||||
|
||||
private final Short code;
|
||||
|
||||
ListHeaderType(CodeEnum<Short> source) { this.code = source.getCode();}
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ListHeaderType fromCode(Short code) {
|
||||
if (code == null) {
|
||||
@@ -32,4 +36,4 @@ public enum ListHeaderType implements CodeEnum<Short> {
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ListHeaderType code: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.kri.contact.server.common.enums;
|
||||
|
||||
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 ListHeaderTypeDefault implements CodeEnum<Short> {
|
||||
|
||||
SID((short) 11), //11 : SID
|
||||
IS_USE((short) 12), //12 : 사용여부
|
||||
OUTSOURCE((short) 13), //13 : 외주사
|
||||
FIELDWORK((short) 14), //14 : 컨택원/면접원
|
||||
MEMO((short) 19); //19 : 메모
|
||||
|
||||
private final Short code;
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ListHeaderTypeDefault fromCode(Short code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (ListHeaderTypeDefault s : values()) {
|
||||
if (s.code.equals(code)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ListHeaderType code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.kri.contact.server.common.enums;
|
||||
|
||||
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 ListHeaderTypeSpecific implements CodeEnum<Short> {
|
||||
|
||||
TEL_NUM((short) 21), //21 : 전화번호
|
||||
EMAIL((short) 31), //31 : 이메일
|
||||
FILE((short) 81); //81 : 파일업로드
|
||||
|
||||
private final Short code;
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ListHeaderTypeSpecific fromCode(Short code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (ListHeaderTypeSpecific s : values()) {
|
||||
if (s.code.equals(code)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ListHeaderSpecificType code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.kri.contact.server.common.enums;
|
||||
|
||||
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 ListIsUse implements CodeEnum<Short> {
|
||||
|
||||
UNUSABLE((short) 0), //0 : 사용 안함
|
||||
USABLE((short) 1), //1 : 사용
|
||||
TEST((short) 9); //9 : TEST
|
||||
|
||||
private final Short code;
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ListIsUse fromCode(Short code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (ListIsUse s : values()) {
|
||||
if (s.code.equals(code)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ListIsUse code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter(onMethod_ = @JsonValue)
|
||||
@RequiredArgsConstructor
|
||||
public enum ListResetMode {
|
||||
|
||||
ALL((short) 0),
|
||||
HIST((short) 1),
|
||||
LIST_UPLOAD((short) 2);
|
||||
|
||||
private final Short code;
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ListResetMode fromCode(Short code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (ListResetMode s : values()) {
|
||||
if (s.code.equals(code)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ListResetMode code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter(onMethod_ = @JsonValue)
|
||||
@RequiredArgsConstructor
|
||||
public enum ListUploadMode implements CodeEnum<Short> {
|
||||
|
||||
CHANGE((short) 0),
|
||||
ADD((short) 1);
|
||||
|
||||
private final Short code;
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ListUploadMode fromCode(Short code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (ListUploadMode s : values()) {
|
||||
if (s.code.equals(code)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ListUploadMode code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -27,4 +27,4 @@ public enum ProjectStatus implements CodeEnum<Short> {
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ProjectStatus code: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -28,4 +28,4 @@ public enum ResultCodeType implements CodeEnum<Short> {
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ResultCodeType code: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
import com.kri.common.feature.enums.CodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.kri.contact.server.common.external.intranet;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.common.http.ExternalApiClient;
|
||||
import com.kri.common.http.ExternalApiResponse;
|
||||
import com.kri.common.feature.http.ExternalApiClient;
|
||||
import com.kri.common.feature.http.ExternalApiResponse;
|
||||
import com.kri.contact.server.dto.auth.LoginRequestDto;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.common.jpa;
|
||||
|
||||
import com.kri.common.jpa.AbstractCodeEnumConverter;
|
||||
import com.kri.common.feature.jpa.AbstractCodeEnumConverter;
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
@@ -10,4 +10,4 @@ public class ResultCodeTypeConverter extends AbstractCodeEnumConverter<ResultCod
|
||||
public ResultCodeTypeConverter() {
|
||||
super(ResultCodeType.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.contact.server.common.util;
|
||||
|
||||
import com.kri.common.excel.ExcelMapper;
|
||||
import com.kri.contact.server.dto.excel.ExcelUploadResponseDto;
|
||||
import com.kri.common.feature.excel.ExcelMapper;
|
||||
import com.kri.contact.server.dto.excel.ExcelUploadResultDto;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
@@ -21,18 +21,19 @@ public final class ExcelUploadResultUtil {
|
||||
* @param errorClass 에러 DTO 타입 (ExcelMapper용)
|
||||
* @param errorFileName 에러 엑셀 파일명
|
||||
*/
|
||||
public static <E> ExcelUploadResponseDto buildUploadResult(
|
||||
public static <E> ExcelUploadResultDto buildUploadResult(
|
||||
int totalCount,
|
||||
int successCount,
|
||||
int failCount,
|
||||
List<E> errorList,
|
||||
Class<E> errorClass,
|
||||
String errorFileName
|
||||
) {
|
||||
int failCount = (errorList != null) ? errorList.size() : 0;
|
||||
int errorListCount = (errorList != null) ? errorList.size() : 0;
|
||||
|
||||
// 1) 에러가 없으면 파일 없이 반환
|
||||
if (failCount == 0) {
|
||||
return ExcelUploadResponseDto.builder()
|
||||
if (errorListCount == 0) {
|
||||
return ExcelUploadResultDto.builder()
|
||||
.totalCount(totalCount)
|
||||
.successCount(successCount)
|
||||
.failCount(0)
|
||||
@@ -41,23 +42,24 @@ public final class ExcelUploadResultUtil {
|
||||
}
|
||||
|
||||
// 2) 에러가 있으면 에러 리스트를 엑셀로 생성
|
||||
try (Workbook errorWb = ExcelMapper.writeToWorkbook(errorList, errorClass);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
|
||||
try (
|
||||
Workbook errorWb = ExcelMapper.writeToWorkbook(errorList, errorClass);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream()
|
||||
) {
|
||||
errorWb.write(bos);
|
||||
byte[] bytes = bos.toByteArray();
|
||||
String base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
|
||||
return ExcelUploadResponseDto.builder()
|
||||
return ExcelUploadResultDto.builder()
|
||||
.totalCount(totalCount)
|
||||
.successCount(successCount)
|
||||
.failCount(failCount)
|
||||
.hasErrorFile(true)
|
||||
.errorFileName(errorFileName)
|
||||
.errorFileBase64(base64)
|
||||
.errorFileBase64(Base64.getEncoder().encodeToString(bytes))
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
// 에러 파일 생성 실패해도 업로드 결과는 그대로 리턴
|
||||
return ExcelUploadResponseDto.builder()
|
||||
return ExcelUploadResultDto.builder()
|
||||
.totalCount(totalCount)
|
||||
.successCount(successCount)
|
||||
.failCount(failCount)
|
||||
|
||||
15
src/main/java/com/kri/contact/server/config/JdbcConfig.java
Normal file
15
src/main/java/com/kri/contact/server/config/JdbcConfig.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.kri.contact.server.config;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@Configuration
|
||||
public class JdbcConfig {
|
||||
|
||||
@Bean
|
||||
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Configuration
|
||||
public class WebResourceConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${kri.contact-senario.upload-base-dir}")
|
||||
@Value("${kri.file.contact-senario-base-dir}")
|
||||
private String uploadBaseDir;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.service.AssignService;
|
||||
import com.kri.contact.server.service.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.dto.auth.LoginRequestDto;
|
||||
import com.kri.contact.server.dto.auth.LoginResponseDto;
|
||||
import com.kri.contact.server.service.AuthService;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.dto.excel.ExcelUploadResultDto;
|
||||
import com.kri.contact.server.dto.list.ListUploadRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||
import com.kri.contact.server.service.ListUploadService;
|
||||
import com.kri.contact.server.service.ProjectService;
|
||||
import com.kri.contact.server.service.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/list")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "List", description = "리스트 API")
|
||||
public class ListController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
private final ListUploadService listUploadService;
|
||||
private final SystemEventLogService systemEventLogService;
|
||||
|
||||
@Operation(summary = "리스트 파일 업로드 양식 다운로드")
|
||||
@PostMapping("excel/template/{prjctIdx}")
|
||||
public ResponseEntity<byte[]> downloadExcelTemplate(
|
||||
@PathVariable Long prjctIdx,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
ProjectInfoDto projectInfoDto = projectService.getProject(prjctIdx);
|
||||
if (projectInfoDto == null) throw BusinessException.internalError("프로젝트가 없습니다.");
|
||||
|
||||
byte[] bytes = listUploadService.downloadExcelTemplate(prjctIdx);
|
||||
String fileName = projectInfoDto.getPrjctName() + " upload_template.xlsx";
|
||||
String contentDisposition = "attachment; filename*=UTF-8''" +
|
||||
URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20");
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
|
||||
.contentType(MediaType.parseMediaType(
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
|
||||
.body(bytes);
|
||||
}
|
||||
|
||||
@Operation(summary = "리스트 파일 업로드")
|
||||
@PostMapping(value = "excel/upload/{prjctIdx}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ExcelUploadResultDto uploadExcel(
|
||||
@PathVariable Long prjctIdx,
|
||||
@RequestParam("file") MultipartFile file,
|
||||
@Valid @RequestPart("request") ListUploadRequestDto request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
ProjectInfoDto projectInfoDto = projectService.getProject(prjctIdx);
|
||||
if (projectInfoDto == null) throw BusinessException.internalError("프로젝트가 없습니다.");
|
||||
|
||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
|
||||
ExcelUploadResultDto result = listUploadService.uploadExcel(prjctIdx, file, request, ctx.getUserId(), now);
|
||||
systemEventLogService.writeUploadList(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx, file.getOriginalFilename());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import com.kri.contact.server.service.ListHeaderService;
|
||||
import com.kri.contact.server.service.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -22,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class ListHeaderController {
|
||||
|
||||
ListHeaderService listHeaderService;
|
||||
SystemEventLogService systemEventLogService;
|
||||
|
||||
@Operation(summary = "리스트 헤더 조회")
|
||||
@GetMapping("/{prjctIdx}")
|
||||
@@ -36,6 +40,10 @@ public class ListHeaderController {
|
||||
@Valid @RequestBody List<ListHeaderDto> headerList,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
listHeaderService.upsertHeader(prjctIdx, headerList, ctx.getUserId());
|
||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
listHeaderService.upsertHeader(prjctIdx, headerList, ctx.getUserId(), now);
|
||||
|
||||
systemEventLogService.writeUpsertListHeader(ctx.getUserId(), now, ctx.getClientIp(), prjctIdx,
|
||||
headerList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.common.webmvc.page.PageResponseDto;
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.common.feature.web.page.PageResponseDto;
|
||||
import com.kri.contact.server.common.enums.ChannelType;
|
||||
import com.kri.contact.server.dto.project.ProjectCreateRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.dto.user.RoleInfoDto;
|
||||
import com.kri.contact.server.service.RoleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -24,4 +24,4 @@ public class RoleController {
|
||||
public List<RoleInfoDto> getRoleList(RequestUserContext ctx) {
|
||||
return roleService.getRoleList(ctx.getUserRole());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.dto.common.DataVerificationDto;
|
||||
import com.kri.contact.server.dto.excel.ExcelUploadResponseDto;
|
||||
import com.kri.contact.server.dto.user.UserInfoDto;
|
||||
import com.kri.contact.server.dto.excel.ExcelUploadResultDto;
|
||||
import com.kri.contact.server.dto.systemlog.UploadUserContentDto;
|
||||
import com.kri.contact.server.dto.user.UserInfoDto;
|
||||
import com.kri.contact.server.service.SystemEventLogService;
|
||||
import com.kri.contact.server.service.UserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -25,8 +25,8 @@ import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -64,7 +64,7 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "컨택원/면접원 목록 조회")
|
||||
@Operation(summary = "컨택트 면접원 목록 조회")
|
||||
@GetMapping("fieldwork")
|
||||
public List<UserInfoDto> getFiledoworkUserList(RequestUserContext ctx) {
|
||||
String searchCmpn = ctx.getUserCmpn();
|
||||
@@ -75,7 +75,7 @@ public class UserController {
|
||||
return userService.getFieldworkUserListWithCmpn(searchCmpn);
|
||||
}
|
||||
|
||||
@Operation(summary = "외주사 목록 조회")
|
||||
@Operation(summary = "외주 목록 조회")
|
||||
@GetMapping("outsource")
|
||||
List<UserInfoDto> getOutsourceList() {
|
||||
return userService.getOutsourceList();
|
||||
@@ -105,20 +105,22 @@ public class UserController {
|
||||
systemEventLogService.writeCreateUserLog(regId, now, clientIp, userInfo);
|
||||
}
|
||||
|
||||
@Operation(summary = "사용자 일괄 생성(엑셀 업로드)")
|
||||
@PostMapping("/excel")
|
||||
public ExcelUploadResponseDto createUserFromExcel(
|
||||
@RequestPart("file") MultipartFile file,
|
||||
@Operation(
|
||||
summary = "사용자 일괄 생성(엑셀 업로드)",
|
||||
description = "성공하면 JSON, 실패가 있으면 실패 내역 엑셀(xlsx) 반환"
|
||||
)
|
||||
@PostMapping(value = "/excel/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ExcelUploadResultDto createUserFromExcel(
|
||||
@RequestParam("file") MultipartFile file,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
String regId = ctx.getUserId();
|
||||
String clientIp = ctx.getClientIp();
|
||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
//외주사급이 업로드로 계정을 생성하는 경우 자신의 회사명으로 고정
|
||||
String forceCmpn =
|
||||
ctx.getUserRole() < ContactConstant.OUTSOURCE_USER_ROLE ? "" : ctx.getUserCmpn();
|
||||
|
||||
ExcelUploadResponseDto result = userService.createUsersFromExcel(file, regId, now, forceCmpn);
|
||||
ExcelUploadResultDto result = userService.createUsersFromExcel(file, regId, now, forceCmpn);
|
||||
|
||||
UploadUserContentDto content = new UploadUserContentDto(
|
||||
file.getOriginalFilename(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.contact.server.dto.auth;
|
||||
|
||||
|
||||
import com.kri.common.auth.dto.JwtUserClaimsDto;
|
||||
import com.kri.common.feature.auth.dto.JwtUserClaimsDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.dto.excel;
|
||||
|
||||
import com.kri.common.excel.ExcelColumn;
|
||||
import com.kri.common.feature.excel.ExcelColumn;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@@ -8,7 +8,7 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ExcelUploadResponseDto {
|
||||
public class ExcelUploadResultDto {
|
||||
|
||||
@Schema(description = "전체 읽은 행 수 (헤더 제외)")
|
||||
private int totalCount;
|
||||
@@ -27,4 +27,14 @@ public class ExcelUploadResponseDto {
|
||||
|
||||
@Schema(description = "에러 엑셀 파일 (xlsx)의 Base64 문자열 (hasErrorFile == true일 때만 세팅)")
|
||||
private String errorFileBase64;
|
||||
|
||||
public static ExcelUploadResultDto success(int totalCount, int successCount) {
|
||||
return ExcelUploadResultDto.builder()
|
||||
.totalCount(totalCount)
|
||||
.successCount(successCount)
|
||||
.failCount(0)
|
||||
.hasErrorFile(false)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.kri.contact.server.dto.excel;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
@Setter
|
||||
public class ListUploadErrorDto extends ExcelErrorDto {
|
||||
public static ListUploadErrorDto of(int rowNumber, String fieldName, String errorMessage) {
|
||||
return ListUploadErrorDto.builder()
|
||||
.rowNumber(rowNumber)
|
||||
.fieldName(fieldName)
|
||||
.errorMessage(errorMessage)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.dto.excel;
|
||||
|
||||
import com.kri.common.excel.ExcelColumn;
|
||||
import com.kri.common.feature.excel.ExcelColumn;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
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;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "")
|
||||
public class ListAssignInfoDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "리스트 id")
|
||||
private Integer sid;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "배정될 사용자 id")
|
||||
private String userId;
|
||||
|
||||
public static ListAssignInfoDto from(Integer sid, String userId) {
|
||||
return ListAssignInfoDto.builder()
|
||||
.sid(sid)
|
||||
.userId(userId)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "컨택/방문 면접 결과")
|
||||
public class ListContactResultDto extends ListResultBaseDto {
|
||||
|
||||
@Schema(description = "컨택/방문면접 시도 횟수")
|
||||
private Integer attemptCount;
|
||||
|
||||
@Schema(description = "마지막 컨택/방문면접 자")
|
||||
private String lastUser;
|
||||
|
||||
@Schema(description = "할당된 컨택/방문면접자")
|
||||
private String assignUser;
|
||||
|
||||
public static ListContactResultDto from(TListEventHistEntity entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ListContactResultDto.builder()
|
||||
.lastResultCd(entity.getResultCd() == null ? null : entity.getResultCd().shortValue())
|
||||
.lastResultDt(entity.getRegDt())
|
||||
.lastUser(entity.getRegUser())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.contact.server.common.enums.ListIsUse;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "리스트 필터 Dto")
|
||||
public class ListFilterDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "sid 목록")
|
||||
private Set<Integer> sidSet;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "리스트 사용 여부 목록")
|
||||
private Set<ListIsUse> listUseSet;
|
||||
|
||||
@Schema(description = "중요 메모")
|
||||
private String memo;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "그 외 필터 정보")
|
||||
private Map<Integer, Set<String>> otherItems;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.kri.contact.server.persistence.entity.TListHeaderEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.NotNull.List;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -45,9 +46,6 @@ public class ListHeaderDto {
|
||||
@Schema(description = "헤더 타입")
|
||||
private ListHeaderType listHderTy;
|
||||
|
||||
@Schema(description = "|로 이어 붙은 필터 값")
|
||||
private String filterValue;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "필터 사용 여부")
|
||||
private Boolean useFilter = false;
|
||||
@@ -72,7 +70,6 @@ public class ListHeaderDto {
|
||||
.listHderGrad(ListHeaderGrade.fromCode(entity.getListHderGrad()))
|
||||
.listHderNm(entity.getListHderNm())
|
||||
.listHderTy(ListHeaderType.fromCode(entity.getListHderTy()))
|
||||
.filterValue(entity.getFilterValue())
|
||||
.useFilter(entity.getUseFilter())
|
||||
.useColView(entity.getUseColView())
|
||||
.useIntrvwerView(entity.getUseIntrvwerView())
|
||||
@@ -80,6 +77,36 @@ public class ListHeaderDto {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ListHeaderDto fromDto(Long prjctIdx, ListHeaderDto src) {
|
||||
return ListHeaderDto.builder()
|
||||
.prjctIdx(prjctIdx)
|
||||
.listHderId(src.getListHderId())
|
||||
.listHderOrder(src.getListHderOrder())
|
||||
.listHderGrad(src.getListHderGrad())
|
||||
.listHderNm(src.getListHderNm())
|
||||
.listHderTy(src.getListHderTy())
|
||||
.useFilter(src.getUseFilter())
|
||||
.useColView(src.getUseColView())
|
||||
.useIntrvwerView(src.getUseIntrvwerView())
|
||||
.useIntrvwerEdit(src.getUseIntrvwerEdit())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ListHeaderDto newCommon(Long prjctIdx, int headerId, String headerName, ListHeaderType type){
|
||||
return ListHeaderDto.builder()
|
||||
.prjctIdx(prjctIdx)
|
||||
.listHderId(headerId)
|
||||
.listHderOrder((short) headerId)
|
||||
.listHderGrad(ListHeaderGrade.COMMON)
|
||||
.listHderNm(headerName)
|
||||
.listHderTy(type)
|
||||
.useFilter(false)
|
||||
.useColView(false)
|
||||
.useIntrvwerView(false)
|
||||
.useIntrvwerEdit(false)
|
||||
.build();
|
||||
}
|
||||
|
||||
public boolean isEqualHard(ListHeaderDto dto) {
|
||||
return Objects.equals(listHderId, dto.listHderId) &&
|
||||
Objects.equals(listHderOrder, dto.listHderOrder) &&
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "결과에 대한 기본 정보")
|
||||
public class ListResultBaseDto {
|
||||
|
||||
@Schema(description = "최종 결과값")
|
||||
private Short lastResultCd;
|
||||
|
||||
@Schema(description = "최종 결과값 일시")
|
||||
private LocalDateTime lastResultDt;
|
||||
|
||||
public static ListResultBaseDto from(TListEventHistEntity entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ListResultBaseDto.builder()
|
||||
.lastResultCd(entity.getResultCd() == null ? null : entity.getResultCd().shortValue())
|
||||
.lastResultDt(entity.getRegDt())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "리스트 조회 기본")
|
||||
public class ListSearchBaseDto {
|
||||
|
||||
@Schema(description = "프로젝트 고유키")
|
||||
private Long prjctIdx;
|
||||
|
||||
@Schema(description = "SID")
|
||||
private Integer sid;
|
||||
|
||||
@Schema(description = "사용 여부")
|
||||
private Short use;
|
||||
|
||||
@Schema(description = "메모")
|
||||
private String memo;
|
||||
|
||||
@Schema(description = "리스트 값 정보")
|
||||
private Map<Integer, String> itemList;
|
||||
|
||||
public static ListSearchBaseDto from(TListEntity entity, Map<Integer, String> itemList) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ListSearchBaseDto.builder()
|
||||
.prjctIdx(entity.getPrjctIdx())
|
||||
.sid(entity.getSid())
|
||||
.use(entity.getUse())
|
||||
.memo(entity.getMemo())
|
||||
.itemList(itemList)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.common.feature.web.page.PageRequestDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "리스트 검색 조건")
|
||||
public class ListSearchRequestDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "리스트 필터")
|
||||
private ListFilterDto listFilter;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "페이지네이션 정보")
|
||||
private PageRequestDto pageRequest;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "리스트 조회 응답(기본 + 결과 + 발송 결과)")
|
||||
public class ListSearchResponseDto extends ListSearchWithResultDto {
|
||||
|
||||
@Schema(description = "메일 발송 결과")
|
||||
private ListResultBaseDto mailSendResult;
|
||||
|
||||
@Schema(description = "문자 발송 결과")
|
||||
private ListResultBaseDto smsSendResult;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "리스트 조회 기본 + 결과")
|
||||
public class ListSearchWithResultDto extends ListSearchBaseDto {
|
||||
@Schema(description = "컨택 결과")
|
||||
private ListContactResultDto contactResult;
|
||||
|
||||
@Schema(description = "대면 면접 결과")
|
||||
private ListContactResultDto interviewResult;
|
||||
|
||||
@Schema(description = "온라인 설문 결과")
|
||||
private ListResultBaseDto surveyResult;
|
||||
|
||||
public static ListSearchWithResultDto from(
|
||||
TListEntity entity,
|
||||
Map<Integer, String> itemList,
|
||||
ListContactResultDto contactResult,
|
||||
ListContactResultDto interviewResult,
|
||||
ListResultBaseDto surveyResult
|
||||
) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ListSearchWithResultDto.builder()
|
||||
.prjctIdx(entity.getPrjctIdx())
|
||||
.sid(entity.getSid())
|
||||
.use(entity.getUse())
|
||||
.memo(entity.getMemo())
|
||||
.itemList(itemList)
|
||||
.contactResult(contactResult)
|
||||
.interviewResult(interviewResult)
|
||||
.surveyResult(surveyResult)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import com.kri.contact.server.common.enums.ListHeaderTypeSpecific;
|
||||
import com.kri.contact.server.common.enums.ListUploadMode;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "리스트 업로드 요청 DTO")
|
||||
public class ListUploadRequestDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "업로드 모드")
|
||||
private ListUploadMode uploadMode;
|
||||
|
||||
@Schema(description = "이메일 중복 체크")
|
||||
private boolean checkDuplicateEmail;
|
||||
|
||||
@Schema(description = "전화번호 중복 체크")
|
||||
private boolean checkDuplicatePhone;
|
||||
|
||||
@Schema(description = "특수 헤더 정보")
|
||||
private Map<String, ListHeaderTypeSpecific> specificHeader;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.dto.project;
|
||||
|
||||
import com.kri.common.webmvc.page.PageRequestDto;
|
||||
import com.kri.common.feature.web.page.PageRequestDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
@@ -25,4 +25,4 @@ public class ProjectSearchRequestDto {
|
||||
|
||||
@Schema(description = "페이지네이션 정보")
|
||||
private PageRequestDto pageRequest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.kri.contact.server.dto.project;
|
||||
|
||||
import com.kri.common.feature.util.CommonUtil;
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.UUID;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -31,7 +31,7 @@ public class ResultCodeDto {
|
||||
|
||||
public static ResultCodeDto from(TResultCodeEntity entity) {
|
||||
return ResultCodeDto.builder()
|
||||
.resultCdUUID(UUID.randomUUID().toString())
|
||||
.resultCdUUID(CommonUtil.uuid32())
|
||||
.prjctIdx(entity.getPrjctIdx())
|
||||
.resultCdTy(entity.getResultCdTy())
|
||||
.resultCd(entity.getResultCd())
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.contact.server.dto.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.contact.server.dto.excel.UserUploadDto;
|
||||
import com.kri.contact.server.persistence.entity.TUserEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@@ -31,10 +31,6 @@ public class TListAssignEntity {
|
||||
@Column(name = "sid", nullable = false)
|
||||
private Integer sid;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "assign_ty", nullable = false)
|
||||
private Short assignTy;
|
||||
|
||||
@Size(max = 32)
|
||||
@Column(name = "user_id", length = 32)
|
||||
private String userId;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TListCallHistEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "list_tel_hist_idx", nullable = false)
|
||||
@Column(name = "list_call_hist_idx", nullable = false)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "prjct_idx", columnDefinition = "int UNSIGNED not null")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TListEntityId;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -20,6 +22,11 @@ public class TListEntity {
|
||||
@EmbeddedId
|
||||
private TListEntityId id;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 32)
|
||||
@Column(name = "list_upload_log_id", nullable = false, length = 32)
|
||||
private String listUploadLogId;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "is_use", nullable = false)
|
||||
private Short use;
|
||||
|
||||
@@ -26,6 +26,10 @@ public class TListEventHistEntity {
|
||||
@Column(name = "list_event_hist_idx", nullable = false)
|
||||
private Long listEventHistIdx;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "event_ty", nullable = false)
|
||||
private Short eventTy;
|
||||
|
||||
@Column(name = "prjct_idx", columnDefinition = "int UNSIGNED not null")
|
||||
private Long prjctIdx;
|
||||
|
||||
@@ -37,10 +41,16 @@ public class TListEventHistEntity {
|
||||
@Column(name = "result_cd", nullable = false)
|
||||
private Integer resultCd;
|
||||
|
||||
@Column(name = "meta_data")
|
||||
private String metaData;
|
||||
|
||||
@Column(name = "list_call_hist_idx")
|
||||
private Long listCallHistIdx;
|
||||
|
||||
@NotNull
|
||||
@Lob
|
||||
@Column(name = "contact_memo", nullable = false)
|
||||
private String contactMemo;
|
||||
@Column(name = "memo", nullable = false)
|
||||
private String memo;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TListHeaderEntityId;
|
||||
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
@@ -45,10 +47,6 @@ public class TListHeaderEntity {
|
||||
@Column(name = "list_hder_ty", nullable = false)
|
||||
private Short listHderTy;
|
||||
|
||||
@Lob
|
||||
@Column(name = "filter_value", columnDefinition = "TEXT")
|
||||
private String filterValue; // |로 이어 붙은 값들
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "use_filter", nullable = false)
|
||||
@@ -106,7 +104,6 @@ public class TListHeaderEntity {
|
||||
.listHderGrad(src.getListHderGrad())
|
||||
.listHderNm(src.getListHderNm())
|
||||
.listHderTy(src.getListHderTy())
|
||||
.filterValue(src.getFilterValue())
|
||||
.useFilter(src.getUseFilter())
|
||||
.useColView(src.getUseColView())
|
||||
.useIntrvwerView(src.getUseIntrvwerView())
|
||||
@@ -123,7 +120,6 @@ public class TListHeaderEntity {
|
||||
.listHderGrad(dto.getListHderGrad().getCode())
|
||||
.listHderNm(dto.getListHderNm())
|
||||
.listHderTy(dto.getListHderTy().getCode())
|
||||
.filterValue(dto.getFilterValue())
|
||||
.useFilter(dto.getUseFilter())
|
||||
.useColView(dto.getUseColView())
|
||||
.useIntrvwerView(dto.getUseIntrvwerView())
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TListItemEntityId;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -21,9 +23,9 @@ public class TListItemEntity {
|
||||
@EmbeddedId
|
||||
private TListItemEntityId id;
|
||||
|
||||
@Size(max = 2048)
|
||||
@NotNull
|
||||
@Lob
|
||||
@Column(name = "list_item_val", nullable = false)
|
||||
@Column(name = "list_item_val", nullable = false, length = 2048)
|
||||
private String listItemVal;
|
||||
|
||||
@Size(max = 32)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TListItemFileEntityId;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -14,11 +16,11 @@ import org.hibernate.annotations.ColumnDefault;
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "t_list_item_upload")
|
||||
public class TListItemUploadEntity {
|
||||
@Table(name = "t_list_item_file")
|
||||
public class TListItemFileEntity {
|
||||
|
||||
@EmbeddedId
|
||||
private TListItemUploadEntityId id;
|
||||
private TListItemFileEntityId id;
|
||||
|
||||
@Size(max = 128)
|
||||
@Column(name = "file_nm", length = 128)
|
||||
@@ -23,9 +23,8 @@ import org.hibernate.annotations.Type;
|
||||
public class TListResetLogEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "list_reset_log_idx", columnDefinition = "int UNSIGNED not null")
|
||||
private Long listResetLogIdx;
|
||||
@Column(name = "list_reset_log_id", nullable = false, length = 32)
|
||||
private String listResetLogId;
|
||||
|
||||
@Column(name = "prjct_idx", columnDefinition = "int UNSIGNED not null")
|
||||
private Long prjctIdx;
|
||||
@@ -38,21 +37,6 @@ public class TListResetLogEntity {
|
||||
@Column(name = "list_cnt", nullable = false)
|
||||
private Integer listCnt;
|
||||
|
||||
@NotNull
|
||||
@Type(JsonType.class)
|
||||
@Column(name = "sid", nullable = false)
|
||||
private Map<String, Object> sid;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "backup_file_path", nullable = false, length = 128)
|
||||
private String backupFilePath;
|
||||
|
||||
@Size(max = 128)
|
||||
@NotNull
|
||||
@Column(name = "backup_file_nm", nullable = false, length = 128)
|
||||
private String backupFileNm;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "reg_user", nullable = false, length = 32)
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.common.feature.util.CommonUtil;
|
||||
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
||||
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 java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "t_list_upload_log")
|
||||
public class TListUploadLogEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "list_upload_log_idx", nullable = false)
|
||||
private Long listUploadLogIdx;
|
||||
@Size(max = 32)
|
||||
@Column(name = "list_upload_log_id", nullable = false, length = 32)
|
||||
private String listUploadLogId;
|
||||
|
||||
@Column(name = "prjct_idx", columnDefinition = "int UNSIGNED not null")
|
||||
private Long prjctIdx;
|
||||
@@ -44,10 +52,10 @@ public class TListUploadLogEntity {
|
||||
@Column(name = "mode", nullable = false)
|
||||
private Short mode;
|
||||
|
||||
@Size(max = 64)
|
||||
@NotNull
|
||||
@Column(name = "optn", nullable = false, length = 64)
|
||||
private String optn;
|
||||
@Type(JsonType.class)
|
||||
@Column(name = "request", nullable = false)
|
||||
private Map<String, Object> request;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "is_success", nullable = false)
|
||||
@@ -63,4 +71,26 @@ public class TListUploadLogEntity {
|
||||
@Column(name = "reg_dt", nullable = false)
|
||||
private LocalDateTime regDt;
|
||||
|
||||
}
|
||||
public static TListUploadLogEntity create(
|
||||
Long prjctIdx,
|
||||
Integer wave,
|
||||
String fileNm,
|
||||
Short mode,
|
||||
Map<String, Object> request,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
return TListUploadLogEntity.builder()
|
||||
.listUploadLogId(CommonUtil.uuid32())
|
||||
.prjctIdx(prjctIdx)
|
||||
.wave(wave)
|
||||
.fileNm(fileNm)
|
||||
.listCnt(0)
|
||||
.mode(mode)
|
||||
.request(request)
|
||||
.success(false)
|
||||
.regUser(regUser)
|
||||
.regDt(regDt)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TPrjctAssignEntityId;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
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;
|
||||
@@ -174,4 +174,4 @@ public class TPrjctEntity {
|
||||
this.modUser = modUser;
|
||||
this.modDt = modDt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TPrjctMainTmplatEntityId;
|
||||
|
||||
import com.kri.contact.server.dto.project.ProjectMainTemplateUpdateRequestDto;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TResultCodeEntityId;
|
||||
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.dto.project.ResultCodeDto;
|
||||
import jakarta.persistence.Column;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.id.TRoleFuncMapEntityId;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
package com.kri.contact.server.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
package com.kri.contact.server.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
package com.kri.contact.server.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
package com.kri.contact.server.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
package com.kri.contact.server.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
package com.kri.contact.server.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
package com.kri.contact.server.persistence.entity.id;
|
||||
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.common.jpa.ResultCodeTypeConverter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.kri.contact.server.persistence.entity;
|
||||
package com.kri.contact.server.persistence.entity.id;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
@@ -0,0 +1,287 @@
|
||||
package com.kri.contact.server.persistence.jdbc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ListResetJdbcSupport {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public void backupHistories(String listResetLogId, Long prjctIdx, Collection<Integer> sids, int chunkSize) {
|
||||
forEachSidChunk(sids, chunkSize, sub -> {
|
||||
backupListEventHist(listResetLogId, prjctIdx, sub);
|
||||
backupListUpdateHist(listResetLogId, prjctIdx, sub);
|
||||
backupListCallHist(listResetLogId, prjctIdx, sub);
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteHistories(Long prjctIdx, Collection<Integer> sids, int chunkSize) {
|
||||
forEachSidChunk(sids, chunkSize, sub -> {
|
||||
deleteBySids("t_list_event_hist", prjctIdx, sub);
|
||||
deleteBySids("t_list_update_hist", prjctIdx, sub);
|
||||
deleteBySids("t_list_call_hist", prjctIdx, sub);
|
||||
});
|
||||
}
|
||||
|
||||
public void backupListData(
|
||||
String listResetLogId,
|
||||
Long prjctIdx,
|
||||
Collection<Integer> sids,
|
||||
boolean includeFile,
|
||||
int chunkSize
|
||||
) {
|
||||
forEachSidChunk(sids, chunkSize, sub -> {
|
||||
backupList(listResetLogId, prjctIdx, sub);
|
||||
backupListItem(listResetLogId, prjctIdx, sub);
|
||||
if (includeFile) {
|
||||
backupListItemFile(listResetLogId, prjctIdx, sub);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public long deleteListData(
|
||||
Long prjctIdx,
|
||||
Collection<Integer> sids,
|
||||
boolean includeFile,
|
||||
boolean includeResve,
|
||||
int chunkSize
|
||||
) {
|
||||
long deletedCount = 0;
|
||||
List<Integer> sidList = new ArrayList<>(sids);
|
||||
for (int i = 0; i < sidList.size(); i += chunkSize) {
|
||||
List<Integer> sub = sidList.subList(i, Math.min(sidList.size(), i + chunkSize));
|
||||
|
||||
if (includeFile) {
|
||||
deleteBySids("t_list_item_file", prjctIdx, sub);
|
||||
}
|
||||
deleteBySids("t_list_item", prjctIdx, sub);
|
||||
deleteBySids("t_list_assign", prjctIdx, sub);
|
||||
if (includeResve) {
|
||||
deleteBySids("t_list_resve", prjctIdx, sub);
|
||||
}
|
||||
deletedCount += deleteBySids("t_list", prjctIdx, sub);
|
||||
}
|
||||
return deletedCount;
|
||||
}
|
||||
|
||||
private void backupListEventHist(String listResetLogId, Long prjctIdx, List<Integer> sids) {
|
||||
String inSql = createInSql(sids);
|
||||
List<Object> args = createArgs(listResetLogId, prjctIdx, sids);
|
||||
jdbcTemplate.update(
|
||||
"""
|
||||
insert into del_list_event_hist (
|
||||
list_reset_log_id,
|
||||
list_event_hist_idx,
|
||||
event_ty,
|
||||
prjct_idx,
|
||||
sid,
|
||||
result_cd,
|
||||
meta_data,
|
||||
list_call_hist_idx,
|
||||
memo,
|
||||
reg_user,
|
||||
reg_dt
|
||||
)
|
||||
select ?, list_event_hist_idx, event_ty, prjct_idx, sid, result_cd, meta_data,
|
||||
list_call_hist_idx, memo, reg_user, reg_dt
|
||||
from t_list_event_hist
|
||||
where prjct_idx = ?
|
||||
and sid in (%s)
|
||||
""".formatted(inSql),
|
||||
args.toArray()
|
||||
);
|
||||
}
|
||||
|
||||
private void backupListUpdateHist(String listResetLogId, Long prjctIdx, List<Integer> sids) {
|
||||
String inSql = createInSql(sids);
|
||||
List<Object> args = createArgs(listResetLogId, prjctIdx, sids);
|
||||
jdbcTemplate.update(
|
||||
"""
|
||||
insert into del_list_update_hist (
|
||||
list_reset_log_id,
|
||||
list_update_hist_idx,
|
||||
prjct_idx,
|
||||
sid,
|
||||
list_hder_id,
|
||||
before_val,
|
||||
after_val,
|
||||
reg_user,
|
||||
reg_dt
|
||||
)
|
||||
select ?, list_update_hist_idx, prjct_idx, sid, list_hder_id, before_val,
|
||||
after_val, reg_user, reg_dt
|
||||
from t_list_update_hist
|
||||
where prjct_idx = ?
|
||||
and sid in (%s)
|
||||
""".formatted(inSql),
|
||||
args.toArray()
|
||||
);
|
||||
}
|
||||
|
||||
private void backupListCallHist(String listResetLogId, Long prjctIdx, List<Integer> sids) {
|
||||
String inSql = createInSql(sids);
|
||||
List<Object> args = createArgs(listResetLogId, prjctIdx, sids);
|
||||
jdbcTemplate.update(
|
||||
"""
|
||||
insert into del_list_call_hist (
|
||||
list_reset_log_id,
|
||||
list_call_hist_idx,
|
||||
prjct_idx,
|
||||
sid,
|
||||
list_hder_id,
|
||||
dest_num,
|
||||
agent_num,
|
||||
ani_num,
|
||||
agent_session_id,
|
||||
dest_session_id,
|
||||
call_ty,
|
||||
start_dt,
|
||||
total_time,
|
||||
talk_time,
|
||||
media_server_id,
|
||||
media_server_name,
|
||||
record_file_name,
|
||||
reg_user,
|
||||
reg_dt
|
||||
)
|
||||
select ?, list_call_hist_idx, prjct_idx, sid, list_hder_id, dest_num,
|
||||
agent_num, ani_num, agent_session_id, dest_session_id, call_ty,
|
||||
start_dt, total_time, talk_time, media_server_id, media_server_name,
|
||||
record_file_name, reg_user, reg_dt
|
||||
from t_list_call_hist
|
||||
where prjct_idx = ?
|
||||
and sid in (%s)
|
||||
""".formatted(inSql),
|
||||
args.toArray()
|
||||
);
|
||||
}
|
||||
|
||||
private void backupList(String listResetLogId, Long prjctIdx, List<Integer> sids) {
|
||||
String inSql = createInSql(sids);
|
||||
List<Object> args = createArgs(listResetLogId, prjctIdx, sids);
|
||||
jdbcTemplate.update(
|
||||
"""
|
||||
insert into del_list (
|
||||
list_reset_log_id,
|
||||
prjct_idx,
|
||||
sid,
|
||||
list_upload_log_id,
|
||||
is_use,
|
||||
memo,
|
||||
reg_user,
|
||||
reg_dt,
|
||||
mod_user,
|
||||
mod_dt
|
||||
)
|
||||
select ?, prjct_idx, sid, list_upload_log_id, is_use, memo, reg_user,
|
||||
reg_dt, mod_user, mod_dt
|
||||
from t_list
|
||||
where prjct_idx = ?
|
||||
and sid in (%s)
|
||||
""".formatted(inSql),
|
||||
args.toArray()
|
||||
);
|
||||
}
|
||||
|
||||
private void backupListItem(String listResetLogId, Long prjctIdx, List<Integer> sids) {
|
||||
String inSql = createInSql(sids);
|
||||
List<Object> args = createArgs(listResetLogId, prjctIdx, sids);
|
||||
jdbcTemplate.update(
|
||||
"""
|
||||
insert into del_list_item (
|
||||
list_reset_log_id,
|
||||
prjct_idx,
|
||||
sid,
|
||||
list_hder_id,
|
||||
list_item_val,
|
||||
reg_user,
|
||||
reg_dt,
|
||||
mod_user,
|
||||
mod_dt
|
||||
)
|
||||
select ?, prjct_idx, sid, list_hder_id, list_item_val, reg_user,
|
||||
reg_dt, mod_user, mod_dt
|
||||
from t_list_item
|
||||
where prjct_idx = ?
|
||||
and sid in (%s)
|
||||
""".formatted(inSql),
|
||||
args.toArray()
|
||||
);
|
||||
}
|
||||
|
||||
private void backupListItemFile(String listResetLogId, Long prjctIdx, List<Integer> sids) {
|
||||
String inSql = createInSql(sids);
|
||||
List<Object> args = createArgs(listResetLogId, prjctIdx, sids);
|
||||
jdbcTemplate.update(
|
||||
"""
|
||||
insert into del_list_item_file (
|
||||
list_reset_log_id,
|
||||
prjct_idx,
|
||||
sid,
|
||||
list_hder_id,
|
||||
file_nm,
|
||||
file_size,
|
||||
file_path,
|
||||
reg_user,
|
||||
reg_dt,
|
||||
mod_user,
|
||||
mod_dt
|
||||
)
|
||||
select ?, prjct_idx, sid, list_hder_id, file_nm, file_size, file_path,
|
||||
reg_user, reg_dt, mod_user, mod_dt
|
||||
from t_list_item_file
|
||||
where prjct_idx = ?
|
||||
and sid in (%s)
|
||||
""".formatted(inSql),
|
||||
args.toArray()
|
||||
);
|
||||
}
|
||||
|
||||
private int deleteBySids(String tableName, Long prjctIdx, List<Integer> sids) {
|
||||
String inSql = createInSql(sids);
|
||||
List<Object> args = new ArrayList<>();
|
||||
args.add(prjctIdx);
|
||||
args.addAll(sids);
|
||||
|
||||
return jdbcTemplate.update(
|
||||
"delete from " + tableName + " where prjct_idx = ? and sid in (" + inSql + ")",
|
||||
args.toArray()
|
||||
);
|
||||
}
|
||||
|
||||
private void forEachSidChunk(Collection<Integer> sids, int chunkSize, ChunkConsumer consumer) {
|
||||
if (sids == null || sids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (chunkSize <= 0) {
|
||||
throw new IllegalArgumentException("chunkSize must be greater than 0");
|
||||
}
|
||||
|
||||
List<Integer> sidList = new ArrayList<>(sids);
|
||||
for (int i = 0; i < sidList.size(); i += chunkSize) {
|
||||
consumer.accept(sidList.subList(i, Math.min(sidList.size(), i + chunkSize)));
|
||||
}
|
||||
}
|
||||
|
||||
private List<Object> createArgs(String listResetLogId, Long prjctIdx, List<Integer> sids) {
|
||||
List<Object> args = new ArrayList<>();
|
||||
args.add(listResetLogId);
|
||||
args.add(prjctIdx);
|
||||
args.addAll(sids);
|
||||
return args;
|
||||
}
|
||||
|
||||
private String createInSql(List<Integer> sids) {
|
||||
return String.join(",", java.util.Collections.nCopies(sids.size(), "?"));
|
||||
}
|
||||
|
||||
private interface ChunkConsumer {
|
||||
void accept(List<Integer> sids);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
package com.kri.contact.server.persistence.jdbc;
|
||||
|
||||
import com.kri.contact.server.common.enums.ListHeaderTypeSpecific;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ListUploadJdbcSupport {
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public void deleteTemp(String listUploadLogId) {
|
||||
jdbcTemplate.update(
|
||||
"delete from t_list_item_upload_tmp where list_upload_log_id = ?",
|
||||
listUploadLogId
|
||||
);
|
||||
}
|
||||
|
||||
public void batchInsertTemp(List<TmpSpecialRow> rows, int batchSize) {
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String sql = """
|
||||
insert into t_list_item_upload_tmp (
|
||||
list_upload_log_id,
|
||||
prjct_idx,
|
||||
row_no,
|
||||
sid,
|
||||
list_hder_id,
|
||||
specific_type,
|
||||
raw_val,
|
||||
normalized_val
|
||||
) values (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""";
|
||||
|
||||
for (int i = 0; i < rows.size(); i += batchSize) {
|
||||
int to = Math.min(rows.size(), i + batchSize);
|
||||
List<TmpSpecialRow> sub = rows.subList(i, to);
|
||||
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(@NonNull PreparedStatement ps, int index) throws SQLException {
|
||||
TmpSpecialRow r = sub.get(index);
|
||||
ps.setString(1, r.listUploadLogId());
|
||||
ps.setLong(2, r.prjctIdx());
|
||||
ps.setInt(3, r.rowNo());
|
||||
ps.setInt(4, r.sid());
|
||||
ps.setInt(5, r.listHderId());
|
||||
ps.setShort(6, r.specificType());
|
||||
setNullableString(ps, 7, r.rawVal());
|
||||
setNullableString(ps, 8, r.normalizedVal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return sub.size();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public List<DuplicateHit> findFileDuplicateRows(String listUploadLogId) {
|
||||
String sql = """
|
||||
select t.row_no, t.list_hder_id, t.raw_val
|
||||
from t_list_item_upload_tmp t
|
||||
join (
|
||||
select list_upload_log_id, specific_type, normalized_val
|
||||
from t_list_item_upload_tmp
|
||||
where list_upload_log_id = ?
|
||||
and normalized_val is not null
|
||||
group by list_upload_log_id, specific_type, normalized_val
|
||||
having count(*) > 1
|
||||
) d
|
||||
on d.list_upload_log_id = t.list_upload_log_id
|
||||
and d.specific_type = t.specific_type
|
||||
and d.normalized_val = t.normalized_val
|
||||
where t.list_upload_log_id = ?
|
||||
order by t.row_no, t.list_hder_id
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(
|
||||
sql,
|
||||
(rs, rowNum) -> new DuplicateHit(
|
||||
rs.getInt("row_no"),
|
||||
rs.getInt("list_hder_id"),
|
||||
rs.getString("raw_val")
|
||||
),
|
||||
listUploadLogId, listUploadLogId
|
||||
);
|
||||
}
|
||||
|
||||
public List<DuplicateHit> findDbDuplicateRows(
|
||||
String listUploadLogId,
|
||||
Long prjctIdx,
|
||||
boolean changeMode
|
||||
) {
|
||||
String sql = """
|
||||
select distinct t.row_no, t.list_hder_id, t.raw_val
|
||||
from t_list_item_upload_tmp t
|
||||
join t_list_item i
|
||||
on i.prjct_idx = t.prjct_idx
|
||||
and i.list_hder_id = t.list_hder_id
|
||||
where t.list_upload_log_id = ?
|
||||
and t.prjct_idx = ?
|
||||
and t.normalized_val is not null
|
||||
and t.specific_type in (?, ?)
|
||||
and lower(trim(i.list_item_val)) = t.normalized_val
|
||||
and (? = false or i.sid <> t.sid)
|
||||
order by t.row_no, t.list_hder_id
|
||||
""";
|
||||
|
||||
return jdbcTemplate.query(
|
||||
sql,
|
||||
(rs, rowNum) -> new DuplicateHit(
|
||||
rs.getInt("row_no"),
|
||||
rs.getInt("list_hder_id"),
|
||||
rs.getString("raw_val")
|
||||
),
|
||||
listUploadLogId,
|
||||
prjctIdx,
|
||||
ListHeaderTypeSpecific.EMAIL.getCode(),
|
||||
ListHeaderTypeSpecific.TEL_NUM.getCode(),
|
||||
changeMode
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void batchInsertList(List<ListRowInsert> rows, int batchSize) {
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String sql = """
|
||||
insert into t_list (
|
||||
prjct_idx,
|
||||
sid,
|
||||
list_upload_log_id,
|
||||
is_use,
|
||||
memo,
|
||||
reg_user,
|
||||
reg_dt
|
||||
) values (?, ?, ?, ?, ?, ?, ?)
|
||||
""";
|
||||
|
||||
for (int i = 0; i < rows.size(); i += batchSize) {
|
||||
List<ListRowInsert> sub = rows.subList(i, Math.min(rows.size(), i + batchSize));
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(@NonNull PreparedStatement ps, int index) throws SQLException {
|
||||
ListRowInsert r = sub.get(index);
|
||||
ps.setLong(1, r.prjctIdx());
|
||||
ps.setInt(2, r.sid());
|
||||
ps.setString(3, r.listUploadLogId());
|
||||
ps.setShort(4, r.isUse());
|
||||
setNullableString(ps, 5, r.memo());
|
||||
ps.setString(6, r.regUser());
|
||||
ps.setTimestamp(7, Timestamp.valueOf(r.regDt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return sub.size();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void batchInsertListItem(List<ListItemRowInsert> rows, int batchSize) {
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String sql = """
|
||||
insert into t_list_item (
|
||||
prjct_idx,
|
||||
sid,
|
||||
list_hder_id,
|
||||
list_item_val,
|
||||
reg_user,
|
||||
reg_dt
|
||||
) values (?, ?, ?, ?, ?, ?)
|
||||
""";
|
||||
|
||||
for (int i = 0; i < rows.size(); i += batchSize) {
|
||||
List<ListItemRowInsert> sub = rows.subList(i, Math.min(rows.size(), i + batchSize));
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(@NonNull PreparedStatement ps, int index) throws SQLException {
|
||||
ListItemRowInsert r = sub.get(index);
|
||||
ps.setLong(1, r.prjctIdx());
|
||||
ps.setInt(2, r.sid());
|
||||
ps.setInt(3, r.listHderId());
|
||||
setNullableString(ps, 4, r.listItemVal());
|
||||
ps.setString(5, r.regUser());
|
||||
ps.setTimestamp(6, Timestamp.valueOf(r.regDt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return sub.size();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void batchInsertListAssign(List<ListAssignRowInsert> rows, int batchSize) {
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String sql = """
|
||||
insert into t_list_assign (
|
||||
prjct_idx,
|
||||
sid,
|
||||
user_id,
|
||||
reg_user,
|
||||
reg_dt
|
||||
) values (?, ?, ?, ?, ?)
|
||||
""";
|
||||
|
||||
for (int i = 0; i < rows.size(); i += batchSize) {
|
||||
List<ListAssignRowInsert> sub = rows.subList(i, Math.min(rows.size(), i + batchSize));
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(@NonNull PreparedStatement ps, int index) throws SQLException {
|
||||
ListAssignRowInsert r = sub.get(index);
|
||||
ps.setLong(1, r.prjctIdx());
|
||||
ps.setInt(2, r.sid());
|
||||
ps.setString(3, r.userId());
|
||||
ps.setString(4, r.regUser());
|
||||
ps.setTimestamp(5, Timestamp.valueOf(r.regDt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return sub.size();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void setNullableString(PreparedStatement ps, int index, String value) throws SQLException {
|
||||
if (value == null) {
|
||||
ps.setNull(index, Types.VARCHAR);
|
||||
} else {
|
||||
ps.setString(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
public record TmpSpecialRow(
|
||||
String listUploadLogId,
|
||||
Long prjctIdx,
|
||||
int rowNo,
|
||||
int sid,
|
||||
int listHderId,
|
||||
short specificType,
|
||||
String rawVal,
|
||||
String normalizedVal
|
||||
) {}
|
||||
|
||||
public record DuplicateHit(
|
||||
int rowNo,
|
||||
int listHderId,
|
||||
String rawVal
|
||||
) {}
|
||||
|
||||
public record ListRowInsert(
|
||||
Long prjctIdx,
|
||||
int sid,
|
||||
String listUploadLogId,
|
||||
short isUse,
|
||||
String memo,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {}
|
||||
|
||||
public record ListItemRowInsert(
|
||||
Long prjctIdx,
|
||||
int sid,
|
||||
int listHderId,
|
||||
String listItemVal,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {}
|
||||
|
||||
public record ListAssignRowInsert(
|
||||
Long prjctIdx,
|
||||
int sid,
|
||||
String userId,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListAssignEntity;
|
||||
import java.util.Collection;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface ListAssignRepository extends JpaRepository<TListAssignEntity, Long> {
|
||||
|
||||
long deleteByUserId(String userId);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListAssignEntity a
|
||||
where a.prjctIdx = :prjctIdx
|
||||
""")
|
||||
int deleteByPrjctIdx(Long prjctIdx);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListAssignEntity a
|
||||
where a.prjctIdx = :prjctIdx
|
||||
and a.sid in :sids
|
||||
""")
|
||||
int deleteWithPrjctIdxAndSids(
|
||||
Long prjctIdx,
|
||||
Collection<Integer> sids
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface ListEventHistRepository extends JpaRepository<TListEventHistEntity, Long> {
|
||||
|
||||
@Query("""
|
||||
select h
|
||||
from TListEventHistEntity h
|
||||
where h.prjctIdx = :prjctIdx
|
||||
and h.eventTy = :eventTy
|
||||
and h.sid = :sid
|
||||
and h.listEventHistIdx = (
|
||||
select max(h2.listEventHistIdx)
|
||||
from TListEventHistEntity h2
|
||||
where h2.prjctIdx = h.prjctIdx
|
||||
and h2.eventTy = h.eventTy
|
||||
and h2.sid = h.sid
|
||||
)
|
||||
""")
|
||||
Optional<TListEventHistEntity> findLatest(
|
||||
Long prjctIdx,
|
||||
Short eventTy,
|
||||
Integer sid
|
||||
);
|
||||
|
||||
@Query("""
|
||||
select h
|
||||
from TListEventHistEntity h
|
||||
where h.prjctIdx = :prjctIdx
|
||||
and h.eventTy = :eventTy
|
||||
and h.sid in :sids
|
||||
and h.listEventHistIdx = (
|
||||
select max(h2.listEventHistIdx)
|
||||
from TListEventHistEntity h2
|
||||
where h2.prjctIdx = h.prjctIdx
|
||||
and h2.eventTy = h.eventTy
|
||||
and h2.sid = h.sid
|
||||
)
|
||||
""")
|
||||
List<TListEventHistEntity> findLatestList(
|
||||
Long prjctIdx,
|
||||
Short eventTy,
|
||||
List<Integer> sids
|
||||
);
|
||||
|
||||
@Query("""
|
||||
select h
|
||||
from TListEventHistEntity h
|
||||
where h.prjctIdx = :prjctIdx
|
||||
and h.sid in :sids
|
||||
and h.listEventHistIdx = (
|
||||
select max(h2.listEventHistIdx)
|
||||
from TListEventHistEntity h2
|
||||
where h2.prjctIdx = h.prjctIdx
|
||||
and h2.eventTy = h.eventTy
|
||||
and h2.sid = h.sid
|
||||
)
|
||||
""")
|
||||
List<TListEventHistEntity> findLatestListByEventTy(
|
||||
Long prjctIdx,
|
||||
List<Integer> sids
|
||||
);
|
||||
}
|
||||
@@ -2,22 +2,24 @@ package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.common.enums.ListHeaderGrade;
|
||||
import com.kri.contact.server.persistence.entity.TListHeaderEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListHeaderEntityId;
|
||||
import com.kri.contact.server.persistence.entity.id.TListHeaderEntityId;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ListHeaderRepository extends JpaRepository<TListHeaderEntity, TListHeaderEntityId> {
|
||||
|
||||
List<TListHeaderEntity> findAllByIdPrjctIdx(Long prjctIdx);
|
||||
List<TListHeaderEntity> findByIdPrjctIdx(Long prjctIdx);
|
||||
|
||||
List<TListHeaderEntity> findAllByIdPrjctIdxAndListHderGradNot(Long prjctIdx, Short listHderGrad);
|
||||
List<TListHeaderEntity> findByIdPrjctIdxAndListHderGradNot(Long prjctIdx, Short listHderGrad);
|
||||
|
||||
List<Integer> findIdListHderIdByIdPrjctIdxAndListHderTyIn(Long prjctIdx, List<Short> listHderTy);
|
||||
|
||||
default List<TListHeaderEntity> findDefaultHeader(){
|
||||
return findAllByIdPrjctIdxAndListHderGradNot(0L, ListHeaderGrade.COMMON.getCode());
|
||||
return findByIdPrjctIdxAndListHderGradNot(0L, ListHeaderGrade.COMMON.getCode());
|
||||
}
|
||||
|
||||
long deleteAllByIdPrjctIdx(Long prjctIdx);
|
||||
long deleteByIdPrjctIdx(Long prjctIdx);
|
||||
|
||||
long deleteAllByIdPrjctIdxAndIdListHderIdNotIn(Long prjctIdx, List<Integer> listHderId);
|
||||
long deleteByIdPrjctIdxAndIdListHderIdNotIn(Long prjctIdx, List<Integer> listHderId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListItemFileEntity;
|
||||
import com.kri.contact.server.persistence.entity.id.TListItemFileEntityId;
|
||||
import java.util.Collection;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface ListItemFileRepository extends JpaRepository<TListItemFileEntity, TListItemFileEntityId> {
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListItemFileEntity f
|
||||
where f.id.prjctIdx = :prjctIdx
|
||||
""")
|
||||
int deleteByPrjctIdx(Long prjctIdx);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListItemFileEntity f
|
||||
where f.id.prjctIdx = :prjctIdx
|
||||
and f.id.sid in :sids
|
||||
""")
|
||||
int deleteWithPrjctIdxAndSids(
|
||||
Long prjctIdx,
|
||||
Collection<Integer> sids
|
||||
);
|
||||
}
|
||||
@@ -1,11 +1,58 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListItemEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListItemEntityId;
|
||||
import com.kri.contact.server.persistence.entity.id.TListItemEntityId;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface ListItemRepository extends JpaRepository<TListItemEntity, TListItemEntityId> {
|
||||
|
||||
long deleteAllByIdPrjctIdxAndIdListHderIdNotIn(Long prjctIdx, List<Integer> listHderId);
|
||||
long deleteByIdPrjctIdxAndIdListHderIdNotIn(Long prjctIdx, List<Integer> listHderIds);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListItemEntity i
|
||||
where i.id.prjctIdx = :prjctIdx
|
||||
""")
|
||||
int deleteByPrjctIdx(Long prjctIdx);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListItemEntity i
|
||||
where i.id.prjctIdx = :prjctIdx
|
||||
and i.id.sid in :sids
|
||||
""")
|
||||
int deleteByPrjctIdxAndSids(
|
||||
Long prjctIdx,
|
||||
Collection<Integer> sids
|
||||
);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListItemEntity i
|
||||
where i.id.prjctIdx = :prjctIdx
|
||||
and i.id.sid in :sids
|
||||
and i.id.listHderId not in :rejectHeaderIds
|
||||
""")
|
||||
int deleteByPrjctIdxAndSidsExceptHeaderIds(
|
||||
Long prjctIdx,
|
||||
Collection<Integer> sids,
|
||||
Collection<Integer> rejectHeaderIds
|
||||
);
|
||||
|
||||
@Query("""
|
||||
select t
|
||||
from TListItemEntity t
|
||||
where t.id.prjctIdx = :prjctIdx
|
||||
and t.id.sid in :sids
|
||||
order by t.id.sid asc, t.id.listHderId asc
|
||||
""")
|
||||
List<TListItemEntity> findByIdPrjctIdxAndIdSidIn(
|
||||
Long prjctIdx,
|
||||
Set<Integer> sids
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.common.feature.web.page.PageRequestDto;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||
import java.util.List;
|
||||
|
||||
public interface ListQueryRepository {
|
||||
|
||||
List<TListEntity> findPagedListEntities(Long prjctIdx, List<Integer> emailTelnumHeaderIds, ListFilterDto listFilter, PageRequestDto pageRequest);
|
||||
|
||||
List<TListEntity> findAllListEntities(Long prjctIdx, List<Integer> emailTelnumHeaderIds, ListFilterDto listFilter);
|
||||
|
||||
List<Integer> findAllSids(Long prjctIdx, List<Integer> emailTelnumHeaderIds, ListFilterDto listFilter);
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import static com.kri.common.feature.util.StringUtil.normalizeBlank;
|
||||
|
||||
import com.kri.common.feature.web.page.PageRequestDto;
|
||||
import com.kri.contact.server.common.enums.ListIsUse;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import com.kri.contact.server.persistence.entity.QTListEntity;
|
||||
import com.kri.contact.server.persistence.entity.QTListItemEntity;
|
||||
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.jpa.JPAExpressions;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ListQueryRepositoryImpl implements ListQueryRepository {
|
||||
|
||||
private final JPAQueryFactory jpaQueryFactory;
|
||||
|
||||
@Override
|
||||
public List<TListEntity> findPagedListEntities(
|
||||
Long prjctIdx,
|
||||
List<Integer> emailTelnumHeaderIds,
|
||||
ListFilterDto listFilter,
|
||||
PageRequestDto pageRequest
|
||||
) {
|
||||
QTListEntity list = QTListEntity.tListEntity;
|
||||
BooleanBuilder predicate = buildListFilterPredicate(prjctIdx, emailTelnumHeaderIds, listFilter, list);
|
||||
|
||||
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))
|
||||
.offset((long) pageIndex * pageSize)
|
||||
.limit(pageSize)
|
||||
.fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TListEntity> findAllListEntities(
|
||||
Long prjctIdx,
|
||||
List<Integer> emailTelnumHeaderIds,
|
||||
ListFilterDto listFilter
|
||||
) {
|
||||
QTListEntity list = QTListEntity.tListEntity;
|
||||
BooleanBuilder predicate = buildListFilterPredicate(prjctIdx, emailTelnumHeaderIds, listFilter, list);
|
||||
|
||||
return jpaQueryFactory.selectFrom(list)
|
||||
.where(predicate)
|
||||
.orderBy(list.id.sid.asc())
|
||||
.fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> findAllSids(
|
||||
Long prjctIdx,
|
||||
List<Integer> emailTelnumHeaderIds,
|
||||
ListFilterDto listFilter
|
||||
) {
|
||||
QTListEntity list = QTListEntity.tListEntity;
|
||||
BooleanBuilder predicate = buildListFilterPredicate(prjctIdx, emailTelnumHeaderIds, listFilter, list);
|
||||
|
||||
return jpaQueryFactory.select(list.id.sid)
|
||||
.from(list)
|
||||
.where(predicate)
|
||||
.orderBy(list.id.sid.asc())
|
||||
.fetch();
|
||||
}
|
||||
|
||||
private BooleanBuilder buildListFilterPredicate(
|
||||
Long prjctIdx,
|
||||
List<Integer> emailTelnumHeaderIds,
|
||||
ListFilterDto listFilter,
|
||||
QTListEntity list
|
||||
) {
|
||||
BooleanBuilder predicate = new BooleanBuilder()
|
||||
.and(list.id.prjctIdx.eq(prjctIdx));
|
||||
|
||||
if (listFilter == null) {
|
||||
return predicate;
|
||||
}
|
||||
|
||||
if (listFilter.getSidSet() != null && !listFilter.getSidSet().isEmpty()) {
|
||||
predicate.and(list.id.sid.in(listFilter.getSidSet()));
|
||||
}
|
||||
|
||||
Set<Short> useCodes = toUseCodes(listFilter.getListUseSet());
|
||||
if (!useCodes.isEmpty()) {
|
||||
predicate.and(list.use.in(useCodes));
|
||||
}
|
||||
|
||||
String memo = normalizeBlank(listFilter.getMemo());
|
||||
if (memo != null) {
|
||||
predicate.and(list.memo.contains(memo));
|
||||
}
|
||||
|
||||
appendOtherItemPredicates(predicate, prjctIdx, emailTelnumHeaderIds, list, listFilter.getOtherItems());
|
||||
return predicate;
|
||||
}
|
||||
|
||||
private void appendOtherItemPredicates(
|
||||
BooleanBuilder predicate,
|
||||
Long prjctIdx,
|
||||
List<Integer> emailTelnumHeaderIds,
|
||||
QTListEntity list,
|
||||
Map<Integer, Set<String>> otherItems
|
||||
) {
|
||||
if (otherItems == null || otherItems.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, Set<String>> entry : otherItems.entrySet()) {
|
||||
Integer listHderId = entry.getKey();
|
||||
Set<String> values = normalizeFilterValues(entry.getValue());
|
||||
if (listHderId == null || values.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//전화번호나 이메일은 Like 조회
|
||||
boolean isLike = emailTelnumHeaderIds != null
|
||||
&& emailTelnumHeaderIds.contains(listHderId)
|
||||
&& values.size() == 1;
|
||||
String likeValue = values.iterator().next();
|
||||
|
||||
QTListItemEntity item = new QTListItemEntity("item_" + listHderId);
|
||||
predicate.and(JPAExpressions.selectOne()
|
||||
.from(item)
|
||||
.where(
|
||||
item.id.prjctIdx.eq(prjctIdx),
|
||||
item.id.sid.eq(list.id.sid),
|
||||
item.id.listHderId.eq(listHderId),
|
||||
isLike
|
||||
? item.listItemVal.contains(likeValue)
|
||||
: item.listItemVal.in(values)
|
||||
)
|
||||
.exists());
|
||||
}
|
||||
}
|
||||
|
||||
private OrderSpecifier<?> resolveOrderSpecifier(QTListEntity list, 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);
|
||||
}
|
||||
if ("memo".equalsIgnoreCase(sortBy)) {
|
||||
return new OrderSpecifier<>(order, list.memo);
|
||||
}
|
||||
return new OrderSpecifier<>(order, list.id.sid);
|
||||
}
|
||||
|
||||
private Set<Short> toUseCodes(Set<ListIsUse> listUseSet) {
|
||||
if (listUseSet == null || listUseSet.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
return listUseSet.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(ListIsUse::getCode)
|
||||
.collect(java.util.stream.Collectors.toCollection(LinkedHashSet::new));
|
||||
}
|
||||
|
||||
private Set<String> normalizeFilterValues(Set<String> values) {
|
||||
if (values == null || values.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<String> normalized = new HashSet<>();
|
||||
for (String value : values) {
|
||||
String normalizedValue = normalizeBlank(value);
|
||||
if (normalizedValue != null) {
|
||||
normalized.add(normalizedValue);
|
||||
}
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,39 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListEntityId;
|
||||
import java.util.List;
|
||||
import com.kri.contact.server.persistence.entity.id.TListEntityId;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface ListRepository extends JpaRepository<TListEntity, TListEntityId>,
|
||||
JpaSpecificationExecutor<TListEntity> {
|
||||
JpaSpecificationExecutor<TListEntity>, ListQueryRepository {
|
||||
|
||||
@Query("""
|
||||
select l.id.sid
|
||||
from TListEntity l
|
||||
where l.id.prjctIdx = :prjctIdx
|
||||
""")
|
||||
Set<Integer> findSidsByPrjctIdx(Long prjctIdx);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListEntity l
|
||||
where l.id.prjctIdx = :prjctIdx
|
||||
""")
|
||||
int deleteByPrjctIdx(Long prjctIdx);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("""
|
||||
delete from TListEntity l
|
||||
where l.id.prjctIdx = :prjctIdx
|
||||
and l.id.sid in :sids
|
||||
""")
|
||||
int deleteWithPrjctIdxAndSids(
|
||||
Long prjctIdx,
|
||||
Collection<Integer> sids
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListResetLogEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ListResetLogRepository extends JpaRepository<TListResetLogEntity, String> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TListUploadLogEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface ListUploadLogRepository extends JpaRepository<TListUploadLogEntity, String> {
|
||||
|
||||
@Query("""
|
||||
select coalesce(max(t.wave), 0)
|
||||
from TListUploadLogEntity t
|
||||
where t.prjctIdx = :prjctIdx
|
||||
""")
|
||||
Integer findMaxWaveByPrjctIdx(Long prjctIdx);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TPrjctAssignEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctAssignEntityId;
|
||||
import com.kri.contact.server.persistence.entity.id.TPrjctAssignEntityId;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.persistence.entity.TPrjctMainTmplatEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctMainTmplatEntityId;
|
||||
import com.kri.contact.server.persistence.entity.id.TPrjctMainTmplatEntityId;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.kri.contact.server.persistence.repository;
|
||||
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
|
||||
import com.kri.contact.server.persistence.entity.TResultCodeEntityId;
|
||||
import com.kri.contact.server.persistence.entity.id.TResultCodeEntityId;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctAssignEntity;
|
||||
import com.kri.contact.server.persistence.repository.ListAssignRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectAssignRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -14,6 +15,15 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class AssignService {
|
||||
|
||||
private final ProjectAssignRepository projectAssignRepository;
|
||||
private final ListAssignRepository listAssignRepository;
|
||||
|
||||
public List<String> getPrjctOutsourceAndFieldworkAssign(Long prjctIdx) {
|
||||
List<String> outsourceAssign = getPrjctOutsourceAssign(prjctIdx);
|
||||
List<String> fieldworkAssign = getPrjctFieldworkAssign(prjctIdx);
|
||||
outsourceAssign.addAll(fieldworkAssign);
|
||||
|
||||
return outsourceAssign;
|
||||
}
|
||||
|
||||
public List<String> getPrjctOutsourceAssign(Long prjctIdx) {
|
||||
return projectAssignRepository.findAssignUserIdByPrjctIdxAndRoleRange(
|
||||
@@ -55,6 +65,11 @@ public class AssignService {
|
||||
insertPrjctAssign(prjctIdx, assignUserIdList, regUser, regDt);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteListAssignWithUser(String userId) {
|
||||
listAssignRepository.deleteByUserId(userId);
|
||||
}
|
||||
|
||||
private void insertPrjctAssign(Long prjctIdx, List<String> assignUserIdList, String regUser,
|
||||
LocalDateTime regDt) {
|
||||
if (assignUserIdList == null || assignUserIdList.isEmpty()) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.auth.dto.JwtUserClaimsDto;
|
||||
import com.kri.common.auth.jwt.JwtService;
|
||||
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;
|
||||
import com.kri.contact.server.common.external.intranet.SearchLoginInfoResponseDto;
|
||||
import com.kri.contact.server.dto.auth.LoginRequestDto;
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.web.BusinessException;
|
||||
import static com.kri.contact.server.common.consts.ContactConstant.EMAIL_TELNUM_TYPE;
|
||||
import static com.kri.contact.server.common.consts.ContactConstant.LIST_TEXT_REGEX;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.contact.server.common.enums.ListHeaderGrade;
|
||||
import com.kri.contact.server.common.enums.ListHeaderType;
|
||||
import com.kri.contact.server.common.enums.ListHeaderTypeSpecific;
|
||||
import com.kri.contact.server.dto.excel.ListUploadErrorDto;
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import com.kri.contact.server.dto.list.ListUploadRequestDto;
|
||||
import com.kri.contact.server.persistence.entity.TListHeaderEntity;
|
||||
import com.kri.contact.server.persistence.repository.ListHeaderRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListItemRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -20,12 +33,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class ListHeaderService {
|
||||
|
||||
private final ListHeaderRepository listHeaderRepository;
|
||||
private final ListItemService listItemService;
|
||||
private final ListItemRepository listItemRepository;
|
||||
|
||||
@Transactional
|
||||
public void copyDefaultHeader(Long prjctIdx, String regUser, LocalDateTime regDt) {
|
||||
|
||||
listHeaderRepository.deleteAllByIdPrjctIdx(prjctIdx);
|
||||
listHeaderRepository.deleteByIdPrjctIdx(prjctIdx);
|
||||
|
||||
List<TListHeaderEntity> defaultHeaderList = listHeaderRepository.findDefaultHeader()
|
||||
.stream()
|
||||
@@ -36,48 +48,132 @@ public class ListHeaderService {
|
||||
}
|
||||
|
||||
public List<ListHeaderDto> getHeader(Long prjctIdx) {
|
||||
List<TListHeaderEntity> headerEntityList = listHeaderRepository.findAllByIdPrjctIdx(prjctIdx);
|
||||
List<TListHeaderEntity> headerEntityList = listHeaderRepository.findByIdPrjctIdx(prjctIdx);
|
||||
|
||||
if (headerEntityList.isEmpty()) {
|
||||
|
||||
}
|
||||
|
||||
return headerEntityList.stream()
|
||||
.map(ListHeaderDto::fromEntity)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void upsertHeader(Long prjctIdx, List<ListHeaderDto> headerList, String regUser) {
|
||||
LocalDateTime regDt = DateTimeUtil.nowKstLocalDateTime();
|
||||
public List<Integer> getEmailTelnumHeaderId(Long prjctIdx) {
|
||||
List<Short> emailTelnumCodeList = EMAIL_TELNUM_TYPE.stream()
|
||||
.map(ListHeaderType::getCode)
|
||||
.toList();
|
||||
|
||||
//headerList에 ListHeaderGrade.IMMUTABLE, ListHeaderGrade.DEFAULT 헤더가 있는지 확인
|
||||
return listHeaderRepository.findIdListHderIdByIdPrjctIdxAndListHderTyIn(prjctIdx, emailTelnumCodeList);
|
||||
}
|
||||
|
||||
public List<ListHeaderDto> resolveUploadHeaders(
|
||||
Long prjctIdx,
|
||||
List<String> excelHeaders,
|
||||
ListUploadRequestDto request,
|
||||
List<ListUploadErrorDto> errors
|
||||
) {
|
||||
if (excelHeaders == null || excelHeaders.isEmpty()) {
|
||||
errors.add(ListUploadErrorDto.of(1, "헤더", "헤더가 없습니다."));
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<ListHeaderDto> defaultHeaders = listHeaderRepository.findDefaultHeader().stream()
|
||||
.map(ListHeaderDto::fromEntity)
|
||||
.sorted(Comparator.comparing(ListHeaderDto::getListHderId))
|
||||
.toList();
|
||||
|
||||
Map<String, ListHeaderDto> defaultByName = new LinkedHashMap<>();
|
||||
for (ListHeaderDto dto : defaultHeaders) {
|
||||
defaultByName.put(dto.getListHderNm(), dto);
|
||||
}
|
||||
|
||||
for (String defaultName : defaultByName.keySet()) {
|
||||
if (!excelHeaders.contains(defaultName)) {
|
||||
errors.add(ListUploadErrorDto.of(1, defaultName, "기본 헤더가 누락되었습니다."));
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> dupCheck = new LinkedHashSet<>();
|
||||
for (String h : excelHeaders) {
|
||||
if (h == null || h.isBlank()) {
|
||||
errors.add(ListUploadErrorDto.of(1, "헤더", "빈 헤더명이 있습니다."));
|
||||
} else if (!dupCheck.add(h)) {
|
||||
errors.add(ListUploadErrorDto.of(1, h, "헤더명이 중복됩니다."));
|
||||
} else if (!h.matches(LIST_TEXT_REGEX)) {
|
||||
errors.add(ListUploadErrorDto.of(1, h, "허용되지 않는 헤더명 입니다."));
|
||||
}
|
||||
}
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<ListHeaderDto> result = new ArrayList<>();
|
||||
for (ListHeaderDto src : defaultHeaders) {
|
||||
result.add(ListHeaderDto.fromDto(prjctIdx, src));
|
||||
}
|
||||
|
||||
int nextId = defaultHeaders.size() + 1;
|
||||
for (String headerName : excelHeaders) {
|
||||
if (defaultByName.containsKey(headerName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int headerId = nextId++;
|
||||
ListHeaderType type = resolveType(headerId, request.getSpecificHeader());
|
||||
|
||||
result.add(ListHeaderDto.newCommon(prjctIdx, headerId, headerName, type));
|
||||
}
|
||||
|
||||
return result.stream()
|
||||
.sorted(Comparator.comparing(ListHeaderDto::getListHderOrder))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void upsertHeader(Long prjctIdx, List<ListHeaderDto> headerList, String regUser, LocalDateTime regDt) {
|
||||
List<ListHeaderDto> defaultHeaderList = listHeaderRepository.findDefaultHeader()
|
||||
.stream().map(ListHeaderDto::fromEntity).toList();
|
||||
.stream()
|
||||
.map(ListHeaderDto::fromEntity)
|
||||
.toList();
|
||||
|
||||
List<ListHeaderDto> extractDefault = headerList.stream()
|
||||
.filter(h -> !Objects.equals(h.getListHderGrad(), ListHeaderGrade.COMMON))
|
||||
.toList();
|
||||
|
||||
if(!isEqualHeader(defaultHeaderList, extractDefault, true)){
|
||||
throw BusinessException.badRequest("WRONG_DEFAULT","기본 헤더가 잘못 됐습니다.");
|
||||
if (!isEqualHeader(defaultHeaderList, extractDefault, true)) {
|
||||
throw BusinessException.badRequest("WRONG_DEFAULT", "기본 헤더가 잘못 됐습니다.");
|
||||
}
|
||||
|
||||
//headerList에 없는 헤더는 삭제
|
||||
List<String> invalidHeaderList = headerList.stream()
|
||||
.map(ListHeaderDto::getListHderNm)
|
||||
.filter(name -> name == null || !name.matches(LIST_TEXT_REGEX))
|
||||
.toList();
|
||||
|
||||
if (!invalidHeaderList.isEmpty()) {
|
||||
throw BusinessException.badRequest("WRONG_HEADER_NAME", "허용되지 않는 헤더명이 있습니다.")
|
||||
.with("invalidHeaderList", invalidHeaderList);
|
||||
}
|
||||
|
||||
// headerList에 없는 헤더는 삭제
|
||||
List<Integer> headerIdList = headerList.stream().map(ListHeaderDto::getListHderId).toList();
|
||||
listHeaderRepository.deleteAllByIdPrjctIdxAndIdListHderIdNotIn(prjctIdx, headerIdList);
|
||||
listHeaderRepository.deleteByIdPrjctIdxAndIdListHderIdNotIn(prjctIdx, headerIdList);
|
||||
|
||||
//없는 정보에 대해서 리스트 아이템 삭제
|
||||
listItemService.deleteHderIdNotIn(prjctIdx, headerIdList);
|
||||
// 없는 정보에 대해서 리스트 아이템 삭제
|
||||
listItemRepository.deleteByIdPrjctIdxAndIdListHderIdNotIn(prjctIdx, headerIdList);
|
||||
|
||||
//ListHeaderGrade.IMMUTABLE 헤더를 제외한 헤더 저장
|
||||
// ListHeaderGrade.IMMUTABLE 헤더를 제외한 헤더 저장
|
||||
List<TListHeaderEntity> headerEntityList = headerList.stream()
|
||||
.filter(h -> !Objects.equals(h.getListHderGrad(), ListHeaderGrade.IMMUTABLE))
|
||||
.map((ListHeaderDto dto) -> TListHeaderEntity.fromDto(dto, regUser, regDt))
|
||||
.map(dto -> TListHeaderEntity.fromDto(dto, regUser, regDt))
|
||||
.toList();
|
||||
|
||||
listHeaderRepository.saveAll(headerEntityList);
|
||||
}
|
||||
|
||||
public boolean isEqualHeader(List<ListHeaderDto> origin, List<ListHeaderDto> target, boolean simpleMode){
|
||||
|
||||
if(origin.size() != target.size()){
|
||||
public boolean isEqualHeader(List<ListHeaderDto> origin, List<ListHeaderDto> target, boolean simpleMode) {
|
||||
if (origin.size() != target.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -86,7 +182,7 @@ public class ListHeaderService {
|
||||
? o -> t -> t.isEqualSimple(o)
|
||||
: o -> t -> t.isEqualHard(o);
|
||||
|
||||
for(ListHeaderDto o : origin){
|
||||
for (ListHeaderDto o : origin) {
|
||||
if (target.stream().noneMatch(predFunc.apply(o))) {
|
||||
return false;
|
||||
}
|
||||
@@ -95,4 +191,44 @@ public class ListHeaderService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Integer> findHeaderIdsByType(List<ListHeaderDto> headers, ListHeaderType type) {
|
||||
return headers.stream()
|
||||
.filter(h -> h.getListHderTy() == type)
|
||||
.map(ListHeaderDto::getListHderId)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public String findHeaderNameByType(List<ListHeaderDto> headers, ListHeaderType type) {
|
||||
return headers.stream()
|
||||
.filter(h -> h.getListHderTy() == type)
|
||||
.map(ListHeaderDto::getListHderNm)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> BusinessException.badRequest("HEADER_NOT_FOUND", type + " 헤더를 찾을 수 없습니다."));
|
||||
}
|
||||
|
||||
public List<String> findHeaderNamesByTypes(List<ListHeaderDto> headers, List<ListHeaderType> types) {
|
||||
return headers.stream()
|
||||
.filter(h -> types.contains(h.getListHderTy()))
|
||||
.map(ListHeaderDto::getListHderNm)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private ListHeaderType resolveType(Integer headerId, Map<String, ListHeaderTypeSpecific> specificHeader) {
|
||||
if (specificHeader == null || specificHeader.isEmpty()) {
|
||||
return ListHeaderType.TEXT;
|
||||
}
|
||||
ListHeaderTypeSpecific specific = specificHeader.get(String.valueOf(headerId));
|
||||
if (specific == null) {
|
||||
return ListHeaderType.TEXT;
|
||||
}
|
||||
return switch (specific) {
|
||||
case EMAIL -> ListHeaderType.EMAIL;
|
||||
case TEL_NUM -> ListHeaderType.TEL_NUM;
|
||||
case FILE -> ListHeaderType.FILE;
|
||||
};
|
||||
}
|
||||
|
||||
private long deleteHderIdNotIn(Long prjctIdx, List<Integer> listHderId){
|
||||
return listItemRepository.deleteByIdPrjctIdxAndIdListHderIdNotIn(prjctIdx, listHderId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.contact.server.persistence.repository.ListItemRepository;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ListItemService {
|
||||
|
||||
private final ListItemRepository listItemRepository;
|
||||
|
||||
public long deleteHderIdNotIn(Long prjctIdx, List<Integer> listHderId){
|
||||
return listItemRepository.deleteAllByIdPrjctIdxAndIdListHderIdNotIn(prjctIdx, listHderId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.feature.util.CommonUtil;
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.common.enums.ListResetMode;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import com.kri.contact.server.persistence.entity.TListResetLogEntity;
|
||||
import com.kri.contact.server.persistence.jdbc.ListResetJdbcSupport;
|
||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListResetLogRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ListResetService {
|
||||
|
||||
private final ListResetLogRepository listResetLogRepository;
|
||||
private final ListRepository listRepository;
|
||||
private final ListHeaderService listHeaderService;
|
||||
private final ListResetJdbcSupport listResetJdbcSupport;
|
||||
|
||||
@Transactional
|
||||
public long resetByFilter(
|
||||
Long prjctIdx,
|
||||
ListFilterDto filter,
|
||||
ListResetMode mode,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
List<Integer> emailTelnumHeaderIds = listHeaderService.getEmailTelnumHeaderId(prjctIdx);
|
||||
Set<Integer> sids = new LinkedHashSet<>(
|
||||
listRepository.findAllSids(prjctIdx, emailTelnumHeaderIds, filter)
|
||||
);
|
||||
return resetBySids(prjctIdx, sids, mode, regUser, regDt);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public long resetBySids(
|
||||
Long prjctIdx,
|
||||
Set<Integer> sids,
|
||||
ListResetMode mode,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
if (sids == null || sids.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
if (mode == null) {
|
||||
throw new IllegalArgumentException("mode must not be null");
|
||||
}
|
||||
|
||||
String listResetLogId = createResetLog(prjctIdx, mode, sids.size(), regUser, regDt);
|
||||
int chunkSize = ContactConstant.INSERT_CHUNK_SIZE;
|
||||
|
||||
switch (mode) {
|
||||
case HIST -> {
|
||||
listResetJdbcSupport.backupHistories(listResetLogId, prjctIdx, sids, chunkSize);
|
||||
listResetJdbcSupport.deleteHistories(prjctIdx, sids, chunkSize);
|
||||
}
|
||||
case ALL -> {
|
||||
listResetJdbcSupport.backupHistories(listResetLogId, prjctIdx, sids, chunkSize);
|
||||
listResetJdbcSupport.backupListData(listResetLogId, prjctIdx, sids, true, chunkSize);
|
||||
listResetJdbcSupport.deleteHistories(prjctIdx, sids, chunkSize);
|
||||
listResetJdbcSupport.deleteListData(prjctIdx, sids, true, true, chunkSize);
|
||||
}
|
||||
case LIST_UPLOAD -> {
|
||||
listResetJdbcSupport.backupListData(listResetLogId, prjctIdx, sids, false, chunkSize);
|
||||
listResetJdbcSupport.deleteListData(prjctIdx, sids, false, false, chunkSize);
|
||||
}
|
||||
}
|
||||
|
||||
return sids.size();
|
||||
}
|
||||
|
||||
private String createResetLog(
|
||||
Long prjctIdx,
|
||||
ListResetMode mode,
|
||||
int listCnt,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
String listResetLogId = CommonUtil.uuid32();
|
||||
|
||||
TListResetLogEntity log = new TListResetLogEntity();
|
||||
log.setListResetLogId(listResetLogId);
|
||||
log.setPrjctIdx(prjctIdx);
|
||||
log.setMode(mode.getCode());
|
||||
log.setListCnt(listCnt);
|
||||
log.setRegUser(regUser);
|
||||
log.setRegDt(regDt);
|
||||
listResetLogRepository.saveAndFlush(log);
|
||||
|
||||
return listResetLogId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.dto.list.ListContactResultDto;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import com.kri.contact.server.dto.list.ListResultBaseDto;
|
||||
import com.kri.contact.server.dto.list.ListSearchBaseDto;
|
||||
import com.kri.contact.server.dto.list.ListSearchRequestDto;
|
||||
import com.kri.contact.server.dto.list.ListSearchWithResultDto;
|
||||
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.repository.ListEventHistRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListItemRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ListSearchService {
|
||||
|
||||
private final ListEventHistRepository listEventHistRepository;
|
||||
private final ListItemRepository listItemRepository;
|
||||
private final ListRepository listRepository;
|
||||
private final ListHeaderService listHeaderService;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<ListSearchBaseDto> getListSearchBaseList(Long prjctIdx, ListSearchRequestDto request) {
|
||||
return createListSearchBase(prjctIdx, findPagedListEntities(prjctIdx, request));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<ListSearchWithResultDto> getListSearchWithResultList(Long prjctIdx, ListSearchRequestDto request) {
|
||||
return createListSearchWithResult(prjctIdx, findPagedListEntities(prjctIdx, request));
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<ListSearchBaseDto> getAllListSearchBaseList(Long prjctIdx, ListFilterDto listFilter) {
|
||||
List<Integer> emailTelnumHeaderIds = listHeaderService.getEmailTelnumHeaderId(prjctIdx);
|
||||
List<TListEntity> listEntities = listRepository.findAllListEntities(
|
||||
prjctIdx,
|
||||
emailTelnumHeaderIds,
|
||||
listFilter
|
||||
);
|
||||
|
||||
return createListSearchBase(prjctIdx, listEntities);
|
||||
}
|
||||
|
||||
private List<TListEntity> findPagedListEntities(Long prjctIdx, ListSearchRequestDto request) {
|
||||
List<Integer> emailTelnumHeaderIds = listHeaderService.getEmailTelnumHeaderId(prjctIdx);
|
||||
|
||||
ListFilterDto listFilter = request == null ? null : request.getListFilter();
|
||||
return listRepository.findPagedListEntities(
|
||||
prjctIdx,
|
||||
emailTelnumHeaderIds,
|
||||
listFilter,
|
||||
request == null ? null : request.getPageRequest()
|
||||
);
|
||||
}
|
||||
|
||||
private List<ListSearchBaseDto> createListSearchBase(Long prjctIdx, List<TListEntity> listEntities) {
|
||||
return createListSearchRows(prjctIdx, listEntities).stream()
|
||||
.map(row -> ListSearchBaseDto.from(row.listEntity(), row.itemList()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<ListSearchWithResultDto> createListSearchWithResult(Long prjctIdx, List<TListEntity> listEntities) {
|
||||
List<ListSearchRow> rows = createListSearchRows(prjctIdx, listEntities);
|
||||
if (rows.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Integer> sids = rows.stream()
|
||||
.map(row -> row.listEntity().getSid())
|
||||
.toList();
|
||||
|
||||
Map<ListResultKey, TListEventHistEntity> resultMap = listEventHistRepository
|
||||
.findLatestListByEventTy(prjctIdx, sids)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
entity -> new ListResultKey(entity.getSid(), entity.getEventTy()),
|
||||
entity -> entity,
|
||||
(left, right) -> left
|
||||
));
|
||||
|
||||
return rows.stream()
|
||||
.map(row -> {
|
||||
Integer sid = row.listEntity().getSid();
|
||||
return ListSearchWithResultDto.from(
|
||||
row.listEntity(),
|
||||
row.itemList(),
|
||||
ListContactResultDto.from(resultMap.get(new ListResultKey(sid, ResultCodeType.CONTACT.getCode()))),
|
||||
ListContactResultDto.from(resultMap.get(new ListResultKey(sid, ResultCodeType.INTERVIEW.getCode()))),
|
||||
ListResultBaseDto.from(resultMap.get(new ListResultKey(sid, ResultCodeType.SURVEY.getCode())))
|
||||
);
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<ListSearchRow> createListSearchRows(Long prjctIdx, List<TListEntity> listEntities) {
|
||||
if (listEntities.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Set<Integer> sidSet = listEntities.stream()
|
||||
.map(TListEntity::getSid)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
|
||||
Map<Integer, Map<Integer, String>> itemMapBySid = listItemRepository
|
||||
.findByIdPrjctIdxAndIdSidIn(prjctIdx, sidSet)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
TListItemEntity::getSid,
|
||||
LinkedHashMap::new,
|
||||
Collectors.toMap(
|
||||
TListItemEntity::getListHderId,
|
||||
TListItemEntity::getListItemVal,
|
||||
(left, right) -> right,
|
||||
LinkedHashMap::new
|
||||
)
|
||||
));
|
||||
|
||||
return listEntities.stream()
|
||||
.map(entity -> new ListSearchRow(
|
||||
entity,
|
||||
itemMapBySid.getOrDefault(entity.getSid(), Collections.emptyMap())
|
||||
))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private record ListSearchRow(
|
||||
TListEntity listEntity,
|
||||
Map<Integer, String> itemList
|
||||
) {}
|
||||
|
||||
private record ListResultKey(
|
||||
Integer sid,
|
||||
Short eventTy
|
||||
) {}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ListService {
|
||||
|
||||
private final ListRepository listRepository;
|
||||
private final ListItemService listItemService;
|
||||
private final ListHeaderService listHeaderService;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import static com.kri.common.feature.util.NumericUtil.parseOnlyInteger;
|
||||
import static com.kri.common.feature.util.StringUtil.isBasicText;
|
||||
import static com.kri.common.feature.util.StringUtil.isNullOrBlank;
|
||||
import static com.kri.common.feature.util.StringUtil.normalizeBlank;
|
||||
import static com.kri.common.feature.util.StringUtil.normalizeEmail;
|
||||
import static com.kri.common.feature.util.StringUtil.normalizeOnlyNumber;
|
||||
import static com.kri.contact.server.common.consts.ContactConstant.ASSIGN_TYPE;
|
||||
import static com.kri.contact.server.common.consts.ContactConstant.DEFAULT_AND_FILE_TYPE;
|
||||
import static com.kri.contact.server.common.consts.ContactConstant.LIST_TEXT_REGEX;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.common.feature.excel.ExcelMapper;
|
||||
import com.kri.common.feature.excel.StreamingReadOptions;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.common.enums.ListHeaderGrade;
|
||||
import com.kri.contact.server.common.enums.ListHeaderType;
|
||||
import com.kri.contact.server.common.enums.ListHeaderTypeSpecific;
|
||||
import com.kri.contact.server.common.enums.ListIsUse;
|
||||
import com.kri.contact.server.common.enums.ListResetMode;
|
||||
import com.kri.contact.server.common.enums.ListUploadMode;
|
||||
import com.kri.contact.server.common.util.ExcelUploadResultUtil;
|
||||
import com.kri.contact.server.dto.excel.ExcelUploadResultDto;
|
||||
import com.kri.contact.server.dto.excel.ListUploadErrorDto;
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import com.kri.contact.server.dto.list.ListUploadRequestDto;
|
||||
import com.kri.contact.server.persistence.entity.TListUploadLogEntity;
|
||||
import com.kri.contact.server.persistence.jdbc.ListUploadJdbcSupport;
|
||||
import com.kri.contact.server.persistence.jdbc.ListUploadJdbcSupport.ListAssignRowInsert;
|
||||
import com.kri.contact.server.persistence.jdbc.ListUploadJdbcSupport.ListItemRowInsert;
|
||||
import com.kri.contact.server.persistence.jdbc.ListUploadJdbcSupport.ListRowInsert;
|
||||
import com.kri.contact.server.persistence.jdbc.ListUploadJdbcSupport.TmpSpecialRow;
|
||||
import com.kri.contact.server.persistence.repository.ListRepository;
|
||||
import com.kri.contact.server.persistence.repository.ListUploadLogRepository;
|
||||
import com.kri.contact.server.service.file.ListFileService;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
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.concurrent.atomic.AtomicInteger;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ListUploadService {
|
||||
|
||||
private static final StreamingReadOptions LOWER_CASE_HEADER_OPTIONS =
|
||||
new StreamingReadOptions(null, 0, 1, header -> header == null ? null : header.toLowerCase(Locale.ROOT));
|
||||
|
||||
private final ListRepository listRepository;
|
||||
private final ListUploadJdbcSupport listUploadJdbcSupport;
|
||||
private final ListUploadLogRepository listUploadLogRepository;
|
||||
private final ListHeaderService listHeaderService;
|
||||
private final ListResetService listResetService;
|
||||
private final ListFileService listFileService;
|
||||
private final AssignService assignService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public byte[] downloadExcelTemplate(Long prjctIdx) {
|
||||
List<ListHeaderDto> listHeaderList = listHeaderService.getHeader(prjctIdx).stream()
|
||||
.sorted(Comparator.comparing(ListHeaderDto::getListHderOrder))
|
||||
.toList();
|
||||
|
||||
Map<String, Object> headerRow = new LinkedHashMap<>();
|
||||
for (ListHeaderDto header : listHeaderList) {
|
||||
headerRow.put(header.getListHderNm(), null);
|
||||
}
|
||||
|
||||
try (
|
||||
Workbook workbook = ExcelMapper.writeFromMapList(List.of(headerRow));
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream()
|
||||
) {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
for (int i = 0; i < headerRow.size(); i++) {
|
||||
sheet.autoSizeColumn(i);
|
||||
sheet.setColumnWidth(i, Math.min(sheet.getColumnWidth(i) + 1024, 255 * 256));
|
||||
}
|
||||
|
||||
workbook.write(out);
|
||||
return out.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw BusinessException.internalError("리스트 업로드 템플릿 엑셀 생성 중 오류");
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ExcelUploadResultDto uploadExcel(
|
||||
Long prjctIdx,
|
||||
MultipartFile file,
|
||||
ListUploadRequestDto request,
|
||||
String uploadUser,
|
||||
LocalDateTime uploadDt
|
||||
) {
|
||||
Path listFilePath = listFileService.saveListFile(file, prjctIdx);
|
||||
|
||||
List<String> excelHeaders = ExcelMapper.readHeaderStreaming(listFilePath, LOWER_CASE_HEADER_OPTIONS);
|
||||
List<ListUploadErrorDto> headerErrorList = new ArrayList<>();
|
||||
|
||||
List<ListHeaderDto> resolvedHeaders = listHeaderService.resolveUploadHeaders(
|
||||
prjctIdx,
|
||||
excelHeaders,
|
||||
request,
|
||||
headerErrorList
|
||||
);
|
||||
if (!headerErrorList.isEmpty()) {
|
||||
return buildErrorResponse(0, headerErrorList, listFilePath);
|
||||
}
|
||||
|
||||
List<ListHeaderDto> existingHeaders = listHeaderService.getHeader(prjctIdx);
|
||||
List<ListHeaderDto> existingCommon = existingHeaders.stream()
|
||||
.filter(h -> Objects.equals(h.getListHderGrad(), ListHeaderGrade.COMMON))
|
||||
.sorted(Comparator.comparing(ListHeaderDto::getListHderOrder))
|
||||
.toList();
|
||||
|
||||
if (!existingCommon.isEmpty() && !listHeaderService.isEqualHeader(existingHeaders, resolvedHeaders, false)) {
|
||||
headerErrorList.add(ListUploadErrorDto.of(1, "헤더", "기존 헤더와 업로드 헤더가 일치하지 않습니다."));
|
||||
return buildErrorResponse(0, headerErrorList, listFilePath);
|
||||
}
|
||||
|
||||
List<String> prjctAssignList = assignService.getPrjctOutsourceAndFieldworkAssign(prjctIdx);
|
||||
|
||||
TListUploadLogEntity uploadLog = createPendingLog(
|
||||
prjctIdx,
|
||||
listFilePath,
|
||||
request,
|
||||
uploadUser,
|
||||
uploadDt
|
||||
);
|
||||
|
||||
ValidationSummary validation = validateFile(
|
||||
prjctIdx,
|
||||
listFilePath,
|
||||
request,
|
||||
resolvedHeaders,
|
||||
prjctAssignList,
|
||||
uploadLog.getListUploadLogId()
|
||||
);
|
||||
|
||||
markValidated(uploadLog, validation.totalCount());
|
||||
|
||||
if (!validation.errors().isEmpty()) {
|
||||
listUploadJdbcSupport.deleteTemp(uploadLog.getListUploadLogId());
|
||||
return buildErrorResponse(validation.totalCount(), validation.errors(), listFilePath);
|
||||
}
|
||||
|
||||
persistUpload(
|
||||
prjctIdx,
|
||||
listFilePath,
|
||||
request,
|
||||
resolvedHeaders,
|
||||
uploadLog.getListUploadLogId(),
|
||||
validation.uploadedSids(),
|
||||
uploadUser,
|
||||
uploadDt
|
||||
);
|
||||
|
||||
markSuccess(uploadLog, validation.totalCount());
|
||||
listUploadJdbcSupport.deleteTemp(uploadLog.getListUploadLogId());
|
||||
|
||||
return ExcelUploadResultDto.success(validation.totalCount(), validation.totalCount());
|
||||
}
|
||||
|
||||
private TListUploadLogEntity createPendingLog(
|
||||
Long prjctIdx,
|
||||
Path listFilePath,
|
||||
ListUploadRequestDto request,
|
||||
String uploadUser,
|
||||
LocalDateTime uploadDt
|
||||
) {
|
||||
TListUploadLogEntity uploadLog = TListUploadLogEntity.create(
|
||||
prjctIdx,
|
||||
listUploadLogRepository.findMaxWaveByPrjctIdx(prjctIdx) + 1,
|
||||
listFilePath.getFileName().toString(),
|
||||
request.getUploadMode().getCode(),
|
||||
objectMapper.convertValue(request, new TypeReference<Map<String, Object>>() {}),
|
||||
uploadUser,
|
||||
uploadDt
|
||||
);
|
||||
|
||||
return listUploadLogRepository.save(uploadLog);
|
||||
}
|
||||
|
||||
private void markValidated(TListUploadLogEntity uploadLog, int totalCount) {
|
||||
uploadLog.setListCnt(totalCount);
|
||||
uploadLog.setSuccess(false);
|
||||
listUploadLogRepository.save(uploadLog);
|
||||
}
|
||||
|
||||
private void markSuccess(TListUploadLogEntity uploadLog, int totalCount) {
|
||||
uploadLog.setListCnt(totalCount);
|
||||
uploadLog.setSuccess(true);
|
||||
listUploadLogRepository.save(uploadLog);
|
||||
}
|
||||
|
||||
private void persistUpload(
|
||||
Long prjctIdx,
|
||||
Path listFilePath,
|
||||
ListUploadRequestDto request,
|
||||
List<ListHeaderDto> resolvedHeaders,
|
||||
String listUploadLogId,
|
||||
Set<Integer> uploadedSids,
|
||||
String uploadUser,
|
||||
LocalDateTime uploadDt
|
||||
) {
|
||||
listHeaderService.upsertHeader(prjctIdx, resolvedHeaders, uploadUser, uploadDt);
|
||||
|
||||
if (request.getUploadMode() == ListUploadMode.CHANGE) {
|
||||
listResetService.resetByFilter(
|
||||
prjctIdx,
|
||||
null,
|
||||
ListResetMode.ALL,
|
||||
uploadUser,
|
||||
uploadDt
|
||||
);
|
||||
}
|
||||
else if (request.getUploadMode() == ListUploadMode.ADD && !uploadedSids.isEmpty()) {
|
||||
listResetService.resetBySids(
|
||||
prjctIdx,
|
||||
uploadedSids,
|
||||
ListResetMode.LIST_UPLOAD,
|
||||
uploadUser,
|
||||
uploadDt
|
||||
);
|
||||
}
|
||||
|
||||
String sidHeaderName = listHeaderService.findHeaderNameByType(resolvedHeaders, ListHeaderType.SID);
|
||||
String isUseHeaderName = listHeaderService.findHeaderNameByType(resolvedHeaders, ListHeaderType.IS_USE);
|
||||
String memoHeaderName = listHeaderService.findHeaderNameByType(resolvedHeaders, ListHeaderType.MEMO);
|
||||
List<String> assginHeaderNames = listHeaderService.findHeaderNamesByTypes(resolvedHeaders, ASSIGN_TYPE);
|
||||
|
||||
List<ListRowInsert> listRows = new ArrayList<>();
|
||||
List<ListItemRowInsert> itemRows = new ArrayList<>();
|
||||
List<ListAssignRowInsert> assignRows = new ArrayList<>();
|
||||
|
||||
ExcelMapper.readStreaming(listFilePath, LOWER_CASE_HEADER_OPTIONS, (row, rowNo) -> {
|
||||
Integer sid = parseOnlyInteger(row.get(sidHeaderName));
|
||||
short isUse = parseIsUseSafe(row.get(isUseHeaderName));
|
||||
String memo = normalizeBlank(row.get(memoHeaderName));
|
||||
|
||||
listRows.add(new ListRowInsert(
|
||||
prjctIdx,
|
||||
sid,
|
||||
listUploadLogId,
|
||||
isUse,
|
||||
memo == null ? "" : memo,
|
||||
uploadUser,
|
||||
uploadDt
|
||||
));
|
||||
|
||||
for (String assignHeaderName : assginHeaderNames) {
|
||||
String userId = normalizeBlank(row.get(assignHeaderName));
|
||||
|
||||
assignRows.add(new ListAssignRowInsert(
|
||||
prjctIdx,
|
||||
sid,
|
||||
userId,
|
||||
uploadUser,
|
||||
uploadDt
|
||||
));
|
||||
}
|
||||
|
||||
for (ListHeaderDto header : resolvedHeaders) {
|
||||
if (DEFAULT_AND_FILE_TYPE.contains(header.getListHderTy())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String raw = normalizeBlank(row.get(header.getListHderNm()));
|
||||
if (header.getListHderTy() == ListHeaderType.EMAIL) {
|
||||
raw = normalizeEmail(raw);
|
||||
}
|
||||
else if (header.getListHderTy() == ListHeaderType.TEL_NUM) {
|
||||
raw = normalizeOnlyNumber(raw);
|
||||
}
|
||||
|
||||
itemRows.add(new ListItemRowInsert(
|
||||
prjctIdx,
|
||||
sid,
|
||||
header.getListHderId(),
|
||||
raw,
|
||||
uploadUser,
|
||||
uploadDt
|
||||
));
|
||||
}
|
||||
|
||||
if (listRows.size() >= ContactConstant.INSERT_CHUNK_SIZE) {
|
||||
listUploadJdbcSupport.batchInsertList(listRows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
listRows.clear();
|
||||
}
|
||||
if (itemRows.size() >= ContactConstant.INSERT_CHUNK_SIZE) {
|
||||
listUploadJdbcSupport.batchInsertListItem(itemRows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
itemRows.clear();
|
||||
}
|
||||
if (assignRows.size() >= ContactConstant.INSERT_CHUNK_SIZE) {
|
||||
listUploadJdbcSupport.batchInsertListAssign(assignRows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
assignRows.clear();
|
||||
}
|
||||
});
|
||||
|
||||
if (!listRows.isEmpty()) {
|
||||
listUploadJdbcSupport.batchInsertList(listRows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
}
|
||||
if (!itemRows.isEmpty()) {
|
||||
listUploadJdbcSupport.batchInsertListItem(itemRows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
}
|
||||
if (!assignRows.isEmpty()) {
|
||||
listUploadJdbcSupport.batchInsertListAssign(assignRows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
private ValidationSummary validateFile(
|
||||
Long prjctIdx,
|
||||
Path listFilePath,
|
||||
ListUploadRequestDto request,
|
||||
List<ListHeaderDto> resolvedHeaders,
|
||||
List<String> prjctAssignList,
|
||||
String listUploadLogId
|
||||
) {
|
||||
Map<Integer, ListHeaderDto> headerById = toHeaderById(resolvedHeaders);
|
||||
|
||||
String sidHeaderName = listHeaderService.findHeaderNameByType(resolvedHeaders, ListHeaderType.SID);
|
||||
String isUseHeaderName = listHeaderService.findHeaderNameByType(resolvedHeaders, ListHeaderType.IS_USE);
|
||||
List<String> assginHeaderNames = listHeaderService.findHeaderNamesByTypes(resolvedHeaders, ASSIGN_TYPE);
|
||||
|
||||
Set<Integer> existingSids = listRepository.findSidsByPrjctIdx(prjctIdx);
|
||||
Set<Integer> uploadedSids = new LinkedHashSet<>();
|
||||
List<ListUploadErrorDto> errors = new ArrayList<>();
|
||||
List<TmpSpecialRow> tempBuffer = new ArrayList<>();
|
||||
AtomicInteger totalCount = new AtomicInteger();
|
||||
|
||||
listUploadJdbcSupport.deleteTemp(listUploadLogId);
|
||||
|
||||
ExcelMapper.readStreaming(listFilePath, LOWER_CASE_HEADER_OPTIONS, (row, rowNo) -> {
|
||||
totalCount.incrementAndGet();
|
||||
|
||||
Integer sid = parseOnlyInteger(row.get(sidHeaderName));
|
||||
if (sid == null) {
|
||||
errors.add(ListUploadErrorDto.of(rowNo, sidHeaderName, "SID는 필수이며 정수여야 합니다."));
|
||||
return;
|
||||
}
|
||||
|
||||
Short isUse = parseIsUse(row.get(isUseHeaderName));
|
||||
if (isUse == null) {
|
||||
errors.add(ListUploadErrorDto.of(rowNo, isUseHeaderName, "사용 여부는 O, X, TEST만 허용됩니다."));
|
||||
}
|
||||
|
||||
if (request.getUploadMode() == ListUploadMode.ADD && existingSids.contains(sid)) {
|
||||
errors.add(ListUploadErrorDto.of(rowNo, sidHeaderName, "이미 존재하는 SID입니다."));
|
||||
}
|
||||
|
||||
if (!uploadedSids.add(sid)) {
|
||||
errors.add(ListUploadErrorDto.of(rowNo, sidHeaderName, "업로드 파일 내 SID가 중복됩니다."));
|
||||
}
|
||||
|
||||
for (String assignHeaderName : assginHeaderNames) {
|
||||
String raw = normalizeBlank(row.get(assignHeaderName));
|
||||
if (!prjctAssignList.contains(raw)) {
|
||||
errors.add(ListUploadErrorDto.of(
|
||||
rowNo,
|
||||
assignHeaderName,
|
||||
"프로젝트에 배정되지 않은 사용자입니다."
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
for (ListHeaderDto header : resolvedHeaders) {
|
||||
if (DEFAULT_AND_FILE_TYPE.contains(header.getListHderTy())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String raw = normalizeBlank(row.get(header.getListHderNm()));
|
||||
if (isNullOrBlank(raw)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (header.getListHderTy() == ListHeaderType.TEXT && !isBasicText(raw, LIST_TEXT_REGEX)) {
|
||||
errors.add(ListUploadErrorDto.of(
|
||||
rowNo,
|
||||
header.getListHderNm(),
|
||||
"데이터에 들어갈 수 없는 문자열이 있습니다. 한글, 영문, 숫자, 공백, 괄호(), 밑줄(_), 하이픈(-), 대괄호[]만 입력할 수 있습니다."
|
||||
));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (header.getListHderTy() == ListHeaderType.EMAIL) {
|
||||
String normalized = normalizeEmail(raw);
|
||||
|
||||
if (normalized == null) {
|
||||
errors.add(ListUploadErrorDto.of(rowNo, header.getListHderNm(), "이메일 형식이 올바르지 않습니다."));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (request.isCheckDuplicateEmail()) {
|
||||
tempBuffer.add(new TmpSpecialRow(
|
||||
listUploadLogId, prjctIdx, rowNo, sid, header.getListHderId(),
|
||||
ListHeaderTypeSpecific.EMAIL.getCode(),
|
||||
raw, normalized
|
||||
));
|
||||
}
|
||||
} else if (header.getListHderTy() == ListHeaderType.TEL_NUM) {
|
||||
String normalized = normalizeOnlyNumber(raw);
|
||||
|
||||
if (normalized == null) {
|
||||
errors.add(ListUploadErrorDto.of(rowNo, header.getListHderNm(), "전화번호 형식이 올바르지 않습니다."));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (request.isCheckDuplicatePhone()) {
|
||||
tempBuffer.add(new TmpSpecialRow(
|
||||
listUploadLogId, prjctIdx, rowNo, sid, header.getListHderId(),
|
||||
ListHeaderTypeSpecific.TEL_NUM.getCode(),
|
||||
raw, normalized
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tempBuffer.size() >= ContactConstant.INSERT_CHUNK_SIZE) {
|
||||
listUploadJdbcSupport.batchInsertTemp(tempBuffer, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
tempBuffer.clear();
|
||||
}
|
||||
});
|
||||
|
||||
if (!tempBuffer.isEmpty()) {
|
||||
listUploadJdbcSupport.batchInsertTemp(tempBuffer, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
tempBuffer.clear();
|
||||
}
|
||||
|
||||
for (ListUploadJdbcSupport.DuplicateHit hit : listUploadJdbcSupport.findFileDuplicateRows(listUploadLogId)) {
|
||||
String fieldName = headerById.get(hit.listHderId()).getListHderNm();
|
||||
errors.add(ListUploadErrorDto.of(hit.rowNo(), fieldName, "업로드 파일 내 중복값입니다."));
|
||||
}
|
||||
|
||||
if (request.isCheckDuplicateEmail() || request.isCheckDuplicatePhone()) {
|
||||
boolean changeMode = request.getUploadMode() == ListUploadMode.CHANGE;
|
||||
for (ListUploadJdbcSupport.DuplicateHit hit : listUploadJdbcSupport.findDbDuplicateRows(
|
||||
listUploadLogId, prjctIdx, changeMode
|
||||
)) {
|
||||
String fieldName = headerById.get(hit.listHderId()).getListHderNm();
|
||||
errors.add(ListUploadErrorDto.of(hit.rowNo(), fieldName, "DB 내 중복값입니다."));
|
||||
}
|
||||
}
|
||||
|
||||
return new ValidationSummary(totalCount.get(), uploadedSids, errors);
|
||||
}
|
||||
|
||||
private ExcelUploadResultDto buildErrorResponse(
|
||||
int totalCount,
|
||||
List<ListUploadErrorDto> errorList,
|
||||
Path sourceFile
|
||||
) {
|
||||
String origin = sourceFile.getFileName().toString();
|
||||
String errorFileName = origin.endsWith(".xlsx")
|
||||
? origin.substring(0, origin.length() - 5) + "_error.xlsx"
|
||||
: origin + "_error.xlsx";
|
||||
int failCount = errorList.stream()
|
||||
.map(ListUploadErrorDto::getRowNumber)
|
||||
.distinct()
|
||||
.toList()
|
||||
.size();
|
||||
|
||||
return ExcelUploadResultUtil.buildUploadResult(
|
||||
totalCount,
|
||||
0,
|
||||
failCount,
|
||||
errorList,
|
||||
ListUploadErrorDto.class,
|
||||
errorFileName
|
||||
);
|
||||
}
|
||||
|
||||
private Map<Integer, ListHeaderDto> toHeaderById(List<ListHeaderDto> headers) {
|
||||
Map<Integer, ListHeaderDto> map = new LinkedHashMap<>();
|
||||
for (ListHeaderDto h : headers) {
|
||||
map.put(h.getListHderId(), h);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private Short parseIsUse(String raw) {
|
||||
String s = normalizeBlank(raw);
|
||||
s = s == null ? "" : s.toUpperCase();
|
||||
|
||||
return switch (s) {
|
||||
case "O" -> ListIsUse.USABLE.getCode();
|
||||
case "X" -> ListIsUse.UNUSABLE.getCode();
|
||||
case "TEST" -> ListIsUse.TEST.getCode();
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private short parseIsUseSafe(String raw) {
|
||||
Short code = parseIsUse(raw);
|
||||
return code == null ? ListIsUse.USABLE.getCode() : code;
|
||||
}
|
||||
|
||||
private record ValidationSummary(
|
||||
int totalCount,
|
||||
Set<Integer> uploadedSids,
|
||||
List<ListUploadErrorDto> errors
|
||||
) {}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.web.BusinessException;
|
||||
import com.kri.common.webmvc.page.PageRequestDto;
|
||||
import com.kri.common.webmvc.page.PageResponseDto;
|
||||
import com.kri.common.webmvc.page.Pageables;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
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.dto.project.ProjectCreateRequestDto;
|
||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import static com.kri.common.json.JsonUtil.toMap;
|
||||
import static com.kri.common.feature.json.JsonUtil.toMap;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.contact.server.common.enums.SystemEventType;
|
||||
@@ -138,11 +138,25 @@ public class SystemEventLogService {
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
"listHeader",
|
||||
"headerList",
|
||||
headerList
|
||||
);
|
||||
}
|
||||
|
||||
public void writeUploadList(String regId, LocalDateTime regDt, String clientIp,
|
||||
Long prjctIdx, String uploadFileName){
|
||||
writeSystemLog(
|
||||
SystemEventType.UPLOAD_LIST,
|
||||
"Upload List",
|
||||
prjctIdx,
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
"uploadFileName",
|
||||
uploadFileName
|
||||
);
|
||||
}
|
||||
|
||||
protected <T> void writeSystemLog(
|
||||
SystemEventType eventType,
|
||||
String title,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.excel.ExcelMapper;
|
||||
import com.kri.common.web.BusinessException;
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.excel.ExcelMapper;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.common.external.intranet.IntranetExtensionApiClient;
|
||||
import com.kri.contact.server.common.util.ExcelUploadResultUtil;
|
||||
import com.kri.contact.server.dto.common.DataVerificationDto;
|
||||
import com.kri.contact.server.dto.excel.ExcelUploadResponseDto;
|
||||
import com.kri.contact.server.dto.excel.ExcelUploadResultDto;
|
||||
import com.kri.contact.server.dto.user.RoleInfoDto;
|
||||
import com.kri.contact.server.dto.user.UserInfoDto;
|
||||
import com.kri.contact.server.dto.excel.UserUploadDto;
|
||||
@@ -31,6 +31,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
public class UserService {
|
||||
|
||||
private final IntranetExtensionApiClient intranetExtensionApiClient;
|
||||
private final AssignService assignService;
|
||||
private final RoleService roleService;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@@ -54,19 +55,24 @@ public class UserService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ExcelUploadResponseDto createUsersFromExcel(MultipartFile file, String regUser,
|
||||
public ExcelUploadResultDto createUsersFromExcel(MultipartFile file, String regUser,
|
||||
LocalDateTime regDt, String forceCmpn) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw BusinessException.badRequest("EMPTY_FILE", "업로드된 파일이 없습니다.");
|
||||
}
|
||||
|
||||
String fileName = file.getOriginalFilename();
|
||||
String errorFileName = fileName != null && fileName.endsWith(".xlsx")
|
||||
? fileName.substring(0, fileName.length() - 5) + "_error.xlsx"
|
||||
: fileName + "_error.xlsx";
|
||||
|
||||
List<UserUploadDto> rows;
|
||||
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
|
||||
// DTO 매핑 (스트리밍 X, 일반 방식)
|
||||
rows = ExcelMapper.readFromWorkbook(workbook, UserUploadDto.class);
|
||||
} catch (Exception e) {
|
||||
throw BusinessException.badRequest("INVALID_EXCEL", "엑셀 파일을 읽는 중 오류가 발생했습니다.")
|
||||
.with("fileName", file.getOriginalFilename());
|
||||
.with("fileName", fileName);
|
||||
}
|
||||
|
||||
int totalCount = rows.size();
|
||||
@@ -114,12 +120,19 @@ public class UserService {
|
||||
}
|
||||
}
|
||||
|
||||
int failCount = errorList.stream()
|
||||
.map(UserUploadErrorDto::getRowNumber)
|
||||
.distinct()
|
||||
.toList()
|
||||
.size();
|
||||
|
||||
return ExcelUploadResultUtil.buildUploadResult(
|
||||
totalCount,
|
||||
successCount,
|
||||
failCount,
|
||||
errorList,
|
||||
UserUploadErrorDto.class,
|
||||
"user_upload_errors.xlsx"
|
||||
errorFileName
|
||||
);
|
||||
}
|
||||
|
||||
@@ -205,6 +218,10 @@ public class UserService {
|
||||
.with("userId", dto.getUserId())
|
||||
);
|
||||
|
||||
if(entity.getUserRole() != dto.getUserRole()) {
|
||||
assignService.deleteListAssignWithUser(dto.getUserId());
|
||||
}
|
||||
|
||||
entity.updateFromDto(dto, modUser, modDt);// 기존 엔티티에 적용
|
||||
}
|
||||
|
||||
@@ -307,7 +324,7 @@ public class UserService {
|
||||
Integer userRole = dto.getUserRole();
|
||||
if (roleList != null && !roleList.isEmpty()) {
|
||||
boolean exists = roleList.stream()
|
||||
.anyMatch(r -> userRole.equals(r.getRoleCd()));
|
||||
.anyMatch(r -> userRole != null && userRole.equals(r.getRoleCd()));
|
||||
|
||||
if (!exists) {
|
||||
result.add(new DataVerificationDto(
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.kri.contact.server.service.file;
|
||||
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.util.CommonUtil;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Optional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public abstract class AbstractFileService {
|
||||
|
||||
protected abstract Path getBaseDir();
|
||||
|
||||
protected String extractExtension(String originalFileName) {
|
||||
if (originalFileName == null || originalFileName.isBlank()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int dot = originalFileName.lastIndexOf('.');
|
||||
if (dot > -1 && dot < originalFileName.length() - 1) {
|
||||
return originalFileName.substring(dot);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
protected String extractBaseName(String originalFileName) {
|
||||
if (originalFileName == null || originalFileName.isBlank()) {
|
||||
return "file";
|
||||
}
|
||||
|
||||
String fileName = java.nio.file.Paths.get(originalFileName).getFileName().toString();
|
||||
int dot = fileName.lastIndexOf('.');
|
||||
|
||||
if (dot > 0) {
|
||||
return fileName.substring(0, dot);
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
protected String buildFileName(MultipartFile file) {
|
||||
String original = Optional.ofNullable(file.getOriginalFilename()).orElse("file");
|
||||
return CommonUtil.uuid32() + extractExtension(original);
|
||||
}
|
||||
|
||||
protected String buildFileNameWithTime(MultipartFile file, String prefix) {
|
||||
String original = Optional.ofNullable(file.getOriginalFilename()).orElse("file");
|
||||
String baseName = extractBaseName(original);
|
||||
String ext = extractExtension(original);
|
||||
|
||||
String timestamp = DateTimeUtil.nowKstLocalDateTime()
|
||||
.format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
|
||||
|
||||
return prefix + "_" + timestamp + "_" + baseName + ext;
|
||||
}
|
||||
|
||||
protected Path createDirectories(Path dir) throws IOException {
|
||||
return Files.createDirectories(dir.toAbsolutePath().normalize());
|
||||
}
|
||||
|
||||
protected String saveFile(Path dir, MultipartFile file) throws IOException {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new IllegalArgumentException("업로드할 파일이 없습니다.");
|
||||
}
|
||||
|
||||
Path normalizedDir = createDirectories(dir);
|
||||
String fileName = buildFileName(file);
|
||||
Path target = normalizedDir.resolve(fileName).normalize();
|
||||
|
||||
if (!target.startsWith(normalizedDir)) {
|
||||
throw new IllegalStateException("잘못된 파일 경로입니다.");
|
||||
}
|
||||
|
||||
file.transferTo(target.toFile());
|
||||
return fileName;
|
||||
}
|
||||
|
||||
protected void saveFile(Path dir, MultipartFile file, String fileName) throws IOException {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new IllegalArgumentException("업로드할 파일이 없습니다.");
|
||||
}
|
||||
|
||||
Path normalizedDir = createDirectories(dir);
|
||||
Path target = normalizedDir.resolve(fileName).normalize();
|
||||
|
||||
if (!target.startsWith(normalizedDir)) {
|
||||
throw new IllegalStateException("잘못된 파일 경로입니다.");
|
||||
}
|
||||
|
||||
file.transferTo(target.toFile());
|
||||
}
|
||||
|
||||
protected void moveFile(Path sourceDir, Path targetDir, String fileName) throws IOException {
|
||||
if (fileName == null || fileName.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Path normalizedSourceDir = sourceDir.toAbsolutePath().normalize();
|
||||
Path normalizedTargetDir = createDirectories(targetDir);
|
||||
|
||||
Path source = normalizedSourceDir.resolve(fileName).normalize();
|
||||
Path target = normalizedTargetDir.resolve(fileName).normalize();
|
||||
|
||||
if (!source.startsWith(normalizedSourceDir) || !target.startsWith(normalizedTargetDir)) {
|
||||
throw new IllegalStateException("잘못된 파일 경로입니다.");
|
||||
}
|
||||
if (!Files.exists(source)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
protected void deleteFile(Path dir, String fileName) throws IOException {
|
||||
if (fileName == null || fileName.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Path normalizedDir = dir.toAbsolutePath().normalize();
|
||||
Path target = normalizedDir.resolve(fileName).normalize();
|
||||
|
||||
if (!target.startsWith(normalizedDir)) {
|
||||
throw new IllegalStateException("잘못된 파일 경로입니다.");
|
||||
}
|
||||
|
||||
Files.deleteIfExists(target);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kri.contact.server.service.file;
|
||||
|
||||
import com.kri.common.file.FileUtil;
|
||||
import com.kri.common.feature.file.FileUtil;
|
||||
import com.kri.contact.server.config.FileStorageProperties;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
@@ -148,4 +148,4 @@ public class ContactScenarioFileService extends AbstractFileService {
|
||||
}
|
||||
return url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.kri.contact.server.service.file;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.contact.server.config.FileStorageProperties;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ListFileService extends AbstractFileService {
|
||||
|
||||
private final FileStorageProperties properties;
|
||||
|
||||
@Override
|
||||
protected Path getBaseDir() {
|
||||
return Paths.get(properties.getListBaseDir()).toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
public Path saveListFile(MultipartFile file, Long prjctIdx) {
|
||||
String newFileName = buildFileNameWithTime(file, prjctIdx.toString());
|
||||
Path dir = getBaseDir().resolve(prjctIdx.toString()).toAbsolutePath().normalize();
|
||||
Path savedPath = dir.resolve(newFileName).toAbsolutePath().normalize();
|
||||
|
||||
try {
|
||||
saveFile(dir, file, newFileName);
|
||||
return savedPath;
|
||||
} catch (IOException e) {
|
||||
throw BusinessException.internalError("FAIL_LIST_UPLOAD", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.kri.contact.server.service.file;
|
||||
|
||||
import com.kri.contact.server.config.FileStorageProperties;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ListItemFileService extends AbstractFileService {
|
||||
|
||||
private final FileStorageProperties properties;
|
||||
|
||||
@Override
|
||||
protected Path getBaseDir() {
|
||||
return Paths.get(properties.getListBaseDir());
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,6 @@ kri:
|
||||
temp-expire-hours: 24
|
||||
temp-cleanup-cron: "0 0 0 * * *" # 매일 00:00(초 분 시 일 월 요일)
|
||||
|
||||
common:
|
||||
web:
|
||||
enabled: true # 공통 Web 구성 사용 여부 (기본 true)
|
||||
webmvc:
|
||||
|
||||
Reference in New Issue
Block a user