파일업로드 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);
}
// 첨부파일 초기화
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
List<EstimateSendResponse> resultList = new ArrayList<EstimateSendResponse>();
resultList = this.sendEstimateApi(estimateRequest);
@ -676,7 +698,8 @@ public class EstimateService {
objectRequest.setSaleStoreId(estimateCopyRequest.getCopySaleStoreId());
objectRequest.setReceiveUser(
StringUtils.defaultString(estimateCopyRequest.getCopyReceiveUser()));
objectRequest.setDelFlg("0");
objectRequest.setDelFlg("1");
objectRequest.setOrgDelFlg("0");
objectRequest.setTempFlg("0");
objectRequest.setTempDelFlg("0");
objectRequest.setUserId(estimateCopyRequest.getUserId());
@ -1205,69 +1228,75 @@ public class EstimateService {
List<EstimateSendResponse> quoteList = new ArrayList<EstimateSendResponse>();
String docNo = "";
// 견적서 상세 조회
EstimateSendResponse estimateSendResponse =
estimateMapper.selectEstimateApiDetail(estimateRequest);
try {
// 견적서 상세 조회
EstimateSendResponse estimateSendResponse =
estimateMapper.selectEstimateApiDetail(estimateRequest);
if (estimateSendResponse == null) {
throw new QcastException(ErrorCode.NOT_FOUND, message.getMessage("common.message.no.data"));
} else {
estimateSendResponse.setSaveType("3");
estimateSendResponse.setSyncFlg("0");
estimateSendResponse.setConstructSpecification(
!StringUtils.isEmpty(estimateSendResponse.getConstructSpecification())
? estimateSendResponse.getConstructSpecification().split("")[0]
: "");
estimateSendResponse.setDelFlg("1".equals(estimateSendResponse.getDelFlg()) ? "Y" : "N");
if (estimateSendResponse == null) {
throw new QcastException(ErrorCode.NOT_FOUND, message.getMessage("common.message.no.data"));
} else {
estimateSendResponse.setSaveType("3");
estimateSendResponse.setSyncFlg("0");
estimateSendResponse.setConstructSpecification(
!StringUtils.isEmpty(estimateSendResponse.getConstructSpecification())
? estimateSendResponse.getConstructSpecification().split("")[0]
: "");
estimateSendResponse.setDelFlg("1".equals(estimateSendResponse.getDelFlg()) ? "Y" : "N");
// 아이템 목록 조회
estimateRequest.setSchBomNotExist("1");
List<ItemResponse> estimateItemList = estimateMapper.selectEstimateItemList(estimateRequest);
estimateSendResponse.setItemList(estimateItemList);
// 아이템 목록 조회
estimateRequest.setSchBomNotExist("1");
List<ItemResponse> estimateItemList =
estimateMapper.selectEstimateItemList(estimateRequest);
estimateSendResponse.setItemList(estimateItemList);
// 첨부파일 목록 조회
FileRequest fileDeleteReq = new FileRequest();
fileDeleteReq.setObjectNo(estimateRequest.getObjectNo());
fileDeleteReq.setPlanNo(estimateRequest.getPlanNo());
fileDeleteReq.setCategory("10");
// 첨부파일 목록 조회
FileRequest fileDeleteReq = new FileRequest();
fileDeleteReq.setObjectNo(estimateRequest.getObjectNo());
fileDeleteReq.setPlanNo(estimateRequest.getPlanNo());
fileDeleteReq.setCategory("10");
List<FileResponse> fileList = fileMapper.selectFileList(fileDeleteReq);
estimateSendResponse.setFileList(fileList);
List<FileResponse> fileList = fileMapper.selectFileList(fileDeleteReq);
estimateSendResponse.setFileList(fileList);
quoteList.add(estimateSendResponse);
estimateSendRequest.setQuoteList(quoteList);
}
quoteList.add(estimateSendResponse);
estimateSendRequest.setQuoteList(quoteList);
}
EstimateApiResponse response = null;
/* [1]. QSP API CALL -> Response */
String strResponse =
interfaceQsp.callApi(
HttpMethod.POST, QSP_API_URL + "/api/order/qcastQuotationSave", estimateSendRequest);
EstimateApiResponse response = null;
/* [1]. QSP API CALL -> Response */
String strResponse =
interfaceQsp.callApi(
HttpMethod.POST, QSP_API_URL + "/api/order/qcastQuotationSave", estimateSendRequest);
if (!"".equals(strResponse)) {
com.fasterxml.jackson.databind.ObjectMapper om =
new com.fasterxml.jackson.databind.ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
response = om.readValue(strResponse, EstimateApiResponse.class);
if (!"".equals(strResponse)) {
com.fasterxml.jackson.databind.ObjectMapper om =
new com.fasterxml.jackson.databind.ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
response = om.readValue(strResponse, EstimateApiResponse.class);
Map<String, Object> result = (Map<String, Object>) response.getData();
Map<String, Object> result = (Map<String, Object>) response.getData();
if (result != null) {
List<Map<String, Object>> succList = (List<Map<String, Object>>) result.get("successList");
for (Map<String, Object> succ : succList) {
if (succ != null) {
for (EstimateSendResponse data : quoteList) {
if (data.getObjectNo().equals(succ.get("objectNo"))
&& data.getPlanNo().equals(succ.get("planNo"))) {
data.setSyncFlg(String.valueOf(succ.get("syncFlg")));
data.setDocNo(String.valueOf(succ.get("docNo")));
if (result != null) {
List<Map<String, Object>> succList =
(List<Map<String, Object>>) result.get("successList");
for (Map<String, Object> succ : succList) {
if (succ != null) {
for (EstimateSendResponse data : quoteList) {
if (data.getObjectNo().equals(succ.get("objectNo"))
&& data.getPlanNo().equals(succ.get("planNo"))) {
data.setSyncFlg(String.valueOf(succ.get("syncFlg")));
data.setDocNo(String.valueOf(succ.get("docNo")));
}
}
}
}
}
} else {
log.error("sendEstimateApi >>> " + message.getMessage("common.message.no.data"));
}
} else {
log.error("sendEstimateApi >>> " + message.getMessage("common.message.no.data"));
} catch (Exception e) {
log.error("sendEstimateApi Error >>> " + e.getMessage());
}
return quoteList;

View File

@ -1,5 +1,6 @@
package com.interplug.qcast.biz.estimate.dto;
import com.interplug.qcast.biz.file.dto.FileRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.Data;
@ -191,6 +192,12 @@ public class EstimateRequest {
@Schema(description = "아이템 목록")
List<ItemRequest> itemList;
@Schema(description = "첨부파일 목록")
List<FileRequest> fileList;
@Schema(description = "삭제 첨부파일 목록")
List<FileRequest> deleteFileList;
@Schema(description = "다운로드 파일명")
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 jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
@ -47,7 +48,7 @@ public class FileController {
@Operation(description = "파일을 업로드 한다.")
@PostMapping("/fileUpload")
@ResponseStatus(HttpStatus.OK)
public Integer fileUpload(
public List<FileRequest> fileUpload(
HttpServletRequest request, HttpServletResponse response, FileRequest fileRequest)
throws Exception {
return fileService.fileUpload(request,fileRequest);

View File

@ -102,6 +102,7 @@ public class FileService {
}
String strSrcFileNm = multipartFile.getOriginalFilename();
strSrcFileNm = this.getUniqueFileName(strFileFolderPath, strSrcFileNm);
File file = new File(strFileFolderPath, strSrcFileNm);
multipartFile.transferTo(file);
@ -340,9 +341,39 @@ public class FileService {
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);
Integer resultCnt = this.setFile(saveFileList, null);
return resultCnt;
// Integer resultCnt = this.setFile(saveFileList, null);
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
, TEMP_FLG
, TEMP_DEL_FLG
, ORG_DEL_FLG
)
SELECT
#{copyObjectNo} AS OBJECT_NO
@ -586,8 +587,9 @@
, CON_TYPE
, COLD_REGION_FLG
, SALT_AREA_FLG
, #{tempFlg}
, #{tempDelFlg}
, #{tempFlg} AS TEMP_FLG
, #{tempDelFlg} AS TEMP_DEL_FLG
, #{orgDelFlg} AS ORG_DEL_FLG
FROM T_OBJECT O WITH (NOLOCK)
WHERE O.OBJECT_NO = #{objectNo}
</insert>