260115_01_ENH : Front 연동 테스트 완료 및 대량발송 결과 다운로드 구현 완료
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@ HELP.md
|
||||
.gradle
|
||||
build/
|
||||
logs/
|
||||
upload-file/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
kri:
|
||||
api-url:
|
||||
intranet-extension: "http://localhost:3031"
|
||||
body-image:
|
||||
public-base-url: http://localhost:4011/body-image
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
|
||||
@@ -4,6 +4,9 @@ kri:
|
||||
email:
|
||||
result-poll:
|
||||
initial-delay-ms: 3000
|
||||
body-image:
|
||||
public-base-url: http://localhost:4011/body-image
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
#private 도메인
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
kri:
|
||||
api-url:
|
||||
intranet-extension: "http://localhost:3031"
|
||||
body-image:
|
||||
public-base-url: http://localhost:4011/body-image
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
|
||||
@@ -75,7 +75,6 @@ kri:
|
||||
|
||||
body-image:
|
||||
upload-base-dir: ./upload-file/body-image
|
||||
public-base-url: /body-image
|
||||
temp-expire-hours: 24
|
||||
temp-cleanup-cron: "0 0 0 * * *" # 매일 00:00(초 분 시 일 월 요일)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "com.kri.common:starter:beta.1.0.60"
|
||||
implementation "com.kri.common:starter:beta.1.0.61"
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
@@ -58,6 +58,8 @@ dependencies {
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
|
||||
implementation 'org.apache.poi:poi-ooxml:5.2.5'
|
||||
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
|
||||
@@ -11,6 +11,7 @@ public final class NotihubConst {
|
||||
|
||||
public static final int CHUNK_SIZE = 5_000;
|
||||
public static final int INSERT_CHUNK_SIZE = 1_000;
|
||||
public static final int ROW_WINDOW = 500;
|
||||
|
||||
public static final short EMAIL_RESULT_SEARCH_DELAY = 500;
|
||||
public static final short EMAIL_DELAY = 500;
|
||||
@@ -18,6 +19,9 @@ public final class NotihubConst {
|
||||
|
||||
public static final List<SendType> MOBILE_TYPE_LIST = List.of(SendType.SMS, SendType.LMS_MMS);
|
||||
|
||||
public static final List<Short> MOBILE_TYPE_CODE_LIST = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
|
||||
public static final List<Short> EMAIL_TYPE_CODE_LIST = List.of(SendType.EMAIL.getCode());
|
||||
|
||||
public static final String EMAIL_RESERVATION_PREFIX = "RESERVATION_";
|
||||
public static final short EMAIL_STANDBY = 100;
|
||||
public static final short EMAIL_PENDING = (short) 111; // 발송요청은 성공했으나 json_return 미조회
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.kri.notihub.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter(onMethod_ = @JsonValue)
|
||||
@RequiredArgsConstructor
|
||||
public enum ChannelType implements CodeEnum<Short> {
|
||||
|
||||
EMAIL((short) 1),
|
||||
SMS((short) 2);
|
||||
|
||||
private final Short code;
|
||||
|
||||
ChannelType(CodeEnum<Short> source) {
|
||||
this.code = source.getCode();
|
||||
}
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ChannelType fromCode(Short code) {
|
||||
if (code == null) return null;
|
||||
for (ChannelType s : values()) {
|
||||
if (s.code == code) return s;
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ChannelType code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.kri.notihub.server.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebResourceConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${kri.body-image.upload-base-dir}")
|
||||
private String uploadBaseDir;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// /body-image/** → /data/upload-file/body-image/** 매핑
|
||||
registry.addResourceHandler("/body-image/**")
|
||||
.addResourceLocations("file:" + uploadBaseDir + "/");
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.kri.common.webmvc.page.PageResponseDto;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
||||
import com.kri.notihub.server.dto.report.ReportExcelResponseDto;
|
||||
import com.kri.notihub.server.dto.report.SendInfoDto;
|
||||
import com.kri.notihub.server.service.ReportService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -24,7 +25,7 @@ public class ReportController {
|
||||
|
||||
private final ReportService reportService;
|
||||
|
||||
@Operation(summary = "대량 발송 리스트 조회")
|
||||
@Operation(summary = "대량발송 리스트 조회")
|
||||
@GetMapping("/bulk-list/{sendTy}/{reqstSvc}/{prjctCd}")
|
||||
public List<BulkSendInfoDto> getBulkSendList(
|
||||
@PathVariable SendType sendTy,
|
||||
@@ -36,7 +37,7 @@ public class ReportController {
|
||||
return reportService.getBulkSendList(sendTy, reqstSvc, prjctCd, regCmpn);
|
||||
}
|
||||
|
||||
@Operation(summary = "이메일 발송 리스트 조회")
|
||||
@Operation(summary = "대량발송 결과 조회")
|
||||
@PostMapping("/bulk-detail/{bulkSendKey}")
|
||||
public PageResponseDto<SendInfoDto> getBulkSendDetail(
|
||||
@PathVariable String bulkSendKey,
|
||||
@@ -44,4 +45,10 @@ public class ReportController {
|
||||
){
|
||||
return reportService.getBulkSendDetail(bulkSendKey, pageReq);
|
||||
}
|
||||
|
||||
@Operation(summary = "대량발송 결과 다운로드")
|
||||
@PostMapping("/bulk-detail/excel/{bulkSendKey}")
|
||||
public ReportExcelResponseDto getBulkSendDetailExcel(@PathVariable String bulkSendKey){
|
||||
return reportService.getBulkSendDetailExcel(bulkSendKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kri.notihub.server.controller;
|
||||
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||
import com.kri.notihub.server.dto.template.TemplateDto;
|
||||
import com.kri.notihub.server.dto.template.TemplateSummaryDto;
|
||||
@@ -25,9 +26,12 @@ public class TemplateController {
|
||||
private final FileService fileService;
|
||||
|
||||
@Operation(summary = "템플릿 목록 조회")
|
||||
@GetMapping("/list/{itrntPrjctCd}")
|
||||
public List<TemplateSummaryDto> getTemplateList(@PathVariable String itrntPrjctCd) {
|
||||
return templateService.getTemplateList(itrntPrjctCd);
|
||||
@GetMapping("/list/{chnnlTy}/{itrntPrjctCd}")
|
||||
public List<TemplateSummaryDto> getTemplateList(
|
||||
@PathVariable ChannelType chnnlTy,
|
||||
@PathVariable String itrntPrjctCd
|
||||
) {
|
||||
return templateService.getTemplateList(chnnlTy, itrntPrjctCd);
|
||||
}
|
||||
|
||||
@Operation(summary = "템플릿 단건 조회")
|
||||
@@ -37,19 +41,23 @@ public class TemplateController {
|
||||
}
|
||||
|
||||
@Operation(summary = "템플릿 생성")
|
||||
@PutMapping("/{itrntPrjctCd}")
|
||||
public long createTemplate(
|
||||
@PathVariable String itrntPrjctCd,
|
||||
@PutMapping
|
||||
public TemplateDto createTemplate(
|
||||
@Valid @RequestBody TemplateBasicDto template,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
String newHtml = fileService.syncOnSave(
|
||||
itrntPrjctCd,
|
||||
template.getTmplatBody()
|
||||
);
|
||||
template.setTmplatBody(newHtml);
|
||||
TemplateDto newTmplat = templateService.createTemplate(template.getItrntPrjctCd(), template, ctx.getUserId());
|
||||
|
||||
return templateService.createTemplate(itrntPrjctCd, template, ctx.getUserId());
|
||||
String newHtml = fileService.syncOnSave(
|
||||
newTmplat.getItrntPrjctCd(),
|
||||
newTmplat.getTmplatIdx(),
|
||||
newTmplat.getTmplatBody()
|
||||
);
|
||||
newTmplat.setTmplatBody(newHtml);
|
||||
|
||||
templateService.updateTemplateBodyWithCreate(newTmplat);
|
||||
|
||||
return newTmplat;
|
||||
}
|
||||
|
||||
@Operation(summary = "시나리오 이미지 업로드")
|
||||
@@ -59,13 +67,14 @@ public class TemplateController {
|
||||
}
|
||||
|
||||
@Operation(summary = "템플릿 수정")
|
||||
@PatchMapping()
|
||||
@PatchMapping
|
||||
public TemplateDto updateTemplate(
|
||||
@Valid @RequestBody TemplateDto template,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
String newHtml = fileService.syncOnSave(
|
||||
template.getItrntPrjctCd(),
|
||||
template.getTmplatIdx(),
|
||||
template.getTmplatBody()
|
||||
);
|
||||
template.setTmplatBody(newHtml);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.kri.notihub.server.dto.report;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ReportExcelResponseDto {
|
||||
|
||||
@Schema(description = "프론트가 저장용으로 쓸 파일명")
|
||||
private String errorFileName;
|
||||
|
||||
@Schema(description = "에러 엑셀 파일 (xlsx)의 Base64 문자열 (hasErrorFile == true일 때만 세팅)")
|
||||
private String errorFileBase64;
|
||||
}
|
||||
@@ -19,6 +19,11 @@ import lombok.experimental.SuperBuilder;
|
||||
@AllArgsConstructor
|
||||
public class TemplateBasicDto {
|
||||
|
||||
@Size(max = 32)
|
||||
@NotBlank
|
||||
@Schema(description = "인트라넷 프로젝트 코드")
|
||||
public String itrntPrjctCd;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "템플릿 타입")
|
||||
public SendType tmplatTy;
|
||||
|
||||
@@ -24,11 +24,6 @@ public class TemplateDto extends TemplateBasicDto{
|
||||
@Schema(description = "템플릿 고유 키 (없으면 Create / 있으면 Update)")
|
||||
public Long tmplatIdx;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotBlank
|
||||
@Schema(description = "인트라넷 프로젝트 코드")
|
||||
public String itrntPrjctCd;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "등록자", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface TemplateRepository extends JpaRepository<TTmplatEntity, Long>,
|
||||
""")
|
||||
int softDeleteByTmplatIdx(long idx, String delUser, LocalDateTime delDt);
|
||||
|
||||
List<TTmplatEntity> findAllByItrntPrjctCdAndDelFalse(String itrntPrjctCd);
|
||||
List<TTmplatEntity> findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(List<Short> tmplatTyList, String itrntPrjctCd);
|
||||
|
||||
Optional<TTmplatEntity> findByTmplatIdxAndDelFalse(long tmplatIdx);
|
||||
}
|
||||
|
||||
@@ -68,13 +68,11 @@ public class FileService {
|
||||
* 2) Asset 디렉토리에서 더 이상 사용되지 않는 파일 삭제
|
||||
* 3) 정리된 HTML 반환
|
||||
*/
|
||||
public String syncOnSave(String prjctCd, String rawHtml) {
|
||||
public String syncOnSave(String prjctCd, Long tmplatIdx, String rawHtml) {
|
||||
if (rawHtml == null) rawHtml = "";
|
||||
|
||||
String returnHtml = rawHtml;
|
||||
try{
|
||||
|
||||
|
||||
// body fragment로 파싱 (KriEditor가 body 없이 <p>...</p> 형태 저장하므로)
|
||||
Document doc = Jsoup.parseBodyFragment(rawHtml);
|
||||
Elements imgs = doc.select("img[src]");
|
||||
@@ -86,23 +84,33 @@ public class FileService {
|
||||
if (src == null || src.isBlank()) continue;
|
||||
if (!src.contains("/" + prjctCd + "/")) continue;
|
||||
|
||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||
|
||||
if (src.contains("/" + prjctCd + "/Temp/")) {
|
||||
// Temp → Asset 이동
|
||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||
moveTempToAsset(prjctCd, fileName);
|
||||
moveTempToAsset(prjctCd, tmplatIdx, fileName);
|
||||
|
||||
String assetSrc = src.replace("/Temp/", "/Asset/");
|
||||
String assetSrc = src.replace("/Temp/", "/Asset/" + tmplatIdx + "/");
|
||||
img.attr("src", assetSrc);
|
||||
|
||||
assetFileNamesToKeep.add(fileName);
|
||||
} else if (src.contains("/" + prjctCd + "/Asset/")) {
|
||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||
if (!src.contains("/" + prjctCd + "/Asset/" + tmplatIdx + "/")){
|
||||
String[] srcArr = src.split("/" + prjctCd + "/Asset/");
|
||||
String fromTmplatIdx = srcArr[1].split("/")[0].replace(fileName, "");
|
||||
|
||||
copyAssetToAsset(prjctCd, fromTmplatIdx, tmplatIdx, fileName);
|
||||
|
||||
String assetSrc = src.replace("/Asset/" + fromTmplatIdx + "/", "/Asset/" + tmplatIdx + "/");
|
||||
img.attr("src", assetSrc);
|
||||
}
|
||||
|
||||
assetFileNamesToKeep.add(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
// Asset 디렉토리 정리 (본문에 없는 파일 삭제)
|
||||
cleanupAssetDir(prjctCd, assetFileNamesToKeep);
|
||||
cleanupAssetDir(prjctCd, tmplatIdx, assetFileNamesToKeep);
|
||||
|
||||
// body 안의 HTML만 반환 (불필요한 <html><body> wrapper 제거)
|
||||
returnHtml = doc.body().html();
|
||||
@@ -126,15 +134,36 @@ public class FileService {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Temp");
|
||||
}
|
||||
|
||||
private Path getAssetDir(String prjctCd) {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Asset");
|
||||
private Path getAssetDir(String prjctCd, String tmplatIdx) {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Asset").resolve(tmplatIdx);
|
||||
}
|
||||
|
||||
private void moveTempToAsset(String prjctCd, String fileName) throws IOException {
|
||||
private Path getAssetDir(String prjctCd, Long tmplatIdx) {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Asset").resolve(tmplatIdx.toString());
|
||||
}
|
||||
|
||||
private void copyAssetToAsset(String prjctCd, String fromTmplatIdx, Long toTmplatIdx, String fileName) throws IOException {
|
||||
if (fileName == null || fileName.isBlank()) return;
|
||||
Path fromDir = getAssetDir(prjctCd, fromTmplatIdx);
|
||||
Path toDir = getAssetDir(prjctCd, toTmplatIdx);
|
||||
|
||||
Path src = fromDir.resolve(fileName).normalize();
|
||||
Path dst = toDir.resolve(fileName).normalize();
|
||||
|
||||
Files.createDirectories(toDir);
|
||||
|
||||
if (!Files.exists(src)) {
|
||||
throw new NoSuchFileException("Source asset not found: " + src);
|
||||
}
|
||||
|
||||
Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
private void moveTempToAsset(String prjctCd, Long tmplatIdx, String fileName) throws IOException {
|
||||
if (fileName == null || fileName.isBlank()) return;
|
||||
|
||||
Path tempDir = getTempDir(prjctCd);
|
||||
Path assetDir = getAssetDir(prjctCd);
|
||||
Path assetDir = getAssetDir(prjctCd, tmplatIdx);
|
||||
Files.createDirectories(assetDir);
|
||||
|
||||
Path source = tempDir.resolve(fileName).normalize();
|
||||
@@ -151,8 +180,8 @@ public class FileService {
|
||||
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
private void cleanupAssetDir(String prjctCd, Set<String> keepFileNames) throws IOException {
|
||||
Path assetDir = getAssetDir(prjctCd);
|
||||
private void cleanupAssetDir(String prjctCd, Long tmplatIdx, Set<String> keepFileNames) throws IOException {
|
||||
Path assetDir = getAssetDir(prjctCd, tmplatIdx);
|
||||
if (!Files.exists(assetDir)) return;
|
||||
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(assetDir)) {
|
||||
|
||||
@@ -1,25 +1,41 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.common.excel.ExcelMapper;
|
||||
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.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
||||
import com.kri.notihub.server.dto.report.ReportExcelResponseDto;
|
||||
import com.kri.notihub.server.dto.report.SendInfoDto;
|
||||
import com.kri.notihub.server.persistence.entity.TBulkSendEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TSendResultCodeEntity;
|
||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendResultCodeRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ReportService {
|
||||
|
||||
private final SendResultCodeRepository sendResultCodeRepository;
|
||||
private final BulkSendRepository bulkSendRepository;
|
||||
private final SendRepository sendRepository;
|
||||
|
||||
@@ -37,10 +53,67 @@ public class ReportService {
|
||||
}
|
||||
|
||||
public PageResponseDto<SendInfoDto> getBulkSendDetail(String bulkSendKey, PageRequestDto pageReq){
|
||||
List<TSendResultCodeEntity> resultCodeList = sendResultCodeRepository.findAll();
|
||||
|
||||
Pageable pageable = Pageables.of(pageReq, TSendEntity.class);
|
||||
Page<SendInfoDto> page = sendRepository.findByBulkSendKey(bulkSendKey, pageable)
|
||||
.map(SendInfoDto::from);
|
||||
.map(entity -> SendInfoDto.from(entity, resultCodeList));
|
||||
|
||||
return PageResponseDto.from(page);
|
||||
}
|
||||
|
||||
public ReportExcelResponseDto getBulkSendDetailExcel(String bulkSendKey){
|
||||
List<TSendResultCodeEntity> resultCodeList = sendResultCodeRepository.findAll();
|
||||
|
||||
Sort sort = Sort.by(Sort.Direction.ASC, "sendIdx");
|
||||
|
||||
TBulkSendEntity bulkSend = bulkSendRepository.findByBulkSendKey(bulkSendKey).orElse(null);
|
||||
if(bulkSend == null){
|
||||
throw BusinessException.badRequest("NOT FOUND BULK SEND","해당 대량발송은 없습니다.")
|
||||
.with("bulkSendKey", bulkSendKey);
|
||||
}
|
||||
|
||||
String ts = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
|
||||
String fileName = "대량 발송 내역_%s_%s_%s.xlsx".formatted(bulkSend.getReqstSvc(), bulkSend.getPrjctCd(), ts);
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(64 * 1024);
|
||||
|
||||
// Base64 스트림으로 바로 쓰기 (엑셀 bytes -> base64 bytes)
|
||||
try (OutputStream b64Out = Base64.getEncoder().wrap(bos);
|
||||
ExcelMapper.StreamingWriter<SendInfoDto> writer =
|
||||
ExcelMapper.openStreamingWriter(SendInfoDto.class, NotihubConst.ROW_WINDOW)) {
|
||||
|
||||
int page = 0;
|
||||
while (true) {
|
||||
Page<TSendEntity> chunkPage = sendRepository.findByBulkSendKey(
|
||||
bulkSendKey,
|
||||
PageRequest.of(page++, NotihubConst.CHUNK_SIZE, sort)
|
||||
);
|
||||
|
||||
if (chunkPage.isEmpty()) break;
|
||||
|
||||
List<SendInfoDto> chunk = chunkPage.getContent()
|
||||
.stream()
|
||||
.map(entity -> SendInfoDto.from(entity, resultCodeList))
|
||||
.toList();
|
||||
|
||||
writer.appendAll(chunk);
|
||||
|
||||
if (!chunkPage.hasNext()) break;
|
||||
}
|
||||
|
||||
//최종 1회 write (XLSX 마무리)
|
||||
writer.writeTo(b64Out);
|
||||
} catch (Exception e) {
|
||||
throw BusinessException.internalError("FAIL MAKE EXCEL","엑셀(Base64) 생성 실패. " + e.getMessage())
|
||||
.with("bulkSendKey", bulkSendKey);
|
||||
}
|
||||
|
||||
String base64 = new String(bos.toByteArray(), StandardCharsets.UTF_8);
|
||||
|
||||
return ReportExcelResponseDto.builder()
|
||||
.errorFileName(fileName)
|
||||
.errorFileBase64(base64)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.kri.notihub.server.service;
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.web.BusinessException;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.common.enums.TemplateEventType;
|
||||
import com.kri.notihub.server.common.util.TemplateContentSanitizer;
|
||||
@@ -28,7 +29,7 @@ public class TemplateService {
|
||||
private final TemplateEventLogRepository templateEventLogRepository;
|
||||
|
||||
@Transactional
|
||||
public long createTemplate(String itrntPrjctCd, TemplateBasicDto template, String regUser) {
|
||||
public TemplateDto createTemplate(String itrntPrjctCd, TemplateBasicDto template, String regUser) {
|
||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
|
||||
validateBySendType(template);
|
||||
@@ -42,11 +43,15 @@ public class TemplateService {
|
||||
|
||||
saveLog(saved.getTmplatIdx(), TemplateEventType.CREATE_TEMPLATE, null, template, regUser, now);
|
||||
|
||||
return saved.getTmplatIdx();
|
||||
return TemplateDto.from(saved);
|
||||
}
|
||||
|
||||
public List<TemplateSummaryDto> getTemplateList(String itrntPrjctCd) {
|
||||
return templateRepository.findAllByItrntPrjctCdAndDelFalse(itrntPrjctCd).stream()
|
||||
public List<TemplateSummaryDto> getTemplateList(ChannelType chnnlTy, String itrntPrjctCd) {
|
||||
List<Short> tmplatTyList = chnnlTy == ChannelType.SMS
|
||||
? NotihubConst.MOBILE_TYPE_CODE_LIST
|
||||
: NotihubConst.EMAIL_TYPE_CODE_LIST;
|
||||
|
||||
return templateRepository.findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(tmplatTyList, itrntPrjctCd).stream()
|
||||
.map(TemplateSummaryDto::from)
|
||||
.toList();
|
||||
}
|
||||
@@ -60,6 +65,17 @@ public class TemplateService {
|
||||
);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateTemplateBodyWithCreate(TemplateDto template) {
|
||||
TTmplatEntity entity = templateRepository.findByTmplatIdxAndDelFalse(template.getTmplatIdx()).orElseThrow(() ->
|
||||
BusinessException.notFound("TEMPLATE_NOT_FOUND", "템플릿을 찾을 수 없습니다.")
|
||||
.with("tmplatIdx", template.getTmplatIdx())
|
||||
);
|
||||
|
||||
entity.setTmplatBody(template.getTmplatBody());
|
||||
templateRepository.save(entity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public TemplateDto updateTemplate(TemplateDto template, String modUser) {
|
||||
long tmplatIdx = template.getTmplatIdx();
|
||||
|
||||
Reference in New Issue
Block a user