견적서 첨부파일 다운로드 API 추가
This commit is contained in:
parent
9e2861f519
commit
8f849e8821
@ -3,6 +3,8 @@ package com.interplug.qcast.biz.object;
|
||||
import com.interplug.qcast.biz.object.dto.*;
|
||||
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;
|
||||
@ -109,4 +111,21 @@ public class ObjectController {
|
||||
public PlanReqResponse selectPlanReqList(PlanReqRequest planReqRequest) throws Exception {
|
||||
return objectService.selectPlanReqList(planReqRequest);
|
||||
}
|
||||
|
||||
@Operation(description = "견적서 파일을 다운로드한다.")
|
||||
@PostMapping("/file/{objectNo}/{no}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void fileDownload(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@PathVariable String objectNo,
|
||||
@PathVariable String no)
|
||||
throws Exception {
|
||||
|
||||
UploadRequest uploadRequest = new UploadRequest();
|
||||
uploadRequest.setObjectNo(objectNo);
|
||||
uploadRequest.setNo(no);
|
||||
|
||||
objectService.fileDownload(request, response, uploadRequest);
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,4 +62,7 @@ interface ObjectMapper {
|
||||
|
||||
// 플랜정보 물건번호 변경
|
||||
public int updatePlanObjectNoChange(ObjectRequest objectRequest);
|
||||
|
||||
// 견적서 첨부파일 조회
|
||||
public UploadResponse selectUpload(UploadRequest uploadRequest);
|
||||
}
|
||||
|
||||
@ -7,6 +7,13 @@ import com.interplug.qcast.config.Exception.QcastException;
|
||||
import com.interplug.qcast.config.message.Messages;
|
||||
import com.interplug.qcast.util.InterfaceQsp;
|
||||
import io.micrometer.common.util.StringUtils;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -20,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@Slf4j
|
||||
@ -371,4 +379,56 @@ public class ObjectService {
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public void fileDownload(
|
||||
HttpServletRequest request, HttpServletResponse response, UploadRequest uploadRequest)
|
||||
throws Exception {
|
||||
|
||||
InputStream inputStream = null;
|
||||
|
||||
try {
|
||||
// 첨부파일 조회
|
||||
UploadResponse uploadResponse = objectMapper.selectUpload(uploadRequest);
|
||||
|
||||
if (uploadResponse != null) {
|
||||
// 첨부파일 물리적 경로
|
||||
String filePath =
|
||||
baseDirPath
|
||||
+ File.separator
|
||||
+ uploadResponse.getObjectNo()
|
||||
+ File.separator
|
||||
+ uploadResponse.getFaileName();
|
||||
File file = new File(filePath);
|
||||
|
||||
if (file.exists()) {
|
||||
// 파일 변환 타입
|
||||
String mimeType = URLConnection.guessContentTypeFromName(file.getName());
|
||||
if (mimeType == null) {
|
||||
mimeType = "application/octet-stream";
|
||||
}
|
||||
|
||||
// 소스 파일 명
|
||||
String srcFileName = uploadResponse.getFaileName();
|
||||
srcFileName = URLEncoder.encode(srcFileName, "UTF-8").replaceAll("\\+", "%20");
|
||||
|
||||
response.setHeader("Content-Transfer-Encoding", "binary;");
|
||||
response.setHeader("Pragma", "no-cache;");
|
||||
response.setHeader("Expires", "-1;");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + srcFileName + "\"");
|
||||
response.setContentType(mimeType);
|
||||
response.setContentLength((int) file.length());
|
||||
|
||||
inputStream = new BufferedInputStream(new FileInputStream(file));
|
||||
|
||||
FileCopyUtils.copy(inputStream, response.getOutputStream());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.interplug.qcast.biz.object.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
// @Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class UploadRequest {
|
||||
@Schema(description = "물건번호")
|
||||
private String objectNo;
|
||||
|
||||
@Schema(description = "파일번호")
|
||||
private String no;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.interplug.qcast.biz.object.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
// @Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class UploadResponse {
|
||||
@Schema(description = "물건번호")
|
||||
private String objectNo;
|
||||
|
||||
@Schema(description = "파일번호")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "첨부파일명")
|
||||
private String faileName;
|
||||
}
|
||||
@ -435,7 +435,8 @@
|
||||
/* sqlid : com.interplug.qcast.biz.object.updateObject */
|
||||
UPDATE T_OBJECT
|
||||
SET
|
||||
OBJECT_STATUS_ID = #{objectStatusId}
|
||||
SALE_STORE_ID = #{saleStoreId}
|
||||
, OBJECT_STATUS_ID = #{objectStatusId}
|
||||
, OBJECT_NAME = #{objectName}
|
||||
, OBJECT_NAME_OMIT = #{objectNameOmit}
|
||||
, OBJECT_NAME_KANA = #{objectNameKana}
|
||||
@ -593,4 +594,16 @@
|
||||
WHERE OBJECT_NO = #{objectNo}
|
||||
</update>
|
||||
|
||||
<select id="selectUpload" parameterType="com.interplug.qcast.biz.object.dto.UploadRequest" resultType="com.interplug.qcast.biz.object.dto.UploadResponse">
|
||||
/* sqlid : com.interplug.qcast.biz.object.selectUpload */
|
||||
SELECT
|
||||
TOP 1
|
||||
U.OBJECT_NO
|
||||
, U.NO
|
||||
, U.FAILE_NAME
|
||||
FROM T_UPLOAD U WITH (NOLOCK)
|
||||
WHERE U.OBJECT_NO = #{objectNo}
|
||||
AND U.NO = #{no}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
x
Reference in New Issue
Block a user