|
|
|
|
@@ -1,5 +1,7 @@
|
|
|
|
|
package com.kri.kmusical.manage.back.service;
|
|
|
|
|
|
|
|
|
|
import static com.kri.kmusical.manage.back.common.consts.KmusicalConstant.MONITORING_REVIEW_TYPE;
|
|
|
|
|
import static com.kri.kmusical.manage.back.common.consts.KmusicalConstant.REVIEW_CLASSIFICATION;
|
|
|
|
|
import static com.kri.kmusical.manage.back.common.consts.KmusicalConstant.REVIEW_TYPE;
|
|
|
|
|
|
|
|
|
|
import com.kri.common.feature.util.StringUtil;
|
|
|
|
|
@@ -35,14 +37,19 @@ public class ReviewTemplateService extends AbstractFileService {
|
|
|
|
|
.normalize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String uploadReviewTemplate(Integer reviewType, MultipartFile file) {
|
|
|
|
|
public String uploadReviewTemplate(Integer reviewType, Integer classification, MultipartFile file) {
|
|
|
|
|
validateReviewTemplateType(reviewType);
|
|
|
|
|
|
|
|
|
|
if(MONITORING_REVIEW_TYPE.equals(reviewType)){
|
|
|
|
|
validateReviewTemplateClassification(classification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
|
|
throw BusinessException.badRequest("EMPTY_FILE", "업로드된 파일이 없습니다.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String fileName = sanitizeFileName(file.getOriginalFilename());
|
|
|
|
|
Path dir = templateDir(reviewType);
|
|
|
|
|
Path dir = templateDir(reviewType, classification);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
deleteExistingFiles(dir);
|
|
|
|
|
@@ -55,20 +62,24 @@ public class ReviewTemplateService extends AbstractFileService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PathResource getReviewTemplateResource(Integer reviewType) {
|
|
|
|
|
Path file = findReviewTemplateFile(reviewType, false);
|
|
|
|
|
public PathResource getReviewTemplateResource(Integer reviewType, Integer classification) {
|
|
|
|
|
Path file = findReviewTemplateFile(reviewType, classification, false);
|
|
|
|
|
return new PathResource(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PathResource getReviewTemplatePdfResource(Integer reviewType) {
|
|
|
|
|
Path file = findReviewTemplateFile(reviewType, true);
|
|
|
|
|
public PathResource getReviewTemplatePdfResource(Integer reviewType, Integer classification) {
|
|
|
|
|
Path file = findReviewTemplateFile(reviewType, classification, true);
|
|
|
|
|
return new PathResource(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Path findReviewTemplateFile(Integer reviewType, boolean pdf) {
|
|
|
|
|
private Path findReviewTemplateFile(Integer reviewType, Integer classification, boolean pdf) {
|
|
|
|
|
validateReviewTemplateType(reviewType);
|
|
|
|
|
|
|
|
|
|
Path dir = templateDir(reviewType);
|
|
|
|
|
if(MONITORING_REVIEW_TYPE.equals(reviewType)){
|
|
|
|
|
validateReviewTemplateClassification(classification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Path dir = templateDir(reviewType, classification);
|
|
|
|
|
if (!Files.isDirectory(dir)) {
|
|
|
|
|
throw BusinessException.notFound("REVIEW_TEMPLATE_NOT_FOUND", "평가양식 파일이 없습니다.")
|
|
|
|
|
.with("reviewType", reviewType);
|
|
|
|
|
@@ -140,11 +151,15 @@ public class ReviewTemplateService extends AbstractFileService {
|
|
|
|
|
return ".pdf".equalsIgnoreCase(extractExtension(fileName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Path templateDir(Integer reviewType) {
|
|
|
|
|
return getBaseDir()
|
|
|
|
|
.resolve(String.valueOf(reviewType))
|
|
|
|
|
.toAbsolutePath()
|
|
|
|
|
.normalize();
|
|
|
|
|
private Path templateDir(Integer reviewType, Integer classification) {
|
|
|
|
|
Path dir = getBaseDir()
|
|
|
|
|
.resolve(String.valueOf(reviewType));
|
|
|
|
|
|
|
|
|
|
if (MONITORING_REVIEW_TYPE.equals(reviewType) && classification != null) {
|
|
|
|
|
dir = dir.resolve(String.valueOf(classification));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dir.toAbsolutePath().normalize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateReviewTemplateType(Integer reviewType) {
|
|
|
|
|
@@ -154,6 +169,13 @@ public class ReviewTemplateService extends AbstractFileService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateReviewTemplateClassification(Integer classification) {
|
|
|
|
|
if (!REVIEW_CLASSIFICATION.contains(classification)) {
|
|
|
|
|
throw BusinessException.badRequest("INVALID_REVIEW_TEMPLATE_CLASSIFICATION", "유효하지 않은 평가양식 분류입니다.")
|
|
|
|
|
.with("classification", classification);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String sanitizeFileName(String originalFileName) {
|
|
|
|
|
if (StringUtil.isNullOrBlank(originalFileName)) {
|
|
|
|
|
return "review-template";
|
|
|
|
|
|