develop #1
@@ -1,6 +1,7 @@
|
||||
package com.kri.kmusical.manage.back.common.consts;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class KmusicalConstant {
|
||||
public static final String SYSTEM_USER_NAME = "SYSTEM";
|
||||
@@ -11,5 +12,14 @@ public class KmusicalConstant {
|
||||
MONITORING_REVIEW_TYPE,
|
||||
CONSULTING_REVIEW_TYPE
|
||||
);
|
||||
|
||||
public static final Integer PUBLIC_OFFERING_REQUEST_FORM_TYPE = 1;
|
||||
public static final Integer ISSUANCE_REQUEST_FORM_TYPE = 2;
|
||||
public static final Map<Integer, String> REQUEST_FORM_DETAIL_KEY = Map.of(
|
||||
PUBLIC_OFFERING_REQUEST_FORM_TYPE, "PublicOfferingRequestForm",
|
||||
ISSUANCE_REQUEST_FORM_TYPE, "IssuanceRequestForm"
|
||||
);
|
||||
public static final Integer COMPLETE_STATUS = 10;
|
||||
|
||||
public static final List<Integer> REVIEW_CLASSIFICATION = List.of(1, 2);
|
||||
}
|
||||
|
||||
@@ -10,4 +10,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
public class FileStorageProperties {
|
||||
private String reviewBaseDir;
|
||||
private String reviewTemplateBaseDir;
|
||||
private String requestFormBaseDir;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kri.kmusical.manage.back.controller;
|
||||
|
||||
import static com.kri.kmusical.manage.back.common.util.DownloadHeaderUtil.attachmentContentDisposition;
|
||||
import static com.kri.kmusical.manage.back.common.util.ExcelResponseBuilder.buildExcelResponse;
|
||||
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
@@ -16,6 +17,8 @@ import jakarta.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
@@ -94,6 +97,27 @@ public class PerformanceController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "공모신청서/교부신청서 업로드")
|
||||
@PostMapping(value = "/request-form/upload/{performanceId}/{formType}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public String uploadRequestForm(
|
||||
@PathVariable String performanceId,
|
||||
@PathVariable Integer formType,
|
||||
@RequestParam("file") MultipartFile file,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return performanceService.uploadRequestForm(
|
||||
performanceId, formType, file, ctx.getUserId(), DateTimeUtil.nowKstLocalDateTime());
|
||||
}
|
||||
|
||||
@Operation(summary = "공모신청서/교부신청서 다운로드")
|
||||
@GetMapping("/request-form/download/{performanceId}/{formType}")
|
||||
public ResponseEntity<Resource> downloadRequestForm(
|
||||
@PathVariable String performanceId,
|
||||
@PathVariable Integer formType
|
||||
) {
|
||||
return download(performanceService.getRequestFormResource(performanceId, formType));
|
||||
}
|
||||
|
||||
@Operation(summary = "공연 정보 수정")
|
||||
@PatchMapping()
|
||||
public void updatePerformance(
|
||||
@@ -119,4 +143,11 @@ public class PerformanceController {
|
||||
performanceService.deletePerformance(performanceId, delId);
|
||||
systemEventLogService.writeDeletePerformanceLog(delId, now, ctx.getClientIp(), performanceId);
|
||||
}
|
||||
|
||||
private ResponseEntity<Resource> download(Resource resource) {
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, attachmentContentDisposition(resource.getFilename()))
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(resource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,25 +100,28 @@ public class ReviewController {
|
||||
@PostMapping(value = "/template/upload/{reviewType}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public String uploadReviewTemplate(
|
||||
@PathVariable Integer reviewType,
|
||||
@RequestParam(required = false) Integer classification,
|
||||
@RequestParam("file") MultipartFile file
|
||||
) {
|
||||
return reviewTemplateService.uploadReviewTemplate(reviewType, file);
|
||||
return reviewTemplateService.uploadReviewTemplate(reviewType, classification, file);
|
||||
}
|
||||
|
||||
@Operation(summary = "평가양식 다운로드")
|
||||
@GetMapping("/template/download/{reviewType}")
|
||||
public ResponseEntity<Resource> downloadReviewTemplate(
|
||||
@PathVariable Integer reviewType
|
||||
@PathVariable Integer reviewType,
|
||||
@RequestParam(required = false) Integer classification
|
||||
) {
|
||||
return download(reviewTemplateService.getReviewTemplateResource(reviewType));
|
||||
return download(reviewTemplateService.getReviewTemplateResource(reviewType, classification));
|
||||
}
|
||||
|
||||
@Operation(summary = "평가양식 pdf 다운로드")
|
||||
@GetMapping("/template/pdf/{reviewType}")
|
||||
public ResponseEntity<Resource> downloadReviewPdfTemplate(
|
||||
@PathVariable Integer reviewType
|
||||
@PathVariable Integer reviewType,
|
||||
@RequestParam(required = false) Integer classification
|
||||
) {
|
||||
return download(reviewTemplateService.getReviewTemplatePdfResource(reviewType));
|
||||
return download(reviewTemplateService.getReviewTemplatePdfResource(reviewType, classification));
|
||||
}
|
||||
|
||||
private ResponseEntity<Resource> download(Resource resource) {
|
||||
|
||||
@@ -18,8 +18,6 @@ public interface PerformanceAssignRepository extends JpaRepository<TPerformanceA
|
||||
|
||||
boolean existsByIdPerformanceIdAndAssignUser(String performanceId, String assignUser);
|
||||
|
||||
boolean existsByAssignUserAndIdPerformanceIdNot(String assignUser, String performanceId);
|
||||
|
||||
Optional<TPerformanceAssignEntity> findByIdPerformanceIdAndIdReviewSlot(
|
||||
String performanceId,
|
||||
Integer reviewSlot
|
||||
|
||||
@@ -152,10 +152,6 @@ public class AssignService {
|
||||
.with("performanceId", performanceId)
|
||||
.with("assignUser", assignUser);
|
||||
}
|
||||
if (performanceAssignRepository.existsByAssignUserAndIdPerformanceIdNot(assignUser, performanceId)) {
|
||||
throw BusinessException.conflict("ASSIGN_USER_ALREADY_CONFIRMED", "다른 공연에 이미 확정된 사용자입니다.")
|
||||
.with("assignUser", assignUser);
|
||||
}
|
||||
|
||||
if (entity == null) {
|
||||
entity = new TPerformanceAssignEntity();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kri.kmusical.manage.back.service;
|
||||
|
||||
import static com.kri.kmusical.manage.back.common.consts.KmusicalConstant.REQUEST_FORM_DETAIL_KEY;
|
||||
import static com.kri.kmusical.manage.back.common.util.AppendCodeSheet.appendCodeSheet;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
@@ -10,6 +11,7 @@ import com.kri.common.feature.util.StringUtil;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.kmusical.manage.back.common.util.ExcelUploadResultUtil;
|
||||
import com.kri.kmusical.manage.back.common.util.TelUtil;
|
||||
import com.kri.kmusical.manage.back.config.FileStorageProperties;
|
||||
import com.kri.kmusical.manage.back.dto.common.CodeDto;
|
||||
import com.kri.kmusical.manage.back.dto.excel.ExcelErrorDto;
|
||||
import com.kri.kmusical.manage.back.dto.excel.ExcelUploadResultDto;
|
||||
@@ -28,6 +30,7 @@ import com.kri.kmusical.manage.back.persistence.entity.TPerformanceEntity;
|
||||
import com.kri.kmusical.manage.back.persistence.entity.TPerformanceMonitoringScheduleEntity;
|
||||
import com.kri.kmusical.manage.back.persistence.entity.TPerformanceReviewEntity;
|
||||
import com.kri.kmusical.manage.back.persistence.entity.TPerformanceStaffEntity;
|
||||
import com.kri.kmusical.manage.back.persistence.entity.id.TPerformanceDetailEntityId;
|
||||
import com.kri.kmusical.manage.back.persistence.mapper.kon.KonMapper;
|
||||
import com.kri.kmusical.manage.back.persistence.repository.PerformanceAssignRepository;
|
||||
import com.kri.kmusical.manage.back.persistence.repository.PerformanceDetailRepository;
|
||||
@@ -36,6 +39,10 @@ import com.kri.kmusical.manage.back.persistence.repository.PerformanceRepository
|
||||
import com.kri.kmusical.manage.back.persistence.repository.PerformanceReviewRepository;
|
||||
import com.kri.kmusical.manage.back.persistence.repository.PerformanceStaffRepository;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@@ -52,6 +59,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.PathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -73,6 +81,7 @@ public class PerformanceService {
|
||||
private final CodeService codeService;
|
||||
private final AssignService assignService;
|
||||
private final ReviewService reviewService;
|
||||
private final FileStorageProperties fileStorageProperties;
|
||||
|
||||
@Value("${kon.survey-type:LIST}")
|
||||
private String surveyType;
|
||||
@@ -108,6 +117,95 @@ public class PerformanceService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public String uploadRequestForm(
|
||||
String performanceId,
|
||||
Integer formType,
|
||||
MultipartFile file,
|
||||
String userId,
|
||||
LocalDateTime now
|
||||
) {
|
||||
String detailKey = requestFormDetailKey(formType);
|
||||
getPerformanceEntity(performanceId);
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw BusinessException.badRequest("EMPTY_FILE", "업로드된 파일이 없습니다.");
|
||||
}
|
||||
|
||||
String originalFileName = file.getOriginalFilename();
|
||||
if (!StringUtil.hasText(originalFileName)) {
|
||||
throw BusinessException.badRequest("INVALID_FILE_NAME", "파일명이 없습니다.");
|
||||
}
|
||||
String fileName = Path.of(originalFileName).getFileName().toString();
|
||||
Path dir = requestFormDir(performanceId, formType);
|
||||
Path target = requestFormPath(dir, fileName);
|
||||
TPerformanceDetailEntityId detailId = new TPerformanceDetailEntityId(performanceId, detailKey);
|
||||
TPerformanceDetailEntity detail = performanceDetailRepository.findById(detailId).orElse(null);
|
||||
String oldFileName = detail == null ? null : detail.getPerformanceDetailValue();
|
||||
|
||||
try {
|
||||
Files.createDirectories(dir);
|
||||
Path stagedFile = Files.createTempFile(dir, "request-form-", ".tmp");
|
||||
try {
|
||||
file.transferTo(stagedFile.toFile());
|
||||
Files.move(stagedFile, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
} finally {
|
||||
Files.deleteIfExists(stagedFile);
|
||||
}
|
||||
if (detail == null) {
|
||||
detail = TPerformanceDetailEntity.update(performanceId, detailKey, fileName, userId, now);
|
||||
} else {
|
||||
detail.setPerformanceDetailValue(fileName);
|
||||
detail.setModUser(userId);
|
||||
detail.setModDt(now);
|
||||
}
|
||||
performanceDetailRepository.save(detail);
|
||||
if (StringUtil.hasText(oldFileName) && !oldFileName.equals(fileName)) {
|
||||
Files.deleteIfExists(requestFormPath(dir, oldFileName));
|
||||
}
|
||||
return fileName;
|
||||
} catch (IOException e) {
|
||||
throw BusinessException.internalError("REQUEST_FORM_SAVE_FAILED", "신청서 파일 저장 중 오류가 발생했습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
public PathResource getRequestFormResource(String performanceId, Integer formType) {
|
||||
String detailKey = requestFormDetailKey(formType);
|
||||
TPerformanceDetailEntityId detailId = new TPerformanceDetailEntityId(performanceId, detailKey);
|
||||
String fileName = performanceDetailRepository.findById(detailId)
|
||||
.map(TPerformanceDetailEntity::getPerformanceDetailValue)
|
||||
.orElseThrow(() -> BusinessException.notFound("REQUEST_FORM_NOT_FOUND", "신청서 파일이 없습니다."));
|
||||
Path file = requestFormPath(requestFormDir(performanceId, formType), fileName);
|
||||
if (!Files.isRegularFile(file)) {
|
||||
throw BusinessException.notFound("REQUEST_FORM_NOT_FOUND", "신청서 파일이 없습니다.");
|
||||
}
|
||||
return new PathResource(file);
|
||||
}
|
||||
|
||||
private String requestFormDetailKey(Integer formType) {
|
||||
String detailKey = formType == null ? null : REQUEST_FORM_DETAIL_KEY.get(formType);
|
||||
if (detailKey != null) {
|
||||
return detailKey;
|
||||
}
|
||||
throw BusinessException.badRequest("INVALID_REQUEST_FORM_TYPE", "유효하지 않은 신청서 유형입니다.")
|
||||
.with("formType", formType);
|
||||
}
|
||||
|
||||
private Path requestFormDir(String performanceId, Integer formType) {
|
||||
Path baseDir = Path.of(fileStorageProperties.getRequestFormBaseDir()).toAbsolutePath().normalize();
|
||||
Path dir = baseDir.resolve(performanceId).resolve(String.valueOf(formType)).normalize();
|
||||
if (!dir.startsWith(baseDir)) {
|
||||
throw BusinessException.badRequest("INVALID_PERFORMANCE_ID", "유효하지 않은 공연 ID입니다.");
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
private Path requestFormPath(Path dir, String fileName) {
|
||||
Path target = dir.resolve(fileName).normalize();
|
||||
if (!target.startsWith(dir) || target.equals(dir)) {
|
||||
throw BusinessException.badRequest("INVALID_FILE_NAME", "유효하지 않은 파일명입니다.");
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ExcelUploadResultDto createPerformancesFromExcel(
|
||||
MultipartFile file,
|
||||
@@ -567,7 +665,7 @@ public class PerformanceService {
|
||||
|
||||
validateRequired(errors, rowNumber, "단체(인) 명", row.getArtistName());
|
||||
validateRequired(errors, rowNumber, "사업 명", row.getPerformanceName());
|
||||
validateRequired(errors, rowNumber, "모니터링 방문 장소", row.getMonitoringAddress());
|
||||
//validateRequired(errors, rowNumber, "모니터링 방문 장소", row.getMonitoringAddress());
|
||||
|
||||
validateStaff(errors, rowNumber, "대표자", row.getOwnStaffName(),
|
||||
row.getOwnStaffTel1(), row.getOwnStaffTel2(), row.getOwnStaffEmail());
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -73,6 +73,7 @@ kri:
|
||||
file:
|
||||
review-base-dir: ./upload-file/review
|
||||
review-template-base-dir: ./upload-file/review-template
|
||||
request-form-base-dir: ./upload-file/request-form
|
||||
resource-pattern: /files/**
|
||||
pdf-converter-command: soffice
|
||||
|
||||
@@ -81,4 +82,4 @@ kri:
|
||||
redis:
|
||||
enabled: false # RedisQueueHelper 사용 시 true
|
||||
scheduling:
|
||||
enabled: false # @Scheduled 사용 시 true
|
||||
enabled: false # @Scheduled 사용 시 true
|
||||
|
||||
Reference in New Issue
Block a user