Merge branch 'susu' into dev

This commit is contained in:
주수현
2025-07-15 15:33:07 +09:00
7 changed files with 161 additions and 37 deletions

View File

@@ -39,8 +39,7 @@
resultType="app.module.front.usecase.info.notice.getNotice.ports.application.domain.GetNoticeUploadFile">
/* getUploadFiles 상세 게시글 조회 시, 첨부파일 조회 */
SELECT
awuf.notice_id AS noticeId,
awuf.upload_files_id AS uploadfileId,
uf.mapping_id AS noticeId,
uf.id AS id,
uf.created_at AS createdAt,
uf.created_by AS createdBy,
@@ -51,9 +50,7 @@
uf.origin_name AS originName,
uf.path AS path,
uf.type AS type
FROM notice_has_upload_file awuf
INNER JOIN upload_file uf
ON awuf.upload_files_id = uf.id
WHERE awuf.notice_id = #{id}
FROM upload_file uf
WHERE uf.mapping_id = #{id} and uf.is_deleted = false and uf.type='NOTICE'
</select>
</mapper>

View File

@@ -13,15 +13,21 @@
</dd>
</dl>
<div class="detail-content">
<p th:utext="${notice.content}"></p>
<p th:utext="${ notice.content }"></p>
</div>
<div class="download-file" th:if="${!#lists.isEmpty(notice.uploadFiles)}">
<p class="tit">첨부파일</p>
<ul>
<li th:each="item : ${notice.uploadFiles}"><a th:href="${item.attachmentURL}" download
th:text="${item.originName}"></a></li>
<li th:each="item : ${notice.uploadFiles}">
<a href="javascript:void(0);"
th:text="${item.originName}"
th:data-url="${item.attachmentURL}"
th:data-filename="${item.originName}"
onclick="formControl.fileDownload(this)">
</a>
</li>
</ul>
</div>
@@ -57,13 +63,71 @@ root: /*[[|#{uri.front.info.user.path}/password|]]*/'rootUrl',
*/
const previousUrl = document.referrer;
if (previousUrl.includes('/info/notice')) {
/* if (previousUrl.includes('/info/notice')) {
history.back();
} else {
} else {*/
location.href = '/info/notice';
// }
},
fileDownload(element) {
const url = element.dataset.url;
const fileName = element.dataset.filename;
if (!url || !fileName) {
console.error('Invalid URL or fileName:', url, fileName);
ajaxUtil._alert('파일 다운로드를 시작할 수 없습니다: 유효하지 않은 URL 또는 파일명입니다.', null);
return;
}
fetch(url, {
method: 'GET',
headers: {
'Accept': 'application/octet-stream'
}
}).then(response => {
console.log('Response status:', response.status);
if (!response.ok) {
// 응답 본문 읽기
return response.text().then(errorMessage => {
let message = errorMessage || '파일 다운로드에 실패했습니다. 상태 코드: ' + response.status;
if (response.status === 404) {
message = errorMessage || '파일을 찾을 수 없습니다.';
} else if (response.status === 500) {
message = errorMessage || '서버 오류로 인해 파일 다운로드에 실패했습니다.';
}
throw new Error(message);
});
}
// Content-Disposition 헤더에서 파일명 추출
const disposition = response.headers.get('Content-Disposition');
console.log('Content-Disposition:', disposition);
let serverFileName = fileName;
if (disposition && disposition.includes('filename*=')) {
const matches = disposition.match(/filename\*=UTF-8''(.+)/);
if (matches && matches[1]) {
try {
serverFileName = decodeURIComponent(matches[1]);
} catch (e) {
console.error('Failed to decode filename:', e);
}
}
}
return response.blob().then(blob => ({ blob, fileName: serverFileName }));
})
.then(({ blob, fileName }) => {
console.log('Blob received, size:', blob.size);
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(link.href);
})
.catch(error => {
console.error('Download error:', error);
ajaxUtil._alert('파일 다운로드에 실패했습니다: ', null);
});
}
},
}
</script>