Merge branch 'dev' into deploy-dev-front

This commit is contained in:
주수현
2025-07-15 15:33:57 +09:00
43 changed files with 740 additions and 661 deletions

View File

@@ -38,7 +38,7 @@ class DownloadFileController {
// 로컬 파일 경로
File downloadedFile = new File(file.getLocalPath());
if (!downloadedFile.exists()) {
throw new IllegalStateException("Downloaded file not found: " + file.getLocalPath());
throw new IllegalStateException("파일 다운로드에 실패하였습니다.");
}

View File

@@ -41,7 +41,7 @@ class UpdateFileDao implements UpdateFilePortOut {
command.getType().getName()
)));
for (UploadFileDto file : deletedFileList) {
/* for (UploadFileDto file : deletedFileList) {
try {
sftpFileDeleteUtil.deleteRealFile(file);
} catch (JSchException | SftpException e) {
@@ -51,7 +51,7 @@ class UpdateFileDao implements UpdateFilePortOut {
log.error("Unexpected error while deleting file for mapping ID {}: {}", file.getId(), e.getMessage(), e);
throw new RuntimeException("Unexpected error while deleting file", e);
}
}
}*/
if (!deletedFileList.isEmpty()) {
mapper.deleteFile(

View File

@@ -18,7 +18,7 @@ public class SftpFileUrlStrategy implements FileUrlStrategy {
@Override
public String getAttachmentURL(Long fileId) {
return String.format("/api/file/download/%s", fileId);
return String.format("/content-disposition/attachment/%s", fileId);
}
}

View File

@@ -1,27 +1,42 @@
package app.module.core.usecase.getAttachment.adapters.web;
import app.module.core.config.application.enums.FileStorageType;
import app.module.core.config.application.util.SftpFileDownloader;
import app.module.core.usecase.file.getFile.ports.GetFilePortIn;
import app.module.core.usecase.file.getFile.ports.application.domain.GetFile;
import app.module.core.usecase.file.getFile.ports.application.domain.GetFileCmd;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriUtils;
@Slf4j
@RestController
@RequiredArgsConstructor
class GetAttachmentController {
private final GetFilePortIn getFilePortIn;
private final SftpFileDownloader sftpFileDownloader;
@Value("${path.upload.public}")
private String publicPath;
@Value("${app.aws.s3.domain:null}")
@@ -34,11 +49,14 @@ class GetAttachmentController {
@GetMapping(path = "/content-disposition/attachment/{fileId}")
ResponseEntity<?> operate(@PathVariable Long fileId) throws MalformedURLException {
GetFile getFile =
getFilePortIn
.operate(new GetFileCmd(fileId))
.orElseThrow(
() -> new RuntimeException(String.format("파일을 찾을 수 없습니다. ID: %s", fileId)));
GetFile getFile;
try {
getFile = getFilePortIn.operate(new GetFileCmd(fileId))
.orElseThrow(() -> new RuntimeException(String.format("파일을 찾을 수 없습니다. ID: %s", fileId)));
} catch (RuntimeException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body("파일을 찾을 수 없습니다: " + e.getMessage());
}
// TODO - private 업로드 기능을 일단 mute
@@ -56,35 +74,74 @@ class GetAttachmentController {
// () -> new AccessDeniedException("[AccessDenied] Private 파일 리소스 접근 권한이 없습니다."));
// }
// HTTP 헤더 설정
String encodedFileName = URLEncoder.encode(getFile.getOriginName(), StandardCharsets.UTF_8)
.replace("+", "%20");
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encodedFileName);
headers.add(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate");
headers.add(HttpHeaders.PRAGMA, "no-cache");
headers.add(HttpHeaders.EXPIRES, "0");
UrlResource resource = null;
switch (FileStorageType.valueOf(uploadStorageType)) {
case LOCAL:
String filePath =
Paths.get(publicPath, getFile.getPath(), getFile.getName())
.toString();
String filePath = Paths.get(publicPath, getFile.getPath(), getFile.getName()).toString();
File localFile = new File(filePath);
if (!localFile.exists()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body("파일을 찾을 수 없습니다: ");
}
return ResponseEntity.ok()
.headers(headers)
.contentLength(localFile.length())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(new FileSystemResource(localFile));
resource = new UrlResource("file:" + filePath);
break;
case S3:
resource =
new UrlResource(
"https://"
+ cloudFrontDomain
+ bucketFolder
+ getFile.getPath()
+ "/"
+ getFile.getName());
break;
String s3Url = "https://" + cloudFrontDomain + bucketFolder + getFile.getPath() + "/" + getFile.getName();
UrlResource s3Resource = new UrlResource(s3Url);
if (!s3Resource.exists()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body("S3 파일을 찾을 수 없습니다: " + s3Url);
}
return ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(s3Resource);
case SFTP:
try {
sftpFileDownloader.downloadFile(getFile);
} catch (JSchException | SftpException | IOException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("SFTP 파일 다운로드에 실패했습니다: " + e.getMessage());
}
File downloadedFile = new File(getFile.getLocalPath());
if (!downloadedFile.exists()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body("다운로드된 파일을 찾을 수 없습니다: " + getFile.getLocalPath());
}
return ResponseEntity.ok()
.headers(headers)
.contentLength(downloadedFile.length())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(new FileSystemResource(downloadedFile));
default:
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body("지원되지 않는 저장소 타입입니다: " + uploadStorageType);
}
String encodedUploadFileName = UriUtils.encode(getFile.getOriginName(),
/* String encodedUploadFileName = UriUtils.encode(getFile.getOriginName(),
StandardCharsets.UTF_8);
String contentDisposition = "attachment; filename=\"" + encodedUploadFileName + "\"";
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
.body(resource);
.body(resource);*/
}
}

View File

@@ -23,8 +23,14 @@
LEFT JOIN uicode u ON u.parent_id = 'code.region.main' AND u.id = a.region_main_code
WHERE a.is_deleted = false
<if test="cmd.searchField != null and cmd.searchValue != null and cmd.searchValue != ''">
<if test="cmd.searchValue != null and cmd.searchValue != ''">
<choose>
<when test="cmd.searchField == ''">
AND (
a.id ILIKE '%' || #{cmd.searchValue} || '%'
OR a.name ILIKE '%' || #{cmd.searchValue} || '%'
)
</when>
<when test="cmd.searchField == 'name'">AND a.name LIKE '%' || #{cmd.searchValue} || '%'</when>
<when test="cmd.searchField == 'id'">AND a.id LIKE '%' || #{cmd.searchValue} || '%'</when>
</choose>
@@ -48,24 +54,7 @@
)
</if>
<if test="pageable.sort != null and !pageable.sort.isEmpty()">
ORDER BY
<foreach collection="pageable.sort" item="order" separator=",">
<choose>
<when test="order.property eq 'id'">a.id</when>
<when test="order.property eq 'email'">a.email</when>
<when test="order.property eq 'accountDisabled'">a.account_disabled</when>
<when test="order.property eq 'accountLocked'">a.account_locked</when>
<when test="order.property eq 'createdAt'">a.created_at</when>
<when test="order.property eq 'updatedAt'">a.updated_at</when>
<otherwise>a.created_at</otherwise>
</choose>
<choose>
<when test="order.direction.toString() eq 'DESC'">DESC</when>
<otherwise>ASC</otherwise>
</choose>
</foreach>
</if>
ORDER BY a.seq DESC
OFFSET #{pageable.offset} ROWS FETCH NEXT #{pageable.pageSize} ROWS ONLY
</select>

View File

@@ -22,7 +22,7 @@ delete from uri where id in (
'uri.admin.settings.adminRoles'
);
-- front_user
-- front_user 테이블 : household 로 사용되어 삭제
DROP TABLE IF EXISTS front_user_has_upload_file;
DROP TABLE IF EXISTS front_user_has_role;
DROP TABLE IF EXISTS front_user_social;
@@ -33,6 +33,7 @@ DROP SEQUENCE IF EXISTS front_user_has_upload_file_seq;
DROP SEQUENCE IF EXISTS front_user_has_role_seq;
DROP SEQUENCE IF EXISTS front_user_social_seq ;
-- 일계부 테이블 : daily_xxx 로 사용되어 삭제
DROP TABLE IF EXISTS input_day_group;
DROP TABLE IF EXISTS daily_input_status;
DROP TABLE IF EXISTS income_expense_record;
@@ -51,10 +52,17 @@ DROP SEQUENCE IF EXISTS work_input_seq;
DROP SEQUENCE IF EXISTS forestry_self_consumption_seq;
DROP SEQUENCE IF EXISTS agriculture_self_consumption_seq;
-- 샘플 게시판 테이블 : 미사용으로 삭제
DROP TABLE IF EXISTS article_has_upload_file ;
DROP TABLE IF EXISTS article_comment ;
DROP TABLE IF EXISTS article ;
DROP SEQUENCE IF EXISTS article_comment_seq ;
-- 이월금(매달 1일, 말일) 테이블 : daily_summary 로 사용되어 삭제
DROP TABLE IF EXISTS monthly_carryover;
DROP SEQUENCE IF EXISTS monthly_carryover_seq;

View File

@@ -39,7 +39,6 @@ DROP TABLE IF EXISTS suggestion;
DROP TABLE IF EXISTS upload_receipt_files;
DROP TABLE IF EXISTS forest_product_yield;
DROP TABLE IF EXISTS forest_product;
DROP TABLE IF EXISTS monthly_carryover;
DROP TABLE IF EXISTS bank_auto_transfer;
DROP TABLE IF EXISTS monthly_input_status;
@@ -84,7 +83,6 @@ DROP SEQUENCE IF EXISTS research_area_seq;
DROP SEQUENCE IF EXISTS upload_receipt_files_seq;
DROP SEQUENCE IF EXISTS forest_product_yield_seq;
DROP SEQUENCE IF EXISTS forest_product_seq;
DROP SEQUENCE IF EXISTS monthly_carryover_seq;
DROP SEQUENCE IF EXISTS bank_auto_transfer_seq;

View File

@@ -1016,46 +1016,6 @@ COMMENT ON COLUMN bank_auto_transfer.transfer_category_code IS '이체 카테고
COMMENT ON COLUMN bank_auto_transfer.unit IS '단위(직접입력)';
COMMENT ON COLUMN bank_auto_transfer.category IS '카테고리';
-- 6. monthly_carryover
-- ============================================
-- TABLE : monthly_carryover
-- DESC : 이월금(매달 1일, 말일) 테이블
-- ============================================
CREATE SEQUENCE monthly_carryover_seq START WITH 1 INCREMENT BY 1 CACHE 1 NO CYCLE;
CREATE TABLE monthly_carryover (
id bigint DEFAULT nextval('monthly_carryover_seq') NOT NULL, -- 이월금 ID
household_seq bigint NOT NULL, -- 임가정보 일련번호 (FK)
month varchar(7) NOT NULL, -- 조사시행 월 (yyyy-mm)
start_price integer, -- 월초이월금(현금)
end_price integer, -- 월말현금
created_at timestamp(6) NOT NULL, -- 생성일
created_by varchar(255) NOT NULL, -- 생성자
updated_at timestamp(6) NOT NULL, -- 수정일
updated_by varchar(255) NOT NULL, -- 수정자
deleted_at timestamp(6), -- 삭제일
deleted_by varchar(255), -- 삭제자
is_deleted boolean DEFAULT false, -- 삭제여부
CONSTRAINT monthly_carryover_pkey PRIMARY KEY (id),
CONSTRAINT fk_monthly_carryover__household FOREIGN KEY (household_seq) REFERENCES household(seq)
);
COMMENT ON TABLE monthly_carryover IS '이월금(매달 1일, 말일)';
COMMENT ON COLUMN monthly_carryover.id IS '이월금 ID';
COMMENT ON COLUMN monthly_carryover.household_seq IS '임가정보 일련번호';
COMMENT ON COLUMN monthly_carryover.month IS '조사시행 월 (yyyy-mm)';
COMMENT ON COLUMN monthly_carryover.start_price IS '월초이월금(현금)';
COMMENT ON COLUMN monthly_carryover.end_price IS '월말현금';
COMMENT ON COLUMN monthly_carryover.created_at IS '생성일';
COMMENT ON COLUMN monthly_carryover.created_by IS '생성자';
COMMENT ON COLUMN monthly_carryover.updated_at IS '수정일';
COMMENT ON COLUMN monthly_carryover.updated_by IS '수정자';
COMMENT ON COLUMN monthly_carryover.deleted_at IS '삭제일';
COMMENT ON COLUMN monthly_carryover.deleted_by IS '삭제자';
COMMENT ON COLUMN monthly_carryover.is_deleted IS '삭제여부';
-- 12. upload_receipt_files
-- ============================================