파일업로드 API 변경

This commit is contained in:
LAPTOP-L3VE7KK2\USER 2024-12-03 14:21:49 +09:00
parent d65396b187
commit a5c4fcb110
5 changed files with 126 additions and 56 deletions

View File

@ -506,6 +506,13 @@ public class EstimateService {
} }
itemRequest.setSpecialNoteCd(specialNoteCd); itemRequest.setSpecialNoteCd(specialNoteCd);
} }
// 첨부파일 초기화
FileRequest fileRequest = new FileRequest();
fileRequest.setObjectNo(estimateRequest.getObjectNo());
fileRequest.setPlanNo(estimateRequest.getPlanNo());
fileRequest.setUserId(estimateRequest.getUserId());
fileMapper.deleteFile(fileRequest);
} }
// 아이템 목록 필수 체크 // 아이템 목록 필수 체크
@ -629,6 +636,21 @@ public class EstimateService {
} }
} }
// 첨부파일 처리
if (estimateRequest.getFileList() != null) {
for (FileRequest fileRequest : estimateRequest.getFileList()) {
fileRequest.setUserId(estimateRequest.getUserId());
fileMapper.insertFile(fileRequest);
}
}
if (estimateRequest.getDeleteFileList() != null) {
for (FileRequest fileRequest : estimateRequest.getDeleteFileList()) {
fileRequest.setUserId(estimateRequest.getUserId());
fileMapper.deleteFile(fileRequest);
}
}
// QSP Q.CAST SEND API // QSP Q.CAST SEND API
List<EstimateSendResponse> resultList = new ArrayList<EstimateSendResponse>(); List<EstimateSendResponse> resultList = new ArrayList<EstimateSendResponse>();
resultList = this.sendEstimateApi(estimateRequest); resultList = this.sendEstimateApi(estimateRequest);
@ -676,7 +698,8 @@ public class EstimateService {
objectRequest.setSaleStoreId(estimateCopyRequest.getCopySaleStoreId()); objectRequest.setSaleStoreId(estimateCopyRequest.getCopySaleStoreId());
objectRequest.setReceiveUser( objectRequest.setReceiveUser(
StringUtils.defaultString(estimateCopyRequest.getCopyReceiveUser())); StringUtils.defaultString(estimateCopyRequest.getCopyReceiveUser()));
objectRequest.setDelFlg("0"); objectRequest.setDelFlg("1");
objectRequest.setOrgDelFlg("0");
objectRequest.setTempFlg("0"); objectRequest.setTempFlg("0");
objectRequest.setTempDelFlg("0"); objectRequest.setTempDelFlg("0");
objectRequest.setUserId(estimateCopyRequest.getUserId()); objectRequest.setUserId(estimateCopyRequest.getUserId());
@ -1205,6 +1228,7 @@ public class EstimateService {
List<EstimateSendResponse> quoteList = new ArrayList<EstimateSendResponse>(); List<EstimateSendResponse> quoteList = new ArrayList<EstimateSendResponse>();
String docNo = ""; String docNo = "";
try {
// 견적서 상세 조회 // 견적서 상세 조회
EstimateSendResponse estimateSendResponse = EstimateSendResponse estimateSendResponse =
estimateMapper.selectEstimateApiDetail(estimateRequest); estimateMapper.selectEstimateApiDetail(estimateRequest);
@ -1222,7 +1246,8 @@ public class EstimateService {
// 아이템 목록 조회 // 아이템 목록 조회
estimateRequest.setSchBomNotExist("1"); estimateRequest.setSchBomNotExist("1");
List<ItemResponse> estimateItemList = estimateMapper.selectEstimateItemList(estimateRequest); List<ItemResponse> estimateItemList =
estimateMapper.selectEstimateItemList(estimateRequest);
estimateSendResponse.setItemList(estimateItemList); estimateSendResponse.setItemList(estimateItemList);
// 첨부파일 목록 조회 // 첨부파일 목록 조회
@ -1253,7 +1278,8 @@ public class EstimateService {
Map<String, Object> result = (Map<String, Object>) response.getData(); Map<String, Object> result = (Map<String, Object>) response.getData();
if (result != null) { if (result != null) {
List<Map<String, Object>> succList = (List<Map<String, Object>>) result.get("successList"); List<Map<String, Object>> succList =
(List<Map<String, Object>>) result.get("successList");
for (Map<String, Object> succ : succList) { for (Map<String, Object> succ : succList) {
if (succ != null) { if (succ != null) {
for (EstimateSendResponse data : quoteList) { for (EstimateSendResponse data : quoteList) {
@ -1269,6 +1295,9 @@ public class EstimateService {
} else { } else {
log.error("sendEstimateApi >>> " + message.getMessage("common.message.no.data")); log.error("sendEstimateApi >>> " + message.getMessage("common.message.no.data"));
} }
} catch (Exception e) {
log.error("sendEstimateApi Error >>> " + e.getMessage());
}
return quoteList; return quoteList;
} }

View File

@ -1,5 +1,6 @@
package com.interplug.qcast.biz.estimate.dto; package com.interplug.qcast.biz.estimate.dto;
import com.interplug.qcast.biz.file.dto.FileRequest;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List; import java.util.List;
import lombok.Data; import lombok.Data;
@ -191,6 +192,12 @@ public class EstimateRequest {
@Schema(description = "아이템 목록") @Schema(description = "아이템 목록")
List<ItemRequest> itemList; List<ItemRequest> itemList;
@Schema(description = "첨부파일 목록")
List<FileRequest> fileList;
@Schema(description = "삭제 첨부파일 목록")
List<FileRequest> deleteFileList;
@Schema(description = "다운로드 파일명") @Schema(description = "다운로드 파일명")
private String fileName; private String fileName;

View File

@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -47,7 +48,7 @@ public class FileController {
@Operation(description = "파일을 업로드 한다.") @Operation(description = "파일을 업로드 한다.")
@PostMapping("/fileUpload") @PostMapping("/fileUpload")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public Integer fileUpload( public List<FileRequest> fileUpload(
HttpServletRequest request, HttpServletResponse response, FileRequest fileRequest) HttpServletRequest request, HttpServletResponse response, FileRequest fileRequest)
throws Exception { throws Exception {
return fileService.fileUpload(request,fileRequest); return fileService.fileUpload(request,fileRequest);

View File

@ -102,6 +102,7 @@ public class FileService {
} }
String strSrcFileNm = multipartFile.getOriginalFilename(); String strSrcFileNm = multipartFile.getOriginalFilename();
strSrcFileNm = this.getUniqueFileName(strFileFolderPath, strSrcFileNm);
File file = new File(strFileFolderPath, strSrcFileNm); File file = new File(strFileFolderPath, strSrcFileNm);
multipartFile.transferTo(file); multipartFile.transferTo(file);
@ -340,9 +341,39 @@ public class FileService {
return iResult; return iResult;
} }
public Integer fileUpload(HttpServletRequest request, FileRequest fileRequest) throws Exception { public List<FileRequest> fileUpload(HttpServletRequest request, FileRequest fileRequest)
throws Exception {
List<FileRequest> saveFileList = this.getUploadFileList(request, fileRequest); List<FileRequest> saveFileList = this.getUploadFileList(request, fileRequest);
Integer resultCnt = this.setFile(saveFileList, null); // Integer resultCnt = this.setFile(saveFileList, null);
return resultCnt; return saveFileList;
}
public String getUniqueFileName(String uploadDir, String fileName) {
File dir = new File(uploadDir);
if (!dir.exists()) {
dir.mkdirs(); // 디렉터리가 없으면 생성
}
String name = fileName;
String extension = "";
// 파일명과 확장자 분리
int dotIndex = fileName.lastIndexOf(".");
if (dotIndex >= 0) {
name = fileName.substring(0, dotIndex);
extension = fileName.substring(dotIndex);
}
File file = new File(uploadDir, fileName);
int counter = 1;
// 파일명이 중복될 경우 번호를 붙임
while (file.exists()) {
String newFileName = name + "_" + counter + extension;
file = new File(uploadDir, newFileName);
counter++;
}
return file.getName();
} }
} }

View File

@ -544,6 +544,7 @@
, SALT_AREA_FLG , SALT_AREA_FLG
, TEMP_FLG , TEMP_FLG
, TEMP_DEL_FLG , TEMP_DEL_FLG
, ORG_DEL_FLG
) )
SELECT SELECT
#{copyObjectNo} AS OBJECT_NO #{copyObjectNo} AS OBJECT_NO
@ -586,8 +587,9 @@
, CON_TYPE , CON_TYPE
, COLD_REGION_FLG , COLD_REGION_FLG
, SALT_AREA_FLG , SALT_AREA_FLG
, #{tempFlg} , #{tempFlg} AS TEMP_FLG
, #{tempDelFlg} , #{tempDelFlg} AS TEMP_DEL_FLG
, #{orgDelFlg} AS ORG_DEL_FLG
FROM T_OBJECT O WITH (NOLOCK) FROM T_OBJECT O WITH (NOLOCK)
WHERE O.OBJECT_NO = #{objectNo} WHERE O.OBJECT_NO = #{objectNo}
</insert> </insert>